- Timestamp:
- 06/26/17 09:10:56 (7 years ago)
- 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 35 35 [StorableClass] 36 36 [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 { 40 38 41 39 #region Parameternames 42 43 40 public const string AlphaParameterName = "Alpha"; 44 45 41 #endregion 46 42 47 43 #region Parameters 48 49 44 public IValueParameter<DoubleValue> AlphaParameter => Parameters[AlphaParameterName] as IValueParameter<DoubleValue>; 50 51 45 #endregion 52 46 53 47 #region Properties 54 55 48 public double Alpha => AlphaParameter.Value.Value; 56 49 [Storable] 57 50 private double Tau; 58 59 51 #endregion 60 52 61 62 #region HL-Constructors, Serialization and Cloning 53 #region Constructors, Serialization and Cloning 63 54 [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) { 67 57 Tau = original.Tau; 68 58 } 69 70 59 public AugmentedExpectedImprovement() { 71 60 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 73 61 } 74 62 public override IDeepCloneable Clone(Cloner cloner) { … … 82 70 } 83 71 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 } 88 76 77 protected override double FindBestFitness(IConfidenceRegressionSolution solution) { 89 78 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); 91 80 var xssIndex = solution.EstimatedTrainingValues.Zip(solution.EstimatedTrainingValues, (m, s2) => m + Alpha * Math.Sqrt(s2)).ArgMin(x => x); 92 81 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); 96 84 } 97 85 } -
branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/ExpectedImprovement.cs
r14818 r15064 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Data;27 26 using HeuristicLab.Encodings.RealVectorEncoding; 28 using HeuristicLab.Parameters;29 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 28 using HeuristicLab.Problems.DataAnalysis; … … 35 33 [StorableClass] 36 34 [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 56 37 [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() { } 69 41 public override IDeepCloneable Clone(Cloner cloner) { 70 42 return new ExpectedImprovement(this, cloner); … … 76 48 var yhat = model.GetEstimation(vector); 77 49 var s = Math.Sqrt(model.GetVariance(vector)); 78 return GetEstimatedImprovement( YMin, yhat, s, ExploitationWeight);50 return GetEstimatedImprovement(BestFitness, yhat, s, ExploitationWeight, ExpensiveMaximization); 79 51 } 80 52 81 p ublic 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); 83 55 } 84 56 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(); 90 59 } 91 92 #region Eventhandling93 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 #endregion106 107 #region Helpers108 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 #endregion137 60 } 138 61 } -
branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/ExpectedQuality.cs
r14818 r15064 29 29 30 30 [StorableClass] 31 [Item("ExpectedQualityMeassure", "Use simply the qualitypredicted by the model")]31 [Item("ExpectedQualityMeassure", "Use the quality predicted by the model")] 32 32 public class ExpectedQuality : InfillCriterionBase { 33 #region HL-Constructors, Serialization and Cloning33 #region Constructors, Serialization and Cloning 34 34 [StorableConstructor] 35 pr ivateExpectedQuality(bool deserializing) : base(deserializing) { }36 pr ivateExpectedQuality(ExpectedQuality original, Cloner cloner) : base(original, cloner) { }35 protected ExpectedQuality(bool deserializing) : base(deserializing) { } 36 protected ExpectedQuality(ExpectedQuality original, Cloner cloner) : base(original, cloner) { } 37 37 public ExpectedQuality() { } 38 38 public override IDeepCloneable Clone(Cloner cloner) { … … 42 42 43 43 public override double Evaluate(RealVector vector) { 44 return RegressionSolution.Model.GetEstimation(vector);44 return ExpensiveMaximization ? RegressionSolution.Model.GetEstimation(vector) : -RegressionSolution.Model.GetEstimation(vector); 45 45 } 46 46 47 public override bool Maximization() { 48 return ExpensiveMaximization; 49 } 50 51 protected override void Initialize() { 47 public override void Initialize() { 52 48 } 53 49 } -
branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/ExpectedQuantileImprovement.cs
r14818 r15064 35 35 [StorableClass] 36 36 [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 { 38 38 39 39 #region Parameternames … … 48 48 49 49 #region Properties 50 51 50 public int MaxEvaluations => MaxEvaluationsParameter.Value.Value; 52 51 public double Alpha => AlphaParameter.Value.Value; 53 52 [Storable] 54 53 private double Tau; 55 56 54 #endregion 57 55 58 56 #region HL-Constructors, Serialization and Cloning 59 57 [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) { 63 60 Tau = original.Tau; 64 61 } 65 66 62 public ExpectedQuantileImprovement() { 67 63 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))); 69 65 MaxEvaluationsParameter.Hidden = true; 70 66 } … … 74 70 #endregion 75 71 76 p ublic 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); 79 75 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]; 82 78 83 return GetEstimatedImprovement(YMin, yhat, s, ExploitationWeight);84 79 } 85 80 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); 100 87 } 101 88 -
branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/InfillCriterionBase.cs
r14818 r15064 30 30 [StorableClass] 31 31 public abstract class InfillCriterionBase : ParameterizedNamedItem, IInfillCriterion { 32 33 32 [Storable] 34 p rotected IRegressionSolution RegressionSolution;33 public IRegressionSolution RegressionSolution { get; set; } 35 34 [Storable] 36 p rotected bool ExpensiveMaximization;35 public bool ExpensiveMaximization { get; set; } 37 36 [Storable] 38 p rotected RealVectorEncoding Encoding;37 public RealVectorEncoding Encoding { get; set; } 39 38 40 39 protected InfillCriterionBase(bool deserializing) : base(deserializing) { } 41 42 40 protected InfillCriterionBase(InfillCriterionBase original, Cloner cloner) : base(original, cloner) { 43 41 RegressionSolution = cloner.Clone(original.RegressionSolution); … … 48 46 49 47 public abstract double Evaluate(RealVector vector); 50 public abstract bool Maximization();48 //public abstract bool Maximization(); 51 49 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(); 61 51 } 62 52 } -
branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/MinimalQuantileCriterium.cs
r14818 r15064 42 42 #region ParameterProperties 43 43 public IFixedValueParameter<DoubleValue> ConfidenceWeightParameter => Parameters[ConfidenceWeightParameterName] as IFixedValueParameter<DoubleValue>; 44 45 44 #endregion 46 45 47 46 #region Properties 48 47 private double ConfidenceWeight => ConfidenceWeightParameter.Value.Value; 49 50 48 #endregion 51 49 52 #region HL-Constructors, Serialization and Cloning50 #region Constructors, Serialization and Cloning 53 51 [StorableConstructor] 54 pr ivateMinimalQuantileCriterium(bool deserializing) : base(deserializing) { }55 pr ivateMinimalQuantileCriterium(MinimalQuantileCriterium original, Cloner cloner) : base(original, cloner) { }52 protected MinimalQuantileCriterium(bool deserializing) : base(deserializing) { } 53 protected MinimalQuantileCriterium(MinimalQuantileCriterium original, Cloner cloner) : base(original, cloner) { } 56 54 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))); 58 56 } 59 57 public override IDeepCloneable Clone(Cloner cloner) { … … 66 64 var yhat = model.GetEstimation(vector); 67 65 var s = Math.Sqrt(model.GetVariance(vector)) * ConfidenceWeight; 68 return ExpensiveMaximization ? yhat + s : yhat -s;66 return (ExpensiveMaximization ? yhat : -yhat) + s; 69 67 } 70 68 71 public override bool Maximization() {72 return ExpensiveMaximization;73 }74 69 75 p rotectedoverride void Initialize() {70 public override void Initialize() { 76 71 var model = RegressionSolution.Model as IConfidenceRegressionModel; 77 72 if (model == null) throw new ArgumentException("can not calculate EI without confidence measure"); -
branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/PluginExpectedImprovement.cs
r14818 r15064 20 20 #endregion 21 21 22 using System;23 22 using System.Linq; 24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; 25 using HeuristicLab.Encodings.RealVectorEncoding; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 27 using HeuristicLab.Problems.DataAnalysis; … … 32 32 [StorableClass] 33 33 [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 { 36 35 37 36 #region HL-Constructors, Serialization and Cloning 38 37 [StorableConstructor] 39 pr ivatePluginExpectedImprovement(bool deserializing) : base(deserializing) { }40 pr ivatePluginExpectedImprovement(PluginExpectedImprovement original, Cloner cloner) : base(original, cloner) { }38 protected PluginExpectedImprovement(bool deserializing) : base(deserializing) { } 39 protected PluginExpectedImprovement(PluginExpectedImprovement original, Cloner cloner) : base(original, cloner) { } 41 40 public PluginExpectedImprovement() { } 42 41 public override IDeepCloneable Clone(Cloner cloner) { … … 45 44 #endregion 46 45 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); 52 52 } 53 53 }
Note: See TracChangeset
for help on using the changeset viewer.