Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/29/17 11:28:16 (7 years ago)
Author:
bwerth
Message:

#2745 added discretized EGO-version for use with IntegerVectors

Location:
branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/DiscreteEGO
Files:
1 added
1 copied

Legend:

Unmodified
Added
Removed
  • branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/DiscreteEGO/DiscreteInfillProblem.cs

    r15340 r15343  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Data;
     28using HeuristicLab.Encodings.IntegerVectorEncoding;
    2829using HeuristicLab.Encodings.RealVectorEncoding;
    2930using HeuristicLab.Optimization;
     
    3334namespace HeuristicLab.Algorithms.EGO {
    3435  [StorableClass]
    35   [Item("InfillProblem", "A problem for finding the most interesing potential new sampling Points by optimizing some InfillCriterion")]
    36   public sealed class InfillProblem : SingleObjectiveBasicProblem<RealVectorEncoding> {
     36  [Item("DiscreteInfillProblem", "A problem for finding the most interesing potential new sampling Points by optimizing some InfillCriterion")]
     37  public sealed class DiscreteInfillProblem : SingleObjectiveBasicProblem<IntegerVectorEncoding> {
    3738
    3839    public override bool Maximization => true;
     
    4748    private IInfillCriterion infillCriterion;
    4849
    49     public IInfillCriterion InfillCriterion
    50     {
     50    public IInfillCriterion InfillCriterion {
    5151      get { return infillCriterion; }
    52       set
    53       {
     52      set {
    5453        infillCriterion = value;
    55         infillCriterion.Encoding = Encoding;
     54        infillCriterion.Encoding = GetRealVectorEncoding(Encoding);
    5655      }
    5756    }
     
    6059    #region Constructors
    6160    [StorableConstructor]
    62     private InfillProblem(bool deserializing) : base(deserializing) { }
    63     private InfillProblem(InfillProblem original, Cloner cloner) : base(original, cloner) {
     61    private DiscreteInfillProblem(bool deserializing) : base(deserializing) { }
     62    private DiscreteInfillProblem(DiscreteInfillProblem original, Cloner cloner) : base(original, cloner) {
    6463      infillCriterion = cloner.Clone(original.infillCriterion);
    6564    }
    66     public InfillProblem() { }
    67     public override IDeepCloneable Clone(Cloner cloner) { return new InfillProblem(this, cloner); }
     65    public DiscreteInfillProblem() { }
     66    public override IDeepCloneable Clone(Cloner cloner) { return new DiscreteInfillProblem(this, cloner); }
    6867    #endregion
    6968
    7069    public override double Evaluate(Individual individual, IRandom r) {
    71       return !InBounds(individual.RealVector(), Encoding.Bounds) ? double.MinValue : InfillCriterion.Evaluate(individual.RealVector());
     70      return !InBounds(individual.IntegerVector(), Encoding.Bounds) ? double.MinValue : InfillCriterion.Evaluate(individual.IntegerVector().ToRealVector());
    7271    }
    7372    public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     
    7675      var newQuality = qualities[best];
    7776      if (!results.ContainsKey(BestInfillQualityResultName)) {
    78         results.Add(new Result(BestInfillSolutionResultName, (RealVector)individuals[best].RealVector().Clone()));
     77        results.Add(new Result(BestInfillSolutionResultName, (IntegerVector)individuals[best].IntegerVector().Clone()));
    7978        results.Add(new Result(BestInfillQualityResultName, new DoubleValue(newQuality)));
    8079        return;
     
    8382      if (qold == null) throw new ArgumentException("Old best quality is not a double value. Conflicting Analyzers?");
    8483      if (qold.Value >= newQuality) return;
    85       results[BestInfillSolutionResultName].Value = (RealVector)individuals[best].RealVector().Clone();
     84      results[BestInfillSolutionResultName].Value = (IntegerVector)individuals[best].IntegerVector().Clone();
    8685      qold.Value = newQuality;
    8786    }
     
    8988      var bounds = Encoding.Bounds;
    9089      var michalewiczIteration = 0;
     90      var sigma = new DoubleArray(new double[] { 1.0 });
     91
    9192      while (true) {
    9293        var neighbour = individual.Copy();
    93         var r = neighbour.RealVector();
    94         switch (random.Next(5)) {
    95           case 0: UniformOnePositionManipulator.Apply(random, r, bounds); break;
    96           case 1: UniformOnePositionManipulator.Apply(random, r, bounds); break;//FixedNormalAllPositionsManipulator.Apply(random, r, new RealVector(new[] { 0.1 })); break;
    97           case 2: MichalewiczNonUniformAllPositionsManipulator.Apply(random, r, bounds, new IntValue(michalewiczIteration++), new IntValue(10000), new DoubleValue(5.0)); break;
    98           case 3: MichalewiczNonUniformOnePositionManipulator.Apply(random, r, bounds, new IntValue(michalewiczIteration++), new IntValue(10000), new DoubleValue(5.0)); break;
    99           case 4: BreederGeneticAlgorithmManipulator.Apply(random, r, bounds, new DoubleValue(0.1)); break;
     94        var r = neighbour.IntegerVector();
     95        switch (random.Next(3) % 3) {
     96          case 0: HeuristicLab.Encodings.IntegerVectorEncoding.UniformOnePositionManipulator.Apply(random, r, bounds); break;
     97          case 1: HeuristicLab.Encodings.IntegerVectorEncoding.RoundedNormalAllPositionsManipulator.Apply(random, r, bounds, sigma); break;//FixedNormalAllPositionsManipulator.Apply(random, r, new RealVector(new[] { 0.1 })); break;
     98          case 2: HeuristicLab.Encodings.IntegerVectorEncoding.UniformSomePositionsManipulator.Apply(random, r, bounds, 0.1); break;
    10099          default: throw new NotImplementedException();
    101100        }
     
    108107      infillCriterion.RegressionSolution = model;
    109108      infillCriterion.ExpensiveMaximization = expensiveMaximization;
    110       infillCriterion.Encoding = Encoding;
     109      infillCriterion.Encoding = GetRealVectorEncoding(Encoding);
    111110      infillCriterion.Initialize();
    112111    }
    113112
    114113    #region helpers
    115     private static bool InBounds(RealVector r, DoubleMatrix bounds) {
     114    private static bool InBounds(IntegerVector r, IntMatrix bounds) {
    116115      return !r.Where((t, i) => t < bounds[i % bounds.Rows, 0] || t > bounds[i % bounds.Rows, 1]).Any();
     116    }
     117
     118    private static RealVectorEncoding GetRealVectorEncoding(IntegerVectorEncoding enc) {
     119      var res = new RealVectorEncoding(enc.Length);
     120      res.Bounds = new DoubleMatrix(enc.Bounds.Rows, enc.Bounds.Columns);
     121      for (int r = 0; r < res.Bounds.Rows; r++)
     122        for (int c = 0; c < res.Bounds.Columns; c++)
     123          res.Bounds[r, c] = enc.Bounds[r, c];
     124      return res;
     125
     126
    117127    }
    118128    #endregion
Note: See TracChangeset for help on using the changeset viewer.