Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/08/13 16:05:14 (12 years ago)
Author:
abeham
Message:

#1961: Improved performance slightly (thx to mkommend)

File:
1 edited

Legend:

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

    r9297 r9303  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    2930using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3031using HeuristicLab.Random;
    31 using System;
    3232
    3333namespace HeuristicLab.Algorithms.CMAEvolutionStrategy {
     
    116116      var nd = new NormalDistributedRandom(random, 0, 1);
    117117
     118      var length = arx[0].Length;
     119
    118120      for (int i = 0; i < lambda; i++) {
    119121        int tries = 0;
    120122        bool inRange;
    121123        if (initialIterations > iterations) {
    122           for (int k = 0; k < arx[i].Length; k++) {
     124          for (int k = 0; k < length; k++) {
    123125            do {
    124126              arx[i][k] = xmean[k] + sp.Sigma * sp.D[k] * nd.NextDouble();
     
    136138            tries++;
    137139            inRange = true;
    138             var artmp = new double[arx[0].Length];
    139             for (int k = 0; k < arx[0].Length; ++k) {
     140            var artmp = new double[length];
     141            for (int k = 0; k < length; ++k) {
    140142              artmp[k] = sp.D[k] * nd.NextDouble();
    141143            }
    142144
    143             for (int k = 0; k < arx[0].Length; k++) {
     145            for (int k = 0; k < length; k++) {
    144146              var sum = 0.0;
    145               for (int j = 0; j < arx[0].Length; j++)
     147              for (int j = 0; j < length; j++)
    146148                sum += B[k, j] * artmp[j];
    147149              arx[i][k] = xmean[k] + sp.Sigma * sum; // m + sig * Normal(0,C)
     
    151153          } while (!inRange && tries < maxTries);
    152154          if (!inRange && maxTries > 1) {
    153             for (int k = 0; k < arx[0].Length; k++) {
     155            for (int k = 0; k < length; k++) {
    154156              if (bounds[k % bounds.Rows, 0] > arx[i][k]) arx[i][k] = bounds[k % bounds.Rows, 0];
    155157              else if (bounds[k % bounds.Rows, 1] < arx[i][k]) arx[i][k] = bounds[k % bounds.Rows, 1];
Note: See TracChangeset for help on using the changeset viewer.