Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegressionModelCreator.cs @ 8401

Last change on this file since 8401 was 8401, checked in by gkronber, 12 years ago

#1423 moved LM-BFGS implementation from data-analysis into the gradient descent algorithm plugin.

File size: 3.4 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.RealVectorEncoding;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using HeuristicLab.Problems.DataAnalysis;
30
31namespace HeuristicLab.Algorithms.DataAnalysis {
32  [StorableClass]
33  [Item(Name = "GaussianProcessRegressionModelCreator",
34    Description = "Creates a Gaussian process model for regression given the data, the hyperparameters, a mean function, and a covariance function.")]
35  public sealed class GaussianProcessRegressionModelCreator : GaussianProcessModelCreator {
36    private const string ProblemDataParameterName = "ProblemData";
37
38    #region Parameter Properties
39    public ILookupParameter<IRegressionProblemData> ProblemDataParameter {
40      get { return (ILookupParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; }
41    }
42    #endregion
43
44    #region Properties
45    private IRegressionProblemData ProblemData {
46      get { return ProblemDataParameter.ActualValue; }
47    }
48    #endregion
49    [StorableConstructor]
50    private GaussianProcessRegressionModelCreator(bool deserializing) : base(deserializing) { }
51    private GaussianProcessRegressionModelCreator(GaussianProcessRegressionModelCreator original, Cloner cloner) : base(original, cloner) { }
52    public GaussianProcessRegressionModelCreator()
53      : base() {
54      Parameters.Add(new LookupParameter<IRegressionProblemData>(ProblemDataParameterName, "The regression problem data for the Gaussian process model."));
55    }
56
57    public override IDeepCloneable Clone(Cloner cloner) {
58      return new GaussianProcessRegressionModelCreator(this, cloner);
59    }
60
61    public override IOperation Apply() {
62      var model = Create(ProblemData, Hyperparameter.ToArray(), MeanFunction, CovarianceFunction);
63      ModelParameter.ActualValue = model;
64      NegativeLogLikelihoodParameter.ActualValue = new DoubleValue(model.NegativeLogLikelihood);
65      HyperparameterGradientsParameter.ActualValue = new RealVector(model.GetHyperparameterGradients());
66      return base.Apply();
67    }
68
69    public static IGaussianProcessModel Create(IRegressionProblemData problemData, double[] hyperparameter, IMeanFunction meanFunction, ICovarianceFunction covarianceFunction) {
70      return new GaussianProcessModel(problemData.Dataset, problemData.TargetVariable, problemData.AllowedInputVariables, problemData.TrainingIndices, hyperparameter, meanFunction, covarianceFunction);
71    }
72  }
73}
Note: See TracBrowser for help on using the repository browser.