[8623] | 1 |
|
---|
| 2 | #region License Information
|
---|
| 3 | /* HeuristicLab
|
---|
[17180] | 4 | * Copyright (C) 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 |
|
---|
| 23 | using System;
|
---|
[9096] | 24 | using System.Linq;
|
---|
[8623] | 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
[13205] | 27 | using HeuristicLab.Data;
|
---|
[8623] | 28 | using HeuristicLab.Parameters;
|
---|
[16565] | 29 | using HEAL.Attic;
|
---|
[9096] | 30 | using HeuristicLab.PluginInfrastructure;
|
---|
[8623] | 31 | using HeuristicLab.Problems.DataAnalysis;
|
---|
| 32 |
|
---|
| 33 | namespace 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)]
|
---|
[16565] | 39 | [StorableType("5D8711E4-1A3F-45E7-83A5-E9BBAC239793")]
|
---|
[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";
|
---|
[13205] | 50 | private const string CreateSolutionParameterName = "CreateSolution";
|
---|
[8623] | 51 |
|
---|
| 52 | #region parameter properties
|
---|
[9098] | 53 | public IConstrainedValueParameter<IGaussianProcessClassificationModelCreator> GaussianProcessModelCreatorParameter {
|
---|
[9096] | 54 | get { return (IConstrainedValueParameter<IGaussianProcessClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
|
---|
[8623] | 55 | }
|
---|
[9098] | 56 | public IFixedValueParameter<GaussianProcessClassificationSolutionCreator> GaussianProcessSolutionCreatorParameter {
|
---|
[9096] | 57 | get { return (IFixedValueParameter<GaussianProcessClassificationSolutionCreator>)Parameters[SolutionCreatorParameterName]; }
|
---|
[8623] | 58 | }
|
---|
[13205] | 59 | public IFixedValueParameter<BoolValue> CreateSolutionParameter {
|
---|
| 60 | get { return (IFixedValueParameter<BoolValue>)Parameters[CreateSolutionParameterName]; }
|
---|
| 61 | }
|
---|
[8623] | 62 | #endregion
|
---|
[13205] | 63 | #region properties
|
---|
| 64 | public bool CreateSolution {
|
---|
| 65 | get { return CreateSolutionParameter.Value.Value; }
|
---|
| 66 | set { CreateSolutionParameter.Value.Value = value; }
|
---|
| 67 | }
|
---|
| 68 | #endregion
|
---|
[8623] | 69 |
|
---|
| 70 | [StorableConstructor]
|
---|
[16565] | 71 | private GaussianProcessClassification(StorableConstructorFlag _) : base(_) { }
|
---|
[8623] | 72 | private GaussianProcessClassification(GaussianProcessClassification original, Cloner cloner)
|
---|
| 73 | : base(original, cloner) {
|
---|
[9096] | 74 | RegisterEventHandlers();
|
---|
[8623] | 75 | }
|
---|
| 76 | public GaussianProcessClassification()
|
---|
[9096] | 77 | : base(new ClassificationProblem()) {
|
---|
[8623] | 78 | this.name = ItemName;
|
---|
| 79 | this.description = ItemDescription;
|
---|
| 80 |
|
---|
[9096] | 81 | var modelCreators = ApplicationManager.Manager.GetInstances<IGaussianProcessClassificationModelCreator>();
|
---|
| 82 | var defaultModelCreator = modelCreators.First(c => c is GaussianProcessClassificationModelCreator);
|
---|
[8623] | 83 |
|
---|
[9096] | 84 | // GP regression and classification algorithms only differ in the model and solution creators,
|
---|
| 85 | // thus we use a common base class and use operator parameters to implement the specific versions.
|
---|
| 86 | // Different model creators can be implemented,
|
---|
| 87 | // but the solution creator is implemented in a generic fashion already and we don't allow derived solution creators
|
---|
| 88 | Parameters.Add(new ConstrainedValueParameter<IGaussianProcessClassificationModelCreator>(ModelCreatorParameterName, "The operator to create the Gaussian process model.",
|
---|
| 89 | new ItemSet<IGaussianProcessClassificationModelCreator>(modelCreators), defaultModelCreator));
|
---|
| 90 | // this parameter is not intended to be changed,
|
---|
| 91 | Parameters.Add(new FixedValueParameter<GaussianProcessClassificationSolutionCreator>(SolutionCreatorParameterName, "The solution creator for the algorithm",
|
---|
| 92 | new GaussianProcessClassificationSolutionCreator()));
|
---|
| 93 | Parameters[SolutionCreatorParameterName].Hidden = true;
|
---|
[13205] | 94 | // TODO: it would be better to deactivate the solution creator when this parameter is changed
|
---|
| 95 | Parameters.Add(new FixedValueParameter<BoolValue>(CreateSolutionParameterName, "Flag that indicates if a solution should be produced at the end of the run", new BoolValue(true)));
|
---|
| 96 | Parameters[CreateSolutionParameterName].Hidden = true;
|
---|
[8623] | 97 |
|
---|
[9096] | 98 | ParameterizedModelCreators();
|
---|
[9098] | 99 | ParameterizeSolutionCreator(GaussianProcessSolutionCreatorParameter.Value);
|
---|
[9096] | 100 | RegisterEventHandlers();
|
---|
| 101 | }
|
---|
[8623] | 102 |
|
---|
| 103 |
|
---|
[9096] | 104 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 105 | private void AfterDeserialization() {
|
---|
[13205] | 106 | // BackwardsCompatibility3.3
|
---|
| 107 | #region Backwards compatible code, remove with 3.4
|
---|
| 108 | if (!Parameters.ContainsKey(CreateSolutionParameterName)) {
|
---|
| 109 | Parameters.Add(new FixedValueParameter<BoolValue>(CreateSolutionParameterName, "Flag that indicates if a solution should be produced at the end of the run", new BoolValue(true)));
|
---|
| 110 | Parameters[CreateSolutionParameterName].Hidden = true;
|
---|
| 111 | }
|
---|
| 112 | #endregion
|
---|
[9096] | 113 | RegisterEventHandlers();
|
---|
| 114 | }
|
---|
[8623] | 115 |
|
---|
[9096] | 116 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 117 | return new GaussianProcessClassification(this, cloner);
|
---|
| 118 | }
|
---|
[8623] | 119 |
|
---|
[9096] | 120 | #region events
|
---|
| 121 | private void RegisterEventHandlers() {
|
---|
[9098] | 122 | GaussianProcessModelCreatorParameter.ValueChanged += ModelCreatorParameter_ValueChanged;
|
---|
[9096] | 123 | }
|
---|
[8623] | 124 |
|
---|
[9096] | 125 | private void ModelCreatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[9098] | 126 | ParameterizedModelCreator(GaussianProcessModelCreatorParameter.Value);
|
---|
[9096] | 127 | }
|
---|
| 128 | #endregion
|
---|
[8623] | 129 |
|
---|
[9096] | 130 | private void ParameterizedModelCreators() {
|
---|
[9098] | 131 | foreach (var creator in GaussianProcessModelCreatorParameter.ValidValues) {
|
---|
[9096] | 132 | ParameterizedModelCreator(creator);
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
[8623] | 135 |
|
---|
[9096] | 136 | private void ParameterizedModelCreator(IGaussianProcessClassificationModelCreator modelCreator) {
|
---|
[8623] | 137 | modelCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
|
---|
| 138 | modelCreator.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
|
---|
| 139 | modelCreator.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
|
---|
| 140 |
|
---|
[9096] | 141 | // parameter names fixed by the algorithm
|
---|
| 142 | modelCreator.ModelParameter.ActualName = ModelParameterName;
|
---|
| 143 | modelCreator.HyperparameterParameter.ActualName = HyperparameterParameterName;
|
---|
| 144 | modelCreator.HyperparameterGradientsParameter.ActualName = HyperparameterGradientsParameterName;
|
---|
| 145 | modelCreator.NegativeLogLikelihoodParameter.ActualName = NegativeLogLikelihoodParameterName;
|
---|
| 146 | }
|
---|
[8623] | 147 |
|
---|
[9096] | 148 | private void ParameterizeSolutionCreator(GaussianProcessClassificationSolutionCreator solutionCreator) {
|
---|
| 149 | solutionCreator.ModelParameter.ActualName = ModelParameterName;
|
---|
[8623] | 150 | solutionCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
|
---|
| 151 | }
|
---|
| 152 | }
|
---|
| 153 | }
|
---|