WatkinsQLambdaAgent<T>

Models & Types · AiDotNet.ReinforcementLearning.Agents.EligibilityTraces

Watkins’s Q(lambda) agent that combines Q-learning with eligibility traces but cuts traces when an exploratory (non-greedy) action is taken, ensuring convergence to the optimal policy.

Inheritance: ReinforcementLearningAgentBase<T> → WatkinsQLambdaAgent<T>

For Beginners

Regular Q(lambda) has a problem: it uses eligibility traces to propagate rewards backwards, but since Q-learning is off-policy (learns the optimal policy while exploring), the traces can cause incorrect updates when exploratory actions are taken.

Watkins’s Q(lambda) solves this by “cutting” the traces whenever the agent explores:

  • Greedy action taken: traces decay normally (lambda * gamma)
  • Exploratory action taken: ALL traces reset to zero

This means:

  • During greedy sequences, you get fast multi-step learning (like Q(lambda))
  • When exploring, you revert to safe 1-step Q-learning

Trade-off: More conservative than naive Q(lambda), but theoretically sound.

How It Works

Watkins’s Q(lambda) is a variant of Q(lambda) that resets eligibility traces to zero whenever the agent takes a non-greedy action. This ensures that only greedy actions contribute to the trace-based updates, maintaining the off-policy guarantee of Q-learning while still benefiting from multi-step credit assignment during greedy sequences.

Example

// Create a Watkins Q(lambda) agent that cuts traces on exploration
var options = new WatkinsQLambdaOptions<double> { Lambda = 0.9, LearningRate = 0.1, StateSize = 4, ActionSize = 2 };
var agent = new WatkinsQLambdaAgent<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
WatkinsQLambdaAgent() Initializes a new instance with default settings.
WatkinsQLambdaAgent(WatkinsQLambdaOptions<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)