use of dr.inference.operators.EllipticalSliceOperator in project beast-mcmc by beast-dev.
the class EllipticalSliceOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
final Parameter variable = (Parameter) xo.getChild(Parameter.class);
boolean drawByRowTemp = false;
if (xo.hasAttribute(DRAW_BY_ROW)) {
drawByRowTemp = xo.getBooleanAttribute(DRAW_BY_ROW);
}
final boolean drawByRow = drawByRowTemp;
boolean signal = xo.getAttribute(SIGNAL_CONSTITUENT_PARAMETERS, true);
if (!signal) {
Parameter possiblyCompound = variable;
if (variable instanceof MaskedParameter) {
possiblyCompound = ((MaskedParameter) variable).getUnmaskedParameter();
}
if (!(possiblyCompound instanceof CompoundParameter)) {
signal = true;
}
}
double bracketAngle = xo.getAttribute(BRACKET_ANGLE, 0.0);
boolean translationInvariant = xo.getAttribute(TRANSLATION_INVARIANT, false);
boolean rotationInvariant = xo.getAttribute(ROTATION_INVARIANT, false);
GaussianProcessRandomGenerator gaussianProcess = (GaussianProcessRandomGenerator) xo.getChild(GaussianProcessRandomGenerator.class);
if (gaussianProcess == null) {
final MultivariateDistributionLikelihood likelihood = (MultivariateDistributionLikelihood) xo.getChild(MultivariateDistributionLikelihood.class);
if (!(likelihood.getDistribution() instanceof GaussianProcessRandomGenerator)) {
throw new XMLParseException("Elliptical slice sampling only works for multivariate normally distributed random variables");
}
if (likelihood.getDistribution() instanceof MultivariateNormalDistribution)
gaussianProcess = (MultivariateNormalDistribution) likelihood.getDistribution();
if (likelihood.getDistribution() instanceof MultivariateNormalDistributionModel)
gaussianProcess = (MultivariateNormalDistributionModel) likelihood.getDistribution();
}
EllipticalSliceOperator operator = new EllipticalSliceOperator(variable, gaussianProcess, drawByRow, signal, bracketAngle, translationInvariant, rotationInvariant);
operator.setWeight(weight);
return operator;
}
Aggregations