Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6090


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

#1215

  • added weight parameters for quality, stddev and evaluated solutions
  • lots of fixes
Location:
branches/HeuristicLab.MetaOptimization
Files:
11 edited

Legend:

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

    r6038 r6090  
    1515using HeuristicLab.Data;
    1616using HeuristicLab.Encodings.RealVectorEncoding;
     17using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    1718//using HeuristicLab.Hive.ExperimentManager;
    1819using HeuristicLab.Optimization;
     
    2122using HeuristicLab.PluginInfrastructure.Manager;
    2223using HeuristicLab.Problems.DataAnalysis.Symbolic;
    23 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
    2424using HeuristicLab.Problems.MetaOptimization;
    2525using HeuristicLab.Problems.TestFunctions;
     
    4242  [Application("TestApp")]
    4343  public class TestApp : ApplicationBase {
    44     //private static int metaAlgorithmPopulationSize = 50;
     44    //private static int metaAlgorithmPopulationSize = 30;
    4545    //private static int metaAlgorithmMaxGenerations = 30;
    46     //private static int metaProblemRepetitions = 5;
    47     //private static int baseAlgorithmMaxGenerations = 1000;
     46    //private static int metaProblemRepetitions = 3;
     47    //private static int baseAlgorithmMaxGenerations = 500;
     48    //private static double mutationProbability = 0.10;
    4849
    4950    private static int metaAlgorithmPopulationSize = 10;
    5051    private static int metaAlgorithmMaxGenerations = 20;
     52    private static double metaAlgorithmMutationProbability = 0.10;
    5153    private static int metaProblemRepetitions = 2;
    52     private static int baseAlgorithmMaxGenerations = 50;
    53     private static double mutationProbability = 0.10;
    54 
     54    private static int baseAlgorithmMaxGenerations = 10;
     55    private static int baseAlgorithmPopulationSize = 10;
     56   
    5557    public override void Run() {
    5658      ContentManager.Initialize(new PersistenceContentManager());
     
    6365      //TestDoubleSampling(); return;
    6466      //TestTypeDiscovery();
    65       TestOperators(); return;
     67      //TestOperators(); return;
    6668      //TestCombinations();
    6769      //TestCombinations2();
     
    7880      //TestSymbolicDataAnalysisGrammar(); return;
    7981
    80       MetaOptimizationProblem metaOptimizationProblem = new MetaOptimizationProblem();
     82      //MetaOptimizationProblem metaOptimizationProblem = LoadOptimizationProblem("Meta Optimization Problem (Genetic Programming - Symbolic Regression 3.4 scaled).hl");
     83      //var algorithmVc = metaOptimizationProblem.ParameterConfigurationTree;
     84
     85      var metaOptimizationProblem = new MetaOptimizationProblem();
     86      var algorithmVc = SetupGAAlgorithm(typeof(GeneticAlgorithm), metaOptimizationProblem);
     87
    8188      metaOptimizationProblem.Repetitions = new IntValue(metaProblemRepetitions);
    82       //GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem);
     89      //GeneticAlgorithm metaLevelAlgorithm = GetSequentialMetaGA(metaOptimizationProblem);
    8390      GeneticAlgorithm metaLevelAlgorithm = GetParallelMetaGA(metaOptimizationProblem);
    8491      //GeneticAlgorithm metaLevelAlgorithm = GetHiveParallelMetaGA(metaOptimizationProblem);
    85 
    8692      //EvolutionStrategy metaLevelAlgorithm = GetMetaES(metaOptimizationProblem);
    87 
    88       var algorithmVc = SetupGAAlgorithm(typeof(GeneticAlgorithm), metaOptimizationProblem);
    89 
    90       string info = algorithmVc.ParameterInfoString;
    9193
    9294      //Console.WriteLine("Press enter to start");
     
    103105    }
    104106
     107    private MetaOptimizationProblem LoadOptimizationProblem(string filename) {
     108      return (MetaOptimizationProblem)ContentManager.Load(filename);
     109    }
     110
    105111    private void TestSymbolicDataAnalysisGrammar() {
    106112      var random = new MersenneTwister();
     
    108114      var grammar1 = new TypeCoherentExpressionGrammar();
    109115      var grammar2 = new TypeCoherentExpressionGrammar();
    110      
     116
    111117      Console.WriteLine("========== Grammar1: ==========");
    112118      PrintGrammar(grammar1);
     
    280286      MetaOptimizationProblem metaOptimizationProblem = new MetaOptimizationProblem();
    281287      metaOptimizationProblem.Repetitions = new IntValue(metaProblemRepetitions);
    282       GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem);
     288      GeneticAlgorithm metaLevelAlgorithm = GetSequentialMetaGA(metaOptimizationProblem);
    283289      ParameterConfigurationTree algorithmVc = SetupGAAlgorithm(typeof(GeneticAlgorithm), metaOptimizationProblem);
    284290      Stopwatch sw = new Stopwatch();
     
    459465
    460466
    461       for (int i = 0; i < 1000; i++) {
     467      for (int i = 0; i < 10000; i++) {
    462468        GeneticAlgorithm clonedGa = (GeneticAlgorithm)ga.Clone();
    463469        clonedGa.Name = "CLONED GA";
     
    479485        }
    480486        sw.Reset();
     487        //Console.ReadLine();
    481488      }
    482489    }
     
    670677    }
    671678
    672     private static GeneticAlgorithm GetMetaGA(MetaOptimizationProblem metaOptimizationProblem) {
     679    private static GeneticAlgorithm GetSequentialMetaGA(MetaOptimizationProblem metaOptimizationProblem) {
    673680      GeneticAlgorithm metaLevelAlgorithm = new GeneticAlgorithm();
    674681      metaLevelAlgorithm.PopulationSize.Value = metaAlgorithmPopulationSize;
     
    681688      //metaLevelAlgorithm.Mutator = ((OptionalConstrainedValueParameter<IManipulator>)((IAlgorithm)metaLevelAlgorithm).Parameters["Mutator"]).ValidValues.Where(x => x.GetType() == typeof(ParameterConfigurationAllPositionsManipulator)).Single();
    682689
    683       metaLevelAlgorithm.MutationProbability.Value = mutationProbability;
     690      metaLevelAlgorithm.MutationProbability.Value = metaAlgorithmMutationProbability;
    684691      //metaLevelAlgorithm.Selector = ((OptionalConstrainedValueParameter<ISelector>)((IAlgorithm)metaLevelAlgorithm).Parameters["Selector"]).ValidValues.Where(x => x.GetType() == typeof(LinearRankSelector)).Single();
    685692      //metaLevelAlgorithm.Selector = ((OptionalConstrainedValueParameter<ISelector>)((IAlgorithm)metaLevelAlgorithm).Parameters["Selector"]).ValidValues.Where(x => x.GetType() == typeof(TournamentSelector)).Single();
    686693      //metaLevelAlgorithm.Selector = ((OptionalConstrainedValueParameter<ISelector>)((IAlgorithm)metaLevelAlgorithm).Parameters["Selector"]).ValidValues.Where(x => x.GetType() == typeof(GenderSpecificSelector)).Single();
    687694      //metaLevelAlgorithm.Selector = ((OptionalConstrainedValueParameter<ISelector>)((IAlgorithm)metaLevelAlgorithm).Parameters["Selector"]).ValidValues.Where(x => x.GetType() == typeof(BestSelector)).Single();
    688       metaLevelAlgorithm.Selector = ((OptionalConstrainedValueParameter<ISelector>)((IAlgorithm)metaLevelAlgorithm).Parameters["Selector"]).ValidValues.Where(x => x.GetType() == typeof(ProportionalSelector)).Single();
     695      metaLevelAlgorithm.Selector = ((OptionalConstrainedValueParameter<ISelector>)((IAlgorithm)metaLevelAlgorithm).Parameters["Selector"]).ValidValues.Where(x => x.GetType() == typeof(TournamentSelector)).Single();
     696
     697      metaLevelAlgorithm.SetSeedRandomly.Value = false;
     698      //metaLevelAlgorithm.Seed.Value = new MersenneTwister().Next(0, 1000000);
     699      metaLevelAlgorithm.Seed.Value = 527875;
    689700
    690701      return metaLevelAlgorithm;
     
    692703
    693704    private static GeneticAlgorithm GetParallelMetaGA(MetaOptimizationProblem metaOptimizationProblem) {
    694       GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem);
     705      GeneticAlgorithm metaLevelAlgorithm = GetSequentialMetaGA(metaOptimizationProblem);
    695706      metaLevelAlgorithm.Engine = new ParallelEngine.ParallelEngine();
    696707      return metaLevelAlgorithm;
     
    722733    private static ParameterConfigurationTree SetupGAAlgorithm(Type baseLevelAlgorithmType, MetaOptimizationProblem metaOptimizationProblem) {
    723734      metaOptimizationProblem.AlgorithmType.Value = baseLevelAlgorithmType;
     735     
     736      //metaOptimizationProblem.ProblemType.Value = typeof(SingleObjectiveTestFunctionProblem);
    724737      //metaOptimizationProblem.Problems.Clear();
    725 
    726       //metaOptimizationProblem.ProblemType.Value = typeof(SingleObjectiveTestFunctionProblem);
    727738      //metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
    728739      //  Evaluator = new GriewankEvaluator(),
     
    731742      //metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
    732743      //  Evaluator = new GriewankEvaluator(),
    733       //  ProblemSize = new IntValue(20)
     744      //  ProblemSize = new IntValue(50)
    734745      //});
    735746      //metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
     
    738749      //});
    739750
    740       metaOptimizationProblem.ProblemType.Value = typeof(SymbolicRegressionSingleObjectiveProblem);
    741      
     751      //metaOptimizationProblem.ProblemType.Value = typeof(SymbolicRegressionSingleObjectiveProblem);
     752      //metaOptimizationProblem.Maximization.Value = true;
     753
     754      // tower problem
     755      metaOptimizationProblem.ImportAlgorithm((IAlgorithm)ContentManager.Load("Genetic Programming - Symbolic Regression 3.4_scaled.hl"));
     756      metaOptimizationProblem.Maximization.Value = true;
     757
    742758      ParameterConfigurationTree algorithmVc = metaOptimizationProblem.ParameterConfigurationTree;
    743759      ((IntValue)algorithmVc.AlgorithmConfiguration.ParameterConfigurations.Single(x => x.Name == "MaximumGenerations").ActualValue.Value).Value = baseAlgorithmMaxGenerations;
    744 
    745       //ConfigurePopulationSize(algorithmVc, 15, 20, 1);
     760      ((IntValue)algorithmVc.AlgorithmConfiguration.ParameterConfigurations.Single(x => x.Name == "PopulationSize").ActualValue.Value).Value = baseAlgorithmPopulationSize;
     761     
     762      //ConfigurePopulationSize(algorithmVc, 10, 100, 1);
    746763      //ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.01);
    747764      //ConfigureMutationOperator(algorithmVc);
    748       //ConfigureElites(algorithmVc, 0, 8, 1);
     765      //ConfigureElites(algorithmVc, 0, 10, 1);
    749766      //ConfigureSelectionOperator(algorithmVc, true);
    750767
     
    772789    private static void ConfigureSymbolicExpressionGrammarVc(SymbolicExpressionGrammarValueConfiguration symbolicExpressionGrammarVc) {
    773790      symbolicExpressionGrammarVc.Optimize = true;
    774       foreach (var pc in symbolicExpressionGrammarVc.ParameterConfigurations) {
    775         if (pc.Name != "Constant"
    776           && pc.Name != "Variable"
    777           && pc.Name != "ProgramRootSymbol"
    778           && pc.Name != "StartSymbol") {
    779           pc.Optimize = true;
    780         }
    781       }
    782       //var additionPc = symbolicExpressionGrammarVc.ParameterConfigurations.Single(x => x.Name == "Addition");
    783       //additionPc.Optimize = true;
     791
     792      SetInitialFrequencyValue(symbolicExpressionGrammarVc, "Addition", 1.0);
     793      SetInitialFrequencyValue(symbolicExpressionGrammarVc, "Subtraction", 1.0);
     794      SetInitialFrequencyValue(symbolicExpressionGrammarVc, "Multiplication", 1.0);
     795      SetInitialFrequencyValue(symbolicExpressionGrammarVc, "Division", 1.0);
     796      SetInitialFrequencyValue(symbolicExpressionGrammarVc, "Average", 1.0);
     797
     798      SetInitialFrequencyValue(symbolicExpressionGrammarVc, "IfThenElse", 0.0);
     799      SetInitialFrequencyValue(symbolicExpressionGrammarVc, "GreaterThan", 0.0);
     800      SetInitialFrequencyValue(symbolicExpressionGrammarVc, "LessThan", 0.0);
     801      SetInitialFrequencyValue(symbolicExpressionGrammarVc, "And", 0.0);
     802      SetInitialFrequencyValue(symbolicExpressionGrammarVc, "Or", 0.0);
     803      SetInitialFrequencyValue(symbolicExpressionGrammarVc, "Not", 0.0);
     804
     805      SetInitialFrequencyValue(symbolicExpressionGrammarVc, "Sine", 0.0);
     806      SetInitialFrequencyValue(symbolicExpressionGrammarVc, "Cosine", 0.0);
     807      SetInitialFrequencyValue(symbolicExpressionGrammarVc, "Tangent", 0.0);
     808
     809      OptimizeInitialFrequency(symbolicExpressionGrammarVc, "Logarithm", "InitialFrequency", 0.0, 5.0, 0.01);
     810      OptimizeInitialFrequency(symbolicExpressionGrammarVc, "Power", "InitialFrequency", 0.0, 5.0, 0.01);
     811      OptimizeInitialFrequency(symbolicExpressionGrammarVc, "Root", "InitialFrequency", 0.0, 5.0, 0.01);
     812
     813      OptimizeInitialFrequency(symbolicExpressionGrammarVc, "Variable", "WeightSigma", 0.01, 10.0, 0.01);
     814      OptimizeInitialFrequency(symbolicExpressionGrammarVc, "Variable", "WeightManipulatorSigma", 0.01, 10.0, 0.01);
     815      OptimizeInitialFrequency(symbolicExpressionGrammarVc, "Variable", "MultiplicativeWeightManipulatorSigma", 0.01, 10.0, 0.01);
     816
     817      OptimizeInitialFrequency(symbolicExpressionGrammarVc, "Constant", "ManipulatorSigma", 0.01, 10.0, 0.01);
     818      OptimizeInitialFrequency(symbolicExpressionGrammarVc, "Constant", "MultiplicativeManipulatorSigma", 0.01, 10.0, 0.01);
     819    }
     820
     821    private static void SetInitialFrequencyValue(SymbolicExpressionGrammarValueConfiguration symbolicExpressionGrammarVc, string symbolName, double value) {
     822      ((Symbol)symbolicExpressionGrammarVc.ParameterConfigurations.Single(x => x.Name == symbolName).ActualValue.Value).InitialFrequency = value;
     823    }
     824
     825    private static void OptimizeInitialFrequency(SymbolicExpressionGrammarValueConfiguration symbolicExpressionGrammarVc, string symbolName, string parameterName, double lower, double upper, double step) {
     826      var pc = symbolicExpressionGrammarVc.ParameterConfigurations.Single(x => x.Name == symbolName);
     827      pc.Optimize = true;
     828      var vc = (SymbolValueConfiguration)pc.ValueConfigurations.Single();
     829      var parameterPc = vc.ParameterConfigurations.Single(x => x.Name == parameterName);
     830      parameterPc.Optimize = true;
     831      parameterPc.ValueConfigurations.Clear();
     832      var rvc = new RangeValueConfiguration(new DoubleValue(5.0), typeof(DoubleValue));
     833      rvc.Optimize = true;
     834      ((DoubleValueRange)rvc.RangeConstraint).LowerBound.Value = lower;
     835      ((DoubleValueRange)rvc.RangeConstraint).UpperBound.Value = upper;
     836      ((DoubleValueRange)rvc.RangeConstraint).StepSize.Value = step;
     837      parameterPc.ValueConfigurations.Add(rvc);
    784838    }
    785839
     
    937991      string outputPath = Path.Combine(path, string.Format("{0} - Console.txt", id));
    938992
    939       ContentManager.Save((IStorableContent)metaLevelAlgorithm, resultPath+"-before.hl", true);
    940 
     993      ContentManager.Save((IStorableContent)metaLevelAlgorithm, resultPath + "-before.hl", true);
     994     
    941995      using (var sw = new StreamWriter(outputPath)) {
    942996        sw.AutoFlush = true;
     
    9471001        sb1.AppendFormat("Meta.Repetitions   : {0}\n", metaProblemRepetitions);
    9481002        sb1.AppendFormat("Meta.MutProb       : {0}\n", ((GeneticAlgorithm)metaLevelAlgorithm).MutationProbability.Value);
     1003        sb1.AppendFormat("Meta.Seed          : {0}\n", ((GeneticAlgorithm)metaLevelAlgorithm).Seed.Value);
    9491004        sb1.AppendFormat("Base.MaxGenerations: {0}\n", baseAlgorithmMaxGenerations);
     1005
    9501006        sb1.AppendLine("Problems:");
    9511007        foreach (var prob in ((MetaOptimizationProblem)metaLevelAlgorithm.Problem).Problems) {
     
    9881044                var orderedRuns = rc.OrderBy(x => x.Results["AverageQualityNormalized"]);
    9891045
    990                 TableBuilder tb = new TableBuilder("QNorm", "Qualities"/*, "PoSi"*/ /*,"MutRa"*/ /*,"Eli", "SelOp",*/ /*"MutOp"*//*, "NrSelSubScopes"*/);
     1046                //TableBuilder tb = new TableBuilder("QNorm", "Qualities"/*, "PoSi"*/ /*,"MutRa"*/ /*,"Eli", "SelOp",*/ /*"MutOp"*//*, "NrSelSubScopes"*/);
     1047                //foreach (IRun run in orderedRuns) {
     1048                //  //string selector;
     1049                //  //if (run.Parameters["Selector"] is TournamentSelector) {
     1050                //  //  selector = string.Format("{0} ({1})", run.Parameters["Selector"].ToString(), ((TournamentSelector)run.Parameters["Selector"]).GroupSizeParameter.Value.ToString());
     1051                //  //} else {
     1052                //  //  selector = string.Format("{0}", run.Parameters["Selector"].ToString());
     1053                //  //}
     1054
     1055                //  tb.AppendRow(
     1056                //    ((DoubleValue)run.Results["AverageQualityNormalized"]).Value.ToString("#0.0000")
     1057                //    ,((DoubleArray)run.Results["RunsAverageQualities"]).ToString()
     1058                //    //,((IntValue)run.Parameters["PopulationSize"]).Value.ToString()
     1059                //    //,((DoubleValue)run.Parameters["MutationProbability"]).Value.ToString("0.0000")
     1060                //    //,((IntValue)run.Parameters["Elites"]).Value.ToString()
     1061                //    //,Shorten(selector, 20)
     1062                //    //,Shorten(run.Parameters.ContainsKey("Mutator") ? run.Parameters["Mutator"].ToString() : "null", 40)
     1063                //    //,((ISelector)run.Parameters["Selector"]).NumberOfSelectedSubScopesParameter.Value.ToString()
     1064                //    );
     1065                //}
     1066                //sb.AppendLine(tb.ToString());
     1067
     1068                var tb = new TableBuilder("QNorm", "Qualities", "StdDevs", "Evaluations", "Parameters");
    9911069                foreach (IRun run in orderedRuns) {
    992                   //string selector;
    993                   //if (run.Parameters["Selector"] is TournamentSelector) {
    994                   //  selector = string.Format("{0} ({1})", run.Parameters["Selector"].ToString(), ((TournamentSelector)run.Parameters["Selector"]).GroupSizeParameter.Value.ToString());
    995                   //} else {
    996                   //  selector = string.Format("{0}", run.Parameters["Selector"].ToString());
    997                   //}
    998 
    9991070                  tb.AppendRow(
    10001071                    ((DoubleValue)run.Results["AverageQualityNormalized"]).Value.ToString("#0.0000")
    1001                     ,((DoubleArray)run.Results["RunsAverageQualities"]).ToString()
    1002                     //,((IntValue)run.Parameters["PopulationSize"]).Value.ToString()
    1003                     //,((DoubleValue)run.Parameters["MutationProbability"]).Value.ToString("0.0000")
    1004                     //,((IntValue)run.Parameters["Elites"]).Value.ToString()
    1005                     //,Shorten(selector, 20)
    1006                     //,Shorten(run.Parameters.ContainsKey("Mutator") ? run.Parameters["Mutator"].ToString() : "null", 40)
    1007                     //,((ISelector)run.Parameters["Selector"]).NumberOfSelectedSubScopesParameter.Value.ToString()
     1072                    , ((DoubleArray)run.Results["RunsAverageQualities"]).ToString()
     1073                    , ((DoubleArray)run.Results["RunsQualityStandardDeviations"]).ToString()
     1074                    , ((DoubleArray)run.Results["RunsAverageEvaluatedSolutions"]).ToString()
     1075                    , run.Name
    10081076                    );
    10091077                }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestParameterConfigurationAnalyzer.cs

    r6018 r6090  
    9898      }
    9999
    100       // population
     100      // population (TODO: extract into PopulationAnalyzer)
    101101      int i = 0;
    102102      RunCollection rc = new RunCollection();
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/ReferenceQualityAnalyzer.cs

    r6018 r6090  
    4141    }
    4242
     43    public LookupParameter<DoubleValue> QualityWeightParameter {
     44      get { return (LookupParameter<DoubleValue>)Parameters[MetaOptimizationProblem.QualityWeightParameterName]; }
     45    }
     46    public LookupParameter<DoubleValue> StandardDeviationWeightParameter {
     47      get { return (LookupParameter<DoubleValue>)Parameters[MetaOptimizationProblem.StandardDeviationWeightParameterName]; }
     48    }
     49    public LookupParameter<DoubleValue> EvaluatedSolutionsWeightParameter {
     50      get { return (LookupParameter<DoubleValue>)Parameters[MetaOptimizationProblem.EvaluatedSolutionsWeightParameterName]; }
     51    }
     52
    4353    public ReferenceQualityAnalyzer()
    4454      : base() {
     
    4959      Parameters.Add(new LookupParameter<DoubleArray>("ReferenceQualityDeviations", ""));
    5060      Parameters.Add(new LookupParameter<DoubleArray>("ReferenceEvaluatedSolutionAverages", ""));
    51       Parameters.Add(new LookupParameter<ConstrainedItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName, ""));
     61      Parameters.Add(new LookupParameter<ConstrainedItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName));
    5262      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized."));
     63      Parameters.Add(new LookupParameter<DoubleValue>(MetaOptimizationProblem.QualityWeightParameterName));
     64      Parameters.Add(new LookupParameter<DoubleValue>(MetaOptimizationProblem.StandardDeviationWeightParameterName));
     65      Parameters.Add(new LookupParameter<DoubleValue>(MetaOptimizationProblem.EvaluatedSolutionsWeightParameterName));
    5366    }
    5467
     
    6578      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
    6679      bool maximization = MaximizationParameter.ActualValue.Value;
     80      double qualityWeight = QualityWeightParameter.ActualValue.Value;
     81      double standardDeviationWeight = StandardDeviationWeightParameter.ActualValue.Value;
     82      double evaluatedSolutionsWeight = EvaluatedSolutionsWeightParameter.ActualValue.Value;
    6783
    6884      if (ReferenceQualityAveragesParameter.ActualValue == null) {
     
    7692        ReferenceEvaluatedSolutionAveragesParameter.ActualValue = referenceEvaluatedSolutionAverages;
    7793
    78         NormalizePopulation(solutions, qualities, referenceQualityAverages, referenceQualityDeviations, referenceEvaluatedSolutionAverages, 1, 1, 1, maximization);
     94        NormalizePopulation(solutions, qualities, referenceQualityAverages, referenceQualityDeviations, referenceEvaluatedSolutionAverages, qualityWeight, standardDeviationWeight, evaluatedSolutionsWeight, maximization);
    7995
    8096        results.Add(new Result("ReferenceQualities", referenceQualityAverages));
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/SolutionCacheAnalyzer.cs

    r6018 r6090  
    7171        }
    7272
    73         var runCollection = allRuns.Single(x => x.Key.Value == key).Value;
    74         foreach (var run in solution.Runs) {
    75           if (!((BoolValue)run.Results["Meta.FromCache"]).Value || first) {
    76             run.Results["Meta.FromCache"] = new BoolValue(true);
    77             runCollection.Add(run);
     73        if (solution.Runs != null) { // Runs is null when a base-level algorithm exception happened due to invalid parameters
     74          var runCollection = allRuns.Single(x => x.Key.Value == key).Value;
     75          foreach (var run in solution.Runs) {
     76            if (!((BoolValue)run.Results["Meta.FromCache"]).Value || first) {
     77              run.Results["Meta.FromCache"] = new BoolValue(true);
     78              runCollection.Add(run);
     79            }
    7880          }
    7981        }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/DoubleValueRange.cs

    r5522 r6090  
    11using System;
    22using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
     3using HeuristicLab.Common;
     4using HeuristicLab.Core;
    55using HeuristicLab.Data;
    6 using HeuristicLab.Common;
    76using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    8 using HeuristicLab.Core;
    97
    108namespace HeuristicLab.Problems.MetaOptimization {
     
    1210  public class DoubleValueRange : Range<DoubleValue> {
    1311
     12    public override DoubleValue LowerBound {
     13      get {
     14        return base.LowerBound;
     15      }
     16      set {
     17        base.LowerBound = value;
     18      }
     19    }
     20   
    1421    public DoubleValueRange(DoubleValue lowerBound, DoubleValue upperBound, DoubleValue stepSize) : base(lowerBound, upperBound, stepSize) { }
    1522    public DoubleValueRange() { }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/Range.cs

    r5576 r6090  
    1212    [Storable]
    1313    private T lowerBound;
    14     public T LowerBound {
     14    public virtual T LowerBound {
    1515      get { return lowerBound; }
    1616      set {
     
    3030    [Storable]
    3131    private T upperBound;
    32     public T UpperBound {
     32    public virtual T UpperBound {
    3333      get { return upperBound; }
    3434      set {
     
    4848    [Storable]
    4949    private T stepSize;
    50     public T StepSize {
     50    public virtual T StepSize {
    5151      get { return stepSize; }
    5252      set {
     
    197197      if (random.NextDouble() < 0.1) {
    198198        if (random.NextDouble() < 0.5) {
    199           return LowerBound;
     199          return (T)LowerBound.Clone();
    200200        } else {
    201           return UpperBound;
     201          return (T)UpperBound.Clone();
    202202        }
    203203      }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/RangeValueConfiguration.cs

    r5653 r6090  
    3636      : base(value, valueDataType) {
    3737      if (actualValue.ValueDataType == typeof(IntValue)) {
    38         RangeConstraint = new IntValueRange(new IntValue(0), (IntValue)value, new IntValue(1));
     38        RangeConstraint = new IntValueRange(new IntValue(0), (IntValue)value.Clone(), new IntValue(1));
    3939      } else if (actualValue.ValueDataType == typeof(DoubleValue)) {
    40         RangeConstraint = new DoubleValueRange(new DoubleValue(0), (DoubleValue)value, new DoubleValue(0.01));
     40        RangeConstraint = new DoubleValueRange(new DoubleValue(0), (DoubleValue)value.Clone(), new DoubleValue(0.01));
    4141      } else if (actualValue.ValueDataType == typeof(PercentValue)) {
    4242        RangeConstraint = new PercentValueRange(new PercentValue(0), new PercentValue(1), new PercentValue(0.01));
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/AlgorithmEvaluator.cs

    r6024 r6090  
    1 using System;
    2 using System.Diagnostics;
    3 using System.Linq;
     1using System.Linq;
    42using HeuristicLab.Common;
    53using HeuristicLab.Core;
     
    108using HeuristicLab.Parameters;
    119using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    12 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
    1310
    1411namespace HeuristicLab.Problems.MetaOptimization {
     
    3330      get { return (ILookupParameter<ParameterConfigurationTree>)Parameters["ParameterConfigurationTree"]; }
    3431    }
    35     public IValueParameter<IItemList<IRun>> RunsParameter {
    36       get { return (IValueParameter<IItemList<IRun>>)Parameters["Runs"]; }
     32    //public IValueParameter<IItemList<IRun>> RunsParameter {
     33    //  get { return (IValueParameter<IItemList<IRun>>)Parameters["Runs"]; }
     34    //}
     35    public LookupParameter<ResultCollection> ResultsParameter {
     36      get { return (LookupParameter<ResultCollection>)Parameters["Results"]; }
    3737    }
    3838    #endregion
     
    4747      Parameters.Add(new LookupParameter<IntValue>("RepetitionIndex", ""));
    4848      Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", ""));
    49       Parameters.Add(new ValueParameter<IItemList<IRun>>("Runs", ""));
     49      Parameters.Add(new LookupParameter<ResultCollection>("Results", ""));
    5050    }
    5151    protected AlgorithmEvaluator(AlgorithmEvaluator original, Cloner cloner) : base(original, cloner) { }
     
    5555
    5656    public override IOperation Apply() {
     57      ItemDictionary<StringValue, RunCollection> solutionCache = ResultsParameter.ActualValue.ContainsKey("SolutionCache") ? (ItemDictionary<StringValue, RunCollection>)ResultsParameter.ActualValue["SolutionCache"].Value : null;
     58      ParameterConfigurationTree parameterConfiguration = ParameterConfigurationParameter.ActualValue;
    5759      IAlgorithm algorithm = AlgorithmParameter.ActualValue;
     60      int repetitionIndex = RepetitionIndexParameter.ActualValue.Value;
    5861
    59       #region Debug Code for SymbolicRegressionGrammar
    60       var srp = (SymbolicRegressionSingleObjectiveProblem)algorithm.Problem;
    61       //Console.WriteLine("Evaluating Grammar: " + PrintGrammar(srp.SymbolicExpressionTreeGrammar));
    62       #endregion
    63 
    64       var sw = new Stopwatch();
    65       sw.Start();
    66       //// prepare and clear is needed, if the algorithm has been started and stopped before (this happens when meta level algorithm is paused)
    67       //algorithm.Prepare(); // <--- SHOULD NOT HAPPEN!
    68       //algorithm.Runs.Clear();
    69 
    70       algorithm.StartSync(CancellationToken);
    71       sw.Stop();
    72       Console.WriteLine("{0},{1}: {2} (Grammar: {3})", ProblemIndexParameter.ActualValue.Value, RepetitionIndexParameter.ActualValue.Value, sw.Elapsed, PrintGrammar(srp.SymbolicExpressionTreeGrammar));
    73 
    74       RunsParameter.Value = new ItemList<IRun>(algorithm.Runs);
    75 
     62      if (solutionCache != null && solutionCache.Count(x => x.Key.Value == parameterConfiguration.ParameterInfoString) > 0) {
     63        algorithm.Runs.Add(solutionCache.Single(x => x.Key.Value == parameterConfiguration.ParameterInfoString).Value.ElementAt(repetitionIndex));
     64      } else {
     65        algorithm.StartSync(CancellationToken);
     66      }
    7667      return base.Apply();
    77     }
    78 
    79     /// <summary>
    80     /// This method should repair an invalid parameterConfiguration.
    81     /// The strategy is to just randomize parameter settings. It's not guaranteed to be a vaild setting
    82     /// </summary>
    83     private void Repair(ParameterConfigurationTree parameterConfiguration, IRandom random) {
    84       parameterConfiguration.Randomize(random);
    8568    }
    8669
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/AlgorithmRunsAnalyzer.cs

    r6038 r6090  
    5454    public LookupParameter<BoolValue> MaximizationParameter {
    5555      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     56    }
     57    public LookupParameter<DoubleValue> QualityWeightParameter {
     58      get { return (LookupParameter<DoubleValue>)Parameters[MetaOptimizationProblem.QualityWeightParameterName]; }
     59    }
     60    public LookupParameter<DoubleValue> StandardDeviationWeightParameter {
     61      get { return (LookupParameter<DoubleValue>)Parameters[MetaOptimizationProblem.StandardDeviationWeightParameterName]; }
     62    }
     63    public LookupParameter<DoubleValue> EvaluatedSolutionsWeightParameter {
     64      get { return (LookupParameter<DoubleValue>)Parameters[MetaOptimizationProblem.EvaluatedSolutionsWeightParameterName]; }
    5665    }
    5766    #endregion
     
    7584      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("RepetitionIndex", "The index of the repetition"));
    7685      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized."));
     86      Parameters.Add(new LookupParameter<DoubleValue>(MetaOptimizationProblem.QualityWeightParameterName));
     87      Parameters.Add(new LookupParameter<DoubleValue>(MetaOptimizationProblem.StandardDeviationWeightParameterName));
     88      Parameters.Add(new LookupParameter<DoubleValue>(MetaOptimizationProblem.EvaluatedSolutionsWeightParameterName));
    7789    }
    7890    protected AlgorithmRunsAnalyzer(AlgorithmRunsAnalyzer original, Cloner cloner)
     
    92104      bool maximization = MaximizationParameter.ActualValue.Value;
    93105      int repetitions = RepetitionsParameter.ActualValue.Value;
     106      double qualityWeight = QualityWeightParameter.ActualValue.Value;
     107      double standardDeviationWeight = StandardDeviationWeightParameter.ActualValue.Value;
     108      double evaluatedSolutionsWeight = EvaluatedSolutionsWeightParameter.ActualValue.Value;
    94109      var resultNames = new List<string> { "BestQuality", "Execution Time", "EvaluatedSolutions" };
    95110      int currentGeneration = GenerationsParameter.ActualValue != null ? GenerationsParameter.ActualValue.Value : 0;
     
    149164        parameterConfiguration.Runs = runs;
    150165
    151         this.QualityParameter.ActualValue = new DoubleValue(MetaOptimizationUtil.Normalize(parameterConfiguration, referenceQualityAverages, referenceQualityDeviations, referenceEvaluatedSolutionAverages, 1, 0.1, 1, maximization));
     166        this.QualityParameter.ActualValue = new DoubleValue(MetaOptimizationUtil.Normalize(parameterConfiguration, referenceQualityAverages, referenceQualityDeviations, referenceEvaluatedSolutionAverages, qualityWeight, standardDeviationWeight, evaluatedSolutionsWeight, maximization));
    152167      } else {
    153168        // something terrible happened -> most probably due to invalid parameters.
     
    155170        double penaltyValue;
    156171        if (maximization)
    157           penaltyValue = results.ContainsKey("CurrentWorstQuality") ? ((DoubleValue)results["CurrentWorstQuality"]).Value : referenceQualityAverages.Min();
     172          penaltyValue = results.ContainsKey("CurrentWorstQuality") ? ((DoubleValue)results["CurrentWorstQuality"].Value).Value : referenceQualityAverages.Min();
    158173        else
    159           penaltyValue = results.ContainsKey("CurrentWorstQuality") ? ((DoubleValue)results["CurrentWorstQuality"]).Value : referenceQualityAverages.Max();
     174          penaltyValue = results.ContainsKey("CurrentWorstQuality") ? ((DoubleValue)results["CurrentWorstQuality"].Value).Value : referenceQualityAverages.Max();
     175       
    160176        this.QualityParameter.ActualValue = new DoubleValue(penaltyValue);
     177        parameterConfiguration.Quality = new DoubleValue(penaltyValue);
     178
     179        parameterConfiguration.AverageExecutionTimes = new ItemList<TimeSpanValue>(Enumerable.Repeat(new TimeSpanValue(TimeSpan.Zero), problems.Count));
     180        parameterConfiguration.AverageEvaluatedSolutions = new DoubleArray(Enumerable.Repeat(0.0, problems.Count).ToArray());
     181        parameterConfiguration.Repetitions = new IntValue(repetitions);
     182        parameterConfiguration.AverageQualities = new DoubleArray(Enumerable.Repeat(0.0, problems.Count).ToArray());
     183        parameterConfiguration.BestQualities = new DoubleArray(Enumerable.Repeat(0.0, problems.Count).ToArray());
     184        parameterConfiguration.WorstQualities = new DoubleArray(Enumerable.Repeat(0.0, problems.Count).ToArray());
     185        parameterConfiguration.QualityVariances = new DoubleArray(Enumerable.Repeat(0.0, problems.Count).ToArray());
     186        parameterConfiguration.QualityStandardDeviations = new DoubleArray(Enumerable.Repeat(0.0, problems.Count).ToArray());
     187        parameterConfiguration.Runs = null;
    161188      }
    162189
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs

    r6017 r6090  
    5151    public const string IntValueCrossoverParameterName = "IntValueCrossover";
    5252    public const string DoubleValueCrossoverParameterName = "DoubleValueCrossover";
     53    public const string QualityWeightParameterName = "QualityWeight";
     54    public const string StandardDeviationWeightParameterName = "StandardDeviationWeight";
     55    public const string EvaluatedSolutionsWeightParameterName = "EvaluatedSolutionsWeight";
     56
    5357
    5458    #region Parameter Properties
     
    134138      var validIntCrossovers = new ItemSet<IIntValueCrossover>(ApplicationManager.Manager.GetInstances<IIntValueCrossover>());
    135139      var validDoubleCrossovers = new ItemSet<IDoubleValueCrossover>(ApplicationManager.Manager.GetInstances<IDoubleValueCrossover>());
    136       Parameters.Add(new ConstrainedValueParameter<IIntValueManipulator>(IntValueManipulatorParameterName, "", validIntManipulators, validIntManipulators.Where(x => x.GetType() == typeof(NormalIntValueManipulator)).SingleOrDefault()));
    137       Parameters.Add(new ConstrainedValueParameter<IDoubleValueManipulator>(DoubleValueManipulatorParameterName, "", validDoubleManipulators, validDoubleManipulators.Where(x => x.GetType() == typeof(NormalDoubleValueManipulator)).SingleOrDefault()));
    138       Parameters.Add(new ConstrainedValueParameter<IIntValueCrossover>(IntValueCrossoverParameterName, "", validIntCrossovers, validIntCrossovers.Where(x => x.GetType() == typeof(NormalIntValueCrossover)).SingleOrDefault()));
    139       Parameters.Add(new ConstrainedValueParameter<IDoubleValueCrossover>(DoubleValueCrossoverParameterName, "", validDoubleCrossovers, validDoubleCrossovers.Where(x => x.GetType() == typeof(NormalDoubleValueCrossover)).SingleOrDefault()));
     140      Parameters.Add(new ConstrainedValueParameter<IIntValueManipulator>(IntValueManipulatorParameterName, validIntManipulators, validIntManipulators.Where(x => x.GetType() == typeof(NormalIntValueManipulator)).SingleOrDefault()));
     141      Parameters.Add(new ConstrainedValueParameter<IDoubleValueManipulator>(DoubleValueManipulatorParameterName, validDoubleManipulators, validDoubleManipulators.Where(x => x.GetType() == typeof(NormalDoubleValueManipulator)).SingleOrDefault()));
     142      Parameters.Add(new ConstrainedValueParameter<IIntValueCrossover>(IntValueCrossoverParameterName, validIntCrossovers, validIntCrossovers.Where(x => x.GetType() == typeof(NormalIntValueCrossover)).SingleOrDefault()));
     143      Parameters.Add(new ConstrainedValueParameter<IDoubleValueCrossover>(DoubleValueCrossoverParameterName, validDoubleCrossovers, validDoubleCrossovers.Where(x => x.GetType() == typeof(NormalDoubleValueCrossover)).SingleOrDefault()));
     144
     145      Parameters.Add(new ValueParameter<DoubleValue>(QualityWeightParameterName, new DoubleValue(1)));
     146      Parameters.Add(new ValueParameter<DoubleValue>(StandardDeviationWeightParameterName, new DoubleValue(0.01)));
     147      Parameters.Add(new ValueParameter<DoubleValue>(EvaluatedSolutionsWeightParameterName, new DoubleValue(0.0005)));
    140148
    141149      Maximization = new BoolValue(false);
     
    182190    private void InitializeOperators() {
    183191      Operators.AddRange(ApplicationManager.Manager.GetInstances<IParameterConfigurationOperator>().Cast<IOperator>());
     192      Operators.Add(new ReferenceQualityAnalyzer());
    184193      Operators.Add(new BestParameterConfigurationAnalyzer());
    185       Operators.Add(new ReferenceQualityAnalyzer());
    186194      Operators.Add(new SolutionCacheAnalyzer());
    187195      Operators.Add(new PMOPopulationDiversityAnalyzer());
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationUtil.cs

    r6018 r6090  
    5757      parameterConfigurationTree.NormalizedEvaluatedSolutions = new DoubleArray(evaluatedSolutionAveragesNormalized);
    5858
    59       double qualityAveragesNormalizedValue = qualityAveragesNormalized.Average() * qualityAveragesWeight;
    60       double qualityDeviationsNormalizedValue = qualityDeviationsNormalized.Average() * qualityDeviationsWeight;
    61       double evaluatedSolutionAveragesNormalizedValue = evaluatedSolutionAveragesNormalized.Average() * evaluatedSolutionsWeight;
     59      double qualityAveragesNormalizedValue = qualityAveragesNormalized.Average();
     60      double qualityDeviationsNormalizedValue = qualityDeviationsNormalized.Average();
     61      double evaluatedSolutionAveragesNormalizedValue = evaluatedSolutionAveragesNormalized.Average();
    6262
     63      // deviation and evaluatedSolutions are always minimization problems. so if maximization=true, flip the values around 1.0 (e.g. 1.15 -> 0.85)
    6364      if (maximization) {
    64         // deviation and evaluatedSolutions are always minimization problems. so if maximization=true, flip the values around 1.0 (e.g. 1.15 -> 0.85)
    6565        qualityDeviationsNormalizedValue -= (qualityDeviationsNormalizedValue - 1) * 2;
    6666        evaluatedSolutionAveragesNormalizedValue -= (evaluatedSolutionAveragesNormalizedValue - 1) * 2;
    6767      }
    6868
     69      // apply weights
    6970      qualityAveragesNormalizedValue *= qualityAveragesWeight;
    7071      qualityDeviationsNormalizedValue *= qualityDeviationsWeight;
    7172      evaluatedSolutionAveragesNormalizedValue *= evaluatedSolutionsWeight;
    7273
    73       parameterConfigurationTree.Quality = new DoubleValue(new double[] {qualityAveragesNormalizedValue, qualityDeviationsNormalizedValue, evaluatedSolutionAveragesNormalizedValue}.Average());
    74      
     74      double weightSum = qualityAveragesWeight + qualityDeviationsWeight + evaluatedSolutionsWeight;
     75      parameterConfigurationTree.Quality = new DoubleValue((qualityAveragesNormalizedValue + qualityDeviationsNormalizedValue + evaluatedSolutionAveragesNormalizedValue) / weightSum);
     76
    7577      return parameterConfigurationTree.Quality.Value;
    7678    }
Note: See TracChangeset for help on using the changeset viewer.