Changeset 5293
- Timestamp:
- 01/14/11 00:41:58 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization
- Files:
-
- 5 added
- 1 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs
r5281 r5293 33 33 private static int metaAlgorithmPopulationSize = 7; 34 34 private static int metaAlgorithmMaxGenerations = 20; 35 private static int metaProblemRepetitions = 3;35 private static int metaProblemRepetitions = 6; 36 36 private static int baseAlgorithmMaxGenerations = 50; 37 37 private static double mutationProbability = 0.35; … … 56 56 //TestExecutionTimeUpdateInvervalPerformance(); 57 57 //TestMemoryConsumption(); 58 //TestNormalCrossover(); 58 59 59 60 GeneticAlgorithm baseLevelAlgorithm = new GeneticAlgorithm(); … … 83 84 84 85 Console.ReadLine(); 86 } 87 88 private static void TestNormalCrossover() { 89 var random = new MersenneTwister(); 90 double d1 = 0.5; 91 double d2 = 0.6; 92 var doubleRange = new DoubleValueRange(new DoubleValue(0.0), new DoubleValue(1.0), new DoubleValue(0.01)); 93 94 using (var sw = new StreamWriter("normalCrossover-DoubleValue.txt")) { 95 for (int i = 0; i < 10000; i++) { 96 sw.WriteLine(NormalDoubleValueCrossover.ApplyStatic(random, new DoubleValue(d1), new DoubleValue(d2), doubleRange)); 97 } 98 } 99 100 int i1 = 180; 101 int i2 = 160; 102 var intRange = new IntValueRange(new IntValue(100), new IntValue(200), new IntValue(1)); 103 104 using (var sw = new StreamWriter("normalCrossover-IntValue.txt")) { 105 for (int i = 0; i < 10000; i++) { 106 sw.WriteLine(NormalIntValueCrossover.ApplyStatic(random, new IntValue(i1), new IntValue(i2), intRange)); 107 } 108 } 85 109 } 86 110 … … 510 534 ParameterConfigurationTree algorithmVc = metaOptimizationProblem.ParameterConfigurationTree; 511 535 512 metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() { 513 Evaluator = new GriewankEvaluator(), 514 ProblemSize = new IntValue(5) 515 }); 536 //metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() { 537 // Evaluator = new GriewankEvaluator(), 538 // ProblemSize = new IntValue(2) 539 //}); 540 //metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() { 541 // Evaluator = new GriewankEvaluator(), 542 // ProblemSize = new IntValue(20) 543 //}); 516 544 metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() { 517 545 Evaluator = new GriewankEvaluator(), 518 546 ProblemSize = new IntValue(50) 519 547 }); 520 metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {521 Evaluator = new GriewankEvaluator(),522 ProblemSize = new IntValue(500)523 });524 548 525 549 ConfigurePopulationSize(algorithmVc, 12, 100, 1); 526 ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.0 1);550 ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.0001); 527 551 ConfigureMutationOperator(algorithmVc); 528 //ConfigureElites(algorithmVc, 0, 10, 1);552 ConfigureElites(algorithmVc, 0, 10, 1); 529 553 //ConfigureSelectionOperator(algorithmVc, true); 530 554 return algorithmVc; … … 738 762 739 763 tb.AppendRow( 740 ((DoubleValue)run.Results["AverageQualityNormalized"]).Value.ToString("#0.00 "),764 ((DoubleValue)run.Results["AverageQualityNormalized"]).Value.ToString("#0.0000"), 741 765 ((DoubleArray)run.Results["RunsAverageQualities"]).ToString(), 742 766 ((IntValue)run.Parameters["PopulationSize"]).Value.ToString(), 743 ((DoubleValue)run.Parameters["MutationProbability"]).Value.ToString("0.00 "),767 ((DoubleValue)run.Parameters["MutationProbability"]).Value.ToString("0.0000"), 744 768 ((IntValue)run.Parameters["Elites"]).Value.ToString(), 745 769 Shorten(selector, 20), -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestParameterConfigurationAnalyzer.cs
r5281 r5293 39 39 get { return (LookupParameter<RunCollection>)Parameters["Population"]; } 40 40 } 41 public LookupParameter<DoubleArray> ProblemQuality MediansParameter {42 get { return (LookupParameter<DoubleArray>)Parameters["ProblemQuality Medians"]; }41 public LookupParameter<DoubleArray> ProblemQualityReferencesParameter { 42 get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityReferences"]; } 43 43 } 44 44 public LookupParameter<ConstrainedItemList<ISingleObjectiveProblem>> ProblemsParameter { … … 55 55 Parameters.Add(new LookupParameter<IRun>("BestKnownSolution", "")); 56 56 Parameters.Add(new LookupParameter<RunCollection>("Population", "")); 57 Parameters.Add(new LookupParameter<DoubleArray>("ProblemQuality Medians", ""));57 Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityReferences", "")); 58 58 Parameters.Add(new LookupParameter<ConstrainedItemList<ISingleObjectiveProblem>>(MetaOptimizationProblem.ProblemsParameterName)); 59 59 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/Crossovers/ParameterConfigurationCrossover.cs
r5277 r5293 38 38 } 39 39 40 /// <summary> 41 /// Whether the problem is a maximization or minimization problem. 42 /// </summary> 43 public ValueLookupParameter<BoolValue> MaximizationParameter { 44 get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 45 } 46 47 /// <summary> 48 /// The quality of the parents. 49 /// </summary> 50 public ScopeTreeLookupParameter<DoubleValue> QualityParameter { 51 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 52 } 53 40 54 [StorableConstructor] 41 55 protected ParameterConfigurationCrossover(bool deserializing) : base(deserializing) { } … … 46 60 Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("Parents", "The parent vectors which should be crossed.")); 47 61 Parameters.Add(new LookupParameter<ParameterConfigurationTree>("Child", "The child vector resulting from the crossover.")); 48 62 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "Whether the problem is a maximization problem or not.")); 63 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality values of the parents.")); 49 64 Parameters.Add(new ValueLookupParameter<IIntValueCrossover>(MetaOptimizationProblem.IntValueCrossoverParameterName, "")); 50 65 Parameters.Add(new ValueLookupParameter<IDoubleValueCrossover>(MetaOptimizationProblem.DoubleValueCrossoverParameterName, "")); … … 55 70 56 71 public override IOperation Apply() { 57 ParameterConfigurationTree child1 = (ParameterConfigurationTree)ParentsParameter.ActualValue[0].Clone(); 58 ParameterConfigurationTree child2 = (ParameterConfigurationTree)ParentsParameter.ActualValue[1]; 72 if (MaximizationParameter.ActualValue == null) throw new InvalidOperationException("HeuristicCrossover: Parameter " + MaximizationParameter.ActualName + " could not be found."); 73 if (QualityParameter.ActualValue == null || QualityParameter.ActualValue.Length != 2) throw new InvalidOperationException("ParameterConfigurationCrossover: Parameter " + QualityParameter.ActualName + " could not be found, or not in the same quantity as there are parents."); 74 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 75 bool maximization = MaximizationParameter.ActualValue.Value; 76 77 ParameterConfigurationTree child1; 78 ParameterConfigurationTree child2; 79 80 if (maximization && qualities[0].Value >= qualities[1].Value || !maximization && qualities[0].Value <= qualities[1].Value) { 81 child1 = (ParameterConfigurationTree)ParentsParameter.ActualValue[0].Clone(); 82 child2 = (ParameterConfigurationTree)ParentsParameter.ActualValue[1]; 83 } else { 84 child1 = (ParameterConfigurationTree)ParentsParameter.ActualValue[1].Clone(); 85 child2 = (ParameterConfigurationTree)ParentsParameter.ActualValue[0]; 86 } 59 87 60 88 child1.Cross(RandomParameter.ActualValue, child2, Cross, IntValueCrossoverParameter.ActualValue, DoubleValueCrossoverParameter.ActualValue); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/ParameterConfigurationEvaluator.cs
r5281 r5293 40 40 } 41 41 42 public LookupParameter<DoubleArray> ProblemQuality MediansParameter {43 get { return (LookupParameter<DoubleArray>)Parameters["ProblemQuality Medians"]; }42 public LookupParameter<DoubleArray> ProblemQualityReferencesParameter { 43 get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityReferences"]; } 44 44 } 45 45 … … 55 55 Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "Missing description.")); 56 56 Parameters.Add(new LookupParameter<IntValue>(MetaOptimizationProblem.RepetitionsParameterName, "Number of evaluations on one problem.")); 57 Parameters.Add(new LookupParameter<DoubleArray>("ProblemQuality Medians", ""));57 Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityReferences", "")); 58 58 } 59 59 … … 72 72 ParameterConfigurationTree parameterConfiguration = ParameterConfigurationParameter.ActualValue; 73 73 74 double[] medians;75 if (ProblemQuality MediansParameter.ActualValue == null) {74 double[] referenceQualities; 75 if (ProblemQualityReferencesParameter.ActualValue == null) { 76 76 // this is generation zero. no reference qualities for normalization have been calculated yet. 77 medians = new double[problems.Count];78 for (int i = 0; i < medians.Length; i++) {79 medians[i] = 1;77 referenceQualities = new double[problems.Count]; 78 for (int i = 0; i < referenceQualities.Length; i++) { 79 referenceQualities[i] = 1; 80 80 } 81 81 } else { 82 medians = ProblemQualityMediansParameter.ActualValue.ToArray();82 referenceQualities = ProblemQualityReferencesParameter.ActualValue.ToArray(); 83 83 } 84 84 … … 131 131 parameterConfiguration.Runs = (RunCollection)algorithm.Runs.Clone(); 132 132 133 this.QualityParameter.ActualValue = new DoubleValue(NormalizeQualities(parameterConfiguration, medians));133 this.QualityParameter.ActualValue = new DoubleValue(NormalizeQualities(parameterConfiguration, referenceQualities)); 134 134 135 135 return base.Apply(); 136 136 } 137 137 138 public static double NormalizeQualities(ParameterConfigurationTree parameterConfigurationTree, double[] medians) {139 double[] qualitiesNormalized = new double[ medians.Length];140 for (int i = 0; i < medians.Length; i++) {141 qualitiesNormalized[i] = parameterConfigurationTree.AverageQualities[i] / medians[i];138 public static double NormalizeQualities(ParameterConfigurationTree parameterConfigurationTree, double[] referenceQualities) { 139 double[] qualitiesNormalized = new double[referenceQualities.Length]; 140 for (int i = 0; i < referenceQualities.Length; i++) { 141 qualitiesNormalized[i] = parameterConfigurationTree.AverageQualities[i] / referenceQualities[i]; 142 142 } 143 143 parameterConfigurationTree.QualitiesNormalized = new DoubleArray(qualitiesNormalized); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj
r5281 r5293 117 117 <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Problems.TestFunctions-3.3.dll</HintPath> 118 118 </Reference> 119 <Reference Include="HeuristicLab.Random-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 120 <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Random-3.3.dll</HintPath> 121 </Reference> 119 122 <Reference Include="HeuristicLab.SequentialEngine-3.3"> 120 123 <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.SequentialEngine-3.3.dll</HintPath> … … 132 135 <None Include="Properties\AssemblyInfo.cs.frame" /> 133 136 <None Include="HeuristicLabProblemsMetaOptimizationPlugin.cs.frame" /> 134 <Compile Include="Analyzers\ MedianQualityAnalyzer.cs" />137 <Compile Include="Analyzers\ReferenceQualityAnalyzer.cs" /> 135 138 <Compile Include="ConstrainedItemList.cs" /> 136 139 <Compile Include="Encoding\NullValue.cs" /> … … 152 155 <Compile Include="Interfaces\ICheckedValueConfigurationCollection.cs" /> 153 156 <Compile Include="Operators\Crossovers\AverageDoubleValueCrossover.cs" /> 157 <Compile Include="Operators\Crossovers\AverageIntValueCrossover.cs" /> 158 <Compile Include="Operators\Crossovers\NormalIntValueCrossover.cs" /> 159 <Compile Include="Operators\Crossovers\NormalDoubleValueCrossover.cs" /> 154 160 <Compile Include="Operators\Crossovers\DiscreteDoubleValueCrossover.cs" /> 155 161 <Compile Include="Operators\Crossovers\DiscreteIntValueCrossover.cs" /> … … 173 179 <Compile Include="Operators\Interfaces\IIntValueCrossover.cs" /> 174 180 <Compile Include="Operators\Interfaces\IValueManipulator.cs" /> 181 <Compile Include="Operators\Manipulators\NormalIntValueManipulator.cs" /> 175 182 <Compile Include="Operators\Manipulators\UniformIntValueManipulator.cs" /> 176 183 <Compile Include="Operators\Manipulators\UniformDoubleValueManipulator.cs" /> -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
r5281 r5293 98 98 get { return Operators.OfType<BestParameterConfigurationAnalyzer>().FirstOrDefault(); } 99 99 } 100 private MedianQualityAnalyzer MedianQualityAnalyzer {101 get { return Operators.OfType< MedianQualityAnalyzer>().FirstOrDefault(); }100 private ReferenceQualityAnalyzer ReferenceQualityAnalyzer { 101 get { return Operators.OfType<ReferenceQualityAnalyzer>().FirstOrDefault(); } 102 102 } 103 103 #endregion … … 114 114 var validIntCrossovers = new ItemSet<IIntValueCrossover>(ApplicationManager.Manager.GetInstances<IIntValueCrossover>()); 115 115 var validDoubleCrossovers = new ItemSet<IDoubleValueCrossover>(ApplicationManager.Manager.GetInstances<IDoubleValueCrossover>()); 116 Parameters.Add(new ConstrainedValueParameter<IIntValueManipulator>(IntValueManipulatorParameterName, "", validIntManipulators, validIntManipulators. First()));117 Parameters.Add(new ConstrainedValueParameter<IDoubleValueManipulator>(DoubleValueManipulatorParameterName, "", validDoubleManipulators, validDoubleManipulators. First()));118 Parameters.Add(new ConstrainedValueParameter<IIntValueCrossover>(IntValueCrossoverParameterName, "", validIntCrossovers, validIntCrossovers. First()));119 Parameters.Add(new ConstrainedValueParameter<IDoubleValueCrossover>(DoubleValueCrossoverParameterName, "", validDoubleCrossovers, validDoubleCrossovers.Where(x => x.GetType() == typeof( AverageDoubleValueCrossover)).SingleOrDefault()));116 Parameters.Add(new ConstrainedValueParameter<IIntValueManipulator>(IntValueManipulatorParameterName, "", validIntManipulators, validIntManipulators.Where(x => x.GetType() == typeof(NormalIntValueManipulator)).SingleOrDefault())); 117 Parameters.Add(new ConstrainedValueParameter<IDoubleValueManipulator>(DoubleValueManipulatorParameterName, "", validDoubleManipulators, validDoubleManipulators.Where(x => x.GetType() == typeof(NormalDoubleValueManipulator)).SingleOrDefault())); 118 Parameters.Add(new ConstrainedValueParameter<IIntValueCrossover>(IntValueCrossoverParameterName, "", validIntCrossovers, validIntCrossovers.Where(x => x.GetType() == typeof(NormalIntValueCrossover)).SingleOrDefault())); 119 Parameters.Add(new ConstrainedValueParameter<IDoubleValueCrossover>(DoubleValueCrossoverParameterName, "", validDoubleCrossovers, validDoubleCrossovers.Where(x => x.GetType() == typeof(NormalDoubleValueCrossover)).SingleOrDefault())); 120 120 121 121 Maximization = new BoolValue(false); … … 161 161 Operators.AddRange(ApplicationManager.Manager.GetInstances<IParameterConfigurationOperator>().Cast<IOperator>()); 162 162 Operators.Add(new BestParameterConfigurationAnalyzer()); 163 Operators.Add(new MedianQualityAnalyzer());163 Operators.Add(new ReferenceQualityAnalyzer()); 164 164 } 165 165 private void ParameterizeSolutionCreator() { … … 172 172 BestParameterConfigurationAnalyzer.ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName; 173 173 } 174 if ( MedianQualityAnalyzer != null) {175 MedianQualityAnalyzer.ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;174 if (ReferenceQualityAnalyzer != null) { 175 ReferenceQualityAnalyzer.ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName; 176 176 } 177 177 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Manipulators/NormalDoubleValueManipulator.cs
r5207 r5293 37 37 public static void ApplyStatic(IRandom random, DoubleValue value, DoubleValueRange range) { 38 38 bool ok = false; 39 RealVector strategy = new RealVector(new double[] { (range.UpperBound.Value - range.LowerBound.Value) / 15});40 RealVector vector = new RealVector(1);39 var strategy = new RealVector(new double[] { (range.UpperBound.Value - range.LowerBound.Value) / 10}); // todo: add strategy parameter 40 var vector = new RealVector(1); 41 41 double val = value.Value; 42 42
Note: See TracChangeset
for help on using the changeset viewer.