| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.app.treestat.statistics; |
| 27 |
|
| 28 |
import dr.evolution.tree.NodeRef; |
| 29 |
import dr.evolution.tree.Tree; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class B1Statistic extends AbstractTreeSummaryStatistic { |
| 38 |
|
| 39 |
private B1Statistic() { } |
| 40 |
|
| 41 |
public double[] getSummaryStatistic(Tree tree) { |
| 42 |
|
| 43 |
double B1 = 0.0; |
| 44 |
int n = tree.getInternalNodeCount(); |
| 45 |
for (int i =0; i < n; i++) { |
| 46 |
|
| 47 |
NodeRef node = tree.getInternalNode(i); |
| 48 |
if (!tree.isRoot(node)) { |
| 49 |
B1 += 1.0/getMi(tree, node); |
| 50 |
} |
| 51 |
} |
| 52 |
return new double[] { B1 }; |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
private static int getMi(Tree tree, NodeRef node) { |
| 60 |
int childCount = tree.getChildCount(node); |
| 61 |
if (childCount == 0) return 0; |
| 62 |
int Mi = 0; |
| 63 |
for (int i =0; i < childCount; i++) { |
| 64 |
int mi = getMi(tree, tree.getChild(node, i)); |
| 65 |
if (mi > Mi) Mi = mi; |
| 66 |
} |
| 67 |
Mi += 1; |
| 68 |
return Mi; |
| 69 |
} |
| 70 |
|
| 71 |
public String getSummaryStatisticName() { return FACTORY.getSummaryStatisticName(); } |
| 72 |
public String getSummaryStatisticDescription() { return FACTORY.getSummaryStatisticDescription(); } |
| 73 |
public String getSummaryStatisticReference() { return FACTORY.getSummaryStatisticReference(); } |
| 74 |
public boolean allowsPolytomies() { return FACTORY.allowsPolytomies(); } |
| 75 |
public boolean allowsNonultrametricTrees() { return FACTORY.allowsNonultrametricTrees(); } |
| 76 |
public boolean allowsUnrootedTrees() { return FACTORY.allowsUnrootedTrees(); } |
| 77 |
public SummaryStatisticDescription.Category getCategory() { return FACTORY.getCategory(); } |
| 78 |
|
| 79 |
public static final TreeSummaryStatistic.Factory FACTORY = new TreeSummaryStatistic.Factory() { |
| 80 |
|
| 81 |
public TreeSummaryStatistic createStatistic() { |
| 82 |
return new B1Statistic(); |
| 83 |
} |
| 84 |
|
| 85 |
public String getSummaryStatisticName() { |
| 86 |
return "B1"; |
| 87 |
} |
| 88 |
|
| 89 |
public String getSummaryStatisticDescription() { |
| 90 |
return "The sum of the reciprocals of the maximum number of nodes between " + |
| 91 |
"each interior node and a tip (Mi) for all internal nodes except the " + |
| 92 |
"root."; |
| 93 |
} |
| 94 |
|
| 95 |
public String getSummaryStatisticReference() { |
| 96 |
return "see Kirkpatrick & Slatkin (1992)"; |
| 97 |
} |
| 98 |
|
| 99 |
public boolean allowsPolytomies() { return false; } |
| 100 |
|
| 101 |
public boolean allowsNonultrametricTrees() { return true; } |
| 102 |
|
| 103 |
public boolean allowsUnrootedTrees() { return false; } |
| 104 |
|
| 105 |
public SummaryStatisticDescription.Category getCategory() { return SummaryStatisticDescription.Category.TREE_SHAPE; } |
| 106 |
}; |
| 107 |
} |