Debian Codegraph @

src/dr/evomodel/arg/ARGTotalLengthStatistic.java

raw symbols SCIP
1 /*
2 * ARGTotalLengthStatistic.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.arg;
27
28 import dr.evomodel.arg.ARGModel.Node;
29 import dr.inference.model.Statistic;
30 import dr.xml.*;
31
32 public class ARGTotalLengthStatistic extends Statistic.Abstract{
33
34 public static final String ARG_TOTAL_LENGTH = "argTotalLengthStatistic";
35 private ARGModel arg;
36
37 public ARGTotalLengthStatistic(String id, ARGModel arg){
38 super(id);
39
40 this.arg = arg;
41 }
42
43 public int getDimension() {
44 return 1;
45 }
46
47 public double getStatisticValue(int dim) {
48
49 double length = 0;
50
51 for(int i = 0; i < arg.getNodeCount(); i++){
52 Node x = (Node) arg.getNode(i);
53
54 if(!x.isRoot()){
55 length += x.getParent(ARGModel.LEFT).getHeight() - x.getHeight();
56 if(x.isReassortment()){
57 length += x.getParent(ARGModel.RIGHT).getHeight() - x.getHeight();
58 }
59 }
60 }
61
62 return length;
63 }
64
65 public static XMLObjectParser PARSER = new AbstractXMLObjectParser(){
66
67 @Override
68 public String getParserDescription() {
69 // TODO Auto-generated method stub
70 return null;
71 }
72
73 @Override
74 public Class getReturnType() {
75
76 return ARGTotalLengthStatistic.class;
77 }
78
79 @Override
80 public XMLSyntaxRule[] getSyntaxRules() {
81 // TODO Auto-generated method stub
82 return null;
83 }
84
85 @Override
86 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
87 String id = xo.getId();
88
89 ARGModel a = (ARGModel) xo.getChild(ARGModel.class);
90
91 return new ARGTotalLengthStatistic(id,a);
92 }
93
94 public String getParserName() {
95 // TODO Auto-generated method stub
96 return ARG_TOTAL_LENGTH;
97 }
98
99 };
100
101 }