| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 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 |
|
| 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 |
} |