DQN

English translation

Graduate course · Research application activities

Compare state representations in a Q-table and a neural network on the same Queue problem, and evaluate the learned policy against rule-based policies.

Before practice

01 What do replay and the target network each change?

Description

DQN replaces the Q-table with a neural network. Replay reuses stored experiences, and the target network separates updates to the parameters used to form targets.

02 Can returns from different environments be compared directly?

Description

Map the buffer, learning start, target updates, input normalization, and exploration schedule as well as the policy name. Returns from different environments do not share the same performance unit.

Execution conditions

Run the baseline Queue example with NumPy. Compare policies on seed=100…104, which was not used for training.

PyTorch is required. This is a short synthetic experiment; its configuration does not guarantee learning performance.

Public environment activities use gymnasium and stable-baselines3. gymnasium[classic-control] is required only for visualization.

If the required package is missing, run %pip install control==0.10.2 gymnasium==1.3.0 stable-baselines3==2.9.2 in a Colab or Jupyter code cell.

Applications

Throughput and cost of equipment and communication resources

An average of 2 items arrive at the synthetic queue each time step. Increasing service capacity reduces queue length but increases energy cost.

Observation·State
Queue length q=0q=0…20. Observation q/20q/20.
Action
Choose a processing capacity of 0, 2, or 4.
Reward·Constraint
−(next queue length + 0.2×capacity² + 10×dropped items). Time limit at 100 steps.
Comparison baseline
Constant capacity of 2, and a threshold policy based on queue length.
Metrics to check
Evaluation return, mean queue length, mean capacity², and dropped-item count.

Design energy storage operation

A research design case distinguishing the roles of price, load, and stored energy before connecting measured data.

Observation·State
SOC, load, price, and time. Observations must exclude future information.
Action
Charging and discharging power. Decide first between discrete levels and a continuous range.
Reward·Constraint
Electricity and degradation costs. Specify rules for SOC and power limits.
Comparison baseline
Time-of-day rules and, if possible, optimization using the same information.
Metrics to check
Total cost, constraint violations, and maximum grid power draw. Split train/test data by date.

Connect one key change to actual policy metrics instead of adding more full retraining runs.

Practice

Preview practice notebookDownload practice notebook

1. DQN on the same small problem

Starting conditions

Compare how Q-tables and neural networks represent actions for each state, and evaluate the learned policy.

Procedure

  1. Check the performance of Queue's rule-based policies first, then run the provided training function.
  2. Plot training loss and selected actions for q=0q=0…20.
  3. Evaluate return, queue length, cost, and dropped items on seed=100…104, which was not used for training.

Results to retain

Items to record and points to check
Training seed
Training transition count
Return mean and standard deviation
Mean queue length
Capacity²
Dropped items

Points to check

  • Did you avoid interpreting a decrease in loss as an immediate improvement in policy performance?
  • Did you record results that fell below the baseline in a short training run as observed?

2. Move to a public DQN implementation

Starting conditions

SB3 DQN, CartPole-v1, and 2048 transitions. Compare with random and rule-based policies in the same environment, without directly comparing scores with the earlier Queue results.

Procedure

  1. Map the public DQN's policy, replay size, target update interval, and learning start to the preceding implementation.
  2. Run the provided short training and evaluate deterministically on seed=100…102.
  3. Compare episode lengths and returns of the learned policy, Random, and Rule, and state the evidence for judging whether the training budget is sufficient.

Results to retain

Items to record and points to check
Policy
Training transition count
Evaluation return mean and standard deviation
Mean length

Points to check

  • Did you avoid assuming SB3 DQN includes Double, Dueling, and PER?
  • Did you avoid claiming superiority based on Queue and CartPole scores from different environments?

3. Apply this to your research problem

Starting conditions

Based on the preceding experiments, choose Queue, Motor, or one of your research problems and design an experiment for real application.

Procedure

  1. Define state, observation, action, reward, termination, and time limit in one table. Record each variable's units and the information you can actually obtain.
  2. Write 3 expected transitions numerically and check whether rewards for good and bad actions match your intent.
  3. Choose one rule-based comparison baseline, one evaluation condition, and one failure case of greatest concern. Also list the required measurements or simulator.

Results to retain

You may continue with the research problem and design table selected earlier. Revisit existing entries and transition examples using the concepts learned in this activity, and update changed entries or reasons for retaining them.

Items to record and points to check
Item
Concrete definition and units
Observability and verification method

Points to check

  • Did you exclude future information and evaluation labels from observations?
  • Did you define domain-specific metrics rather than judging the research contribution solely by training return?

Official examples and data