Free cookie consent management tool by TermsFeed Policy Generator

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/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.