use of dr.util.NumberFormatter in project beast-mcmc by beast-dev.
the class CompoundLikelihood method getReport.
public String getReport(int indent) {
if (EVALUATION_TIMERS) {
String message = "\n";
boolean first = true;
final NumberFormatter nf = new NumberFormatter(6);
int index = 0;
for (Likelihood lik : likelihoods) {
if (!first) {
message += ", ";
} else {
first = false;
}
if (indent >= 0) {
message += "\n";
for (int i = 0; i < indent; i++) {
message += " ";
}
}
message += lik.prettyName() + "=";
if (lik instanceof CompoundLikelihood) {
final String d = ((CompoundLikelihood) lik).getReport(indent < 0 ? -1 : indent + 2);
if (d != null && d.length() > 0) {
message += "(" + d;
if (indent >= 0) {
message += "\n";
for (int i = 0; i < indent; i++) {
message += " ";
}
}
message += ")";
}
} else {
double secs = (double) evaluationTimes[index] / 1.0E9;
message += evaluationCounts[index] + " evaluations in " + nf.format(secs) + " secs (" + nf.format(secs / evaluationCounts[index]) + " secs/eval)";
}
index++;
}
message += "\n\n";
for (int i = 0; i < indent; i++) {
message += " ";
}
message += this.getId() + " log-likelihood = " + this.getLogLikelihood();
if (indent == 0)
message += "\n\n";
return message;
} else {
return "No evaluation timer report available";
}
}
use of dr.util.NumberFormatter in project beast-mcmc by beast-dev.
the class CompoundLikelihood method getDiagnosis.
public String getDiagnosis(int indent) {
String message = "";
boolean first = true;
final NumberFormatter nf = new NumberFormatter(6);
for (Likelihood lik : likelihoods) {
if (!first) {
message += ", ";
} else {
first = false;
}
if (indent >= 0) {
message += "\n";
for (int i = 0; i < indent; i++) {
message += " ";
}
}
message += lik.prettyName() + "=";
if (lik instanceof CompoundLikelihood) {
final String d = ((CompoundLikelihood) lik).getDiagnosis(indent < 0 ? -1 : indent + 2);
if (d != null && d.length() > 0) {
message += "(" + d;
if (indent >= 0) {
message += "\n";
for (int i = 0; i < indent; i++) {
message += " ";
}
}
message += ")";
}
} else {
final double logLikelihood = lik.getLogLikelihood();
if (logLikelihood == Double.NEGATIVE_INFINITY) {
message += "-Inf";
} else if (Double.isNaN(logLikelihood)) {
message += "NaN";
} else if (logLikelihood == Double.POSITIVE_INFINITY) {
message += "+Inf";
} else {
message += nf.formatDecimal(logLikelihood, 4);
}
}
}
message += "\n";
for (int i = 0; i < indent; i++) {
message += " ";
}
message += "Total = " + this.getLogLikelihood();
return message;
}
use of dr.util.NumberFormatter in project beast-mcmc by beast-dev.
the class ThreadedCompoundLikelihood method getDiagnosis.
public String getDiagnosis() {
String message = "";
boolean first = true;
for (Likelihood lik : likelihoods) {
if (!first) {
message += ", ";
} else {
first = false;
}
String id = lik.getId();
if (id == null || id.trim().length() == 0) {
String[] parts = lik.getClass().getName().split("\\.");
id = parts[parts.length - 1];
}
message += id + "=";
if (lik instanceof ThreadedCompoundLikelihood) {
String d = ((ThreadedCompoundLikelihood) lik).getDiagnosis();
if (d != null && d.length() > 0) {
message += "(" + d + ")";
}
} else {
if (lik.getLogLikelihood() == Double.NEGATIVE_INFINITY) {
message += "-Inf";
} else if (Double.isNaN(lik.getLogLikelihood())) {
message += "NaN";
} else {
NumberFormatter nf = new NumberFormatter(6);
message += nf.formatDecimal(lik.getLogLikelihood(), 4);
}
}
}
return message;
}
use of dr.util.NumberFormatter in project beast-mcmc by beast-dev.
the class TestThreadedCompoundLikelihood method getDiagnosis.
public String getDiagnosis() {
String message = "";
boolean first = true;
for (Likelihood lik : likelihoods) {
if (!first) {
message += ", ";
} else {
first = false;
}
String id = lik.getId();
if (id == null || id.trim().length() == 0) {
String[] parts = lik.getClass().getName().split("\\.");
id = parts[parts.length - 1];
}
message += id + "=";
if (lik instanceof TestThreadedCompoundLikelihood) {
String d = ((TestThreadedCompoundLikelihood) lik).getDiagnosis();
if (d != null && d.length() > 0) {
message += "(" + d + ")";
}
} else {
if (lik.getLogLikelihood() == Double.NEGATIVE_INFINITY) {
message += "-Inf";
} else if (Double.isNaN(lik.getLogLikelihood())) {
message += "NaN";
} else {
NumberFormatter nf = new NumberFormatter(6);
message += nf.formatDecimal(lik.getLogLikelihood(), 4);
}
}
}
return message;
}
use of dr.util.NumberFormatter in project beast-mcmc by beast-dev.
the class TraceAnalysisParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String fileName = xo.getStringAttribute(FILE_NAME);
boolean withStdError = xo.getAttribute(STD_ERROR, false);
boolean computeMSE = xo.getAttribute(COMPUTE_MSE, false);
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 + File.separator, name);
if (file.exists()) {
fileName = file.getName();
// leaving the burnin attribute off will result in 10% being used
int burnin = xo.getAttribute(BURN_IN, -1);
TraceList traces = TraceAnalysis.report(fileName, burnin, null, withStdError);
for (int x = 0; x < xo.getChildCount(); x++) {
XMLObject child = (XMLObject) xo.getChild(x);
String statName = child.getStringAttribute(Attribute.NAME);
double expectation = child.getDoubleAttribute(Attribute.VALUE);
NumberFormatter formatter = new NumberFormatter(6);
formatter.setPadding(true);
formatter.setFieldWidth(14);
for (int i = 0; i < traces.getTraceCount(); i++) {
TraceDistribution distribution = traces.getDistributionStatistics(i);
TraceCorrelation corr = traces.getCorrelationStatistics(i);
if (traces.getTraceName(i).equals(statName)) {
double estimate = distribution.getMean();
double error = corr.getStdErrorOfMean();
System.out.print("E[" + statName + "] = " + formatter.format(expectation));
if (computeMSE) {
List values = traces.getValues(i);
double[] dv = new double[values.size()];
for (int j = 0; j < dv.length; j++) {
dv[j] = ((Number) values.get(j)).doubleValue();
}
double MSE = distribution.getMeanSquaredError(dv, expectation);
System.out.println(" MSE = " + formatter.format(MSE));
} else {
System.out.println("");
if (expectation > (estimate - (2 * error)) && expectation < (estimate + (2 * error))) {
System.out.println("OK: " + formatter.format(estimate) + " +- " + formatter.format(error) + "\n");
} else {
System.out.print("WARNING: " + formatter.format(estimate) + " +- " + formatter.format(error) + "\n");
}
}
}
}
}
System.out.println();
System.out.flush();
return traces;
} else {
throw new XMLParseException("Log file, " + parent + File.separator + name + " does not exist.");
}
} 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.toString());
}
}
Aggregations