Changeset 5023 for branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators
- Timestamp:
- 12/04/10 18:08:43 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/MetaOptimizationEvaluator.cs
r5009 r5023 1 1 using System; 2 using System.Linq; 2 3 using System.Threading; 3 4 using HeuristicLab.Common; … … 8 9 using HeuristicLab.Parameters; 9 10 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 11 using System.Collections.Generic; 10 12 11 13 namespace HeuristicLab.Problems.MetaOptimization { … … 69 71 algorithm.Stopped += new EventHandler(ActualValue_Stopped); 70 72 71 double qualitySum = 0; 73 List<double> qualities = new List<double>(); 74 List<TimeSpan> executionTimes = new List<TimeSpan>(); 75 algorithm.Prepare(true); 72 76 73 //foreach (ISingleObjectiveProblem problem in ProblemsParameter.ActualValue) { 74 algorithm.Engine = new SequentialEngine.SequentialEngine(); 75 //algorithm.Problem = problem; 76 algorithm.Prepare(); 77 algorithm.Start(); 78 while (!algorithmStopped) { 79 Thread.Sleep(1000); // wait for algorithm to complete; do not rely on Algorithm.ExecutionState here, because change of ExecutionState happens before Run is added (which causes problems because Algorithm might get cloned when its started already) 77 for (int i = 0; i < Repetitions.Value; i++) { 78 algorithm.Engine = new SequentialEngine.SequentialEngine(); 79 algorithm.Prepare(); 80 algorithm.Start(); 81 while (!algorithmStopped) { 82 Thread.Sleep(200); // wait for algorithm to complete; do not rely on Algorithm.ExecutionState here, because change of ExecutionState happens before Run is added (which causes problems because Algorithm might get cloned when its started already) 83 } 84 qualities.Add(((DoubleValue)algorithm.Results["BestQuality"].Value).Value); 85 executionTimes.Add(algorithm.ExecutionTime); 86 87 algorithmStopped = false; 80 88 } 81 double quality = ((DoubleValue)algorithm.Results["BestQuality"].Value).Value;82 ParameterConfigurationParameter.ActualValue.Quality.Value = quality;83 qualitySum += quality;84 //}85 86 89 algorithm.Stopped -= new EventHandler(ActualValue_Stopped); 87 90 88 //double qualityAvg = qualitySum / ProblemsParameter.ActualValue.Count; 89 //this.QualityParameter.ActualValue = new DoubleValue(qualityAvg); 91 qualities = qualities.OrderBy(x => x).ToList(); // todo: respect Maximization:true/false 92 93 ParameterConfigurationParameter.ActualValue.AverageExecutionTime = new TimeSpanValue(TimeSpan.FromMilliseconds(executionTimes.Average(t => t.TotalMilliseconds))); 94 ParameterConfigurationParameter.ActualValue.Repetitions = Repetitions; 95 ParameterConfigurationParameter.ActualValue.BestQuality = new DoubleValue(qualities.First()); 96 ParameterConfigurationParameter.ActualValue.AverageQuality = new DoubleValue(qualities.Average()); 97 ParameterConfigurationParameter.ActualValue.WorstQuality = new DoubleValue(qualities.Last()); 98 ParameterConfigurationParameter.ActualValue.QualityVariance = new DoubleValue(qualities.Variance()); 99 ParameterConfigurationParameter.ActualValue.QualityStandardDeviation = new DoubleValue(qualities.StandardDeviation()); 100 ParameterConfigurationParameter.ActualValue.Runs = algorithm.Runs; 101 102 double quality = ParameterConfigurationParameter.ActualValue.AverageQuality.Value; // todo: also include other measures (executiontime, variance) 90 103 this.QualityParameter.ActualValue = new DoubleValue(quality); 104 105 return base.Apply(); 106 } 91 107 92 return base.Apply(); 108 public static double Variance(IEnumerable<double> source) { 109 double avg = source.Average(); 110 double d = source.Aggregate(0.0, (total, next) => total += Math.Pow(next - avg, 2)); 111 return d / (source.Count() - 1); 112 } 113 114 public static double StandardDeviation(IEnumerable<double> source) { 115 return Math.Sqrt(source.Variance()); 93 116 } 94 117 … … 96 119 algorithmStopped = true; 97 120 } 98 99 //private void ParameterizeAlgorithm() {100 // foreach (IParameterConfiguration parameter in ParameterVectorParameter.ActualValue) {101 // if (typeof(IAlgorithm).IsAssignableFrom(parameter.OperatorType)) {102 // this.AlgorithmParameter.ActualValue.Parameters[parameter.Parameter.Name].ActualValue = parameter.Parameter.ActualValue;103 // } else if (typeof(IProblem).IsAssignableFrom(parameter.OperatorType)) {104 // this.AlgorithmParameter.ActualValue.Problem.Parameters[parameter.Parameter.Name].ActualValue = parameter.Parameter.ActualValue;105 // }106 // }107 //}108 121 } 109 122 }
Note: See TracChangeset
for help on using the changeset viewer.