use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.
the class RandomWalkOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
CoercionMode mode = CoercionMode.parseMode(xo);
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
double windowSize = xo.getDoubleAttribute(WINDOW_SIZE);
Parameter parameter = (Parameter) xo.getChild(Parameter.class);
Double lower = null;
Double upper = null;
if (xo.hasAttribute(LOWER)) {
lower = xo.getDoubleAttribute(LOWER);
}
if (xo.hasAttribute(UPPER)) {
upper = xo.getDoubleAttribute(UPPER);
}
if (lower != null || upper != null) {
throw new XMLParseException("Do not provide lower/upper bounds on for a RandomWalkOperator; set these values are parameter bounds");
}
RandomWalkOperator.BoundaryCondition condition = RandomWalkOperator.BoundaryCondition.valueOf(xo.getAttribute(BOUNDARY_CONDITION, RandomWalkOperator.BoundaryCondition.reflecting.name()));
if (condition == RandomWalkOperator.BoundaryCondition.logit) {
final Bounds<Double> bounds = parameter.getBounds();
final int dim = parameter.getDimension();
boolean boundsSet = true;
for (int i = 0; i < dim; ++i) {
if (bounds.getLowerLimit(i) == null || Double.isInfinite(bounds.getLowerLimit(i))) {
boundsSet = false;
}
if (bounds.getUpperLimit(i) == null || Double.isInfinite(bounds.getUpperLimit(i))) {
boundsSet = false;
}
}
if (!boundsSet) {
throw new XMLParseException("The logit transformed RandomWalkOperator cannot be used on a parameter without bounds.");
}
}
if (xo.hasChildNamed(UPDATE_INDEX)) {
XMLObject cxo = xo.getChild(UPDATE_INDEX);
Parameter updateIndex = (Parameter) cxo.getChild(Parameter.class);
if (updateIndex.getDimension() != parameter.getDimension())
throw new RuntimeException("Parameter to update and missing indices must have the same dimension");
return new RandomWalkOperator(parameter, updateIndex, windowSize, condition, weight, mode, lower, upper);
}
return new RandomWalkOperator(parameter, null, windowSize, condition, weight, mode, lower, upper);
}
use of dr.inference.model.Parameter 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 && !(variable 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;
}
use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.
the class SwapOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Parameter parameter = (Parameter) xo.getChild(Parameter.class);
double weight = xo.getDoubleAttribute("weight");
int size = xo.getIntegerAttribute("size");
boolean autoOptimize = xo.getBooleanAttribute("autoOptimize");
if (autoOptimize)
throw new XMLParseException("swapOperator can't be optimized!");
System.out.println("Creating swap operator for parameter " + parameter.getParameterName() + " (weight=" + weight + ")");
SwapOperator so = new SwapOperator(parameter, size);
so.setWeight(weight);
return so;
}
use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.
the class UniformOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
Parameter parameter = (Parameter) xo.getChild(Parameter.class);
if (parameter.getDimension() == 0) {
throw new XMLParseException("parameter with 0 dimension.");
}
Double lower = null;
Double upper = null;
if (xo.hasAttribute(LOWER)) {
lower = xo.getDoubleAttribute(LOWER);
}
if (xo.hasAttribute(UPPER)) {
upper = xo.getDoubleAttribute(UPPER);
}
return new UniformOperator(parameter, weight, lower, upper);
}
use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.
the class MultipleRandomWalkIntegerOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
double w = xo.getDoubleAttribute(RandomWalkIntegerOperatorParser.WINDOW_SIZE);
if (w != Math.floor(w)) {
throw new XMLParseException("The window size of a randomWalkIntegerOperator should be an integer");
}
double s = xo.getDoubleAttribute(SAMPLE_SIZE);
if (s != Math.floor(s)) {
throw new XMLParseException("The window size of a randomWalkIntegerOperator should be an integer");
}
int windowSize = (int) w;
int sampleSize = (int) s;
Parameter parameter = (Parameter) xo.getChild(Parameter.class);
return new MultipleRandomWalkIntegerOperator(parameter, windowSize, sampleSize, weight);
}
Aggregations