Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9199


Ignore:
Timestamp:
01/31/13 22:17:35 (12 years ago)
Author:
abeham
Message:

#1961:

  • Switched to ALGLIB's high quality normal distributed random number generator
  • Added automatic restriction to bounds after mutation in case MaxTries > 1 and no valid solution could be obtained
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/CMAES/HeuristicLab.Algorithms.CMAEvolutionStrategy/3.3/CMAOperators/CMAMutator.cs

    r9148 r9199  
    2828using HeuristicLab.Parameters;
    2929using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    30 using HeuristicLab.Random;
    3130using System;
    3231
     
    114113        RealVectorParameter.ActualValue = arx;
    115114      }
    116       var nd = new NormalDistributedRandom(random, 0, 1);
     115      alglib.hqrndstate state;
     116      alglib.hqrndseed(random.Next(), random.Next(), out state);
    117117
    118118      for (int i = 0; i < lambda; i++) {
    119119        int tries = 0;
     120        bool inRange;
    120121        if (initialIterations > iterations) {
    121122          for (int k = 0; k < arx[i].Length; k++) {
    122123            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            }
    126132          }
    127133        } else {
    128           bool inRange;
    129134          var B = sp.B;
    130           tries = 0;
    131135          do {
    132136            tries++;
     
    134138            var artmp = new double[arx[0].Length];
    135139            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);
    137141            }
    138142
     
    146150            }
    147151          } 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          }
    148158        }
    149159      }
Note: See TracChangeset for help on using the changeset viewer.