Changeset 18112


Ignore:
Timestamp:
12/09/21 14:28:17 (7 months ago)
Author:
chaider
Message:

#3140

  • Adding INumericSymbol and INumericTreeNode
  • Using the new interfaces inside of interpreters and formatters
  • Renaming Num to Number, RealConstant to Constant
  • More classes refactored
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  
    8585      };
    8686
    87     Num num = new Num();
     87    Number number = new Number();
     88    Constant constant = new Constant();
    8889    Variable variable = new Variable();
    8990    LaggedVariable laggedVariable = new LaggedVariable();
     
    161162        return tree;
    162163      } else if (tokens.Peek().Symbol == TokenSymbol.NUMBER) {
    163         NumTreeNode t = (NumTreeNode)num.CreateTreeNode();
     164        var t = (INumericTreeNode)number.CreateTreeNode();
    164165        t.Value = tokens.Dequeue().DoubleValue;
    165166        return t;
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalArithBoundsEstimator.cs

    r18093 r18112  
    127127          }
    128128        case OpCodes.Constant: {
    129             var constTreeNode = (NumTreeNode)currentInstr.dynamicNode;
     129            var constTreeNode = (ConstantTreeNode)currentInstr.dynamicNode;
    130130            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);
    131136            break;
    132137          }
     
    324329        where
    325330          !(n.Symbol is Variable) &&
    326           !(n.Symbol is Num) &&
    327           !(n.Symbol is RealConstant) &&
     331          !(n.Symbol is Number) &&
     332          !(n.Symbol is Constant) &&
    328333          !(n.Symbol is StartSymbol) &&
    329334          !(n.Symbol is Addition) &&
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalArithCompiledExpressionBoundsEstimator.cs

    r18093 r18112  
    116116        where
    117117          !(n.Symbol is Variable) &&
    118           !(n.Symbol is Num) &&
    119           !(n.Symbol is RealConstant) &&
     118          !(n.Symbol is Number) &&
     119          !(n.Symbol is Constant) &&
    120120          !(n.Symbol is StartSymbol) &&
    121121          !(n.Symbol is Addition) &&
     
    155155          }
    156156        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;
    158163            // 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)
    159164            return Expression.Constant(new Interval(v, v), typeof(Interval));
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs

    r18093 r18112  
    187187          }
    188188        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);
    191191            break;
    192192          }
    193193        case OpCodes.Constant: {
    194           var constTreeNode = (RealConstantTreeNode)currentInstr.dynamicNode;
     194          var constTreeNode = (ConstantTreeNode)currentInstr.dynamicNode;
    195195          result = new Interval(constTreeNode.Value, constTreeNode.Value);
    196196          break;
     
    329329        if (
    330330          !(n.Symbol is Variable) &&
    331           !(n.Symbol is Num) &&
     331          !(n.Symbol is Number) &&
    332332          !(n.Symbol is StartSymbol) &&
    333333          !(n.Symbol is Addition) &&
     
    351351        else if (n.Symbol is Power) {
    352352          // only integer exponents are supported
    353           var exp = n.GetSubtree(1) as NumTreeNode;
     353          var exp = n.GetSubtree(1) as NumberTreeNode;
    354354          if (exp == null || exp.Value != Math.Truncate(exp.Value)) return false;
    355355        }
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs

    r18093 r18112  
    4646    Variable = 18,
    4747    LagVariable = 19,
    48     Num = 20,
     48    Number = 20,
    4949    Arg = 21,
    5050    Power = 22,
     
    102102    public const byte Variable = (byte)OpCode.Variable;
    103103    public const byte LagVariable = (byte)OpCode.LagVariable;
    104     public const byte Number = (byte)OpCode.Num;
     104    public const byte Number = (byte)OpCode.Number;
    105105    public const byte Constant = (byte) OpCode.Constant;
    106106    public const byte Arg = (byte)OpCode.Arg;
     
    161161      { typeof(LaggedVariable), OpCodes.LagVariable },
    162162      { typeof(AutoregressiveTargetVariable),OpCodes.LagVariable},
    163       { typeof(Num), OpCodes.Number },
    164       { typeof(RealConstant), OpCodes.Constant },
     163      { typeof(Number), OpCodes.Number },
     164      { typeof(Constant), OpCodes.Constant },
    165165      { typeof(Argument), OpCodes.Arg },
    166166      { typeof(Power),OpCodes.Power},
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs

    r18093 r18112  
    158158      switch (opcode) {
    159159        case OpCodes.Constant: {
    160             var constantTreeNode = (NumTreeNode)node;
     160            var constantTreeNode = (ConstantTreeNode)node;
    161161            return Expression.Constant(constantTreeNode.Value);
     162          }
     163        case OpCodes.Number: {
     164          var numberTreeNode = (NumberTreeNode)node;
     165          return Expression.Constant(numberTreeNode.Value);
    162166          }
    163167        case OpCodes.Variable: {
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeBatchInterpreter.cs

    r18093 r18112  
    279279            cachedData[variable.VariableName] = code[i].data;
    280280          }
    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;
    283283          for (int j = 0; j < BATCHSIZE; ++j)
    284284            code[i].buf[j] = code[i].value;
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r18093 r18112  
    712712          }
    713713        case OpCodes.Number: {
    714             NumTreeNode 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);
    716716            return;
    717717          }
    718718        case OpCodes.Constant: {
    719           RealConstantTreeNode constNode = (RealConstantTreeNode) currentInstr.dynamicNode;
     719          ConstantTreeNode constNode = (ConstantTreeNode) currentInstr.dynamicNode;
    720720          il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, constNode.Value);
    721721          return;
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r18093 r18112  
    497497          }
    498498        case OpCodes.Constant: {
    499             var constTreeNode = (NumTreeNode)currentInstr.dynamicNode;
     499            var constTreeNode = (ConstantTreeNode)currentInstr.dynamicNode;
    500500            return constTreeNode.Value;
    501501          }
    502502        case OpCodes.Number: {
    503           var numberTreeNode = (RealConstantTreeNode) currentInstr.dynamicNode;
     503          var numberTreeNode = (NumberTreeNode) currentInstr.dynamicNode;
    504504          return numberTreeNode.Value;
    505505        }
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs

    r18093 r18112  
    417417        switch (instr.opCode) {
    418418          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;
    421421              instr.skip = true; // the value is already set so this instruction should be skipped in the evaluation phase
    422422            }
    423423            break;
    424424          case OpCodes.Constant: {
    425             var constTreeNode = (RealConstantTreeNode)instr.dynamicNode;
     425            var constTreeNode = (ConstantTreeNode)instr.dynamicNode;
    426426            instr.value = constTreeNode.Value;
    427427            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  
    8282          code[i].weight = variable.Weight;
    8383          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;
    8686        }
    8787
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionPruningOperator.cs

    r18093 r18112  
    172172      for (int i = 0; i < nodes.Count; ++i) {
    173173        var node = nodes[i];
    174         if (node is NumTreeNode) continue;
     174        if (node is INumericTreeNode) continue;
    175175
    176176        double impactValue, replacementValue;
     
    181181        if (!PruneOnlyZeroImpactNodes && impactValue > NodeImpactThreshold) continue;
    182182
    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;
    185185
    186186        var length = node.GetLength();
    187         ReplaceWithConstant(node, constantNode);
     187        ReplaceWithConstant(node, numberNode);
    188188        i += length - 1; // skip subtrees under the node that was folded
    189189
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModelComplexityCalculator.cs

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

    r18093 r18112  
    5959        tempModelParentNode.RemoveSubtree(i);
    6060
    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);
    6363
    6464        newQualityForImpactsCalculation = CalculateQualityForImpacts(tempModel, problemData, rows);
     
    8080      IDataset dataset, IEnumerable<int> rows) {
    8181      //optimization: constant nodes return always the same value
    82       NumTreeNode numNode = node as NumTreeNode;
     82      NumberTreeNode numberNode = node as NumberTreeNode;
    8383      BinaryFactorVariableTreeNode binaryFactorNode = node as BinaryFactorVariableTreeNode;
    8484      FactorVariableTreeNode factorNode = node as FactorVariableTreeNode;
    85       if (numNode != null) {
    86         yield return numNode.Value;
     85      if (numberNode != null) {
     86        yield return numberNode.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/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
    622using HEAL.Attic;
    723using HeuristicLab.Common;
     
    1127namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    1228  [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{
    3831    private const int minimumArity = 0;
    3932    private const int maximumArity = 0;
    4033
    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);
    4643    }
    4744
    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.") {}
    6346
    6447    public override ISymbolicExpressionTreeNode CreateTreeNode() {
    65       return new RealConstantTreeNode(this);
     48      return new ConstantTreeNode(this);
    6649    }
    6750  }
  • 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
    622using HEAL.Attic;
    723using HeuristicLab.Common;
     
    1026namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    1127  [StorableType("F91000E6-B041-4648-A9E8-595228F957FA")]
    12   public sealed class RealConstantTreeNode : SymbolicExpressionTreeTerminalNode{
     28  public sealed class ConstantTreeNode : SymbolicExpressionTreeTerminalNode, INumericTreeNode{
    1329
    14     public new RealConstant Symbol {
    15       get { return (RealConstant) base.Symbol; }
    16     }
     30    public new Constant Symbol => (Constant) base.Symbol;
    1731
    1832    public double Value { get; set; }
    1933
    2034    [StorableConstructor]
    21     private RealConstantTreeNode(StorableConstructorFlag _) : base(_) { }
     35    private ConstantTreeNode(StorableConstructorFlag _) : base(_) { }
    2236
    23     private RealConstantTreeNode(RealConstantTreeNode original, Cloner cloner)
     37    private ConstantTreeNode(ConstantTreeNode original, Cloner cloner)
    2438      : base(original, cloner) {
    2539      Value = original.Value;
    2640    }
    2741
    28     private RealConstantTreeNode() : base() { }
    29     public RealConstantTreeNode(RealConstant realConstantSymbol) : base(realConstantSymbol) { }
     42    private ConstantTreeNode() : base() { }
     43    public ConstantTreeNode(Constant constantSymbol) : base(constantSymbol) { }
    3044
    3145    public override IDeepCloneable Clone(Cloner cloner) {
    32       return new RealConstantTreeNode(this, cloner);
     46      return new ConstantTreeNode(this, cloner);
    3347    }
    3448
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/Number.cs

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

    r18111 r18112  
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2828  [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;
    3241    }
    3342
    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) { }
    4045
    41     [StorableConstructor]
    42     private NumTreeNode(StorableConstructorFlag _) : base(_) { }
     46    public override bool HasLocalParameters => true;
    4347
    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     }
    5748    public override void ResetLocalParameters(IRandom random) {
    5849      base.ResetLocalParameters(random);
     
    6556      // 50% additive & 50% multiplicative
    6657      if (random.NextDouble() < 0.5) {
    67         double x = NormalDistributedRandom.NextDouble(random, Symbol.ManipulatorMu, Symbol.ManipulatorSigma);
     58        var x = NormalDistributedRandom.NextDouble(random, Symbol.ManipulatorMu, Symbol.ManipulatorSigma);
    6859        Value = Value + x * shakingFactor;
    6960      } else {
    70         double x = NormalDistributedRandom.NextDouble(random, 1.0, Symbol.MultiplicativeManipulatorSigma);
     61        var x = NormalDistributedRandom.NextDouble(random, 1.0, Symbol.MultiplicativeManipulatorSigma);
    7162        Value = Value * x;
    7263      }
     
    7465
    7566    public override IDeepCloneable Clone(Cloner cloner) {
    76       return new NumTreeNode(this, cloner);
     67      return new NumberTreeNode(this, cloner);
    7768    }
    7869
    7970    public override string ToString() {
    80       return $"<{constantValue:E4}>";
    81       // return constantValue.ToString("E4");
     71      return $"{Value:E4}";
    8272    }
    8373  }
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Transformations/SymbolicExpressionTreeBacktransformator.cs

    r18093 r18112  
    9090    private ISymbolicExpressionTreeNode CreateNodeFromWeight(ISymbolicExpressionTreeNode transformationTree, VariableTreeNode variableNode) {
    9191      var multiplicationNode = new SymbolicExpressionTreeNode(new Multiplication());
    92       multiplicationNode.AddSubtree(new NumTreeNode(new Num()) { Value = variableNode.Weight });
     92      multiplicationNode.AddSubtree(new NumberTreeNode(new Number()) { Value = variableNode.Weight });
    9393      multiplicationNode.AddSubtree(transformationTree);
    9494      return multiplicationNode;
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Transformations/TransformationToSymbolicTreeMapper.cs

    r18093 r18112  
    279279    }
    280280
    281     private NumTreeNode CreateConstantTreeNode(string description, double value) {
    282       return new NumTreeNode(new Num()) { Value = value };
     281    private NumberTreeNode CreateConstantTreeNode(string description, double value) {
     282      return new NumberTreeNode(new Number()) { Value = value };
    283283    }
    284284
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeBottomUpSimilarityCalculator.cs

    r17180 r18112  
    211211        return node.Symbol.Name;
    212212
    213       if (node is ConstantTreeNode constant)
     213      if (node is INumericTreeNode constant)
    214214        return MatchConstantValues ? constant.Value.ToString(CultureInfo.InvariantCulture) : constant.Symbol.Name;
    215215
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeNodeComparer.cs

    r17180 r18112  
    5252
    5353      // 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;
    5656
    5757      if (ca != null && cb != null)
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeNodeEqualityComparer.cs

    r17180 r18112  
    8686        return (!MatchVariableNames || va.VariableName.Equals(vb.VariableName)) && (!MatchVariableWeights || va.Weight.Equals(vb.Weight));
    8787      }
    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;
    9191        if (cb == null) return false;
    9292        return (!MatchConstantValues || ca.Value.Equals(cb.Value));
  • branches/3140_NumberSymbol/HeuristicLab.Problems.ExternalEvaluation.GP/3.5/ExternalEvaluationExpressionGrammar.cs

    r18093 r18112  
    6262      var or = new Or();
    6363      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();
    6768      variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
    6869
    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 };
    7071      var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, not };
    7172      var binaryFunctionSymbols = new List<Symbol>() { gt, lt };
     
    8687
    8788      SetSubtreeCount(@if, 3, 3);
    88       SetSubtreeCount(constant, 0, 0);
     89      SetSubtreeCount(number, 0, 0);
     90      SetSubtreeCount(constant,0, 0);
    8991      SetSubtreeCount(variableSymbol, 0, 0);
    9092
  • branches/3140_NumberSymbol/HeuristicLab.Problems.ExternalEvaluation.GP/3.5/ExternalEvaluationSymbolicExpressionTreeStringFormatter.cs

    r18093 r18112  
    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 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));
    111111        } else {
    112112          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  
    4242  ///   integer vector and rule may be one value from a "content" integer vector.
    4343  ///   
    44   ///   Order:   NT   = nont % Num. NT      ... determines, which non-terminal to expand next
    45   ///   Content: Rule = rule % Num. Rules   ... rule determination as with standard GE mappers
     44  ///   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
    4646  ///
    4747  /// Four mutation and crossover strategies possible:
     
    155155          current.AddSubtree(GetRandomTerminalNode(current, grammar, random));
    156156        } else {
    157           // Order:   NT   = nont % Num. NT
     157          // Order:   NT   = nont % Number. NT
    158158          int nt = NontVector[genotypeIndex] % nonTerminals.Count;
    159159          ISymbolicExpressionTreeNode current = nonTerminals[nt];
    160160          nonTerminals.RemoveAt(nt);
    161161
    162           // Content: Rule = rule % Num. Rules
     162          // Content: Rule = rule % Number. Rules
    163163          ISymbolicExpressionTreeNode newNode = GetNewChildNode(current, genotype, grammar, genotypeIndex, random);
    164164          int arity = SampleArity(random, newNode, grammar);
  • branches/3140_NumberSymbol/HeuristicLab.Problems.GrammaticalEvolution/3.4/SymbolicRegression/GESymbolicExpressionGrammar.cs

    r17413 r18112  
    8181          var constVal = rand.NextDouble() * 20.0 - 10.0;
    8282          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;
    8883        } 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.
    8984        constants.Add(constant);
Note: See TracChangeset for help on using the changeset viewer.