Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/MeanFunctions/MeanConst.cs @ 18079

Last change on this file since 18079 was 17181, checked in by swagner, 5 years ago

#2875: Merged r17180 from trunk to stable

File size: 3.0 KB
RevLine 
[8401]1#region License Information
2/* HeuristicLab
[17181]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[8401]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
[8323]22using System;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
[8612]25using HeuristicLab.Data;
[8982]26using HeuristicLab.Parameters;
[17097]27using HEAL.Attic;
[8323]28
[8371]29namespace HeuristicLab.Algorithms.DataAnalysis {
[17097]30  [StorableType("6E29FC23-D11B-4F32-9101-DB2BF5B2F29E")]
[8323]31  [Item(Name = "MeanConst", Description = "Constant mean function for Gaussian processes.")]
[8612]32  public sealed class MeanConst : ParameterizedNamedItem, IMeanFunction {
[8982]33    public IValueParameter<DoubleValue> ValueParameter {
34      get { return (IValueParameter<DoubleValue>)Parameters["Value"]; }
35    }
[8473]36
[8323]37    [StorableConstructor]
[17097]38    private MeanConst(StorableConstructorFlag _) : base(_) { }
[8612]39    private MeanConst(MeanConst original, Cloner cloner)
[8323]40      : base(original, cloner) {
41    }
42    public MeanConst()
43      : base() {
[8612]44      this.name = ItemName;
45      this.description = ItemDescription;
46
[8982]47      Parameters.Add(new OptionalValueParameter<DoubleValue>("Value", "The constant value for the constant mean function."));
[8323]48    }
49
[8612]50    public override IDeepCloneable Clone(Cloner cloner) {
51      return new MeanConst(this, cloner);
[8323]52    }
[8612]53
54    public int GetNumberOfParameters(int numberOfVariables) {
[8982]55      return ValueParameter.Value != null ? 0 : 1;
[8612]56    }
57
[8982]58    public void SetParameter(double[] p) {
59      double c;
60      GetParameters(p, out c);
61      ValueParameter.Value = new DoubleValue(c);
[8612]62    }
63
[8982]64    private void GetParameters(double[] p, out double c) {
65      if (ValueParameter.Value == null) {
66        c = p[0];
67      } else {
68        if (p.Length > 0)
69          throw new ArgumentException(
70            "The length of the parameter vector does not match the number of free parameters for the constant mean function.",
71            "p");
72        c = ValueParameter.Value.Value;
73      }
[8323]74    }
75
[13981]76    public ParameterizedMeanFunction GetParameterizedMeanFunction(double[] p, int[] columnIndices) {
[8982]77      double c;
78      GetParameters(p, out c);
79      var mf = new ParameterizedMeanFunction();
80      mf.Mean = (x, i) => c;
81      mf.Gradient = (x, i, k) => {
82        if (k > 0) throw new ArgumentException();
83        return 1.0;
84      };
85      return mf;
[8323]86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.