/** * Directly delegates to {@link #edgeCount()} */ public int edgeCount(EdgeType type) { return edgeCount(); }
public double getNormalizedDistance() { // empty trees => distance 1 if (t1 == null && t2 == null) return 1.0; double d = getDistance(); // count internal nodes int c = t1.edgeCount() - t1.getNumTaxa(); c += t2.edgeCount() - t2.getNumTaxa(); // add 2, one for each root. the roots are not counted when we // use edge count - taxa to find internal nodes ! c += 2; return (d / (double) c); }
public static double getNormalizedDifference(Tree tree, Tree otherTree, boolean prune) { RFDistance r = new RFDistance(tree, otherTree, prune); int d = r.getDifference(); // count internal nodes in both trees int c = tree.edgeCount() - tree.getNumTaxa(); c += otherTree.edgeCount() - otherTree.getNumTaxa(); // add 2, one for each root. the roots are not counted when we // use edge count - taxa to find internal nodes ! c += 2; return ((double) d / (double) c); }
private void buildNormTrees() { normalizedTrees = new ArrayList<Tree>(trees.size()); for (int i = 0; i < factors.length; i++) { double factor = factors[i]; Tree clone = trees.get(i).cloneTree(); if (factor != 1d) { Set<Edge> edges = new HashSet<Edge>(clone.edgeCount()); for (TreeNode node : clone.getRoot().depthFirstIterator()) { edges.addAll(node.getAllEdges()); } for (Edge edge : edges) { edge.setWeight(edge.getWeight() * factor); } } normalizedTrees.add(clone); } }
public static double[][] getNormalizedDifference(Tree[] trees, boolean prune, boolean useBCN) { double[][] d = new double[trees.length][trees.length]; // count internal nodes int[] counts = new int[trees.length]; for (int i = 0; i < counts.length; i++) { // +1 for the root counts[i] = (trees[i].edgeCount() - trees[i].getNumTaxa()) + 1; } for (int i = 0; i < d.length; i++) { for (int j = i; j < d[i].length; j++) { if (i == j) continue; double dist = 0; if (useBCN) { dist = RFDistance.getNormalizedBCNPartitionDist(trees[i], trees[j]); } else { dist = RFDistance.getDifference(trees[i], trees[j], prune); dist = dist / (counts[i] + counts[j]); } d[i][j] = dist; d[j][i] = d[i][j]; } } return d; }
public RFDistance(Tree tree, Tree compareTree, boolean prune) { if (prune && !tree.getRoot().getPartition().equals(compareTree.getRoot().getPartition())) { Tree[] ts = new Tree[]{tree, compareTree}; ts = TreeUtils.cloneAndPruneTrees(ts); if (ts != null) { this.tree = ts[0]; this.compareTree = ts[1]; } else { // pruning failed, the two trees have nothing in // common so we set the difference to max // count internal nodes int c = tree.edgeCount() - tree.getNumTaxa(); c += compareTree.edgeCount() - compareTree.getNumTaxa(); // add 2, one for each root. the roots are not counted when we // use edge count - taxa to find internal nodes ! c += 2; this.difference = c; } } else { this.tree = tree; this.compareTree = compareTree; } this.roots = new TreeNode[2]; this.roots[0] = (TreeNode) compareTree.getRoot(); this.roots[1] = (TreeNode) tree.getRoot(); this.sym = false; }