Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/02/15 16:08:21 (9 years ago)
Author:
gkronber
Message:

#2283: several major extensions for grammatical optimization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/Bandits/TruncatedNormalBandit.cs

    r11711 r11730  
    44using System.Text;
    55using System.Threading.Tasks;
     6using HeuristicLab.Common;
    67
    78namespace HeuristicLab.Algorithms.Bandits {
    8   public class TruncatedNormalBandit {
     9  public class TruncatedNormalBandit : IBandit {
    910    public int NumArms { get; private set; }
    1011    public double OptimalExpectedReward { get; private set; } // reward of the best arm, for calculating regret
     12    public int OptimalExpectedRewardArm { get; private set; }
     13    // the arm with highest expected reward also has the highest probability of return a reward of 1.0
     14    public int OptimalMaximalRewardArm { get { return OptimalExpectedRewardArm; } }
     15
    1116    private readonly Random random;
    1217    private readonly double[] expReward;
     
    1823      OptimalExpectedReward = double.NegativeInfinity;
    1924      for (int i = 0; i < nArms; i++) {
    20         expReward[i] = random.NextDouble();
    21         if (expReward[i] > OptimalExpectedReward) OptimalExpectedReward = expReward[i];
     25        expReward[i] = random.NextDouble() * 0.7;
     26        if (expReward[i] > OptimalExpectedReward) {
     27          OptimalExpectedReward = expReward[i];
     28          OptimalExpectedRewardArm = i;
     29        }
    2230      }
    2331    }
     
    2836      double x = 0;
    2937      do {
    30         var z = Transform(random.NextDouble(), random.NextDouble());
     38        var z = Rand.RandNormal(random);
    3139        x = z * 0.1 + expReward[arm];
    3240      }
     
    3442      return x;
    3543    }
    36 
    37     // box muller transform
    38     private double Transform(double u1, double u2) {
    39       return Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2);
    40     }
    4144  }
    4245}
Note: See TracChangeset for help on using the changeset viewer.