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