Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GP-MoveOperators/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/HyperParameter.cs @ 9579

Last change on this file since 9579 was 8612, checked in by gkronber, 12 years ago

#1902 implemented all mean and covariance functions with parameters as ParameterizedNamedItems

File size: 2.5 KB
Line 
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 HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Parameters;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Algorithms.DataAnalysis {
29  [StorableClass]
30  [Item(Name = "HyperParameter", Description = "Represents a hyperparameter for Gaussian processes.")]
31  internal class HyperParameter<T> : OptionalValueParameter<T>, IValueParameter<T> where T : class, IItem {
32
33    [Storable]
34    private bool @fixed = false;
35
36    public bool Fixed {
37      get { return @fixed; }
38    }
39
40    [StorableConstructor]
41    protected HyperParameter(bool deserializing)
42      : base(deserializing) {
43    }
44
45    protected HyperParameter(HyperParameter<T> original, Cloner cloner)
46      : base(original, cloner) {
47      this.@fixed = original.@fixed;
48    }
49
50    public HyperParameter() : base("HyperParameter", "Represents a hyperparameter for Gaussian processes.") { }
51
52    public HyperParameter(string name, string description)
53      : base(name, description) {
54    }
55
56    public override IDeepCloneable Clone(Cloner cloner) {
57      return new HyperParameter<T>(this, cloner);
58    }
59
60    // if a value is set through this property then we fix the value of the hyperparameter
61    public override T Value {
62      get {
63        return base.Value;
64      }
65      set {
66        base.Value = value;
67        @fixed = value != null;
68      }
69    }
70
71    // in the optimization we are allowed to set the value of non-fixed parameters
72    public void SetValue(T value) {
73      if (@fixed) throw new InvalidOperationException("Can't set the value of a fixed hyperparameter");
74      base.Value = value;
75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.