[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] | 23 | using System;
|
---|
[9096] | 24 | using System.Linq;
|
---|
[8323] | 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
[13205] | 27 | using HeuristicLab.Data;
|
---|
[8323] | 28 | using HeuristicLab.Optimization;
|
---|
| 29 | using HeuristicLab.Parameters;
|
---|
| 30 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[9096] | 31 | using HeuristicLab.PluginInfrastructure;
|
---|
[8323] | 32 | using HeuristicLab.Problems.DataAnalysis;
|
---|
| 33 |
|
---|
[8371] | 34 | namespace HeuristicLab.Algorithms.DataAnalysis {
|
---|
[8323] | 35 | /// <summary>
|
---|
| 36 | ///Gaussian process regression data analysis algorithm.
|
---|
| 37 | /// </summary>
|
---|
| 38 | [Item("Gaussian Process Regression", "Gaussian process regression data analysis algorithm.")]
|
---|
[12504] | 39 | [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 160)]
|
---|
[8323] | 40 | [StorableClass]
|
---|
[9096] | 41 | public sealed class GaussianProcessRegression : GaussianProcessBase, IStorableContent {
|
---|
[8371] | 42 | public string Filename { get; set; }
|
---|
| 43 |
|
---|
| 44 | public override Type ProblemType { get { return typeof(IRegressionProblem); } }
|
---|
| 45 | public new IRegressionProblem Problem {
|
---|
| 46 | get { return (IRegressionProblem)base.Problem; }
|
---|
| 47 | set { base.Problem = value; }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[9096] | 50 | private const string ModelParameterName = "Model";
|
---|
[13205] | 51 | private const string CreateSolutionParameterName = "CreateSolution";
|
---|
[8323] | 52 |
|
---|
[13205] | 53 |
|
---|
[8323] | 54 | #region parameter properties
|
---|
[9098] | 55 | public IConstrainedValueParameter<IGaussianProcessRegressionModelCreator> GaussianProcessModelCreatorParameter {
|
---|
[9096] | 56 | get { return (IConstrainedValueParameter<IGaussianProcessRegressionModelCreator>)Parameters[ModelCreatorParameterName]; }
|
---|
[8323] | 57 | }
|
---|
[9098] | 58 | public IFixedValueParameter<GaussianProcessRegressionSolutionCreator> GaussianProcessSolutionCreatorParameter {
|
---|
[9096] | 59 | get { return (IFixedValueParameter<GaussianProcessRegressionSolutionCreator>)Parameters[SolutionCreatorParameterName]; }
|
---|
[8323] | 60 | }
|
---|
[13205] | 61 | public IFixedValueParameter<BoolValue> CreateSolutionParameter {
|
---|
| 62 | get { return (IFixedValueParameter<BoolValue>)Parameters[CreateSolutionParameterName]; }
|
---|
| 63 | }
|
---|
[8323] | 64 | #endregion
|
---|
[13205] | 65 | #region properties
|
---|
| 66 | public bool CreateSolution {
|
---|
| 67 | get { return CreateSolutionParameter.Value.Value; }
|
---|
| 68 | set { CreateSolutionParameter.Value.Value = value; }
|
---|
| 69 | }
|
---|
| 70 | #endregion
|
---|
[8419] | 71 |
|
---|
[8323] | 72 | [StorableConstructor]
|
---|
| 73 | private GaussianProcessRegression(bool deserializing) : base(deserializing) { }
|
---|
| 74 | private GaussianProcessRegression(GaussianProcessRegression original, Cloner cloner)
|
---|
| 75 | : base(original, cloner) {
|
---|
[9096] | 76 | RegisterEventHandlers();
|
---|
[8323] | 77 | }
|
---|
| 78 | public GaussianProcessRegression()
|
---|
[9096] | 79 | : base(new RegressionProblem()) {
|
---|
[8396] | 80 | this.name = ItemName;
|
---|
| 81 | this.description = ItemDescription;
|
---|
| 82 |
|
---|
[9096] | 83 | var modelCreators = ApplicationManager.Manager.GetInstances<IGaussianProcessRegressionModelCreator>();
|
---|
| 84 | var defaultModelCreator = modelCreators.First(c => c is GaussianProcessRegressionModelCreator);
|
---|
[8323] | 85 |
|
---|
[9096] | 86 | // GP regression and classification algorithms only differ in the model and solution creators,
|
---|
| 87 | // thus we use a common base class and use operator parameters to implement the specific versions.
|
---|
| 88 | // Different model creators can be implemented,
|
---|
| 89 | // but the solution creator is implemented in a generic fashion already and we don't allow derived solution creators
|
---|
| 90 | Parameters.Add(new ConstrainedValueParameter<IGaussianProcessRegressionModelCreator>(ModelCreatorParameterName, "The operator to create the Gaussian process model.",
|
---|
| 91 | new ItemSet<IGaussianProcessRegressionModelCreator>(modelCreators), defaultModelCreator));
|
---|
[13205] | 92 | // the solution creator cannot be changed
|
---|
[9096] | 93 | Parameters.Add(new FixedValueParameter<GaussianProcessRegressionSolutionCreator>(SolutionCreatorParameterName, "The solution creator for the algorithm",
|
---|
| 94 | new GaussianProcessRegressionSolutionCreator()));
|
---|
| 95 | Parameters[SolutionCreatorParameterName].Hidden = true;
|
---|
[13205] | 96 | // TODO: it would be better to deactivate the solution creator when this parameter is changed
|
---|
| 97 | Parameters.Add(new FixedValueParameter<BoolValue>(CreateSolutionParameterName, "Flag that indicates if a solution should be produced at the end of the run", new BoolValue(true)));
|
---|
| 98 | Parameters[CreateSolutionParameterName].Hidden = true;
|
---|
[8419] | 99 |
|
---|
[9096] | 100 | ParameterizedModelCreators();
|
---|
[9098] | 101 | ParameterizeSolutionCreator(GaussianProcessSolutionCreatorParameter.Value);
|
---|
[9096] | 102 | RegisterEventHandlers();
|
---|
| 103 | }
|
---|
[8371] | 104 |
|
---|
| 105 |
|
---|
[9096] | 106 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 107 | private void AfterDeserialization() {
|
---|
[13205] | 108 | // BackwardsCompatibility3.3
|
---|
| 109 | #region Backwards compatible code, remove with 3.4
|
---|
| 110 | if (!Parameters.ContainsKey(CreateSolutionParameterName)) {
|
---|
| 111 | Parameters.Add(new FixedValueParameter<BoolValue>(CreateSolutionParameterName, "Flag that indicates if a solution should be produced at the end of the run", new BoolValue(true)));
|
---|
| 112 | Parameters[CreateSolutionParameterName].Hidden = true;
|
---|
| 113 | }
|
---|
| 114 | #endregion
|
---|
[9096] | 115 | RegisterEventHandlers();
|
---|
| 116 | }
|
---|
[8371] | 117 |
|
---|
[9096] | 118 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 119 | return new GaussianProcessRegression(this, cloner);
|
---|
| 120 | }
|
---|
[8371] | 121 |
|
---|
[9096] | 122 | #region events
|
---|
| 123 | private void RegisterEventHandlers() {
|
---|
[9098] | 124 | GaussianProcessModelCreatorParameter.ValueChanged += ModelCreatorParameter_ValueChanged;
|
---|
[9096] | 125 | }
|
---|
[8371] | 126 |
|
---|
[9096] | 127 | private void ModelCreatorParameter_ValueChanged(object sender, EventArgs e) {
|
---|
[9098] | 128 | ParameterizedModelCreator(GaussianProcessModelCreatorParameter.Value);
|
---|
[9096] | 129 | }
|
---|
| 130 | #endregion
|
---|
[8371] | 131 |
|
---|
[9096] | 132 | private void ParameterizedModelCreators() {
|
---|
[9098] | 133 | foreach (var creator in GaussianProcessModelCreatorParameter.ValidValues) {
|
---|
[9096] | 134 | ParameterizedModelCreator(creator);
|
---|
| 135 | }
|
---|
| 136 | }
|
---|
[8371] | 137 |
|
---|
[9096] | 138 | private void ParameterizedModelCreator(IGaussianProcessRegressionModelCreator modelCreator) {
|
---|
[8371] | 139 | modelCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
|
---|
| 140 | modelCreator.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
|
---|
| 141 | modelCreator.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
|
---|
| 142 |
|
---|
[9096] | 143 | // parameter names fixed by the algorithm
|
---|
| 144 | modelCreator.ModelParameter.ActualName = ModelParameterName;
|
---|
| 145 | modelCreator.HyperparameterParameter.ActualName = HyperparameterParameterName;
|
---|
| 146 | modelCreator.HyperparameterGradientsParameter.ActualName = HyperparameterGradientsParameterName;
|
---|
| 147 | modelCreator.NegativeLogLikelihoodParameter.ActualName = NegativeLogLikelihoodParameterName;
|
---|
| 148 | }
|
---|
[8371] | 149 |
|
---|
[9096] | 150 | private void ParameterizeSolutionCreator(GaussianProcessRegressionSolutionCreator solutionCreator) {
|
---|
| 151 | solutionCreator.ModelParameter.ActualName = ModelParameterName;
|
---|
[8375] | 152 | solutionCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
|
---|
[8323] | 153 | }
|
---|
| 154 | }
|
---|
| 155 | }
|
---|