[8323] | 1 |
|
---|
| 2 | #region License Information
|
---|
| 3 | /* HeuristicLab
|
---|
| 4 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 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;
|
---|
[8401] | 24 | using HeuristicLab.Algorithms.GradientDescent;
|
---|
[8323] | 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
[8371] | 28 | using HeuristicLab.Operators;
|
---|
[8323] | 29 | using HeuristicLab.Optimization;
|
---|
| 30 | using HeuristicLab.Parameters;
|
---|
| 31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 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.")]
|
---|
| 39 | [Creatable("Data Analysis")]
|
---|
| 40 | [StorableClass]
|
---|
[8371] | 41 | public sealed class GaussianProcessRegression : EngineAlgorithm, IStorableContent {
|
---|
| 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 |
|
---|
[8323] | 50 | private const string MeanFunctionParameterName = "MeanFunction";
|
---|
| 51 | private const string CovarianceFunctionParameterName = "CovarianceFunction";
|
---|
[8371] | 52 | private const string MinimizationIterationsParameterName = "Iterations";
|
---|
[8396] | 53 | private const string ApproximateGradientsParameterName = "ApproximateGradients";
|
---|
[8419] | 54 | private const string SeedParameterName = "Seed";
|
---|
| 55 | private const string SetSeedRandomlyParameterName = "SetSeedRandomly";
|
---|
[8323] | 56 |
|
---|
| 57 | #region parameter properties
|
---|
[8494] | 58 | public IValueParameter<IMeanFunction> MeanFunctionParameter {
|
---|
[8495] | 59 | get { return (IValueParameter<IMeanFunction>)Parameters[MeanFunctionParameterName]; }
|
---|
[8323] | 60 | }
|
---|
[8494] | 61 | public IValueParameter<ICovarianceFunction> CovarianceFunctionParameter {
|
---|
[8495] | 62 | get { return (IValueParameter<ICovarianceFunction>)Parameters[CovarianceFunctionParameterName]; }
|
---|
[8323] | 63 | }
|
---|
| 64 | public IValueParameter<IntValue> MinimizationIterationsParameter {
|
---|
| 65 | get { return (IValueParameter<IntValue>)Parameters[MinimizationIterationsParameterName]; }
|
---|
| 66 | }
|
---|
[8419] | 67 | public IValueParameter<IntValue> SeedParameter {
|
---|
| 68 | get { return (IValueParameter<IntValue>)Parameters[SeedParameterName]; }
|
---|
| 69 | }
|
---|
| 70 | public IValueParameter<BoolValue> SetSeedRandomlyParameter {
|
---|
| 71 | get { return (IValueParameter<BoolValue>)Parameters[SetSeedRandomlyParameterName]; }
|
---|
| 72 | }
|
---|
[8323] | 73 | #endregion
|
---|
| 74 | #region properties
|
---|
| 75 | public IMeanFunction MeanFunction {
|
---|
| 76 | set { MeanFunctionParameter.Value = value; }
|
---|
| 77 | get { return MeanFunctionParameter.Value; }
|
---|
| 78 | }
|
---|
| 79 | public ICovarianceFunction CovarianceFunction {
|
---|
| 80 | set { CovarianceFunctionParameter.Value = value; }
|
---|
| 81 | get { return CovarianceFunctionParameter.Value; }
|
---|
| 82 | }
|
---|
| 83 | public int MinimizationIterations {
|
---|
| 84 | set { MinimizationIterationsParameter.Value.Value = value; }
|
---|
| 85 | get { return MinimizationIterationsParameter.Value.Value; }
|
---|
| 86 | }
|
---|
[8419] | 87 | public int Seed { get { return SeedParameter.Value.Value; } set { SeedParameter.Value.Value = value; } }
|
---|
| 88 | public bool SetSeedRandomly { get { return SetSeedRandomlyParameter.Value.Value; } set { SetSeedRandomlyParameter.Value.Value = value; } }
|
---|
[8323] | 89 | #endregion
|
---|
[8419] | 90 |
|
---|
[8323] | 91 | [StorableConstructor]
|
---|
| 92 | private GaussianProcessRegression(bool deserializing) : base(deserializing) { }
|
---|
| 93 | private GaussianProcessRegression(GaussianProcessRegression original, Cloner cloner)
|
---|
| 94 | : base(original, cloner) {
|
---|
| 95 | }
|
---|
| 96 | public GaussianProcessRegression()
|
---|
| 97 | : base() {
|
---|
[8396] | 98 | this.name = ItemName;
|
---|
| 99 | this.description = ItemDescription;
|
---|
| 100 |
|
---|
[8323] | 101 | Problem = new RegressionProblem();
|
---|
| 102 |
|
---|
[8494] | 103 | Parameters.Add(new ValueParameter<IMeanFunction>(MeanFunctionParameterName, "The mean function to use.", new MeanConst()));
|
---|
[8615] | 104 | Parameters.Add(new ValueParameter<ICovarianceFunction>(CovarianceFunctionParameterName, "The covariance function to use.", new CovarianceSquaredExponentialIso()));
|
---|
[8396] | 105 | Parameters.Add(new ValueParameter<IntValue>(MinimizationIterationsParameterName, "The number of iterations for likelihood optimization with LM-BFGS.", new IntValue(20)));
|
---|
[8419] | 106 | Parameters.Add(new ValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
|
---|
| 107 | Parameters.Add(new ValueParameter<BoolValue>(SetSeedRandomlyParameterName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
|
---|
| 108 |
|
---|
[8396] | 109 | Parameters.Add(new ValueParameter<BoolValue>(ApproximateGradientsParameterName, "Indicates that gradients should not be approximated (necessary for LM-BFGS).", new BoolValue(false)));
|
---|
| 110 | Parameters[ApproximateGradientsParameterName].Hidden = true; // should not be changed
|
---|
[8371] | 111 |
|
---|
[8419] | 112 | var randomCreator = new HeuristicLab.Random.RandomCreator();
|
---|
[8396] | 113 | var gpInitializer = new GaussianProcessHyperparameterInitializer();
|
---|
| 114 | var bfgsInitializer = new LbfgsInitializer();
|
---|
| 115 | var makeStep = new LbfgsMakeStep();
|
---|
[8371] | 116 | var branch = new ConditionalBranch();
|
---|
| 117 | var modelCreator = new GaussianProcessRegressionModelCreator();
|
---|
[8396] | 118 | var updateResults = new LbfgsUpdateResults();
|
---|
| 119 | var analyzer = new LbfgsAnalyzer();
|
---|
[8375] | 120 | var finalModelCreator = new GaussianProcessRegressionModelCreator();
|
---|
[8396] | 121 | var finalAnalyzer = new LbfgsAnalyzer();
|
---|
[8375] | 122 | var solutionCreator = new GaussianProcessRegressionSolutionCreator();
|
---|
[8371] | 123 |
|
---|
[8419] | 124 | OperatorGraph.InitialOperator = randomCreator;
|
---|
| 125 | randomCreator.SeedParameter.ActualName = SeedParameterName;
|
---|
| 126 | randomCreator.SeedParameter.Value = null;
|
---|
| 127 | randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameterName;
|
---|
| 128 | randomCreator.SetSeedRandomlyParameter.Value = null;
|
---|
| 129 | randomCreator.Successor = gpInitializer;
|
---|
[8371] | 130 |
|
---|
[8396] | 131 | gpInitializer.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
|
---|
| 132 | gpInitializer.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
|
---|
| 133 | gpInitializer.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
|
---|
| 134 | gpInitializer.HyperparameterParameter.ActualName = modelCreator.HyperparameterParameter.Name;
|
---|
[8419] | 135 | gpInitializer.RandomParameter.ActualName = randomCreator.RandomParameter.Name;
|
---|
[8396] | 136 | gpInitializer.Successor = bfgsInitializer;
|
---|
[8371] | 137 |
|
---|
[8396] | 138 | bfgsInitializer.IterationsParameter.ActualName = MinimizationIterationsParameterName;
|
---|
| 139 | bfgsInitializer.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name;
|
---|
| 140 | bfgsInitializer.ApproximateGradientsParameter.ActualName = ApproximateGradientsParameterName;
|
---|
| 141 | bfgsInitializer.Successor = makeStep;
|
---|
[8371] | 142 |
|
---|
[8396] | 143 | makeStep.StateParameter.ActualName = bfgsInitializer.StateParameter.Name;
|
---|
[8375] | 144 | makeStep.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name;
|
---|
[8371] | 145 | makeStep.Successor = branch;
|
---|
| 146 |
|
---|
| 147 | branch.ConditionParameter.ActualName = makeStep.TerminationCriterionParameter.Name;
|
---|
| 148 | branch.FalseBranch = modelCreator;
|
---|
[8375] | 149 | branch.TrueBranch = finalModelCreator;
|
---|
[8371] | 150 |
|
---|
| 151 | modelCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
|
---|
| 152 | modelCreator.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
|
---|
| 153 | modelCreator.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
|
---|
| 154 | modelCreator.Successor = updateResults;
|
---|
| 155 |
|
---|
[8396] | 156 | updateResults.StateParameter.ActualName = bfgsInitializer.StateParameter.Name;
|
---|
[8375] | 157 | updateResults.QualityParameter.ActualName = modelCreator.NegativeLogLikelihoodParameter.Name;
|
---|
| 158 | updateResults.QualityGradientsParameter.ActualName = modelCreator.HyperparameterGradientsParameter.Name;
|
---|
[8396] | 159 | updateResults.ApproximateGradientsParameter.ActualName = ApproximateGradientsParameterName;
|
---|
[8375] | 160 | updateResults.Successor = analyzer;
|
---|
[8371] | 161 |
|
---|
[8375] | 162 | analyzer.QualityParameter.ActualName = modelCreator.NegativeLogLikelihoodParameter.Name;
|
---|
| 163 | analyzer.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name;
|
---|
| 164 | analyzer.QualityGradientsParameter.ActualName = modelCreator.HyperparameterGradientsParameter.Name;
|
---|
[8396] | 165 | analyzer.StateParameter.ActualName = bfgsInitializer.StateParameter.Name;
|
---|
[8375] | 166 | analyzer.PointsTableParameter.ActualName = "Hyperparameter table";
|
---|
| 167 | analyzer.QualityGradientsTableParameter.ActualName = "Gradients table";
|
---|
| 168 | analyzer.QualitiesTableParameter.ActualName = "Negative log likelihood table";
|
---|
| 169 | analyzer.Successor = makeStep;
|
---|
| 170 |
|
---|
| 171 | finalModelCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
|
---|
| 172 | finalModelCreator.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
|
---|
| 173 | finalModelCreator.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
|
---|
[8396] | 174 | finalModelCreator.HyperparameterParameter.ActualName = bfgsInitializer.PointParameter.ActualName;
|
---|
[8375] | 175 | finalModelCreator.Successor = finalAnalyzer;
|
---|
| 176 |
|
---|
| 177 | finalAnalyzer.QualityParameter.ActualName = modelCreator.NegativeLogLikelihoodParameter.Name;
|
---|
| 178 | finalAnalyzer.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name;
|
---|
| 179 | finalAnalyzer.QualityGradientsParameter.ActualName = modelCreator.HyperparameterGradientsParameter.Name;
|
---|
| 180 | finalAnalyzer.PointsTableParameter.ActualName = analyzer.PointsTableParameter.ActualName;
|
---|
| 181 | finalAnalyzer.QualityGradientsTableParameter.ActualName = analyzer.QualityGradientsTableParameter.ActualName;
|
---|
| 182 | finalAnalyzer.QualitiesTableParameter.ActualName = analyzer.QualitiesTableParameter.ActualName;
|
---|
| 183 | finalAnalyzer.Successor = solutionCreator;
|
---|
| 184 |
|
---|
| 185 | solutionCreator.ModelParameter.ActualName = finalModelCreator.ModelParameter.Name;
|
---|
| 186 | solutionCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
|
---|
[8323] | 187 | }
|
---|
[8375] | 188 |
|
---|
[8323] | 189 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 190 | private void AfterDeserialization() { }
|
---|
| 191 |
|
---|
| 192 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 193 | return new GaussianProcessRegression(this, cloner);
|
---|
| 194 | }
|
---|
| 195 | }
|
---|
| 196 | }
|
---|