#region License Information /* HeuristicLab * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Encodings.RealVectorEncoding; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Problems.DataAnalysis; // ReSharper disable once CheckNamespace namespace HeuristicLab.Algorithms.EGO { [StorableClass] [Item("RobustImprovementMeassure", "Adding or Subtracting the variance * factor to the model estimation")] public class RobustImprovement : InfillCriterionBase { #region ParameterNames private const string ConfidenceWeightParameterName = "ConfidenceWeight"; #endregion #region ParameterProperties public IFixedValueParameter ConfidenceWeightParameter { get { return Parameters[ConfidenceWeightParameterName] as IFixedValueParameter; } } #endregion #region Properties private double ConfidenceWeight { get { return ConfidenceWeightParameter.Value.Value; } } #endregion #region HL-Constructors, Serialization and Cloning [StorableConstructor] private RobustImprovement(bool deserializing) : base(deserializing) { } private RobustImprovement(RobustImprovement original, Cloner cloner) : base(original, cloner) { } public RobustImprovement() { Parameters.Add(new FixedValueParameter(ConfidenceWeightParameterName, "A value between 0 and 1 indicating the focus on exploration (0) or exploitation (1)", new DoubleValue(0.5))); } public override IDeepCloneable Clone(Cloner cloner) { return new RobustImprovement(this, cloner); } #endregion public override double Evaluate(IRegressionSolution solution, RealVector vector, bool maximization) { var model = solution.Model as IConfidenceRegressionModel; if (model == null) throw new ArgumentException("can not calculate EI without confidence measure"); var yhat = model.GetEstimation(vector); var s = Math.Sqrt(model.GetVariance(vector)) * ConfidenceWeight; return maximization ? yhat + s : yhat - s; } } }