Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5357


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
Location:
branches/HeuristicLab.MetaOptimization
Files:
4 edited

Legend:

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

    r5340 r5357  
    3939    static void Main(string[] args) {
    4040      ContentManager.Initialize(new PersistenceContentManager());
    41 
     41     
    4242      //TestTableBuilder();
    4343      //TestShorten();
     
    5151      //TestCombinations3();
    5252      //TestEnumeratorCollectionEnumerator();
    53       //TestCombinations4();
     53      //TestCombinations4(); return;
    5454      //TestAlgorithmPerformanceIssue();
    5555      //TestWaitAny();
     
    566566      });
    567567
    568       ConfigurePopulationSize(algorithmVc, 12, 100, 1);
     568      ConfigurePopulationSize(algorithmVc, 0, 20, 1);
    569569      //ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.01);
    570570      //ConfigureMutationOperator(algorithmVc);
    571       ConfigureElites(algorithmVc, 0, 10, 1);
     571      ConfigureElites(algorithmVc, 0, 30, 1);
    572572      //ConfigureSelectionOperator(algorithmVc, true);
    573573      return algorithmVc;
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterCombinationsEnumerator.cs

    r5277 r5357  
    109109            }
    110110          }
     111          enumerators.Reverse(); // this makes the list of combinations better readable
    111112        }
    112113      }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/ValueConfiguration.cs

    r5340 r5357  
    214214      get {
    215215        StringBuilder sb = new StringBuilder();
    216         if (this.Optimize) {
    217           if (this.ParameterConfigurations.Count > 0) {
    218             var parameterInfos = new List<string>();
    219             foreach (var pc in this.ParameterConfigurations) {
    220               if (pc.Optimize) parameterInfos.Add(pc.ParameterInfoString);
    221             }
    222             sb.Append(string.Join(", ", parameterInfos.ToArray()));
    223           }
     216        if (this.Optimize && this.ParameterConfigurations.Count > 0) {
     217          var parameterInfos = new List<string>();
     218          foreach (var pc in this.ParameterConfigurations) {
     219            if (pc.Optimize) parameterInfos.Add(pc.ParameterInfoString);
     220          }
     221          sb.Append(string.Join(", ", parameterInfos.ToArray()));
    224222        }
    225223        return sb.ToString();
     
    273271      var list = new List<IOptimizable>();
    274272      foreach (var pc in ParameterConfigurations) {
    275         if(pc.Optimize) {
    276           if(pc.ValueConfigurations.CheckedItems.Count() > 1) list.Add(pc); // only add if there are more than 1 choices. otherwise it makes no sense to optimize which VC is selected
     273        if (pc.Optimize) {
     274          if (pc.ValueConfigurations.CheckedItems.Count() > 1) list.Add(pc); // only add if there are more than 1 choices. otherwise it makes no sense to optimize which VC is selected
    277275          list.AddRange(pc.GetAllOptimizables());
    278276        }
  • 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.