#region License Information /* HeuristicLab * Copyright (C) 2002-2012 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 HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Problems.DataAnalysis; namespace HeuristicLab.Algorithms.DataAnalysis { [StorableClass] [Item(Name = "GaussianProcessRegressionSolutionCreator", Description = "Creates a Gaussian process solution from a trained model.")] public sealed class GaussianProcessRegressionSolutionCreator : SingleSuccessorOperator { private const string ProblemDataParameterName = "ProblemData"; private const string ModelParameterName = "GaussianProcessRegressionModel"; private const string SolutionParameterName = "Solution"; private const string ResultsParameterName = "Results"; private const string TrainingRSquaredResultName = "Training R²"; private const string TestRSquaredResultName = "Test R²"; #region Parameter Properties public ILookupParameter ProblemDataParameter { get { return (ILookupParameter)Parameters[ProblemDataParameterName]; } } public ILookupParameter SolutionParameter { get { return (ILookupParameter)Parameters[SolutionParameterName]; } } public ILookupParameter ModelParameter { get { return (ILookupParameter)Parameters[ModelParameterName]; } } public ILookupParameter ResultsParameter { get { return (ILookupParameter)Parameters[ResultsParameterName]; } } #endregion [StorableConstructor] private GaussianProcessRegressionSolutionCreator(bool deserializing) : base(deserializing) { } private GaussianProcessRegressionSolutionCreator(GaussianProcessRegressionSolutionCreator original, Cloner cloner) : base(original, cloner) { } public GaussianProcessRegressionSolutionCreator() : base() { // in Parameters.Add(new LookupParameter(ProblemDataParameterName, "The regression problem data for the Gaussian process solution.")); Parameters.Add(new LookupParameter(ModelParameterName, "The Gaussian process regression model to use for the solution.")); // in & out Parameters.Add(new LookupParameter(ResultsParameterName, "The result collection of the algorithm.")); // out Parameters.Add(new LookupParameter(SolutionParameterName, "The produced Gaussian process solution.")); } public override IDeepCloneable Clone(Cloner cloner) { return new GaussianProcessRegressionSolutionCreator(this, cloner); } public override IOperation Apply() { var m = ModelParameter.ActualValue; var data = ProblemDataParameter.ActualValue; var s = new GaussianProcessRegressionSolution(m, data); SolutionParameter.ActualValue = s; var results = ResultsParameter.ActualValue; if (!results.ContainsKey(SolutionParameterName)) { results.Add(new Result(ResultsParameterName, "The Gaussian process regression solution", s)); results.Add(new Result(TrainingRSquaredResultName, "The Pearson's R² of the Gaussian process solution on the training partition.", new DoubleValue(s.TrainingRSquared))); results.Add(new Result(TestRSquaredResultName, "The Pearson's R² of the Gaussian process solution on the test partition.", new DoubleValue(s.TestRSquared))); } else { results[ResultsParameterName].Value = s; results[TrainingRSquaredResultName].Value = new DoubleValue(s.TrainingRSquared); results[TestRSquaredResultName].Value = new DoubleValue(s.TestRSquared); } return base.Apply(); } } }