- Timestamp:
- 08/05/16 14:25:28 (8 years ago)
- Location:
- branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r14232 r14237 200 200 <Compile Include="Symbols\FactorVariable.cs" /> 201 201 <Compile Include="Symbols\FactorVariableTreeNode.cs" /> 202 <Compile Include="Symbols\VariableBase.cs" /> 203 <Compile Include="Symbols\VariableTreeNodeBase.cs" /> 202 204 <Compile Include="Symbols\Xor.cs" /> 203 205 <Compile Include="Symbols\Erf.cs" /> -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r14232 r14237 639 639 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, varNode.VariableValue); 640 640 il.Emit(System.Reflection.Emit.OpCodes.Call, string_eq); 641 throw new NotSupportedException(); 641 642 // TODO: convert bool to 1 / 0? 642 643 } else { … … 652 653 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, varNode.VariableValue); 653 654 il.Emit(System.Reflection.Emit.OpCodes.Call, string_eq); 655 throw new NotSupportedException(); 654 656 // TODO: convert bool to 1 / 0? 655 657 il.Emit(System.Reflection.Emit.OpCodes.Br, normalResult); -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r14232 r14237 462 462 if (row < 0 || row >= dataset.Rows) return double.NaN; 463 463 var factorVarTreeNode = currentInstr.dynamicNode as FactorVariableTreeNode; 464 return ((IList<string>)currentInstr.data)[row] == factorVarTreeNode.VariableValue ? 1: 0;464 return ((IList<string>)currentInstr.data)[row] == factorVarTreeNode.VariableValue ? factorVarTreeNode.Weight : 0; 465 465 } 466 466 case OpCodes.LagVariable: { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r14232 r14237 152 152 else { 153 153 var factorTreeNode = instr.dynamicNode as FactorVariableTreeNode; 154 instr.value = ((IList<string>)instr.data)[row] == factorTreeNode.VariableValue ? 1: 0;154 instr.value = ((IList<string>)instr.data)[row] == factorTreeNode.VariableValue ? factorTreeNode.Weight : 0; 155 155 } 156 156 } else if (instr.opCode == OpCodes.LagVariable) { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplifier.cs
r14185 r14237 833 833 var subtrees = new List<ISymbolicExpressionTreeNode>(sum.Subtrees); 834 834 while (sum.Subtrees.Any()) sum.RemoveSubtree(0); 835 var groupedVarNodes = from node in subtrees.OfType<VariableTreeNode >()835 var groupedVarNodes = from node in subtrees.OfType<VariableTreeNodeBase>() 836 836 let lag = (node is LaggedVariableTreeNode) ? ((LaggedVariableTreeNode)node).Lag : 0 837 837 group node by node.VariableName + lag into g 838 838 select g; 839 var unchangedSubtrees = subtrees.Where(t => !(t is VariableTreeNode ));839 var unchangedSubtrees = subtrees.Where(t => !(t is VariableTreeNodeBase)); 840 840 841 841 foreach (var variableNodeGroup in groupedVarNodes) { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/FactorVariable.cs
r14233 r14237 41 41 [StorableClass] 42 42 [Item("FactorVariable", "Represents a categorical variable (comparable to factors as in R).")] 43 public class FactorVariable : Symbol { 44 #region Properties 45 private List<string> variableNames; 46 [Storable] 47 public IEnumerable<string> VariableNames { 48 get { return variableNames; } 49 set { 50 if (value == null) throw new ArgumentNullException(); 51 variableNames.Clear(); 52 variableNames.AddRange(value); 53 OnChanged(EventArgs.Empty); 54 } 55 } 56 57 private List<string> allVariableNames; 58 [Storable] 59 public IEnumerable<string> AllVariableNames { 60 get { return allVariableNames; } 61 set { 62 if (value == null) throw new ArgumentNullException(); 63 allVariableNames.Clear(); 64 allVariableNames.AddRange(value); 65 } 66 } 43 public class FactorVariable : VariableBase { 67 44 68 45 private Dictionary<string, List<string>> variableValues; … … 80 57 } 81 58 82 83 public override bool Enabled {84 get {85 if (variableNames.Count == 0) return false;86 return base.Enabled;87 }88 set {89 if (variableNames.Count == 0) base.Enabled = false;90 else base.Enabled = value;91 }92 }93 94 private const int minimumArity = 0;95 private const int maximumArity = 0;96 97 public override int MinimumArity {98 get { return minimumArity; }99 }100 public override int MaximumArity {101 get { return maximumArity; }102 }103 #endregion104 105 59 [StorableConstructor] 106 60 protected FactorVariable(bool deserializing) 107 61 : base(deserializing) { 108 variableNames = new List<string>();109 allVariableNames = new List<string>();110 62 variableValues = new Dictionary<string, List<string>>(); 111 63 } 112 64 protected FactorVariable(FactorVariable original, Cloner cloner) 113 65 : base(original, cloner) { 114 variableNames = new List<string>(original.variableNames);115 allVariableNames = new List<string>(original.allVariableNames);116 66 variableValues = 117 67 original.variableValues.ToDictionary(kvp => kvp.Key, kvp => new List<string>(kvp.Value)); … … 120 70 public FactorVariable(string name, string description) 121 71 : base(name, description) { 122 variableNames = new List<string>();123 allVariableNames = new List<string>();124 72 variableValues = new Dictionary<string, List<string>>(); 125 73 } 126 74 127 [StorableHook(HookType.AfterDeserialization)]128 private void AfterDeserialization() {129 if (allVariableNames == null || (allVariableNames.Count == 0 && variableNames.Count > 0)) {130 allVariableNames = variableNames;131 }132 }133 75 public override ISymbolicExpressionTreeNode CreateTreeNode() { 134 76 return new FactorVariableTreeNode(this); -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/FactorVariableTreeNode.cs
r14233 r14237 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 28 [StorableClass] 29 public class FactorVariableTreeNode : SymbolicExpressionTreeTerminalNode {29 public class FactorVariableTreeNode : VariableTreeNodeBase { 30 30 public new FactorVariable Symbol { 31 31 get { return (FactorVariable)base.Symbol; } 32 }33 [Storable]34 private string variableName;35 public string VariableName {36 get { return variableName; }37 set { variableName = value; }38 32 } 39 33 … … 49 43 protected FactorVariableTreeNode(FactorVariableTreeNode original, Cloner cloner) 50 44 : base(original, cloner) { 51 variableName = original.variableName;52 45 variableValue = original.variableValue; 53 46 } … … 61 54 public override void ResetLocalParameters(IRandom random) { 62 55 base.ResetLocalParameters(random); 63 variableName = Symbol.VariableNames.SampleRandom(random);64 56 variableValue = Symbol.GetVariableValues(VariableName).SampleRandom(random); 65 57 } 66 58 67 59 public override void ShakeLocalParameters(IRandom random, double shakingFactor) { 68 base.ShakeLocalParameters(random, shakingFactor); 60 // 50% additive & 50% multiplicative 61 if (random.NextDouble() < 0.5) { 62 double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorMu, Symbol.WeightManipulatorSigma); 63 Weight = Weight + x * shakingFactor; 64 } else { 65 double x = NormalDistributedRandom.NextDouble(random, 1.0, Symbol.MultiplicativeWeightManipulatorSigma); 66 Weight = Weight * x; 67 } 69 68 if (random.NextDouble() < 0.2) { 70 variableName = Symbol.VariableNames.SampleRandom(random);69 VariableName = Symbol.VariableNames.SampleRandom(random); 71 70 } 72 71 variableValue = Symbol.GetVariableValues(VariableName).SampleRandom(random); … … 78 77 79 78 public override string ToString() { 80 return variableName+ " = " + variableValue;79 return base.ToString() + " = " + variableValue; 81 80 } 82 81 } -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/LaggedVariable.cs
r14185 r14237 27 27 [StorableClass] 28 28 [Item("LaggedVariable", "Represents a variable value with a time offset.")] 29 public class LaggedVariable : Variable {29 public class LaggedVariable : VariableBase { 30 30 [Storable] 31 31 private int minLag; -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/LaggedVariableTreeNode.cs
r14185 r14237 26 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 27 [StorableClass] 28 public sealed class LaggedVariableTreeNode : VariableTreeNode , ILaggedTreeNode {28 public sealed class LaggedVariableTreeNode : VariableTreeNodeBase, ILaggedTreeNode { 29 29 public new LaggedVariable Symbol { 30 30 get { return (LaggedVariable)base.Symbol; } -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/Variable.cs
r14185 r14237 29 29 [StorableClass] 30 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 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 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 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 } 134 #endregion 135 136 [StorableHook(HookType.AfterDeserialization)] 137 private void AfterDeserialization() { 138 if (allVariableNames == null || (allVariableNames.Count == 0 && variableNames.Count > 0)) { 139 allVariableNames = variableNames; 140 } 141 } 31 public class Variable : VariableBase { 142 32 143 33 [StorableConstructor] 144 34 protected Variable(bool deserializing) 145 35 : base(deserializing) { 146 variableNames = new List<string>();147 allVariableNames = new List<string>();148 36 } 149 37 protected Variable(Variable original, Cloner cloner) 150 38 : base(original, cloner) { 151 weightMu = original.weightMu;152 weightSigma = original.weightSigma;153 variableNames = new List<string>(original.variableNames);154 allVariableNames = new List<string>(original.allVariableNames);155 weightManipulatorMu = original.weightManipulatorMu;156 weightManipulatorSigma = original.weightManipulatorSigma;157 multiplicativeWeightManipulatorSigma = original.multiplicativeWeightManipulatorSigma;158 39 } 159 public Variable() : this("Variable", "Represents a variable value.") { } 160 public Variable(string name, string description) 161 : base(name, description) { 162 weightMu = 1.0; 163 weightSigma = 1.0; 164 weightManipulatorMu = 0.0; 165 weightManipulatorSigma = 0.05; 166 multiplicativeWeightManipulatorSigma = 0.03; 167 variableNames = new List<string>(); 168 allVariableNames = new List<string>(); 169 } 40 public Variable() : base("Variable", "Represents a variable value.") { } 170 41 171 42 public override ISymbolicExpressionTreeNode CreateTreeNode() { -
branches/symbreg-factors-2650/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableTreeNode.cs
r14185 r14237 21 21 22 22 using HeuristicLab.Common; 23 using HeuristicLab.Core;24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;25 23 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Random;27 24 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 25 [StorableClass] 29 public class VariableTreeNode : SymbolicExpressionTreeTerminalNode {26 public class VariableTreeNode : VariableTreeNodeBase { 30 27 public new Variable Symbol { 31 28 get { return (Variable)base.Symbol; } 32 29 } 33 [Storable]34 private double weight;35 public double Weight {36 get { return weight; }37 set { weight = value; }38 }39 [Storable]40 private string variableName;41 public string VariableName {42 get { return variableName; }43 set { variableName = value; }44 }45 46 30 [StorableConstructor] 47 31 protected VariableTreeNode(bool deserializing) : base(deserializing) { } 48 32 protected VariableTreeNode(VariableTreeNode original, Cloner cloner) 49 33 : base(original, cloner) { 50 weight = original.weight;51 variableName = original.variableName;52 34 } 53 35 protected VariableTreeNode() { } 54 36 public VariableTreeNode(Variable variableSymbol) : base(variableSymbol) { } 55 37 56 public override bool HasLocalParameters {57 get { return true; }58 }59 60 public override void ResetLocalParameters(IRandom random) {61 base.ResetLocalParameters(random);62 weight = NormalDistributedRandom.NextDouble(random, Symbol.WeightMu, Symbol.WeightSigma);63 64 #pragma warning disable 612, 61865 variableName = Symbol.VariableNames.SelectRandom(random);66 #pragma warning restore 612, 61867 }68 69 public override void ShakeLocalParameters(IRandom random, double shakingFactor) {70 base.ShakeLocalParameters(random, shakingFactor);71 // 50% additive & 50% multiplicative72 if (random.NextDouble() < 0) {73 double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorMu, Symbol.WeightManipulatorSigma);74 weight = weight + x * shakingFactor;75 } else {76 double x = NormalDistributedRandom.NextDouble(random, 1.0, Symbol.MultiplicativeWeightManipulatorSigma);77 weight = weight * x;78 }79 #pragma warning disable 612, 61880 variableName = Symbol.VariableNames.SelectRandom(random);81 #pragma warning restore 612, 61882 }83 84 38 public override IDeepCloneable Clone(Cloner cloner) { 85 39 return new VariableTreeNode(this, cloner); 86 40 } 87 88 public override string ToString() {89 if (weight.IsAlmost(1.0)) return variableName;90 else return weight.ToString("E4") + " " + variableName;91 }92 41 } 93 42 }
Note: See TracChangeset
for help on using the changeset viewer.