Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 13119 was 12504, checked in by mkommend, 9 years ago

#2025: Changed categories for all creatables.

File size: 6.0 KB
Line 
1
2#region License Information
3/* HeuristicLab
4 * Copyright (C) 2002-2015 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.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.PluginInfrastructure;
31using HeuristicLab.Problems.DataAnalysis;
32
33namespace HeuristicLab.Algorithms.DataAnalysis {
34  /// <summary>
35  ///Gaussian process regression data analysis algorithm.
36  /// </summary>
37  [Item("Gaussian Process Regression", "Gaussian process regression data analysis algorithm.")]
38  [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 160)]
39  [StorableClass]
40  public sealed class GaussianProcessRegression : GaussianProcessBase, IStorableContent {
41    public string Filename { get; set; }
42
43    public override Type ProblemType { get { return typeof(IRegressionProblem); } }
44    public new IRegressionProblem Problem {
45      get { return (IRegressionProblem)base.Problem; }
46      set { base.Problem = value; }
47    }
48
49    private const string ModelParameterName = "Model";
50
51    #region parameter properties
52    public IConstrainedValueParameter<IGaussianProcessRegressionModelCreator> GaussianProcessModelCreatorParameter {
53      get { return (IConstrainedValueParameter<IGaussianProcessRegressionModelCreator>)Parameters[ModelCreatorParameterName]; }
54    }
55    public IFixedValueParameter<GaussianProcessRegressionSolutionCreator> GaussianProcessSolutionCreatorParameter {
56      get { return (IFixedValueParameter<GaussianProcessRegressionSolutionCreator>)Parameters[SolutionCreatorParameterName]; }
57    }
58    #endregion
59
60    [StorableConstructor]
61    private GaussianProcessRegression(bool deserializing) : base(deserializing) { }
62    private GaussianProcessRegression(GaussianProcessRegression original, Cloner cloner)
63      : base(original, cloner) {
64      RegisterEventHandlers();
65    }
66    public GaussianProcessRegression()
67      : base(new RegressionProblem()) {
68      this.name = ItemName;
69      this.description = ItemDescription;
70
71      var modelCreators = ApplicationManager.Manager.GetInstances<IGaussianProcessRegressionModelCreator>();
72      var defaultModelCreator = modelCreators.First(c => c is GaussianProcessRegressionModelCreator);
73
74      // GP regression and classification algorithms only differ in the model and solution creators,
75      // thus we use a common base class and use operator parameters to implement the specific versions.
76      // Different model creators can be implemented,
77      // but the solution creator is implemented in a generic fashion already and we don't allow derived solution creators
78      Parameters.Add(new ConstrainedValueParameter<IGaussianProcessRegressionModelCreator>(ModelCreatorParameterName, "The operator to create the Gaussian process model.",
79        new ItemSet<IGaussianProcessRegressionModelCreator>(modelCreators), defaultModelCreator));
80      // this parameter is not intended to be changed,
81      Parameters.Add(new FixedValueParameter<GaussianProcessRegressionSolutionCreator>(SolutionCreatorParameterName, "The solution creator for the algorithm",
82        new GaussianProcessRegressionSolutionCreator()));
83      Parameters[SolutionCreatorParameterName].Hidden = true;
84
85      ParameterizedModelCreators();
86      ParameterizeSolutionCreator(GaussianProcessSolutionCreatorParameter.Value);
87      RegisterEventHandlers();
88    }
89
90
91    [StorableHook(HookType.AfterDeserialization)]
92    private void AfterDeserialization() {
93      RegisterEventHandlers();
94    }
95
96    public override IDeepCloneable Clone(Cloner cloner) {
97      return new GaussianProcessRegression(this, cloner);
98    }
99
100    #region events
101    private void RegisterEventHandlers() {
102      GaussianProcessModelCreatorParameter.ValueChanged += ModelCreatorParameter_ValueChanged;
103    }
104
105    private void ModelCreatorParameter_ValueChanged(object sender, EventArgs e) {
106      ParameterizedModelCreator(GaussianProcessModelCreatorParameter.Value);
107    }
108    #endregion
109
110    private void ParameterizedModelCreators() {
111      foreach (var creator in GaussianProcessModelCreatorParameter.ValidValues) {
112        ParameterizedModelCreator(creator);
113      }
114    }
115
116    private void ParameterizedModelCreator(IGaussianProcessRegressionModelCreator modelCreator) {
117      modelCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
118      modelCreator.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
119      modelCreator.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
120
121      // parameter names fixed by the algorithm
122      modelCreator.ModelParameter.ActualName = ModelParameterName;
123      modelCreator.HyperparameterParameter.ActualName = HyperparameterParameterName;
124      modelCreator.HyperparameterGradientsParameter.ActualName = HyperparameterGradientsParameterName;
125      modelCreator.NegativeLogLikelihoodParameter.ActualName = NegativeLogLikelihoodParameterName;
126    }
127
128    private void ParameterizeSolutionCreator(GaussianProcessRegressionSolutionCreator solutionCreator) {
129      solutionCreator.ModelParameter.ActualName = ModelParameterName;
130      solutionCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
131    }
132  }
133}
Note: See TracBrowser for help on using the repository browser.