Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/23/11 12:47:33 (13 years ago)
Author:
cneumuel
Message:

#1215

  • changed ordering of parameter combinations to make them better readable
  • changed handling of invalid parameter settings from penalty approach to repair approach
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/ParameterConfigurationEvaluator.cs

    r5340 r5357  
    2121  [Item("ParameterConfigurationEvaluator", "A base class for operators which evaluate Meta Optimization solutions.")]
    2222  [StorableClass]
    23   public class ParameterConfigurationEvaluator : SingleSuccessorOperator, IParameterConfigurationEvaluator {
    24     private const double PenaltyQuality = 100000.0; // todo: use something better
    25 
     23  public class ParameterConfigurationEvaluator : SingleSuccessorOperator, IParameterConfigurationEvaluator, IStochasticOperator {
     24    public ILookupParameter<IRandom> RandomParameter {
     25      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
     26    }
    2627    public ILookupParameter<DoubleValue> QualityParameter {
    2728      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
     
    5657    public ParameterConfigurationEvaluator()
    5758      : base() {
     59      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used to initialize the new random permutation."));
    5860      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The evaluated quality of the ParameterVector."));
    5961      Parameters.Add(new LookupParameter<TypeValue>(MetaOptimizationProblem.AlgorithmTypeParameterName, "Missing description."));
     
    7678
    7779    public override IOperation Apply() {
     80      IRandom random = RandomParameter.ActualValue;
    7881      ParameterConfigurationTree parameterConfiguration = ParameterConfigurationParameter.ActualValue;
    7982      IAlgorithm algorithm = (IAlgorithm)Activator.CreateInstance(AlgorithmTypeParameter.ActualValue.Value);
     
    8790        Console.WriteLine("Used Cache for {0}", parameterConfiguration.ParameterInfoString);
    8891      } else {
    89         runs = ExecuteAlgorithm(parameterConfiguration, algorithm, problems);
     92        do {
     93          runs = ExecuteAlgorithm(parameterConfiguration, algorithm, problems, Repetitions.Value, GenerationsParameter.ActualValue != null ? GenerationsParameter.ActualValue.Value : 0);
     94          if (runs == null) {
     95            Repair(parameterConfiguration, random);
     96            parameterConfiguration.Parameterize(algorithm);
     97          }
     98        } while (runs == null);
    9099      }
    91100
     
    111120
    112121      return base.Apply();
     122    }
     123
     124    /// <summary>
     125    /// This method should repair an invalid parameterConfiguration.
     126    /// The strategy is to just randomize parameter settings. It's not guaranteed to be a vaild setting
     127    /// </summary>
     128    private void Repair(ParameterConfigurationTree parameterConfiguration, IRandom random) {
     129      parameterConfiguration.Randomize(random);
    113130    }
    114131
     
    127144    }
    128145
    129     private RunCollection ExecuteAlgorithm(ParameterConfigurationTree parameterConfiguration, IAlgorithm algorithm, IItemList<IProblem> problems) {
     146    /// <summary>
     147    /// Executes an algorithm
     148    /// </summary>
     149    /// <param name="parameterConfiguration"></param>
     150    /// <param name="algorithm"></param>
     151    /// <param name="problems"></param>
     152    /// <returns></returns>
     153    private static RunCollection ExecuteAlgorithm(ParameterConfigurationTree parameterConfiguration, IAlgorithm algorithm, IItemList<IProblem> problems, int repetitions, int currentGeneration) {
    130154      IAlgorithm algorithmClone = (IAlgorithm)algorithm.Clone();
    131155      var parameterNames = new List<string>();
     
    145169        algorithmClone.Problem = (IProblem)problem.Clone();
    146170
    147         for (int i = 0; i < Repetitions.Value; i++) {
     171        for (int i = 0; i < repetitions; i++) {
    148172          algorithmClone.Prepare();
    149173
     
    152176
    153177          if (algorithmClone.ExecutionState == ExecutionState.Paused) {
    154             // this parametercombination was bad. set penalty for this solution
    155             // TODO!
     178            // the parameter settings were invalid.
     179            // (1) set penalty for this solution.
     180            //     it's difficult to create penalty values for BestQuality and ExecutionTime. Maybe ReferenceQuality * X (but what about ExecutionTime?)
     181            //     therefore use repair instead.
     182           
     183            // (2) repair and retry
     184            return null;
    156185          }
    157186          int problemIndex = problems.IndexOf(problem) + 1;
     
    159188          CleanRun(run, resultNames, parameterNames);
    160189          run.Results.Add("Meta.FromCache", new BoolValue(false));
    161           run.Results.Add("Meta.Generation", new IntValue(GenerationsParameter.ActualValue != null ? GenerationsParameter.ActualValue.Value : 0));
     190          run.Results.Add("Meta.Generation", new IntValue(currentGeneration));
    162191          run.Results.Add("Meta.ProblemIndex", new IntValue(problemIndex));
    163192          int runCountOfThisProblem = algorithmClone.Runs.Where(x => ((IntValue)x.Results["Meta.ProblemIndex"]).Value == problemIndex).Count();
     
    173202    /// only keep the results which are important and the parameters which were optimized
    174203    /// </summary>
    175     private void CleanRun(IRun run, IEnumerable<string> resultsToKeep, IEnumerable<string> parametersToKeep) {
     204    private static void CleanRun(IRun run, IEnumerable<string> resultsToKeep, IEnumerable<string> parametersToKeep) {
    176205      var resultsToRemove = new List<string>();
    177206      var parametersToRemove = new List<string>();
Note: See TracChangeset for help on using the changeset viewer.