当前位置: 首页>>代码示例>>C#>>正文


C# ISymbolicExpressionTreeNode类代码示例

本文整理汇总了C#中ISymbolicExpressionTreeNode的典型用法代码示例。如果您正苦于以下问题:C# ISymbolicExpressionTreeNode类的具体用法?C# ISymbolicExpressionTreeNode怎么用?C# ISymbolicExpressionTreeNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ISymbolicExpressionTreeNode类属于命名空间,在下文中一共展示了ISymbolicExpressionTreeNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CalculateImpactAndReplacementValues

    public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node,
      IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation,
      double qualityForImpactsCalculation = Double.NaN) {
      var classificationModel = (ISymbolicClassificationModel)model;
      var classificationProblemData = (IClassificationProblemData)problemData;

      if (double.IsNaN(qualityForImpactsCalculation))
        qualityForImpactsCalculation = CalculateQualityForImpacts(classificationModel, classificationProblemData, rows);

      replacementValue = CalculateReplacementValue(classificationModel, node, classificationProblemData, rows);
      var constantNode = new ConstantTreeNode(new Constant()) { Value = replacementValue };

      var cloner = new Cloner();
      var tempModel = cloner.Clone(classificationModel);
      var tempModelNode = (ISymbolicExpressionTreeNode)cloner.GetClone(node);

      var tempModelParentNode = tempModelNode.Parent;
      int i = tempModelParentNode.IndexOfSubtree(tempModelNode);
      tempModelParentNode.RemoveSubtree(i);
      tempModelParentNode.InsertSubtree(i, constantNode);

      OnlineCalculatorError errorState;
      var dataset = classificationProblemData.Dataset;
      var targetClassValues = dataset.GetDoubleValues(classificationProblemData.TargetVariable, rows);
      var estimatedClassValues = tempModel.GetEstimatedClassValues(dataset, rows);
      newQualityForImpactsCalculation = OnlineAccuracyCalculator.Calculate(targetClassValues, estimatedClassValues, out errorState);
      if (errorState != OnlineCalculatorError.None) newQualityForImpactsCalculation = 0.0;

      impactValue = qualityForImpactsCalculation - newQualityForImpactsCalculation;
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:30,代码来源:SymbolicClassificationSolutionImpactValuesCalculator.cs

示例2: Create

    public static void Create(IRandom random, ISymbolicExpressionTreeNode seedNode, int maxDepth) {
      // make sure it is possible to create a trees smaller than maxDepth
      if (seedNode.Grammar.GetMinimumExpressionDepth(seedNode.Symbol) > maxDepth)
        throw new ArgumentException("Cannot create trees of depth " + maxDepth + " or smaller because of grammar constraints.", "maxDepth");

      var arity = SampleArity(random, seedNode);
      // throw an exception if the seedNode happens to be a terminal, since in this case we cannot grow a tree
      if (arity <= 0)
        throw new ArgumentException("Cannot grow tree. Seed node shouldn't have arity zero.");

      var allowedSymbols = seedNode.Grammar.AllowedSymbols.Where(s => s.InitialFrequency > 0.0).ToList();

      for (var i = 0; i < arity; i++) {
        var possibleSymbols = allowedSymbols.Where(s => seedNode.Grammar.IsAllowedChildSymbol(seedNode.Symbol, s, i)).ToList();
        var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList();

#pragma warning disable 612, 618
        var selectedSymbol = possibleSymbols.SelectRandom(weights, random);
#pragma warning restore 612, 618

        var tree = selectedSymbol.CreateTreeNode();
        if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
        seedNode.AddSubtree(tree);
      }

      // Only iterate over the non-terminal nodes (those which have arity > 0)
      // Start from depth 2 since the first two levels are formed by the rootNode and the seedNode
      foreach (var subTree in seedNode.Subtrees)
        if (subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0)
          RecursiveCreate(random, subTree, 2, maxDepth);
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:31,代码来源:GrowTreeCreator.cs

示例3: RenderNode

 public static void RenderNode(TextWriter writer, ISymbolicExpressionTreeNode node, string prefix) {
   string label = node.ToString();
   writer.Write(label);
   if (node.SubtreeCount > 0) {
     var padding = prefix + new string(' ', label.Length);
     for (int i = 0; i != node.SubtreeCount; ++i) {
       char connector, extender = ' ';
       if (i == 0) {
         if (node.SubtreeCount > 1) {
           connector = RenderChars.JunctionDown;
           extender = RenderChars.VerticalLine;
         } else {
           connector = RenderChars.HorizontalLine;
           extender = ' ';
         }
       } else {
         writer.Write(padding);
         if (i == node.SubtreeCount - 1) {
           connector = RenderChars.CornerRight;
           extender = ' ';
         } else {
           connector = RenderChars.JunctionRight;
           extender = RenderChars.VerticalLine;
         }
       }
       writer.Write(string.Concat(connector, RenderChars.HorizontalLine));
       var newPrefix = string.Concat(padding, extender, ' ');
       RenderNode(writer, node.GetSubtree(i), newPrefix);
     }
   } else
     writer.WriteLine();
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:32,代码来源:SymbolicExpressionTreeHierarchicalFormatter.cs

示例4: MapBreathFirstIteratively

    /// <summary>
    /// Genotype-to-Phenotype mapper (iterative breath-first approach, by using a queue -> FIFO).
    /// </summary>
    /// <param name="startNode">first node of the tree with arity 1</param>
    /// <param name="genotype">integer vector, which should be mapped to a tree</param>
    /// <param name="grammar">grammar to determine the allowed child symbols for each node</param>
    /// <param name="maxSubtreeCount">maximum allowed subtrees (= number of used genomes)</param>
    /// <param name="random">random number generator</param>
    private void MapBreathFirstIteratively(ISymbolicExpressionTreeNode startNode,
                                          IntegerVector genotype,
                                          ISymbolicExpressionGrammar grammar,
                                          int maxSubtreeCount, IRandom random) {

      Queue<Tuple<ISymbolicExpressionTreeNode, int>> queue
        = new Queue<Tuple<ISymbolicExpressionTreeNode, int>>(); // tuples of <node, arity>

      int genotypeIndex = 0;
      queue.Enqueue(new Tuple<ISymbolicExpressionTreeNode, int>(startNode, 1));

      while (queue.Count > 0) {

        Tuple<ISymbolicExpressionTreeNode, int> current = queue.Dequeue();

        // foreach subtree of the current node, create a new node and enqueue it, if it is no terminal node
        for (int i = 0; i < current.Item2; ++i) {

          if (genotypeIndex >= maxSubtreeCount) {
            // if all genomes were used, only add terminal nodes to the remaining subtrees
            current.Item1.AddSubtree(GetRandomTerminalNode(current.Item1, grammar, random));
          } else {
            var newNode = GetNewChildNode(current.Item1, genotype, grammar, genotypeIndex, random);
            int arity = SampleArity(random, newNode, grammar);

            current.Item1.AddSubtree(newNode);
            genotypeIndex++;
            if (arity > 0) {
              // new node has subtrees so enqueue the node 
              queue.Enqueue(new Tuple<ISymbolicExpressionTreeNode, int>(newNode, arity));
            }
          }
        }
      }
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:43,代码来源:BreathFirstMapper.cs

示例5: CompareNodes

    public static int CompareNodes(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {
      var ta = a as SymbolicExpressionTreeTerminalNode;
      var tb = b as SymbolicExpressionTreeTerminalNode;

      if (ta == null)
        return tb == null ? String.CompareOrdinal(a.Symbol.Name, b.Symbol.Name) : -1;

      if (tb == null)
        return 1;

      // at this point we know a and b are both terminals
      var va = a as VariableTreeNode;
      var vb = b as VariableTreeNode;

      if (va != null)
        return vb == null ? -1 : CompareVariables(va, vb);

      if (vb != null)
        return 1;

      // at this point we know a and b are not variables
      var ca = a as ConstantTreeNode;
      var cb = b as ConstantTreeNode;

      if (ca != null && cb != null)
        return ca.Value.CompareTo(cb.Value);

      // for other unknown terminal types, compare strings
      return string.CompareOrdinal(a.ToString(), b.ToString());
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:30,代码来源:SymbolicExpressionTreeNodeComparer.cs

示例6: VariableNodeEditDialog

    public VariableNodeEditDialog(ISymbolicExpressionTreeNode node) {
      InitializeComponent();
      oldValueTextBox.TabStop = false; // cannot receive focus using tab key

      NewNode = (VariableTreeNode)node; // will throw an invalid cast exception if node is not of the correct type
      InitializeFields();
    }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:7,代码来源:SymbolicExpressionTreeVariableNodeEditDialog.cs

示例7: FormatRecursively

    private string FormatRecursively(ISymbolicExpressionTreeNode node, int indentLength, ref int nodeId) {
      // save id of current node
      int currentNodeId = nodeId;
      // increment id for next node
      nodeId++;

      StringBuilder strBuilder = new StringBuilder();
      if (Indent) strBuilder.Append(' ', indentLength);

      // get label for node and map if necessary
      string nodeLabel = node.ToString();
      if (symbolNameMap.ContainsKey(nodeLabel)) {
        nodeLabel = symbolNameMap[nodeLabel];
      }

      strBuilder.Append("node" + currentNodeId + "[label=\"" + nodeLabel + "\"");
      // leaf nodes should have box shape
      if (node.SubtreeCount == 0) {
        strBuilder.AppendLine(", shape=\"box\"];");
      } else {
        strBuilder.AppendLine("];");
      }

      // internal nodes or leaf nodes?
      foreach (ISymbolicExpressionTreeNode subTree in node.Subtrees) {
        // add an edge 
        if (Indent) strBuilder.Append(' ', indentLength);
        strBuilder.AppendLine("node" + currentNodeId + " -- node" + nodeId + ";");
        // format the whole subtree
        strBuilder.Append(FormatRecursively(subTree, indentLength + 2, ref nodeId));
      }

      return strBuilder.ToString();
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:34,代码来源:SymbolicExpressionTreeGraphvizFormatter.cs

示例8: FormatRecursively

 private void FormatRecursively(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
   // TODO: adapt to interpreter semantics. The HL interpreter also allows Boolean operations on reals
   if (node.Subtrees.Any()) {
     if (node.Symbol is Addition) {
       FormatOperator(node, "+", strBuilder);
     } else if (node.Symbol is And) {
       FormatOperator(node, "&&", strBuilder);
     } else if (node.Symbol is Average) {
       FormatFunction(node, "Average", strBuilder);
     } else if (node.Symbol is Cosine) {
       FormatFunction(node, "Math.Cos", strBuilder);
     } else if (node.Symbol is Division) {
       FormatDivision(node, strBuilder);
     } else if (node.Symbol is Exponential) {
       FormatFunction(node, "Math.Exp", strBuilder);
     } else if (node.Symbol is GreaterThan) {
       FormatOperator(node, ">", strBuilder);
     } else if (node.Symbol is IfThenElse) {
       FormatFunction(node, "EvaluateIf", strBuilder);
     } else if (node.Symbol is LessThan) {
       FormatOperator(node, "<", strBuilder);
     } else if (node.Symbol is Logarithm) {
       FormatFunction(node, "Math.Log", strBuilder);
     } else if (node.Symbol is Multiplication) {
       FormatOperator(node, "*", strBuilder);
     } else if (node.Symbol is Not) {
       FormatOperator(node, "!", strBuilder);
     } else if (node.Symbol is Or) {
       FormatOperator(node, "||", strBuilder);
     } else if (node.Symbol is Xor) {
       FormatOperator(node, "^", strBuilder);
     } else if (node.Symbol is Sine) {
       FormatFunction(node, "Math.Sin", strBuilder);
     } else if (node.Symbol is Subtraction) {
       FormatSubtraction(node, strBuilder);
     } else if (node.Symbol is Tangent) {
       FormatFunction(node, "Math.Tan", strBuilder);
     } else if (node.Symbol is Square) {
       FormatSquare(node, strBuilder);
     } else if (node.Symbol is SquareRoot) {
       FormatFunction(node, "Math.Sqrt", strBuilder);
     } else if (node.Symbol is Power) {
       FormatFunction(node, "Math.Pow", strBuilder);
     } else if (node.Symbol is Root) {
       FormatRoot(node, strBuilder);
     } else {
       throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for C# symbolic expression tree formatter.");
     }
   } else {
     if (node is VariableTreeNode) {
       var varNode = node as VariableTreeNode;
       strBuilder.AppendFormat("{0} * {1}", varNode.VariableName, varNode.Weight.ToString("g17", CultureInfo.InvariantCulture));
     } else if (node is ConstantTreeNode) {
       var constNode = node as ConstantTreeNode;
       strBuilder.Append(constNode.Value.ToString("g17", CultureInfo.InvariantCulture));
     } else {
       throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for C# symbolic expression tree formatter.");
     }
   }
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:60,代码来源:SymbolicDataAnalysisExpressionCSharpFormatter.cs

示例9: FormatRecursively

 private string FormatRecursively(ISymbolicExpressionTreeNode node, int indentLength) {
   StringBuilder strBuilder = new StringBuilder();
   if (Indent) strBuilder.Append(' ', indentLength);
   if (node.Subtrees.Count() > 0) { // internal node
     strBuilder.Append("(");
     if (node.Symbol is Addition) {
       strBuilder.AppendLine("+");
     } else if (node.Symbol is And) {
       strBuilder.AppendLine("&&");
     } else if (node.Symbol is Average) {
       strBuilder.AppendLine("avg");
     } else if (node.Symbol is Cosine) {
       strBuilder.AppendLine("cos");
     } else if (node.Symbol is Division) {
       strBuilder.AppendLine("/");
     } else if (node.Symbol is Exponential) {
       strBuilder.AppendLine("exp");
     } else if (node.Symbol is GreaterThan) {
       strBuilder.AppendLine(">");
     } else if (node.Symbol is IfThenElse) {
       strBuilder.AppendLine("if");
     } else if (node.Symbol is LessThan) {
       strBuilder.AppendLine("<");
     } else if (node.Symbol is Logarithm) {
       strBuilder.AppendLine("ln");
     } else if (node.Symbol is Multiplication) {
       strBuilder.AppendLine("*");
     } else if (node.Symbol is Not) {
       strBuilder.AppendLine("!");
     } else if (node.Symbol is Or) {
       strBuilder.AppendLine("||");
     } else if (node.Symbol is Sine) {
       strBuilder.AppendLine("sin");
     } else if (node.Symbol is Subtraction) {
       strBuilder.AppendLine("-");
     } else if (node.Symbol is Tangent) {
       strBuilder.AppendLine("tan");
     } else {
       throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for external evaluation.");
     }
     // each subtree expression on a new line
     // and closing ')' also on new line
     foreach (var subtree in node.Subtrees) {
       strBuilder.AppendLine(FormatRecursively(subtree, indentLength + 2));
     }
     if (Indent) strBuilder.Append(' ', indentLength);
     strBuilder.Append(")");
   } else {
     if (node is VariableTreeNode) {
       var varNode = node as VariableTreeNode;
       strBuilder.AppendFormat("(* {0} {1})", varNode.VariableName, varNode.Weight.ToString("g17", CultureInfo.InvariantCulture));
     } else if (node is ConstantTreeNode) {
       var constNode = node as ConstantTreeNode;
       strBuilder.Append(constNode.Value.ToString("g17", CultureInfo.InvariantCulture));
     } else {
       throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for external evaluation.");
     }
   }
   return strBuilder.ToString();
 }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:60,代码来源:ExternalEvaluationSymbolicExpressionTreeStringFormatter.cs

示例10: FormatRecursively

 private static string FormatRecursively(ISymbolicExpressionTreeNode node) {
   StringBuilder strBuilder = new StringBuilder();
   if (node.Subtrees.Count() > 0) {
     // node
     var symbol = node.Symbol as CFGSymbol;
     if (symbol != null) {
       var partsEnumerator = symbol.GetTerminalParts().GetEnumerator();
       var subtreeEnumerator = node.Subtrees.GetEnumerator();
       while (partsEnumerator.MoveNext() && subtreeEnumerator.MoveNext()) {
         strBuilder.Append(partsEnumerator.Current);
         strBuilder.Append(FormatRecursively(subtreeEnumerator.Current));
       }
       strBuilder.Append(partsEnumerator.Current);
     } else {
       // ProgramRoot or StartSymbol
       foreach (var subtree in node.Subtrees) {
         strBuilder.Append(FormatRecursively(subtree));
       }
     }
   } else {
     // leaf
     var symbol = node.Symbol as CFGSymbol;
     if (symbol != null) {
       var parts = symbol.GetTerminalParts();
       strBuilder.Append(parts.First());
     }
   }
   return strBuilder.ToString();
 }
开发者ID:t-h-e,项目名称:HeuristicLab.CFGGP,代码行数:29,代码来源:CFGSymbolicExpressionTreeStringFormatter.cs

示例11: FindMatches

    public static IEnumerable<ISymbolicExpressionTreeNode> FindMatches(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode subtree, SymbolicExpressionTreeNodeEqualityComparer comp) {
      var fragmentLength = subtree.GetLength();
      // below, we use ">=" for Match(n, subtree, comp) >= fragmentLength because in case of relaxed conditions, 
      // we can have multiple matches of the same node

      return root.IterateNodesBreadth().Where(n => n.GetLength() >= fragmentLength && Match(n, subtree, comp) == fragmentLength);
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:7,代码来源:SymbolicExpressionTreeMatching.cs

示例12: FormatOnlyExpression

 public string FormatOnlyExpression(ISymbolicExpressionTreeNode expressionNode) {
   var stringBuilder = new StringBuilder();
   stringBuilder.AppendLine("  for " + CurrentIndexVariable + " = 1:1:rows");
   stringBuilder.AppendLine("    estimated(" + CurrentIndexVariable + ") = " + FormatRecursively(expressionNode.GetSubtree(0)) + ";");
   stringBuilder.AppendLine("  end;");
   return stringBuilder.ToString();
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:7,代码来源:SymbolicDataAnalysisExpressionMATLABFormatter.cs

示例13: SortSubtrees

 public void SortSubtrees(ISymbolicExpressionTreeNode node) {
   if (node.SubtreeCount == 0) return;
   var subtrees = node.Subtrees as List<ISymbolicExpressionTreeNode> ?? node.Subtrees.ToList();
   if (IsSymmetric(node.Symbol)) {
     var comparer = new SymbolicExpressionTreeNodeComparer();
     subtrees.Sort(comparer);
   }
   foreach (var s in subtrees)
     SortSubtrees(s);
 }
开发者ID:thunder176,项目名称:HeuristicLab,代码行数:10,代码来源:SymbolicExpressionTreeCanonicalSorter.cs

示例14: SwapVariableWithTree

    private void SwapVariableWithTree(VariableTreeNode variableNode, ISymbolicExpressionTreeNode treeNode) {
      var parent = variableNode.Parent;
      int index = parent.IndexOfSubtree(variableNode);
      parent.RemoveSubtree(index);

      if (!variableNode.Weight.IsAlmost(1.0))
        treeNode = CreateNodeFromWeight(treeNode, variableNode);

      parent.InsertSubtree(index, treeNode);
    }
开发者ID:t-h-e,项目名称:HeuristicLab,代码行数:10,代码来源:SymbolicExpressionTreeBacktransformator.cs

示例15: FormatRecursively

 private static string FormatRecursively(ISymbolicExpressionTreeNode node) {
   StringBuilder strBuilder = new StringBuilder();
   if (node.Subtrees.Count() > 0) {
     // node
     foreach (var subtree in node.Subtrees) {
       strBuilder.Append(FormatRecursively(subtree));
     }
   } else {
     // leaf
     strBuilder.Append(node.ToString());
   }
   return strBuilder.ToString();
 }
开发者ID:t-h-e,项目名称:HeuristicLab.CFGGP,代码行数:13,代码来源:SymbolicExpressionTreeTerminalNodeStringFormatter.cs


注:本文中的ISymbolicExpressionTreeNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。