Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanConst.cs @ 8331

Last change on this file since 8331 was 8323, checked in by gkronber, 12 years ago

#1902 initial import of Gaussian process regression algorithm

File size: 1.4 KB
Line 
1
2using System;
3using System.Linq;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7
8namespace HeuristicLab.Algorithms.DataAnalysis.GaussianProcess {
9  [StorableClass]
10  [Item(Name = "MeanConst", Description = "Constant mean function for Gaussian processes.")]
11  public class MeanConst : Item, IMeanFunction {
12    [Storable]
13    private double c;
14    [Storable]
15    private int n;
16    public int GetNumberOfParameters(int numberOfVariables) {
17      return 1;
18    }
19    [StorableConstructor]
20    protected MeanConst(bool deserializing) : base(deserializing) { }
21    protected MeanConst(MeanConst original, Cloner cloner)
22      : base(original, cloner) {
23      this.c = original.c;
24      this.n = original.n;
25    }
26    public MeanConst()
27      : base() {
28    }
29
30    public void SetParameter(double[] hyp, double[,] x) {
31      if (hyp.Length != 1) throw new ArgumentException("Only one hyper-parameter allowed for constant mean function.", "hyp");
32      this.c = hyp[0];
33      this.n = x.GetLength(0);
34    }
35
36    public double[] GetMean() {
37      return Enumerable.Repeat(c, n).ToArray();
38    }
39
40    public double[] GetGradients(int k) {
41      if (k > 0) throw new ArgumentException();
42      return Enumerable.Repeat(1.0, n).ToArray();
43    }
44
45    public override IDeepCloneable Clone(Cloner cloner) {
46      return new MeanConst(this, cloner);
47    }
48  }
49}
Note: See TracBrowser for help on using the repository browser.