Changeset 12876 for branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Problems.Bandits/GaussianBandit.cs
- Timestamp:
- 08/17/15 19:13:19 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization-gkr/HeuristicLab.Problems.Bandits/GaussianBandit.cs
r11849 r12876 12 12 public int OptimalExpectedRewardArm { get; private set; } 13 13 public int OptimalMaximalRewardArm { get; private set; } 14 14 public double MaxReward { get; private set; } 15 public double MinReward { get; private set; } 15 16 private readonly Random random; 16 17 private readonly double[] exp; 17 18 private readonly double[] stdDev; 18 public GaussianBandit(Random random, int nArms) { 19 public GaussianBandit(Random random, int nArms, double minReward = double.NegativeInfinity, double maxReward = double.PositiveInfinity) { 20 this.MaxReward = maxReward; 21 this.MinReward = minReward; 19 22 this.random = random; 20 23 this.NumArms = nArms; … … 31 34 OptimalExpectedRewardArm = i; 32 35 } 33 var q = alglib.invnormaldistribution(0.99 ) * stdDev[i] + exp[i];36 var q = alglib.invnormaldistribution(0.999) * stdDev[i] + exp[i]; 34 37 if (q > bestQ) { 35 38 bestQ = q; … … 39 42 } 40 43 41 // pulling an arm results in a truncatednormally distributed reward42 // with mean expReward[i] and std.dev 0.144 // pulling an arm results in a normally distributed reward 45 // with mean expReward[i] and std.dev 43 46 public double Pull(int arm) { 44 var z = Rand.RandNormal(random); 45 var x = z * stdDev[arm] + exp[arm]; 47 double x; 48 do { 49 var z = Rand.RandNormal(random); 50 x = z * stdDev[arm] + exp[arm]; 51 } while (x <= MinReward || x > MaxReward); 46 52 return x; 47 53 }
Note: See TracChangeset
for help on using the changeset viewer.