- Timestamp:
- 11/27/14 11:23:37 (10 years ago)
- Location:
- branches/Breadcrumbs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Breadcrumbs
- Property svn:ignore
-
old new 8 8 FxCopResults.txt 9 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll 10 11 HeuristicLab 3.3.5.1.ReSharper.user 11 12 HeuristicLab 3.3.6.0.ReSharper.user 12 13 HeuristicLab.4.5.resharper.user 13 14 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development 14 16 HeuristicLab.resharper.user 15 17 ProtoGen.exe … … 17 19 _ReSharper.HeuristicLab 18 20 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests 19 22 _ReSharper.HeuristicLab.ExtLibs 20 23 bin 21 24 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests23 Google.ProtocolBuffers-2.4.1.473.dll
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/Breadcrumbs/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Creators/RandomBinaryVectorCreator.cs
r9456 r11594 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 23 23 using HeuristicLab.Core; 24 24 using HeuristicLab.Data; 25 using HeuristicLab.Parameters; 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 27 … … 32 33 [StorableClass] 33 34 public sealed class RandomBinaryVectorCreator : BinaryVectorCreator { 35 private const string TrueProbabilityParameterName = "TruePropability"; 36 37 private IFixedValueParameter<DoubleValue> TrueProbabilityParameter { 38 get { return (IFixedValueParameter<DoubleValue>)Parameters[TrueProbabilityParameterName]; } 39 } 40 41 public double TrueProbability { 42 get { return TrueProbabilityParameter.Value.Value; } 43 set { TrueProbabilityParameter.Value.Value = value; } 44 } 45 34 46 [StorableConstructor] 35 47 private RandomBinaryVectorCreator(bool deserializing) : base(deserializing) { } 48 36 49 private RandomBinaryVectorCreator(RandomBinaryVectorCreator original, Cloner cloner) : base(original, cloner) { } 37 public RandomBinaryVectorCreator() : base() {}50 public override IDeepCloneable Clone(Cloner cloner) { return new RandomBinaryVectorCreator(this, cloner); } 38 51 39 public override IDeepCloneable Clone(Cloner cloner) { 40 return new RandomBinaryVectorCreator(this, cloner); 52 public RandomBinaryVectorCreator() 53 : base() { 54 Parameters.Add(new FixedValueParameter<DoubleValue>(TrueProbabilityParameterName, "Probability of true value", new DoubleValue(0.5))); 55 } 56 57 [StorableHook(HookType.AfterDeserialization)] 58 private void AfterDeserialization() { 59 if (!Parameters.ContainsKey(TrueProbabilityParameterName)) 60 Parameters.Add(new FixedValueParameter<DoubleValue>(TrueProbabilityParameterName, "Probability of true value", new DoubleValue(0.5))); 41 61 } 42 62 … … 46 66 /// <param name="random">The random number generator.</param> 47 67 /// <param name="length">The length of the binary vector.</param> 68 /// <param name="trueProbability">The propability for true to occur at a certain position in the binary vector</param> 48 69 /// <returns>The newly created binary vector.</returns> 49 public static BinaryVector Apply(IRandom random, int length) { 50 BinaryVector result = new BinaryVector(length, random); 70 public static BinaryVector Apply(IRandom random, int length, double trueProbability = 0.5) { 71 BinaryVector result; 72 73 //Backwards compatiblity code to ensure the same behavior for existing algorithm runs 74 //remove with HL 3.4 75 if (trueProbability.IsAlmost(0.5)) 76 result = new BinaryVector(length, random); 77 else { 78 var values = new bool[length]; 79 for (int i = 0; i < length; i++) 80 values[i] = random.NextDouble() < trueProbability; 81 result = new BinaryVector(values); 82 } 51 83 return result; 52 84 } 53 85 54 86 protected override BinaryVector Create(IRandom random, IntValue length) { 55 return Apply(random, length.Value );87 return Apply(random, length.Value, TrueProbability); 56 88 } 57 89 }
Note: See TracChangeset
for help on using the changeset viewer.