Free cookie consent management tool by TermsFeed Policy Generator

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

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

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

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