Debian Codegraph @

src/dr/app/treestat/statistics/B1Statistic.java

raw symbols SCIP
1 /*
2 * B1Statistic.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 * @version $Id: B1Statistic.java,v 1.2 2005/09/28 13:50:56 rambaut Exp $
34 *
35 * @author Alexei Drummond
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 * Assumes strictly bifurcating tree
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 }