Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegression.cs @ 10041

Last change on this file since 10041 was 9456, checked in by swagner, 12 years ago

Updated copyright year and added some missing license headers (#1889)

File size: 6.1 KB
RevLine 
[8323]1
2#region License Information
3/* HeuristicLab
[9456]4 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[8323]5 *
6 * This file is part of HeuristicLab.
7 *
8 * HeuristicLab is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * HeuristicLab is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
20 */
21#endregion
22
[8371]23using System;
[9096]24using System.Linq;
[8401]25using HeuristicLab.Algorithms.GradientDescent;
[8323]26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
[8371]29using HeuristicLab.Operators;
[8323]30using HeuristicLab.Optimization;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[9096]33using HeuristicLab.PluginInfrastructure;
[8323]34using HeuristicLab.Problems.DataAnalysis;
35
[8371]36namespace HeuristicLab.Algorithms.DataAnalysis {
[8323]37  /// <summary>
38  ///Gaussian process regression data analysis algorithm.
39  /// </summary>
40  [Item("Gaussian Process Regression", "Gaussian process regression data analysis algorithm.")]
41  [Creatable("Data Analysis")]
42  [StorableClass]
[9096]43  public sealed class GaussianProcessRegression : GaussianProcessBase, IStorableContent {
[8371]44    public string Filename { get; set; }
45
46    public override Type ProblemType { get { return typeof(IRegressionProblem); } }
47    public new IRegressionProblem Problem {
48      get { return (IRegressionProblem)base.Problem; }
49      set { base.Problem = value; }
50    }
51
[9096]52    private const string ModelParameterName = "Model";
[8323]53
54    #region parameter properties
[9098]55    public IConstrainedValueParameter<IGaussianProcessRegressionModelCreator> GaussianProcessModelCreatorParameter {
[9096]56      get { return (IConstrainedValueParameter<IGaussianProcessRegressionModelCreator>)Parameters[ModelCreatorParameterName]; }
[8323]57    }
[9098]58    public IFixedValueParameter<GaussianProcessRegressionSolutionCreator> GaussianProcessSolutionCreatorParameter {
[9096]59      get { return (IFixedValueParameter<GaussianProcessRegressionSolutionCreator>)Parameters[SolutionCreatorParameterName]; }
[8323]60    }
61    #endregion
[8419]62
[8323]63    [StorableConstructor]
64    private GaussianProcessRegression(bool deserializing) : base(deserializing) { }
65    private GaussianProcessRegression(GaussianProcessRegression original, Cloner cloner)
66      : base(original, cloner) {
[9096]67      RegisterEventHandlers();
[8323]68    }
69    public GaussianProcessRegression()
[9096]70      : base(new RegressionProblem()) {
[8396]71      this.name = ItemName;
72      this.description = ItemDescription;
73
[9096]74      var modelCreators = ApplicationManager.Manager.GetInstances<IGaussianProcessRegressionModelCreator>();
75      var defaultModelCreator = modelCreators.First(c => c is GaussianProcessRegressionModelCreator);
[8323]76
[9096]77      // GP regression and classification algorithms only differ in the model and solution creators,
78      // thus we use a common base class and use operator parameters to implement the specific versions.
79      // Different model creators can be implemented,
80      // but the solution creator is implemented in a generic fashion already and we don't allow derived solution creators
81      Parameters.Add(new ConstrainedValueParameter<IGaussianProcessRegressionModelCreator>(ModelCreatorParameterName, "The operator to create the Gaussian process model.",
82        new ItemSet<IGaussianProcessRegressionModelCreator>(modelCreators), defaultModelCreator));
83      // this parameter is not intended to be changed,
84      Parameters.Add(new FixedValueParameter<GaussianProcessRegressionSolutionCreator>(SolutionCreatorParameterName, "The solution creator for the algorithm",
85        new GaussianProcessRegressionSolutionCreator()));
86      Parameters[SolutionCreatorParameterName].Hidden = true;
[8419]87
[9096]88      ParameterizedModelCreators();
[9098]89      ParameterizeSolutionCreator(GaussianProcessSolutionCreatorParameter.Value);
[9096]90      RegisterEventHandlers();
91    }
[8371]92
93
[9096]94    [StorableHook(HookType.AfterDeserialization)]
95    private void AfterDeserialization() {
96      RegisterEventHandlers();
97    }
[8371]98
[9096]99    public override IDeepCloneable Clone(Cloner cloner) {
100      return new GaussianProcessRegression(this, cloner);
101    }
[8371]102
[9096]103    #region events
104    private void RegisterEventHandlers() {
[9098]105      GaussianProcessModelCreatorParameter.ValueChanged += ModelCreatorParameter_ValueChanged;
[9096]106    }
[8371]107
[9096]108    private void ModelCreatorParameter_ValueChanged(object sender, EventArgs e) {
[9098]109      ParameterizedModelCreator(GaussianProcessModelCreatorParameter.Value);
[9096]110    }
111    #endregion
[8371]112
[9096]113    private void ParameterizedModelCreators() {
[9098]114      foreach (var creator in GaussianProcessModelCreatorParameter.ValidValues) {
[9096]115        ParameterizedModelCreator(creator);
116      }
117    }
[8371]118
[9096]119    private void ParameterizedModelCreator(IGaussianProcessRegressionModelCreator modelCreator) {
[8371]120      modelCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
121      modelCreator.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
122      modelCreator.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
123
[9096]124      // parameter names fixed by the algorithm
125      modelCreator.ModelParameter.ActualName = ModelParameterName;
126      modelCreator.HyperparameterParameter.ActualName = HyperparameterParameterName;
127      modelCreator.HyperparameterGradientsParameter.ActualName = HyperparameterGradientsParameterName;
128      modelCreator.NegativeLogLikelihoodParameter.ActualName = NegativeLogLikelihoodParameterName;
129    }
[8371]130
[9096]131    private void ParameterizeSolutionCreator(GaussianProcessRegressionSolutionCreator solutionCreator) {
132      solutionCreator.ModelParameter.ActualName = ModelParameterName;
[8375]133      solutionCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
[8323]134    }
135  }
136}
Note: See TracBrowser for help on using the repository browser.