Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5381


Ignore:
Timestamp:
01/26/11 18:39:49 (14 years ago)
Author:
abeham
Message:

#1395

  • Allowed to select the bounds checker to use in all RealVectorManipulator and RealVectorCrossover operators
  • Added a second bounds checker, the ReflectiveBoundsChecker which does not cut at the bounds, but mirrors the vector at the bounds
  • Use a repeating strategy in the move generators
  • Removed obsolete IRealVectorPSODecoder and IRealVectorPSOEncoder interfaces
  • Marked RealVectorToRealVectorEncoder as obsolete, internal and removed all meaningful code from it (it slipped into the release and should be thrown out as soon as possible)
  • Use a repeating strategy to stick within the bounds in the StdDevStrategyVectorManipulator when manipulating the mutation strengths
  • By default use smaller initial bounds in the StdDevStrategyVectorCreator (parameterized by the problem)
Location:
trunk/sources
Files:
1 added
2 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/BoundsChecker.cs

    r4722 r5381  
    3333  /// If not, the elements are corrected.
    3434  /// </summary>
    35   [Item("BoundsChecker", "Checks if all elements of a real vector are inside the bounds. If not, elements are corrected.")]
     35  [Item("BoundsChecker", "Checks if all elements of a real vector are inside the bounds. If not, elements are set to the respective values of the bounds.")]
    3636  [StorableClass]
    3737  public class BoundsChecker : SingleSuccessorOperator, IRealVectorBoundsChecker {
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/HeuristicLab.Encodings.RealVectorEncoding-3.3.csproj

    r5163 r5381  
    1212    <AssemblyName>HeuristicLab.Encodings.RealVectorEncoding-3.3</AssemblyName>
    1313    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    14     <TargetFrameworkProfile></TargetFrameworkProfile>
     14    <TargetFrameworkProfile>
     15    </TargetFrameworkProfile>
    1516    <FileAlignment>512</FileAlignment>
    1617    <SignAssembly>true</SignAssembly>
     
    157158    <Compile Include="Manipulators\PolynomialOnePositionManipulator.cs" />
    158159    <Compile Include="Manipulators\UniformOnePositionManipulator.cs" />
     160    <Compile Include="ReflectiveBoundsChecker.cs" />
    159161    <Compile Include="StrategyParameters\StdDevStrategyVectorCreator.cs" />
    160162    <Compile Include="StrategyParameters\StdDevStrategyVectorCrossover.cs" />
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Moves/AdditiveMoveGenerator.cs

    r4722 r5381  
    6565    public override IOperation Apply() {
    6666      RealVector vector = RealVectorParameter.ActualValue;
    67       AdditiveMove[] moves = GenerateMoves(RandomParameter.ActualValue, vector);
    6867      DoubleMatrix bounds = BoundsParameter.ActualValue;
    69       if (bounds != null) {
    70         for (int i = 0; i < moves.Length; i++) {
    71           AdditiveMove move = moves[i];
    72           if (vector[move.Dimension] + move.MoveDistance < bounds[move.Dimension % bounds.Rows, 0])
    73             vector[move.Dimension] = bounds[move.Dimension % bounds.Rows, 0];
    74           else if (vector[move.Dimension] + move.MoveDistance > bounds[move.Dimension % bounds.Rows, 1])
    75             vector[move.Dimension] = bounds[move.Dimension % bounds.Rows, 1];
    76         }
    77       }
     68      AdditiveMove[] moves = GenerateMoves(RandomParameter.ActualValue, vector, bounds);
    7869      Scope[] moveScopes = new Scope[moves.Length];
    7970      for (int i = 0; i < moveScopes.Length; i++) {
     
    8576    }
    8677
    87     protected abstract AdditiveMove[] GenerateMoves(IRandom random, RealVector realVector);
     78    protected abstract AdditiveMove[] GenerateMoves(IRandom random, RealVector realVector, DoubleMatrix bounds);
    8879  }
    8980}
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Moves/StochasticNormalMultiMoveGenerator.cs

    r4722 r5381  
    5252    }
    5353
    54     public static AdditiveMove[] Apply(IRandom random, RealVector realVector, double sigma, int sampleSize) {
     54    public static AdditiveMove[] Apply(IRandom random, RealVector vector, double sigma, int sampleSize, DoubleMatrix bounds) {
    5555      AdditiveMove[] moves = new AdditiveMove[sampleSize];
    5656      NormalDistributedRandom N = new NormalDistributedRandom(random, 0, sigma);
    5757      for (int i = 0; i < sampleSize; i++) {
    58         int index = random.Next(realVector.Length);
    59         moves[i] = new AdditiveMove(index, N.NextDouble());
     58        int index = random.Next(vector.Length);
     59        double strength = 0, min = bounds[index % bounds.Rows, 0], max = bounds[index % bounds.Rows, 1];
     60        do {
     61          strength = N.NextDouble();
     62        } while (vector[index] + strength < min || vector[index] + strength > max);
     63        moves[i] = new AdditiveMove(index, strength);
    6064      }
    6165      return moves;
    6266    }
    6367
    64     protected override AdditiveMove[] GenerateMoves(IRandom random, RealVector realVector) {
    65       return Apply(random, realVector, SigmaParameter.ActualValue.Value, SampleSizeParameter.ActualValue.Value);
     68    protected override AdditiveMove[] GenerateMoves(IRandom random, RealVector realVector, DoubleMatrix bounds) {
     69      return Apply(random, realVector, SigmaParameter.ActualValue.Value, SampleSizeParameter.ActualValue.Value, bounds);
    6670    }
    6771  }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Moves/StochasticPolynomialMultiMoveGenerator.cs

    r4722 r5381  
    6262    }
    6363
    64     public static AdditiveMove[] Apply(IRandom random, RealVector realVector, double contiguity, int sampleSize, double maxManipulation) {
     64    public static AdditiveMove[] Apply(IRandom random, RealVector vector, double contiguity, int sampleSize, double maxManipulation, DoubleMatrix bounds) {
    6565      AdditiveMove[] moves = new AdditiveMove[sampleSize];
    6666      for (int i = 0; i < sampleSize; i++) {
    67         int index = random.Next(realVector.Length);
    68         moves[i] = new AdditiveMove(index, PolynomialOnePositionManipulator.Apply(random, contiguity) * maxManipulation);
     67        int index = random.Next(vector.Length);
     68        double strength = 0, min = bounds[index % bounds.Rows, 0], max = bounds[index % bounds.Rows, 1];
     69        do {
     70          strength = PolynomialOnePositionManipulator.Apply(random, contiguity) * maxManipulation;
     71        } while (vector[index] + strength < min || vector[index] + strength > max);
     72        moves[i] = new AdditiveMove(index, strength);
    6973      }
    7074      return moves;
    7175    }
    7276
    73     protected override AdditiveMove[] GenerateMoves(IRandom random, RealVector realVector) {
    74       return Apply(random, realVector, ContiguityParameter.ActualValue.Value, SampleSizeParameter.ActualValue.Value, MaximumManipulationParameter.ActualValue.Value);
     77    protected override AdditiveMove[] GenerateMoves(IRandom random, RealVector realVector, DoubleMatrix bounds) {
     78      return Apply(random, realVector, ContiguityParameter.ActualValue.Value, SampleSizeParameter.ActualValue.Value, MaximumManipulationParameter.ActualValue.Value, bounds);
    7579    }
    7680  }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorCrossover.cs

    r4722 r5381  
    5151      get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    5252    }
     53    public OptionalValueParameter<IRealVectorBoundsChecker> BoundsCheckerParameter {
     54      get { return (OptionalValueParameter<IRealVectorBoundsChecker>)Parameters["BoundsChecker"]; }
     55    }
    5356
    5457    [StorableConstructor]
     
    6366      ChildParameter.ActualName = "RealVector";
    6467      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds of the real vector."));
     68      Parameters.Add(new OptionalValueParameter<IRealVectorBoundsChecker>("BoundsChecker", "The bounds checker that ensures that the values stay within the bounds.", new BoundsChecker()));
    6569    }
     70
     71    // BackwardsCompatibility3.3
     72    #region Backwards compatible code (remove with 3.4)
     73    [StorableHook(HookType.AfterDeserialization)]
     74    private void AfterDeserialization() {
     75      if (!Parameters.ContainsKey("BoundsChecker"))
     76        Parameters.Add(new OptionalValueParameter<IRealVectorBoundsChecker>("BoundsChecker", "The bounds checker that ensures that the values stay within the bounds.", new BoundsChecker()));
     77    }
     78    #endregion
    6679
    6780    public sealed override IOperation Apply() {
    6881      RealVector result = Cross(RandomParameter.ActualValue, ParentsParameter.ActualValue);
    69       DoubleMatrix bounds = BoundsParameter.ActualValue;
    70       if (bounds != null) BoundsChecker.Apply(result, bounds);
    71       ChildParameter.ActualValue = result;
    72       return base.Apply();
     82
     83      IRealVectorBoundsChecker checker = BoundsCheckerParameter.Value;
     84      IOperation successor = base.Apply();
     85      if (checker != null) {
     86        IOperation checkerOperation = ExecutionContext.CreateChildOperation(checker);
     87        if (successor == null) return checkerOperation;
     88        else return new OperationCollection(checkerOperation, successor);
     89      } else return successor;
    7390    }
    7491
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/RealVectorManipulator.cs

    r4722 r5381  
    4848      get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    4949    }
     50    public OptionalValueParameter<IRealVectorBoundsChecker> BoundsCheckerParameter {
     51      get { return (OptionalValueParameter<IRealVectorBoundsChecker>)Parameters["BoundsChecker"]; }
     52    }
    5053
    5154    [StorableConstructor]
     
    5760      Parameters.Add(new LookupParameter<RealVector>("RealVector", "The vector which should be manipulated."));
    5861      Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds of the real vector."));
     62      Parameters.Add(new OptionalValueParameter<IRealVectorBoundsChecker>("BoundsChecker", "The bounds checker that ensures that the values stay within the bounds.", new BoundsChecker()));
    5963    }
     64
     65    // BackwardsCompatibility3.3
     66    #region Backwards compatible code (remove with 3.4)
     67    [StorableHook(HookType.AfterDeserialization)]
     68    private void AfterDeserialization() {
     69      if (!Parameters.ContainsKey("BoundsChecker"))
     70        Parameters.Add(new OptionalValueParameter<IRealVectorBoundsChecker>("BoundsChecker", "The bounds checker that ensures that the values stay within the bounds.", new BoundsChecker()));
     71    }
     72    #endregion
    6073
    6174    public sealed override IOperation Apply() {
    6275      RealVector vector = RealVectorParameter.ActualValue;
    6376      Manipulate(RandomParameter.ActualValue, vector);
    64       DoubleMatrix bounds = BoundsParameter.ActualValue;
    65       if (bounds != null) BoundsChecker.Apply(vector, bounds);
    66       return base.Apply();
     77
     78      IRealVectorBoundsChecker checker = BoundsCheckerParameter.Value;
     79      IOperation successor = base.Apply();
     80      if (checker != null) {
     81        IOperation checkerOperation = ExecutionContext.CreateChildOperation(checker);
     82        if (successor == null) return checkerOperation;
     83        else return new OperationCollection(checkerOperation, successor);
     84      } else return successor;
    6785    }
    6886
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/StrategyParameters/StdDevStrategyVectorManipulator.cs

    r4722 r5381  
    8989      double generalMultiplier = Math.Exp(generalLearningRate * N.NextDouble());
    9090      for (int i = 0; i < vector.Length; i++) {
    91         vector[i] *= generalMultiplier * Math.Exp(learningRate * N.NextDouble());
     91        double change = vector[i] * generalMultiplier * Math.Exp(learningRate * N.NextDouble());
    9292        if (bounds != null) {
    9393          double min = bounds[i % bounds.Rows, 0], max = bounds[i % bounds.Rows, 1];
    94           if (vector[i] < min) vector[i] = min;
    95           if (vector[i] > max) vector[i] = max;
     94          if (min == max) vector[i] = min;
     95          else {
     96            while (change < min || change > max)
     97              change = vector[i] * generalMultiplier * Math.Exp(learningRate * N.NextDouble());
     98            vector[i] = change;
     99          }
    96100        }
    97101      }
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/HeuristicLab.Problems.TestFunctions-3.3.csproj

    r5163 r5381  
    1212    <AssemblyName>HeuristicLab.Problems.TestFunctions-3.3</AssemblyName>
    1313    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    14     <TargetFrameworkProfile></TargetFrameworkProfile>
     14    <TargetFrameworkProfile>
     15    </TargetFrameworkProfile>
    1516    <FileAlignment>512</FileAlignment>
    1617    <SignAssembly>true</SignAssembly>
     
    128129    <Compile Include="Evaluators\ZakharovEvaluator.cs" />
    129130    <Compile Include="HeuristicLabProblemsTestFunctionsPlugin.cs" />
    130     <Compile Include="Interfaces\IRealVectorPSODecoder.cs" />
    131131    <Compile Include="Interfaces\IBestSingleObjectiveTestFunctionSolutionAnalyzer.cs" />
    132132    <Compile Include="Interfaces\IRastriginMoveEvaluator.cs" />
    133     <Compile Include="Interfaces\IRealVectorPSOEncoder.cs" />
    134133    <Compile Include="Interfaces\ISingleObjectiveTestFunctionAdditiveMoveEvaluator.cs" />
    135134    <Compile Include="Interfaces\ISingleObjectiveTestFunctionMoveEvaluator.cs" />
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/RealVectorToRealVectorEncoder.cs

    r4722 r5381  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
    24 using HeuristicLab.Data;
    25 using HeuristicLab.Encodings.RealVectorEncoding;
    2625using HeuristicLab.Operators;
    27 using HeuristicLab.Parameters;
    2826using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2927
    3028namespace HeuristicLab.Problems.TestFunctions {
    31   public class RealVectorToRealVectorEncoder : SingleSuccessorOperator, IRealVectorPSOEncoder, IRealVectorOperator {
    32     #region Parameters
    33 
    34     public IParameter OriginalRealVectorParameter {
    35       get { return (IParameter)Parameters["OriginalRealVector"]; }
    36     }
    37 
    38     public IParameter RealVectorParameter {
    39       get { return (IParameter)Parameters["RealVector"]; }
    40     }
    41 
    42     public ILookupParameter<IntValue> LengthParameter {
    43       get { return (ILookupParameter<IntValue>)Parameters["Length"]; }
    44     }
    45 
    46     public IValueLookupParameter<DoubleMatrix> BoundsParameter {
    47       get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; }
    48     }
    49 
    50     protected ScopeParameter CurrentScopeParameter {
    51       get { return (ScopeParameter)Parameters["CurrentScope"]; }
    52     }
    53     #endregion
    54 
    55     public IScope CurrentScope {
    56       get { return CurrentScopeParameter.ActualValue; }
    57     }
     29  // BackwardsCompatibility3.3
     30  #region Backwards compatible code (remove with 3.4)
     31  [Obsolete("This operator should not be used anymore.")]
     32  internal class RealVectorToRealVectorEncoder : SingleSuccessorOperator {
    5833
    5934    [StorableConstructor]
     
    6237    public RealVectorToRealVectorEncoder()
    6338      : base() {
    64       Parameters.Add(new LookupParameter<RealVector>("OriginalRealVector", "The original real vector."));
    65       Parameters.Add(new LookupParameter<RealVector>("RealVector", "The resulting reference to the original real vector."));
    66       Parameters.Add(new LookupParameter<IntValue>("Length", "Vector length."));
    67       Parameters.Add(new ScopeParameter("CurrentScope", "The current scope bounds matrix should be cloned."));
    68       Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds in each dimension."));
    6939    }
    7040
     
    7444
    7545    public override IOperation Apply() {
    76       RealVectorParameter.ActualValue = OriginalRealVectorParameter.ActualValue;
    77       IItem value = (IItem)BoundsParameter.ActualValue.Clone();
    78       CurrentScope.Variables.Add(new Variable("ParticleBounds", BoundsParameter.Description, value == null ? null : (IItem)value.Clone()));
    7946      return base.Apply();
    8047    }
     
    8451    }
    8552  }
     53  #endregion
    8654}
  • trunk/sources/HeuristicLab.Problems.TestFunctions/3.3/SingleObjectiveTestFunctionProblem.cs

    r5287 r5381  
    403403        op.RealVectorParameter.ActualName = SolutionCreator.RealVectorParameter.ActualName;
    404404      }
    405       foreach (IRealVectorPSOEncoder op in Operators.OfType<IRealVectorPSOEncoder>()) {
    406         ((ILookupParameter)op.OriginalRealVectorParameter).ActualName = SolutionCreator.RealVectorParameter.ActualName;
    407         op.BoundsParameter.Value = (DoubleMatrix)BoundsParameter.Value.Clone();
    408         op.BoundsParameter.ActualName = "ParticleBounds";
    409       }
    410405    }
    411406    private void UpdateStrategyVectorBounds() {
    412407      DoubleMatrix strategyBounds = (DoubleMatrix)Bounds.Clone();
    413       for (int i = 0; i < strategyBounds.Rows; i++)
     408      for (int i = 0; i < strategyBounds.Rows; i++) {
    414409        if (strategyBounds[i, 0] < 0) strategyBounds[i, 0] = 0;
     410        strategyBounds[i, 1] = 0.1 * (Bounds[i, 1] - Bounds[i, 0]);
     411      }
    415412      strategyVectorCreator.BoundsParameter.Value = strategyBounds;
    416413    }
Note: See TracChangeset for help on using the changeset viewer.