Free cookie consent management tool by TermsFeed Policy Generator

source: branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableBase.cs @ 14237

Last change on this file since 14237 was 14237, checked in by gkronber, 8 years ago

#2650: work in progress..

File size: 5.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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.Encodings.SymbolicExpressionTreeEncoding;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
28  [StorableClass]
29  public abstract class VariableBase : Symbol {
30    #region Properties
31    [Storable]
32    private double weightMu;
33    public double WeightMu {
34      get { return weightMu; }
35      set {
36        if (value != weightMu) {
37          weightMu = value;
38          OnChanged(EventArgs.Empty);
39        }
40      }
41    }
42    [Storable]
43    private double weightSigma;
44    public double WeightSigma {
45      get { return weightSigma; }
46      set {
47        if (weightSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
48        if (value != weightSigma) {
49          weightSigma = value;
50          OnChanged(EventArgs.Empty);
51        }
52      }
53    }
54    [Storable]
55    private double weightManipulatorMu;
56    public double WeightManipulatorMu {
57      get { return weightManipulatorMu; }
58      set {
59        if (value != weightManipulatorMu) {
60          weightManipulatorMu = value;
61          OnChanged(EventArgs.Empty);
62        }
63      }
64    }
65    [Storable]
66    private double weightManipulatorSigma;
67    public double WeightManipulatorSigma {
68      get { return weightManipulatorSigma; }
69      set {
70        if (weightManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
71        if (value != weightManipulatorSigma) {
72          weightManipulatorSigma = value;
73          OnChanged(EventArgs.Empty);
74        }
75      }
76    }
77    [Storable(DefaultValue = 0.0)]
78    private double multiplicativeWeightManipulatorSigma;
79    public double MultiplicativeWeightManipulatorSigma {
80      get { return multiplicativeWeightManipulatorSigma; }
81      set {
82        if (multiplicativeWeightManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
83        if (value != multiplicativeWeightManipulatorSigma) {
84          multiplicativeWeightManipulatorSigma = value;
85          OnChanged(EventArgs.Empty);
86        }
87      }
88    }
89    private List<string> variableNames;
90    [Storable]
91    public IEnumerable<string> VariableNames {
92      get { return variableNames; }
93      set {
94        if (value == null) throw new ArgumentNullException();
95        variableNames.Clear();
96        variableNames.AddRange(value);
97        OnChanged(EventArgs.Empty);
98      }
99    }
100
101    private List<string> allVariableNames;
102    [Storable]
103    public IEnumerable<string> AllVariableNames {
104      get { return allVariableNames; }
105      set {
106        if (value == null) throw new ArgumentNullException();
107        allVariableNames.Clear();
108        allVariableNames.AddRange(value);
109      }
110    }
111
112    public override bool Enabled {
113      get {
114        if (variableNames.Count == 0) return false;
115        return base.Enabled;
116      }
117      set {
118        if (variableNames.Count == 0) base.Enabled = false;
119        else base.Enabled = value;
120      }
121    }
122
123    private const int minimumArity = 0;
124    private const int maximumArity = 0;
125
126    public override int MinimumArity {
127      get { return minimumArity; }
128    }
129    public override int MaximumArity {
130      get { return maximumArity; }
131    }
132    #endregion
133
134    [StorableHook(HookType.AfterDeserialization)]
135    private void AfterDeserialization() {
136      if (allVariableNames == null || (allVariableNames.Count == 0 && variableNames.Count > 0)) {
137        allVariableNames = variableNames;
138      }
139    }
140
141    [StorableConstructor]
142    protected VariableBase(bool deserializing)
143      : base(deserializing) {
144      variableNames = new List<string>();
145      allVariableNames = new List<string>();
146    }
147    protected VariableBase(VariableBase original, Cloner cloner)
148      : base(original, cloner) {
149      weightMu = original.weightMu;
150      weightSigma = original.weightSigma;
151      variableNames = new List<string>(original.variableNames);
152      allVariableNames = new List<string>(original.allVariableNames);
153      weightManipulatorMu = original.weightManipulatorMu;
154      weightManipulatorSigma = original.weightManipulatorSigma;
155      multiplicativeWeightManipulatorSigma = original.multiplicativeWeightManipulatorSigma;
156    }
157    protected VariableBase(string name, string description)
158      : base(name, description) {
159      weightMu = 1.0;
160      weightSigma = 1.0;
161      weightManipulatorMu = 0.0;
162      weightManipulatorSigma = 0.05;
163      multiplicativeWeightManipulatorSigma = 0.03;
164      variableNames = new List<string>();
165      allVariableNames = new List<string>();
166    }
167  }
168}
Note: See TracBrowser for help on using the repository browser.