use of dr.inference.trace.MarginalLikelihoodAnalysis in project beast-mcmc by beast-dev.
the class AICMAnalysisParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String fileName = xo.getStringAttribute(FILE_NAME);
try {
// Open file
File file = new File(fileName);
String name = file.getName();
String parent = file.getParent();
if (!file.isAbsolute()) {
parent = System.getProperty("user.dir");
}
file = new File(parent, name);
fileName = file.getAbsolutePath();
// Set analysisType
String analysisType = "aicm";
// Set bootstrapLength
int bootstrapLength = xo.getAttribute(BOOTSTRAP_LENGTH, 1000);
// Load traces and remove burnin
LogFileTraces traces = new LogFileTraces(fileName, file);
traces.loadTraces();
long maxState = traces.getMaxState();
long burnin = xo.getAttribute(BURN_IN, maxState / 10);
if (burnin < 0 || burnin >= maxState) {
burnin = maxState / 10;
System.out.println("WARNING: Burn-in larger than total number of states - using to 10%");
}
traces.setBurnIn(burnin);
// Find likelihood column
XMLObject cxo = xo.getChild(COLUMN_NAME);
String likelihoodName = cxo.getStringAttribute(Attribute.NAME);
int traceIndex = -1;
for (int i = 0; i < traces.getTraceCount(); i++) {
String traceName = traces.getTraceName(i);
if (traceName.equals(likelihoodName)) {
traceIndex = i;
break;
}
}
if (traceIndex == -1) {
throw new XMLParseException("Column '" + likelihoodName + "' can not be found for " + getParserName() + " element.");
}
// Get samples and perform analysis
List<Double> sample = traces.getValues(traceIndex);
MarginalLikelihoodAnalysis analysis = new MarginalLikelihoodAnalysis(sample, traces.getTraceName(traceIndex), (int) burnin, analysisType, bootstrapLength);
System.out.println(analysis.toString());
return analysis;
} catch (FileNotFoundException fnfe) {
throw new XMLParseException("File '" + fileName + "' can not be opened for " + getParserName() + " element.");
} catch (java.io.IOException ioe) {
throw new XMLParseException(ioe.getMessage());
} catch (TraceException e) {
throw new XMLParseException(e.getMessage());
}
}
use of dr.inference.trace.MarginalLikelihoodAnalysis in project beast-mcmc by beast-dev.
the class ArithmeticMeanAnalysisParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String fileName = xo.getStringAttribute(FILE_NAME);
try {
// Open file
File file = new File(fileName);
String name = file.getName();
String parent = file.getParent();
if (!file.isAbsolute()) {
parent = System.getProperty("user.dir");
}
file = new File(parent, name);
fileName = file.getAbsolutePath();
// Set analysisType
String analysisType = "arithmetic";
// Set bootstrapLength
int bootstrapLength = xo.getAttribute(BOOTSTRAP_LENGTH, 1000);
// Load traces and remove burnin
LogFileTraces traces = new LogFileTraces(fileName, file);
traces.loadTraces();
long maxState = traces.getMaxState();
long burnin = xo.getAttribute(BURN_IN, maxState / 10);
if (burnin < 0 || burnin >= maxState) {
burnin = maxState / 10;
System.out.println("WARNING: Burn-in larger than total number of states - using to 10%");
}
traces.setBurnIn(burnin);
// Find likelihood column
XMLObject cxo = xo.getChild(COLUMN_NAME);
String likelihoodName = cxo.getStringAttribute(Attribute.NAME);
int traceIndex = -1;
for (int i = 0; i < traces.getTraceCount(); i++) {
String traceName = traces.getTraceName(i);
if (traceName.equals(likelihoodName)) {
traceIndex = i;
break;
}
}
if (traceIndex == -1) {
throw new XMLParseException("Column '" + likelihoodName + "' can not be found for " + getParserName() + " element.");
}
// Get samples and perform analysis
List<Double> sample = traces.getValues(traceIndex);
MarginalLikelihoodAnalysis analysis = new MarginalLikelihoodAnalysis(sample, traces.getTraceName(traceIndex), (int) burnin, analysisType, bootstrapLength);
System.out.println(analysis.toString());
return analysis;
} catch (FileNotFoundException fnfe) {
throw new XMLParseException("File '" + fileName + "' can not be opened for " + getParserName() + " element.");
} catch (java.io.IOException ioe) {
throw new XMLParseException(ioe.getMessage());
} catch (TraceException e) {
throw new XMLParseException(e.getMessage());
}
}
use of dr.inference.trace.MarginalLikelihoodAnalysis in project beast-mcmc by beast-dev.
the class HarmonicMeanAnalysisParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String fileName = xo.getStringAttribute(FILE_NAME);
try {
// Open file
File file = new File(fileName);
String name = file.getName();
String parent = file.getParent();
if (!file.isAbsolute()) {
parent = System.getProperty("user.dir");
}
file = new File(parent, name);
fileName = file.getAbsolutePath();
// Set analysisType
String analysisType = "harmonic";
boolean smoothedEstimate = false;
if (xo.hasAttribute(SMOOTHED_ESTIMATE))
smoothedEstimate = xo.getBooleanAttribute(SMOOTHED_ESTIMATE);
if (smoothedEstimate)
analysisType = "smoothed";
// Set bootstrapLength
int bootstrapLength = xo.getAttribute(BOOTSTRAP_LENGTH, 1000);
// Load traces and remove burnin
LogFileTraces traces = new LogFileTraces(fileName, file);
traces.loadTraces();
long maxState = traces.getMaxState();
long burnin = xo.getAttribute(BURN_IN, maxState / 10);
if (burnin < 0 || burnin >= maxState) {
burnin = (int) (maxState / 10);
System.out.println("WARNING: Burn-in larger than total number of states - using to 10%");
}
traces.setBurnIn(burnin);
// Find likelihood column
XMLObject cxo = xo.getChild(COLUMN_NAME);
String likelihoodName = cxo.getStringAttribute(Attribute.NAME);
int traceIndex = -1;
for (int i = 0; i < traces.getTraceCount(); i++) {
String traceName = traces.getTraceName(i);
if (traceName.equals(likelihoodName)) {
traceIndex = i;
break;
}
}
if (traceIndex == -1) {
throw new XMLParseException("Column '" + likelihoodName + "' can not be found for " + getParserName() + " element.");
}
// Get samples and perform analysis
List<Double> sample = traces.getValues(traceIndex);
MarginalLikelihoodAnalysis analysis = new MarginalLikelihoodAnalysis(sample, traces.getTraceName(traceIndex), (int) burnin, analysisType, bootstrapLength);
System.out.println(analysis.toString());
return analysis;
} catch (FileNotFoundException fnfe) {
throw new XMLParseException("File '" + fileName + "' can not be opened for " + getParserName() + " element.");
} catch (java.io.IOException ioe) {
throw new XMLParseException(ioe.getMessage());
} catch (TraceException e) {
throw new XMLParseException(e.getMessage());
}
}
use of dr.inference.trace.MarginalLikelihoodAnalysis in project beast-mcmc by beast-dev.
the class MarginalLikelihoodAnalysisParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String fileName = xo.getStringAttribute(FILE_NAME);
try {
File file = new File(fileName);
String name = file.getName();
String parent = file.getParent();
if (!file.isAbsolute()) {
parent = System.getProperty("user.dir");
}
file = new File(parent, name);
fileName = file.getAbsolutePath();
XMLObject cxo = xo.getChild(COLUMN_NAME);
String likelihoodName = cxo.getStringAttribute(Attribute.NAME);
LogFileTraces traces = new LogFileTraces(fileName, file);
traces.loadTraces();
long maxState = traces.getMaxState();
// leaving the burnin attribute off will result in 10% being used
long burnin = xo.getAttribute(BURN_IN, maxState / 10);
if (burnin < 0 || burnin >= maxState) {
burnin = maxState / 10;
System.out.println("WARNING: Burn-in larger than total number of states - using to 10%");
}
traces.setBurnIn(burnin);
int traceIndex = -1;
for (int i = 0; i < traces.getTraceCount(); i++) {
String traceName = traces.getTraceName(i);
if (traceName.equals(likelihoodName)) {
traceIndex = i;
break;
}
}
if (traceIndex == -1) {
throw new XMLParseException("Column '" + likelihoodName + "' can not be found for " + getParserName() + " element.");
}
// Set analysisType
String analysisType = "smoothed";
boolean harmonicOnly = false;
if (xo.hasAttribute(ONLY_HARMONIC))
harmonicOnly = xo.getBooleanAttribute(ONLY_HARMONIC);
if (harmonicOnly)
analysisType = "harmonic";
int bootstrapLength = cxo.getAttribute(BOOTSTRAP_LENGTH, 1000);
List<Double> sample = traces.getValues(traceIndex);
MarginalLikelihoodAnalysis analysis = new MarginalLikelihoodAnalysis(sample, traces.getTraceName(traceIndex), (int) burnin, analysisType, bootstrapLength);
System.out.println(analysis.toString());
return analysis;
} catch (FileNotFoundException fnfe) {
throw new XMLParseException("File '" + fileName + "' can not be opened for " + getParserName() + " element.");
} catch (java.io.IOException ioe) {
throw new XMLParseException(ioe.getMessage());
} catch (TraceException e) {
throw new XMLParseException(e.getMessage());
}
}
Aggregations