Debian Codegraph @

src/dr/inference/model/LoggableStatistic.java

raw symbols SCIP
1 /*
2 * LoggableStatistic.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.inference.model;
27
28 import dr.inference.loggers.LogColumn;
29 import dr.inference.loggers.Loggable;
30 import dr.inference.loggers.NumberColumn;
31 import dr.xml.*;
32
33 /**
34 * @author Marc A. Suchard
35 */
36 public class LoggableStatistic extends Statistic.Abstract {
37
38 public static final String LOGGABLE_STATISTIC = "loggableStatistic";
39
40 private final NumberColumn[] logColumns;
41
42 public LoggableStatistic(String name, NumberColumn[] columns) {
43 super(name);
44 logColumns = columns;
45 }
46
47 public int getDimension() {
48 return logColumns.length;
49 }
50
51 public double getStatisticValue(int dim) {
52 return logColumns[dim].getDoubleValue();
53 }
54
55 public String getDimensionName(int dim) {
56 return logColumns[dim].getLabel();
57 }
58
59 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
60
61 public String getParserName() {
62 return LOGGABLE_STATISTIC;
63 }
64
65 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
66
67 String name;
68 if (xo.hasAttribute(NAME) || xo.hasAttribute(dr.xml.XMLParser.ID))
69 name = xo.getAttribute(NAME, xo.getId());
70 else
71 name = "";
72
73
74 final Loggable loggable = (Loggable) xo.getChild(Loggable.class);
75 final LogColumn[] logColumns = loggable.getColumns();
76 final NumberColumn[] numberColumns = new NumberColumn[logColumns.length];
77
78 for (int i = 0; i < logColumns.length; i++) {
79 if (logColumns[i] instanceof NumberColumn) {
80 numberColumns[i] = (NumberColumn) logColumns[i];
81 } else
82 throw new XMLParseException("Can only convert NumberColumns into Statistics");
83 }
84
85 return new LoggableStatistic(name, numberColumns);
86 }
87
88 //************************************************************************
89 // AbstractXMLObjectParser implementation
90 //************************************************************************
91
92 public String getParserDescription() {
93 return "Allows you to choose specific dimensions of a given statistic";
94 }
95
96 public Class getReturnType() {
97 return SubStatistic.class;
98 }
99
100 public XMLSyntaxRule[] getSyntaxRules() {
101 return new XMLSyntaxRule[]{
102 new ElementRule(Loggable.class),
103 };
104 }
105 };
106 }