Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * CollessIndex.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 import dr.evolution.tree.TreeUtils;
31
32 /**
33 *
34 * @version $Id: CollessIndex.java,v 1.2 2005/09/28 13:50:56 rambaut Exp $
35 *
36 * @author Alexei Drummond
37 */
38 public class CollessIndex extends AbstractTreeSummaryStatistic {
39
40 public CollessIndex() { }
41
42 /**
43 * Assumes strictly bifurcating tree.
44 */
45 public double[] getSummaryStatistic(Tree tree) {
46
47 double C = 0.0;
48 int n = tree.getInternalNodeCount();
49 for (int i =0; i < n; i++) {
50
51 NodeRef node = tree.getInternalNode(i);
52
53 int r = TreeUtils.getLeafCount(tree, tree.getChild(node, 0));
54 int s = TreeUtils.getLeafCount(tree, tree.getChild(node, 1));
55
56 C += Math.abs(r-s);
57 }
58
59 n = tree.getExternalNodeCount();
60 C *= 2.0 / (n * (n - 3) + 2);
61 return new double[] { C };
62 }
63
64 public String getSummaryStatisticName() { return FACTORY.getSummaryStatisticName(); }
65 public String getSummaryStatisticDescription() { return FACTORY.getSummaryStatisticDescription(); }
66 public String getSummaryStatisticReference() { return FACTORY.getSummaryStatisticReference(); }
67 public boolean allowsPolytomies() { return FACTORY.allowsPolytomies(); }
68 public boolean allowsNonultrametricTrees() { return FACTORY.allowsNonultrametricTrees(); }
69 public boolean allowsUnrootedTrees() { return FACTORY.allowsUnrootedTrees(); }
70 public SummaryStatisticDescription.Category getCategory() { return FACTORY.getCategory(); }
71
72 public static final TreeSummaryStatistic.Factory FACTORY = new TreeSummaryStatistic.Factory() {
73
74 public TreeSummaryStatistic createStatistic() {
75 return new CollessIndex();
76 }
77
78 public String getSummaryStatisticName() {
79 return "Colless tree-imbalance";
80 }
81
82 public String getSummaryStatisticDescription() {
83 return "The normalized sum of differences of number of children " +
84 "in left and right subtrees over all internal nodes";
85 }
86
87 public String getSummaryStatisticReference() {
88 return "Colless (1982)";
89 }
90
91 public boolean allowsPolytomies() { return false; }
92
93 public boolean allowsNonultrametricTrees() { return true; }
94
95 public boolean allowsUnrootedTrees() { return false; }
96
97 public SummaryStatisticDescription.Category getCategory() { return SummaryStatisticDescription.Category.TREE_SHAPE; }
98 };
99 }