Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessHyperparameterInitializer.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: 4.9 KB
RevLine 
[8371]1#region License Information
2/* HeuristicLab
[9456]3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[8371]4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
[8396]25using HeuristicLab.Encodings.RealVectorEncoding;
[8371]26using HeuristicLab.Operators;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using HeuristicLab.Problems.DataAnalysis;
30
31namespace HeuristicLab.Algorithms.DataAnalysis {
32  [StorableClass]
[8396]33  [Item(Name = "GaussianProcessHyperparameterInitializer",
34    Description = "Initializers the hyperparameter vector based on the mean function, covariance function, and number of allowed input variables.")]
35  public sealed class GaussianProcessHyperparameterInitializer : SingleSuccessorOperator {
[8371]36    private const string MeanFunctionParameterName = "MeanFunction";
37    private const string CovarianceFunctionParameterName = "CovarianceFunction";
38    private const string ProblemDataParameterName = "ProblemData";
[8396]39    private const string HyperparameterParameterName = "Hyperparameter";
[8419]40    private const string RandomParameterName = "Random";
[8371]41
42    #region Parameter Properties
43    // in
44    public ILookupParameter<IMeanFunction> MeanFunctionParameter {
45      get { return (ILookupParameter<IMeanFunction>)Parameters[MeanFunctionParameterName]; }
46    }
47    public ILookupParameter<ICovarianceFunction> CovarianceFunctionParameter {
48      get { return (ILookupParameter<ICovarianceFunction>)Parameters[CovarianceFunctionParameterName]; }
49    }
50    public ILookupParameter<IDataAnalysisProblemData> ProblemDataParameter {
51      get { return (ILookupParameter<IDataAnalysisProblemData>)Parameters[ProblemDataParameterName]; }
52    }
[8419]53    public ILookupParameter<IRandom> RandomParameter {
54      get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }
55    }
[8371]56    // out
[8396]57    public ILookupParameter<RealVector> HyperparameterParameter {
58      get { return (ILookupParameter<RealVector>)Parameters[HyperparameterParameterName]; }
[8371]59    }
60    #endregion
61
62    #region Properties
[8375]63    private IMeanFunction MeanFunction { get { return MeanFunctionParameter.ActualValue; } }
64    private ICovarianceFunction CovarianceFunction { get { return CovarianceFunctionParameter.ActualValue; } }
65    private IDataAnalysisProblemData ProblemData { get { return ProblemDataParameter.ActualValue; } }
[8371]66    #endregion
67
68    [StorableConstructor]
[8396]69    private GaussianProcessHyperparameterInitializer(bool deserializing) : base(deserializing) { }
70    private GaussianProcessHyperparameterInitializer(GaussianProcessHyperparameterInitializer original, Cloner cloner) : base(original, cloner) { }
71    public GaussianProcessHyperparameterInitializer()
[8371]72      : base() {
73      // in
74      Parameters.Add(new LookupParameter<IMeanFunction>(MeanFunctionParameterName, "The mean function for the Gaussian process model."));
75      Parameters.Add(new LookupParameter<ICovarianceFunction>(CovarianceFunctionParameterName, "The covariance function for the Gaussian process model."));
76      Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName, "The input data for the Gaussian process."));
[8419]77      Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The pseudo random number generator to use for initializing the hyperparameter vector."));
[8371]78      // out
[8396]79      Parameters.Add(new LookupParameter<RealVector>(HyperparameterParameterName, "The initial hyperparameter vector for the Gaussian process model."));
[8371]80    }
81
82    public override IDeepCloneable Clone(Cloner cloner) {
[8396]83      return new GaussianProcessHyperparameterInitializer(this, cloner);
[8371]84    }
85
[8396]86    public override IOperation Apply() {
[8371]87      var inputVariablesCount = ProblemData.AllowedInputVariables.Count();
88      int l = 1 + MeanFunction.GetNumberOfParameters(inputVariablesCount) +
89              CovarianceFunction.GetNumberOfParameters(inputVariablesCount);
[8419]90      var r = new RealVector(l);
91      var rand = RandomParameter.ActualValue;
92      for (int i = 0; i < r.Length; i++)
[8732]93        r[i] = rand.NextDouble() * 10 - 5;
[8419]94
95      HyperparameterParameter.ActualValue = r;
[8371]96      return base.Apply();
97    }
98  }
99}
Note: See TracBrowser for help on using the repository browser.