Changeset 11730 for branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/Bandits/TruncatedNormalBandit.cs
- Timestamp:
- 01/02/15 16:08:21 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GrammaticalOptimization/HeuristicLab.Algorithms.Bandits/Bandits/TruncatedNormalBandit.cs
r11711 r11730 4 4 using System.Text; 5 5 using System.Threading.Tasks; 6 using HeuristicLab.Common; 6 7 7 8 namespace HeuristicLab.Algorithms.Bandits { 8 public class TruncatedNormalBandit {9 public class TruncatedNormalBandit : IBandit { 9 10 public int NumArms { get; private set; } 10 11 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 11 16 private readonly Random random; 12 17 private readonly double[] expReward; … … 18 23 OptimalExpectedReward = double.NegativeInfinity; 19 24 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 } 22 30 } 23 31 } … … 28 36 double x = 0; 29 37 do { 30 var z = Transform(random.NextDouble(), random.NextDouble());38 var z = Rand.RandNormal(random); 31 39 x = z * 0.1 + expReward[arm]; 32 40 } … … 34 42 return x; 35 43 } 36 37 // box muller transform38 private double Transform(double u1, double u2) {39 return Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2);40 }41 44 } 42 45 }
Note: See TracChangeset
for help on using the changeset viewer.