NStepSARSAAgent<T>
Models & Types · AiDotNet.ReinforcementLearning.Agents.NStepSARSA
N-step SARSA agent using multi-step bootstrapping.
Inheritance: ReinforcementLearningAgentBase<T> → NStepSARSAAgent<T>
Implements: IGradientComputable<T, Vector<T>, Vector<T>>
For Beginners
Instead of updating based on just the next reward (1-step SARSA), n-step methods look ahead n steps to get better return estimates before bootstrapping.
Update: G_t = r_t+1 + γr_t+2 + … + γ^(n-1)r_t+n + γ^n Q(s_t+n, a_t+n)
Benefits:
- Better credit assignment: Propagates rewards faster than 1-step
- Lower variance: Than full Monte Carlo
- Flexible: Choose n to balance bias and variance
Common values: n=3 to n=10 Famous for: Sutton & Barto’s RL textbook, Chapter 7
How It Works
N-step SARSA uses n-step returns that look ahead multiple steps before bootstrapping. This provides a middle ground between TD (1-step) and Monte Carlo (full episode).
Example
// Create an n-step SARSA agent that looks 5 steps ahead
var options = new NStepSARSAOptions<double> { NSteps = 5, StateSize = 4, ActionSize = 2 };
var agent = new NStepSARSAAgent<double>(options);
// Select an action for the current state
var state = new Vector<double>(new double[] { 0.5, -0.3, 1.0, 0.2 });
var action = agent.SelectAction(state);
Constructors
| Constructor | Summary |
|---|---|
NStepSARSAAgent() |
|
NStepSARSAAgent(NStepSARSAOptions<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) |