Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/21/10 01:13:49 (14 years ago)
Author:
cneumuel
Message:

#1215

  • added possibility to create all parameter combinations from a ParameterConfigurationTree and generate an experiment from them
Location:
branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurationTree.cs

    r5112 r5144  
    88using HeuristicLab.Optimization;
    99using HeuristicLab.Data;
     10using System.Collections;
    1011
    1112namespace HeuristicLab.Problems.MetaOptimization {
    1213  // todo: storable, name, descr, ...
    1314  [StorableClass]
    14   public class ParameterConfigurationTree : ValueConfiguration {
     15  public class ParameterConfigurationTree : ValueConfiguration, IEnumerable {
    1516    //[Storable]
    1617    //public EngineAlgorithm Algorithm {
     
    180181      ((IAlgorithm)item).CollectParameterValues(this.Parameters);
    181182    }
     183
     184    public Experiment GenerateExperiment(IAlgorithm algorithm) {
     185      Experiment experiment = new Experiment();
     186      foreach (IValueConfiguration combination in this) {
     187        IAlgorithm clonedAlg = (IAlgorithm)algorithm.Clone();
     188        clonedAlg.Name = combination.ToParameterInfoString();
     189        combination.Parameterize(clonedAlg);
     190        experiment.Optimizers.Add(clonedAlg);
     191      }
     192      return experiment;
     193    }
     194
     195    public IEnumerator GetEnumerator() {
     196      IEnumerator enumerator = new ParameterCombinationsEnumerator(this);
     197      enumerator.Reset();
     198      return enumerator;
     199    }
     200
     201    public long GetCombinationCount() {
     202      long cnt = 0;
     203      foreach (var c in this) {
     204        cnt++;
     205      }
     206      return cnt;
     207    }
    182208  }
    183209}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs

    r5112 r5144  
    99using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    1010using HeuristicLab.PluginInfrastructure;
     11using System.Text;
    1112
    1213namespace HeuristicLab.Problems.MetaOptimization {
     
    299300    }
    300301
     302    public string ToParameterInfoString() {
     303      StringBuilder sb = new StringBuilder();
     304      if (this.Optimize) {
     305        sb.Append(string.Format("{0}: {1}", parameterName, this.ActualValue.Value));
     306        //sb.Append(" (");
     307        //var subParams = new List<string>();
     308        //if (this.ActualValue.Value is IParameterizedItem) {
     309        //  subParams.Add(this.ValueConfigurations.CheckedItems.ElementAt(actualValueConfigurationIndex).ToParameterInfoString());
     310        //}
     311        //sb.Append(string.Join(", ", subParams.ToArray()));
     312        //sb.Append(")");
     313      }
     314      return sb.ToString();
     315    }
     316
    301317    public static IParameterConfiguration Create(IParameterizedNamedItem parent, IParameter parameter) {
    302318      if (parameter is IValueParameter) {
     
    348364      }
    349365    }
     366
     367    public void UpdateActualValueIndexToItem(IValueConfiguration vc) {
     368      for (int i = 0; i < this.ValueConfigurations.CheckedItems.Count(); i++) {
     369        if (this.ValueConfigurations.CheckedItems.ElementAt(i) == vc) {
     370          this.actualValueConfigurationIndex = i;
     371          return;
     372        }
     373      }
     374    }
     375
    350376  }
    351377}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/DoubleValueRange.cs

    r5112 r5144  
    3737      if (value.Value < this.LowerBound.Value) value.Value = this.LowerBound.Value;
    3838    }
     39
     40    public override IEnumerable<DoubleValue> GetCombinations() {
     41      var solutions = new List<DoubleValue>();
     42      double value = ((int)Math.Round(LowerBound.Value / StepSize.Value, 0)) * StepSize.Value;
     43      if (value < LowerBound.Value) value += StepSize.Value;
     44
     45      while (value <= UpperBound.Value) {
     46        //yield return new DoubleValue(value);
     47        solutions.Add(new DoubleValue(value));
     48        value += StepSize.Value;
     49      }
     50      return solutions;
     51    }
    3952  }
    4053}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/IntValueRange.cs

    r5112 r5144  
    3737      if (value.Value < this.LowerBound.Value) value.Value = this.LowerBound.Value;
    3838    }
     39
     40    public override IEnumerable<IntValue> GetCombinations() {
     41      var solutions = new List<IntValue>();
     42      int value = (this.LowerBound.Value / StepSize.Value) * StepSize.Value;
     43      if (value < this.LowerBound.Value) value += StepSize.Value;
     44
     45      while (value <= this.UpperBound.Value) {
     46        //yield return new IntValue(value);
     47        solutions.Add(new IntValue(value));
     48        value += this.StepSize.Value;
     49      }
     50      return solutions;
     51    }
    3952  }
    4053}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/PercentValueRange.cs

    r5112 r5144  
    3232      return new DoubleValueRange(LowerBound, UpperBound, StepSize);
    3333    }
     34
     35    public override IEnumerable<PercentValue> GetCombinations() {
     36      var solutions = new List<PercentValue>();
     37      double value = ((int)Math.Round(LowerBound.Value / StepSize.Value, 0)) * StepSize.Value;
     38      if (value < LowerBound.Value) value += StepSize.Value;
     39
     40      while (value <= UpperBound.Value) {
     41        //yield return new PercentValue(value);
     42        solutions.Add(new PercentValue(value));
     43        value += StepSize.Value;
     44      }
     45      return solutions;
     46    }
    3447  }
    3548}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/RangeConstraints/Range.cs

    r5112 r5144  
    11using System;
     2using System.Collections.Generic;
     3using System.Linq;
    24using HeuristicLab.Common;
    35using HeuristicLab.Core;
     
    206208
    207209    protected abstract T GetRandomSample(IRandom random);
    208 
    209210    IItem IRange.GetRandomValue(IRandom random) {
    210211      return GetRandomValue(random);
    211212    }
     213
     214    public abstract IEnumerable<T> GetCombinations();
     215    IEnumerable<IItem> IRange.GetCombinations() {
     216      return GetCombinations().Cast<IItem>().ToArray();
     217    }
    212218  }
    213219}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ValueConfigurations/ValueConfiguration.cs

    r5112 r5144  
    99using HeuristicLab.Encodings.IntegerVectorEncoding;
    1010using HeuristicLab.PluginInfrastructure;
     11using System.Collections.Generic;
     12using System.Text;
    1113
    1214namespace HeuristicLab.Problems.MetaOptimization {
     
    8991      this.IsOptimizable = true;
    9092      if (actualValue.ValueDataType == typeof(IntValue)) {
    91         rangeConstraint = new IntValueRange(new IntValue(0), (IntValue)value, new IntValue(1));
     93        RangeConstraint = new IntValueRange(new IntValue(0), (IntValue)value, new IntValue(1));
    9294      } else if (actualValue.ValueDataType == typeof(DoubleValue)) {
    93         rangeConstraint = new DoubleValueRange(new DoubleValue(0), (DoubleValue)value, new DoubleValue(0.01));
     95        RangeConstraint = new DoubleValueRange(new DoubleValue(0), (DoubleValue)value, new DoubleValue(0.01));
    9496      } else if (actualValue.ValueDataType == typeof(PercentValue)) {
    95         rangeConstraint = new PercentValueRange(new PercentValue(0), new PercentValue(1), new PercentValue(0.001));
     97        RangeConstraint = new PercentValueRange(new PercentValue(0), new PercentValue(1), new PercentValue(0.001));
    9698      } else if (actualValue.ValueDataType == typeof(BoolValue)) {
    9799        this.IsOptimizable = false; // there is nothing to configure for bools
    98100      } else {
    99         rangeConstraint = null;
    100       }
    101       RegisterRangeConstraintEvents();
     101        RangeConstraint = null;
     102      }
    102103    }
    103104
     
    155156    }
    156157    #endregion
    157    
     158
    158159    #region IItem Members
    159160    public override string ItemDescription {
     
    169170    }
    170171    #endregion
    171    
     172
    172173    #region Event Handlers
    173174    public virtual event EventHandler ValueChanged;
     
    208209        return base.ToString();
    209210      }
     211    }
     212
     213    public string ToParameterInfoString() {
     214      StringBuilder sb = new StringBuilder();
     215      if (this.Optimize) {
     216        if (this.ParameterConfigurations.Count > 0) {
     217          var parameterInfos = new List<string>();
     218          foreach (var pc in this.ParameterConfigurations) {
     219            if (pc.Optimize) parameterInfos.Add(pc.ToParameterInfoString());
     220          }
     221          sb.Append(string.Join(", ", parameterInfos.ToArray()));
     222        }
     223      }
     224      return sb.ToString();
    210225    }
    211226
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj

    r5111 r5144  
    134134    <Compile Include="ConstrainedItemList.cs" />
    135135    <Compile Include="Encoding\NullValue.cs" />
     136    <Compile Include="Encoding\ParameterCombinationsEnumerator.cs" />
    136137    <Compile Include="Encoding\RangeConstraints\PercentValueRange.cs">
    137138      <SubType>Code</SubType>
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IOptimizable.cs

    r5111 r5144  
    1818    void Mutate(IRandom random, MutateDelegate mutate, ParameterConfigurationManipulator pcmanip);
    1919    void Cross(IRandom random, IOptimizable other, CrossDelegate cross, ParameterConfigurationCrossover pccross);
    20    
     20    string ToParameterInfoString();
     21
    2122    event EventHandler IsOptimizableChanged;
    2223    event EventHandler OptimizeChanged;
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterConfiguration.cs

    r5111 r5144  
    1414
    1515    void Parameterize(IValueParameter parameter);
     16    void UpdateActualValueIndexToItem(IValueConfiguration vc);
    1617  }
    1718}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IRange.cs

    r5009 r5144  
    33using HeuristicLab.Core;
    44using HeuristicLab.Data;
     5using System.Collections.Generic;
    56
    67namespace HeuristicLab.Problems.MetaOptimization {
     
    1516
    1617    IItem GetRandomValue(IRandom random);
     18
     19    IEnumerable<IItem> GetCombinations();
    1720  }
    1821
     
    2225    new T StepSize { get; set; }
    2326    new T GetRandomValue(IRandom random);
     27    new IEnumerable<T> GetCombinations();
    2428  }
    2529}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IValueConfiguration.cs

    r5009 r5144  
    22using HeuristicLab.Core;
    33using HeuristicLab.Data;
     4using System.Collections.Generic;
    45
    56namespace HeuristicLab.Problems.MetaOptimization {
     
    89    IRange RangeConstraint { get; }
    910    event EventHandler ValueChanged;
    10 
     11   
    1112    void Parameterize(IParameterizedItem item);
    1213  }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs

    r5111 r5144  
    4040    public const string ProblemTypeParameterName = "ProblemType";
    4141    public const string ProblemsParameterName = "Problems";
    42     public const string ParameterConfigurationParameterName = "InitialParameterConfigurationTree";
     42    public const string ParameterConfigurationTreeParameterName = "ParameterConfigurationTree";
    4343    public const string RepetitionsParameterName = "Repetitions";
    4444
     
    5858      get { return (ValueParameter<ConstrainedItemList<ISingleObjectiveProblem>>)Parameters[ProblemsParameterName]; }
    5959    }
    60     public IValueParameter<ParameterConfigurationTree> ParameterConfigurationParameter {
    61       get { return (ValueParameter<ParameterConfigurationTree>)Parameters[ParameterConfigurationParameterName]; }
     60    public IValueParameter<ParameterConfigurationTree> ParameterConfigurationTreeParameter {
     61      get { return (ValueParameter<ParameterConfigurationTree>)Parameters[ParameterConfigurationTreeParameterName]; }
    6262    }
    6363    public IValueParameter<IntValue> RepetitionsParameter {
     
    8787      set { ProblemsParameter.Value = value; }
    8888    }
    89     public ParameterConfigurationTree AlgorithmParameterConfiguration {
    90       get { return ParameterConfigurationParameter.Value; }
    91       set { ParameterConfigurationParameter.Value = value; }
     89    public ParameterConfigurationTree ParameterConfigurationTree {
     90      get { return ParameterConfigurationTreeParameter.Value; }
     91      set { ParameterConfigurationTreeParameter.Value = value; }
    9292    }
    9393    public IntValue Repetitions {
     
    101101      Parameters.Add(new ValueParameter<ISingleObjectiveProblem>(ProblemTypeParameterName, "The problem type.", new SingleObjectiveTestFunctionProblem()));
    102102      Parameters.Add(new ValueParameter<ConstrainedItemList<ISingleObjectiveProblem>>(ProblemsParameterName, "The problems that should be evaluated.", new ConstrainedItemList<ISingleObjectiveProblem>()));
    103       Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfigurationParameterName, "List of algorithm parameters that should be optimized."));
     103      Parameters.Add(new ValueParameter<ParameterConfigurationTree>(ParameterConfigurationTreeParameterName, "List of algorithm parameters that should be optimized."));
    104104      Parameters.Add(new ValueParameter<IntValue>(RepetitionsParameterName, "The number of evaluations for each problem.", new IntValue(3)));
    105105
     
    122122      Problems.Type = Problem.GetType();
    123123      Algorithm.Problem = Problem;
    124       ParameterConfigurationParameter.ActualValue = new ParameterConfigurationTree(Algorithm);
     124      ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm);
    125125    }
    126126
     
    185185    void AlgorithmTypeParameter_ValueChanged(object sender, EventArgs e) {
    186186      Algorithm.Problem = Problem;
    187       ParameterConfigurationParameter.ActualValue = new ParameterConfigurationTree(Algorithm);
     187      ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm);
    188188    }
    189189    void ProblemTypeParameter_ValueChanged(object sender, EventArgs e) {
    190190      Problems.Type = Problem.GetType();
    191191      Algorithm.Problem = Problem;
    192       ParameterConfigurationParameter.ActualValue = new ParameterConfigurationTree(Algorithm);
     192      ParameterConfigurationTreeParameter.ActualValue = new ParameterConfigurationTree(Algorithm);
    193193    }
    194194    #endregion
Note: See TracChangeset for help on using the changeset viewer.