Changeset 6018 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers
- Timestamp:
- 04/17/11 18:22:28 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestParameterConfigurationAnalyzer.cs
r5576 r6018 7 7 using HeuristicLab.Parameters; 8 8 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 9 using System.Collections.Generic;10 using System;11 9 12 10 namespace HeuristicLab.Problems.MetaOptimization { … … 39 37 get { return (LookupParameter<RunCollection>)Parameters["Population"]; } 40 38 } 41 public LookupParameter<DoubleArray> ProblemQualityReferencesParameter {42 get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityReferences"]; }43 }44 39 public LookupParameter<ConstrainedItemList<IProblem>> ProblemsParameter { 45 40 get { return (LookupParameter<ConstrainedItemList<IProblem>>)Parameters[MetaOptimizationProblem.ProblemsParameterName]; } 41 } 42 public LookupParameter<BoolValue> MaximizationParameter { 43 get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; } 46 44 } 47 45 … … 55 53 Parameters.Add(new LookupParameter<IRun>("BestKnownSolution", "")); 56 54 Parameters.Add(new LookupParameter<RunCollection>("Population", "")); 57 Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityReferences", ""));58 55 Parameters.Add(new LookupParameter<ConstrainedItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName)); 56 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.")); 59 57 } 60 58 … … 71 69 DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue; 72 70 ItemArray<ParameterConfigurationTree> parameterTrees = ParameterConfigurationParameter.ActualValue; 71 bool maximization = MaximizationParameter.ActualValue.Value; 73 72 74 int idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 73 int idxBest; 74 if (maximization) 75 idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).Last().index; 76 else 77 idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 75 78 76 79 ParameterConfigurationTree best = (ParameterConfigurationTree)parameterTrees[idxBest]; … … 79 82 best.CollectParameterValues(bestRun.Parameters); 80 83 81 if (bestKnownQuality == null || qualities[idxBest].Value < bestKnownQuality.Value) { // todo: respect Maximization:true/false 84 if (bestKnownQuality == null || 85 (!maximization && (qualities[idxBest].Value < bestKnownQuality.Value) || 86 (maximization && (qualities[idxBest].Value > bestKnownQuality.Value)))) { 82 87 BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[idxBest].Value); 83 88 … … 96 101 int i = 0; 97 102 RunCollection rc = new RunCollection(); 98 foreach (ParameterConfigurationTree pt in parameterTrees.OrderBy(x => x.AverageQualityNormalized)) { // todo: respect Maximization:true/false103 foreach (ParameterConfigurationTree pt in (maximization ? parameterTrees.OrderByDescending(x => x.Quality) : parameterTrees.OrderBy(x => x.Quality))) { 99 104 rc.Add(pt.ToRun(string.Format("Individual {0} ({1})", i, pt.ParameterInfoString))); 100 105 i++; -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/PMOBestSolutionHistoryAnalyzer.cs
r5576 r6018 7 7 using HeuristicLab.Parameters; 8 8 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 9 using System.Collections.Generic;10 using System;11 using HeuristicLab.Analysis;12 9 13 10 namespace HeuristicLab.Problems.MetaOptimization { … … 34 31 get { return (LookupParameter<IntValue>)Parameters["Generations"]; } 35 32 } 33 public LookupParameter<BoolValue> MaximizationParameter { 34 get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; } 35 } 36 36 37 37 public PMOBestSolutionHistoryAnalyzer() … … 42 42 Parameters.Add(new LookupParameter<ConstrainedItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName)); 43 43 Parameters.Add(new LookupParameter<IntValue>("Generations", "")); 44 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.")); 44 45 } 45 46 … … 56 57 ItemArray<ParameterConfigurationTree> parameterTrees = ParameterConfigurationParameter.ActualValue; 57 58 int currentGeneration = GenerationsParameter.ActualValue.Value; 58 int idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; // todo: respect Min/Max 59 bool maximization = MaximizationParameter.ActualValue.Value; 60 61 int idxBest; 62 if (maximization) 63 idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).Last().index; 64 else 65 idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 66 59 67 ParameterConfigurationTree best = parameterTrees[idxBest]; 60 68 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/PMOProblemQualitiesAnalyzer.cs
r5576 r6018 1 1 using System.Linq; 2 using HeuristicLab.Analysis; 2 3 using HeuristicLab.Common; 3 4 using HeuristicLab.Core; … … 7 8 using HeuristicLab.Parameters; 8 9 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 9 using System.Collections.Generic;10 using System;11 using HeuristicLab.Analysis;12 10 13 11 namespace HeuristicLab.Problems.MetaOptimization { … … 31 29 get { return (LookupParameter<ConstrainedItemList<IProblem>>)Parameters[MetaOptimizationProblem.ProblemsParameterName]; } 32 30 } 31 public LookupParameter<BoolValue> MaximizationParameter { 32 get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; } 33 } 33 34 34 35 public PMOProblemQualitiesAnalyzer() … … 38 39 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "")); 39 40 Parameters.Add(new LookupParameter<ConstrainedItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName)); 41 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.")); 40 42 } 41 43 … … 51 53 ResultCollection results = ResultsParameter.ActualValue; 52 54 ItemArray<ParameterConfigurationTree> parameterTrees = ParameterConfigurationParameter.ActualValue; 53 int idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; // todo: respect Min/Max 54 int idxWorst = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).Last().index; 55 55 bool maximization = MaximizationParameter.ActualValue.Value; 56 57 int idxBest ; 58 int idxWorst; 59 if (maximization) { 60 idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).Last().index; 61 idxWorst = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 62 } else { 63 idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 64 idxWorst = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).Last().index; 65 } 66 56 67 int problemCount = ProblemsParameter.ActualValue.Count; 57 68 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/ReferenceQualityAnalyzer.cs
r5653 r6018 7 7 using HeuristicLab.Parameters; 8 8 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 9 using System.Collections.Generic;10 using System;11 9 12 10 namespace HeuristicLab.Problems.MetaOptimization { … … 17 15 [StorableClass] 18 16 public sealed class ReferenceQualityAnalyzer : SingleSuccessorOperator, IAnalyzer { 19 17 20 18 public ValueLookupParameter<ResultCollection> ResultsParameter { 21 19 get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; } … … 27 25 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 28 26 } 29 public LookupParameter<DoubleArray> ProblemQualityReferenceParameter { 30 get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityReferences"]; } 27 public LookupParameter<DoubleArray> ReferenceQualityAveragesParameter { 28 get { return (LookupParameter<DoubleArray>)Parameters["ReferenceQualityAverages"]; } 29 } 30 public LookupParameter<DoubleArray> ReferenceQualityDeviationsParameter { 31 get { return (LookupParameter<DoubleArray>)Parameters["ReferenceQualityDeviations"]; } 32 } 33 public LookupParameter<DoubleArray> ReferenceEvaluatedSolutionAveragesParameter { 34 get { return (LookupParameter<DoubleArray>)Parameters["ReferenceEvaluatedSolutionAverages"]; } 31 35 } 32 36 public LookupParameter<ConstrainedItemList<IProblem>> ProblemsParameter { 33 37 get { return (LookupParameter<ConstrainedItemList<IProblem>>)Parameters[MetaOptimizationProblem.ProblemsParameterName]; } 38 } 39 public LookupParameter<BoolValue> MaximizationParameter { 40 get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; } 34 41 } 35 42 … … 39 46 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "")); 40 47 Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "")); 41 Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityReferences", "")); 48 Parameters.Add(new LookupParameter<DoubleArray>("ReferenceQualityAverages", "")); 49 Parameters.Add(new LookupParameter<DoubleArray>("ReferenceQualityDeviations", "")); 50 Parameters.Add(new LookupParameter<DoubleArray>("ReferenceEvaluatedSolutionAverages", "")); 42 51 Parameters.Add(new LookupParameter<ConstrainedItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName, "")); 52 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.")); 43 53 } 44 54 … … 54 64 ItemArray<ParameterConfigurationTree> solutions = ParameterConfigurationParameter.ActualValue; 55 65 ItemArray<DoubleValue> qualities = QualityParameter.ActualValue; 66 bool maximization = MaximizationParameter.ActualValue.Value; 56 67 57 if (ProblemQualityReferenceParameter.ActualValue == null) { 58 DoubleArray referenceQualities = CalculateReferenceQualities(solutions); 59 ProblemQualityReferenceParameter.ActualValue = referenceQualities; 60 NormalizePopulation(solutions, qualities, referenceQualities); 61 results.Add(new Result("QualityReferences", referenceQualities)); 68 if (ReferenceQualityAveragesParameter.ActualValue == null) { 69 // this is generation zero. calculate the reference values and apply them on population. in future generations `AlgorithmRunsAnalyzer` will do the nomalization 70 DoubleArray referenceQualityAverages = CalculateReferenceQualityAverages(solutions, maximization); 71 DoubleArray referenceQualityDeviations = CalculateReferenceQualityDeviations(solutions, maximization); 72 DoubleArray referenceEvaluatedSolutionAverages = CalculateReferenceEvaluatedSolutionAverages(solutions, maximization); 73 74 ReferenceQualityAveragesParameter.ActualValue = referenceQualityAverages; 75 ReferenceQualityDeviationsParameter.ActualValue = referenceQualityDeviations; 76 ReferenceEvaluatedSolutionAveragesParameter.ActualValue = referenceEvaluatedSolutionAverages; 77 78 NormalizePopulation(solutions, qualities, referenceQualityAverages, referenceQualityDeviations, referenceEvaluatedSolutionAverages, 1, 1, 1, maximization); 79 80 results.Add(new Result("ReferenceQualities", referenceQualityAverages)); 81 results.Add(new Result("ReferenceQualityDeviations", referenceQualityDeviations)); 82 results.Add(new Result("ReferenceEvaluatedSolutionAverages", referenceEvaluatedSolutionAverages)); 62 83 } 63 84 … … 65 86 } 66 87 67 private DoubleArray CalculateReferenceQualit ies(ItemArray<ParameterConfigurationTree> solutions) {68 DoubleArray reference Qualities = new DoubleArray(ProblemsParameter.ActualValue.Count);88 private DoubleArray CalculateReferenceQualityAverages(ItemArray<ParameterConfigurationTree> solutions, bool maximization) { 89 DoubleArray references = new DoubleArray(ProblemsParameter.ActualValue.Count); 69 90 for (int pi = 0; pi < ProblemsParameter.ActualValue.Count; pi++) { 70 referenceQualities[pi] = solutions.Where(x => x.AverageQualities != null).Select(x => x.AverageQualities[pi]).Min(); // todo: respect minimization / maximization 91 if (maximization) 92 references[pi] = solutions.Where(x => x.AverageQualities != null).Select(x => x.AverageQualities[pi]).Max(); 93 else 94 references[pi] = solutions.Where(x => x.AverageQualities != null).Select(x => x.AverageQualities[pi]).Min(); 71 95 } 72 return reference Qualities;96 return references; 73 97 } 74 98 75 private void NormalizePopulation(ItemArray<ParameterConfigurationTree> solutions, ItemArray<DoubleValue> qualities, DoubleArray referenceQualities) { 99 private DoubleArray CalculateReferenceQualityDeviations(ItemArray<ParameterConfigurationTree> solutions, bool maximization) { 100 DoubleArray references = new DoubleArray(ProblemsParameter.ActualValue.Count); 101 for (int pi = 0; pi < ProblemsParameter.ActualValue.Count; pi++) { 102 if (maximization) 103 references[pi] = solutions.Where(x => x.QualityStandardDeviations != null).Select(x => x.QualityStandardDeviations[pi]).Max(); 104 else 105 references[pi] = solutions.Where(x => x.QualityStandardDeviations != null).Select(x => x.QualityStandardDeviations[pi]).Min(); 106 } 107 return references; 108 } 109 110 private DoubleArray CalculateReferenceEvaluatedSolutionAverages(ItemArray<ParameterConfigurationTree> solutions, bool maximization) { 111 DoubleArray references = new DoubleArray(ProblemsParameter.ActualValue.Count); 112 for (int pi = 0; pi < ProblemsParameter.ActualValue.Count; pi++) { 113 if (maximization) 114 references[pi] = solutions.Where(x => x.AverageEvaluatedSolutions != null).Select(x => x.AverageEvaluatedSolutions[pi]).Max(); 115 else 116 references[pi] = solutions.Where(x => x.AverageEvaluatedSolutions != null).Select(x => x.AverageEvaluatedSolutions[pi]).Min(); 117 } 118 return references; 119 } 120 121 private void NormalizePopulation(ItemArray<ParameterConfigurationTree> solutions, ItemArray<DoubleValue> qualities, 122 DoubleArray referenceQualityAverages, 123 DoubleArray referenceQualityDeviations, 124 DoubleArray referenceEvaluatedSolutionAverages, 125 double qualityAveragesWeight, 126 double qualityDeviationsWeight, 127 double evaluatedSolutionsWeight, 128 bool maximization) { 76 129 for (int i = 0; i < solutions.Length; i++) { 77 qualities[i].Value = MetaOptimizationUtil.NormalizeQualities(solutions[i], referenceQualities.ToArray()); 130 if (solutions[i].AverageQualities == null || solutions[i].QualityStandardDeviations == null || solutions[i].AverageEvaluatedSolutions == null) { 131 // this parameterConfigurationTree has not been evaluated correctly (due to a faulty configuration, which led to an exception) 132 // since we are in generation zero, there is no WorstQuality available for a penalty value 133 double penaltyValue = maximization ? double.MinValue : double.MaxValue; 134 qualities[i].Value = penaltyValue; 135 } else { 136 qualities[i].Value = MetaOptimizationUtil.Normalize(solutions[i], 137 referenceQualityAverages.ToArray(), 138 referenceQualityDeviations.ToArray(), 139 referenceEvaluatedSolutionAverages.ToArray(), 140 qualityAveragesWeight, 141 qualityDeviationsWeight, 142 evaluatedSolutionsWeight, 143 maximization); 144 } 78 145 } 79 146 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/SolutionCacheAnalyzer.cs
r5359 r6018 7 7 using HeuristicLab.Parameters; 8 8 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 9 using System.Collections.Generic;10 using System;11 9 12 10 namespace HeuristicLab.Problems.MetaOptimization { … … 27 25 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 28 26 } 29 public LookupParameter<DoubleArray> ProblemQualityReferenceParameter {30 get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityReferences"]; }31 }32 27 public LookupParameter<ConstrainedItemList<IProblem>> ProblemsParameter { 33 28 get { return (LookupParameter<ConstrainedItemList<IProblem>>)Parameters[MetaOptimizationProblem.ProblemsParameterName]; } … … 45 40 Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "")); 46 41 Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "")); 47 Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityReferences", ""));48 42 Parameters.Add(new LookupParameter<ConstrainedItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName, "")); 49 43 Parameters.Add(new LookupParameter<IntValue>("Generations", ""));
Note: See TracChangeset
for help on using the changeset viewer.