1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
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 |
|
---|
22 | using System;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.Algorithms.DataAnalysis {
|
---|
28 | [StorableClass]
|
---|
29 | [Item(Name = "CovarianceNoise",
|
---|
30 | Description = "Noise covariance function for Gaussian processes.")]
|
---|
31 | public class CovarianceNoise : Item, ICovarianceFunction {
|
---|
32 | [Storable]
|
---|
33 | private double sf2;
|
---|
34 |
|
---|
35 | [StorableConstructor]
|
---|
36 | protected CovarianceNoise(bool deserializing)
|
---|
37 | : base(deserializing) {
|
---|
38 | }
|
---|
39 |
|
---|
40 | protected CovarianceNoise(CovarianceNoise original, Cloner cloner)
|
---|
41 | : base(original, cloner) {
|
---|
42 | this.sf2 = original.sf2;
|
---|
43 | }
|
---|
44 |
|
---|
45 | public CovarianceNoise()
|
---|
46 | : base() {
|
---|
47 | }
|
---|
48 |
|
---|
49 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
50 | return new CovarianceNoise(this, cloner);
|
---|
51 | }
|
---|
52 |
|
---|
53 | public int GetNumberOfParameters(int numberOfVariables) {
|
---|
54 | return 1;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public void SetParameter(double[] hyp) {
|
---|
58 | this.sf2 = Math.Min(1E6, Math.Exp(2 * hyp[0])); // upper limit for scale
|
---|
59 | }
|
---|
60 | public void SetData(double[,] x) {
|
---|
61 | // nothing to do
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | public void SetData(double[,] x, double[,] xt) {
|
---|
66 | // nothing to do
|
---|
67 | }
|
---|
68 |
|
---|
69 | public double GetCovariance(int i, int j) {
|
---|
70 | if (i == j) return sf2;
|
---|
71 | else return 0.0;
|
---|
72 | }
|
---|
73 |
|
---|
74 | public double GetGradient(int i, int j, int k) {
|
---|
75 | if (k != 0) throw new ArgumentException("CovarianceConst has only one hyperparameters", "k");
|
---|
76 | if (i == j)
|
---|
77 | return 2 * sf2;
|
---|
78 | else
|
---|
79 | return 0.0;
|
---|
80 | }
|
---|
81 | }
|
---|
82 | }
|
---|