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 |
|
---|
23 | using System;
|
---|
24 | using HeuristicLab.Algorithms.GradientDescent;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Operators;
|
---|
29 | using HeuristicLab.Optimization;
|
---|
30 | using HeuristicLab.Parameters;
|
---|
31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
32 | using HeuristicLab.Problems.DataAnalysis;
|
---|
33 |
|
---|
34 | namespace HeuristicLab.Algorithms.DataAnalysis {
|
---|
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]
|
---|
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 |
|
---|
50 | private const string MeanFunctionParameterName = "MeanFunction";
|
---|
51 | private const string CovarianceFunctionParameterName = "CovarianceFunction";
|
---|
52 | private const string MinimizationIterationsParameterName = "Iterations";
|
---|
53 | private const string ApproximateGradientsParameterName = "ApproximateGradients";
|
---|
54 | private const string SeedParameterName = "Seed";
|
---|
55 | private const string SetSeedRandomlyParameterName = "SetSeedRandomly";
|
---|
56 |
|
---|
57 | #region parameter properties
|
---|
58 | public IValueParameter<IMeanFunction> MeanFunctionParameter {
|
---|
59 | get { return (IValueParameter<IMeanFunction>)Parameters[MeanFunctionParameterName]; }
|
---|
60 | }
|
---|
61 | public IValueParameter<ICovarianceFunction> CovarianceFunctionParameter {
|
---|
62 | get { return (IValueParameter<ICovarianceFunction>)Parameters[CovarianceFunctionParameterName]; }
|
---|
63 | }
|
---|
64 | public IValueParameter<IntValue> MinimizationIterationsParameter {
|
---|
65 | get { return (IValueParameter<IntValue>)Parameters[MinimizationIterationsParameterName]; }
|
---|
66 | }
|
---|
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 | }
|
---|
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 | }
|
---|
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; } }
|
---|
89 | #endregion
|
---|
90 |
|
---|
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() {
|
---|
98 | this.name = ItemName;
|
---|
99 | this.description = ItemDescription;
|
---|
100 |
|
---|
101 | Problem = new RegressionProblem();
|
---|
102 |
|
---|
103 | Parameters.Add(new ValueParameter<IMeanFunction>(MeanFunctionParameterName, "The mean function to use.", new MeanConst()));
|
---|
104 | Parameters.Add(new ValueParameter<ICovarianceFunction>(CovarianceFunctionParameterName, "The covariance function to use.", new CovarianceSEiso()));
|
---|
105 | Parameters.Add(new ValueParameter<IntValue>(MinimizationIterationsParameterName, "The number of iterations for likelihood optimization with LM-BFGS.", new IntValue(20)));
|
---|
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 |
|
---|
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
|
---|
111 |
|
---|
112 | var randomCreator = new HeuristicLab.Random.RandomCreator();
|
---|
113 | var gpInitializer = new GaussianProcessHyperparameterInitializer();
|
---|
114 | var bfgsInitializer = new LbfgsInitializer();
|
---|
115 | var makeStep = new LbfgsMakeStep();
|
---|
116 | var branch = new ConditionalBranch();
|
---|
117 | var modelCreator = new GaussianProcessRegressionModelCreator();
|
---|
118 | var updateResults = new LbfgsUpdateResults();
|
---|
119 | var analyzer = new LbfgsAnalyzer();
|
---|
120 | var finalModelCreator = new GaussianProcessRegressionModelCreator();
|
---|
121 | var finalAnalyzer = new LbfgsAnalyzer();
|
---|
122 | var solutionCreator = new GaussianProcessRegressionSolutionCreator();
|
---|
123 |
|
---|
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;
|
---|
130 |
|
---|
131 | gpInitializer.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
|
---|
132 | gpInitializer.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
|
---|
133 | gpInitializer.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
|
---|
134 | gpInitializer.HyperparameterParameter.ActualName = modelCreator.HyperparameterParameter.Name;
|
---|
135 | gpInitializer.RandomParameter.ActualName = randomCreator.RandomParameter.Name;
|
---|
136 | gpInitializer.Successor = bfgsInitializer;
|
---|
137 |
|
---|
138 | bfgsInitializer.IterationsParameter.ActualName = MinimizationIterationsParameterName;
|
---|
139 | bfgsInitializer.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name;
|
---|
140 | bfgsInitializer.ApproximateGradientsParameter.ActualName = ApproximateGradientsParameterName;
|
---|
141 | bfgsInitializer.Successor = makeStep;
|
---|
142 |
|
---|
143 | makeStep.StateParameter.ActualName = bfgsInitializer.StateParameter.Name;
|
---|
144 | makeStep.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name;
|
---|
145 | makeStep.Successor = branch;
|
---|
146 |
|
---|
147 | branch.ConditionParameter.ActualName = makeStep.TerminationCriterionParameter.Name;
|
---|
148 | branch.FalseBranch = modelCreator;
|
---|
149 | branch.TrueBranch = finalModelCreator;
|
---|
150 |
|
---|
151 | modelCreator.ProblemDataParameter.ActualName = Problem.ProblemDataParameter.Name;
|
---|
152 | modelCreator.MeanFunctionParameter.ActualName = MeanFunctionParameterName;
|
---|
153 | modelCreator.CovarianceFunctionParameter.ActualName = CovarianceFunctionParameterName;
|
---|
154 | modelCreator.Successor = updateResults;
|
---|
155 |
|
---|
156 | updateResults.StateParameter.ActualName = bfgsInitializer.StateParameter.Name;
|
---|
157 | updateResults.QualityParameter.ActualName = modelCreator.NegativeLogLikelihoodParameter.Name;
|
---|
158 | updateResults.QualityGradientsParameter.ActualName = modelCreator.HyperparameterGradientsParameter.Name;
|
---|
159 | updateResults.ApproximateGradientsParameter.ActualName = ApproximateGradientsParameterName;
|
---|
160 | updateResults.Successor = analyzer;
|
---|
161 |
|
---|
162 | analyzer.QualityParameter.ActualName = modelCreator.NegativeLogLikelihoodParameter.Name;
|
---|
163 | analyzer.PointParameter.ActualName = modelCreator.HyperparameterParameter.Name;
|
---|
164 | analyzer.QualityGradientsParameter.ActualName = modelCreator.HyperparameterGradientsParameter.Name;
|
---|
165 | analyzer.StateParameter.ActualName = bfgsInitializer.StateParameter.Name;
|
---|
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;
|
---|
174 | finalModelCreator.HyperparameterParameter.ActualName = bfgsInitializer.PointParameter.ActualName;
|
---|
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;
|
---|
187 | }
|
---|
188 |
|
---|
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 | }
|
---|