Changeset 9199
- Timestamp:
- 01/31/13 22:17:35 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CMAES/HeuristicLab.Algorithms.CMAEvolutionStrategy/3.3/CMAOperators/CMAMutator.cs
r9148 r9199 28 28 using HeuristicLab.Parameters; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Random;31 30 using System; 32 31 … … 114 113 RealVectorParameter.ActualValue = arx; 115 114 } 116 var nd = new NormalDistributedRandom(random, 0, 1); 115 alglib.hqrndstate state; 116 alglib.hqrndseed(random.Next(), random.Next(), out state); 117 117 118 118 for (int i = 0; i < lambda; i++) { 119 119 int tries = 0; 120 bool inRange; 120 121 if (initialIterations > iterations) { 121 122 for (int k = 0; k < arx[i].Length; k++) { 122 123 do { 123 tries++; 124 arx[i][k] = xmean[k] + sp.Sigma.Value * sp.D[k] * nd.NextDouble(); 125 } while ((bounds[k % bounds.Rows, 0] > arx[i][k] || arx[i][k] > bounds[k % bounds.Rows, 1]) && tries < maxTries); 124 arx[i][k] = xmean[k] + sp.Sigma.Value * sp.D[k] * alglib.hqrndnormal(state); 125 inRange = bounds[k % bounds.Rows, 0] <= arx[i][k] || arx[i][k] <= bounds[k % bounds.Rows, 1]; 126 if (!inRange) tries++; 127 } while (!inRange && tries < maxTries); 128 if (!inRange && maxTries > 1) { 129 if (bounds[k % bounds.Rows, 0] > arx[i][k]) arx[i][k] = bounds[k % bounds.Rows, 0]; 130 else if (bounds[k % bounds.Rows, 1] < arx[i][k]) arx[i][k] = bounds[i % bounds.Rows, 1]; 131 } 126 132 } 127 133 } else { 128 bool inRange;129 134 var B = sp.B; 130 tries = 0;131 135 do { 132 136 tries++; … … 134 138 var artmp = new double[arx[0].Length]; 135 139 for (int k = 0; k < arx[0].Length; ++k) { 136 artmp[k] = sp.D[k] * nd.NextDouble();140 artmp[k] = sp.D[k] * alglib.hqrndnormal(state); 137 141 } 138 142 … … 146 150 } 147 151 } while (!inRange && tries < maxTries); 152 if (!inRange && maxTries > 1) { 153 for (int k = 0; k < arx[0].Length; k++) { 154 if (bounds[k % bounds.Rows, 0] > arx[i][k]) arx[i][k] = bounds[k % bounds.Rows, 0]; 155 else if (bounds[k % bounds.Rows, 1] < arx[i][k]) arx[i][k] = bounds[i % bounds.Rows, 1]; 156 } 157 } 148 158 } 149 159 }
Note: See TracChangeset
for help on using the changeset viewer.