ExpectedSARSAAgent<T>
Models & Types · AiDotNet.ReinforcementLearning.Agents.ExpectedSARSA
Expected SARSA agent using tabular methods.
Inheritance: ReinforcementLearningAgentBase<T> → ExpectedSARSAAgent<T>
Implements: IGradientComputable<T, Vector<T>, Vector<T>>
For Beginners
Expected SARSA is like SARSA but instead of using the actual next action, it uses the average Q-value weighted by the probability of taking each action. This reduces variance compared to SARSA.
Update: Q(s,a) ← Q(s,a) + α[r + γ Σ π(a’|s’)Q(s’,a’) - Q(s,a)]
Benefits over SARSA:
- Lower Variance: Averages over actions instead of sampling
- Off-Policy Learning: Can learn optimal policy while exploring
- Better Performance: Often converges faster than SARSA
Famous for: Van Seijen et al. 2009, bridging SARSA and Q-Learning
How It Works
Expected SARSA is a TD control algorithm that uses the expected value under the current policy instead of sampling the next action.
Example
// Create an Expected SARSA agent that averages over next actions
var options = new ExpectedSARSAOptions<double>(stateSize: 4, actionSize: 2) { LearningRate = 0.1 };
var agent = new ExpectedSARSAAgent<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 |
|---|---|
ExpectedSARSAAgent() |
Initializes a new instance with default settings. |
ExpectedSARSAAgent(ExpectedSARSAOptions<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 SaveModel(string filepath) |
|
void StoreExperience(Vector<T> state, Vector<T> action, T reward, Vector<T> nextState, bool done) |