Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Distributions/MixtureModel.cs @ 13820

Last change on this file since 13820 was 12893, checked in by gkronber, 9 years ago

#2283: experiments on grammatical optimization algorithms (maxreward instead of avg reward, ...)

File size: 1.2 KB
RevLine 
[12893]1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Diagnostics.Contracts;
5using System.Linq;
6using System.Text;
7using System.Threading.Tasks;
8using HeuristicLab.Common;
9
10namespace HeuristicLab.Algorithms.Bandits.Models {
11  // mixture of two models with mixture weights
12  public class MixtureModel : IModel {
13
14    private readonly IModel u;
15    private readonly IModel v;
16    private readonly double w;
17
18    // w is the weight for u (the weight for v is 1-w)
19    public MixtureModel(IModel u, IModel v, double w) {
20      Contract.Assert(w >= 0.0 && w <= 1.0);
21      this.u = u;
22      this.v = v;
23      this.w = w;
24    }
25
26    public double Sample(Random random) {
27      if (random.NextDouble() <= w) {
28        return u.Sample(random);
29      } else {
30        return v.Sample(random);
31      }
32    }
33
34    public void Update(double reward) {
35      throw new NotSupportedException();
36    }
37
38    public void Reset() {
39      throw new NotSupportedException();
40    }
41
42    public object Clone() {
43      return new MixtureModel(u, v, w);
44    }
45
46    public override string ToString() {
47      return string.Format("Mixture({0},{1},{2:F2})", u, v, w);
48    }
49  }
50}
Note: See TracBrowser for help on using the repository browser.