NStepQLearningAgent<T>

Models & Types ยท AiDotNet.ReinforcementLearning.Agents.NStepQLearning

N-step Q-Learning agent using multi-step off-policy returns.

Inheritance: ReinforcementLearningAgentBase<T> โ†’ NStepQLearningAgent<T>

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

For Beginners

N-step Q-Learning extends regular Q-Learning by looking ahead n steps before bootstrapping. Regular Q-Learning updates based on the very next reward, while n-step looks at n future rewards. This propagates information faster (like seeing further down a road before deciding which way to turn). The trade-off: higher n means faster learning but more variance. Common values are n=3 to n=10.

Example

// Create an n-step Q-Learning agent for faster reward propagation
var options = new NStepQLearningOptions<double> { NSteps = 5, StateSize = 4, ActionSize = 2 };
var agent = new NStepQLearningAgent<double>(options);
            
// Select an action using epsilon-greedy over Q-values
var state = new Vector<double>(new double[] { 0.5, -0.3, 1.0, 0.2 });
var action = agent.SelectAction(state);

Constructors

Constructor Summary
NStepQLearningAgent() Initializes a new instance with default settings.
NStepQLearningAgent(NStepQLearningOptions<T> options)

Properties

Property Summary
int FeatureCount { get; }

Methods

Method Summary
ModelMetadata<T> GetModelMetadata()
T Train()
Vector<T> ComputeGradients(Vector<T> input, Vector<T> target, ILossFunction<T> lossFunction)
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 ResetEpisode()
void SaveModel(string filepath)
void StoreExperience(Vector<T> state, Vector<T> action, T reward, Vector<T> nextState, bool done)