Changeset 3912
- Timestamp:
- 06/09/10 14:07:42 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/Evaluators/MultinormalEvaluator.cs
r3869 r3912 22 22 get { return (RealVector)Parameters["s^2s"].ActualValue; } 23 23 set { Parameters["s^2s"].ActualValue = value; } 24 } 24 } 25 private static Random Random = new Random(); 25 26 26 27 [StorableConstructor] 27 28 public MultinormalEvaluator(bool deserializing) { } 28 29 public MultinormalEvaluator() { 29 30 private Dictionary<int, List<RealVector>> stdCenters; 31 public IEnumerable<RealVector> Centers(int nDim) { 32 if (stdCenters == null) 33 stdCenters = new Dictionary<int, List<RealVector>>(); 34 if (!stdCenters.ContainsKey(nDim)) 35 stdCenters[nDim] = GetCenters(nDim).ToList(); 36 return stdCenters[nDim]; 37 } 38 39 private IEnumerable<RealVector> GetCenters(int nDim) { 40 RealVector r0 = new RealVector(nDim); 41 for (int i = 0; i < r0.Length; i++) 42 r0[i] = 5; 43 yield return r0; 44 for (int i = 1; i < 1 << nDim; i++) { 45 RealVector r = new RealVector(nDim); 46 for (int j = 0; j < nDim; j++) { 47 r[j] = (i >> j) % 2 == 0 ? Random.NextDouble() + 4.5 : Random.NextDouble() + 14.5; 48 } 49 yield return r; 50 } 51 } 52 53 private Dictionary<int, List<double>> stdSigma_2s; 54 public IEnumerable<double> Sigma_2s(int nDim) { 55 if (stdSigma_2s == null) 56 stdSigma_2s = new Dictionary<int, List<double>>(); 57 if (!stdSigma_2s.ContainsKey(nDim)) 58 stdSigma_2s[nDim] = GetSigma_2s(nDim).ToList(); 59 return stdSigma_2s[nDim]; 60 } 61 private IEnumerable<double> GetSigma_2s(int nDim) { 62 yield return 0.2; 63 for (int i = 1; i < (1 << nDim)-1; i++) { 64 yield return Random.NextDouble() * 0.5 + 0.75; 65 } 66 yield return 2; 67 } 68 69 public MultinormalEvaluator() { 30 70 Parameters.Add(new ValueParameter<ItemList<RealVector>>("Centers", "Centers of normal distributions")); 31 71 Parameters.Add(new ValueParameter<RealVector>("s^2s", "sigma^2 of normal distributions")); 32 centers = new ItemList<RealVector>() { 72 Parameters.Add(new LookupParameter<IRandom>("Random", "Random number generator")); 73 centers = new ItemList<RealVector>(); 74 s_2s = new RealVector(); 75 /* centers = new ItemList<RealVector>() { 33 76 new RealVector(new double[] { -5.0, -5.0 }), 34 new RealVector(new double[] { 5.0, -5.0 }), 77 new RealVector(new double[] { 5.0, -5.0 }), 35 78 new RealVector(new double[] { -5.0, 5.0 }), 36 79 new RealVector(new double[] { 5.0, 5.0 }), 37 80 }; 38 s_2s = new RealVector(new double[] { 0.2, 1, 1, 2 }); 81 s_2s = new RealVector(new double[] { 0.2, 1, 1, 2 }); 39 82 } 40 83 … … 65 108 66 109 public override DoubleMatrix Bounds { 67 get { return new DoubleMatrix(new double[,] { { -10, 10 } }); }110 get { return new DoubleMatrix(new double[,] { { 0, 20 } }); } 68 111 } 69 112 70 113 public override double BestKnownQuality { 71 114 get { 72 RealVector bestSolution; 73 return FastFindOptimum(out bestSolution); 115 if (centers.Count == 0) { 116 return - 1 / (2 * Math.PI * 0.2); 117 } else { 118 RealVector bestSolution; 119 return FastFindOptimum(out bestSolution); 120 } 74 121 } 75 122 } … … 77 124 public override int MinimumProblemSize { get { return 1; } } 78 125 79 public override int MaximumProblemSize { get { return 100 0; } }126 public override int MaximumProblemSize { get { return 100; } } 80 127 81 128 private RealVector Shorten(RealVector x, int dimensions) { 82 return new RealVector(x.Take(dimensions).ToArray()); 129 return new RealVector(x.Take(dimensions).ToArray()); 83 130 } 84 131 85 132 public override RealVector GetBestKnownSolution(int dimension) { 86 RealVector bestSolution; 87 FastFindOptimum(out bestSolution); 88 return Shorten(bestSolution, dimension); 133 if (centers.Count == 0) { 134 RealVector r = new RealVector(dimension); 135 for (int i = 0; i < r.Length; i++) 136 r[i] = 5; 137 return r; 138 } else { 139 RealVector bestSolution; 140 FastFindOptimum(out bestSolution); 141 return Shorten(bestSolution, dimension); 142 } 89 143 } 90 144 … … 95 149 protected override double EvaluateFunction(RealVector point) { 96 150 double value = 0; 97 for (int i = 0; i < centers.Count; i++) { 98 value -= N(point, Shorten(centers[i], point.Length), s_2s[i]); 151 if (centers.Count == 0) { 152 var c = Centers(point.Length).GetEnumerator(); 153 var s = Sigma_2s(point.Length).GetEnumerator(); 154 while (c.MoveNext() && s.MoveNext()) { 155 value -= N(point, c.Current, s.Current); 156 } 157 } else { 158 for (int i = 0; i < centers.Count; i++) { 159 value -= N(point, centers[i], s_2s[i]); 160 } 99 161 } 100 162 return value;
Note: See TracChangeset
for help on using the changeset viewer.