- Timestamp:
- 11/24/21 13:40:39 (3 years ago)
- Location:
- branches/3140_NumberSymbol
- Files:
-
- 2 added
- 31 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/SymbolicRegressionSolutionResponseFunctionView.cs
r17180 r18093 120 120 121 121 private void ChangeVariableValue(string variableName, double value) { 122 foreach (var constNode in variableNodes[variableName].Cast< ConstantTreeNode>())122 foreach (var constNode in variableNodes[variableName].Cast<NumTreeNode>()) 123 123 constNode.Value = value; 124 124 … … 223 223 } 224 224 225 private ISymbolicExpressionTreeNode MakeProduct( ConstantTreeNode c, double weight) {225 private ISymbolicExpressionTreeNode MakeProduct(NumTreeNode c, double weight) { 226 226 var mul = new Multiplication(); 227 227 var prod = mul.CreateTreeNode(); … … 231 231 } 232 232 233 private ConstantTreeNode MakeConstantTreeNode(double value) {234 Constant constant = new Constant();235 constant.MinValue = value - 1;236 constant.MaxValue = value + 1;237 ConstantTreeNode constantTreeNode = (ConstantTreeNode)constant.CreateTreeNode();238 constantTreeNode.Value = value;239 return constantTreeNode;233 private NumTreeNode MakeConstantTreeNode(double value) { 234 Num num = new Num(); 235 num.MinValue = value - 1; 236 num.MaxValue = value + 1; 237 NumTreeNode numTreeNode = (NumTreeNode)num.CreateTreeNode(); 238 numTreeNode.Value = value; 239 return numTreeNode; 240 240 } 241 241 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/NMSESingleObjectiveConstraintsEvaluator.cs
r17958 r18093 155 155 if (errorState == OnlineCalculatorError.None) { 156 156 //Set alpha and beta to the scaling nodes from ia grammar 157 var offsetParameter = offset.GetSubtree(1) as ConstantTreeNode;157 var offsetParameter = offset.GetSubtree(1) as NumTreeNode; 158 158 offsetParameter.Value = alpha; 159 var scalingParameter = scaling.GetSubtree(1) as ConstantTreeNode;159 var scalingParameter = scaling.GetSubtree(1) as NumTreeNode; 160 160 scalingParameter.Value = beta; 161 161 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs
r17944 r18093 32 32 33 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 34 [Item(" ConstantOptimization Evaluator", "Calculates Pearson R² of a symbolic regression solution and optimizes the constant used.")]34 [Item("Num Optimization Evaluator", "Calculates Pearson R² of a symbolic regression solution and optimizes the constant used.")] 35 35 [StorableType("24B68851-036D-4446-BD6F-3823E9028FF4")] 36 36 public class SymbolicRegressionConstantOptimizationEvaluator : SymbolicRegressionSingleObjectiveEvaluator { … … 307 307 int i = 0; 308 308 foreach (var node in tree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTerminalNode>()) { 309 ConstantTreeNode constantTreeNode = node as ConstantTreeNode;309 NumTreeNode numTreeNode = node as NumTreeNode; 310 310 VariableTreeNodeBase variableTreeNodeBase = node as VariableTreeNodeBase; 311 311 FactorVariableTreeNode factorVarTreeNode = node as FactorVariableTreeNode; 312 if ( constantTreeNode != null) {313 if ( constantTreeNode.Parent.Symbol is Power314 && constantTreeNode.Parent.GetSubtree(1) == constantTreeNode) continue; // exponents in powers are not optimizated (see TreeToAutoDiffTermConverter)315 constantTreeNode.Value = constants[i++];312 if (numTreeNode != null) { 313 if (numTreeNode.Parent.Symbol is Power 314 && numTreeNode.Parent.GetSubtree(1) == numTreeNode) continue; // exponents in powers are not optimizated (see TreeToAutoDiffTermConverter) 315 numTreeNode.Value = constants[i++]; 316 316 } else if (updateVariableWeights && variableTreeNodeBase != null) 317 317 variableTreeNodeBase.Weight = constants[i++]; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/LinearModelToTreeConverter.cs
r17180 r18093 58 58 59 59 if (@const!=0.0) { 60 ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode();60 NumTreeNode cNode = (NumTreeNode)new Num().CreateTreeNode(); 61 61 cNode.Value = @const; 62 62 add.AddSubtree(cNode); … … 99 99 100 100 if (!@const.IsAlmost(0.0)) { 101 ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode();101 NumTreeNode cNode = (NumTreeNode)new Num().CreateTreeNode(); 102 102 cNode.Value = @const; 103 103 addition.AddSubtree(cNode); … … 130 130 131 131 if (!@const.IsAlmost(0.0)) { 132 ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode();132 NumTreeNode cNode = (NumTreeNode)new Num().CreateTreeNode(); 133 133 cNode.Value = @const; 134 134 addition.AddSubtree(cNode); -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs
r17817 r18093 145 145 146 146 private AutoDiff.Term ConvertToAutoDiff(ISymbolicExpressionTreeNode node) { 147 if (node.Symbol is Constant) { 148 initialConstants.Add(((ConstantTreeNode)node).Value); 147 if (node.Symbol is Num) { 148 initialConstants.Add(((NumTreeNode)node).Value); 149 var var = new AutoDiff.Variable(); 150 variables.Add(var); 151 return var; 152 } 153 154 if (node.Symbol is RealConstant) { 155 initialConstants.Add(((RealConstantTreeNode)node).Value); 149 156 var var = new AutoDiff.Variable(); 150 157 variables.Add(var); … … 260 267 } 261 268 if (node.Symbol is Power) { 262 var powerNode = node.GetSubtree(1) as ConstantTreeNode;269 var powerNode = node.GetSubtree(1) as NumTreeNode; 263 270 if (powerNode == null) 264 271 throw new NotSupportedException("Only integer powers are allowed in parameter optimization. Try to use exp() and log() instead of the power symbol."); … … 330 337 !(n.Symbol is FactorVariable) && 331 338 !(n.Symbol is LaggedVariable) && 332 !(n.Symbol is Constant) && 339 !(n.Symbol is Num) && 340 !(n.Symbol is RealConstant) && 333 341 !(n.Symbol is Addition) && 334 342 !(n.Symbol is Subtraction) && -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/ArithmeticExpressionGrammar.cs
r17413 r18093 49 49 var mul = new Multiplication(); 50 50 var div = new Division(); 51 var constant = new Constant();51 var constant = new Num(); 52 52 constant.MinValue = -20; 53 53 constant.MaxValue = 20; 54 var number = new RealConstant(); 55 number.MinValue = -20; 56 number.MaxValue = 20; 54 57 var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 55 58 var binFactorVariableSymbol = new BinaryFactorVariable(); 56 59 var factorVariableSymbol = new FactorVariable(); 57 60 58 var allSymbols = new List<Symbol>() { add, sub, mul, div, constant, variableSymbol, binFactorVariableSymbol, factorVariableSymbol };61 var allSymbols = new List<Symbol>() { add, sub, mul, div, constant, number, variableSymbol, binFactorVariableSymbol, factorVariableSymbol }; 59 62 var functionSymbols = new List<Symbol>() { add, sub, mul, div }; 60 63 … … 66 69 } 67 70 SetSubtreeCount(constant, 0, 0); 71 SetSubtreeCount(number, 0, 0); 68 72 SetSubtreeCount(variableSymbol, 0, 0); 69 73 SetSubtreeCount(binFactorVariableSymbol, 0, 0); -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs
r17413 r18093 118 118 variableCondition.InitialFrequency = 0.0; 119 119 120 var constant = new Constant();120 var constant = new Num(); 121 121 constant.MinValue = -20; 122 122 constant.MaxValue = 20; … … 130 130 autoregressiveVariable.Enabled = false; 131 131 132 var number = new RealConstant(); 133 number.MinValue = -20; 134 number.MaxValue = 20; 135 132 136 var allSymbols = new List<Symbol>() { add, sub, mul, div, aq, mean, abs, sin, cos, tan, log, square, cube, pow, sqrt, cubeRoot, root, exp, tanh, 133 137 airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral, 134 @if, gt, lt, and, or, not,xor, timeLag, integral, derivative, constant, variableSymbol, binFactorVariable, factorVariable, laggedVariable,autoregressiveVariable, variableCondition };138 @if, gt, lt, and, or, not,xor, timeLag, integral, derivative, constant, number, variableSymbol, binFactorVariable, factorVariable, laggedVariable,autoregressiveVariable, variableCondition }; 135 139 var unaryFunctionSymbols = new List<Symbol>() { abs, square, sqrt, cube, cubeRoot, sin, cos, tan, log, exp, tanh, not, timeLag, integral, derivative, 136 140 airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral … … 139 143 var binaryFunctionSymbols = new List<Symbol>() { pow, root, gt, lt, aq, variableCondition }; 140 144 var ternarySymbols = new List<Symbol>() { add, sub, mul, div, mean, and, or, xor }; 141 var terminalSymbols = new List<Symbol>() { variableSymbol, binFactorVariable, factorVariable, constant, laggedVariable, autoregressiveVariable };145 var terminalSymbols = new List<Symbol>() { variableSymbol, binFactorVariable, factorVariable, constant, number, laggedVariable, autoregressiveVariable }; 142 146 143 147 foreach (var symb in allSymbols) -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/LinearScalingGrammar.cs
r17958 r18093 66 66 var abs = new Absolute(); 67 67 var aq = new AnalyticQuotient(); 68 var constant = new Constant();68 var constant = new Num(); 69 69 constant.MinValue = -20; 70 70 constant.MaxValue = 20; 71 var number = new RealConstant(); 72 number.MinValue = -20; 73 number.MaxValue = 20; 71 74 var variableSymbol = new Variable(); 72 75 … … 78 81 //all other symbols 79 82 var allSymbols = new List<Symbol> { 80 add, sub, mul, div, constant, variableSymbol, sin, cos, tan, log, square, sqrt, cube, cbrt, exp,83 add, sub, mul, div, constant, number, variableSymbol, sin, cos, tan, log, square, sqrt, cube, cbrt, exp, 81 84 tanh, aq, abs 82 85 }; … … 86 89 var realValueSymbols = new List<Symbol> { 87 90 add, sub, mul, div, sin, cos, tan, tanh, exp, log, aq, abs, square, cube, sqrt, cbrt, 88 variableSymbol, constant, 91 variableSymbol, constant, number 89 92 }; 90 93 -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs
r17413 r18093 105 105 var derivative = new Derivative(); 106 106 107 var constant = new Constant();107 var constant = new Num(); 108 108 constant.MinValue = -20; 109 109 constant.MaxValue = 20; 110 var number = new RealConstant(); 111 number.MinValue = -20; 112 number.MaxValue = 20; 110 113 var variableSymbol = new Variable(); 111 114 var binFactorVariable = new BinaryFactorVariable(); … … 121 124 var specialFunctions = new GroupSymbol(SpecialFunctionsName, new List<ISymbol> { abs, airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, 122 125 fresnelCosineIntegral,fresnelSineIntegral,gamma,hypCosineIntegral,hypSineIntegral,norm, psi, sineIntegral, analyticalQuotient}); 123 var terminalSymbols = new GroupSymbol(TerminalsName, new List<ISymbol> { constant, variableSymbol, binFactorVariable, factorVariable });126 var terminalSymbols = new GroupSymbol(TerminalsName, new List<ISymbol> { constant, number, variableSymbol, binFactorVariable, factorVariable }); 124 127 var realValuedSymbols = new GroupSymbol(RealValuedSymbolsName, new List<ISymbol>() { arithmeticSymbols, trigonometricSymbols, exponentialAndLogarithmicSymbols, specialFunctions, terminalSymbols }); 125 128 -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs
r17180 r18093 36 36 private static readonly Sine sin = new Sine(); 37 37 private static readonly Cosine cos = new Cosine(); 38 private static readonly Constant constant = new Constant();38 private static readonly Num Num = new Num(); 39 39 40 40 private static ISymbolicExpressionTreeNode ActualRoot(this ISymbolicExpressionTree tree) => tree.Root.GetSubtree(0).GetSubtree(0); … … 66 66 var symbol = node.Symbol; 67 67 var name = symbol.Name; 68 if (node is ConstantTreeNode constantNode) {68 if (node is NumTreeNode constantNode) { 69 69 name = strict ? constantNode.Value.ToString() : symbol.Name; 70 70 } else if (node is VariableTreeNode variableNode) { … … 222 222 variableTreeNode.VariableName = variable.VariableName; 223 223 variableTreeNode.Weight = variable.Weight; 224 } else if (node.Data is ConstantTreeNode @const) {225 var constantTreeNode = ( ConstantTreeNode)treeNodes[i];224 } else if (node.Data is NumTreeNode @const) { 225 var constantTreeNode = (NumTreeNode)treeNodes[i]; 226 226 constantTreeNode.Value = @const.Value; 227 227 } … … 285 285 286 286 var symbol = child.Data.Symbol; 287 if (child.Data is ConstantTreeNode firstConst) {287 if (child.Data is NumTreeNode firstConst) { 288 288 // fold sibling constant nodes into the first constant 289 289 for (int k = j + 1; k < children.Length; ++k) { 290 290 var sibling = nodes[children[k]]; 291 if (sibling.Data is ConstantTreeNode otherConst) {291 if (sibling.Data is NumTreeNode otherConst) { 292 292 sibling.Enabled = false; 293 293 node.Arity--; … … 301 301 for (int k = j + 1; k < children.Length; ++k) { 302 302 var sibling = nodes[children[k]]; 303 if (sibling.Data is ConstantTreeNode constantNode) {303 if (sibling.Data is NumTreeNode constantNode) { 304 304 sibling.Enabled = false; 305 305 node.Arity--; … … 329 329 330 330 if (node.Arity == 0) { // if everything is simplified this node becomes constant 331 var constantTreeNode = constant.CreateTreeNode<ConstantTreeNode>();331 var constantTreeNode = Num.CreateTreeNode<NumTreeNode>(); 332 332 constantTreeNode.Value = 1; 333 333 nodes[i] = constantTreeNode.ToHashNode(); … … 344 344 var tmp = nodes; 345 345 346 if (children.All(x => tmp[x].Data.Symbol is Constant)) {347 var v = (( ConstantTreeNode)nodes[children.First()].Data).Value;346 if (children.All(x => tmp[x].Data.Symbol is Num)) { 347 var v = ((NumTreeNode)nodes[children.First()].Data).Value; 348 348 if (node.Arity == 1) { 349 349 v = 1 / v; 350 350 } else if (node.Arity > 1) { 351 351 foreach (var j in children.Skip(1)) { 352 v /= (( ConstantTreeNode)nodes[j].Data).Value;352 v /= ((NumTreeNode)nodes[j].Data).Value; 353 353 } 354 354 } 355 var constantTreeNode = constant.CreateTreeNode<ConstantTreeNode>();355 var constantTreeNode = Num.CreateTreeNode<NumTreeNode>(); 356 356 constantTreeNode.Value = v; 357 357 nodes[i] = constantTreeNode.ToHashNode(); … … 368 368 } 369 369 if (node.Arity == 0) { 370 var constantTreeNode = constant.CreateTreeNode<ConstantTreeNode>();370 var constantTreeNode = Num.CreateTreeNode<NumTreeNode>(); 371 371 constantTreeNode.Value = 1; // x / x = 1 372 372 nodes[i] = constantTreeNode.ToHashNode(); … … 383 383 var childSymbol = child.Data.Symbol; 384 384 385 if (childSymbol is Constant) {385 if (childSymbol is Num) { 386 386 nodes[i].Enabled = false; 387 387 } else if ((parentSymbol is Exponential && childSymbol is Logarithm) || (parentSymbol is Logarithm && childSymbol is Exponential)) { … … 393 393 var children = nodes.IterateChildren(i); 394 394 var tmp = nodes; 395 if (children.All(x => tmp[x].Data.Symbol is Constant)) {395 if (children.All(x => tmp[x].Data.Symbol is Num)) { 396 396 foreach (var j in children) { 397 397 nodes[j].Enabled = false; 398 398 } 399 nodes[i] = constant.CreateTreeNode().ToHashNode();399 nodes[i] = Num.CreateTreeNode().ToHashNode(); 400 400 } 401 401 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r17958 r18093 47 47 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 48 48 <Prefer32Bit>false</Prefer32Bit> 49 <LangVersion>default</LangVersion> 49 50 </PropertyGroup> 50 51 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> … … 57 58 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 58 59 <Prefer32Bit>false</Prefer32Bit> 60 <LangVersion>default</LangVersion> 59 61 </PropertyGroup> 60 62 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> … … 67 69 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 68 70 <Prefer32Bit>false</Prefer32Bit> 71 <LangVersion>default</LangVersion> 69 72 </PropertyGroup> 70 73 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> … … 77 80 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 78 81 <Prefer32Bit>false</Prefer32Bit> 82 <LangVersion>default</LangVersion> 79 83 </PropertyGroup> 80 84 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> … … 87 91 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 88 92 <Prefer32Bit>false</Prefer32Bit> 93 <LangVersion>default</LangVersion> 89 94 </PropertyGroup> 90 95 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> … … 97 102 <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet> 98 103 <Prefer32Bit>false</Prefer32Bit> 104 <LangVersion>default</LangVersion> 99 105 </PropertyGroup> 100 106 <ItemGroup> … … 232 238 <Compile Include="Symbols\AutoregressiveVariable.cs" /> 233 239 <Compile Include="Symbols\Average.cs" /> 234 <Compile Include="Symbols\ Constant.cs" />235 <Compile Include="Symbols\ ConstantTreeNode.cs" />240 <Compile Include="Symbols\Num.cs" /> 241 <Compile Include="Symbols\NumTreeNode.cs" /> 236 242 <Compile Include="Symbols\AiryA.cs" /> 237 243 <Compile Include="Symbols\AiryB.cs" /> … … 245 251 <Compile Include="Symbols\CubeRoot.cs" /> 246 252 <Compile Include="Symbols\HyperbolicTangent.cs" /> 253 <Compile Include="Symbols\RealConstant.cs" /> 254 <Compile Include="Symbols\RealConstantTreeNode.cs" /> 247 255 <Compile Include="Symbols\VariableBase.cs" /> 248 256 <Compile Include="Symbols\VariableTreeNodeBase.cs" /> -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs
r17902 r18093 57 57 /// </summary> 58 58 public sealed class InfixExpressionParser { 59 private enum TokenType { Operator, Identifier, Number, LeftPar, RightPar, LeftBracket, RightBracket, Comma, Eq, End, NA };59 private enum TokenType { Operator, Identifier, Number, LeftPar, RightPar, LeftBracket, RightBracket, LeftAngleBracket, RightAngleBracket, Comma, Eq, End, NA }; 60 60 private class Token { 61 61 internal double doubleVal; … … 82 82 knownSymbols = new BidirectionalLookup<string, ISymbol>(StringComparer.InvariantCulture, new SymbolComparer()); 83 83 84 private Constant constant = new Constant(); 84 private Num num = new Num(); 85 private RealConstant realConstant = new RealConstant(); 85 86 private Variable variable = new Variable(); 86 87 private BinaryFactorVariable binaryFactorVar = new BinaryFactorVariable(); … … 265 266 pos++; 266 267 yield return new Token { TokenType = TokenType.Comma, strVal = "," }; 268 } else if (str[pos] == '<') { 269 pos++; 270 yield return new Token {TokenType = TokenType.LeftAngleBracket, strVal = "<"}; 271 } else if (str[pos] == '>') { 272 pos++; 273 yield return new Token {TokenType = TokenType.RightAngleBracket, strVal = ">"}; 267 274 } else { 268 275 throw new ArgumentException("Invalid character: " + str[pos]); … … 326 333 foreach (var negTerm in negTerms) sumNeg.AddSubtree(negTerm); 327 334 328 var constNode = ( ConstantTreeNode)constant.CreateTreeNode();335 var constNode = (NumTreeNode)num.CreateTreeNode(); 329 336 constNode.Value = -1.0; 330 337 var prod = GetSymbol("*").CreateTreeNode(); … … 524 531 } 525 532 } 533 } else if (next.TokenType == TokenType.LeftAngleBracket) { 534 var leftAngleBracket = tokens.Dequeue(); 535 if (leftAngleBracket.TokenType != TokenType.LeftAngleBracket) 536 throw new ArgumentException("opening bracket < expected"); 537 538 var idTok = tokens.Dequeue(); 539 if (idTok.TokenType != TokenType.Identifier || idTok.strVal.ToLower() != "num") 540 throw new ArgumentException("string 'num' expected"); 541 var rightAngleBracket = tokens.Dequeue(); 542 if (rightAngleBracket.TokenType != TokenType.RightAngleBracket) 543 throw new ArgumentException("closing bracket > expected"); 544 var numNode = (NumTreeNode)num.CreateTreeNode(); 545 return numNode; 526 546 } else if (next.TokenType == TokenType.Number) { 527 547 var numTok = tokens.Dequeue(); 528 var constNode = ( ConstantTreeNode)constant.CreateTreeNode();548 var constNode = (RealConstantTreeNode)realConstant.CreateTreeNode(); 529 549 constNode.Value = numTok.doubleVal; 530 550 return constNode; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/SymbolicExpressionImporter.cs
r17180 r18093 85 85 }; 86 86 87 Constant constant = new Constant();87 Num num = new Num(); 88 88 Variable variable = new Variable(); 89 89 LaggedVariable laggedVariable = new LaggedVariable(); … … 161 161 return tree; 162 162 } else if (tokens.Peek().Symbol == TokenSymbol.NUMBER) { 163 ConstantTreeNode t = (ConstantTreeNode)constant.CreateTreeNode();163 NumTreeNode t = (NumTreeNode)num.CreateTreeNode(); 164 164 t.Value = tokens.Dequeue().DoubleValue; 165 165 return t; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalArithBoundsEstimator.cs
r17964 r18093 127 127 } 128 128 case OpCodes.Constant: { 129 var constTreeNode = ( ConstantTreeNode)currentInstr.dynamicNode;129 var constTreeNode = (NumTreeNode)currentInstr.dynamicNode; 130 130 result = new Interval(constTreeNode.Value, constTreeNode.Value); 131 131 break; … … 324 324 where 325 325 !(n.Symbol is Variable) && 326 !(n.Symbol is Constant) && 326 !(n.Symbol is Num) && 327 !(n.Symbol is RealConstant) && 327 328 !(n.Symbol is StartSymbol) && 328 329 !(n.Symbol is Addition) && -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalArithCompiledExpressionBoundsEstimator.cs
r17909 r18093 116 116 where 117 117 !(n.Symbol is Variable) && 118 !(n.Symbol is Constant) && 118 !(n.Symbol is Num) && 119 !(n.Symbol is RealConstant) && 119 120 !(n.Symbol is StartSymbol) && 120 121 !(n.Symbol is Addition) && … … 154 155 } 155 156 case OpCodes.Constant: { 156 var v = (node as ConstantTreeNode).Value;157 var v = (node as NumTreeNode).Value; 157 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) 158 159 return Expression.Constant(new Interval(v, v), typeof(Interval)); -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
r17993 r18093 186 186 break; 187 187 } 188 case OpCodes.Number: { 189 var constTreeNode = (NumTreeNode)currentInstr.dynamicNode; 190 result = new Interval(constTreeNode.Value, constTreeNode.Value); 191 break; 192 } 188 193 case OpCodes.Constant: { 189 var constTreeNode = (ConstantTreeNode)currentInstr.dynamicNode;190 191 194 var constTreeNode = (RealConstantTreeNode)currentInstr.dynamicNode; 195 result = new Interval(constTreeNode.Value, constTreeNode.Value); 196 break; 192 197 } 193 198 case OpCodes.Add: { … … 324 329 if ( 325 330 !(n.Symbol is Variable) && 326 !(n.Symbol is Constant) &&331 !(n.Symbol is Num) && 327 332 !(n.Symbol is StartSymbol) && 328 333 !(n.Symbol is Addition) && … … 346 351 else if (n.Symbol is Power) { 347 352 // only integer exponents are supported 348 var exp = n.GetSubtree(1) as ConstantTreeNode;353 var exp = n.GetSubtree(1) as NumTreeNode; 349 354 if (exp == null || exp.Value != Math.Truncate(exp.Value)) return false; 350 355 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r17963 r18093 46 46 Variable = 18, 47 47 LagVariable = 19, 48 Constant= 20,48 Num = 20, 49 49 Arg = 21, 50 50 Power = 22, … … 79 79 CubeRoot = 51, 80 80 Tanh = 52, 81 Constant = 53 81 82 }; 82 83 public static class OpCodes { … … 101 102 public const byte Variable = (byte)OpCode.Variable; 102 103 public const byte LagVariable = (byte)OpCode.LagVariable; 103 public const byte Constant = (byte)OpCode.Constant; 104 public const byte Number = (byte)OpCode.Num; 105 public const byte Constant = (byte) OpCode.Constant; 104 106 public const byte Arg = (byte)OpCode.Arg; 105 107 public const byte Power = (byte)OpCode.Power; … … 159 161 { typeof(LaggedVariable), OpCodes.LagVariable }, 160 162 { typeof(AutoregressiveTargetVariable),OpCodes.LagVariable}, 161 { typeof(Constant), OpCodes.Constant }, 163 { typeof(Num), OpCodes.Number }, 164 { typeof(RealConstant), OpCodes.Constant }, 162 165 { typeof(Argument), OpCodes.Arg }, 163 166 { typeof(Power),OpCodes.Power}, -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs
r17351 r18093 158 158 switch (opcode) { 159 159 case OpCodes.Constant: { 160 var constantTreeNode = ( ConstantTreeNode)node;160 var constantTreeNode = (NumTreeNode)node; 161 161 return Expression.Constant(constantTreeNode.Value); 162 162 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeBatchInterpreter.cs
r17801 r18093 279 279 cachedData[variable.VariableName] = code[i].data; 280 280 } 281 } else if (node is ConstantTreeNode constant) {281 } else if (node is NumTreeNode constant) { 282 282 code[i].value = constant.Value; 283 283 for (int j = 0; j < BATCHSIZE; ++j) -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs
r17180 r18093 711 711 return; 712 712 } 713 case OpCodes.Number: { 714 NumTreeNode constNode = (NumTreeNode)currentInstr.dynamicNode; 715 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, constNode.Value); 716 return; 717 } 713 718 case OpCodes.Constant: { 714 ConstantTreeNode constNode = (ConstantTreeNode)currentInstr.dynamicNode;715 716 717 719 RealConstantTreeNode constNode = (RealConstantTreeNode) currentInstr.dynamicNode; 720 il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, constNode.Value); 721 return; 722 } 718 723 719 724 //mkommend: this symbol uses the logistic function f(x) = 1 / (1 + e^(-alpha * x) ) -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs
r17180 r18093 497 497 } 498 498 case OpCodes.Constant: { 499 var constTreeNode = ( ConstantTreeNode)currentInstr.dynamicNode;499 var constTreeNode = (NumTreeNode)currentInstr.dynamicNode; 500 500 return constTreeNode.Value; 501 501 } 502 case OpCodes.Number: { 503 var numberTreeNode = (RealConstantTreeNode) currentInstr.dynamicNode; 504 return numberTreeNode.Value; 505 } 502 506 503 507 //mkommend: this symbol uses the logistic function f(x) = 1 / (1 + e^(-alpha * x) ) -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs
r17180 r18093 416 416 #region opcode switch 417 417 switch (instr.opCode) { 418 case OpCodes. Constant: {419 var constTreeNode = ( ConstantTreeNode)instr.dynamicNode;418 case OpCodes.Number: { 419 var constTreeNode = (NumTreeNode)instr.dynamicNode; 420 420 instr.value = constTreeNode.Value; 421 421 instr.skip = true; // the value is already set so this instruction should be skipped in the evaluation phase 422 } 423 break; 424 case OpCodes.Constant: { 425 var constTreeNode = (RealConstantTreeNode)instr.dynamicNode; 426 instr.value = constTreeNode.Value; 427 instr.skip = true; // the value is already set so this instruction should be skipped in the evaluation phase 422 428 } 423 429 break; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs
r17801 r18093 82 82 code[i].weight = variable.Weight; 83 83 code[i].data = cachedData[variable.VariableName].AddrOfPinnedObject(); 84 } else if (node is ConstantTreeNode constant) {84 } else if (node is NumTreeNode constant) { 85 85 code[i].value = constant.Value; 86 86 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionPruningOperator.cs
r17180 r18093 172 172 for (int i = 0; i < nodes.Count; ++i) { 173 173 var node = nodes[i]; 174 if (node is ConstantTreeNode) continue;174 if (node is NumTreeNode) continue; 175 175 176 176 double impactValue, replacementValue; … … 181 181 if (!PruneOnlyZeroImpactNodes && impactValue > NodeImpactThreshold) continue; 182 182 183 var constantNode = ( ConstantTreeNode)node.Grammar.GetSymbol("Constant").CreateTreeNode();183 var constantNode = (NumTreeNode)node.Grammar.GetSymbol("Num").CreateTreeNode(); 184 184 constantNode.Value = replacementValue; 185 185 -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs
r17180 r18093 115 115 if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) return; 116 116 117 ConstantTreeNode alphaTreeNode = null;118 ConstantTreeNode betaTreeNode = null;117 NumTreeNode alphaTreeNode = null; 118 NumTreeNode betaTreeNode = null; 119 119 // check if model has a structure that can be re-used for scaling 120 120 var startNode = SymbolicExpressionTree.Root.GetSubtree(0); 121 121 var addNode = startNode.GetSubtree(0); 122 122 if (addNode.Symbol is Addition && addNode.SubtreeCount == 2) { 123 alphaTreeNode = ( ConstantTreeNode)addNode.Subtrees.LastOrDefault(n => n is ConstantTreeNode);123 alphaTreeNode = (NumTreeNode)addNode.Subtrees.LastOrDefault(n => n is NumTreeNode); 124 124 var mulNode = addNode.Subtrees.FirstOrDefault(n => n.Symbol is Multiplication); 125 125 if (mulNode != null) { 126 betaTreeNode = ( ConstantTreeNode)mulNode.Subtrees.LastOrDefault(n => n is ConstantTreeNode);126 betaTreeNode = (NumTreeNode)mulNode.Subtrees.LastOrDefault(n => n is NumTreeNode); 127 127 } 128 128 } … … 167 167 168 168 private static ISymbolicExpressionTreeNode MakeConstant(double c) { 169 var node = ( ConstantTreeNode)(new Constant()).CreateTreeNode();169 var node = (NumTreeNode)(new Num()).CreateTreeNode(); 170 170 node.Value = c; 171 171 return node; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModelComplexityCalculator.cs
r17180 r18093 80 80 case OpCodes.Root: { 81 81 double complexity = CalculateComplexity(node.GetSubtree(0)); 82 var exponent = node.GetSubtree(1) as ConstantTreeNode;82 var exponent = node.GetSubtree(1) as NumTreeNode; 83 83 if (exponent != null) { 84 84 double expVal = exponent.Value; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs
r17180 r18093 59 59 tempModelParentNode.RemoveSubtree(i); 60 60 61 var constantNode = new ConstantTreeNode(new Constant()) { Value = repValue };61 var constantNode = new NumTreeNode(new Num()) { Value = repValue }; 62 62 tempModelParentNode.InsertSubtree(i, constantNode); 63 63 … … 80 80 IDataset dataset, IEnumerable<int> rows) { 81 81 //optimization: constant nodes return always the same value 82 ConstantTreeNode constantNode = node as ConstantTreeNode;82 NumTreeNode numNode = node as NumTreeNode; 83 83 BinaryFactorVariableTreeNode binaryFactorNode = node as BinaryFactorVariableTreeNode; 84 84 FactorVariableTreeNode factorNode = node as FactorVariableTreeNode; 85 if ( constantNode != null) {86 yield return constantNode.Value;85 if (numNode != null) { 86 yield return numNode.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/Num.cs
r18092 r18093 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 28 [StorableType("5CD355EA-36E4-4E43-B8C4-9E9CF4CBC860")] 29 [Item(" Constant", "Represents a constant value.")]30 public sealed class Constant: Symbol {29 [Item("Num", "Represents a constant value.")] 30 public sealed class Num : Symbol { 31 31 #region Properties 32 32 [Storable] … … 100 100 101 101 [StorableConstructor] 102 private Constant(StorableConstructorFlag _) : base(_) { }103 private Constant(Constantoriginal, Cloner cloner)102 private Num(StorableConstructorFlag _) : base(_) { } 103 private Num(Num original, Cloner cloner) 104 104 : base(original, cloner) { 105 105 minValue = original.minValue; … … 109 109 multiplicativeManipulatorSigma = original.multiplicativeManipulatorSigma; 110 110 } 111 public Constant()112 : base(" Constant", "Represents a constant value.") {111 public Num() 112 : base("Num", "Represents a constant value.") { 113 113 manipulatorMu = 0.0; 114 114 manipulatorSigma = 1.0; … … 119 119 120 120 public override ISymbolicExpressionTreeNode CreateTreeNode() { 121 return new ConstantTreeNode(this);121 return new NumTreeNode(this); 122 122 } 123 123 124 124 public override IDeepCloneable Clone(Cloner cloner) { 125 return new Constant(this, cloner);125 return new Num(this, cloner); 126 126 } 127 127 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/NumTreeNode.cs
r18092 r18093 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 28 [StorableType("247DBD04-18F2-4184-B6F5-6E283BF06FD0")] 29 public sealed class ConstantTreeNode : SymbolicExpressionTreeTerminalNode {30 public new ConstantSymbol {31 get { return ( Constant)base.Symbol; }29 public sealed class NumTreeNode : SymbolicExpressionTreeTerminalNode { 30 public new Num Symbol { 31 get { return (Num)base.Symbol; } 32 32 } 33 33 … … 40 40 41 41 [StorableConstructor] 42 private ConstantTreeNode(StorableConstructorFlag _) : base(_) { }42 private NumTreeNode(StorableConstructorFlag _) : base(_) { } 43 43 44 private ConstantTreeNode(ConstantTreeNode original, Cloner cloner)44 private NumTreeNode(NumTreeNode original, Cloner cloner) 45 45 : base(original, cloner) { 46 46 constantValue = original.constantValue; 47 47 } 48 48 49 private ConstantTreeNode() : base() { }50 public ConstantTreeNode(Constant constantSymbol) : base(constantSymbol) { }49 private NumTreeNode() : base() { } 50 public NumTreeNode(Num numSymbol) : base(numSymbol) { } 51 51 52 52 public override bool HasLocalParameters { … … 74 74 75 75 public override IDeepCloneable Clone(Cloner cloner) { 76 return new ConstantTreeNode(this, cloner);76 return new NumTreeNode(this, cloner); 77 77 } 78 78 79 79 public override string ToString() { 80 return constantValue.ToString("E4"); 80 return $"<{constantValue:E4}>"; 81 // return constantValue.ToString("E4"); 81 82 } 82 83 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Transformations/SymbolicExpressionTreeBacktransformator.cs
r17180 r18093 90 90 private ISymbolicExpressionTreeNode CreateNodeFromWeight(ISymbolicExpressionTreeNode transformationTree, VariableTreeNode variableNode) { 91 91 var multiplicationNode = new SymbolicExpressionTreeNode(new Multiplication()); 92 multiplicationNode.AddSubtree(new ConstantTreeNode(new Constant()) { Value = variableNode.Weight });92 multiplicationNode.AddSubtree(new NumTreeNode(new Num()) { Value = variableNode.Weight }); 93 93 multiplicationNode.AddSubtree(transformationTree); 94 94 return multiplicationNode; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Transformations/TransformationToSymbolicTreeMapper.cs
r17180 r18093 279 279 } 280 280 281 private ConstantTreeNode CreateConstantTreeNode(string description, double value) {282 return new ConstantTreeNode(new Constant()) { Value = value };281 private NumTreeNode CreateConstantTreeNode(string description, double value) { 282 return new NumTreeNode(new Num()) { Value = value }; 283 283 } 284 284 -
branches/3140_NumberSymbol/HeuristicLab.Problems.ExternalEvaluation.GP/3.5/ExternalEvaluationExpressionGrammar.cs
r17413 r18093 62 62 var or = new Or(); 63 63 var not = new Not(); 64 var constant = new Constant();64 var constant = new Num(); 65 65 constant.MinValue = -20; 66 66 constant.MaxValue = 20; -
branches/3140_NumberSymbol/HeuristicLab.Problems.ExternalEvaluation.GP/3.5/ExternalEvaluationSymbolicExpressionTreeStringFormatter.cs
r17180 r18093 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 Constant) {109 var constNode = node as ConstantTreeNode;108 } else if (node.Symbol is Num) { 109 var constNode = node as NumTreeNode; 110 110 strBuilder.Append(constNode.Value.ToString("g17", CultureInfo.InvariantCulture)); 111 111 } else {
Note: See TracChangeset
for help on using the changeset viewer.