Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2969


Ignore:
Timestamp:
03/08/10 15:30:26 (14 years ago)
Author:
abeham
Message:

Updated operators for real vector encoding #890

Location:
trunk/sources/HeuristicLab.Encodings.RealVector/3.3
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Crossovers/HeuristicCrossover.cs

    r2964 r2969  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
     25using HeuristicLab.Parameters;
    2726using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using HeuristicLab.Parameters;
    2927
    3028namespace HeuristicLab.Encodings.RealVector {
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Crossovers/LocalCrossover.cs

    r2964 r2969  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Crossovers/RandomConvexCrossover.cs

    r2964 r2969  
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Crossovers/SelfAdaptiveDiscreteCrossover.cs

    r2900 r2969  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
     25using HeuristicLab.Parameters;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2727
    2828namespace HeuristicLab.Encodings.RealVector {
    2929  /// <summary>
    30   /// Discrete crossover for real vectors: creates a new offspring by combining the alleles in the parents such that each allele is
    31   /// randomly selected from one parent. It will also use the same strategy to combine the endogenous
    32   /// strategy parameter vector.
     30  /// The self adaptive discrete crossover is similar to the <see cref="DiscreteCrossover"/>, but will also copy values from an exising strategy vector (such as in the sigma self adaptive evolution strategy)
     31  /// from the same parent to the offspring in each position. The strategy vector can be of different length to the parent vector. The idea is that if it is shorter, it will be cycled.
    3332  /// </summary>
    34   public class SelfAdaptiveDiscreteCrossover : RealVectorCrossoverBase {
    35     /// <inheritdoc select="summary"/>
    36     public override string Description {
    37       get {
    38         return @"Discrete crossover for real vectors: creates a new offspring by combining the alleles in the parents such that each allele is randomly selected from one parent. It will also use the same strategy to combine the endogenous strategy parameter vector.";
    39       }
     33  /// <remarks>
     34  /// This operator is not mentioned in the literature, as typically intermediate recombination (<see cref="AverageCrossover"/>) should be used to recombine the strategy vector (Beyer and Schwefel 2002).
     35  /// Since <see cref="AverageCrossover"/> is deterministic this can be done for solution vector and strategy vector separately.<br/>
     36  /// However if one wishes to use discrete (dominant) recombination on the strategy vectors the idea is probably that the same parent should donate strategy value and solution value in a position. In this case use this operator.
     37  /// Otherwise, you can also apply <see cref="DiscreteCrossover"/> independently on the solution vector and on the strategy vector.
     38  /// </remarks>
     39  public class SelfAdaptiveDiscreteCrossover : RealVectorCrossover {
     40    /// <summary>
     41    /// Parameter for the parents' strategy vectors.
     42    /// </summary>
     43    public SubScopesLookupParameter<DoubleArrayData> ParentsStrategyVectorParameter {
     44      get { return (SubScopesLookupParameter<DoubleArrayData>)Parameters["ParentsStrategyVector"]; }
     45    }
     46    /// <summary>
     47    /// Parameter for the child's strategy vector.
     48    /// </summary>
     49    public LookupParameter<DoubleArrayData> ChildStrategyVectorParameter {
     50      get { return (LookupParameter<DoubleArrayData>)Parameters["ChildStrategyVector"]; }
     51    }
     52    /// <summary>
     53    /// Initializes a new instance of <see cref="SelfAdaptiveDiscreteCrossover"/> with two parameters (<c>ParentsStrategyVector</c>, and <c>ChildStrategyVector</c>).
     54    /// </summary>
     55    public SelfAdaptiveDiscreteCrossover()
     56      : base() {
     57      Parameters.Add(new SubScopesLookupParameter<DoubleArrayData>("ParentsStrategyVector", "The vector containing the parents' endogenous strategy parameters."));
     58      ParentsStrategyVectorParameter.ActualName = "StrategyVector";
     59      Parameters.Add(new LookupParameter<DoubleArrayData>("ChildStrategyVector", "The vector containing the child's endogenous strategy parameters."));
     60      ChildStrategyVectorParameter.ActualName = "StrategyVector";
    4061    }
    4162
    4263    /// <summary>
    43     /// Initializes a new instance of <see cref="SelfAdaptiveDiscreteCrossover"/> with one additional
    44     /// variable infos (<c>StrategyVector</c>).
     64    /// Performs a discrete crossover operation for multiple given parent vectors in a way that the same parent
     65    /// is used to donate the value of the solution and of the strategy vector in each position.
    4566    /// </summary>
    46     public SelfAdaptiveDiscreteCrossover()
    47       : base() {
    48       AddVariableInfo(new VariableInfo("StrategyVector", "Endogenous strategy parameter vector", typeof(DoubleArrayData), VariableKind.In | VariableKind.New));
    49     }
    50 
    51     /// <summary>
    52     /// Performs a discrete crossover operation for multiple given parent real vectors that combines the strategy vectors in the same way.
    53     /// </summary>
     67    /// <remarks>
     68    /// The parent vectors can be of a different length to the strategy vectors, but among each group the length has to be the same.
     69    /// </remarks>
    5470    /// <param name="random">A random number generator.</param>
    5571    /// <param name="parents">An array containing the parents that should be crossed.</param>
     
    5773    /// <param name="child">The newly created real vector, resulting from the crossover operation (output parameter).</param>
    5874    /// <param name="strategy">The newly created strategy vector, resulting from the crossover operation (output parameter).</param>
    59     public static void Apply(IRandom random, double[][] parents, double[][] strategies, out double[] child, out double[] strategy) {
    60       child = new double[parents[0].Length];
    61       strategy = new double[strategies[0].Length];
    62       for (int i = 0; i < child.Length; i++) {
    63         int nextParent = random.Next(parents.Length);
    64         child[i] = parents[nextParent][i];
    65         strategy[i] = strategies[nextParent][i];
     75    public static void Apply(IRandom random, ItemArray<DoubleArrayData> parents, ItemArray<DoubleArrayData> strategies, out DoubleArrayData child, out DoubleArrayData strategy) {
     76      if (strategies.Length != parents.Length) throw new ArgumentException("SelfAdaptiveDiscreteCrossover: Number of parents is not equal to the number of strategy vectors", "parents");
     77      int length = parents[0].Length, strategyLength = strategies[0].Length, parentsCount = parents.Length;
     78      child = new DoubleArrayData(length);
     79      strategy = new DoubleArrayData(strategyLength);
     80      int loopEnd = Math.Max(length, strategyLength);
     81      try {
     82        for (int i = 0; i < loopEnd; i++) {
     83          int nextParent = random.Next(parentsCount);
     84          if (i < length) child[i] = parents[nextParent][i];
     85          if (i < strategyLength) strategy[i] = strategies[nextParent][i];
     86        }
     87      } catch (IndexOutOfRangeException) {
     88        throw new ArgumentException("SelfAdaptiveDiscreteCrossover: There are different lengths among either the parent vectors or the parents' strategy vectors.");
    6689      }
    6790    }
    6891
    6992    /// <summary>
    70     /// Performs a discrete crossover operation for multiple given parent real vectors that combines the strategy vectors in the same way.
     93    /// Checks that there are at least two parents, that the strategy vector is not null and forwards the call to <see cref="Apply(IRandom, ItemArray<DoubleArrayData>, ItemArray<DoubleArrayData>, out DoubleArrayData, out DoubleArrayData)"/>.
    7194    /// </summary>
    72     /// <exception cref="InvalidOperationException">Thrown if there are less than two parents or if the length of the strategy vectors is not the same as the length of the real vectors.</exception>
    73     /// <param name="scope">The current scope.</param>
    74     /// <param name="random">A random number generator.</param>
    75     /// <param name="parents">An array containing the real vectors that should be crossed.</param>
    76     /// <returns>The newly created real vector, resulting from the crossover operation.</returns>
    77     protected override double[] Cross(IScope scope, IRandom random, double[][] parents) {
    78       if (parents.Length < 2) throw new InvalidOperationException("ERROR in SelfAdaptiveDiscreteCrossover: The number of parents is less than 2");
    79       double[][] strategies = new double[scope.SubScopes.Count][];
    80       int length = parents[0].Length;
    81       for (int i = 0; i < scope.SubScopes.Count; i++) {
    82         strategies[i] = scope.SubScopes[i].GetVariableValue<DoubleArrayData>("StrategyVector", false).Data;
    83         if (strategies[i].Length != length) throw new InvalidOperationException("ERROR in SelfAdaptiveDiscreteCrossover: Strategy vectors do not have the same length as the real vectors");
    84       }
    85 
    86       double[] child, strategy;
    87       Apply(random, parents, strategies, out child, out strategy);
    88       scope.AddVariable(new Variable(scope.TranslateName("StrategyVector"), new DoubleArrayData(strategy)));
    89       return child;
     95    /// <param name="random">The random number generator.</param>
     96    /// <param name="parents">The collection of parents (at least of size 2).</param>
     97    /// <returns>The child vector that results from the crossover.</returns>
     98    protected override DoubleArrayData Cross(IRandom random, ItemArray<DoubleArrayData> parents) {
     99      if (parents.Length < 2) throw new ArgumentException("SelfAdaptiveDiscreteCrossover: The number of parents is less than 2", "parents");
     100      if (ParentsStrategyVectorParameter.ActualValue == null) throw new InvalidOperationException("SelfAdaptiveDiscreteCrossover: Parameter " + ParentsStrategyVectorParameter.ActualName + " could not be found.");
     101      ItemArray<DoubleArrayData> strategies = ParentsStrategyVectorParameter.ActualValue;     
     102      DoubleArrayData result, resultStrategyVector;
     103      Apply(random, parents, strategies, out result, out resultStrategyVector);
     104      ChildStrategyVectorParameter.ActualValue = resultStrategyVector;
     105      return result;
    90106    }
    91107  }
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/HeuristicLab.Encodings.RealVector-3.3.csproj

    r2964 r2969  
    104104    <Compile Include="Crossovers\UniformSomePositionsArithmeticCrossover.cs" />
    105105    <Compile Include="HeuristicLabEncodingsRealVectorPlugin.cs" />
     106    <Compile Include="Manipulators\BreederGeneticAlgorithmManipulator.cs" />
    106107    <Compile Include="Manipulators\PolynomialAllPositionManipulator.cs" />
    107108    <Compile Include="Manipulators\MichalewiczNonUniformAllPositionsManipulator.cs">
     
    110111    <Compile Include="Manipulators\MichalewiczNonUniformOnePositionManipulator.cs" />
    111112    <Compile Include="Manipulators\PolynomialOnePositionManipulator.cs" />
     113    <Compile Include="Manipulators\SelfAdaptiveNormalAllPositionsManipulator.cs" />
    112114    <Compile Include="Manipulators\UniformOnePositionManipulator.cs" />
    113115    <None Include="HeuristicLab.snk" />
     
    151153      <Name>HeuristicLab.PluginInfrastructure</Name>
    152154    </ProjectReference>
     155    <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj">
     156      <Project>{F4539FB6-4708-40C9-BE64-0A1390AEA197}</Project>
     157      <Name>HeuristicLab.Random-3.3</Name>
     158    </ProjectReference>
    153159  </ItemGroup>
    154160  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Manipulators/BreederGeneticAlgorithmManipulator.cs

    r2900 r2969  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
     25using HeuristicLab.Parameters;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2727
    2828namespace HeuristicLab.Encodings.RealVector {
    2929  /// <summary>
    30   /// Mühlenbein, Schlierkamp-Voosen (1993)
    31   /// Predictive Models for the Breeder Genetic Algorithm I. Continuous Parameter Optimization<br/>
    32   /// Changes one position of a real vector by adding/substracting a value of the interval [(2^-15)*range, ..., (2^0)*range], where range is SearchIntervalFactor * (max - min).
     30  /// Changes one position of a real vector by adding/substracting a value of the interval [(2^-15)*range;~2*range], where range is SearchIntervalFactor * (max - min).
     31  /// Note that the interval is not uniformly sampled, but smaller values are sampled more often.
    3332  /// </summary>
    34   public class BreederGeneticAlgorithmManipulator : RealVectorManipulatorBase {
    35     /// <inheritdoc select="summary"/>
    36     public override string Description {
    37       get {
    38         return
    39 @"Breeder Genetic Algorithm Manipulator (Mühlenbein, Schlierkamp-Voosen, 1993). Changes one position of a real vector by adding/substracting a value of the interval [(2^-15)*range, ..., (2^0)*range], where range is SearchIntervalFactor * (max - min).
    40 
    41 Mühlenbein, Schlierkamp-Voosen (1993). Predictive Models for the Breeder Genetic Algorithm I. Continuous Parameter Optimization";
    42       }
     33  /// <remarks>
     34  /// It is implemented as described by Mühlenbein, H. and Schlierkamp-Voosen, D. 1993. Predictive Models for the Breeder Genetic Algorithm - I. Continuous Parameter Optimization. Evolutionary Computation, 1(1), pp. 25-49.<br/>
     35  /// </remarks>
     36  [Item("BreederGeneticAlgorithmManipulator", "It is implemented as described by Mühlenbein, H. and Schlierkamp-Voosen, D. 1993. Predictive Models for the Breeder Genetic Algorithm - I. Continuous Parameter Optimization. Evolutionary Computation, 1(1), pp. 25-49.")]
     37  public class BreederGeneticAlgorithmManipulator : RealVectorManipulator {
     38    private static readonly double[] powerOfTwo = new double[] { 1, 0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625, 0.0078125, 0.00390625, 0.001953125, 0.0009765625, 0.00048828125, 0.000244140625, 0.0001220703125, 0.00006103515625, 0.000030517578125 };
     39    public ValueLookupParameter<DoubleData> MinimumParameter {
     40      get { return (ValueLookupParameter<DoubleData>)Parameters["Minimum"]; }
    4341    }
    44 
     42    public ValueLookupParameter<DoubleData> MaximumParameter {
     43      get { return (ValueLookupParameter<DoubleData>)Parameters["Maximum"]; }
     44    }
     45    public ValueLookupParameter<DoubleData> SearchIntervalFactorParameter {
     46      get { return (ValueLookupParameter<DoubleData>)Parameters["SearchIntervalFactor"]; }
     47    }
    4548    /// <summary>
    4649    /// Initializes a new instance of <see cref="BreederGeneticAlgorithmManipulator"/> with three variable
     
    4952    public BreederGeneticAlgorithmManipulator()
    5053      : base() {
    51       AddVariableInfo(new VariableInfo("Minimum", "Minimum of the sampling range for the vector element (included)", typeof(DoubleData), VariableKind.In));
    52       AddVariableInfo(new VariableInfo("Maximum", "Maximum of the sampling range for the vector element (excluded)", typeof(DoubleData), VariableKind.In));
    53       VariableInfo sifInfo = new VariableInfo("SearchIntervalFactor", "The factor determining the size of the search interval, that will be added/removed to/from the allele selected for manipulation.", typeof(DoubleData), VariableKind.In);
    54       sifInfo.Local = true;
    55       AddVariableInfo(sifInfo);
    56       AddVariable(new Variable("SearchIntervalFactor", new DoubleData(0.1)));
     54      Parameters.Add(new ValueLookupParameter<DoubleData>("Minimum", "The lower bound for each element in the vector."));
     55      Parameters.Add(new ValueLookupParameter<DoubleData>("Maximum", "The upper bound for each element in the vector."));
     56      Parameters.Add(new ValueLookupParameter<DoubleData>("SearchIntervalFactor", "The factor determining the size of the search interval, that will be added/removed to/from the allele selected for manipulation.", new DoubleData(0.1)));
    5757    }
    5858
     
    6060    /// Performs a Breeder Genetic Algorithm Manipulation on the given <paramref name="vector"/>.
    6161    /// </summary>
    62     /// <param name="scope">The current scope.</param>
    6362    /// <param name="random">A random number generator.</param>
    6463    /// <param name="vector">The real vector to manipulate.</param>
     
    6665    /// <param name="max">The maximum number of the sampling range for the vector element (exclusive).</param>
    6766    /// <param name="searchIntervalFactor">The factor determining the size of the search interval.</param>
    68     /// <returns>The manipulated real vector.</returns>
    69     public static double[] Apply(IScope scope, IRandom random, double[] vector, double min, double max, double searchIntervalFactor) {
     67    public static void Apply(IRandom random, DoubleArrayData vector, DoubleData min, DoubleData max, DoubleData searchIntervalFactor) {
    7068      int length = vector.Length;
    71       int pos = random.Next(length);
    72       double range = searchIntervalFactor * (max - min);
    73       double value = range * Sigma(random);
     69      double prob, value;
     70      do {
     71        value = Sigma(random);
     72      } while (value == 0);
     73      value *= searchIntervalFactor.Value * (max.Value - min.Value);
    7474
    75       if (random.NextDouble() < 0.5) {
    76         vector[pos] = vector[pos] + value;
    77       } else {
    78         vector[pos] = vector[pos] - value;
     75      prob = 1.0 / (double)length;
     76      bool wasMutated = false;
     77
     78      for (int i = 0; i < length; i++) {
     79        if (random.NextDouble() < prob) {
     80          if (random.NextDouble() < 0.5) {
     81            vector[i] = vector[i] + value;
     82          } else {
     83            vector[i] = vector[i] - value;
     84          }
     85          wasMutated = true;
     86        }
    7987      }
    8088
    81       return vector;
     89      // make sure at least one gene was mutated
     90      if (!wasMutated) {
     91        int pos = random.Next(length);
     92        if (random.NextDouble() < 0.5) {
     93          vector[pos] = vector[pos] + value;
     94        } else {
     95          vector[pos] = vector[pos] - value;
     96        }
     97      }
    8298    }
    8399
     
    89105        if (random.Next(limit) == 15) {
    90106          // execute this statement with a probability of 1/16
    91           sigma += Math.Pow(2, -i);
     107          sigma += powerOfTwo[i];
    92108        }
    93109      }
     
    97113
    98114    /// <summary>
    99     /// Performs a Breeder Genetic Algorithm Manipulation on the given <paramref name="vector"/>.
     115    /// Checks the parameters Minimum, Maximum, and SearchIntervalFactor and forwards the call to <see cref="Apply(IRandom, DoubleArrayData, DoubleData, DoubleData, DoubleData)"/>.
    100116    /// </summary>
    101     /// <remarks>Calls <see cref="Apply"/>.</remarks>
    102     /// <param name="scope">The current scope.</param>
    103     /// <param name="random">The random number generator.</param>
    104     /// <param name="vector">The real vector to manipulate.</param>
    105     /// <returns>The manipulated real vector</returns>
    106     protected override double[] Manipulate(IScope scope, IRandom random, double[] vector) {
    107       double min = GetVariableValue<DoubleData>("Minimum", scope, true).Data;
    108       double max = GetVariableValue<DoubleData>("Maximum", scope, true).Data;
    109       double searchIntervalFactor = GetVariableValue<DoubleData>("SearchIntervalFactor", scope, true).Data;
    110       return Apply(scope, random, vector, min, max, searchIntervalFactor);
     117    /// <param name="random">A random number generator.</param>
     118    /// <param name="realVector">The real vector to manipulate.</param>
     119    protected override void Manipulate(IRandom random, DoubleArrayData realVector) {
     120      if (MinimumParameter.ActualValue == null) throw new InvalidOperationException("BreederGeneticAlgorithmManipulator: Parameter " + MinimumParameter.ActualName + " could not be found.");
     121      if (MaximumParameter.ActualValue == null) throw new InvalidOperationException("BreederGeneticAlgorithmManipulator: Paraemter " + MaximumParameter.ActualName + " could not be found.");
     122      if (SearchIntervalFactorParameter.ActualValue == null) throw new InvalidOperationException("BreederGeneticAlgorithmManipulator: Paraemter " + SearchIntervalFactorParameter.ActualName + " could not be found.");
     123      Apply(random, realVector, MinimumParameter.ActualValue, MaximumParameter.ActualValue, SearchIntervalFactorParameter.ActualValue);
    111124    }
    112125  }
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/Manipulators/SelfAdaptiveNormalAllPositionsManipulator.cs

    r2900 r2969  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
    24 using System.Text;
    2523using HeuristicLab.Core;
    2624using HeuristicLab.Data;
     25using HeuristicLab.Parameters;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2727using HeuristicLab.Random;
    2828
     
    3232  /// in the strategy parameter vector.
    3333  /// </summary>
    34   public class SelfAdaptiveNormalAllPositionsManipulator : RealVectorManipulatorBase {
    35     /// <inheritdoc select="summary"/>
    36     public override string Description {
    37       get { return @"Manipulates each dimension in the real vector with the mutation strength given in the strategy parameter vector"; }
     34  /// <remarks>
     35  /// It is implemented as described in Beyer, H.-G. and Schwefel, H.-P. 2002. Evolution Strategies - A Comprehensive Introduction Natural Computing, 1, pp. 3-52.<br/>
     36  /// The strategy vector can be of smaller length than the solution vector, in which case values are taken from the beginning again once the end of the strategy vector is reached.
     37  /// </remarks>
     38  [Item("SelfAdaptiveNormalAllPositionsManipulator", "This manipulation operator adds a value sigma_i * N(0,1) to the current value in each position i. The values for sigma_i are taken from the strategy vector. It is implemented as described in Beyer, H.-G. and Schwefel, H.-P. 2002. Evolution Strategies - A Comprehensive Introduction Natural Computing, 1, pp. 3-52.")]
     39  [EmptyStorableClass]
     40  public class SelfAdaptiveNormalAllPositionsManipulator : RealVectorManipulator {
     41    /// <summary>
     42    /// Parameter for the strategy vector.
     43    /// </summary>
     44    public LookupParameter<DoubleArrayData> StrategyVectorParameter {
     45      get { return (LookupParameter<DoubleArrayData>)Parameters["StrategyVector"]; }
     46    }
     47    /// <summary>
     48    /// Initializes a new instance of <see cref="SelfAdaptiveNormalAllPositionsManipulator"/> with one
     49    /// parameter (<c>StrategyVector</c>).
     50    /// </summary>
     51    public SelfAdaptiveNormalAllPositionsManipulator()
     52      : base() {
     53      Parameters.Add(new LookupParameter<DoubleArrayData>("StrategyVector", "The vector containing the endogenous strategy parameters."));
    3854    }
    3955
    4056    /// <summary>
    41     /// Initializes a new instance of <see cref="SelfAdaptiveNormalAllPositionsManipulator"/> with one
    42     /// variable info (<c>StrategyVector</c>).
    43     /// </summary>
    44     public SelfAdaptiveNormalAllPositionsManipulator()
    45       : base() {
    46       AddVariableInfo(new VariableInfo("StrategyVector", "The strategy vector determining the strength of the mutation", typeof(DoubleArrayData), VariableKind.In));
    47     }
    48 
    49     /// <summary>
    50     /// Performs a self adaptive normally distributed all position manipulation on the given
     57    /// Performs an adaptive normally distributed all position manipulation on the given
    5158    /// <paramref name="vector"/>.
    5259    /// </summary>
     
    5764    /// <param name="vector">The real vector to manipulate.</param>
    5865    /// <returns>The manipulated real vector.</returns>
    59     public static double[] Apply(double[] strategyParameters, IRandom random, double[] vector) {
     66    public static void Apply(IRandom random, DoubleArrayData vector, DoubleArrayData strategyParameters) {
    6067      NormalDistributedRandom N = new NormalDistributedRandom(random, 0.0, 1.0);
    6168      for (int i = 0; i < vector.Length; i++) {
    6269        vector[i] = vector[i] + (N.NextDouble() * strategyParameters[i % strategyParameters.Length]);
    6370      }
    64       return vector;
    6571    }
    6672
    6773    /// <summary>
    68     /// Performs a self adaptive normally distributed all position manipulation on the given
    69     /// <paramref name="vector"/>.
     74    /// Checks that the strategy vector is not null and forwards the call to <see cref="Apply(IRandom, DoubleArrayData, DoubleArrayData)"/>.
    7075    /// </summary>
    71     /// <remarks>Calls <see cref="Apply"/>.</remarks>
    72     /// <param name="scope">The current scope.</param>
    73     /// <param name="random">A random number generator.</param>
    74     /// <param name="vector">The real vector to manipulate.</param>
    75     /// <returns>The manipulated real vector.</returns>
    76     protected override double[] Manipulate(IScope scope, IRandom random, double[] vector) {
    77       double[] strategyVector = scope.GetVariableValue<DoubleArrayData>("StrategyVector", true).Data;
    78       return Apply(strategyVector, random, vector);
     76    /// <param name="random">The random number generator.</param>
     77    /// <param name="realVector">The vector of real values that is manipulated.</param>
     78    protected override void Manipulate(IRandom random, DoubleArrayData realVector) {
     79      if (StrategyVectorParameter.ActualValue == null) throw new InvalidOperationException("SelfAdaptiveNormalAllPositionsManipulator: Parameter " + StrategyVectorParameter.ActualName + " could not be found.");
     80      Apply(random, realVector, StrategyVectorParameter.ActualValue);
    7981    }
    8082  }
  • trunk/sources/HeuristicLab.Encodings.RealVector/3.3/RealVectorCreator.cs

    r2900 r2969  
    5555      Parameters.Add(new LookupParameter<DoubleArrayData>("RealVector", "The vector which should be manipulated."));
    5656      Parameters.Add(new ValueLookupParameter<IntData>("Length", "The length of the vector."));
     57      Parameters.Add(new ValueLookupParameter<DoubleData>("Minimum", "The lower bound for each element in the vector."));
     58      Parameters.Add(new ValueLookupParameter<DoubleData>("Maximum", "The upper bound for each element in the vector."));
    5759    }
    5860
Note: See TracChangeset for help on using the changeset viewer.