DQNAgent<T>

Models & Types · AiDotNet.ReinforcementLearning.Agents.DQN

Deep Q-Network (DQN) agent for reinforcement learning.

Inheritance: ReinforcementLearningAgentBase<T> → DeepReinforcementLearningAgentBase<T> → DQNAgent<T>

Implements: IGeneratedParameterRegistrar<T>, IGradientComputable<T, Vector<T>, Vector<T>>

For Beginners

DQN learns to play games (or solve problems) by learning how valuable each action is in each situation. It uses a neural network to estimate these “Q-values” - essentially, expected future rewards.

The agent:

  • Sees the current state (like game screen)
  • Evaluates each possible action using its Q-network
  • Picks the action with highest Q-value (with some random exploration)
  • Learns from past experiences stored in memory

Famous for: Learning to play Atari games from pixels (DeepMind, 2015)

How It Works

DQN is a landmark algorithm that combined Q-learning with deep neural networks, enabling RL to scale to high-dimensional state spaces. It introduced two key innovations:

  1. Experience Replay: Breaks temporal correlations by training on random past experiences
  2. Target Network: Provides stable Q-value targets by using a slowly-updating copy

Reference: Mnih, V., et al. (2015). “Human-level control through deep reinforcement learning.” Nature.

Example

// Create a Deep Q-Network agent for discrete action spaces
var options = new DQNOptions<double> { StateSize = 4, ActionSize = 2, LearningRate = 0.001 };
var agent = new DQNAgent<double>(options);
            
// Select an action for the current game state
var state = new Vector<double>(new double[] { 0.5, -0.3, 1.0, 0.2 });
var action = agent.SelectAction(state);

Constructors

Constructor Summary
DQNAgent() Initializes a new instance with default settings.
DQNAgent(DQNOptions<T> options) Initializes a new instance of the DQNAgent class.

Properties

Property Summary
int FeatureCount { get; }

Methods

Method Summary
Dictionary<string, T> GetMetrics()
ModelMetadata<T> GetModelMetadata()
ModelOptions GetOptions()
T Train()
Vector<T> ComputeGradients(Vector<T> input, Vector<T> target, ILossFunction<T> lossFunction) Computes gradients of the loss with respect to this agent’s parameters, without updating them.
Vector<T> SelectAction(Vector<T> state, bool training)
byte[] Serialize() Auto-generated common model serialization surface.
void ApplyGradients(Vector<T> gradients, T learningRate)
void Deserialize(byte[] data) Auto-generated common model deserialization surface.
void LoadModel(string filepath)
void SaveModel(string filepath)
void StoreExperience(Vector<T> state, Vector<T> action, T reward, Vector<T> nextState, bool done)