Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11860


Ignore:
Timestamp:
02/02/15 15:11:45 (10 years ago)
Author:
ascheibe
Message:

#2296 merged r11794 into stable branch

Location:
stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Encodings.RealVectorEncoding/3.3/Creators/NormalDistributedRealVectorCreator.cs

    r11170 r11860  
    8888    /// </remarks>
    8989    /// <param name="random">The random number generator.</param>
    90     /// <param name="mean">The mean vector around which the resulting vector is sampled.</param>
    91     /// <param name="sigma">The vector of standard deviations, must have at least one row.</param>
     90    /// <param name="means">The mean vector around which the resulting vector is sampled.</param>
     91    /// <param name="sigmas">The vector of standard deviations, must have at least one row.</param>
    9292    /// <param name="bounds">The lower and upper bound (1st and 2nd column) of the positions in the vector. If there are less rows than dimensions, the rows are cycled.</param>
    9393    /// <param name="maximumTries">The maximum number of tries to sample a value inside the bounds for each dimension. If a valid value cannot be obtained, the mean will be used.</param>
    9494    /// <returns>The newly created real vector.</returns>
    95     public static RealVector Apply(IRandom random, RealVector mean, DoubleArray sigma, DoubleMatrix bounds, int maximumTries = 1000) {
     95    public static RealVector Apply(IntValue lengthValue, IRandom random, RealVector means, DoubleArray sigmas, DoubleMatrix bounds, int maximumTries = 1000) {
     96      if (lengthValue == null || lengthValue.Value == 0) throw new ArgumentException("Length is not defined or zero");
    9697      if (random == null) throw new ArgumentNullException("Random is not defined", "random");
    97       if (mean == null || mean.Length == 0) throw new ArgumentNullException("Mean is not defined", "mean");
    98       if (sigma == null || sigma.Length == 0) throw new ArgumentNullException("Sigma is not defined.", "sigma");
     98      if (means == null || means.Length == 0) throw new ArgumentNullException("Mean is not defined", "mean");
     99      if (sigmas == null || sigmas.Length == 0) throw new ArgumentNullException("Sigma is not defined.", "sigma");
    99100      if (bounds == null || bounds.Rows == 0) bounds = new DoubleMatrix(new[,] { { double.MinValue, double.MaxValue } });
     101      var length = lengthValue.Value;
    100102      var nd = new NormalDistributedRandom(random, 0, 1);
    101       var result = (RealVector)mean.Clone();
     103      var result = new RealVector(length);
    102104      for (int i = 0; i < result.Length; i++) {
    103105        var min = bounds[i % bounds.Rows, 0];
    104106        var max = bounds[i % bounds.Rows, 1];
    105         if (min.IsAlmost(max) || mean[i] < min) result[i] = min;
    106         else if (mean[i] > max) result[i] = max;
     107        var mean = means[i % means.Length];
     108        var sigma = sigmas[i % sigmas.Length];
     109        if (min.IsAlmost(max) || mean < min) result[i] = min;
     110        else if (mean > max) result[i] = max;
    107111        else {
    108112          int count = 0;
    109113          bool inRange;
    110114          do {
    111             result[i] = mean[i] + sigma[i % sigma.Length] * nd.NextDouble();
    112             inRange = result[i] >= bounds[i % bounds.Rows, 0] && result[i] < bounds[i % bounds.Rows, 1];
     115            result[i] = mean + sigma * nd.NextDouble();
     116            inRange = result[i] >= min && result[i] < max;
    113117            count++;
    114118          } while (count < maximumTries && !inRange);
    115119          if (count == maximumTries && !inRange)
    116             result[i] = mean[i];
     120            result[i] = mean;
    117121        }
    118122      }
     
    128132    /// <returns>The newly created real vector.</returns>
    129133    protected override RealVector Create(IRandom random, IntValue length, DoubleMatrix bounds) {
    130       return Apply(random, MeanParameter.ActualValue, SigmaParameter.ActualValue, bounds, MaximumTriesParameter.Value.Value);
     134      return Apply(length, random, MeanParameter.ActualValue, SigmaParameter.ActualValue, bounds, MaximumTriesParameter.Value.Value);
    131135    }
    132136  }
Note: See TracChangeset for help on using the changeset viewer.