Search in sources :

Example 1 with SplineInterpolatedLikelihood

use of dr.inference.distribution.SplineInterpolatedLikelihood in project beast-mcmc by beast-dev.

the class EmpiricalDistributionLikelihoodParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String fileName = xo.getStringAttribute(FILE_NAME);
    boolean splineInterpolation = xo.getAttribute(SPLINE_INTERPOLATION, false);
    // Default is cubic-spline
    int degree = xo.getAttribute(DEGREE, 3);
    boolean inverse = xo.getAttribute(INVERSE, false);
    boolean byColumn = xo.getAttribute(READ_BY_COLUMN, true);
    EmpiricalDistributionLikelihood likelihood;
    if (splineInterpolation) {
        if (degree < 1)
            throw new XMLParseException("Spline degree must be greater than zero!");
        likelihood = new SplineInterpolatedLikelihood(fileName, degree, inverse, byColumn);
    } else
        //likelihood = new EmpiricalDistributionLikelihood(fileName,inverse,byColumn);
        throw new XMLParseException("Only spline-interpolated empirical distributions are currently support");
    XMLObject cxo1 = xo.getChild(DATA);
    final int from = cxo1.getAttribute(FROM, -1);
    int to = cxo1.getAttribute(TO, -1);
    if (from >= 0 || to >= 0) {
        if (to < 0) {
            to = Integer.MAX_VALUE;
        }
        if (!(from >= 0 && to >= 0 && from < to)) {
            throw new XMLParseException("ill formed from-to");
        }
        likelihood.setRange(from, to);
    }
    for (int j = 0; j < cxo1.getChildCount(); j++) {
        if (cxo1.getChild(j) instanceof Statistic) {
            likelihood.addData((Statistic) cxo1.getChild(j));
        } else {
            throw new XMLParseException("illegal element in " + cxo1.getName() + " element");
        }
    }
    double offset = cxo1.getAttribute(OFFSET, 0);
    likelihood.setOffset(offset);
    if (cxo1.hasAttribute(LOWER) || cxo1.hasAttribute(UPPER)) {
        likelihood.setBounds(cxo1.getAttribute(LOWER, Double.NEGATIVE_INFINITY), cxo1.getAttribute(UPPER, Double.POSITIVE_INFINITY));
    }
    return likelihood;
}
Also used : SplineInterpolatedLikelihood(dr.inference.distribution.SplineInterpolatedLikelihood) EmpiricalDistributionLikelihood(dr.inference.distribution.EmpiricalDistributionLikelihood) Statistic(dr.inference.model.Statistic)

Aggregations

EmpiricalDistributionLikelihood (dr.inference.distribution.EmpiricalDistributionLikelihood)1 SplineInterpolatedLikelihood (dr.inference.distribution.SplineInterpolatedLikelihood)1 Statistic (dr.inference.model.Statistic)1