[3253] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[11646] | 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[3253] | 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 |
|
---|
[4068] | 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[3376] | 24 | using HeuristicLab.Common;
|
---|
[3269] | 25 | using HeuristicLab.Core;
|
---|
[4068] | 26 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[3269] | 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[5532] | 28 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
[3269] | 29 | [StorableClass]
|
---|
| 30 | [Item("Variable", "Represents a variable value.")]
|
---|
[4022] | 31 | public class Variable : Symbol {
|
---|
[3269] | 32 | #region Properties
|
---|
[3485] | 33 | [Storable]
|
---|
[4989] | 34 | private double weightMu;
|
---|
| 35 | public double WeightMu {
|
---|
| 36 | get { return weightMu; }
|
---|
[3824] | 37 | set {
|
---|
[4989] | 38 | if (value != weightMu) {
|
---|
| 39 | weightMu = value;
|
---|
[3824] | 40 | OnChanged(EventArgs.Empty);
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
[3269] | 43 | }
|
---|
[3485] | 44 | [Storable]
|
---|
[3294] | 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.");
|
---|
[3824] | 50 | if (value != weightSigma) {
|
---|
| 51 | weightSigma = value;
|
---|
| 52 | OnChanged(EventArgs.Empty);
|
---|
| 53 | }
|
---|
[3294] | 54 | }
|
---|
[3269] | 55 | }
|
---|
[3485] | 56 | [Storable]
|
---|
[4989] | 57 | private double weightManipulatorMu;
|
---|
| 58 | public double WeightManipulatorMu {
|
---|
| 59 | get { return weightManipulatorMu; }
|
---|
[3824] | 60 | set {
|
---|
[4989] | 61 | if (value != weightManipulatorMu) {
|
---|
| 62 | weightManipulatorMu = value;
|
---|
[3824] | 63 | OnChanged(EventArgs.Empty);
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
[3512] | 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.");
|
---|
[3824] | 73 | if (value != weightManipulatorSigma) {
|
---|
| 74 | weightManipulatorSigma = value;
|
---|
| 75 | OnChanged(EventArgs.Empty);
|
---|
| 76 | }
|
---|
[3512] | 77 | }
|
---|
| 78 | }
|
---|
[5326] | 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 | }
|
---|
[3541] | 91 | private List<string> variableNames;
|
---|
[3512] | 92 | [Storable]
|
---|
[3442] | 93 | public IEnumerable<string> VariableNames {
|
---|
[3294] | 94 | get { return variableNames; }
|
---|
| 95 | set {
|
---|
| 96 | if (value == null) throw new ArgumentNullException();
|
---|
| 97 | variableNames.Clear();
|
---|
| 98 | variableNames.AddRange(value);
|
---|
[3824] | 99 | OnChanged(EventArgs.Empty);
|
---|
[3294] | 100 | }
|
---|
[3269] | 101 | }
|
---|
[6803] | 102 |
|
---|
[8853] | 103 | private List<string> allVariableNames;
|
---|
| 104 | [Storable]
|
---|
| 105 | public IEnumerable<string> AllVariableNames {
|
---|
| 106 | get { return allVariableNames; }
|
---|
| 107 | set {
|
---|
| 108 | if (value == null) throw new ArgumentNullException();
|
---|
| 109 | allVariableNames.Clear();
|
---|
| 110 | allVariableNames.AddRange(value);
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 |
|
---|
[8798] | 114 | public override bool Enabled {
|
---|
| 115 | get {
|
---|
| 116 | if (variableNames.Count == 0) return false;
|
---|
| 117 | return base.Enabled;
|
---|
| 118 | }
|
---|
| 119 | set {
|
---|
| 120 | if (variableNames.Count == 0) base.Enabled = false;
|
---|
| 121 | else base.Enabled = value;
|
---|
| 122 | }
|
---|
| 123 | }
|
---|
| 124 |
|
---|
[6803] | 125 | private const int minimumArity = 0;
|
---|
| 126 | private const int maximumArity = 0;
|
---|
| 127 |
|
---|
| 128 | public override int MinimumArity {
|
---|
| 129 | get { return minimumArity; }
|
---|
| 130 | }
|
---|
| 131 | public override int MaximumArity {
|
---|
| 132 | get { return maximumArity; }
|
---|
| 133 | }
|
---|
[3269] | 134 | #endregion
|
---|
[6803] | 135 |
|
---|
[8853] | 136 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 137 | private void AfterDeserialization() {
|
---|
| 138 | if (allVariableNames == null || (allVariableNames.Count == 0 && variableNames.Count > 0)) {
|
---|
| 139 | allVariableNames = variableNames;
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 |
|
---|
[4722] | 143 | [StorableConstructor]
|
---|
[5326] | 144 | protected Variable(bool deserializing)
|
---|
| 145 | : base(deserializing) {
|
---|
[4722] | 146 | variableNames = new List<string>();
|
---|
[8853] | 147 | allVariableNames = new List<string>();
|
---|
[4722] | 148 | }
|
---|
| 149 | protected Variable(Variable original, Cloner cloner)
|
---|
| 150 | : base(original, cloner) {
|
---|
[4989] | 151 | weightMu = original.weightMu;
|
---|
[4722] | 152 | weightSigma = original.weightSigma;
|
---|
| 153 | variableNames = new List<string>(original.variableNames);
|
---|
[8853] | 154 | allVariableNames = new List<string>(original.allVariableNames);
|
---|
[4989] | 155 | weightManipulatorMu = original.weightManipulatorMu;
|
---|
[4722] | 156 | weightManipulatorSigma = original.weightManipulatorSigma;
|
---|
[5326] | 157 | multiplicativeWeightManipulatorSigma = original.multiplicativeWeightManipulatorSigma;
|
---|
[4722] | 158 | }
|
---|
[4022] | 159 | public Variable() : this("Variable", "Represents a variable value.") { }
|
---|
| 160 | public Variable(string name, string description)
|
---|
| 161 | : base(name, description) {
|
---|
[4989] | 162 | weightMu = 1.0;
|
---|
[3294] | 163 | weightSigma = 1.0;
|
---|
[4989] | 164 | weightManipulatorMu = 0.0;
|
---|
[5334] | 165 | weightManipulatorSigma = 0.05;
|
---|
[5326] | 166 | multiplicativeWeightManipulatorSigma = 0.03;
|
---|
[3294] | 167 | variableNames = new List<string>();
|
---|
[8853] | 168 | allVariableNames = new List<string>();
|
---|
[3269] | 169 | }
|
---|
| 170 |
|
---|
[5532] | 171 | public override ISymbolicExpressionTreeNode CreateTreeNode() {
|
---|
[3253] | 172 | return new VariableTreeNode(this);
|
---|
| 173 | }
|
---|
[3485] | 174 |
|
---|
| 175 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[4722] | 176 | return new Variable(this, cloner);
|
---|
[3485] | 177 | }
|
---|
[3253] | 178 | }
|
---|
| 179 | }
|
---|