Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Problems.Bandits/Bandit.cs @ 13234

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

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

File size: 988 bytes
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6
7namespace HeuristicLab.Algorithms.Bandits {
8  public class Bandit : IBandit {
9    public int NumArms { get { return distributions.Length; } }
10    public int OptimalExpectedRewardArm { get; private set; }
11    public int OptimalMaximalRewardArm { get; private set; }
12
13    private readonly IModel[] distributions;
14    private readonly Random random;
15    public Bandit(Random random, IEnumerable<IModel> distributions, int bestExpRewardArm, int bestMaxRewardArm) {
16      this.random = random;
17      this.distributions = distributions.ToArray();
18
19      OptimalExpectedRewardArm = bestExpRewardArm;
20      OptimalMaximalRewardArm = bestMaxRewardArm;
21    }
22
23    // pulling an arm results in a bernoulli distributed reward
24    // with mean expReward[i]
25    public double Pull(int arm) {
26      return distributions[arm].Sample(random);
27    }
28  }
29}
Note: See TracBrowser for help on using the repository browser.