Changeset 5111


Ignore:
Timestamp:
12/15/10 23:41:33 (10 years ago)
Author:
cneumuel
Message:

#1215

  • improved exchangeability of crossover and mutation operators for parameter values
Location:
branches/HeuristicLab.MetaOptimization
Files:
16 added
5 deleted
8 edited

Legend:

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

    • Property svn:ignore
      •  

        old new  
        11bin
        22obj
         3HeuristicLab.MetaOptimization.Test.csproj.user
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs

    r5110 r5111  
    2222namespace HeuristicLab.MetaOptimization.Test {
    2323  class Program {
    24     private static int metaAlgorithmPopulationSize = 3;
     24    private static int metaAlgorithmPopulationSize = 50;
    2525    private static int metaAlgorithmMaxGenerations = 30;
    26     private static int metaProblemRepetitions = 3;
    27 
    28     private static int baseAlgorithmMaxGenerations = 3;
     26    private static int metaProblemRepetitions = 6;
     27
     28    private static int baseAlgorithmMaxGenerations = 250;
    2929
    3030    static void Main(string[] args) {
     
    3434      //TestDoubleSampling();
    3535      //TestTypeDiscovery();
     36      //TestOperators();
    3637     
    3738      GeneticAlgorithm baseLevelAlgorithm = new GeneticAlgorithm();
     
    5354
    5455      //TestMemoryLeak(metaLevelAlgorithm);
     56
     57      Console.ReadLine();
     58    }
     59
     60    private static void TestOperators() {
     61      IRandom random = new MersenneTwister();
     62      ParameterConfigurationManipulator manip = new ParameterConfigurationManipulator();
     63
     64      manip.IntValueManipulatorParameter.ActualValue = new UniformIntValueManipulator();
     65      manip.DoubleValueManipulatorParameter.ActualValue = new NormalDoubleValueManipulator();
     66     
     67      var doubleRange = new DoubleValueRange(new DoubleValue(0), new DoubleValue(100), new DoubleValue(0.1));
     68      using (var sw = new StreamWriter("out-DoubleValue.txt")) {
     69        for (int i = 0; i < 10000; i++) {
     70          var val = new DoubleValue(50);
     71          NormalDoubleValueManipulator.ApplyStatic(random, val, doubleRange);
     72         
     73          sw.WriteLine(val);
     74        }
     75      }
     76
     77      var percentRange = new PercentValueRange(new PercentValue(0), new PercentValue(1), new PercentValue(0.001));
     78      using (var sw = new StreamWriter("out-PercentValue.txt")) {
     79        for (int i = 0; i < 10000; i++) {
     80          var val = new PercentValue(0.5);
     81          NormalDoubleValueManipulator.ApplyStatic(random, val, percentRange.AsDoubleValueRange());
     82          sw.WriteLine(val);
     83        }
     84      }
     85
     86      var intRange = new IntValueRange(new IntValue(0), new IntValue(100), new IntValue(1));
     87      using (var sw = new StreamWriter("out-IntValue.txt")) {
     88        for (int i = 0; i < 10000; i++) {
     89          var val = new IntValue(50);
     90          UniformIntValueManipulator.ApplyStatic(random, val, intRange);
     91          sw.WriteLine(val);
     92        }
     93      }
    5594
    5695      Console.ReadLine();
     
    145184      for (int i = 0; i < 10; i++) {
    146185        IValueConfiguration clonedVc = (IValueConfiguration)algorithmVc.Clone();
     186        GeneticAlgorithm newAlg = (GeneticAlgorithm)baseLevelAlgorithm.Clone();
    147187        clonedVc.Randomize(rand);
    148         clonedVc.Parameterize((GeneticAlgorithm)clonedVc.ActualValue.Value);
    149         GeneticAlgorithm newAlg = (GeneticAlgorithm)clonedVc.ActualValue.Value;
     188        clonedVc.Parameterize(newAlg);
    150189        Console.WriteLine(string.Format("PopSize: original: {0}, randomized: {1}", baseLevelAlgorithm.PopulationSize, newAlg.PopulationSize));
    151190        Console.WriteLine(string.Format("MutRate: original: {0}, randomized: {1}", baseLevelAlgorithm.MutationProbability, newAlg.MutationProbability));
    152191        Console.WriteLine(string.Format("MutOp: original: {0}, randomized: {1}", baseLevelAlgorithm.Mutator, newAlg.Mutator));
    153192        Console.WriteLine(string.Format("SelOp: original: {0}, randomized: {1}", baseLevelAlgorithm.Selector, newAlg.Selector));
    154         Console.WriteLine(string.Format("GrSi: original: {0}, randomized: {1}", "?", ((TournamentSelector)newAlg.Selector).GroupSizeParameter.Value));
     193        //Console.WriteLine(string.Format("GrSi: original: {0}, randomized: {1}", "?", ((TournamentSelector)newAlg.Selector).GroupSizeParameter.Value));
    155194        Console.WriteLine("---");
    156195      }
     
    162201      for (int i = 0; i < 10; i++) {
    163202        IValueConfiguration clonedVc = (IValueConfiguration)algorithmVc.Clone();
    164         clonedVc.Mutate(rand);
    165         clonedVc.Parameterize((GeneticAlgorithm)clonedVc.ActualValue.Value);
    166         GeneticAlgorithm newAlg = (GeneticAlgorithm)clonedVc.ActualValue.Value;
     203        GeneticAlgorithm newAlg = (GeneticAlgorithm)baseLevelAlgorithm.Clone();
     204        //clonedVc.Mutate(rand);
     205       
     206        //.Apply(rand, clonedVc); todo
     207        clonedVc.Parameterize(newAlg);
    167208        Console.WriteLine(string.Format("PopSize: original: {0}, mutated: {1}", baseLevelAlgorithm.PopulationSize, newAlg.PopulationSize));
    168209        Console.WriteLine(string.Format("MutRate: original: {0}, mutated: {1}", baseLevelAlgorithm.MutationProbability, newAlg.MutationProbability));
    169210        Console.WriteLine(string.Format("MutOp: original: {0}, mutated: {1}", baseLevelAlgorithm.Mutator, newAlg.Mutator));
    170211        Console.WriteLine(string.Format("SelOp: original: {0}, mutated: {1}", baseLevelAlgorithm.Selector, newAlg.Selector));
    171         Console.WriteLine(string.Format("GrSi: original: {0}, mutated: {1}", ((TournamentSelector)baseLevelAlgorithm.Selector).GroupSizeParameter.Value, ((TournamentSelector)newAlg.Selector).GroupSizeParameter.Value));
     212        //Console.WriteLine(string.Format("GrSi: original: {0}, mutated: {1}", ((TournamentSelector)baseLevelAlgorithm.Selector).GroupSizeParameter.Value, ((TournamentSelector)newAlg.Selector).GroupSizeParameter.Value));
    172213        Console.WriteLine("---");
    173214      }
     
    179220        IValueConfiguration clonedVc2 = (IValueConfiguration)algorithmVc.Clone();
    180221
    181         GeneticAlgorithm first = (GeneticAlgorithm)clonedVc1.ActualValue.Value.Clone();
    182         GeneticAlgorithm second = (GeneticAlgorithm)clonedVc2.ActualValue.Value.Clone();
     222        GeneticAlgorithm first = (GeneticAlgorithm)baseLevelAlgorithm.Clone();
     223        GeneticAlgorithm second = (GeneticAlgorithm)baseLevelAlgorithm.Clone();
    183224
    184225        clonedVc1.Randomize(rand);
     
    192233        var mutOpBefore = first.Mutator;
    193234        var selOpBefore = first.Selector;
    194         var groupSizeBefore = ((TournamentSelector)first.Selector).GroupSizeParameter.Value.Value;
    195 
    196         clonedVc1.Cross(clonedVc2, rand);
     235        //var groupSizeBefore = ((TournamentSelector)first.Selector).GroupSizeParameter.Value.Value;
     236
     237        //clonedVc1.Cross(clonedVc2, rand); todo
    197238        clonedVc1.Parameterize(first);
    198239
     
    201242        Console.WriteLine(string.Format("MutOp: first: {0}, second: {1}, crossed: {2}", mutOpBefore, second.Mutator, first.Mutator));
    202243        Console.WriteLine(string.Format("SelOp: first: {0}, second: {1}, crossed: {2}", selOpBefore, second.Selector, first.Selector));
    203         Console.WriteLine(string.Format("GrSi: first: {0}, second: {1}, crossed: {2}", groupSizeBefore, ((TournamentSelector)second.Selector).GroupSizeParameter.Value, ((TournamentSelector)first.Selector).GroupSizeParameter.Value));
     244        //Console.WriteLine(string.Format("GrSi: first: {0}, second: {1}, crossed: {2}", groupSizeBefore, ((TournamentSelector)second.Selector).GroupSizeParameter.Value, ((TournamentSelector)first.Selector).GroupSizeParameter.Value));
    204245        Console.WriteLine("---");
    205246      }
     
    306347            sb.AppendLine("=================================");
    307348
     349            sb.AppendLine(metaLevelAlgorithm.ExecutionState.ToString());
    308350            foreach (var result in metaLevelAlgorithm.Results) {
    309351              sb.AppendLine(result.ToString());
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization.Views/3.3/HeuristicLab.Problems.MetaOptimization.Views-3.3.csproj

    r5110 r5111  
    118118  </ItemGroup>
    119119  <ItemGroup>
     120    <None Include="ClassDiagram1.cd" />
    120121    <None Include="HeuristicLabProblemsMetaOptimizationViewsPlugin.cs.frame" />
    121122    <Compile Include="ConstrainedItemListView.cs">
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj

    r5110 r5111  
    130130  <ItemGroup>
    131131    <Compile Include="Analyzers\BestParameterConfigurationAnalyzer.cs" />
    132     <None Include="ClassDiagram1.cd" />
    133132    <None Include="Properties\AssemblyInfo.cs.frame" />
    134133    <None Include="HeuristicLabProblemsMetaOptimizationPlugin.cs.frame" />
    135134    <Compile Include="ConstrainedItemList.cs" />
    136     <Compile Include="Encodings\NullValue.cs" />
    137     <Compile Include="Encodings\ValueConfigurations\NullValueConfiguration.cs" />
    138     <Compile Include="Encodings\RangeConstraints\ConstrainedValue.cs">
     135    <Compile Include="Encoding\NullValue.cs" />
     136    <Compile Include="Encoding\RangeConstraints\PercentValueRange.cs">
    139137      <SubType>Code</SubType>
    140138    </Compile>
    141     <Compile Include="Encodings\RangeConstraints\PercentValueRange.cs" />
    142     <Compile Include="Encodings\RangeConstraints\DoubleValueRange.cs" />
    143     <Compile Include="Encodings\RangeConstraints\IntValueRange.cs" />
    144     <Compile Include="Encodings\ParameterConfigurationTree.cs" />
    145     <Compile Include="Encodings\ValueConfigurations\ValueConfiguration.cs" />
    146     <Compile Include="Encodings\ValueConfigurations\CheckedValueConfigurationCollection.cs" />
     139    <Compile Include="Encoding\ValueConfigurations\NullValueConfiguration.cs" />
     140    <Compile Include="Encoding\RangeConstraints\ConstrainedValue.cs">
     141      <SubType>Code</SubType>
     142    </Compile>
     143    <Compile Include="Encoding\RangeConstraints\DoubleValueRange.cs" />
     144    <Compile Include="Encoding\RangeConstraints\IntValueRange.cs" />
     145    <Compile Include="Encoding\ParameterConfigurationTree.cs" />
     146    <Compile Include="Encoding\ValueConfigurations\ValueConfiguration.cs" />
     147    <Compile Include="Encoding\ValueConfigurations\CheckedValueConfigurationCollection.cs" />
    147148    <Compile Include="Interfaces\ICheckedValueConfigurationCollection.cs" />
     149    <Compile Include="Operators\Crossovers\DiscreteIntValueCrossover.cs" />
     150    <Compile Include="Operators\Interfaces\IDoubleValueCrossover.cs" />
     151    <Compile Include="Operators\Interfaces\IDoubleValueManipulator.cs" />
     152    <Compile Include="Operators\Interfaces\IIntValueManipulator.cs" />
    148153    <Compile Include="Interfaces\IOptimizable.cs" />
    149154    <Compile Include="Interfaces\IParameterConfigurationCreator.cs" />
    150155    <Compile Include="Creators\RandomParameterConfigurationCreator.cs" />
    151     <Compile Include="Encodings\Crossovers\ParameterConfigurationCrossover.cs" />
     156    <Compile Include="Encoding\Crossovers\ParameterConfigurationCrossover.cs" />
    152157    <Compile Include="Interfaces\IParameterConfigurationOperator.cs" />
    153158    <Compile Include="Interfaces\IRange.cs" />
    154     <Compile Include="Evaluators\MetaOptimizationEvaluator.cs" />
    155     <Compile Include="Interfaces\IMetaOptimizationEvaluator.cs" />
     159    <Compile Include="Evaluators\ParameterConfigurationEvaluator.cs" />
     160    <Compile Include="Interfaces\IParameterConfigurationEvaluator.cs" />
    156161    <Compile Include="Interfaces\IParameterConfiguration.cs" />
    157     <Compile Include="Encodings\ParameterConfigurations\ParameterConfiguration.cs" />
     162    <Compile Include="Encoding\ParameterConfigurations\ParameterConfiguration.cs" />
    158163    <Compile Include="Interfaces\IValueConfiguration.cs" />
    159     <Compile Include="Encodings\RangeConstraints\Range.cs" />
     164    <Compile Include="Encoding\RangeConstraints\Range.cs" />
    160165    <Compile Include="Interfaces\IParameterConfigurationManipulator.cs" />
    161     <Compile Include="Manipulators\ParameterConfigurationManipulator.cs" />
     166    <Compile Include="Encoding\Manipulators\ParameterConfigurationManipulator.cs" />
     167    <Compile Include="Operators\Interfaces\IIntValueCrossover.cs" />
     168    <Compile Include="Operators\Interfaces\IValueManipulator.cs" />
     169    <Compile Include="Operators\Manipulators\UniformIntValueManipulator.cs" />
     170    <Compile Include="Operators\Manipulators\UniformDoubleValueManipulator.cs" />
     171    <Compile Include="Operators\Manipulators\NormalDoubleValueManipulator.cs" />
    162172    <Compile Include="Properties\AssemblyInfo.cs" />
    163173    <Compile Include="MetaOptimizationProblem.cs" />
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IOptimizable.cs

    r5023 r5111  
    77
    88namespace HeuristicLab.Problems.MetaOptimization {
     9  public delegate void MutateDelegate(IRandom random, IOptimizable configuartion, ParameterConfigurationManipulator pcmanip);
     10  public delegate void CrossDelegate(IRandom random, IOptimizable configuartion, ParameterConfigurationCrossover pccross);
     11
    912  public interface IOptimizable : IItem {
    1013    bool IsOptimizable { get; }
    1114    bool Optimize { get; set; }
    1215    ConstrainedValue ActualValue { get; set; }
    13 
     16   
    1417    void Randomize(IRandom random);
    15     void Mutate(IRandom random);
    16     void Cross(IOptimizable other, IRandom random);
     18    void Mutate(IRandom random, MutateDelegate mutate, ParameterConfigurationManipulator pcmanip);
     19    void Cross(IRandom random, IOptimizable other, CrossDelegate cross, ParameterConfigurationCrossover pccross);
    1720   
    1821    event EventHandler IsOptimizableChanged;
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterConfiguration.cs

    r5009 r5111  
    1111    ICheckedValueConfigurationCollection ValueConfigurations { get; }
    1212    IItemSet<IItem> ValidValues { get; }
     13    int ActualValueConfigurationIndex { get; set; }
    1314
    1415    void Parameterize(IValueParameter parameter);
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Interfaces/IParameterConfigurationManipulator.cs

    r5009 r5111  
    88namespace HeuristicLab.Problems.MetaOptimization {
    99  public interface IParameterConfigurationManipulator : IParameterConfigurationOperator, IManipulator {
    10     ILookupParameter<ParameterConfigurationTree> ParameterConfigurationTreeParameter { get; }
     10    IValueLookupParameter<ParameterConfigurationTree> ParameterConfigurationTreeParameter { get; }
    1111  }
    1212}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs

    r5110 r5111  
    3636  [Creatable("Problems")]
    3737  [StorableClass]
    38   public sealed class MetaOptimizationProblem : SingleObjectiveProblem<IMetaOptimizationEvaluator, IParameterConfigurationCreator> {
     38  public sealed class MetaOptimizationProblem : SingleObjectiveProblem<IParameterConfigurationEvaluator, IParameterConfigurationCreator> {
    3939    public const string AlgorithmTypeParameterName = "AlgorithmType";
    4040    public const string ProblemTypeParameterName = "ProblemType";
     
    4242    public const string ParameterConfigurationParameterName = "InitialParameterConfigurationTree";
    4343    public const string RepetitionsParameterName = "Repetitions";
     44
     45    public const string IntValueManipulatorParameterName = "IntValueManipulator";
     46    public const string DoubleValueManipulatorParameterName = "DoubleValueManipulator";
     47    public const string IntValueCrossoverParameterName = "IntValueCrossover";
     48    public const string DoubleValueCrossoverParameterName = "DoubleValueCrossover";
    4449
    4550    #region Parameter Properties
     
    5863    public IValueParameter<IntValue> RepetitionsParameter {
    5964      get { return (ValueParameter<IntValue>)Parameters[RepetitionsParameterName]; }
     65    }
     66
     67    public IValueParameter<IIntValueManipulator> IntValueManipulatorParameter {
     68      get { return (ValueParameter<IIntValueManipulator>)Parameters[IntValueManipulatorParameterName]; }
     69    }
     70
     71    public IValueParameter<IDoubleValueManipulator> DoubleValueManipulatorParameter {
     72      get { return (ValueParameter<IDoubleValueManipulator>)Parameters[DoubleValueManipulatorParameterName]; }
    6073    }
    6174    #endregion
     
    91104      Parameters.Add(new ValueParameter<IntValue>(RepetitionsParameterName, "The number of evaluations for each problem.", new IntValue(3)));
    92105
     106      var validIntManipulators = new ItemSet<IIntValueManipulator>( ApplicationManager.Manager.GetInstances<IIntValueManipulator>());
     107      var validDoubleManipulators = new ItemSet<IDoubleValueManipulator>(ApplicationManager.Manager.GetInstances<IDoubleValueManipulator>());
     108      Parameters.Add(new ConstrainedValueParameter<IIntValueManipulator>(IntValueManipulatorParameterName, "", validIntManipulators, new UniformIntValueManipulator()));
     109      Parameters.Add(new ConstrainedValueParameter<IDoubleValueManipulator>(DoubleValueManipulatorParameterName, "", validDoubleManipulators, new NormalDoubleValueManipulator()));
     110
     111
    93112      Maximization = new BoolValue(false);
    94113      SolutionCreator = new RandomParameterConfigurationCreator();
    95       Evaluator = new MetaOptimizationEvaluator();
     114      Evaluator = new ParameterConfigurationEvaluator();
    96115
    97116      InitializeOperators();
     
    136155    }
    137156    private void ParameterizeEvaluator() {
    138       ((MetaOptimizationEvaluator)Evaluator).ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
     157      ((ParameterConfigurationEvaluator)Evaluator).ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
    139158    }
    140159    private void ParameterizeAnalyzer() {
Note: See TracChangeset for help on using the changeset viewer.