Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5281


Ignore:
Timestamp:
01/11/11 17:55:30 (14 years ago)
Author:
cneumuel
Message:

#1215

  • fixed normalization problems in first generation and with elites
Location:
branches/HeuristicLab.MetaOptimization
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs

    r5277 r5281  
    3131    //private static int baseAlgorithmMaxGenerations = 1000;
    3232
    33     private static int metaAlgorithmPopulationSize = 16;
     33    private static int metaAlgorithmPopulationSize = 7;
    3434    private static int metaAlgorithmMaxGenerations = 20;
    3535    private static int metaProblemRepetitions = 3;
    3636    private static int baseAlgorithmMaxGenerations = 50;
     37    private static double mutationProbability = 0.35;
    3738
    3839    static void Main(string[] args) {
     
    468469      metaLevelAlgorithm.Mutator = ((OptionalConstrainedValueParameter<IManipulator>)((IAlgorithm)metaLevelAlgorithm).Parameters["Mutator"]).ValidValues.Last();
    469470
    470       metaLevelAlgorithm.MutationProbability.Value = 0.15;
     471      metaLevelAlgorithm.MutationProbability.Value = mutationProbability;
    471472
    472473      return metaLevelAlgorithm;
     
    509510      ParameterConfigurationTree algorithmVc = metaOptimizationProblem.ParameterConfigurationTree;
    510511
    511       //metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
    512       //  Evaluator = new GriewankEvaluator(),
    513       //  ProblemSize = new IntValue(5)
    514       //});
    515       //metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
    516       //  Evaluator = new GriewankEvaluator(),
    517       //  ProblemSize = new IntValue(50)
    518       //});
     512      metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
     513        Evaluator = new GriewankEvaluator(),
     514        ProblemSize = new IntValue(5)
     515      });
     516      metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
     517        Evaluator = new GriewankEvaluator(),
     518        ProblemSize = new IntValue(50)
     519      });
    519520      metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
    520521        Evaluator = new GriewankEvaluator(),
     
    708709          Thread.Sleep(1000);
    709710          if (metaLevelAlgorithm.Results.ContainsKey("Generations") && ((IntValue)metaLevelAlgorithm.Results["Generations"].Value).Value != currentGeneration) {
    710             while (metaLevelAlgorithm.Results.Count < 3) Thread.Sleep(100);
     711            while (metaLevelAlgorithm.Results.Count < 6) Thread.Sleep(1000);
    711712            StringBuilder sb = new StringBuilder();
    712713            sb.AppendLine(DateTime.Now.ToLongTimeString());
     
    714715
    715716            sb.AppendLine(metaLevelAlgorithm.ExecutionState.ToString());
    716             var rsClone = (ResultCollection)metaLevelAlgorithm.Results.Clone();
     717            ResultCollection rsClone = null;
     718            while (rsClone == null) {
     719              try {
     720                rsClone = (ResultCollection)metaLevelAlgorithm.Results.Clone();
     721              }
     722              catch { }
     723            }
    717724            foreach (var result in rsClone) {
    718725              sb.AppendLine(result.ToString());
     
    721728                var orderedRuns = rc.OrderBy(x => x.Results["AverageQualityNormalized"]);
    722729
    723                 TableBuilder tb = new TableBuilder("QNorm", "PoSi", "MutRa", "Eli", "SelOp", "MutOp", "NrSelSubScopes");
     730                TableBuilder tb = new TableBuilder("QNorm", "Qualities", "PoSi", "MutRa", "Eli", "SelOp", "MutOp", "NrSelSubScopes");
    724731                foreach (IRun run in orderedRuns) {
    725732                  string selector;
     
    732739                  tb.AppendRow(
    733740                    ((DoubleValue)run.Results["AverageQualityNormalized"]).Value.ToString("#0.00"),
     741                    ((DoubleArray)run.Results["RunsAverageQualities"]).ToString(),
    734742                    ((IntValue)run.Parameters["PopulationSize"]).Value.ToString(),
    735743                    ((DoubleValue)run.Parameters["MutationProbability"]).Value.ToString("0.00"),
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestParameterConfigurationAnalyzer.cs

    r5212 r5281  
    1414  /// TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.
    1515  /// </summary>
    16   [Item("BestParameterConfigurationAnalyzer", "TODO An operator for analyzing the best solution of Traveling Salesman Problems given in path representation using city coordinates.")]
     16  [Item("BestParameterConfigurationAnalyzer", "")]
    1717  [StorableClass]
    1818  public sealed class BestParameterConfigurationAnalyzer : SingleSuccessorOperator, IAnalyzer {
     
    3939      get { return (LookupParameter<RunCollection>)Parameters["Population"]; }
    4040    }
    41 
    42     // stores the medians of the qualities of each problem
    4341    public LookupParameter<DoubleArray> ProblemQualityMediansParameter {
    4442      get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityMedians"]; }
     
    5048    public BestParameterConfigurationAnalyzer()
    5149      : base() {
    52       Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "TODO The TSP solutions given in path representation from which the best solution should be analyzed."));
    53       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "TODO The qualities of the TSP solutions which should be analyzed."));
    54       Parameters.Add(new LookupParameter<IRun>("BestSolution", "TODO The best TSP solution."));
    55       Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", "TODO The result collection where the best TSP solution should be stored."));
    56       Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "TODO The quality of the best known solution of this TSP instance."));
    57       Parameters.Add(new LookupParameter<IRun>("BestKnownSolution", "TODO The best known solution of this TSP instance."));
    58       Parameters.Add(new LookupParameter<RunCollection>("Population", "TODO The best known solution of this TSP instance."));
     50      Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", ""));
     51      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", ""));
     52      Parameters.Add(new LookupParameter<IRun>("BestSolution", ""));
     53      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", ""));
     54      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", ""));
     55      Parameters.Add(new LookupParameter<IRun>("BestKnownSolution", ""));
     56      Parameters.Add(new LookupParameter<RunCollection>("Population", ""));
    5957      Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityMedians", ""));
    6058      Parameters.Add(new LookupParameter<ConstrainedItemList<ISingleObjectiveProblem>>(MetaOptimizationProblem.ProblemsParameterName));
     
    114112      }
    115113
    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 
    133114      return base.Apply();
    134115    }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/ParameterConfigurationEvaluator.cs

    r5231 r5281  
    7070      EngineAlgorithm algorithm = (EngineAlgorithm)AlgorithmParameter.ActualValue.Clone();
    7171      IItemList<ISingleObjectiveProblem> problems = ProblemsParameter.ActualValue;
     72      ParameterConfigurationTree parameterConfiguration = ParameterConfigurationParameter.ActualValue;
    7273
    7374      double[] medians;
    7475      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
     76        // this is generation zero. no reference qualities for normalization have been calculated yet.
     77        medians = new double[problems.Count];
    7778        for (int i = 0; i < medians.Length; i++) {
    7879          medians[i] = 1;
     
    8384
    8485      // set parameters
    85       ParameterConfigurationParameter.ActualValue.Parameterize(algorithm);
     86      parameterConfiguration.Parameterize(algorithm);
    8687      algorithm.StoreAlgorithmInEachRun = false;
    8788
     
    121122      algorithm.Prepare();
    122123
    123       ParameterConfigurationParameter.ActualValue.AverageExecutionTimes = new ItemList<TimeSpanValue>(executionTimes.Select(t => new TimeSpanValue(TimeSpan.FromMilliseconds(t.Average(ts => ts.TotalMilliseconds)))));
    124       ParameterConfigurationParameter.ActualValue.Repetitions = (IntValue)Repetitions.Clone();
    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());
    130       ParameterConfigurationParameter.ActualValue.Runs = (RunCollection)algorithm.Runs.Clone();
     124      parameterConfiguration.AverageExecutionTimes = new ItemList<TimeSpanValue>(executionTimes.Select(t => new TimeSpanValue(TimeSpan.FromMilliseconds(t.Average(ts => ts.TotalMilliseconds)))));
     125      parameterConfiguration.Repetitions = (IntValue)Repetitions.Clone();
     126      parameterConfiguration.BestQualities = new DoubleArray(qualities.Select(q => q.Min()).ToArray()); // todo: respect Maximization:true/false
     127      parameterConfiguration.AverageQualities = new DoubleArray(qualities.Select(q => q.Average()).ToArray());
     128      parameterConfiguration.WorstQualities = new DoubleArray(qualities.Select(q => q.Max()).ToArray()); // todo: respect Maximization:true/false
     129      parameterConfiguration.QualityVariances = new DoubleArray(qualities.Select(q => q.Variance()).ToArray());
     130      parameterConfiguration.QualityStandardDeviations = new DoubleArray(qualities.Select(q => q.StandardDeviation()).ToArray());
     131      parameterConfiguration.Runs = (RunCollection)algorithm.Runs.Clone();
    131132
    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;
     133      this.QualityParameter.ActualValue = new DoubleValue(NormalizeQualities(parameterConfiguration, medians));
    141134
    142135      return base.Apply();
     136    }
     137
     138    public static double NormalizeQualities(ParameterConfigurationTree parameterConfigurationTree, double[] medians) {
     139      double[] qualitiesNormalized = new double[medians.Length];
     140      for (int i = 0; i < medians.Length; i++) {
     141        qualitiesNormalized[i] = parameterConfigurationTree.AverageQualities[i] / medians[i];
     142      }
     143      parameterConfigurationTree.QualitiesNormalized = new DoubleArray(qualitiesNormalized);
     144      parameterConfigurationTree.AverageQualityNormalized = new DoubleValue(qualitiesNormalized.Average());
     145      return parameterConfigurationTree.AverageQualityNormalized.Value;
    143146    }
    144147
     
    153156    }
    154157  }
    155 
    156   /// <summary>
    157   /// Can execute an algorithm synchronously
    158   /// </summary>
    159   public class AlgorithmExecutor {
    160     private EngineAlgorithm algorithm;
    161     private AutoResetEvent waitHandle = new AutoResetEvent(false);
    162 
    163     public AlgorithmExecutor(EngineAlgorithm algorithm) {
    164       this.algorithm = algorithm;
    165     }
    166 
    167     public void StartSync() {
    168       algorithm.Stopped += new EventHandler(algorithm_Stopped);
    169       algorithm.Paused += new EventHandler(algorithm_Paused);
    170       algorithm.Start();
    171       waitHandle.WaitOne();
    172       waitHandle.Dispose();
    173       algorithm.Stopped -= new EventHandler(algorithm_Stopped);
    174       algorithm.Paused -= new EventHandler(algorithm_Paused);
    175     }
    176 
    177     void algorithm_Paused(object sender, EventArgs e) {
    178       waitHandle.Set();
    179     }
    180 
    181     void algorithm_Stopped(object sender, EventArgs e) {
    182       waitHandle.Set();
    183     }
    184   }
    185158}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj

    r5277 r5281  
    132132    <None Include="Properties\AssemblyInfo.cs.frame" />
    133133    <None Include="HeuristicLabProblemsMetaOptimizationPlugin.cs.frame" />
     134    <Compile Include="Analyzers\MedianQualityAnalyzer.cs" />
    134135    <Compile Include="ConstrainedItemList.cs" />
    135136    <Compile Include="Encoding\NullValue.cs" />
     
    147148    <Compile Include="Encoding\ValueConfigurations\ValueConfiguration.cs" />
    148149    <Compile Include="Encoding\ValueConfigurations\CheckedValueConfigurationCollection.cs" />
     150    <Compile Include="Evaluators\AlgorithmExecutor.cs" />
    149151    <Compile Include="Interfaces\IParameterConfigurationCrossover.cs" />
    150152    <Compile Include="Interfaces\ICheckedValueConfigurationCollection.cs" />
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs

    r5277 r5281  
    9898      get { return Operators.OfType<BestParameterConfigurationAnalyzer>().FirstOrDefault(); }
    9999    }
     100    private MedianQualityAnalyzer MedianQualityAnalyzer {
     101      get { return Operators.OfType<MedianQualityAnalyzer>().FirstOrDefault(); }
     102    }
    100103    #endregion
    101104
     
    158161      Operators.AddRange(ApplicationManager.Manager.GetInstances<IParameterConfigurationOperator>().Cast<IOperator>());
    159162      Operators.Add(new BestParameterConfigurationAnalyzer());
     163      Operators.Add(new MedianQualityAnalyzer());
    160164    }
    161165    private void ParameterizeSolutionCreator() {
     
    167171      if (BestParameterConfigurationAnalyzer != null) {
    168172        BestParameterConfigurationAnalyzer.ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
     173      }
     174      if (MedianQualityAnalyzer != null) {
     175        MedianQualityAnalyzer.ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
    169176      }
    170177    }
Note: See TracChangeset for help on using the changeset viewer.