Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessClassification.cs @ 12966

Last change on this file since 12966 was 12504, checked in by mkommend, 10 years ago

#2025: Changed categories for all creatables.

File size: 6.2 KB
RevLine 
[8623]1
2#region License Information
3/* HeuristicLab
[12012]4 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[8623]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;
[9096]24using System.Linq;
[8623]25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[9096]30using HeuristicLab.PluginInfrastructure;
[8623]31using HeuristicLab.Problems.DataAnalysis;
32
33namespace HeuristicLab.Algorithms.DataAnalysis {
34  /// <summary>
35  /// Gaussian process least-squares classification data analysis algorithm.
36  /// </summary>
37  [Item("Gaussian Process Least-Squares Classification", "Gaussian process least-squares classification data analysis algorithm.")]
[12504]38  [Creatable(CreatableAttribute.Categories.DataAnalysisClassification, Priority = 160)]
[8623]39  [StorableClass]
[9096]40  public sealed class GaussianProcessClassification : GaussianProcessBase, IStorableContent {
[8623]41    public string Filename { get; set; }
42
43    public override Type ProblemType { get { return typeof(IClassificationProblem); } }
44    public new IClassificationProblem Problem {
45      get { return (IClassificationProblem)base.Problem; }
46      set { base.Problem = value; }
47    }
48
[9096]49    private const string ModelParameterName = "Model";
[8623]50
51    #region parameter properties
[9098]52    public IConstrainedValueParameter<IGaussianProcessClassificationModelCreator> GaussianProcessModelCreatorParameter {
[9096]53      get { return (IConstrainedValueParameter<IGaussianProcessClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
[8623]54    }
[9098]55    public IFixedValueParameter<GaussianProcessClassificationSolutionCreator> GaussianProcessSolutionCreatorParameter {
[9096]56      get { return (IFixedValueParameter<GaussianProcessClassificationSolutionCreator>)Parameters[SolutionCreatorParameterName]; }
[8623]57    }
58    #endregion
59
60    [StorableConstructor]
61    private GaussianProcessClassification(bool deserializing) : base(deserializing) { }
62    private GaussianProcessClassification(GaussianProcessClassification original, Cloner cloner)
63      : base(original, cloner) {
[9096]64      RegisterEventHandlers();
[8623]65    }
66    public GaussianProcessClassification()
[9096]67      : base(new ClassificationProblem()) {
[8623]68      this.name = ItemName;
69      this.description = ItemDescription;
70
[9096]71      var modelCreators = ApplicationManager.Manager.GetInstances<IGaussianProcessClassificationModelCreator>();
72      var defaultModelCreator = modelCreators.First(c => c is GaussianProcessClassificationModelCreator);
[8623]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<IGaussianProcessClassificationModelCreator>(ModelCreatorParameterName, "The operator to create the Gaussian process model.",
79        new ItemSet<IGaussianProcessClassificationModelCreator>(modelCreators), defaultModelCreator));
80      // this parameter is not intended to be changed,
81      Parameters.Add(new FixedValueParameter<GaussianProcessClassificationSolutionCreator>(SolutionCreatorParameterName, "The solution creator for the algorithm",
82        new GaussianProcessClassificationSolutionCreator()));
83      Parameters[SolutionCreatorParameterName].Hidden = true;
[8623]84
[9096]85      ParameterizedModelCreators();
[9098]86      ParameterizeSolutionCreator(GaussianProcessSolutionCreatorParameter.Value);
[9096]87      RegisterEventHandlers();
88    }
[8623]89
90
[9096]91    [StorableHook(HookType.AfterDeserialization)]
92    private void AfterDeserialization() {
93      RegisterEventHandlers();
94    }
[8623]95
[9096]96    public override IDeepCloneable Clone(Cloner cloner) {
97      return new GaussianProcessClassification(this, cloner);
98    }
[8623]99
[9096]100    #region events
101    private void RegisterEventHandlers() {
[9098]102      GaussianProcessModelCreatorParameter.ValueChanged += ModelCreatorParameter_ValueChanged;
[9096]103    }
[8623]104
[9096]105    private void ModelCreatorParameter_ValueChanged(object sender, EventArgs e) {
[9098]106      ParameterizedModelCreator(GaussianProcessModelCreatorParameter.Value);
[9096]107    }
108    #endregion
[8623]109
[9096]110    private void ParameterizedModelCreators() {
[9098]111      foreach (var creator in GaussianProcessModelCreatorParameter.ValidValues) {
[9096]112        ParameterizedModelCreator(creator);
113      }
114    }
[8623]115
[9096]116    private void ParameterizedModelCreator(IGaussianProcessClassificationModelCreator modelCreator) {
[8623]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    }
[8623]127
[9096]128    private void ParameterizeSolutionCreator(GaussianProcessClassificationSolutionCreator solutionCreator) {
129      solutionCreator.ModelParameter.ActualName = ModelParameterName;
[8623]130      solutionCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
131    }
132  }
133}
Note: See TracBrowser for help on using the repository browser.