PolicyIterationAgent<T>
Models & Types ยท AiDotNet.ReinforcementLearning.Agents.DynamicProgramming
Policy Iteration agent for reinforcement learning using dynamic programming.
Inheritance: ReinforcementLearningAgentBase<T> โ PolicyIterationAgent<T>
For Beginners
Policy Iteration works in two repeating steps:
- Evaluate: calculate how good the current strategy is for every state
- Improve: update the strategy to be greedy with respect to the evaluation These steps repeat until the strategy stops changing (convergence). It requires a complete model of the environment (transition probabilities and rewards) and works best for small, fully-known environments like grid worlds or simple games.
How It Works
Policy Iteration alternates between policy evaluation and policy improvement until convergence to the optimal policy.
Example
// Create a Policy Iteration agent for environments with known dynamics
var options = new PolicyIterationOptions<double> { StateSize = 4, ActionSize = 2 };
var agent = new PolicyIterationAgent<double>(options);
// Select an action using the current policy
var state = new Vector<double>(new double[] { 0.5, -0.3, 1.0, 0.2 });
var action = agent.SelectAction(state);
Constructors
| Constructor | Summary |
|---|---|
PolicyIterationAgent() |
Initializes a new instance with default settings. |
PolicyIterationAgent(PolicyIterationOptions<T> options) |
Properties
| Property | Summary |
|---|---|
int FeatureCount { get; } |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T> GetMetrics() |
|
ModelMetadata<T> GetModelMetadata() |
|
T Train() |
|
Task TrainAsync() |
|
Task<Vector<T>> PredictAsync(Vector<T> input) |
|
Vector<T> Predict(Vector<T> input) |
|
Vector<T> SelectAction(Vector<T> state, bool training) |
|
byte[] Serialize() |
Auto-generated common model serialization surface. |
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) |