use of dr.inference.model.Statistic in project beast-mcmc by beast-dev.
the class SubStatisticParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
String name;
if (xo.hasAttribute(Statistic.NAME) || xo.hasAttribute(dr.xml.XMLParser.ID))
name = xo.getAttribute(Statistic.NAME, xo.getId());
else
name = "";
final Statistic stat = (Statistic) xo.getChild(Statistic.class);
final int[] values = xo.getIntegerArrayAttribute(DIMENSION);
if (values.length == 0) {
throw new XMLParseException("Must specify at least one dimension");
}
final int dim = stat.getDimension();
for (int value : values) {
if (value >= dim || value < 0) {
throw new XMLParseException("Dimension " + value + " is not a valid dimension.");
}
}
return new SubStatistic(name, values, stat);
}
use of dr.inference.model.Statistic in project beast-mcmc by beast-dev.
the class ExponentialStatisticParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
ExponentialStatistic expStatistic = null;
Object child = xo.getChild(0);
if (child instanceof Statistic) {
expStatistic = new ExponentialStatistic(EXPONENTIAL_STATISTIC, (Statistic) child);
} else {
throw new XMLParseException("Unknown element found in " + getParserName() + " element:" + child);
}
return expStatistic;
}
use of dr.inference.model.Statistic in project beast-mcmc by beast-dev.
the class ImmutableParameterParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
final Statistic statistic = (Statistic) xo.getChild(Statistic.class);
Parameter.Abstract immutableParameter = new Parameter.Abstract() {
public void setParameterValueNotifyChangedAll(int dim, double value) {
throw new RuntimeException("Forbidden call to ImmutableParameter.");
}
public void setParameterValueQuietly(int dim, double value) {
throw new RuntimeException("Forbidden call to ImmutableParameter.");
}
public void storeValues() {
//do nothing
}
public void restoreValues() {
//do nothing
}
public void acceptValues() {
//do nothing
}
public int getDimension() {
return statistic.getDimension();
}
public void setParameterValue(int dim, double value) {
throw new RuntimeException("Forbidden call to ImmutableParameter.");
}
public double getParameterValue(int dim) {
return statistic.getStatisticValue(dim);
}
public String getParameterName() {
if (getId() == null)
return "immutable." + statistic.getStatisticName();
return getId();
}
public void adoptValues(Parameter source) {
throw new RuntimeException("Forbidden call to ImmutableParameter.");
}
public void addDimension(int index, double value) {
throw new RuntimeException("Forbidden call to ImmutableParameter.");
}
public double removeDimension(int index) {
throw new RuntimeException("Forbidden call to ImmutableParameter.");
}
public void addBounds(Bounds<Double> bounds) {
throw new RuntimeException("Forbidden call to ImmutableParameter.");
}
public Bounds<Double> getBounds() {
throw new RuntimeException("Forbidden call to ImmutableParameter.");
}
};
return immutableParameter;
}
use of dr.inference.model.Statistic in project beast-mcmc by beast-dev.
the class LogarithmStatisticParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
LogarithmStatistic logStatistic;
// base 0.0 means natural logarithm, the default base
double base = xo.getAttribute(BASE, 0.0);
if (base <= 1.0 && base != 0.0) {
throw new XMLParseException("Error parsing " + getParserName() + " element: base attribute should be > 1");
}
Object child = xo.getChild(0);
if (child instanceof Statistic) {
logStatistic = new LogarithmStatistic(LOGARITHM_STATISTIC, (Statistic) child, base);
} else {
throw new XMLParseException("Unknown element found in " + getParserName() + " element:" + child);
}
return logStatistic;
}
use of dr.inference.model.Statistic in project beast-mcmc by beast-dev.
the class SumStatisticParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
boolean elementwise = xo.getAttribute(ELEMENTWISE, false);
boolean absolute = xo.getAttribute(ABSOLUTE, false);
String name = SUM_STATISTIC;
if (xo.hasAttribute(Statistic.NAME)) {
name = xo.getAttribute(Statistic.NAME, xo.getId());
} else if (xo.hasAttribute(XMLParser.ID)) {
name = xo.getAttribute(XMLParser.ID, xo.getId());
}
final SumStatistic sumStatistic = new SumStatistic(name, elementwise, absolute);
for (int i = 0; i < xo.getChildCount(); i++) {
final Statistic statistic = (Statistic) xo.getChild(i);
try {
sumStatistic.addStatistic(statistic);
} catch (IllegalArgumentException iae) {
throw new XMLParseException("Statistic added to " + getParserName() + " element is not of the same dimension");
}
}
return sumStatistic;
}
Aggregations