- Timestamp:
- 01/05/11 02:03:20 (14 years ago)
- Location:
- branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestParameterConfigurationAnalyzer.cs
r5087 r5212 40 40 } 41 41 42 // stores the medians of the qualities of each problem 43 public LookupParameter<DoubleArray> ProblemQualityMediansParameter { 44 get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityMedians"]; } 45 } 46 public LookupParameter<ConstrainedItemList<ISingleObjectiveProblem>> ProblemsParameter { 47 get { return (LookupParameter<ConstrainedItemList<ISingleObjectiveProblem>>)Parameters[MetaOptimizationProblem.ProblemsParameterName]; } 48 } 49 42 50 public BestParameterConfigurationAnalyzer() 43 51 : base() { … … 49 57 Parameters.Add(new LookupParameter<IRun>("BestKnownSolution", "TODO The best known solution of this TSP instance.")); 50 58 Parameters.Add(new LookupParameter<RunCollection>("Population", "TODO The best known solution of this TSP instance.")); 59 Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityMedians", "")); 60 Parameters.Add(new LookupParameter<ConstrainedItemList<ISingleObjectiveProblem>>(MetaOptimizationProblem.ProblemsParameterName)); 51 61 } 52 62 … … 65 75 66 76 int idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; 67 68 77 69 78 ParameterConfigurationTree best = (ParameterConfigurationTree)parameterTrees[idxBest]; … … 87 96 88 97 // population 89 90 98 int i = 0; 91 99 RunCollection rc = new RunCollection(); 92 foreach (ParameterConfigurationTree pt in parameterTrees.OrderBy Descending(x => x.BestQuality.Value)) { // todo: respect Maximization:true/false100 foreach (ParameterConfigurationTree pt in parameterTrees.OrderBy(x => x.AverageQualityNormalized)) { // todo: respect Maximization:true/false 93 101 IRun run = new Run(); 94 102 run.Name = string.Format("Individuum ({0})", i); … … 106 114 } 107 115 116 // medians for the problems 117 DoubleArray medians = new DoubleArray(ProblemsParameter.ActualValue.Count); 118 for (int pi = 0; pi < ProblemsParameter.ActualValue.Count; pi++) { 119 double[] values = new double[rc.Count]; 120 for (int ri = 0; ri < rc.Count; ri++) { 121 values[ri] = ((DoubleArray)rc.ElementAt(ri).Results["RunsAverageQualities"])[pi]; 122 } 123 medians[pi] = values.Median(); 124 } 125 ProblemQualityMediansParameter.ActualValue = medians; 126 127 if (results.ContainsKey("ProblemsAverageQualityMedians")) { 128 results["ProblemsAverageQualityMedians"].Value = medians; 129 } else { 130 results.Add(new Result("ProblemsAverageQualityMedians", medians)); 131 } 132 108 133 return base.Apply(); 109 134 } -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurationTree.cs
r5207 r5212 14 14 [StorableClass] 15 15 public class ParameterConfigurationTree : ValueConfiguration, IEnumerable { 16 [Storable] 17 private DoubleValue bestQuality; 18 public DoubleValue BestQuality { 19 get { return bestQuality; } 16 17 [Storable] 18 private DoubleValue averageQualityNormalized; 19 public DoubleValue AverageQualityNormalized { 20 get { return averageQualityNormalized; } 20 21 set { 21 if (bestQuality != value) { 22 if (bestQuality != null) DeregisterQualityEvents(); 23 bestQuality = value; 24 if (bestQuality != null) RegisterQualityEvents(); 22 if (averageQualityNormalized != value) { 23 averageQualityNormalized = value; 25 24 OnQualityChanged(); 26 25 } … … 29 28 30 29 [Storable] 31 private DoubleValue averageQuality; 32 public DoubleValue AverageQuality { 33 get { return averageQuality; } 34 set { averageQuality = value; } 35 } 36 37 [Storable] 38 private DoubleValue worstQuality; 39 public DoubleValue WorstQuality { 40 get { return worstQuality; } 41 set { worstQuality = value; } 42 } 43 44 [Storable] 45 private DoubleValue qualityVariance; 46 public DoubleValue QualityVariance { 47 get { return qualityVariance; } 48 set { qualityVariance = value; } 49 } 50 51 [Storable] 52 private DoubleValue qualityStandardDeviation; 53 public DoubleValue QualityStandardDeviation { 54 get { return qualityStandardDeviation; } 55 set { qualityStandardDeviation = value; } 56 } 57 58 [Storable] 59 private TimeSpanValue averageExecutionTime; 60 public TimeSpanValue AverageExecutionTime { 61 get { return averageExecutionTime; } 62 set { averageExecutionTime = value; } 30 private DoubleArray qualitiesNormalized; 31 public DoubleArray QualitiesNormalized { 32 get { return qualitiesNormalized; } 33 set { 34 if (qualitiesNormalized != value) { 35 qualitiesNormalized = value; 36 } 37 } 38 } 39 40 [Storable] 41 private DoubleArray bestQualities; 42 public DoubleArray BestQualities { 43 get { return bestQualities; } 44 set { 45 if (bestQualities != value) { 46 bestQualities = value; 47 } 48 } 49 } 50 51 [Storable] 52 private DoubleArray averageQualities; 53 public DoubleArray AverageQualities { 54 get { return averageQualities; } 55 set { averageQualities = value; } 56 } 57 58 [Storable] 59 private DoubleArray worstQualities; 60 public DoubleArray WorstQualities { 61 get { return worstQualities; } 62 set { worstQualities = value; } 63 } 64 65 [Storable] 66 private DoubleArray qualityVariances; 67 public DoubleArray QualityVariances { 68 get { return qualityVariances; } 69 set { qualityVariances = value; } 70 } 71 72 [Storable] 73 private DoubleArray qualityStandardDeviations; 74 public DoubleArray QualityStandardDeviations { 75 get { return qualityStandardDeviations; } 76 set { qualityStandardDeviations = value; } 77 } 78 79 [Storable] 80 private ItemList<TimeSpanValue> averageExecutionTimes; 81 public ItemList<TimeSpanValue> AverageExecutionTimes { 82 get { return averageExecutionTimes; } 83 set { averageExecutionTimes = value; } 63 84 } 64 85 … … 88 109 : base(null, algorithm.GetType()) { 89 110 this.Optimize = true; // root must always be optimized 90 this.BestQuality = new DoubleValue();91 111 this.parameters = new Dictionary<string, IItem>(); 92 112 93 113 PopulateParameterConfigurations(algorithm); 94 Initialize();95 114 } 96 115 public ParameterConfigurationTree() { 97 Initialize();98 116 } 99 117 [StorableConstructor] … … 101 119 protected ParameterConfigurationTree(ParameterConfigurationTree original, Cloner cloner) 102 120 : base(original, cloner) { 103 this.bestQualit y = cloner.Clone(original.BestQuality);104 this.averageQualit y = cloner.Clone(original.averageQuality);105 this.worstQualit y = cloner.Clone(original.worstQuality);106 this.qualityStandardDeviation = cloner.Clone(original.qualityStandardDeviation);107 this.qualityVariance = cloner.Clone(original.qualityVariance);108 this.averageExecutionTime = cloner.Clone(original.averageExecutionTime);121 this.bestQualities = cloner.Clone(original.BestQualities); 122 this.averageQualities = cloner.Clone(original.averageQualities); 123 this.worstQualities = cloner.Clone(original.worstQualities); 124 this.qualityStandardDeviations = cloner.Clone(original.qualityStandardDeviations); 125 this.qualityVariances = cloner.Clone(original.qualityVariances); 126 this.averageExecutionTimes = cloner.Clone(original.averageExecutionTimes); 109 127 this.repetitions = cloner.Clone(original.repetitions); 110 128 this.runs = cloner.Clone(original.runs); … … 113 131 this.parameters.Add(p.Key, cloner.Clone(p.Value)); 114 132 } 115 Initialize();116 133 } 117 134 public override IDeepCloneable Clone(Cloner cloner) { … … 120 137 [StorableHook(HookType.AfterDeserialization)] 121 138 private void AfterDeserialization() { 122 Initialize();123 139 } 124 140 #endregion 125 141 126 private void Initialize() {127 //if (algorithm != null) RegisterAlgorithmEvents();128 if (bestQuality != null) RegisterQualityEvents();129 }130 131 142 public virtual void CollectResultValues(IDictionary<string, IItem> values) { 132 values.Add("RunsAverageExecutionTime ", AverageExecutionTime);143 values.Add("RunsAverageExecutionTimes", AverageExecutionTimes); 133 144 values.Add("Repetitions", Repetitions); 134 values.Add("RunsBestQuality", BestQuality); 135 values.Add("RunsAverageQuality", AverageQuality); 136 values.Add("RunsWorstQuality", WorstQuality); 137 values.Add("RunsQualityVariance", QualityVariance); 138 values.Add("RunsQualityStandardDeviation", QualityStandardDeviation); 145 values.Add("RunsBestQualities", BestQualities); 146 values.Add("RunsAverageQualities", AverageQualities); 147 values.Add("RunsWorstQualities", WorstQualities); 148 values.Add("RunsQualityVariances", QualityVariances); 149 values.Add("RunsQualityStandardDeviations", QualityStandardDeviations); 150 values.Add("QualitiesNormalized", QualitiesNormalized); 151 values.Add("AverageQualityNormalized", AverageQualityNormalized); 139 152 values.Add("Runs", Runs); 140 153 } … … 147 160 148 161 #region Events 149 //public event EventHandler AlgorithmChanged;150 //private void OnAlgorithmChanged() {151 // var handler = AlgorithmChanged;152 // if (handler != null) handler(this, EventArgs.Empty);153 //}154 162 public event EventHandler QualityChanged; 155 163 private void OnQualityChanged() { 156 164 var handler = QualityChanged; 157 165 if (handler != null) handler(this, EventArgs.Empty); 158 }159 160 //private void RegisterAlgorithmEvents() {161 162 //}163 //private void DeregisterAlgorithmEvents() {164 165 //}166 private void RegisterQualityEvents() {167 BestQuality.ValueChanged += new EventHandler(Quality_ValueChanged);168 }169 private void DeregisterQualityEvents() {170 BestQuality.ValueChanged -= new EventHandler(Quality_ValueChanged);171 166 } 172 167 -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/ParameterConfigurationEvaluator.cs
r5207 r5212 40 40 } 41 41 42 public LookupParameter<DoubleArray> ProblemQualityMediansParameter { 43 get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityMedians"]; } 44 } 45 42 46 public IntValue Repetitions { 43 47 get { return RepetitionsParameter.ActualValue; } … … 51 55 Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "Missing description.")); 52 56 Parameters.Add(new LookupParameter<IntValue>(MetaOptimizationProblem.RepetitionsParameterName, "Number of evaluations on one problem.")); 57 Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityMedians", "")); 53 58 } 54 59 … … 66 71 IItemList<ISingleObjectiveProblem> problems = ProblemsParameter.ActualValue; 67 72 73 double[] medians; 74 if (ProblemQualityMediansParameter.ActualValue == null) { 75 // this is generation zero. no reference qualities for scaling have been calculated yet. calculate a random individuum to get reference values 76 medians = new double[problems.Count]; // todo 77 for (int i = 0; i < medians.Length; i++) { 78 medians[i] = 10; 79 } 80 } else { 81 medians = ProblemQualityMediansParameter.ActualValue.ToArray(); 82 } 83 68 84 // set parameters 69 85 ParameterConfigurationParameter.ActualValue.Parameterize(algorithm); 70 86 algorithm.StoreAlgorithmInEachRun = false; 71 87 72 List< double> qualities = new List<double>();73 List< TimeSpan> executionTimes = new List<TimeSpan>();88 List<List<double>> qualities = new List<List<double>>(); 89 List<List<TimeSpan>> executionTimes = new List<List<TimeSpan>>(); 74 90 algorithm.Engine = new SequentialEngine.SequentialEngine(); 75 91 algorithm.Prepare(true); … … 77 93 foreach (ISingleObjectiveProblem problem in problems) { 78 94 algorithm.Problem = (IProblem)problem.Clone(); 95 var problemQualities = new List<double>(); 96 var problemExecutionTimes = new List<TimeSpan>(); 79 97 80 98 for (int i = 0; i < Repetitions.Value; i++) { … … 86 104 if (algorithm.ExecutionState == ExecutionState.Paused) { 87 105 // this parametercombination was bad. set penalty for this solution 88 qualities.Add(PenaltyQuality); // todo: respect Maximization; problem: this messes up average value; solution: use currently worst quality*289 executionTimes.Add(algorithm.ExecutionTime);106 problemQualities.Add(PenaltyQuality); // todo: respect Maximization; problem: this messes up average value; solution: use currently worst quality*2 107 problemExecutionTimes.Add(algorithm.ExecutionTime); 90 108 } else { 91 qualities.Add(((DoubleValue)algorithm.Results["BestQuality"].Value).Value);92 executionTimes.Add(algorithm.ExecutionTime);109 problemQualities.Add(((DoubleValue)algorithm.Results["BestQuality"].Value).Value); 110 problemExecutionTimes.Add(algorithm.ExecutionTime); 93 111 94 112 // parameters will be stored in ParameterConfigurationTree anyway. they would be redundant in runs … … 98 116 } 99 117 } 118 qualities.Add(problemQualities); 119 executionTimes.Add(problemExecutionTimes); 100 120 } 101 121 algorithm.Prepare(); 102 122 103 qualities = qualities.OrderBy(x => x).ToList(); // todo: respect Maximization:true/false 104 105 ParameterConfigurationParameter.ActualValue.AverageExecutionTime = new TimeSpanValue(TimeSpan.FromMilliseconds(executionTimes.Average(t => t.TotalMilliseconds))); 123 ParameterConfigurationParameter.ActualValue.AverageExecutionTimes = new ItemList<TimeSpanValue>(executionTimes.Select(t => new TimeSpanValue(TimeSpan.FromMilliseconds(t.Average(ts => ts.TotalMilliseconds))))); 106 124 ParameterConfigurationParameter.ActualValue.Repetitions = (IntValue)Repetitions.Clone(); 107 ParameterConfigurationParameter.ActualValue.BestQualit y = new DoubleValue(qualities.First());108 ParameterConfigurationParameter.ActualValue.AverageQualit y = new DoubleValue(qualities.Average());109 ParameterConfigurationParameter.ActualValue.WorstQualit y = new DoubleValue(qualities.Last());110 ParameterConfigurationParameter.ActualValue.QualityVariance = new DoubleValue(qualities.Variance());111 ParameterConfigurationParameter.ActualValue.QualityStandardDeviation = new DoubleValue(qualities.StandardDeviation());125 ParameterConfigurationParameter.ActualValue.BestQualities = new DoubleArray(qualities.Select(q => q.Min()).ToArray()); // todo: respect Maximization:true/false 126 ParameterConfigurationParameter.ActualValue.AverageQualities = new DoubleArray(qualities.Select(q => q.Average()).ToArray()); 127 ParameterConfigurationParameter.ActualValue.WorstQualities = new DoubleArray(qualities.Select(q => q.Max()).ToArray()); // todo: respect Maximization:true/false 128 ParameterConfigurationParameter.ActualValue.QualityVariances = new DoubleArray(qualities.Select(q => q.Variance()).ToArray()); 129 ParameterConfigurationParameter.ActualValue.QualityStandardDeviations = new DoubleArray(qualities.Select(q => q.StandardDeviation()).ToArray()); 112 130 ParameterConfigurationParameter.ActualValue.Runs = (RunCollection)algorithm.Runs.Clone(); 113 131 114 double quality = ParameterConfigurationParameter.ActualValue.AverageQuality.Value; // todo: also include other measures (executiontime, variance) 115 this.QualityParameter.ActualValue = new DoubleValue(quality); 132 // normalize qualities 133 double[] qualitiesNormalized = new double[problems.Count]; 134 for (int i = 0; i < problems.Count; i++) { 135 qualitiesNormalized[i] = qualities[i].Average() / medians[i]; 136 } 137 ParameterConfigurationParameter.ActualValue.QualitiesNormalized = new DoubleArray(qualitiesNormalized); 138 ParameterConfigurationParameter.ActualValue.AverageQualityNormalized = new DoubleValue(qualitiesNormalized.Average()); 139 140 this.QualityParameter.ActualValue = ParameterConfigurationParameter.ActualValue.AverageQualityNormalized; 116 141 117 142 return base.Apply(); … … 129 154 } 130 155 156 /// <summary> 157 /// Can execute an algorithm synchronously 158 /// </summary> 131 159 public class AlgorithmExecutor { 132 160 private EngineAlgorithm algorithm; -
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs
r5184 r5212 109 109 var validIntManipulators = new ItemSet<IIntValueManipulator>( ApplicationManager.Manager.GetInstances<IIntValueManipulator>()); 110 110 var validDoubleManipulators = new ItemSet<IDoubleValueManipulator>(ApplicationManager.Manager.GetInstances<IDoubleValueManipulator>()); 111 Parameters.Add(new ConstrainedValueParameter<IIntValueManipulator>(IntValueManipulatorParameterName, "", validIntManipulators, new UniformIntValueManipulator()));112 Parameters.Add(new ConstrainedValueParameter<IDoubleValueManipulator>(DoubleValueManipulatorParameterName, "", validDoubleManipulators, new NormalDoubleValueManipulator()));111 Parameters.Add(new ConstrainedValueParameter<IIntValueManipulator>(IntValueManipulatorParameterName, "", validIntManipulators, validIntManipulators.First())); 112 Parameters.Add(new ConstrainedValueParameter<IDoubleValueManipulator>(DoubleValueManipulatorParameterName, "", validDoubleManipulators, validDoubleManipulators.First())); 113 113 114 114 Maximization = new BoolValue(false);
Note: See TracChangeset
for help on using the changeset viewer.