IQLAgent<T>
Models & Types · AiDotNet.ReinforcementLearning.Agents.IQL
Implicit Q-Learning (IQL) agent for offline reinforcement learning.
Inheritance: ReinforcementLearningAgentBase<T> → DeepReinforcementLearningAgentBase<T> → IQLAgent<T>
Implements: IGeneratedParameterRegistrar<T>, IGradientComputable<T, Vector<T>, Vector<T>>
For Beginners
IQL is an offline RL algorithm that learns from fixed datasets. It uses a clever statistical technique (expectile regression) to avoid overestimating values of unseen actions.
Key features:
- Expectile Regression: Asymmetric loss that focuses on upper quantiles
- Three Networks: V(s), Q(s,a), and π(a|s)
- Simpler than CQL: No conservative penalties or Lagrangian multipliers
- Advantage-Weighted Regression: Extracts policy from Q and V functions
Think of expectiles like percentiles - focusing on “typically good” outcomes rather than “best possible” outcomes helps avoid overoptimism.
Advantages:
- Simpler hyperparameter tuning than CQL
- Often more stable
- Good for offline datasets with diverse quality
How It Works
IQL uses expectile regression to learn a value function that focuses on high-return trajectories, enabling effective offline policy learning without explicit conservative penalties like CQL.
Example
// Create an Implicit Q-Learning agent for offline RL
var options = new IQLOptions<double> { StateSize = 4, ActionSize = 2, Expectile = 0.7 };
var agent = new IQLAgent<double>(options);
// Select an action using advantage-weighted regression
var state = new Vector<double>(new double[] { 0.5, -0.3, 1.0, 0.2 });
var action = agent.SelectAction(state);
Constructors
| Constructor | Summary |
|---|---|
IQLAgent() |
Initializes a new instance with default settings. |
IQLAgent(IQLOptions<T> options) |
Properties
| Property | Summary |
|---|---|
int FeatureCount { get; } |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T> GetMetrics() |
|
ModelMetadata<T> GetModelMetadata() |
|
ModelOptions GetOptions() |
|
T Train() |
|
Task TrainAsync() |
|
Task<Vector<T>> PredictAsync(Vector<T> input) |
|
Vector<T> ComputeGradients(Vector<T> input, Vector<T> target, ILossFunction<T> lossFunction) |
|
Vector<T> Predict(Vector<T> input) |
|
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 LoadOfflineData(List<ValueTuple<Vector<T>, Vector<T>, T, Vector<T>, bool>> dataset) |
Load offline dataset into the replay buffer. |
void ResetEpisode() |
|
void SaveModel(string filepath) |
|
void StoreExperience(Vector<T> state, Vector<T> action, T reward, Vector<T> nextState, bool done) |