using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.Contracts; using System.Linq; using System.Text; using System.Threading.Tasks; using HeuristicLab.Common; namespace HeuristicLab.Algorithms.Bandits.Models { // mixture of two models with mixture weights public class MixtureModel : IModel { private readonly IModel u; private readonly IModel v; private readonly double w; // w is the weight for u (the weight for v is 1-w) public MixtureModel(IModel u, IModel v, double w) { Contract.Assert(w >= 0.0 && w <= 1.0); this.u = u; this.v = v; this.w = w; } public double Sample(Random random) { if (random.NextDouble() <= w) { return u.Sample(random); } else { return v.Sample(random); } } public void Update(double reward) { throw new NotSupportedException(); } public void Reset() { throw new NotSupportedException(); } public object Clone() { return new MixtureModel(u, v, w); } public override string ToString() { return string.Format("Mixture({0},{1},{2:F2})", u, v, w); } } }