Free cookie consent management tool by TermsFeed Policy Generator

source: branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/ExpectedQuantileImprovement.cs @ 14818

Last change on this file since 14818 was 14818, checked in by bwerth, 7 years ago

#2745 added several new InfillCriteria and moved Parameters from the InfillProblem to the Criteria themselves; added Sanitiy checks for GaussianProcessRegression

File size: 4.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Encodings.RealVectorEncoding;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.Problems.DataAnalysis;
31
32// ReSharper disable once CheckNamespace
33namespace HeuristicLab.Algorithms.EGO {
34
35  [StorableClass]
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 {
38
39    #region Parameternames
40    public const string AlphaParameterName = "Alpha";
41    public const string MaxEvaluationsParameterName = "MaxEvaluations";
42    #endregion
43
44    #region Parameters
45    public IFixedValueParameter<DoubleValue> AlphaParameter => Parameters[AlphaParameterName] as IFixedValueParameter<DoubleValue>;
46    public IValueParameter<IntValue> MaxEvaluationsParameter => Parameters[MaxEvaluationsParameterName] as IValueParameter<IntValue>;
47    #endregion
48
49    #region Properties
50
51    public int MaxEvaluations => MaxEvaluationsParameter.Value.Value;
52    public double Alpha => AlphaParameter.Value.Value;
53    [Storable]
54    private double Tau;
55
56    #endregion
57
58    #region HL-Constructors, Serialization and Cloning
59    [StorableConstructor]
60    private ExpectedQuantileImprovement(bool deserializing) : base(deserializing) { }
61
62    private ExpectedQuantileImprovement(ExpectedQuantileImprovement original, Cloner cloner) : base(original, cloner) {
63      Tau = original.Tau;
64    }
65
66    public ExpectedQuantileImprovement() {
67      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)));
69      MaxEvaluationsParameter.Hidden = true;
70    }
71    public override IDeepCloneable Clone(Cloner cloner) {
72      return new ExpectedQuantileImprovement(this, cloner);
73    }
74    #endregion
75
76    public override double Evaluate(RealVector vector) {
77      var model = RegressionSolution.Model as IConfidenceRegressionModel;
78      var s2 = model.GetVariance(vector);
79
80      var yhat = model.GetEstimation(vector) + Alpha * Math.Sqrt(Tau * s2 / (Tau + s2));
81      var s = Math.Sqrt(s2 * s2 / (Tau + s2));
82
83      return GetEstimatedImprovement(YMin, yhat, s, ExploitationWeight);
84    }
85
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);
100    }
101
102  }
103}
Note: See TracBrowser for help on using the repository browser.