LSPIAgent<T>

Models & Types ยท AiDotNet.ReinforcementLearning.Agents.AdvancedRL

LSPI (Least-Squares Policy Iteration) agent using iterative policy improvement with LSTDQ.

Inheritance: ReinforcementLearningAgentBase<T> โ†’ LSPIAgent<T>

For Beginners

LSPI is a batch RL algorithm that makes the most efficient use of collected data. Instead of learning from one experience at a time, it collects a batch of experiences and uses linear algebra to find the best policy in one shot. Think of it like studying all past exam questions at once rather than one at a time. This makes it very sample-efficient but requires storing all experiences in memory.

Example

// Create an LSPI agent for batch policy iteration
var options = new LSPIOptions<double> { FeatureSize = 4, ActionSize = 2 };
var agent = new LSPIAgent<double>(options);
            
// Select an action using the current policy weights
var state = new Vector<double>(new double[] { 0.5, -0.3, 1.0, 0.2 });
var action = agent.SelectAction(state);

Constructors

Constructor Summary
LSPIAgent() Initializes a new instance with default settings.
LSPIAgent(LSPIOptions<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)