Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2025: Changed categories for all creatables.

File size: 6.0 KB
RevLine 
[8323]1
2#region License Information
3/* HeuristicLab
[12012]4 * Copyright (C) 2002-2015 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;
[8323]25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[9096]30using HeuristicLab.PluginInfrastructure;
[8323]31using HeuristicLab.Problems.DataAnalysis;
32
[8371]33namespace HeuristicLab.Algorithms.DataAnalysis {
[8323]34  /// <summary>
35  ///Gaussian process regression data analysis algorithm.
36  /// </summary>
37  [Item("Gaussian Process Regression", "Gaussian process regression data analysis algorithm.")]
[12504]38  [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 160)]
[8323]39  [StorableClass]
[9096]40  public sealed class GaussianProcessRegression : GaussianProcessBase, IStorableContent {
[8371]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
[9096]49    private const string ModelParameterName = "Model";
[8323]50
51    #region parameter properties
[9098]52    public IConstrainedValueParameter<IGaussianProcessRegressionModelCreator> GaussianProcessModelCreatorParameter {
[9096]53      get { return (IConstrainedValueParameter<IGaussianProcessRegressionModelCreator>)Parameters[ModelCreatorParameterName]; }
[8323]54    }
[9098]55    public IFixedValueParameter<GaussianProcessRegressionSolutionCreator> GaussianProcessSolutionCreatorParameter {
[9096]56      get { return (IFixedValueParameter<GaussianProcessRegressionSolutionCreator>)Parameters[SolutionCreatorParameterName]; }
[8323]57    }
58    #endregion
[8419]59
[8323]60    [StorableConstructor]
61    private GaussianProcessRegression(bool deserializing) : base(deserializing) { }
62    private GaussianProcessRegression(GaussianProcessRegression original, Cloner cloner)
63      : base(original, cloner) {
[9096]64      RegisterEventHandlers();
[8323]65    }
66    public GaussianProcessRegression()
[9096]67      : base(new RegressionProblem()) {
[8396]68      this.name = ItemName;
69      this.description = ItemDescription;
70
[9096]71      var modelCreators = ApplicationManager.Manager.GetInstances<IGaussianProcessRegressionModelCreator>();
72      var defaultModelCreator = modelCreators.First(c => c is GaussianProcessRegressionModelCreator);
[8323]73
[9096]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;
[8419]84
[9096]85      ParameterizedModelCreators();
[9098]86      ParameterizeSolutionCreator(GaussianProcessSolutionCreatorParameter.Value);
[9096]87      RegisterEventHandlers();
88    }
[8371]89
90
[9096]91    [StorableHook(HookType.AfterDeserialization)]
92    private void AfterDeserialization() {
93      RegisterEventHandlers();
94    }
[8371]95
[9096]96    public override IDeepCloneable Clone(Cloner cloner) {
97      return new GaussianProcessRegression(this, cloner);
98    }
[8371]99
[9096]100    #region events
101    private void RegisterEventHandlers() {
[9098]102      GaussianProcessModelCreatorParameter.ValueChanged += ModelCreatorParameter_ValueChanged;
[9096]103    }
[8371]104
[9096]105    private void ModelCreatorParameter_ValueChanged(object sender, EventArgs e) {
[9098]106      ParameterizedModelCreator(GaussianProcessModelCreatorParameter.Value);
[9096]107    }
108    #endregion
[8371]109
[9096]110    private void ParameterizedModelCreators() {
[9098]111      foreach (var creator in GaussianProcessModelCreatorParameter.ValidValues) {
[9096]112        ParameterizedModelCreator(creator);
113      }
114    }
[8371]115
[9096]116    private void ParameterizedModelCreator(IGaussianProcessRegressionModelCreator modelCreator) {
[8371]117      modelCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
118      modelCreator.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
119      modelCreator.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
120
[9096]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    }
[8371]127
[9096]128    private void ParameterizeSolutionCreator(GaussianProcessRegressionSolutionCreator solutionCreator) {
129      solutionCreator.ModelParameter.ActualName = ModelParameterName;
[8375]130      solutionCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
[8323]131    }
132  }
133}
Note: See TracBrowser for help on using the repository browser.