Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5293


Ignore:
Timestamp:
01/14/11 00:41:58 (14 years ago)
Author:
cneumuel
Message:

#1215

  • added NormalCrossover operators
  • renamed MedianQualityAnalyzer to ReferenceQualityAnalyzer
Location:
branches/HeuristicLab.MetaOptimization
Files:
5 added
1 deleted
7 edited

Legend:

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

    r5281 r5293  
    3333    private static int metaAlgorithmPopulationSize = 7;
    3434    private static int metaAlgorithmMaxGenerations = 20;
    35     private static int metaProblemRepetitions = 3;
     35    private static int metaProblemRepetitions = 6;
    3636    private static int baseAlgorithmMaxGenerations = 50;
    3737    private static double mutationProbability = 0.35;
     
    5656      //TestExecutionTimeUpdateInvervalPerformance();
    5757      //TestMemoryConsumption();
     58      //TestNormalCrossover();
    5859
    5960      GeneticAlgorithm baseLevelAlgorithm = new GeneticAlgorithm();
     
    8384
    8485      Console.ReadLine();
     86    }
     87
     88    private static void TestNormalCrossover() {
     89      var random = new MersenneTwister();
     90      double d1 = 0.5;
     91      double d2 = 0.6;
     92      var doubleRange = new DoubleValueRange(new DoubleValue(0.0), new DoubleValue(1.0), new DoubleValue(0.01));
     93
     94      using (var sw = new StreamWriter("normalCrossover-DoubleValue.txt")) {
     95        for (int i = 0; i < 10000; i++) {
     96          sw.WriteLine(NormalDoubleValueCrossover.ApplyStatic(random, new DoubleValue(d1), new DoubleValue(d2), doubleRange));
     97        }
     98      }
     99
     100      int i1 = 180;
     101      int i2 = 160;
     102      var intRange = new IntValueRange(new IntValue(100), new IntValue(200), new IntValue(1));
     103
     104      using (var sw = new StreamWriter("normalCrossover-IntValue.txt")) {
     105        for (int i = 0; i < 10000; i++) {
     106         sw.WriteLine(NormalIntValueCrossover.ApplyStatic(random, new IntValue(i1), new IntValue(i2), intRange));
     107        }
     108      }
    85109    }
    86110
     
    510534      ParameterConfigurationTree algorithmVc = metaOptimizationProblem.ParameterConfigurationTree;
    511535
    512       metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
    513         Evaluator = new GriewankEvaluator(),
    514         ProblemSize = new IntValue(5)
    515       });
     536      //metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
     537      //  Evaluator = new GriewankEvaluator(),
     538      //  ProblemSize = new IntValue(2)
     539      //});
     540      //metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
     541      //  Evaluator = new GriewankEvaluator(),
     542      //  ProblemSize = new IntValue(20)
     543      //});
    516544      metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
    517545        Evaluator = new GriewankEvaluator(),
    518546        ProblemSize = new IntValue(50)
    519547      });
    520       metaOptimizationProblem.Problems.Add(new HeuristicLab.Problems.TestFunctions.SingleObjectiveTestFunctionProblem() {
    521         Evaluator = new GriewankEvaluator(),
    522         ProblemSize = new IntValue(500)
    523       });
    524548
    525549      ConfigurePopulationSize(algorithmVc, 12, 100, 1);
    526       ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.01);
     550      ConfigureMutationRate(algorithmVc, 0.0, 1.0, 0.0001);
    527551      ConfigureMutationOperator(algorithmVc);
    528       //ConfigureElites(algorithmVc, 0, 10, 1);
     552      ConfigureElites(algorithmVc, 0, 10, 1);
    529553      //ConfigureSelectionOperator(algorithmVc, true);
    530554      return algorithmVc;
     
    738762
    739763                  tb.AppendRow(
    740                     ((DoubleValue)run.Results["AverageQualityNormalized"]).Value.ToString("#0.00"),
     764                    ((DoubleValue)run.Results["AverageQualityNormalized"]).Value.ToString("#0.0000"),
    741765                    ((DoubleArray)run.Results["RunsAverageQualities"]).ToString(),
    742766                    ((IntValue)run.Parameters["PopulationSize"]).Value.ToString(),
    743                     ((DoubleValue)run.Parameters["MutationProbability"]).Value.ToString("0.00"),
     767                    ((DoubleValue)run.Parameters["MutationProbability"]).Value.ToString("0.0000"),
    744768                    ((IntValue)run.Parameters["Elites"]).Value.ToString(),
    745769                    Shorten(selector, 20),
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestParameterConfigurationAnalyzer.cs

    r5281 r5293  
    3939      get { return (LookupParameter<RunCollection>)Parameters["Population"]; }
    4040    }
    41     public LookupParameter<DoubleArray> ProblemQualityMediansParameter {
    42       get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityMedians"]; }
     41    public LookupParameter<DoubleArray> ProblemQualityReferencesParameter {
     42      get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityReferences"]; }
    4343    }
    4444    public LookupParameter<ConstrainedItemList<ISingleObjectiveProblem>> ProblemsParameter {
     
    5555      Parameters.Add(new LookupParameter<IRun>("BestKnownSolution", ""));
    5656      Parameters.Add(new LookupParameter<RunCollection>("Population", ""));
    57       Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityMedians", ""));
     57      Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityReferences", ""));
    5858      Parameters.Add(new LookupParameter<ConstrainedItemList<ISingleObjectiveProblem>>(MetaOptimizationProblem.ProblemsParameterName));
    5959    }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/Crossovers/ParameterConfigurationCrossover.cs

    r5277 r5293  
    3838    }
    3939
     40    /// <summary>
     41    /// Whether the problem is a maximization or minimization problem.
     42    /// </summary>
     43    public ValueLookupParameter<BoolValue> MaximizationParameter {
     44      get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     45    }
     46
     47    /// <summary>
     48    /// The quality of the parents.
     49    /// </summary>
     50    public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
     51      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
     52    }
     53
    4054    [StorableConstructor]
    4155    protected ParameterConfigurationCrossover(bool deserializing) : base(deserializing) { }
     
    4660      Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("Parents", "The parent vectors which should be crossed."));
    4761      Parameters.Add(new LookupParameter<ParameterConfigurationTree>("Child", "The child vector resulting from the crossover."));
    48 
     62      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "Whether the problem is a maximization problem or not."));
     63      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality values of the parents."));
    4964      Parameters.Add(new ValueLookupParameter<IIntValueCrossover>(MetaOptimizationProblem.IntValueCrossoverParameterName, ""));
    5065      Parameters.Add(new ValueLookupParameter<IDoubleValueCrossover>(MetaOptimizationProblem.DoubleValueCrossoverParameterName, ""));
     
    5570
    5671    public override IOperation Apply() {
    57       ParameterConfigurationTree child1 = (ParameterConfigurationTree)ParentsParameter.ActualValue[0].Clone();
    58       ParameterConfigurationTree child2 = (ParameterConfigurationTree)ParentsParameter.ActualValue[1];
     72      if (MaximizationParameter.ActualValue == null) throw new InvalidOperationException("HeuristicCrossover: Parameter " + MaximizationParameter.ActualName + " could not be found.");
     73      if (QualityParameter.ActualValue == null || QualityParameter.ActualValue.Length != 2) throw new InvalidOperationException("ParameterConfigurationCrossover: Parameter " + QualityParameter.ActualName + " could not be found, or not in the same quantity as there are parents.");
     74      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
     75      bool maximization = MaximizationParameter.ActualValue.Value;
     76
     77      ParameterConfigurationTree child1;
     78      ParameterConfigurationTree child2;
     79
     80      if (maximization && qualities[0].Value >= qualities[1].Value || !maximization && qualities[0].Value <= qualities[1].Value) {
     81        child1 = (ParameterConfigurationTree)ParentsParameter.ActualValue[0].Clone();
     82        child2 = (ParameterConfigurationTree)ParentsParameter.ActualValue[1];
     83      } else {
     84        child1 = (ParameterConfigurationTree)ParentsParameter.ActualValue[1].Clone();
     85        child2 = (ParameterConfigurationTree)ParentsParameter.ActualValue[0];
     86      }
    5987
    6088      child1.Cross(RandomParameter.ActualValue, child2, Cross, IntValueCrossoverParameter.ActualValue, DoubleValueCrossoverParameter.ActualValue);
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/ParameterConfigurationEvaluator.cs

    r5281 r5293  
    4040    }
    4141
    42     public LookupParameter<DoubleArray> ProblemQualityMediansParameter {
    43       get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityMedians"]; }
     42    public LookupParameter<DoubleArray> ProblemQualityReferencesParameter {
     43      get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityReferences"]; }
    4444    }
    4545
     
    5555      Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", "Missing description."));
    5656      Parameters.Add(new LookupParameter<IntValue>(MetaOptimizationProblem.RepetitionsParameterName, "Number of evaluations on one problem."));
    57       Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityMedians", ""));
     57      Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityReferences", ""));
    5858    }
    5959
     
    7272      ParameterConfigurationTree parameterConfiguration = ParameterConfigurationParameter.ActualValue;
    7373
    74       double[] medians;
    75       if (ProblemQualityMediansParameter.ActualValue == null) {
     74      double[] referenceQualities;
     75      if (ProblemQualityReferencesParameter.ActualValue == null) {
    7676        // this is generation zero. no reference qualities for normalization have been calculated yet.
    77         medians = new double[problems.Count];
    78         for (int i = 0; i < medians.Length; i++) {
    79           medians[i] = 1;
     77        referenceQualities = new double[problems.Count];
     78        for (int i = 0; i < referenceQualities.Length; i++) {
     79          referenceQualities[i] = 1;
    8080        }
    8181      } else {
    82         medians = ProblemQualityMediansParameter.ActualValue.ToArray();
     82        referenceQualities = ProblemQualityReferencesParameter.ActualValue.ToArray();
    8383      }
    8484
     
    131131      parameterConfiguration.Runs = (RunCollection)algorithm.Runs.Clone();
    132132
    133       this.QualityParameter.ActualValue = new DoubleValue(NormalizeQualities(parameterConfiguration, medians));
     133      this.QualityParameter.ActualValue = new DoubleValue(NormalizeQualities(parameterConfiguration, referenceQualities));
    134134
    135135      return base.Apply();
    136136    }
    137137
    138     public static double NormalizeQualities(ParameterConfigurationTree parameterConfigurationTree, double[] medians) {
    139       double[] qualitiesNormalized = new double[medians.Length];
    140       for (int i = 0; i < medians.Length; i++) {
    141         qualitiesNormalized[i] = parameterConfigurationTree.AverageQualities[i] / medians[i];
     138    public static double NormalizeQualities(ParameterConfigurationTree parameterConfigurationTree, double[] referenceQualities) {
     139      double[] qualitiesNormalized = new double[referenceQualities.Length];
     140      for (int i = 0; i < referenceQualities.Length; i++) {
     141        qualitiesNormalized[i] = parameterConfigurationTree.AverageQualities[i] / referenceQualities[i];
    142142      }
    143143      parameterConfigurationTree.QualitiesNormalized = new DoubleArray(qualitiesNormalized);
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/HeuristicLab.Problems.MetaOptimization-3.3.csproj

    r5281 r5293  
    117117      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Problems.TestFunctions-3.3.dll</HintPath>
    118118    </Reference>
     119    <Reference Include="HeuristicLab.Random-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
     120      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Random-3.3.dll</HintPath>
     121    </Reference>
    119122    <Reference Include="HeuristicLab.SequentialEngine-3.3">
    120123      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.SequentialEngine-3.3.dll</HintPath>
     
    132135    <None Include="Properties\AssemblyInfo.cs.frame" />
    133136    <None Include="HeuristicLabProblemsMetaOptimizationPlugin.cs.frame" />
    134     <Compile Include="Analyzers\MedianQualityAnalyzer.cs" />
     137    <Compile Include="Analyzers\ReferenceQualityAnalyzer.cs" />
    135138    <Compile Include="ConstrainedItemList.cs" />
    136139    <Compile Include="Encoding\NullValue.cs" />
     
    152155    <Compile Include="Interfaces\ICheckedValueConfigurationCollection.cs" />
    153156    <Compile Include="Operators\Crossovers\AverageDoubleValueCrossover.cs" />
     157    <Compile Include="Operators\Crossovers\AverageIntValueCrossover.cs" />
     158    <Compile Include="Operators\Crossovers\NormalIntValueCrossover.cs" />
     159    <Compile Include="Operators\Crossovers\NormalDoubleValueCrossover.cs" />
    154160    <Compile Include="Operators\Crossovers\DiscreteDoubleValueCrossover.cs" />
    155161    <Compile Include="Operators\Crossovers\DiscreteIntValueCrossover.cs" />
     
    173179    <Compile Include="Operators\Interfaces\IIntValueCrossover.cs" />
    174180    <Compile Include="Operators\Interfaces\IValueManipulator.cs" />
     181    <Compile Include="Operators\Manipulators\NormalIntValueManipulator.cs" />
    175182    <Compile Include="Operators\Manipulators\UniformIntValueManipulator.cs" />
    176183    <Compile Include="Operators\Manipulators\UniformDoubleValueManipulator.cs" />
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationProblem.cs

    r5281 r5293  
    9898      get { return Operators.OfType<BestParameterConfigurationAnalyzer>().FirstOrDefault(); }
    9999    }
    100     private MedianQualityAnalyzer MedianQualityAnalyzer {
    101       get { return Operators.OfType<MedianQualityAnalyzer>().FirstOrDefault(); }
     100    private ReferenceQualityAnalyzer ReferenceQualityAnalyzer {
     101      get { return Operators.OfType<ReferenceQualityAnalyzer>().FirstOrDefault(); }
    102102    }
    103103    #endregion
     
    114114      var validIntCrossovers = new ItemSet<IIntValueCrossover>(ApplicationManager.Manager.GetInstances<IIntValueCrossover>());
    115115      var validDoubleCrossovers = new ItemSet<IDoubleValueCrossover>(ApplicationManager.Manager.GetInstances<IDoubleValueCrossover>());
    116       Parameters.Add(new ConstrainedValueParameter<IIntValueManipulator>(IntValueManipulatorParameterName, "", validIntManipulators, validIntManipulators.First()));
    117       Parameters.Add(new ConstrainedValueParameter<IDoubleValueManipulator>(DoubleValueManipulatorParameterName, "", validDoubleManipulators, validDoubleManipulators.First()));
    118       Parameters.Add(new ConstrainedValueParameter<IIntValueCrossover>(IntValueCrossoverParameterName, "", validIntCrossovers, validIntCrossovers.First()));
    119       Parameters.Add(new ConstrainedValueParameter<IDoubleValueCrossover>(DoubleValueCrossoverParameterName, "", validDoubleCrossovers, validDoubleCrossovers.Where(x => x.GetType() == typeof(AverageDoubleValueCrossover)).SingleOrDefault()));
     116      Parameters.Add(new ConstrainedValueParameter<IIntValueManipulator>(IntValueManipulatorParameterName, "", validIntManipulators, validIntManipulators.Where(x => x.GetType() == typeof(NormalIntValueManipulator)).SingleOrDefault()));
     117      Parameters.Add(new ConstrainedValueParameter<IDoubleValueManipulator>(DoubleValueManipulatorParameterName, "", validDoubleManipulators, validDoubleManipulators.Where(x => x.GetType() == typeof(NormalDoubleValueManipulator)).SingleOrDefault()));
     118      Parameters.Add(new ConstrainedValueParameter<IIntValueCrossover>(IntValueCrossoverParameterName, "", validIntCrossovers, validIntCrossovers.Where(x => x.GetType() == typeof(NormalIntValueCrossover)).SingleOrDefault()));
     119      Parameters.Add(new ConstrainedValueParameter<IDoubleValueCrossover>(DoubleValueCrossoverParameterName, "", validDoubleCrossovers, validDoubleCrossovers.Where(x => x.GetType() == typeof(NormalDoubleValueCrossover)).SingleOrDefault()));
    120120
    121121      Maximization = new BoolValue(false);
     
    161161      Operators.AddRange(ApplicationManager.Manager.GetInstances<IParameterConfigurationOperator>().Cast<IOperator>());
    162162      Operators.Add(new BestParameterConfigurationAnalyzer());
    163       Operators.Add(new MedianQualityAnalyzer());
     163      Operators.Add(new ReferenceQualityAnalyzer());
    164164    }
    165165    private void ParameterizeSolutionCreator() {
     
    172172        BestParameterConfigurationAnalyzer.ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
    173173      }
    174       if (MedianQualityAnalyzer != null) {
    175         MedianQualityAnalyzer.ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
     174      if (ReferenceQualityAnalyzer != null) {
     175        ReferenceQualityAnalyzer.ParameterConfigurationParameter.ActualName = ((RandomParameterConfigurationCreator)SolutionCreator).ParameterConfigurationParameter.ActualName;
    176176      }
    177177    }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Operators/Manipulators/NormalDoubleValueManipulator.cs

    r5207 r5293  
    3737    public static void ApplyStatic(IRandom random, DoubleValue value, DoubleValueRange range) {
    3838      bool ok = false;
    39       RealVector strategy = new RealVector(new double[] { (range.UpperBound.Value - range.LowerBound.Value) / 15});
    40       RealVector vector = new RealVector(1);
     39      var strategy = new RealVector(new double[] { (range.UpperBound.Value - range.LowerBound.Value) / 10}); // todo: add strategy parameter
     40      var vector = new RealVector(1);
    4141      double val = value.Value;
    4242
Note: See TracChangeset for help on using the changeset viewer.