ThompsonSamplingAgent<T>

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

Thompson Sampling (Bayesian) Multi-Armed Bandit agent.

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

For Beginners

Thompson Sampling uses probability to decide which action to try. For each arm/action, it maintains a belief distribution (typically Beta distribution) about how good that action is. To choose an action, it draws a random sample from each distribution and picks the arm with the highest sample. Actions the agent is uncertain about naturally get explored more. This Bayesian approach often outperforms epsilon-greedy and UCB in practice and is widely used in A/B testing and recommendation systems.

Example

// Create a Thompson Sampling agent for Bayesian bandit problems
var options = new ThompsonSamplingOptions<double> { NumArms = 10 };
var agent = new ThompsonSamplingAgent<double>(options);
            
// Select an arm by sampling from posterior Beta distributions
var state = new Vector<double>(new double[] { 1.0 });
var action = agent.SelectAction(state);

Constructors

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