Debian Codegraph @

src/dr/evomodel/tree/TreeLengthStatistic.java

raw symbols SCIP
1 /*
2 * TreeLengthStatistic.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.evomodel.tree;
27
28 import dr.evolution.tree.NodeRef;
29 import dr.evolution.tree.Tree;
30 import dr.inference.model.Statistic;
31
32 /**
33 * A statistic that reports the total length of all the branches in the tree
34 *
35 * @author Alexei Drummond
36 * @version $Id: RateStatistic.java,v 1.9 2005/07/11 14:06:25 rambaut Exp $
37 */
38 public class TreeLengthStatistic extends TreeStatistic {
39
40 public TreeLengthStatistic(String name, Tree tree) {
41 super(name);
42 this.tree = tree;
43 }
44
45 public void setTree(Tree tree) {
46 this.tree = tree;
47 }
48
49 public Tree getTree() {
50 return tree;
51 }
52
53 public int getDimension() {
54 return 1;
55 }
56
57 /**
58 * @return the total length of all the branches in the tree
59 */
60 public double getStatisticValue(int dim) {
61
62 double treeLength = 0.0;
63 for (int i = 0; i < tree.getNodeCount(); i++) {
64 NodeRef node = tree.getNode(i);
65
66 if (node != tree.getRoot()) {
67 NodeRef parent = tree.getParent(node);
68 treeLength += tree.getNodeHeight(parent) - tree.getNodeHeight(node);
69 }
70 }
71 return treeLength;
72 }
73
74 private Tree tree = null;
75 }