Changeset 18093


Ignore:
Timestamp:
11/24/21 13:40:39 (7 days ago)
Author:
chaider
Message:

#3041

  • Renaming Constant Symbol to Num, behaves like before
  • Adding new Symbol RealConstant (Constant), this symbol behaves now like a real constant, won't be changed by parameter optimization or manipulators
  • Refactored classes part1
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  
    120120
    121121    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>())
    123123        constNode.Value = value;
    124124
     
    223223    }
    224224
    225     private ISymbolicExpressionTreeNode MakeProduct(ConstantTreeNode c, double weight) {
     225    private ISymbolicExpressionTreeNode MakeProduct(NumTreeNode c, double weight) {
    226226      var mul = new Multiplication();
    227227      var prod = mul.CreateTreeNode();
     
    231231    }
    232232
    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;
    240240    }
    241241  }
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/NMSESingleObjectiveConstraintsEvaluator.cs

    r17958 r18093  
    155155          if (errorState == OnlineCalculatorError.None) {
    156156            //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;
    158158            offsetParameter.Value = alpha;
    159             var scalingParameter = scaling.GetSubtree(1) as ConstantTreeNode;
     159            var scalingParameter = scaling.GetSubtree(1) as NumTreeNode;
    160160            scalingParameter.Value = beta;
    161161          }
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/SymbolicRegressionConstantOptimizationEvaluator.cs

    r17944 r18093  
    3232
    3333namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
    34   [Item("Constant Optimization 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.")]
    3535  [StorableType("24B68851-036D-4446-BD6F-3823E9028FF4")]
    3636  public class SymbolicRegressionConstantOptimizationEvaluator : SymbolicRegressionSingleObjectiveEvaluator {
     
    307307      int i = 0;
    308308      foreach (var node in tree.Root.IterateNodesPrefix().OfType<SymbolicExpressionTreeTerminalNode>()) {
    309         ConstantTreeNode constantTreeNode = node as ConstantTreeNode;
     309        NumTreeNode numTreeNode = node as NumTreeNode;
    310310        VariableTreeNodeBase variableTreeNodeBase = node as VariableTreeNodeBase;
    311311        FactorVariableTreeNode factorVarTreeNode = node as FactorVariableTreeNode;
    312         if (constantTreeNode != null) {
    313           if (constantTreeNode.Parent.Symbol is Power
    314               && 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++];
    316316        } else if (updateVariableWeights && variableTreeNodeBase != null)
    317317          variableTreeNodeBase.Weight = constants[i++];
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/LinearModelToTreeConverter.cs

    r17180 r18093  
    5858
    5959      if (@const!=0.0) {
    60         ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode();
     60        NumTreeNode cNode = (NumTreeNode)new Num().CreateTreeNode();
    6161        cNode.Value = @const;
    6262        add.AddSubtree(cNode);
     
    9999
    100100      if (!@const.IsAlmost(0.0)) {
    101         ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode();
     101        NumTreeNode cNode = (NumTreeNode)new Num().CreateTreeNode();
    102102        cNode.Value = @const;
    103103        addition.AddSubtree(cNode);
     
    130130
    131131      if (!@const.IsAlmost(0.0)) {
    132         ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode();
     132        NumTreeNode cNode = (NumTreeNode)new Num().CreateTreeNode();
    133133        cNode.Value = @const;
    134134        addition.AddSubtree(cNode);
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs

    r17817 r18093  
    145145
    146146    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);
    149156        var var = new AutoDiff.Variable();
    150157        variables.Add(var);
     
    260267      }
    261268      if (node.Symbol is Power) {
    262         var powerNode = node.GetSubtree(1) as ConstantTreeNode;
     269        var powerNode = node.GetSubtree(1) as NumTreeNode;
    263270        if (powerNode == null)
    264271          throw new NotSupportedException("Only integer powers are allowed in parameter optimization. Try to use exp() and log() instead of the power symbol.");
     
    330337          !(n.Symbol is FactorVariable) &&
    331338          !(n.Symbol is LaggedVariable) &&
    332           !(n.Symbol is Constant) &&
     339          !(n.Symbol is Num) &&
     340          !(n.Symbol is RealConstant) &&
    333341          !(n.Symbol is Addition) &&
    334342          !(n.Symbol is Subtraction) &&
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/ArithmeticExpressionGrammar.cs

    r17413 r18093  
    4949      var mul = new Multiplication();
    5050      var div = new Division();
    51       var constant = new Constant();
     51      var constant = new Num();
    5252      constant.MinValue = -20;
    5353      constant.MaxValue = 20;
     54      var number = new RealConstant();
     55      number.MinValue = -20;
     56      number.MaxValue = 20;
    5457      var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
    5558      var binFactorVariableSymbol = new BinaryFactorVariable();
    5659      var factorVariableSymbol = new FactorVariable();
    5760
    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 };
    5962      var functionSymbols = new List<Symbol>() { add, sub, mul, div };
    6063
     
    6669      }
    6770      SetSubtreeCount(constant, 0, 0);
     71      SetSubtreeCount(number, 0, 0);
    6872      SetSubtreeCount(variableSymbol, 0, 0);
    6973      SetSubtreeCount(binFactorVariableSymbol, 0, 0);
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs

    r17413 r18093  
    118118      variableCondition.InitialFrequency = 0.0;
    119119
    120       var constant = new Constant();
     120      var constant = new Num();
    121121      constant.MinValue = -20;
    122122      constant.MaxValue = 20;
     
    130130      autoregressiveVariable.Enabled = false;
    131131
     132      var number = new RealConstant();
     133      number.MinValue = -20;
     134      number.MaxValue = 20;
     135
    132136      var allSymbols = new List<Symbol>() { add, sub, mul, div, aq, mean, abs, sin, cos, tan, log, square, cube, pow, sqrt, cubeRoot, root, exp, tanh,
    133137        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 };
    135139      var unaryFunctionSymbols = new List<Symbol>() { abs, square, sqrt, cube, cubeRoot, sin, cos, tan, log, exp, tanh, not, timeLag, integral, derivative,
    136140        airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral
     
    139143      var binaryFunctionSymbols = new List<Symbol>() { pow, root, gt, lt, aq, variableCondition };
    140144      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 };
    142146
    143147      foreach (var symb in allSymbols)
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/LinearScalingGrammar.cs

    r17958 r18093  
    6666      var abs = new Absolute();
    6767      var aq = new AnalyticQuotient();
    68       var constant = new Constant();
     68      var constant = new Num();
    6969      constant.MinValue = -20;
    7070      constant.MaxValue = 20;
     71      var number = new RealConstant();
     72      number.MinValue = -20;
     73      number.MaxValue = 20;
    7174      var variableSymbol = new Variable();
    7275
     
    7881      //all other symbols
    7982      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,
    8184        tanh, aq, abs
    8285      };
     
    8689      var realValueSymbols = new List<Symbol> {
    8790         add, sub, mul, div, sin, cos, tan, tanh, exp, log, aq, abs, square, cube, sqrt, cbrt,
    88          variableSymbol, constant,
     91         variableSymbol, constant, number
    8992        };
    9093
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs

    r17413 r18093  
    105105      var derivative = new Derivative();
    106106
    107       var constant = new Constant();
     107      var constant = new Num();
    108108      constant.MinValue = -20;
    109109      constant.MaxValue = 20;
     110      var number = new RealConstant();
     111      number.MinValue = -20;
     112      number.MaxValue = 20;
    110113      var variableSymbol = new Variable();
    111114      var binFactorVariable = new BinaryFactorVariable();
     
    121124      var specialFunctions = new GroupSymbol(SpecialFunctionsName, new List<ISymbol> { abs, airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi,
    122125        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 });
    124127      var realValuedSymbols = new GroupSymbol(RealValuedSymbolsName, new List<ISymbol>() { arithmeticSymbols, trigonometricSymbols, exponentialAndLogarithmicSymbols, specialFunctions, terminalSymbols });
    125128
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs

    r17180 r18093  
    3636    private static readonly Sine sin = new Sine();
    3737    private static readonly Cosine cos = new Cosine();
    38     private static readonly Constant constant = new Constant();
     38    private static readonly Num Num = new Num();
    3939
    4040    private static ISymbolicExpressionTreeNode ActualRoot(this ISymbolicExpressionTree tree) => tree.Root.GetSubtree(0).GetSubtree(0);
     
    6666      var symbol = node.Symbol;
    6767      var name = symbol.Name;
    68       if (node is ConstantTreeNode constantNode) {
     68      if (node is NumTreeNode constantNode) {
    6969        name = strict ? constantNode.Value.ToString() : symbol.Name;
    7070      } else if (node is VariableTreeNode variableNode) {
     
    222222            variableTreeNode.VariableName = variable.VariableName;
    223223            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];
    226226            constantTreeNode.Value = @const.Value;
    227227          }
     
    285285
    286286        var symbol = child.Data.Symbol;
    287         if (child.Data is ConstantTreeNode firstConst) {
     287        if (child.Data is NumTreeNode firstConst) {
    288288          // fold sibling constant nodes into the first constant
    289289          for (int k = j + 1; k < children.Length; ++k) {
    290290            var sibling = nodes[children[k]];
    291             if (sibling.Data is ConstantTreeNode otherConst) {
     291            if (sibling.Data is NumTreeNode otherConst) {
    292292              sibling.Enabled = false;
    293293              node.Arity--;
     
    301301          for (int k = j + 1; k < children.Length; ++k) {
    302302            var sibling = nodes[children[k]];
    303             if (sibling.Data is ConstantTreeNode constantNode) {
     303            if (sibling.Data is NumTreeNode constantNode) {
    304304              sibling.Enabled = false;
    305305              node.Arity--;
     
    329329
    330330        if (node.Arity == 0) { // if everything is simplified this node becomes constant
    331           var constantTreeNode = constant.CreateTreeNode<ConstantTreeNode>();
     331          var constantTreeNode = Num.CreateTreeNode<NumTreeNode>();
    332332          constantTreeNode.Value = 1;
    333333          nodes[i] = constantTreeNode.ToHashNode();
     
    344344      var tmp = nodes;
    345345
    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;
    348348        if (node.Arity == 1) {
    349349          v = 1 / v;
    350350        } else if (node.Arity > 1) {
    351351          foreach (var j in children.Skip(1)) {
    352             v /= ((ConstantTreeNode)nodes[j].Data).Value;
     352            v /= ((NumTreeNode)nodes[j].Data).Value;
    353353          }
    354354        }
    355         var constantTreeNode = constant.CreateTreeNode<ConstantTreeNode>();
     355        var constantTreeNode = Num.CreateTreeNode<NumTreeNode>();
    356356        constantTreeNode.Value = v;
    357357        nodes[i] = constantTreeNode.ToHashNode();
     
    368368        }
    369369        if (node.Arity == 0) {
    370           var constantTreeNode = constant.CreateTreeNode<ConstantTreeNode>();
     370          var constantTreeNode = Num.CreateTreeNode<NumTreeNode>();
    371371          constantTreeNode.Value = 1; // x / x = 1
    372372          nodes[i] = constantTreeNode.ToHashNode();
     
    383383      var childSymbol = child.Data.Symbol;
    384384
    385       if (childSymbol is Constant) {
     385      if (childSymbol is Num) {
    386386        nodes[i].Enabled = false;
    387387      } else if ((parentSymbol is Exponential && childSymbol is Logarithm) || (parentSymbol is Logarithm && childSymbol is Exponential)) {
     
    393393      var children = nodes.IterateChildren(i);
    394394      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)) {
    396396        foreach (var j in children) {
    397397          nodes[j].Enabled = false;
    398398        }
    399         nodes[i] = constant.CreateTreeNode().ToHashNode();
     399        nodes[i] = Num.CreateTreeNode().ToHashNode();
    400400      }
    401401    }
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r17958 r18093  
    4747    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    4848    <Prefer32Bit>false</Prefer32Bit>
     49    <LangVersion>default</LangVersion>
    4950  </PropertyGroup>
    5051  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     
    5758    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    5859    <Prefer32Bit>false</Prefer32Bit>
     60    <LangVersion>default</LangVersion>
    5961  </PropertyGroup>
    6062  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
     
    6769    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    6870    <Prefer32Bit>false</Prefer32Bit>
     71    <LangVersion>default</LangVersion>
    6972  </PropertyGroup>
    7073  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
     
    7780    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    7881    <Prefer32Bit>false</Prefer32Bit>
     82    <LangVersion>default</LangVersion>
    7983  </PropertyGroup>
    8084  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
     
    8791    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    8892    <Prefer32Bit>false</Prefer32Bit>
     93    <LangVersion>default</LangVersion>
    8994  </PropertyGroup>
    9095  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
     
    97102    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    98103    <Prefer32Bit>false</Prefer32Bit>
     104    <LangVersion>default</LangVersion>
    99105  </PropertyGroup>
    100106  <ItemGroup>
     
    232238    <Compile Include="Symbols\AutoregressiveVariable.cs" />
    233239    <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" />
    236242    <Compile Include="Symbols\AiryA.cs" />
    237243    <Compile Include="Symbols\AiryB.cs" />
     
    245251    <Compile Include="Symbols\CubeRoot.cs" />
    246252    <Compile Include="Symbols\HyperbolicTangent.cs" />
     253    <Compile Include="Symbols\RealConstant.cs" />
     254    <Compile Include="Symbols\RealConstantTreeNode.cs" />
    247255    <Compile Include="Symbols\VariableBase.cs" />
    248256    <Compile Include="Symbols\VariableTreeNodeBase.cs" />
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs

    r17902 r18093  
    5757  /// </summary>
    5858  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 };
    6060    private class Token {
    6161      internal double doubleVal;
     
    8282      knownSymbols = new BidirectionalLookup<string, ISymbol>(StringComparer.InvariantCulture, new SymbolComparer());
    8383
    84     private Constant constant = new Constant();
     84    private Num num = new Num();
     85    private RealConstant realConstant = new RealConstant();
    8586    private Variable variable = new Variable();
    8687    private BinaryFactorVariable binaryFactorVar = new BinaryFactorVariable();
     
    265266          pos++;
    266267          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 = ">"};
    267274        } else {
    268275          throw new ArgumentException("Invalid character: " + str[pos]);
     
    326333          foreach (var negTerm in negTerms) sumNeg.AddSubtree(negTerm);
    327334
    328           var constNode = (ConstantTreeNode)constant.CreateTreeNode();
     335          var constNode = (NumTreeNode)num.CreateTreeNode();
    329336          constNode.Value = -1.0;
    330337          var prod = GetSymbol("*").CreateTreeNode();
     
    524531          }
    525532        }
     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;
    526546      } else if (next.TokenType == TokenType.Number) {
    527547        var numTok = tokens.Dequeue();
    528         var constNode = (ConstantTreeNode)constant.CreateTreeNode();
     548        var constNode = (RealConstantTreeNode)realConstant.CreateTreeNode();
    529549        constNode.Value = numTok.doubleVal;
    530550        return constNode;
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/SymbolicExpressionImporter.cs

    r17180 r18093  
    8585      };
    8686
    87     Constant constant = new Constant();
     87    Num num = new Num();
    8888    Variable variable = new Variable();
    8989    LaggedVariable laggedVariable = new LaggedVariable();
     
    161161        return tree;
    162162      } else if (tokens.Peek().Symbol == TokenSymbol.NUMBER) {
    163         ConstantTreeNode t = (ConstantTreeNode)constant.CreateTreeNode();
     163        NumTreeNode t = (NumTreeNode)num.CreateTreeNode();
    164164        t.Value = tokens.Dequeue().DoubleValue;
    165165        return t;
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalArithBoundsEstimator.cs

    r17964 r18093  
    127127          }
    128128        case OpCodes.Constant: {
    129             var constTreeNode = (ConstantTreeNode)currentInstr.dynamicNode;
     129            var constTreeNode = (NumTreeNode)currentInstr.dynamicNode;
    130130            result = new Interval(constTreeNode.Value, constTreeNode.Value);
    131131            break;
     
    324324        where
    325325          !(n.Symbol is Variable) &&
    326           !(n.Symbol is Constant) &&
     326          !(n.Symbol is Num) &&
     327          !(n.Symbol is RealConstant) &&
    327328          !(n.Symbol is StartSymbol) &&
    328329          !(n.Symbol is Addition) &&
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalArithCompiledExpressionBoundsEstimator.cs

    r17909 r18093  
    116116        where
    117117          !(n.Symbol is Variable) &&
    118           !(n.Symbol is Constant) &&
     118          !(n.Symbol is Num) &&
     119          !(n.Symbol is RealConstant) &&
    119120          !(n.Symbol is StartSymbol) &&
    120121          !(n.Symbol is Addition) &&
     
    154155          }
    155156        case OpCodes.Constant: {
    156             var v = (node as ConstantTreeNode).Value;
     157            var v = (node as NumTreeNode).Value;
    157158            // 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)
    158159            return Expression.Constant(new Interval(v, v), typeof(Interval));
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs

    r17993 r18093  
    186186            break;
    187187          }
     188        case OpCodes.Number: {
     189            var constTreeNode = (NumTreeNode)currentInstr.dynamicNode;
     190            result = new Interval(constTreeNode.Value, constTreeNode.Value);
     191            break;
     192          }
    188193        case OpCodes.Constant: {
    189             var constTreeNode = (ConstantTreeNode)currentInstr.dynamicNode;
    190             result = new Interval(constTreeNode.Value, constTreeNode.Value);
    191             break;
     194          var constTreeNode = (RealConstantTreeNode)currentInstr.dynamicNode;
     195          result = new Interval(constTreeNode.Value, constTreeNode.Value);
     196          break;
    192197          }
    193198        case OpCodes.Add: {
     
    324329        if (
    325330          !(n.Symbol is Variable) &&
    326           !(n.Symbol is Constant) &&
     331          !(n.Symbol is Num) &&
    327332          !(n.Symbol is StartSymbol) &&
    328333          !(n.Symbol is Addition) &&
     
    346351        else if (n.Symbol is Power) {
    347352          // only integer exponents are supported
    348           var exp = n.GetSubtree(1) as ConstantTreeNode;
     353          var exp = n.GetSubtree(1) as NumTreeNode;
    349354          if (exp == null || exp.Value != Math.Truncate(exp.Value)) return false;
    350355        }
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs

    r17963 r18093  
    4646    Variable = 18,
    4747    LagVariable = 19,
    48     Constant = 20,
     48    Num = 20,
    4949    Arg = 21,
    5050    Power = 22,
     
    7979    CubeRoot = 51,
    8080    Tanh = 52,
     81    Constant = 53
    8182  };
    8283  public static class OpCodes {
     
    101102    public const byte Variable = (byte)OpCode.Variable;
    102103    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;
    104106    public const byte Arg = (byte)OpCode.Arg;
    105107    public const byte Power = (byte)OpCode.Power;
     
    159161      { typeof(LaggedVariable), OpCodes.LagVariable },
    160162      { typeof(AutoregressiveTargetVariable),OpCodes.LagVariable},
    161       { typeof(Constant), OpCodes.Constant },
     163      { typeof(Num), OpCodes.Number },
     164      { typeof(RealConstant), OpCodes.Constant },
    162165      { typeof(Argument), OpCodes.Arg },
    163166      { typeof(Power),OpCodes.Power},
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs

    r17351 r18093  
    158158      switch (opcode) {
    159159        case OpCodes.Constant: {
    160             var constantTreeNode = (ConstantTreeNode)node;
     160            var constantTreeNode = (NumTreeNode)node;
    161161            return Expression.Constant(constantTreeNode.Value);
    162162          }
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeBatchInterpreter.cs

    r17801 r18093  
    279279            cachedData[variable.VariableName] = code[i].data;
    280280          }
    281         } else if (node is ConstantTreeNode constant) {
     281        } else if (node is NumTreeNode constant) {
    282282          code[i].value = constant.Value;
    283283          for (int j = 0; j < BATCHSIZE; ++j)
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r17180 r18093  
    711711            return;
    712712          }
     713        case OpCodes.Number: {
     714            NumTreeNode constNode = (NumTreeNode)currentInstr.dynamicNode;
     715            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, constNode.Value);
     716            return;
     717          }
    713718        case OpCodes.Constant: {
    714             ConstantTreeNode constNode = (ConstantTreeNode)currentInstr.dynamicNode;
    715             il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, constNode.Value);
    716             return;
    717           }
     719          RealConstantTreeNode constNode = (RealConstantTreeNode) currentInstr.dynamicNode;
     720          il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, constNode.Value);
     721          return;
     722        }
    718723
    719724        //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  
    497497          }
    498498        case OpCodes.Constant: {
    499             var constTreeNode = (ConstantTreeNode)currentInstr.dynamicNode;
     499            var constTreeNode = (NumTreeNode)currentInstr.dynamicNode;
    500500            return constTreeNode.Value;
    501501          }
     502        case OpCodes.Number: {
     503          var numberTreeNode = (RealConstantTreeNode) currentInstr.dynamicNode;
     504          return numberTreeNode.Value;
     505        }
    502506
    503507        //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  
    416416        #region opcode switch
    417417        switch (instr.opCode) {
    418           case OpCodes.Constant: {
    419               var constTreeNode = (ConstantTreeNode)instr.dynamicNode;
     418          case OpCodes.Number: {
     419              var constTreeNode = (NumTreeNode)instr.dynamicNode;
    420420              instr.value = constTreeNode.Value;
    421421              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
    422428            }
    423429            break;
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeNativeInterpreter.cs

    r17801 r18093  
    8282          code[i].weight = variable.Weight;
    8383          code[i].data = cachedData[variable.VariableName].AddrOfPinnedObject();
    84         } else if (node is ConstantTreeNode constant) {
     84        } else if (node is NumTreeNode constant) {
    8585          code[i].value = constant.Value;
    8686        }
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionPruningOperator.cs

    r17180 r18093  
    172172      for (int i = 0; i < nodes.Count; ++i) {
    173173        var node = nodes[i];
    174         if (node is ConstantTreeNode) continue;
     174        if (node is NumTreeNode) continue;
    175175
    176176        double impactValue, replacementValue;
     
    181181        if (!PruneOnlyZeroImpactNodes && impactValue > NodeImpactThreshold) continue;
    182182
    183         var constantNode = (ConstantTreeNode)node.Grammar.GetSymbol("Constant").CreateTreeNode();
     183        var constantNode = (NumTreeNode)node.Grammar.GetSymbol("Num").CreateTreeNode();
    184184        constantNode.Value = replacementValue;
    185185
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs

    r17180 r18093  
    115115      if (linearScalingCalculator.ErrorState != OnlineCalculatorError.None) return;
    116116
    117       ConstantTreeNode alphaTreeNode = null;
    118       ConstantTreeNode betaTreeNode = null;
     117      NumTreeNode alphaTreeNode = null;
     118      NumTreeNode betaTreeNode = null;
    119119      // check if model has a structure that can be re-used for scaling
    120120      var startNode = SymbolicExpressionTree.Root.GetSubtree(0);
    121121      var addNode = startNode.GetSubtree(0);
    122122      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);
    124124        var mulNode = addNode.Subtrees.FirstOrDefault(n => n.Symbol is Multiplication);
    125125        if (mulNode != null) {
    126           betaTreeNode = (ConstantTreeNode)mulNode.Subtrees.LastOrDefault(n => n is ConstantTreeNode);
     126          betaTreeNode = (NumTreeNode)mulNode.Subtrees.LastOrDefault(n => n is NumTreeNode);
    127127        }
    128128      }
     
    167167
    168168    private static ISymbolicExpressionTreeNode MakeConstant(double c) {
    169       var node = (ConstantTreeNode)(new Constant()).CreateTreeNode();
     169      var node = (NumTreeNode)(new Num()).CreateTreeNode();
    170170      node.Value = c;
    171171      return node;
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModelComplexityCalculator.cs

    r17180 r18093  
    8080        case OpCodes.Root: {
    8181            double complexity = CalculateComplexity(node.GetSubtree(0));
    82             var exponent = node.GetSubtree(1) as ConstantTreeNode;
     82            var exponent = node.GetSubtree(1) as NumTreeNode;
    8383            if (exponent != null) {
    8484              double expVal = exponent.Value;
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs

    r17180 r18093  
    5959        tempModelParentNode.RemoveSubtree(i);
    6060
    61         var constantNode = new ConstantTreeNode(new Constant()) { Value = repValue };
     61        var constantNode = new NumTreeNode(new Num()) { Value = repValue };
    6262        tempModelParentNode.InsertSubtree(i, constantNode);
    6363
     
    8080      IDataset dataset, IEnumerable<int> rows) {
    8181      //optimization: constant nodes return always the same value
    82       ConstantTreeNode constantNode = node as ConstantTreeNode;
     82      NumTreeNode numNode = node as NumTreeNode;
    8383      BinaryFactorVariableTreeNode binaryFactorNode = node as BinaryFactorVariableTreeNode;
    8484      FactorVariableTreeNode factorNode = node as FactorVariableTreeNode;
    85       if (constantNode != null) {
    86         yield return constantNode.Value;
     85      if (numNode != null) {
     86        yield return numNode.Value;
    8787      } else if (binaryFactorNode != null) {
    8888        // valid replacements are either all off or all on
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/Num.cs

    r18092 r18093  
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2828  [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 {
    3131    #region Properties
    3232    [Storable]
     
    100100
    101101    [StorableConstructor]
    102     private Constant(StorableConstructorFlag _) : base(_) { }
    103     private Constant(Constant original, Cloner cloner)
     102    private Num(StorableConstructorFlag _) : base(_) { }
     103    private Num(Num original, Cloner cloner)
    104104      : base(original, cloner) {
    105105      minValue = original.minValue;
     
    109109      multiplicativeManipulatorSigma = original.multiplicativeManipulatorSigma;
    110110    }
    111     public Constant()
    112       : base("Constant", "Represents a constant value.") {
     111    public Num()
     112      : base("Num", "Represents a constant value.") {
    113113      manipulatorMu = 0.0;
    114114      manipulatorSigma = 1.0;
     
    119119
    120120    public override ISymbolicExpressionTreeNode CreateTreeNode() {
    121       return new ConstantTreeNode(this);
     121      return new NumTreeNode(this);
    122122    }
    123123
    124124    public override IDeepCloneable Clone(Cloner cloner) {
    125       return new Constant(this, cloner);
     125      return new Num(this, cloner);
    126126    }
    127127  }
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/NumTreeNode.cs

    r18092 r18093  
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2828  [StorableType("247DBD04-18F2-4184-B6F5-6E283BF06FD0")]
    29   public sealed class ConstantTreeNode : SymbolicExpressionTreeTerminalNode {
    30     public new Constant Symbol {
    31       get { return (Constant)base.Symbol; }
     29  public sealed class NumTreeNode : SymbolicExpressionTreeTerminalNode {
     30    public new Num Symbol {
     31      get { return (Num)base.Symbol; }
    3232    }
    3333
     
    4040
    4141    [StorableConstructor]
    42     private ConstantTreeNode(StorableConstructorFlag _) : base(_) { }
     42    private NumTreeNode(StorableConstructorFlag _) : base(_) { }
    4343
    44     private ConstantTreeNode(ConstantTreeNode original, Cloner cloner)
     44    private NumTreeNode(NumTreeNode original, Cloner cloner)
    4545      : base(original, cloner) {
    4646      constantValue = original.constantValue;
    4747    }
    4848
    49     private ConstantTreeNode() : base() { }
    50     public ConstantTreeNode(Constant constantSymbol) : base(constantSymbol) { }
     49    private NumTreeNode() : base() { }
     50    public NumTreeNode(Num numSymbol) : base(numSymbol) { }
    5151
    5252    public override bool HasLocalParameters {
     
    7474
    7575    public override IDeepCloneable Clone(Cloner cloner) {
    76       return new ConstantTreeNode(this, cloner);
     76      return new NumTreeNode(this, cloner);
    7777    }
    7878
    7979    public override string ToString() {
    80       return constantValue.ToString("E4");
     80      return $"<{constantValue:E4}>";
     81      // return constantValue.ToString("E4");
    8182    }
    8283  }
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Transformations/SymbolicExpressionTreeBacktransformator.cs

    r17180 r18093  
    9090    private ISymbolicExpressionTreeNode CreateNodeFromWeight(ISymbolicExpressionTreeNode transformationTree, VariableTreeNode variableNode) {
    9191      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 });
    9393      multiplicationNode.AddSubtree(transformationTree);
    9494      return multiplicationNode;
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Transformations/TransformationToSymbolicTreeMapper.cs

    r17180 r18093  
    279279    }
    280280
    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 };
    283283    }
    284284
  • branches/3140_NumberSymbol/HeuristicLab.Problems.ExternalEvaluation.GP/3.5/ExternalEvaluationExpressionGrammar.cs

    r17413 r18093  
    6262      var or = new Or();
    6363      var not = new Not();
    64       var constant = new Constant();
     64      var constant = new Num();
    6565      constant.MinValue = -20;
    6666      constant.MaxValue = 20;
  • branches/3140_NumberSymbol/HeuristicLab.Problems.ExternalEvaluation.GP/3.5/ExternalEvaluationSymbolicExpressionTreeStringFormatter.cs

    r17180 r18093  
    106106          var varNode = node as VariableTreeNode;
    107107          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;
    110110          strBuilder.Append(constNode.Value.ToString("g17", CultureInfo.InvariantCulture));
    111111        } else {
Note: See TracChangeset for help on using the changeset viewer.