Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/CovarianceFunction.cs @ 8592

Last change on this file since 8592 was 8582, checked in by gkronber, 12 years ago

#1902 implemented a few covariance functions as parameterized named items. Implemented rudimentary view for Gaussian process models.

File size: 3.4 KB
RevLine 
[8582]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
22using System;
23using System.Collections.Generic;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Algorithms.DataAnalysis {
30  [StorableClass]
31  // base class for covariance functions
32  public abstract class CovarianceFunction : ParameterizedNamedItem, ICovarianceFunction {
33    [StorableConstructor]
34    protected CovarianceFunction(bool deserializing)
35      : base(deserializing) {
36    }
37
38    protected CovarianceFunction(CovarianceFunction original, Cloner cloner)
39      : base(original, cloner) {
40    }
41
42    protected CovarianceFunction()
43      : base() {
44      Name = ItemName;
45      Description = ItemDescription;
46    }
47
48    protected void SetNullableDoubleParameter(IValueParameter<DoubleValue> parameter, double? value) {
49      if (value.HasValue) {
50        parameter.Value = new DoubleValue(value.Value);
51      } else {
52        parameter.Value = null;
53      }
54    }
55
56    protected double? GetNullableDoubleParameter(IValueParameter<DoubleValue> parameter) {
57      return parameter.Value == null ? (double?)null : parameter.Value.Value;
58    }
59
60    protected void AttachValueChangeHandler<T, U>(IValueParameter<T> parameter, Action action)
61      where T : ValueTypeValue<U>
62      where U : struct {
63      parameter.ValueChanged += (sender, args) => {
64        if (parameter.Value != null) {
65          parameter.Value.ValueChanged += (s, a) => action();
66          action();
67        }
68      };
69      if (parameter.Value != null) {
70        parameter.Value.ValueChanged += (s, a) => action();
71      }
72    }
73
74    protected void AttachArrayChangeHandler<T, U>(IValueParameter<T> parameter, Action action)
75      where T : ValueTypeArray<U>
76      where U : struct {
77      parameter.ValueChanged += (sender, args) => {
78        if (parameter.Value != null) {
79          parameter.Value.ItemChanged += (s, a) => action();
80          parameter.Value.Reset += (s, a) => action();
81          action();
82        }
83      };
84      if (parameter.Value != null) {
85        parameter.Value.ItemChanged += (s, a) => action();
86        parameter.Value.Reset += (s, a) => action();
87      }
88
89    }
90
91    public abstract int GetNumberOfParameters(int numberOfVariables);
92    public abstract void SetParameter(double[] hyp);
93    public abstract double GetCovariance(double[,] x, int i, int j);
94    public abstract IEnumerable<double> GetGradient(double[,] x, int i, int j);
95    public abstract double GetCrossCovariance(double[,] x, double[,] xt, int i, int j);
96
97  }
98}
Note: See TracBrowser for help on using the repository browser.