Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/05/11 02:03:20 (14 years ago)
Author:
cneumuel
Message:

#1215

  • added normalization for quality values of individuals
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  
    4040    }
    4141
     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
    4250    public BestParameterConfigurationAnalyzer()
    4351      : base() {
     
    4957      Parameters.Add(new LookupParameter<IRun>("BestKnownSolution", "TODO The best known solution of this TSP instance."));
    5058      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));
    5161    }
    5262
     
    6575
    6676      int idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
    67 
    6877
    6978      ParameterConfigurationTree best = (ParameterConfigurationTree)parameterTrees[idxBest];
     
    8796
    8897      // population
    89 
    9098      int i = 0;
    9199      RunCollection rc = new RunCollection();
    92       foreach (ParameterConfigurationTree pt in parameterTrees.OrderByDescending(x => x.BestQuality.Value)) { // todo: respect Maximization:true/false
     100      foreach (ParameterConfigurationTree pt in parameterTrees.OrderBy(x => x.AverageQualityNormalized)) { // todo: respect Maximization:true/false
    93101        IRun run = new Run();
    94102        run.Name = string.Format("Individuum ({0})", i);
     
    106114      }
    107115
     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
    108133      return base.Apply();
    109134    }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurationTree.cs

    r5207 r5212  
    1414  [StorableClass]
    1515  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; }
    2021      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;
    2524          OnQualityChanged();
    2625        }
     
    2928
    3029    [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; }
    6384    }
    6485
     
    88109      : base(null, algorithm.GetType()) {
    89110      this.Optimize = true; // root must always be optimized
    90       this.BestQuality = new DoubleValue();
    91111      this.parameters = new Dictionary<string, IItem>();
    92112
    93113      PopulateParameterConfigurations(algorithm);
    94       Initialize();
    95114    }
    96115    public ParameterConfigurationTree() {
    97       Initialize();
    98116    }
    99117    [StorableConstructor]
     
    101119    protected ParameterConfigurationTree(ParameterConfigurationTree original, Cloner cloner)
    102120      : base(original, cloner) {
    103       this.bestQuality = cloner.Clone(original.BestQuality);
    104       this.averageQuality = cloner.Clone(original.averageQuality);
    105       this.worstQuality = 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);
    109127      this.repetitions = cloner.Clone(original.repetitions);
    110128      this.runs = cloner.Clone(original.runs);
     
    113131        this.parameters.Add(p.Key, cloner.Clone(p.Value));
    114132      }
    115       Initialize();
    116133    }
    117134    public override IDeepCloneable Clone(Cloner cloner) {
     
    120137    [StorableHook(HookType.AfterDeserialization)]
    121138    private void AfterDeserialization() {
    122       Initialize();
    123139    }
    124140    #endregion
    125141
    126     private void Initialize() {
    127       //if (algorithm != null) RegisterAlgorithmEvents();
    128       if (bestQuality != null) RegisterQualityEvents();
    129     }
    130 
    131142    public virtual void CollectResultValues(IDictionary<string, IItem> values) {
    132       values.Add("RunsAverageExecutionTime", AverageExecutionTime);
     143      values.Add("RunsAverageExecutionTimes", AverageExecutionTimes);
    133144      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);
    139152      values.Add("Runs", Runs);
    140153    }
     
    147160
    148161    #region Events
    149     //public event EventHandler AlgorithmChanged;
    150     //private void OnAlgorithmChanged() {
    151     //  var handler = AlgorithmChanged;
    152     //  if (handler != null) handler(this, EventArgs.Empty);
    153     //}
    154162    public event EventHandler QualityChanged;
    155163    private void OnQualityChanged() {
    156164      var handler = QualityChanged;
    157165      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);
    171166    }
    172167
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/ParameterConfigurationEvaluator.cs

    r5207 r5212  
    4040    }
    4141
     42    public LookupParameter<DoubleArray> ProblemQualityMediansParameter {
     43      get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityMedians"]; }
     44    }
     45
    4246    public IntValue Repetitions {
    4347      get { return RepetitionsParameter.ActualValue; }
     
    5155      Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "Missing description."));
    5256      Parameters.Add(new LookupParameter<IntValue>(MetaOptimizationProblem.RepetitionsParameterName, "Number of evaluations on one problem."));
     57      Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityMedians", ""));
    5358    }
    5459
     
    6671      IItemList<ISingleObjectiveProblem> problems = ProblemsParameter.ActualValue;
    6772
     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
    6884      // set parameters
    6985      ParameterConfigurationParameter.ActualValue.Parameterize(algorithm);
    7086      algorithm.StoreAlgorithmInEachRun = false;
    7187
    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>>();
    7490      algorithm.Engine = new SequentialEngine.SequentialEngine();
    7591      algorithm.Prepare(true);
     
    7793      foreach (ISingleObjectiveProblem problem in problems) {
    7894        algorithm.Problem = (IProblem)problem.Clone();
     95        var problemQualities = new List<double>();
     96        var problemExecutionTimes = new List<TimeSpan>();
    7997
    8098        for (int i = 0; i < Repetitions.Value; i++) {
     
    86104          if (algorithm.ExecutionState == ExecutionState.Paused) {
    87105            // 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*2
    89             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);
    90108          } 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);
    93111
    94112            // parameters will be stored in ParameterConfigurationTree anyway. they would be redundant in runs
     
    98116          }
    99117        }
     118        qualities.Add(problemQualities);
     119        executionTimes.Add(problemExecutionTimes);
    100120      }
    101121      algorithm.Prepare();
    102122
    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)))));
    106124      ParameterConfigurationParameter.ActualValue.Repetitions = (IntValue)Repetitions.Clone();
    107       ParameterConfigurationParameter.ActualValue.BestQuality = new DoubleValue(qualities.First());
    108       ParameterConfigurationParameter.ActualValue.AverageQuality = new DoubleValue(qualities.Average());
    109       ParameterConfigurationParameter.ActualValue.WorstQuality = 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());
    112130      ParameterConfigurationParameter.ActualValue.Runs = (RunCollection)algorithm.Runs.Clone();
    113131
    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;
    116141
    117142      return base.Apply();
     
    129154  }
    130155
     156  /// <summary>
     157  /// Can execute an algorithm synchronously
     158  /// </summary>
    131159  public class AlgorithmExecutor {
    132160    private EngineAlgorithm algorithm;
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs

    r5184 r5212  
    109109      var validIntManipulators = new ItemSet<IIntValueManipulator>( ApplicationManager.Manager.GetInstances<IIntValueManipulator>());
    110110      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()));
    113113
    114114      Maximization = new BoolValue(false);
Note: See TracChangeset for help on using the changeset viewer.