[14237] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17180] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[14237] | 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.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[16565] | 26 | using HEAL.Attic;
|
---|
[14237] | 27 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
[16565] | 28 | [StorableType("F8A6AD96-28D9-4BEC-8392-8B7BA824B085")]
|
---|
[14238] | 29 | public abstract class VariableBase : Symbol, IVariableSymbol {
|
---|
[14237] | 30 | #region Properties
|
---|
| 31 | [Storable]
|
---|
| 32 | private double weightMu;
|
---|
| 33 | public double WeightMu {
|
---|
| 34 | get { return weightMu; }
|
---|
| 35 | set {
|
---|
[14829] | 36 | if (value != weightMu) {
|
---|
[14237] | 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 {
|
---|
[14829] | 47 | if (weightSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
|
---|
| 48 | if (value != weightSigma) {
|
---|
[14237] | 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 {
|
---|
[14829] | 59 | if (value != weightManipulatorMu) {
|
---|
[14237] | 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 {
|
---|
[14829] | 70 | if (weightManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
|
---|
| 71 | if (value != weightManipulatorSigma) {
|
---|
[14237] | 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 {
|
---|
[14829] | 82 | if (multiplicativeWeightManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
|
---|
| 83 | if (value != multiplicativeWeightManipulatorSigma) {
|
---|
[14237] | 84 | multiplicativeWeightManipulatorSigma = value;
|
---|
| 85 | OnChanged(EventArgs.Empty);
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
[14758] | 89 |
|
---|
| 90 | [Storable(DefaultValue = 1.0)]
|
---|
| 91 | private double variableChangeProbability;
|
---|
| 92 |
|
---|
| 93 | public double VariableChangeProbability {
|
---|
[14759] | 94 | get { return variableChangeProbability; }
|
---|
[14758] | 95 | set {
|
---|
[14829] | 96 | if (value < 0 || value > 1.0) throw new ArgumentException("Variable change probability must lie in the interval [0..1]");
|
---|
[14758] | 97 | variableChangeProbability = value;
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[14237] | 101 | private List<string> variableNames;
|
---|
| 102 | [Storable]
|
---|
| 103 | public IEnumerable<string> VariableNames {
|
---|
| 104 | get { return variableNames; }
|
---|
| 105 | set {
|
---|
[14829] | 106 | if (value == null) throw new ArgumentNullException();
|
---|
[14237] | 107 | variableNames.Clear();
|
---|
| 108 | variableNames.AddRange(value);
|
---|
| 109 | OnChanged(EventArgs.Empty);
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | private List<string> allVariableNames;
|
---|
| 114 | [Storable]
|
---|
| 115 | public IEnumerable<string> AllVariableNames {
|
---|
| 116 | get { return allVariableNames; }
|
---|
| 117 | set {
|
---|
[14829] | 118 | if (value == null) throw new ArgumentNullException();
|
---|
[14237] | 119 | allVariableNames.Clear();
|
---|
| 120 | allVariableNames.AddRange(value);
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | public override bool Enabled {
|
---|
| 125 | get {
|
---|
[14829] | 126 | if (variableNames.Count == 0) return false;
|
---|
[14237] | 127 | return base.Enabled;
|
---|
| 128 | }
|
---|
| 129 | set {
|
---|
[14829] | 130 | if (variableNames.Count == 0) base.Enabled = false;
|
---|
[14237] | 131 | else base.Enabled = value;
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 |
|
---|
| 135 | private const int minimumArity = 0;
|
---|
| 136 | private const int maximumArity = 0;
|
---|
| 137 |
|
---|
| 138 | public override int MinimumArity {
|
---|
| 139 | get { return minimumArity; }
|
---|
| 140 | }
|
---|
| 141 | public override int MaximumArity {
|
---|
| 142 | get { return maximumArity; }
|
---|
| 143 | }
|
---|
[17604] | 144 |
|
---|
| 145 | [Storable]
|
---|
| 146 | private Type variableDataType;
|
---|
| 147 | public Type VariableDataType {
|
---|
| 148 | get { return variableDataType; }
|
---|
| 149 | set {
|
---|
| 150 | if (variableDataType == value) return;
|
---|
| 151 | variableDataType = value;
|
---|
| 152 | OnChanged(EventArgs.Empty);
|
---|
| 153 | }
|
---|
| 154 | }
|
---|
[14237] | 155 | #endregion
|
---|
| 156 |
|
---|
| 157 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 158 | private void AfterDeserialization() {
|
---|
[14829] | 159 | if (allVariableNames == null || (allVariableNames.Count == 0 && variableNames.Count > 0)) {
|
---|
[14237] | 160 | allVariableNames = variableNames;
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | [StorableConstructor]
|
---|
[16565] | 165 | protected VariableBase(StorableConstructorFlag _) : base(_) {
|
---|
[14237] | 166 | variableNames = new List<string>();
|
---|
| 167 | allVariableNames = new List<string>();
|
---|
| 168 | }
|
---|
| 169 | protected VariableBase(VariableBase original, Cloner cloner)
|
---|
| 170 | : base(original, cloner) {
|
---|
| 171 | weightMu = original.weightMu;
|
---|
| 172 | weightSigma = original.weightSigma;
|
---|
| 173 | variableNames = new List<string>(original.variableNames);
|
---|
| 174 | allVariableNames = new List<string>(original.allVariableNames);
|
---|
| 175 | weightManipulatorMu = original.weightManipulatorMu;
|
---|
| 176 | weightManipulatorSigma = original.weightManipulatorSigma;
|
---|
| 177 | multiplicativeWeightManipulatorSigma = original.multiplicativeWeightManipulatorSigma;
|
---|
[14758] | 178 | variableChangeProbability = original.variableChangeProbability;
|
---|
[17604] | 179 | variableDataType = original.variableDataType;
|
---|
[14829] | 180 | }
|
---|
[14237] | 181 | protected VariableBase(string name, string description)
|
---|
| 182 | : base(name, description) {
|
---|
| 183 | weightMu = 1.0;
|
---|
| 184 | weightSigma = 1.0;
|
---|
| 185 | weightManipulatorMu = 0.0;
|
---|
| 186 | weightManipulatorSigma = 0.05;
|
---|
| 187 | multiplicativeWeightManipulatorSigma = 0.03;
|
---|
[14758] | 188 | variableChangeProbability = 0.2;
|
---|
[14237] | 189 | variableNames = new List<string>();
|
---|
| 190 | allVariableNames = new List<string>();
|
---|
| 191 | }
|
---|
| 192 | }
|
---|
| 193 | }
|
---|