SACAgent<T>

Models & Types · AiDotNet.ReinforcementLearning.Agents.SAC

Soft Actor-Critic (SAC) agent for continuous control reinforcement learning.

Inheritance: ReinforcementLearningAgentBase<T> → DeepReinforcementLearningAgentBase<T> → SACAgent<T>

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

For Beginners

SAC is one of the best algorithms for continuous control (robot movement, etc.).

Key innovations:

  • Maximum Entropy: Learns to be both effective AND diverse
  • Twin Q-Networks: Two critics prevent overestimation
  • Automatic Tuning: Adjusts exploration automatically
  • Off-Policy: Very sample efficient

Think of it like learning to drive: you want to reach your destination (high reward) but also maintain flexibility in how you drive (high entropy). This makes the policy more robust and adaptable.

Used by: Boston Dynamics robots, autonomous vehicles, dexterous manipulation

How It Works

SAC is a state-of-the-art off-policy actor-critic algorithm that achieves high sample efficiency and robustness by incorporating maximum entropy reinforcement learning. It’s particularly effective for continuous control tasks.

Reference: Haarnoja et al., “Soft Actor-Critic: Off-Policy Maximum Entropy Deep RL with a Stochastic Actor”, 2018.

Example

// Create a Soft Actor-Critic agent for continuous control
var options = new SACOptions<double> { StateSize = 4, ActionSize = 2, AutoTuneTemperature = true };
var agent = new SACAgent<double>(options);
            
// Select a continuous action with entropy-driven exploration
var state = new Vector<double>(new double[] { 0.5, -0.3, 1.0, 0.2 });
var action = agent.SelectAction(state);

Constructors

Constructor Summary
SACAgent() Initializes a new instance with default settings.
SACAgent(SACOptions<T> options) Initializes a new instance of the SACAgent 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 Train(Vector<T> state, Vector<T> target)