Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/26/17 09:10:56 (7 years ago)
Author:
bwerth
Message:

#2745 implemented EGO as EngineAlgorithm + some simplifications in the IInfillCriterion interface

Location:
branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria
Files:
2 added
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/AugmentedExpectedImprovement.cs

    r14818 r15064  
    3535  [StorableClass]
    3636  [Item("AugmentedExpectedImprovement", "Noisy InfillCriterion, Extension of the Expected Improvement as described in\n Global optimization of stochastic black-box systems via sequential kriging meta-models.\r\nHuang, D., Allen, T., Notz, W., Zeng, N.")]
    37   public class AugmentedExpectedImprovement : ExpectedImprovement {
    38 
    39 
     37  public class AugmentedExpectedImprovement : ExpectedImprovementBase {
    4038
    4139    #region Parameternames
    42 
    4340    public const string AlphaParameterName = "Alpha";
    44 
    4541    #endregion
    4642
    4743    #region Parameters
    48 
    4944    public IValueParameter<DoubleValue> AlphaParameter => Parameters[AlphaParameterName] as IValueParameter<DoubleValue>;
    50 
    5145    #endregion
    5246
    5347    #region Properties
    54 
    5548    public double Alpha => AlphaParameter.Value.Value;
    5649    [Storable]
    5750    private double Tau;
    58 
    5951    #endregion
    6052
    61 
    62     #region HL-Constructors, Serialization and Cloning
     53    #region Constructors, Serialization and Cloning
    6354    [StorableConstructor]
    64     private AugmentedExpectedImprovement(bool deserializing) : base(deserializing) { }
    65 
    66     private AugmentedExpectedImprovement(AugmentedExpectedImprovement original, Cloner cloner) : base(original, cloner) {
     55    protected AugmentedExpectedImprovement(bool deserializing) : base(deserializing) { }
     56    protected AugmentedExpectedImprovement(AugmentedExpectedImprovement original, Cloner cloner) : base(original, cloner) {
    6757      Tau = original.Tau;
    6858    }
    69 
    7059    public AugmentedExpectedImprovement() {
    7160      Parameters.Add(new ValueParameter<DoubleValue>(AlphaParameterName, "The Alpha value specifiying the robustness of the \"effective best solution\". Recommended value is 1", new DoubleValue(1.0)));
    72 
    7361    }
    7462    public override IDeepCloneable Clone(Cloner cloner) {
     
    8270    }
    8371
    84     protected override void Initialize() {
    85       if (ExpensiveMaximization) throw new NotImplementedException("AugmentedExpectedImprovement for maximization not yet implemented");
    86       var solution = RegressionSolution as IConfidenceRegressionSolution;
    87       if (solution == null) throw new ArgumentException("can not calculate Augmented EI without a regression solution providing confidence values");
     72    protected override double Evaluate(RealVector vector, double estimatedFitness, double estimatedStandardDeviation) {
     73      var d = GetEstimatedImprovement(BestFitness, estimatedFitness, estimatedStandardDeviation, ExploitationWeight, ExpensiveMaximization);
     74      return d * (1 - Tau / Math.Sqrt(estimatedStandardDeviation * estimatedStandardDeviation + Tau * Tau));
     75    }
    8876
     77    protected override double FindBestFitness(IConfidenceRegressionSolution solution) {
    8978      Tau = RegressionSolution.EstimatedTrainingValues.Zip(RegressionSolution.ProblemData.TargetVariableTrainingValues, (d, d1) => Math.Abs(d - d1)).Average();
    90       var xss = new RealVector(Encoding.Length);
     79      var bestSolution = new RealVector(Encoding.Length);
    9180      var xssIndex = solution.EstimatedTrainingValues.Zip(solution.EstimatedTrainingValues, (m, s2) => m + Alpha * Math.Sqrt(s2)).ArgMin(x => x);
    9281      var i = solution.ProblemData.TrainingIndices.ToArray()[xssIndex];
    93       for (var j = 0; j < Encoding.Length; j++) xss[j] = solution.ProblemData.Dataset.GetDoubleValue(i, j);
    94 
    95       YMin = RegressionSolution.Model.GetEstimation(xss);
     82      for (var j = 0; j < Encoding.Length; j++) bestSolution[j] = solution.ProblemData.Dataset.GetDoubleValue(i, j);
     83      return RegressionSolution.Model.GetEstimation(bestSolution);
    9684    }
    9785  }
  • branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/ExpectedImprovement.cs

    r14818 r15064  
    2424using HeuristicLab.Common;
    2525using HeuristicLab.Core;
    26 using HeuristicLab.Data;
    2726using HeuristicLab.Encodings.RealVectorEncoding;
    28 using HeuristicLab.Parameters;
    2927using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3028using HeuristicLab.Problems.DataAnalysis;
     
    3533  [StorableClass]
    3634  [Item("ExpectedImprovementMeassure", "Extension of the Expected Improvement to a weighted version by ANDRAS SÓBESTER , STEPHEN J. LEARY and ANDY J. KEANE   in \n On the Design of Optimization Strategies Based on Global Response Surface Approximation Models")]
    37   public class ExpectedImprovement : InfillCriterionBase {
    38 
    39     #region ParameterNames
    40     private const string ExploitationWeightParameterName = "ExploitationWeight";
    41     #endregion
    42 
    43     #region ParameterProperties
    44     public IFixedValueParameter<DoubleValue> ExploitationWeightParameter => Parameters[ExploitationWeightParameterName] as IFixedValueParameter<DoubleValue>;
    45 
    46     #endregion
    47 
    48     #region Properties
    49     protected double ExploitationWeight => ExploitationWeightParameter.Value.Value;
    50 
    51     [Storable]
    52     protected double YMin;
    53     #endregion
    54 
    55     #region HL-Constructors, Serialization and Cloning
     35  public sealed class ExpectedImprovement : ExpectedImprovementBase {
     36    #region Constructors, Serialization and Cloning
    5637    [StorableConstructor]
    57     protected ExpectedImprovement(bool deserializing) : base(deserializing) { }
    58     [StorableHook(HookType.AfterDeserialization)]
    59     private void AfterDeserialization() {
    60       RegisterEventhandlers();
    61     }
    62     protected ExpectedImprovement(ExpectedImprovement original, Cloner cloner) : base(original, cloner) {
    63       RegisterEventhandlers();
    64     }
    65     public ExpectedImprovement() {
    66       Parameters.Add(new FixedValueParameter<DoubleValue>(ExploitationWeightParameterName, "A value between 0 and 1 indicating the focus on exploration (0) or exploitation (1)", new DoubleValue(0.5)));
    67       RegisterEventhandlers();
    68     }
     38    private ExpectedImprovement(bool deserializing) : base(deserializing) { }
     39    private ExpectedImprovement(ExpectedImprovement original, Cloner cloner) : base(original, cloner) { }
     40    public ExpectedImprovement() { }
    6941    public override IDeepCloneable Clone(Cloner cloner) {
    7042      return new ExpectedImprovement(this, cloner);
     
    7648      var yhat = model.GetEstimation(vector);
    7749      var s = Math.Sqrt(model.GetVariance(vector));
    78       return GetEstimatedImprovement(YMin, yhat, s, ExploitationWeight);
     50      return GetEstimatedImprovement(BestFitness, yhat, s, ExploitationWeight, ExpensiveMaximization);
    7951    }
    8052
    81     public override bool Maximization() {
    82       return true;
     53    protected override double Evaluate(RealVector vector, double estimatedFitness, double estimatedStandardDeviation) {
     54      return GetEstimatedImprovement(BestFitness, estimatedFitness, estimatedStandardDeviation, ExploitationWeight, ExpensiveMaximization);
    8355    }
    8456
    85     protected override void Initialize() {
    86       if (ExpensiveMaximization) throw new NotImplementedException("Expected Improvement for maximization not yet implemented");
    87       var model = RegressionSolution.Model as IConfidenceRegressionModel;
    88       if (model == null) throw new ArgumentException("can not calculate EI without confidence measure");
    89       YMin = RegressionSolution.ProblemData.TargetVariableTrainingValues.Min();
     57    protected override double FindBestFitness(IConfidenceRegressionSolution solution) {
     58      return ExpensiveMaximization ? solution.ProblemData.TargetVariableTrainingValues.Max() : solution.ProblemData.TargetVariableTrainingValues.Min();
    9059    }
    91 
    92     #region Eventhandling
    93     private void RegisterEventhandlers() {
    94       DeregisterEventhandlers();
    95       ExploitationWeightParameter.Value.ValueChanged += OnExploitationWeightChanged;
    96     }
    97     private void DeregisterEventhandlers() {
    98       ExploitationWeightParameter.Value.ValueChanged -= OnExploitationWeightChanged;
    99     }
    100     private void OnExploitationWeightChanged(object sender, EventArgs e) {
    101       ExploitationWeightParameter.Value.ValueChanged -= OnExploitationWeightChanged;
    102       ExploitationWeightParameter.Value.Value = Math.Max(0, Math.Min(ExploitationWeight, 1));
    103       ExploitationWeightParameter.Value.ValueChanged += OnExploitationWeightChanged;
    104     }
    105     #endregion
    106 
    107     #region Helpers
    108     protected static double GetEstimatedImprovement(double ymin, double yhat, double s, double w) {
    109       if (Math.Abs(s) < double.Epsilon) return 0;
    110       var val = (ymin - yhat) / s;
    111       var res = w * (ymin - yhat) * StandardNormalDistribution(val) + (1 - w) * s * StandardNormalDensity(val);
    112       return double.IsInfinity(res) || double.IsNaN(res) ? 0 : res;
    113     }
    114 
    115     private static double StandardNormalDensity(double x) {
    116       if (Math.Abs(x) > 10) return 0;
    117       return Math.Exp(-0.5 * x * x) / Math.Sqrt(2 * Math.PI);
    118     }
    119 
    120     //taken from https://www.johndcook.com/blog/2009/01/19/stand-alone-error-function-erf/
    121     private static double StandardNormalDistribution(double x) {
    122       if (x > 10) return 1;
    123       if (x < -10) return 0;
    124       const double a1 = 0.254829592;
    125       const double a2 = -0.284496736;
    126       const double a3 = 1.421413741;
    127       const double a4 = -1.453152027;
    128       const double a5 = 1.061405429;
    129       const double p = 0.3275911;
    130       var sign = x < 0 ? -1 : 1;
    131       x = Math.Abs(x) / Math.Sqrt(2.0);
    132       var t = 1.0 / (1.0 + p * x);
    133       var y = 1.0 - ((((a5 * t + a4) * t + a3) * t + a2) * t + a1) * t * Math.Exp(-x * x);
    134       return 0.5 * (1.0 + sign * y);
    135     }
    136     #endregion
    13760  }
    13861}
  • branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/ExpectedQuality.cs

    r14818 r15064  
    2929
    3030  [StorableClass]
    31   [Item("ExpectedQualityMeassure", "Use simply the qualitypredicted by the model")]
     31  [Item("ExpectedQualityMeassure", "Use the quality predicted by the model")]
    3232  public class ExpectedQuality : InfillCriterionBase {
    33     #region HL-Constructors, Serialization and Cloning
     33    #region Constructors, Serialization and Cloning
    3434    [StorableConstructor]
    35     private ExpectedQuality(bool deserializing) : base(deserializing) { }
    36     private ExpectedQuality(ExpectedQuality original, Cloner cloner) : base(original, cloner) { }
     35    protected ExpectedQuality(bool deserializing) : base(deserializing) { }
     36    protected ExpectedQuality(ExpectedQuality original, Cloner cloner) : base(original, cloner) { }
    3737    public ExpectedQuality() { }
    3838    public override IDeepCloneable Clone(Cloner cloner) {
     
    4242
    4343    public override double Evaluate(RealVector vector) {
    44       return RegressionSolution.Model.GetEstimation(vector);
     44      return ExpensiveMaximization ? RegressionSolution.Model.GetEstimation(vector) : -RegressionSolution.Model.GetEstimation(vector);
    4545    }
    4646
    47     public override bool Maximization() {
    48       return ExpensiveMaximization;
    49     }
    50 
    51     protected override void Initialize() {
     47    public override void Initialize() {
    5248    }
    5349  }
  • branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/ExpectedQuantileImprovement.cs

    r14818 r15064  
    3535  [StorableClass]
    3636  [Item("ExpectedQuantileImprovement", "Noisy InfillCriterion, Extension of the Expected Improvement as described in \n Noisy expectedimprovement and on - line computation time allocation for the optimization of simulators with tunable fidelitys\r\nPicheny, V., Ginsbourger, D., Richet, Y")]
    37   public class ExpectedQuantileImprovement : ExpectedImprovement {
     37  public class ExpectedQuantileImprovement : ExpectedImprovementBase {
    3838
    3939    #region Parameternames
     
    4848
    4949    #region Properties
    50 
    5150    public int MaxEvaluations => MaxEvaluationsParameter.Value.Value;
    5251    public double Alpha => AlphaParameter.Value.Value;
    5352    [Storable]
    5453    private double Tau;
    55 
    5654    #endregion
    5755
    5856    #region HL-Constructors, Serialization and Cloning
    5957    [StorableConstructor]
    60     private ExpectedQuantileImprovement(bool deserializing) : base(deserializing) { }
    61 
    62     private ExpectedQuantileImprovement(ExpectedQuantileImprovement original, Cloner cloner) : base(original, cloner) {
     58    protected ExpectedQuantileImprovement(bool deserializing) : base(deserializing) { }
     59    protected ExpectedQuantileImprovement(ExpectedQuantileImprovement original, Cloner cloner) : base(original, cloner) {
    6360      Tau = original.Tau;
    6461    }
    65 
    6662    public ExpectedQuantileImprovement() {
    6763      Parameters.Add(new FixedValueParameter<DoubleValue>(AlphaParameterName, "The Alpha value specifiying the robustness of the \"effective best solution\". Recommended value is 1.0", new DoubleValue(1.0)));
    68       Parameters.Add(new ValueParameter<IntValue>(MaxEvaluationsParameterName, "The maximum number of evaluations allowed for EGO", new IntValue(100)));
     64      Parameters.Add(new ValueParameter<IntValue>(MaxEvaluationsParameterName, "The maximum number of evaluations allowed for EGO", new IntValue(500)));
    6965      MaxEvaluationsParameter.Hidden = true;
    7066    }
     
    7470    #endregion
    7571
    76     public override double Evaluate(RealVector vector) {
    77       var model = RegressionSolution.Model as IConfidenceRegressionModel;
    78       var s2 = model.GetVariance(vector);
     72    protected override double FindBestFitness(IConfidenceRegressionSolution solution) {
     73      Tau = RegressionSolution.EstimatedTrainingValues.Zip(solution.ProblemData.TargetVariableTrainingValues, (d, d1) => Math.Abs(d - d1)).Average();
     74      Tau = Tau * Tau / (MaxEvaluations - solution.ProblemData.Dataset.Rows % MaxEvaluations + 1);
    7975
    80       var yhat = model.GetEstimation(vector) + Alpha * Math.Sqrt(Tau * s2 / (Tau + s2));
    81       var s = Math.Sqrt(s2 * s2 / (Tau + s2));
     76      var index = solution.EstimatedTrainingValues.Zip(solution.EstimatedTrainingVariances, (m, s2) => m + Alpha * Math.Sqrt(s2)).ArgMin(x => x);
     77      return solution.EstimatedTrainingValues.ToArray()[index];
    8278
    83       return GetEstimatedImprovement(YMin, yhat, s, ExploitationWeight);
    8479    }
    8580
    86     protected override void Initialize() {
    87       if (ExpensiveMaximization) throw new NotImplementedException("AugmentedExpectedImprovement for maximization not yet implemented");
    88       var solution = RegressionSolution as IConfidenceRegressionSolution;
    89       if (solution == null) throw new ArgumentException("can not calculate Augmented EI without a regression solution providing confidence values");
    90 
    91       Tau = RegressionSolution.EstimatedTrainingValues.Zip(RegressionSolution.ProblemData.TargetVariableTrainingValues, (d, d1) => Math.Abs(d - d1)).Average();
    92       Tau = Tau * Tau / (MaxEvaluations - RegressionSolution.ProblemData.Dataset.Rows + 1);
    93 
    94       var xss = new RealVector(Encoding.Length);
    95       var xssIndex = solution.EstimatedTrainingVariances.Zip(solution.EstimatedTrainingVariances, (m, s2) => m + Alpha * Math.Sqrt(s2)).ArgMin(x => x);
    96       var i = solution.ProblemData.TrainingIndices.ToArray()[xssIndex];
    97       for (var j = 0; j < Encoding.Length; j++) xss[j] = solution.ProblemData.Dataset.GetDoubleValue(i, j);
    98 
    99       YMin = RegressionSolution.Model.GetEstimation(xss);
     81    protected override double Evaluate(RealVector vector, double estimatedFitness, double estimatedStandardDeviation) {
     82      var s2 = estimatedStandardDeviation * estimatedStandardDeviation;
     83      var penalty = Alpha * Math.Sqrt(Tau * s2 / (Tau + s2));
     84      var yhat = estimatedFitness + (ExpensiveMaximization ? -penalty : penalty);
     85      var s = Math.Sqrt(s2 * s2 / (Tau + s2));
     86      return GetEstimatedImprovement(BestFitness, yhat, s, ExploitationWeight, ExpensiveMaximization);
    10087    }
    10188
  • branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/InfillCriterionBase.cs

    r14818 r15064  
    3030  [StorableClass]
    3131  public abstract class InfillCriterionBase : ParameterizedNamedItem, IInfillCriterion {
    32 
    3332    [Storable]
    34     protected IRegressionSolution RegressionSolution;
     33    public IRegressionSolution RegressionSolution { get; set; }
    3534    [Storable]
    36     protected bool ExpensiveMaximization;
     35    public bool ExpensiveMaximization { get; set; }
    3736    [Storable]
    38     protected RealVectorEncoding Encoding;
     37    public RealVectorEncoding Encoding { get; set; }
    3938
    4039    protected InfillCriterionBase(bool deserializing) : base(deserializing) { }
    41 
    4240    protected InfillCriterionBase(InfillCriterionBase original, Cloner cloner) : base(original, cloner) {
    4341      RegressionSolution = cloner.Clone(original.RegressionSolution);
     
    4846
    4947    public abstract double Evaluate(RealVector vector);
    50     public abstract bool Maximization();
     48    //public abstract bool Maximization();
    5149
    52     public void Initialize(IRegressionSolution solution, bool expensiveMaximization, RealVectorEncoding encoding) {
    53       RegressionSolution = solution;
    54       ExpensiveMaximization = expensiveMaximization;
    55       Encoding = encoding;
    56       Initialize();
    57     }
    58 
    59     protected abstract void Initialize();
    60 
     50    public abstract void Initialize();
    6151  }
    6252}
  • branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/MinimalQuantileCriterium.cs

    r14818 r15064  
    4242    #region ParameterProperties
    4343    public IFixedValueParameter<DoubleValue> ConfidenceWeightParameter => Parameters[ConfidenceWeightParameterName] as IFixedValueParameter<DoubleValue>;
    44 
    4544    #endregion
    4645
    4746    #region Properties
    4847    private double ConfidenceWeight => ConfidenceWeightParameter.Value.Value;
    49 
    5048    #endregion
    5149
    52     #region HL-Constructors, Serialization and Cloning
     50    #region Constructors, Serialization and Cloning
    5351    [StorableConstructor]
    54     private MinimalQuantileCriterium(bool deserializing) : base(deserializing) { }
    55     private MinimalQuantileCriterium(MinimalQuantileCriterium original, Cloner cloner) : base(original, cloner) { }
     52    protected MinimalQuantileCriterium(bool deserializing) : base(deserializing) { }
     53    protected MinimalQuantileCriterium(MinimalQuantileCriterium original, Cloner cloner) : base(original, cloner) { }
    5654    public MinimalQuantileCriterium() {
    57       Parameters.Add(new FixedValueParameter<DoubleValue>(ConfidenceWeightParameterName, "A value between 0 and 1 indicating the focus on exploration (0) or exploitation (1)", new DoubleValue(0.5)));
     55      Parameters.Add(new FixedValueParameter<DoubleValue>(ConfidenceWeightParameterName, "A value greater than 0. The larger the value the stronger the emphasis on exploration", new DoubleValue(0.5)));
    5856    }
    5957    public override IDeepCloneable Clone(Cloner cloner) {
     
    6664      var yhat = model.GetEstimation(vector);
    6765      var s = Math.Sqrt(model.GetVariance(vector)) * ConfidenceWeight;
    68       return ExpensiveMaximization ? yhat + s : yhat - s;
     66      return (ExpensiveMaximization ? yhat : -yhat) + s;
    6967    }
    7068
    71     public override bool Maximization() {
    72       return ExpensiveMaximization;
    73     }
    7469
    75     protected override void Initialize() {
     70    public override void Initialize() {
    7671      var model = RegressionSolution.Model as IConfidenceRegressionModel;
    7772      if (model == null) throw new ArgumentException("can not calculate EI without confidence measure");
  • branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/PluginExpectedImprovement.cs

    r14818 r15064  
    2020#endregion
    2121
    22 using System;
    2322using System.Linq;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.Core;
     25using HeuristicLab.Encodings.RealVectorEncoding;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2727using HeuristicLab.Problems.DataAnalysis;
     
    3232  [StorableClass]
    3333  [Item("PluginExpectedImprovement", "Noisy InfillCriterion, Extension of the Expected Improvement by using the minimal prediction on the observed points\n rather than the minimal observed value as described in \n Global optimization based on noisy evaluations: An empirical study of two statistical approaches\r\nEmmanuel Vazqueza, Julien Villemonteixb, Maryan Sidorkiewiczb and Éric Walterc")]
    34   public class PluginExpectedImprovement : ExpectedImprovement {
    35 
     34  public class PluginExpectedImprovement : ExpectedImprovementBase {
    3635
    3736    #region HL-Constructors, Serialization and Cloning
    3837    [StorableConstructor]
    39     private PluginExpectedImprovement(bool deserializing) : base(deserializing) { }
    40     private PluginExpectedImprovement(PluginExpectedImprovement original, Cloner cloner) : base(original, cloner) { }
     38    protected PluginExpectedImprovement(bool deserializing) : base(deserializing) { }
     39    protected PluginExpectedImprovement(PluginExpectedImprovement original, Cloner cloner) : base(original, cloner) { }
    4140    public PluginExpectedImprovement() { }
    4241    public override IDeepCloneable Clone(Cloner cloner) {
     
    4544    #endregion
    4645
    47     protected override void Initialize() {
    48       if (ExpensiveMaximization) throw new NotImplementedException("PluginExpectedImprovement for maximization not yet implemented");
    49       var model = RegressionSolution.Model as IConfidenceRegressionModel;
    50       if (model == null) throw new ArgumentException("can not calculate EI without confidence measure");
    51       YMin = RegressionSolution.EstimatedTrainingValues.Min();
     46    protected override double FindBestFitness(IConfidenceRegressionSolution solution) {
     47      return ExpensiveMaximization ? RegressionSolution.EstimatedTrainingValues.Max() : RegressionSolution.EstimatedTrainingValues.Min();
     48    }
     49
     50    protected override double Evaluate(RealVector vector, double estimatedFitness, double estimatedStandardDeviation) {
     51      return GetEstimatedImprovement(BestFitness, estimatedFitness, estimatedStandardDeviation, ExploitationWeight, ExpensiveMaximization);
    5252    }
    5353  }
Note: See TracChangeset for help on using the changeset viewer.