- Timestamp:
- 05/01/11 22:02:28 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestParameterConfigurationAnalyzer.cs
r6018 r6090 98 98 } 99 99 100 // population 100 // population (TODO: extract into PopulationAnalyzer) 101 101 int i = 0; 102 102 RunCollection rc = new RunCollection(); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/ReferenceQualityAnalyzer.cs
r6018 r6090 41 41 } 42 42 43 public LookupParameter<DoubleValue> QualityWeightParameter { 44 get { return (LookupParameter<DoubleValue>)Parameters[MetaOptimizationProblem.QualityWeightParameterName]; } 45 } 46 public LookupParameter<DoubleValue> StandardDeviationWeightParameter { 47 get { return (LookupParameter<DoubleValue>)Parameters[MetaOptimizationProblem.StandardDeviationWeightParameterName]; } 48 } 49 public LookupParameter<DoubleValue> EvaluatedSolutionsWeightParameter { 50 get { return (LookupParameter<DoubleValue>)Parameters[MetaOptimizationProblem.EvaluatedSolutionsWeightParameterName]; } 51 } 52 43 53 public ReferenceQualityAnalyzer() 44 54 : base() { … … 49 59 Parameters.Add(new LookupParameter<DoubleArray>("ReferenceQualityDeviations", "")); 50 60 Parameters.Add(new LookupParameter<DoubleArray>("ReferenceEvaluatedSolutionAverages", "")); 51 Parameters.Add(new LookupParameter<ConstrainedItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName , ""));61 Parameters.Add(new LookupParameter<ConstrainedItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName)); 52 62 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.")); 63 Parameters.Add(new LookupParameter<DoubleValue>(MetaOptimizationProblem.QualityWeightParameterName)); 64 Parameters.Add(new LookupParameter<DoubleValue>(MetaOptimizationProblem.StandardDeviationWeightParameterName)); 65 Parameters.Add(new LookupParameter<DoubleValue>(MetaOptimizationProblem.EvaluatedSolutionsWeightParameterName)); 53 66 } 54 67 … … 65 78 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 66 79 bool maximization = MaximizationParameter.ActualValue.Value; 80 double qualityWeight = QualityWeightParameter.ActualValue.Value; 81 double standardDeviationWeight = StandardDeviationWeightParameter.ActualValue.Value; 82 double evaluatedSolutionsWeight = EvaluatedSolutionsWeightParameter.ActualValue.Value; 67 83 68 84 if (ReferenceQualityAveragesParameter.ActualValue == null) { … … 76 92 ReferenceEvaluatedSolutionAveragesParameter.ActualValue = referenceEvaluatedSolutionAverages; 77 93 78 NormalizePopulation(solutions, qualities, referenceQualityAverages, referenceQualityDeviations, referenceEvaluatedSolutionAverages, 1, 1, 1, maximization);94 NormalizePopulation(solutions, qualities, referenceQualityAverages, referenceQualityDeviations, referenceEvaluatedSolutionAverages, qualityWeight, standardDeviationWeight, evaluatedSolutionsWeight, maximization); 79 95 80 96 results.Add(new Result("ReferenceQualities", referenceQualityAverages)); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/SolutionCacheAnalyzer.cs
r6018 r6090 71 71 } 72 72 73 var runCollection = allRuns.Single(x => x.Key.Value == key).Value; 74 foreach (var run in solution.Runs) { 75 if (!((BoolValue)run.Results["Meta.FromCache"]).Value || first) { 76 run.Results["Meta.FromCache"] = new BoolValue(true); 77 runCollection.Add(run); 73 if (solution.Runs != null) { // Runs is null when a base-level algorithm exception happened due to invalid parameters 74 var runCollection = allRuns.Single(x => x.Key.Value == key).Value; 75 foreach (var run in solution.Runs) { 76 if (!((BoolValue)run.Results["Meta.FromCache"]).Value || first) { 77 run.Results["Meta.FromCache"] = new BoolValue(true); 78 runCollection.Add(run); 79 } 78 80 } 79 81 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/DoubleValueRange.cs
r5522 r6090 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Linq;4 using System.Text;3 using HeuristicLab.Common; 4 using HeuristicLab.Core; 5 5 using HeuristicLab.Data; 6 using HeuristicLab.Common;7 6 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 8 using HeuristicLab.Core;9 7 10 8 namespace HeuristicLab.Problems.MetaOptimization { … … 12 10 public class DoubleValueRange : Range<DoubleValue> { 13 11 12 public override DoubleValue LowerBound { 13 get { 14 return base.LowerBound; 15 } 16 set { 17 base.LowerBound = value; 18 } 19 } 20 14 21 public DoubleValueRange(DoubleValue lowerBound, DoubleValue upperBound, DoubleValue stepSize) : base(lowerBound, upperBound, stepSize) { } 15 22 public DoubleValueRange() { } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/Range.cs
r5576 r6090 12 12 [Storable] 13 13 private T lowerBound; 14 public T LowerBound {14 public virtual T LowerBound { 15 15 get { return lowerBound; } 16 16 set { … … 30 30 [Storable] 31 31 private T upperBound; 32 public T UpperBound {32 public virtual T UpperBound { 33 33 get { return upperBound; } 34 34 set { … … 48 48 [Storable] 49 49 private T stepSize; 50 public T StepSize {50 public virtual T StepSize { 51 51 get { return stepSize; } 52 52 set { … … 197 197 if (random.NextDouble() < 0.1) { 198 198 if (random.NextDouble() < 0.5) { 199 return LowerBound;199 return (T)LowerBound.Clone(); 200 200 } else { 201 return UpperBound;201 return (T)UpperBound.Clone(); 202 202 } 203 203 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/RangeValueConfiguration.cs
r5653 r6090 36 36 : base(value, valueDataType) { 37 37 if (actualValue.ValueDataType == typeof(IntValue)) { 38 RangeConstraint = new IntValueRange(new IntValue(0), (IntValue)value , new IntValue(1));38 RangeConstraint = new IntValueRange(new IntValue(0), (IntValue)value.Clone(), new IntValue(1)); 39 39 } else if (actualValue.ValueDataType == typeof(DoubleValue)) { 40 RangeConstraint = new DoubleValueRange(new DoubleValue(0), (DoubleValue)value , new DoubleValue(0.01));40 RangeConstraint = new DoubleValueRange(new DoubleValue(0), (DoubleValue)value.Clone(), new DoubleValue(0.01)); 41 41 } else if (actualValue.ValueDataType == typeof(PercentValue)) { 42 42 RangeConstraint = new PercentValueRange(new PercentValue(0), new PercentValue(1), new PercentValue(0.01)); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/AlgorithmEvaluator.cs
r6024 r6090 1 using System; 2 using System.Diagnostics; 3 using System.Linq; 1 using System.Linq; 4 2 using HeuristicLab.Common; 5 3 using HeuristicLab.Core; … … 10 8 using HeuristicLab.Parameters; 11 9 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 12 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;13 10 14 11 namespace HeuristicLab.Problems.MetaOptimization { … … 33 30 get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; } 34 31 } 35 public IValueParameter<IItemList<IRun>> RunsParameter { 36 get { return (IValueParameter<IItemList<IRun>>)Parameters["Runs"]; } 32 //public IValueParameter<IItemList<IRun>> RunsParameter { 33 // get { return (IValueParameter<IItemList<IRun>>)Parameters["Runs"]; } 34 //} 35 public LookupParameter<ResultCollection> ResultsParameter { 36 get { return (LookupParameter<ResultCollection>)Parameters["Results"]; } 37 37 } 38 38 #endregion … … 47 47 Parameters.Add(new LookupParameter<IntValue>("RepetitionIndex", "")); 48 48 Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "")); 49 Parameters.Add(new ValueParameter<IItemList<IRun>>("Runs", ""));49 Parameters.Add(new LookupParameter<ResultCollection>("Results", "")); 50 50 } 51 51 protected AlgorithmEvaluator(AlgorithmEvaluator original, Cloner cloner) : base(original, cloner) { } … … 55 55 56 56 public override IOperation Apply() { 57 ItemDictionary<StringValue, RunCollection> solutionCache = ResultsParameter.ActualValue.ContainsKey("SolutionCache") ? (ItemDictionary<StringValue, RunCollection>)ResultsParameter.ActualValue["SolutionCache"].Value : null; 58 ParameterConfigurationTree parameterConfiguration = ParameterConfigurationParameter.ActualValue; 57 59 IAlgorithm algorithm = AlgorithmParameter.ActualValue; 60 int repetitionIndex = RepetitionIndexParameter.ActualValue.Value; 58 61 59 #region Debug Code for SymbolicRegressionGrammar 60 var srp = (SymbolicRegressionSingleObjectiveProblem)algorithm.Problem; 61 //Console.WriteLine("Evaluating Grammar: " + PrintGrammar(srp.SymbolicExpressionTreeGrammar)); 62 #endregion 63 64 var sw = new Stopwatch(); 65 sw.Start(); 66 //// prepare and clear is needed, if the algorithm has been started and stopped before (this happens when meta level algorithm is paused) 67 //algorithm.Prepare(); // <--- SHOULD NOT HAPPEN! 68 //algorithm.Runs.Clear(); 69 70 algorithm.StartSync(CancellationToken); 71 sw.Stop(); 72 Console.WriteLine("{0},{1}: {2} (Grammar: {3})", ProblemIndexParameter.ActualValue.Value, RepetitionIndexParameter.ActualValue.Value, sw.Elapsed, PrintGrammar(srp.SymbolicExpressionTreeGrammar)); 73 74 RunsParameter.Value = new ItemList<IRun>(algorithm.Runs); 75 62 if (solutionCache != null && solutionCache.Count(x => x.Key.Value == parameterConfiguration.ParameterInfoString) > 0) { 63 algorithm.Runs.Add(solutionCache.Single(x => x.Key.Value == parameterConfiguration.ParameterInfoString).Value.ElementAt(repetitionIndex)); 64 } else { 65 algorithm.StartSync(CancellationToken); 66 } 76 67 return base.Apply(); 77 }78 79 /// <summary>80 /// This method should repair an invalid parameterConfiguration.81 /// The strategy is to just randomize parameter settings. It's not guaranteed to be a vaild setting82 /// </summary>83 private void Repair(ParameterConfigurationTree parameterConfiguration, IRandom random) {84 parameterConfiguration.Randomize(random);85 68 } 86 69 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/AlgorithmRunsAnalyzer.cs
r6038 r6090 54 54 public LookupParameter<BoolValue> MaximizationParameter { 55 55 get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; } 56 } 57 public LookupParameter<DoubleValue> QualityWeightParameter { 58 get { return (LookupParameter<DoubleValue>)Parameters[MetaOptimizationProblem.QualityWeightParameterName]; } 59 } 60 public LookupParameter<DoubleValue> StandardDeviationWeightParameter { 61 get { return (LookupParameter<DoubleValue>)Parameters[MetaOptimizationProblem.StandardDeviationWeightParameterName]; } 62 } 63 public LookupParameter<DoubleValue> EvaluatedSolutionsWeightParameter { 64 get { return (LookupParameter<DoubleValue>)Parameters[MetaOptimizationProblem.EvaluatedSolutionsWeightParameterName]; } 56 65 } 57 66 #endregion … … 75 84 Parameters.Add(new ScopeTreeLookupParameter<IntValue>("RepetitionIndex", "The index of the repetition")); 76 85 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.")); 86 Parameters.Add(new LookupParameter<DoubleValue>(MetaOptimizationProblem.QualityWeightParameterName)); 87 Parameters.Add(new LookupParameter<DoubleValue>(MetaOptimizationProblem.StandardDeviationWeightParameterName)); 88 Parameters.Add(new LookupParameter<DoubleValue>(MetaOptimizationProblem.EvaluatedSolutionsWeightParameterName)); 77 89 } 78 90 protected AlgorithmRunsAnalyzer(AlgorithmRunsAnalyzer original, Cloner cloner) … … 92 104 bool maximization = MaximizationParameter.ActualValue.Value; 93 105 int repetitions = RepetitionsParameter.ActualValue.Value; 106 double qualityWeight = QualityWeightParameter.ActualValue.Value; 107 double standardDeviationWeight = StandardDeviationWeightParameter.ActualValue.Value; 108 double evaluatedSolutionsWeight = EvaluatedSolutionsWeightParameter.ActualValue.Value; 94 109 var resultNames = new List<string> { "BestQuality", "Execution Time", "EvaluatedSolutions" }; 95 110 int currentGeneration = GenerationsParameter.ActualValue != null ? GenerationsParameter.ActualValue.Value : 0; … … 149 164 parameterConfiguration.Runs = runs; 150 165 151 this.QualityParameter.ActualValue = new DoubleValue(MetaOptimizationUtil.Normalize(parameterConfiguration, referenceQualityAverages, referenceQualityDeviations, referenceEvaluatedSolutionAverages, 1, 0.1, 1, maximization));166 this.QualityParameter.ActualValue = new DoubleValue(MetaOptimizationUtil.Normalize(parameterConfiguration, referenceQualityAverages, referenceQualityDeviations, referenceEvaluatedSolutionAverages, qualityWeight, standardDeviationWeight, evaluatedSolutionsWeight, maximization)); 152 167 } else { 153 168 // something terrible happened -> most probably due to invalid parameters. … … 155 170 double penaltyValue; 156 171 if (maximization) 157 penaltyValue = results.ContainsKey("CurrentWorstQuality") ? ((DoubleValue)results["CurrentWorstQuality"] ).Value : referenceQualityAverages.Min();172 penaltyValue = results.ContainsKey("CurrentWorstQuality") ? ((DoubleValue)results["CurrentWorstQuality"].Value).Value : referenceQualityAverages.Min(); 158 173 else 159 penaltyValue = results.ContainsKey("CurrentWorstQuality") ? ((DoubleValue)results["CurrentWorstQuality"]).Value : referenceQualityAverages.Max(); 174 penaltyValue = results.ContainsKey("CurrentWorstQuality") ? ((DoubleValue)results["CurrentWorstQuality"].Value).Value : referenceQualityAverages.Max(); 175 160 176 this.QualityParameter.ActualValue = new DoubleValue(penaltyValue); 177 parameterConfiguration.Quality = new DoubleValue(penaltyValue); 178 179 parameterConfiguration.AverageExecutionTimes = new ItemList<TimeSpanValue>(Enumerable.Repeat(new TimeSpanValue(TimeSpan.Zero), problems.Count)); 180 parameterConfiguration.AverageEvaluatedSolutions = new DoubleArray(Enumerable.Repeat(0.0, problems.Count).ToArray()); 181 parameterConfiguration.Repetitions = new IntValue(repetitions); 182 parameterConfiguration.AverageQualities = new DoubleArray(Enumerable.Repeat(0.0, problems.Count).ToArray()); 183 parameterConfiguration.BestQualities = new DoubleArray(Enumerable.Repeat(0.0, problems.Count).ToArray()); 184 parameterConfiguration.WorstQualities = new DoubleArray(Enumerable.Repeat(0.0, problems.Count).ToArray()); 185 parameterConfiguration.QualityVariances = new DoubleArray(Enumerable.Repeat(0.0, problems.Count).ToArray()); 186 parameterConfiguration.QualityStandardDeviations = new DoubleArray(Enumerable.Repeat(0.0, problems.Count).ToArray()); 187 parameterConfiguration.Runs = null; 161 188 } 162 189 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
r6017 r6090 51 51 public const string IntValueCrossoverParameterName = "IntValueCrossover"; 52 52 public const string DoubleValueCrossoverParameterName = "DoubleValueCrossover"; 53 public const string QualityWeightParameterName = "QualityWeight"; 54 public const string StandardDeviationWeightParameterName = "StandardDeviationWeight"; 55 public const string EvaluatedSolutionsWeightParameterName = "EvaluatedSolutionsWeight"; 56 53 57 54 58 #region Parameter Properties … … 134 138 var validIntCrossovers = new ItemSet<IIntValueCrossover>(ApplicationManager.Manager.GetInstances<IIntValueCrossover>()); 135 139 var validDoubleCrossovers = new ItemSet<IDoubleValueCrossover>(ApplicationManager.Manager.GetInstances<IDoubleValueCrossover>()); 136 Parameters.Add(new ConstrainedValueParameter<IIntValueManipulator>(IntValueManipulatorParameterName, "", validIntManipulators, validIntManipulators.Where(x => x.GetType() == typeof(NormalIntValueManipulator)).SingleOrDefault())); 137 Parameters.Add(new ConstrainedValueParameter<IDoubleValueManipulator>(DoubleValueManipulatorParameterName, "", validDoubleManipulators, validDoubleManipulators.Where(x => x.GetType() == typeof(NormalDoubleValueManipulator)).SingleOrDefault())); 138 Parameters.Add(new ConstrainedValueParameter<IIntValueCrossover>(IntValueCrossoverParameterName, "", validIntCrossovers, validIntCrossovers.Where(x => x.GetType() == typeof(NormalIntValueCrossover)).SingleOrDefault())); 139 Parameters.Add(new ConstrainedValueParameter<IDoubleValueCrossover>(DoubleValueCrossoverParameterName, "", validDoubleCrossovers, validDoubleCrossovers.Where(x => x.GetType() == typeof(NormalDoubleValueCrossover)).SingleOrDefault())); 140 Parameters.Add(new ConstrainedValueParameter<IIntValueManipulator>(IntValueManipulatorParameterName, validIntManipulators, validIntManipulators.Where(x => x.GetType() == typeof(NormalIntValueManipulator)).SingleOrDefault())); 141 Parameters.Add(new ConstrainedValueParameter<IDoubleValueManipulator>(DoubleValueManipulatorParameterName, validDoubleManipulators, validDoubleManipulators.Where(x => x.GetType() == typeof(NormalDoubleValueManipulator)).SingleOrDefault())); 142 Parameters.Add(new ConstrainedValueParameter<IIntValueCrossover>(IntValueCrossoverParameterName, validIntCrossovers, validIntCrossovers.Where(x => x.GetType() == typeof(NormalIntValueCrossover)).SingleOrDefault())); 143 Parameters.Add(new ConstrainedValueParameter<IDoubleValueCrossover>(DoubleValueCrossoverParameterName, validDoubleCrossovers, validDoubleCrossovers.Where(x => x.GetType() == typeof(NormalDoubleValueCrossover)).SingleOrDefault())); 144 145 Parameters.Add(new ValueParameter<DoubleValue>(QualityWeightParameterName, new DoubleValue(1))); 146 Parameters.Add(new ValueParameter<DoubleValue>(StandardDeviationWeightParameterName, new DoubleValue(0.01))); 147 Parameters.Add(new ValueParameter<DoubleValue>(EvaluatedSolutionsWeightParameterName, new DoubleValue(0.0005))); 140 148 141 149 Maximization = new BoolValue(false); … … 182 190 private void InitializeOperators() { 183 191 Operators.AddRange(ApplicationManager.Manager.GetInstances<IParameterConfigurationOperator>().Cast<IOperator>()); 192 Operators.Add(new ReferenceQualityAnalyzer()); 184 193 Operators.Add(new BestParameterConfigurationAnalyzer()); 185 Operators.Add(new ReferenceQualityAnalyzer());186 194 Operators.Add(new SolutionCacheAnalyzer()); 187 195 Operators.Add(new PMOPopulationDiversityAnalyzer()); -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationUtil.cs
r6018 r6090 57 57 parameterConfigurationTree.NormalizedEvaluatedSolutions = new DoubleArray(evaluatedSolutionAveragesNormalized); 58 58 59 double qualityAveragesNormalizedValue = qualityAveragesNormalized.Average() * qualityAveragesWeight;60 double qualityDeviationsNormalizedValue = qualityDeviationsNormalized.Average() * qualityDeviationsWeight;61 double evaluatedSolutionAveragesNormalizedValue = evaluatedSolutionAveragesNormalized.Average() * evaluatedSolutionsWeight;59 double qualityAveragesNormalizedValue = qualityAveragesNormalized.Average(); 60 double qualityDeviationsNormalizedValue = qualityDeviationsNormalized.Average(); 61 double evaluatedSolutionAveragesNormalizedValue = evaluatedSolutionAveragesNormalized.Average(); 62 62 63 // deviation and evaluatedSolutions are always minimization problems. so if maximization=true, flip the values around 1.0 (e.g. 1.15 -> 0.85) 63 64 if (maximization) { 64 // deviation and evaluatedSolutions are always minimization problems. so if maximization=true, flip the values around 1.0 (e.g. 1.15 -> 0.85)65 65 qualityDeviationsNormalizedValue -= (qualityDeviationsNormalizedValue - 1) * 2; 66 66 evaluatedSolutionAveragesNormalizedValue -= (evaluatedSolutionAveragesNormalizedValue - 1) * 2; 67 67 } 68 68 69 // apply weights 69 70 qualityAveragesNormalizedValue *= qualityAveragesWeight; 70 71 qualityDeviationsNormalizedValue *= qualityDeviationsWeight; 71 72 evaluatedSolutionAveragesNormalizedValue *= evaluatedSolutionsWeight; 72 73 73 parameterConfigurationTree.Quality = new DoubleValue(new double[] {qualityAveragesNormalizedValue, qualityDeviationsNormalizedValue, evaluatedSolutionAveragesNormalizedValue}.Average()); 74 74 double weightSum = qualityAveragesWeight + qualityDeviationsWeight + evaluatedSolutionsWeight; 75 parameterConfigurationTree.Quality = new DoubleValue((qualityAveragesNormalizedValue + qualityDeviationsNormalizedValue + evaluatedSolutionAveragesNormalizedValue) / weightSum); 76 75 77 return parameterConfigurationTree.Quality.Value; 76 78 }
Note: See TracChangeset
for help on using the changeset viewer.