Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ALPS/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessRegression.cs @ 11677

Last change on this file since 11677 was 11171, checked in by ascheibe, 10 years ago

#2115 merged r11170 (copyright update) into trunk

File size: 6.1 KB
Line 
1
2#region License Information
3/* HeuristicLab
4 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
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
23using System;
24using System.Linq;
25using HeuristicLab.Algorithms.GradientDescent;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29using HeuristicLab.Operators;
30using HeuristicLab.Optimization;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
33using HeuristicLab.PluginInfrastructure;
34using HeuristicLab.Problems.DataAnalysis;
35
36namespace HeuristicLab.Algorithms.DataAnalysis {
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]
43  public sealed class GaussianProcessRegression : GaussianProcessBase, IStorableContent {
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
52    private const string ModelParameterName = "Model";
53
54    #region parameter properties
55    public IConstrainedValueParameter<IGaussianProcessRegressionModelCreator> GaussianProcessModelCreatorParameter {
56      get { return (IConstrainedValueParameter<IGaussianProcessRegressionModelCreator>)Parameters[ModelCreatorParameterName]; }
57    }
58    public IFixedValueParameter<GaussianProcessRegressionSolutionCreator> GaussianProcessSolutionCreatorParameter {
59      get { return (IFixedValueParameter<GaussianProcessRegressionSolutionCreator>)Parameters[SolutionCreatorParameterName]; }
60    }
61    #endregion
62
63    [StorableConstructor]
64    private GaussianProcessRegression(bool deserializing) : base(deserializing) { }
65    private GaussianProcessRegression(GaussianProcessRegression original, Cloner cloner)
66      : base(original, cloner) {
67      RegisterEventHandlers();
68    }
69    public GaussianProcessRegression()
70      : base(new RegressionProblem()) {
71      this.name = ItemName;
72      this.description = ItemDescription;
73
74      var modelCreators = ApplicationManager.Manager.GetInstances<IGaussianProcessRegressionModelCreator>();
75      var defaultModelCreator = modelCreators.First(c => c is GaussianProcessRegressionModelCreator);
76
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;
87
88      ParameterizedModelCreators();
89      ParameterizeSolutionCreator(GaussianProcessSolutionCreatorParameter.Value);
90      RegisterEventHandlers();
91    }
92
93
94    [StorableHook(HookType.AfterDeserialization)]
95    private void AfterDeserialization() {
96      RegisterEventHandlers();
97    }
98
99    public override IDeepCloneable Clone(Cloner cloner) {
100      return new GaussianProcessRegression(this, cloner);
101    }
102
103    #region events
104    private void RegisterEventHandlers() {
105      GaussianProcessModelCreatorParameter.ValueChanged += ModelCreatorParameter_ValueChanged;
106    }
107
108    private void ModelCreatorParameter_ValueChanged(object sender, EventArgs e) {
109      ParameterizedModelCreator(GaussianProcessModelCreatorParameter.Value);
110    }
111    #endregion
112
113    private void ParameterizedModelCreators() {
114      foreach (var creator in GaussianProcessModelCreatorParameter.ValidValues) {
115        ParameterizedModelCreator(creator);
116      }
117    }
118
119    private void ParameterizedModelCreator(IGaussianProcessRegressionModelCreator modelCreator) {
120      modelCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
121      modelCreator.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
122      modelCreator.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
123
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    }
130
131    private void ParameterizeSolutionCreator(GaussianProcessRegressionSolutionCreator solutionCreator) {
132      solutionCreator.ModelParameter.ActualName = ModelParameterName;
133      solutionCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
134    }
135  }
136}
Note: See TracBrowser for help on using the repository browser.