Changeset 18112
- Timestamp:
- 12/09/21 14:28:17 (3 years ago)
- Location:
- branches/3140_NumberSymbol
- Files:
-
- 23 edited
- 4 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/SymbolicExpressionImporter.cs
r18093 r18112 85 85 }; 86 86 87 Num num = new Num(); 87 Number number = new Number(); 88 Constant constant = new Constant(); 88 89 Variable variable = new Variable(); 89 90 LaggedVariable laggedVariable = new LaggedVariable(); … … 161 162 return tree; 162 163 } else if (tokens.Peek().Symbol == TokenSymbol.NUMBER) { 163 NumTreeNode t = (NumTreeNode)num.CreateTreeNode();164 var t = (INumericTreeNode)number.CreateTreeNode(); 164 165 t.Value = tokens.Dequeue().DoubleValue; 165 166 return t; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalArithBoundsEstimator.cs
r18093 r18112 127 127 } 128 128 case OpCodes.Constant: { 129 var constTreeNode = ( NumTreeNode)currentInstr.dynamicNode;129 var constTreeNode = (ConstantTreeNode)currentInstr.dynamicNode; 130 130 result = new Interval(constTreeNode.Value, constTreeNode.Value); 131 break; 132 } 133 case OpCodes.Number: { 134 var numberTreeNode = (NumberTreeNode)currentInstr.dynamicNode; 135 result = new Interval(numberTreeNode.Value, numberTreeNode.Value); 131 136 break; 132 137 } … … 324 329 where 325 330 !(n.Symbol is Variable) && 326 !(n.Symbol is Num ) &&327 !(n.Symbol is RealConstant) &&331 !(n.Symbol is Number) && 332 !(n.Symbol is Constant) && 328 333 !(n.Symbol is StartSymbol) && 329 334 !(n.Symbol is Addition) && -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalArithCompiledExpressionBoundsEstimator.cs
r18093 r18112 116 116 where 117 117 !(n.Symbol is Variable) && 118 !(n.Symbol is Num ) &&119 !(n.Symbol is RealConstant) &&118 !(n.Symbol is Number) && 119 !(n.Symbol is Constant) && 120 120 !(n.Symbol is StartSymbol) && 121 121 !(n.Symbol is Addition) && … … 155 155 } 156 156 case OpCodes.Constant: { 157 var v = (node as NumTreeNode).Value; 157 var v = (node as NumberTreeNode).Value; 158 // we have to make an interval out of the constant because this may be the root of the tree (and we are expected to return an Interval) 159 return Expression.Constant(new Interval(v, v), typeof(Interval)); 160 } 161 case OpCodes.Number: { 162 var v = (node as NumberTreeNode).Value; 158 163 // we have to make an interval out of the constant because this may be the root of the tree (and we are expected to return an Interval) 159 164 return Expression.Constant(new Interval(v, v), typeof(Interval)); -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
r18093 r18112 187 187 } 188 188 case OpCodes.Number: { 189 var constTreeNode = (NumTreeNode)currentInstr.dynamicNode;190 result = new Interval( constTreeNode.Value, constTreeNode.Value);189 var numberTreeNode = (NumberTreeNode)currentInstr.dynamicNode; 190 result = new Interval(numberTreeNode.Value, numberTreeNode.Value); 191 191 break; 192 192 } 193 193 case OpCodes.Constant: { 194 var constTreeNode = ( RealConstantTreeNode)currentInstr.dynamicNode;194 var constTreeNode = (ConstantTreeNode)currentInstr.dynamicNode; 195 195 result = new Interval(constTreeNode.Value, constTreeNode.Value); 196 196 break; … … 329 329 if ( 330 330 !(n.Symbol is Variable) && 331 !(n.Symbol is Num ) &&331 !(n.Symbol is Number) && 332 332 !(n.Symbol is StartSymbol) && 333 333 !(n.Symbol is Addition) && … … 351 351 else if (n.Symbol is Power) { 352 352 // only integer exponents are supported 353 var exp = n.GetSubtree(1) as Num TreeNode;353 var exp = n.GetSubtree(1) as NumberTreeNode; 354 354 if (exp == null || exp.Value != Math.Truncate(exp.Value)) return false; 355 355 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r18093 r18112 46 46 Variable = 18, 47 47 LagVariable = 19, 48 Num = 20,48 Number = 20, 49 49 Arg = 21, 50 50 Power = 22, … … 102 102 public const byte Variable = (byte)OpCode.Variable; 103 103 public const byte LagVariable = (byte)OpCode.LagVariable; 104 public const byte Number = (byte)OpCode.Num ;104 public const byte Number = (byte)OpCode.Number; 105 105 public const byte Constant = (byte) OpCode.Constant; 106 106 public const byte Arg = (byte)OpCode.Arg; … … 161 161 { typeof(LaggedVariable), OpCodes.LagVariable }, 162 162 { typeof(AutoregressiveTargetVariable),OpCodes.LagVariable}, 163 { typeof(Num ), OpCodes.Number },164 { typeof( RealConstant), OpCodes.Constant },163 { typeof(Number), OpCodes.Number }, 164 { typeof(Constant), OpCodes.Constant }, 165 165 { typeof(Argument), OpCodes.Arg }, 166 166 { typeof(Power),OpCodes.Power}, -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs
r18093 r18112 158 158 switch (opcode) { 159 159 case OpCodes.Constant: { 160 var constantTreeNode = ( NumTreeNode)node;160 var constantTreeNode = (ConstantTreeNode)node; 161 161 return Expression.Constant(constantTreeNode.Value); 162 } 163 case OpCodes.Number: { 164 var numberTreeNode = (NumberTreeNode)node; 165 return Expression.Constant(numberTreeNode.Value); 162 166 } 163 167 case OpCodes.Variable: { -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeBatchInterpreter.cs
r18093 r18112 279 279 cachedData[variable.VariableName] = code[i].data; 280 280 } 281 } else if (node is NumTreeNode constant) {282 code[i].value = constant.Value;281 } else if (node is INumericTreeNode numeric) { 282 code[i].value = numeric.Value; 283 283 for (int j = 0; j < BATCHSIZE; ++j) 284 284 code[i].buf[j] = code[i].value; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r18093 r18112 712 712 } 713 713 case OpCodes.Number: { 714 Num TreeNode constNode = (NumTreeNode)currentInstr.dynamicNode;715 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, constNode.Value);714 NumberTreeNode numberNode = (NumberTreeNode)currentInstr.dynamicNode; 715 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, numberNode.Value); 716 716 return; 717 717 } 718 718 case OpCodes.Constant: { 719 RealConstantTreeNode constNode = (RealConstantTreeNode) currentInstr.dynamicNode;719 ConstantTreeNode constNode = (ConstantTreeNode) currentInstr.dynamicNode; 720 720 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, constNode.Value); 721 721 return; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r18093 r18112 497 497 } 498 498 case OpCodes.Constant: { 499 var constTreeNode = ( NumTreeNode)currentInstr.dynamicNode;499 var constTreeNode = (ConstantTreeNode)currentInstr.dynamicNode; 500 500 return constTreeNode.Value; 501 501 } 502 502 case OpCodes.Number: { 503 var numberTreeNode = ( RealConstantTreeNode) currentInstr.dynamicNode;503 var numberTreeNode = (NumberTreeNode) currentInstr.dynamicNode; 504 504 return numberTreeNode.Value; 505 505 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r18093 r18112 417 417 switch (instr.opCode) { 418 418 case OpCodes.Number: { 419 var constTreeNode = (NumTreeNode)instr.dynamicNode;420 instr.value = constTreeNode.Value;419 var numberTreeNode = (NumberTreeNode)instr.dynamicNode; 420 instr.value = numberTreeNode.Value; 421 421 instr.skip = true; // the value is already set so this instruction should be skipped in the evaluation phase 422 422 } 423 423 break; 424 424 case OpCodes.Constant: { 425 var constTreeNode = ( RealConstantTreeNode)instr.dynamicNode;425 var constTreeNode = (ConstantTreeNode)instr.dynamicNode; 426 426 instr.value = constTreeNode.Value; 427 427 instr.skip = true; // the value is already set so this instruction should be skipped in the evaluation phase -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs
r18093 r18112 82 82 code[i].weight = variable.Weight; 83 83 code[i].data = cachedData[variable.VariableName].AddrOfPinnedObject(); 84 } else if (node is NumTreeNode constant) {85 code[i].value = constant.Value;84 } else if (node is INumericTreeNode numeric) { 85 code[i].value = numeric.Value; 86 86 } 87 87 -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionPruningOperator.cs
r18093 r18112 172 172 for (int i = 0; i < nodes.Count; ++i) { 173 173 var node = nodes[i]; 174 if (node is NumTreeNode) continue;174 if (node is INumericTreeNode) continue; 175 175 176 176 double impactValue, replacementValue; … … 181 181 if (!PruneOnlyZeroImpactNodes && impactValue > NodeImpactThreshold) continue; 182 182 183 var constantNode = (NumTreeNode)node.Grammar.GetSymbol("Num").CreateTreeNode();184 constantNode.Value = replacementValue;183 var numberNode = (NumberTreeNode)node.Grammar.GetSymbol("Number").CreateTreeNode(); 184 numberNode.Value = replacementValue; 185 185 186 186 var length = node.GetLength(); 187 ReplaceWithConstant(node, constantNode);187 ReplaceWithConstant(node, numberNode); 188 188 i += length - 1; // skip subtrees under the node that was folded 189 189 -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModelComplexityCalculator.cs
r18093 r18112 80 80 case OpCodes.Root: { 81 81 double complexity = CalculateComplexity(node.GetSubtree(0)); 82 var exponent = node.GetSubtree(1) as NumTreeNode;82 var exponent = node.GetSubtree(1) as INumericTreeNode; 83 83 if (exponent != null) { 84 84 double expVal = exponent.Value; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs
r18093 r18112 59 59 tempModelParentNode.RemoveSubtree(i); 60 60 61 var constantNode = new NumTreeNode(new Num()) { Value = repValue };62 tempModelParentNode.InsertSubtree(i, constantNode);61 var numberNode = new NumberTreeNode(new Number()) { Value = repValue }; 62 tempModelParentNode.InsertSubtree(i, numberNode); 63 63 64 64 newQualityForImpactsCalculation = CalculateQualityForImpacts(tempModel, problemData, rows); … … 80 80 IDataset dataset, IEnumerable<int> rows) { 81 81 //optimization: constant nodes return always the same value 82 Num TreeNode numNode = node as NumTreeNode;82 NumberTreeNode numberNode = node as NumberTreeNode; 83 83 BinaryFactorVariableTreeNode binaryFactorNode = node as BinaryFactorVariableTreeNode; 84 84 FactorVariableTreeNode factorNode = node as FactorVariableTreeNode; 85 if (num Node != null) {86 yield return num Node.Value;85 if (numberNode != null) { 86 yield return numberNode.Value; 87 87 } else if (binaryFactorNode != null) { 88 88 // valid replacements are either all off or all on -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/Constant.cs
r18111 r18112 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 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 6 22 using HEAL.Attic; 7 23 using HeuristicLab.Common; … … 11 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 12 28 [StorableType("44E03792-5E65-4C70-99B2-7849B8927E28")] 13 [Item("RealConstant", "Represents a number.")] 14 public sealed class RealConstant : Symbol{ 15 [Storable] 16 private double minValue; 17 public double MinValue { 18 get { return minValue; } 19 set { 20 if (value != minValue) { 21 minValue = value; 22 OnChanged(EventArgs.Empty); 23 } 24 } 25 } 26 [Storable] 27 private double maxValue; 28 public double MaxValue { 29 get { return maxValue; } 30 set { 31 if (value != maxValue) { 32 maxValue = value; 33 OnChanged(EventArgs.Empty); 34 } 35 } 36 } 37 29 [Item("Constant", "Represents a constant number.")] 30 public sealed class Constant : Symbol, INumericSymbol{ 38 31 private const int minimumArity = 0; 39 32 private const int maximumArity = 0; 40 33 41 public override int MinimumArity { 42 get { return minimumArity; } 43 } 44 public override int MaximumArity { 45 get { return maximumArity; } 34 public override int MinimumArity => minimumArity; 35 public override int MaximumArity => maximumArity; 36 37 [StorableConstructor] 38 private Constant(StorableConstructorFlag _) : base(_) { } 39 40 private Constant(Constant original, Cloner cloner) : base(original, cloner) {} 41 public override IDeepCloneable Clone(Cloner cloner) { 42 return new Constant(this, cloner); 46 43 } 47 44 48 [StorableConstructor] 49 private RealConstant(StorableConstructorFlag _) : base(_) { } 50 51 private RealConstant(RealConstant original, Cloner cloner) : base(original, cloner) { 52 minValue = original.minValue; 53 maxValue = original.maxValue; 54 } 55 public override IDeepCloneable Clone(Cloner cloner) { 56 return new RealConstant(this, cloner); 57 } 58 59 public RealConstant() : base("RealConstant", "Represents a number.") { 60 minValue = -20.0; 61 maxValue = 20.0; 62 } 45 public Constant() : base("Constant", "Represents a constant number.") {} 63 46 64 47 public override ISymbolicExpressionTreeNode CreateTreeNode() { 65 return new RealConstantTreeNode(this);48 return new ConstantTreeNode(this); 66 49 } 67 50 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/ConstantTreeNode.cs
r18111 r18112 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 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 6 22 using HEAL.Attic; 7 23 using HeuristicLab.Common; … … 10 26 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 11 27 [StorableType("F91000E6-B041-4648-A9E8-595228F957FA")] 12 public sealed class RealConstantTreeNode : SymbolicExpressionTreeTerminalNode{28 public sealed class ConstantTreeNode : SymbolicExpressionTreeTerminalNode, INumericTreeNode{ 13 29 14 public new RealConstant Symbol { 15 get { return (RealConstant) base.Symbol; } 16 } 30 public new Constant Symbol => (Constant) base.Symbol; 17 31 18 32 public double Value { get; set; } 19 33 20 34 [StorableConstructor] 21 private RealConstantTreeNode(StorableConstructorFlag _) : base(_) { }35 private ConstantTreeNode(StorableConstructorFlag _) : base(_) { } 22 36 23 private RealConstantTreeNode(RealConstantTreeNode original, Cloner cloner)37 private ConstantTreeNode(ConstantTreeNode original, Cloner cloner) 24 38 : base(original, cloner) { 25 39 Value = original.Value; 26 40 } 27 41 28 private RealConstantTreeNode() : base() { }29 public RealConstantTreeNode(RealConstant realConstantSymbol) : base(realConstantSymbol) { }42 private ConstantTreeNode() : base() { } 43 public ConstantTreeNode(Constant constantSymbol) : base(constantSymbol) { } 30 44 31 45 public override IDeepCloneable Clone(Cloner cloner) { 32 return new RealConstantTreeNode(this, cloner);46 return new ConstantTreeNode(this, cloner); 33 47 } 34 48 -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/Number.cs
r18111 r18112 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 28 [StorableType("5CD355EA-36E4-4E43-B8C4-9E9CF4CBC860")] 29 [Item("Num ", "Represents a constant value.")]30 public sealed class Num :Symbol {29 [Item("Number", "Represents a number.")] 30 public sealed class Number : Symbol, INumericSymbol { 31 31 #region Properties 32 32 [Storable] … … 100 100 101 101 [StorableConstructor] 102 private Num (StorableConstructorFlag _) : base(_) { }103 private Num (Numoriginal, Cloner cloner)102 private Number(StorableConstructorFlag _) : base(_) { } 103 private Number(Number original, Cloner cloner) 104 104 : base(original, cloner) { 105 105 minValue = original.minValue; … … 109 109 multiplicativeManipulatorSigma = original.multiplicativeManipulatorSigma; 110 110 } 111 public Num ()112 : base("Num ", "Represents a constantvalue.") {111 public Number() 112 : base("Number", "Represents a numerical value.") { 113 113 manipulatorMu = 0.0; 114 114 manipulatorSigma = 1.0; … … 119 119 120 120 public override ISymbolicExpressionTreeNode CreateTreeNode() { 121 return new Num TreeNode(this);121 return new NumberTreeNode(this); 122 122 } 123 123 124 124 public override IDeepCloneable Clone(Cloner cloner) { 125 return new Num (this, cloner);125 return new Number(this, cloner); 126 126 } 127 127 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/NumberTreeNode.cs
r18111 r18112 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 28 [StorableType("247DBD04-18F2-4184-B6F5-6E283BF06FD0")] 29 public sealed class NumTreeNode : SymbolicExpressionTreeTerminalNode { 30 public new Num Symbol { 31 get { return (Num)base.Symbol; } 29 public sealed class NumberTreeNode : SymbolicExpressionTreeTerminalNode, INumericTreeNode { 30 public new Number Symbol => (Number)base.Symbol; 31 32 [Storable] 33 public double Value { get; set; } 34 35 [StorableConstructor] 36 private NumberTreeNode(StorableConstructorFlag _) : base(_) { } 37 38 private NumberTreeNode(NumberTreeNode original, Cloner cloner) 39 : base(original, cloner) { 40 Value = original.Value; 32 41 } 33 42 34 private double constantValue; 35 [Storable] 36 public double Value { 37 get { return constantValue; } 38 set { constantValue = value; } 39 } 43 private NumberTreeNode() : base() { } 44 public NumberTreeNode(Number numberSymbol) : base(numberSymbol) { } 40 45 41 [StorableConstructor] 42 private NumTreeNode(StorableConstructorFlag _) : base(_) { } 46 public override bool HasLocalParameters => true; 43 47 44 private NumTreeNode(NumTreeNode original, Cloner cloner)45 : base(original, cloner) {46 constantValue = original.constantValue;47 }48 49 private NumTreeNode() : base() { }50 public NumTreeNode(Num numSymbol) : base(numSymbol) { }51 52 public override bool HasLocalParameters {53 get {54 return true;55 }56 }57 48 public override void ResetLocalParameters(IRandom random) { 58 49 base.ResetLocalParameters(random); … … 65 56 // 50% additive & 50% multiplicative 66 57 if (random.NextDouble() < 0.5) { 67 doublex = NormalDistributedRandom.NextDouble(random, Symbol.ManipulatorMu, Symbol.ManipulatorSigma);58 var x = NormalDistributedRandom.NextDouble(random, Symbol.ManipulatorMu, Symbol.ManipulatorSigma); 68 59 Value = Value + x * shakingFactor; 69 60 } else { 70 doublex = NormalDistributedRandom.NextDouble(random, 1.0, Symbol.MultiplicativeManipulatorSigma);61 var x = NormalDistributedRandom.NextDouble(random, 1.0, Symbol.MultiplicativeManipulatorSigma); 71 62 Value = Value * x; 72 63 } … … 74 65 75 66 public override IDeepCloneable Clone(Cloner cloner) { 76 return new Num TreeNode(this, cloner);67 return new NumberTreeNode(this, cloner); 77 68 } 78 69 79 70 public override string ToString() { 80 return $"<{constantValue:E4}>"; 81 // return constantValue.ToString("E4"); 71 return $"{Value:E4}"; 82 72 } 83 73 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Transformations/SymbolicExpressionTreeBacktransformator.cs
r18093 r18112 90 90 private ISymbolicExpressionTreeNode CreateNodeFromWeight(ISymbolicExpressionTreeNode transformationTree, VariableTreeNode variableNode) { 91 91 var multiplicationNode = new SymbolicExpressionTreeNode(new Multiplication()); 92 multiplicationNode.AddSubtree(new Num TreeNode(new Num()) { Value = variableNode.Weight });92 multiplicationNode.AddSubtree(new NumberTreeNode(new Number()) { Value = variableNode.Weight }); 93 93 multiplicationNode.AddSubtree(transformationTree); 94 94 return multiplicationNode; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Transformations/TransformationToSymbolicTreeMapper.cs
r18093 r18112 279 279 } 280 280 281 private Num TreeNode CreateConstantTreeNode(string description, double value) {282 return new Num TreeNode(new Num()) { Value = value };281 private NumberTreeNode CreateConstantTreeNode(string description, double value) { 282 return new NumberTreeNode(new Number()) { Value = value }; 283 283 } 284 284 -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeBottomUpSimilarityCalculator.cs
r17180 r18112 211 211 return node.Symbol.Name; 212 212 213 if (node is ConstantTreeNode constant)213 if (node is INumericTreeNode constant) 214 214 return MatchConstantValues ? constant.Value.ToString(CultureInfo.InvariantCulture) : constant.Symbol.Name; 215 215 -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeNodeComparer.cs
r17180 r18112 52 52 53 53 // at this point we know a and b are not variables 54 var ca = a as ConstantTreeNode;55 var cb = b as ConstantTreeNode;54 var ca = a as INumericTreeNode; 55 var cb = b as INumericTreeNode; 56 56 57 57 if (ca != null && cb != null) -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeNodeEqualityComparer.cs
r17180 r18112 86 86 return (!MatchVariableNames || va.VariableName.Equals(vb.VariableName)) && (!MatchVariableWeights || va.Weight.Equals(vb.Weight)); 87 87 } 88 var ca = a as ConstantTreeNode; 89 if ( ca != null) {90 var cb = b as ConstantTreeNode;88 89 if (a is INumericTreeNode ca) { 90 var cb = b as INumericTreeNode; 91 91 if (cb == null) return false; 92 92 return (!MatchConstantValues || ca.Value.Equals(cb.Value)); -
branches/3140_NumberSymbol/HeuristicLab.Problems.ExternalEvaluation.GP/3.5/ExternalEvaluationExpressionGrammar.cs
r18093 r18112 62 62 var or = new Or(); 63 63 var not = new Not(); 64 var constant = new Num(); 65 constant.MinValue = -20; 66 constant.MaxValue = 20; 64 var number = new Number(); 65 number.MinValue = -20; 66 number.MaxValue = 20; 67 var constant = new Constant(); 67 68 variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 68 69 69 var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, exp, @if, gt, lt, and, or, not, constant, variableSymbol };70 var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, exp, @if, gt, lt, and, or, not, number, constant, variableSymbol }; 70 71 var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, not }; 71 72 var binaryFunctionSymbols = new List<Symbol>() { gt, lt }; … … 86 87 87 88 SetSubtreeCount(@if, 3, 3); 88 SetSubtreeCount(constant, 0, 0); 89 SetSubtreeCount(number, 0, 0); 90 SetSubtreeCount(constant,0, 0); 89 91 SetSubtreeCount(variableSymbol, 0, 0); 90 92 -
branches/3140_NumberSymbol/HeuristicLab.Problems.ExternalEvaluation.GP/3.5/ExternalEvaluationSymbolicExpressionTreeStringFormatter.cs
r18093 r18112 106 106 var varNode = node as VariableTreeNode; 107 107 strBuilder.AppendFormat("(* {0} {1})", varNode.VariableName, varNode.Weight.ToString("g17", CultureInfo.InvariantCulture)); 108 } else if (node.Symbol is Num) {109 var constNode = node as NumTreeNode;110 strBuilder.Append( constNode.Value.ToString("g17", CultureInfo.InvariantCulture));108 } else if (node.Symbol is INumericSymbol) { 109 var numericNode = node as INumericTreeNode; 110 strBuilder.Append(numericNode.Value.ToString("g17", CultureInfo.InvariantCulture)); 111 111 } else { 112 112 throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for external evaluation."); -
branches/3140_NumberSymbol/HeuristicLab.Problems.GrammaticalEvolution/3.4/Mappers/PIGEMapper.cs
r17180 r18112 42 42 /// integer vector and rule may be one value from a "content" integer vector. 43 43 /// 44 /// Order: NT = nont % Num . NT ... determines, which non-terminal to expand next45 /// Content: Rule = rule % Num . Rules ... rule determination as with standard GE mappers44 /// Order: NT = nont % Number. NT ... determines, which non-terminal to expand next 45 /// Content: Rule = rule % Number. Rules ... rule determination as with standard GE mappers 46 46 /// 47 47 /// Four mutation and crossover strategies possible: … … 155 155 current.AddSubtree(GetRandomTerminalNode(current, grammar, random)); 156 156 } else { 157 // Order: NT = nont % Num . NT157 // Order: NT = nont % Number. NT 158 158 int nt = NontVector[genotypeIndex] % nonTerminals.Count; 159 159 ISymbolicExpressionTreeNode current = nonTerminals[nt]; 160 160 nonTerminals.RemoveAt(nt); 161 161 162 // Content: Rule = rule % Num . Rules162 // Content: Rule = rule % Number. Rules 163 163 ISymbolicExpressionTreeNode newNode = GetNewChildNode(current, genotype, grammar, genotypeIndex, random); 164 164 int arity = SampleArity(random, newNode, grammar); -
branches/3140_NumberSymbol/HeuristicLab.Problems.GrammaticalEvolution/3.4/SymbolicRegression/GESymbolicExpressionGrammar.cs
r17413 r18112 81 81 var constVal = rand.NextDouble() * 20.0 - 10.0; 82 82 constant.Name = string.Format("{0:0.000}", constVal); 83 constant.MinValue = constVal;84 constant.MaxValue = constVal;85 constant.ManipulatorSigma = 0.0;86 constant.ManipulatorMu = 0.0;87 constant.MultiplicativeManipulatorSigma = 0.0;88 83 } while (constants.Any(c => c.Name == constant.Name)); // unlikely, but it could happen that the same constant value is sampled twice. so we resample if necessary. 89 84 constants.Add(constant);
Note: See TracChangeset
for help on using the changeset viewer.