Last change
on this file since 12940 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
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Diagnostics;
|
---|
4 | using System.Diagnostics.Contracts;
|
---|
5 | using System.Linq;
|
---|
6 | using System.Text;
|
---|
7 | using System.Threading.Tasks;
|
---|
8 | using HeuristicLab.Common;
|
---|
9 |
|
---|
10 | namespace 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.