PPOAgent<T>
Models & Types · AiDotNet.ReinforcementLearning.Agents.PPO
Proximal Policy Optimization (PPO) agent for reinforcement learning.
Inheritance: ReinforcementLearningAgentBase<T> → DeepReinforcementLearningAgentBase<T> → PPOAgent<T>
Implements: IGradientComputable<T, Vector<T>, Vector<T>>
For Beginners
PPO is one of the most popular RL algorithms today. It’s used by:
- OpenAI’s ChatGPT (for RLHF training)
- Many robotics systems
- Game AI (including Dota 2 bots)
Key idea: Make small, safe policy improvements by clipping updates. Think of it like driving - small steering adjustments work better than jerking the wheel.
PPO learns two things:
- A policy (actor): What action to take in each state
- A value function (critic): How good each state is
The critic helps the actor learn more efficiently.
How It Works
PPO is a policy gradient method that uses a clipped surrogate objective to enable multiple epochs of minibatch updates without destructively large policy changes. It achieves state-of-the-art performance across many RL benchmarks while being simpler and more robust than methods like TRPO.
Reference: Schulman, J., et al. (2017). “Proximal Policy Optimization Algorithms.” arXiv:1707.06347.
Example
// Create a PPO agent for stable policy optimization
var options = new PPOOptions<double> { StateSize = 4, ActionSize = 2, ClipEpsilon = 0.2 };
var agent = new PPOAgent<double>(options);
// Select an action using the clipped policy
var state = new Vector<double>(new double[] { 0.5, -0.3, 1.0, 0.2 });
var action = agent.SelectAction(state);
Constructors
| Constructor | Summary |
|---|---|
PPOAgent() |
Initializes a new instance with default settings. |
PPOAgent(PPOOptions<T> options) |
Initializes a new instance of the PPOAgent 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) |
|
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) |
|
void StoreExperience(Vector<T> state, Vector<T> action, T reward, Vector<T> nextState, bool terminated, bool truncated) |