Debian Codegraph @

src/dr/inference/trace/LogFileTraceExporter.java

raw symbols SCIP
1 /*
2 * LogFileTraceExporter.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.trace;
27
28 import dr.util.TabularData;
29
30 import java.io.File;
31 import java.io.IOException;
32
33 /**
34 * Export trace analysis data such as mean,median,HPD and ESS of trace variables.
35 *
36 * @author Joseph Heled
37 * Date: 25/10/2007
38 */
39 public class LogFileTraceExporter extends TabularData {
40 private final LogFileTraces analysis;
41 private final String[] rows = {"mean", "median", "hpdLower", "hpdUpper", "ESS"};
42 TraceCorrelation[] distributions;
43
44 public LogFileTraceExporter(File file, int burnin) throws TraceException, IOException {
45
46 analysis = new LogFileTraces(file.getCanonicalPath(), file);
47 analysis.loadTraces();
48 if (burnin >= 0) {
49 analysis.setBurnIn(burnin);
50 }
51
52 distributions = new TraceCorrelation[nColumns()];
53 }
54
55 public int nColumns() {
56 return analysis.getTraceCount();
57 }
58
59 public String columnName(int nColumn) {
60 return analysis.getTraceName(nColumn);
61 }
62
63 public int nRows() {
64 return rows.length;
65 }
66
67 public Object data(int nRow, int nColumn) {
68 // read on demand
69 if (distributions[nColumn] == null) {
70 analysis.analyseTrace(nColumn);
71 distributions[nColumn] = analysis.getCorrelationStatistics(nColumn);
72 }
73
74 TraceCorrelation distribution = distributions[nColumn];
75
76 switch (nRow) {
77 case 0: {
78 return distribution.getMean();
79 }
80 case 1: {
81 return distribution.getMedian();
82 }
83 case 2: {
84 return distribution.getLowerHPD();
85 }
86 case 3: {
87 return distribution.getUpperHPD();
88 }
89 case 4: {
90 return distribution.getESS();
91 }
92 }
93
94 return null;
95 }
96
97 }