Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/11/21 12:26:27 (3 years ago)
Author:
chaider
Message:

#3140

  • Refactored ConstantOptimization ==> ParameterOptimization
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs

    r18093 r18113  
    3636    private static readonly Sine sin = new Sine();
    3737    private static readonly Cosine cos = new Cosine();
    38     private static readonly Num Num = new Num();
     38    private static readonly Number number = new Number();
    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 NumTreeNode constantNode) {
     68      if (node is NumberTreeNode 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 NumTreeNode @const) {
    225             var constantTreeNode = (NumTreeNode)treeNodes[i];
     224          } else if (node.Data is NumberTreeNode @const) {
     225            var constantTreeNode = (NumberTreeNode)treeNodes[i];
    226226            constantTreeNode.Value = @const.Value;
    227227          }
     
    285285
    286286        var symbol = child.Data.Symbol;
    287         if (child.Data is NumTreeNode firstConst) {
     287        if (child.Data is NumberTreeNode 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 NumTreeNode otherConst) {
     291            if (sibling.Data is NumberTreeNode 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 NumTreeNode constantNode) {
     303            if (sibling.Data is NumberTreeNode 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 = Num.CreateTreeNode<NumTreeNode>();
     331          var constantTreeNode = number.CreateTreeNode<NumberTreeNode>();
    332332          constantTreeNode.Value = 1;
    333333          nodes[i] = constantTreeNode.ToHashNode();
     
    344344      var tmp = nodes;
    345345
    346       if (children.All(x => tmp[x].Data.Symbol is Num)) {
    347         var v = ((NumTreeNode)nodes[children.First()].Data).Value;
     346      if (children.All(x => tmp[x].Data.Symbol is Number)) {
     347        var v = ((NumberTreeNode)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 /= ((NumTreeNode)nodes[j].Data).Value;
     352            v /= ((NumberTreeNode)nodes[j].Data).Value;
    353353          }
    354354        }
    355         var constantTreeNode = Num.CreateTreeNode<NumTreeNode>();
     355        var constantTreeNode = number.CreateTreeNode<NumberTreeNode>();
    356356        constantTreeNode.Value = v;
    357357        nodes[i] = constantTreeNode.ToHashNode();
     
    368368        }
    369369        if (node.Arity == 0) {
    370           var constantTreeNode = Num.CreateTreeNode<NumTreeNode>();
     370          var constantTreeNode = number.CreateTreeNode<NumberTreeNode>();
    371371          constantTreeNode.Value = 1; // x / x = 1
    372372          nodes[i] = constantTreeNode.ToHashNode();
     
    383383      var childSymbol = child.Data.Symbol;
    384384
    385       if (childSymbol is Num) {
     385      if (childSymbol is Number) {
    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 Num)) {
     395      if (children.All(x => tmp[x].Data.Symbol is Number)) {
    396396        foreach (var j in children) {
    397397          nodes[j].Enabled = false;
    398398        }
    399         nodes[i] = Num.CreateTreeNode().ToHashNode();
     399        nodes[i] = number.CreateTreeNode().ToHashNode();
    400400      }
    401401    }
Note: See TracChangeset for help on using the changeset viewer.