Changeset 11946
- Timestamp:
- 02/06/15 14:15:10 (10 years ago)
- Location:
- branches/ProgrammableProblem
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Encodings.BinaryVectorEncoding (added) merged: 11909
- Property svn:mergeinfo changed
-
branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Creators/RandomBinaryVectorCreator.cs
r11411 r11946 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 35 36 private const string TrueProbabilityParameterName = "TruePropability"; 36 37 37 private I FixedValueParameter<DoubleValue> TrueProbabilityParameter {38 get { return (I FixedValueParameter<DoubleValue>)Parameters[TrueProbabilityParameterName]; }38 private IValueLookupParameter<DoubleValue> TrueProbabilityParameter { 39 get { return (IValueLookupParameter<DoubleValue>)Parameters[TrueProbabilityParameterName]; } 39 40 } 40 41 41 public double TrueProbability {42 get { return TrueProbabilityParameter.Value .Value; }43 set { TrueProbabilityParameter.Value .Value= value; }42 public DoubleValue TrueProbability { 43 get { return TrueProbabilityParameter.Value; } 44 set { TrueProbabilityParameter.Value = value; } 44 45 } 45 46 46 47 [StorableConstructor] 47 48 private RandomBinaryVectorCreator(bool deserializing) : base(deserializing) { } 48 49 49 private RandomBinaryVectorCreator(RandomBinaryVectorCreator original, Cloner cloner) : base(original, cloner) { } 50 50 public override IDeepCloneable Clone(Cloner cloner) { return new RandomBinaryVectorCreator(this, cloner); } 51 52 51 public RandomBinaryVectorCreator() 53 52 : base() { 54 Parameters.Add(new FixedValueParameter<DoubleValue>(TrueProbabilityParameterName, "Probability of true value", new DoubleValue(0.5)));53 Parameters.Add(new ValueLookupParameter<DoubleValue>(TrueProbabilityParameterName, "Probability of true value", new DoubleValue(0.5))); 55 54 } 56 55 57 56 [StorableHook(HookType.AfterDeserialization)] 58 57 private void AfterDeserialization() { 58 // BackwardsCompatibility3.3 59 #region Backwards compatible code, remove with 3.4 60 var defaultValue = 0.5; 61 if (Parameters.ContainsKey(TrueProbabilityParameterName) && Parameters[TrueProbabilityParameterName] is IFixedValueParameter<DoubleValue>) { 62 defaultValue = ((IFixedValueParameter<DoubleValue>)Parameters[TrueProbabilityParameterName]).Value.Value; 63 Parameters.Remove(TrueProbabilityParameterName); 64 } 59 65 if (!Parameters.ContainsKey(TrueProbabilityParameterName)) 60 Parameters.Add(new FixedValueParameter<DoubleValue>(TrueProbabilityParameterName, "Probability of true value", new DoubleValue(0.5))); 66 Parameters.Add(new ValueLookupParameter<DoubleValue>(TrueProbabilityParameterName, "Probability of true value", new DoubleValue(defaultValue))); 67 #endregion 61 68 } 62 69 … … 74 81 //remove with HL 3.4 75 82 if (trueProbability.IsAlmost(0.5)) 76 result = new BinaryVector(length, random);83 result = new BinaryVector(length, random); 77 84 else { 78 85 var values = new bool[length]; … … 85 92 86 93 protected override BinaryVector Create(IRandom random, IntValue length) { 87 return Apply(random, length.Value, TrueProbability); 94 if (TrueProbabilityParameter.ActualValue == null) throw new InvalidOperationException("RandomBinaryVectorCreator: Parameter " + TrueProbabilityParameter.ActualName + " could not be found."); 95 return Apply(random, length.Value, TrueProbabilityParameter.ActualValue.Value); 88 96 } 89 97 } -
branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/NPointCrossover.cs
r11171 r11946 41 41 /// Number of crossover points. 42 42 /// </summary> 43 public ValueLookupParameter<IntValue> NParameter {44 get { return ( ValueLookupParameter<IntValue>)Parameters["N"]; }43 public IValueLookupParameter<IntValue> NParameter { 44 get { return (IValueLookupParameter<IntValue>)Parameters["N"]; } 45 45 } 46 46 … … 137 137 if (NParameter.ActualValue == null) throw new InvalidOperationException("NPointCrossover: Parameter " + NParameter.ActualName + " could not be found."); 138 138 139 return Apply(random, parents[0], parents[1], NParameter. Value);139 return Apply(random, parents[0], parents[1], NParameter.ActualValue); 140 140 } 141 141 } -
branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Manipulators/SomePositionsBitflipManipulator.cs
r11171 r11946 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 39 40 /// Mmutation probability for each position. 40 41 /// </summary> 41 public ValueLookupParameter<DoubleValue> MutationProbabilityParameter {42 get { return ( ValueLookupParameter<DoubleValue>)Parameters["MutationProbability"]; }42 public IValueLookupParameter<DoubleValue> MutationProbabilityParameter { 43 get { return (IValueLookupParameter<DoubleValue>)Parameters["MutationProbability"]; } 43 44 } 44 45 … … 78 79 /// <param name="realVector">The vector of binary values to manipulate.</param> 79 80 protected override void Manipulate(IRandom random, BinaryVector binaryVector) { 80 Apply(random, binaryVector, MutationProbabilityParameter.Value); 81 if (MutationProbabilityParameter.ActualValue == null) throw new InvalidOperationException("SomePositionsBitflipManipulator: Parameter " + MutationProbabilityParameter.ActualName + " could not be found."); 82 Apply(random, binaryVector, MutationProbabilityParameter.ActualValue); 81 83 } 82 84 } -
branches/ProgrammableProblem/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Moves/OneBitflipMove/StochasticOneBitflipMultiMoveGenerator.cs
r11171 r11946 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 30 31 [Item("StochasticOneBitflipMultiMoveGenerator", "Randomly samples n from all possible one bitflip moves from a given BinaryVector.")] 31 32 [StorableClass] 32 public class StochasticOneBitflipMultiMoveGenerator : OneBitflipMoveGenerator, I MultiMoveGenerator {33 public class StochasticOneBitflipMultiMoveGenerator : OneBitflipMoveGenerator, IStochasticOperator, IMultiMoveGenerator { 33 34 public ILookupParameter<IRandom> RandomParameter { 34 35 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } … … 66 67 protected override OneBitflipMove[] GenerateMoves(BinaryVector binaryVector) { 67 68 IRandom random = RandomParameter.ActualValue; 69 if (SampleSizeParameter.ActualValue == null) throw new InvalidOperationException("StochasticOneBitflipMultiMoveGenerator: Parameter " + SampleSizeParameter.ActualName + " could not be found."); 68 70 return Apply(binaryVector, random, SampleSizeParameter.ActualValue.Value); 69 71 } -
branches/ProgrammableProblem/HeuristicLab.Encodings.IntegerVectorEncoding
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding (added) merged: 11818
- Property svn:mergeinfo changed
-
branches/ProgrammableProblem/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Interfaces/IIntegerVectorStdDevStrategyParameterOperator.cs
r11394 r11946 23 23 24 24 namespace HeuristicLab.Encodings.IntegerVectorEncoding { 25 public interface IIntegerVectorStdDevStrategyParameterOperator : I Item{25 public interface IIntegerVectorStdDevStrategyParameterOperator : IOperator { 26 26 } 27 27 } -
branches/ProgrammableProblem/HeuristicLab.Encodings.PermutationEncoding
- Property svn:mergeinfo changed (with no actual effect on merging)
-
branches/ProgrammableProblem/HeuristicLab.Encodings.RealVectorEncoding
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Encodings.RealVectorEncoding (added) merged: 11794
- Property svn:mergeinfo changed
-
branches/ProgrammableProblem/HeuristicLab.Encodings.RealVectorEncoding/3.3/Creators/NormalDistributedRealVectorCreator.cs
r11171 r11946 88 88 /// </remarks> 89 89 /// <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> 92 92 /// <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> 93 93 /// <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> 94 94 /// <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"); 96 97 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"); 99 100 if (bounds == null || bounds.Rows == 0) bounds = new DoubleMatrix(new[,] { { double.MinValue, double.MaxValue } }); 101 var length = lengthValue.Value; 100 102 var nd = new NormalDistributedRandom(random, 0, 1); 101 var result = (RealVector)mean.Clone();103 var result = new RealVector(length); 102 104 for (int i = 0; i < result.Length; i++) { 103 105 var min = bounds[i % bounds.Rows, 0]; 104 106 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; 107 111 else { 108 112 int count = 0; 109 113 bool inRange; 110 114 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; 113 117 count++; 114 118 } while (count < maximumTries && !inRange); 115 119 if (count == maximumTries && !inRange) 116 result[i] = mean [i];120 result[i] = mean; 117 121 } 118 122 } … … 128 132 /// <returns>The newly created real vector.</returns> 129 133 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); 131 135 } 132 136 } -
branches/ProgrammableProblem/HeuristicLab.Optimization
- Property svn:mergeinfo changed (with no actual effect on merging)
Note: See TracChangeset
for help on using the changeset viewer.