#region License Information /* HeuristicLab * Copyright (C) 2002-2015 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 System.Linq; 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; namespace HeuristicLab.Algorithms.DataAnalysis { [StorableClass] [Item(Name = "StudentTProcessRegressionModelCreator", Description = "Creates a Student-t process model for regression given the data, the hyperparameters, a mean function, and a covariance function.")] public sealed class StudentTProcessRegressionModelCreator : GaussianProcessModelCreator, IGaussianProcessRegressionModelCreator { private const string ProblemDataParameterName = "ProblemData"; #region Parameter Properties public ILookupParameter ProblemDataParameter { get { return (ILookupParameter)Parameters[ProblemDataParameterName]; } } #endregion #region Properties private IRegressionProblemData ProblemData { get { return ProblemDataParameter.ActualValue; } } #endregion [StorableConstructor] private StudentTProcessRegressionModelCreator(bool deserializing) : base(deserializing) { } private StudentTProcessRegressionModelCreator(StudentTProcessRegressionModelCreator original, Cloner cloner) : base(original, cloner) { } public StudentTProcessRegressionModelCreator() : base() { Parameters.Add(new LookupParameter(ProblemDataParameterName, "The regression problem data for the Gaussian process model.")); } public override IDeepCloneable Clone(Cloner cloner) { return new StudentTProcessRegressionModelCreator(this, cloner); } public override IOperation Apply() { try { var model = Create(ProblemData, Hyperparameter.ToArray(), MeanFunction, CovarianceFunction, ScaleInputValues); ModelParameter.ActualValue = model; NegativeLogLikelihoodParameter.ActualValue = new DoubleValue(model.NegativeLogLikelihood); HyperparameterGradientsParameter.ActualValue = new RealVector(model.HyperparameterGradients); return base.Apply(); } catch (ArgumentException) { } catch (alglib.alglibexception) { } NegativeLogLikelihoodParameter.ActualValue = new DoubleValue(1E300); HyperparameterGradientsParameter.ActualValue = new RealVector(Hyperparameter.Count()); return base.Apply(); } public static IGaussianProcessModel Create(IRegressionProblemData problemData, double[] hyperparameter, IMeanFunction meanFunction, ICovarianceFunction covarianceFunction, bool scaleInputs = true) { return new StudentTProcessModel(problemData.Dataset, problemData.TargetVariable, problemData.AllowedInputVariables, problemData.TrainingIndices, hyperparameter, meanFunction, covarianceFunction, scaleInputs); } } }