Search in sources :

Example 1 with UniformIntegerOperator

use of dr.inference.operators.UniformIntegerOperator in project beast-mcmc by beast-dev.

the class UniformIntegerOperatorTest method testIntegerParameterStaircaseBound.

public void testIntegerParameterStaircaseBound() {
    // 3 vaules
    count = new int[dimension][3];
    // dimension = 3
    Variable<Integer> parameterInt = new Variable.I(new int[dimension - 1]);
    // integer index parameter size = real size - 1
    parameterInt.addBounds(new Bounds.Staircase(parameterInt));
    UniformIntegerOperator uniformIntegerOperator = new UniformIntegerOperator(parameterInt, 10, 1);
    for (int i = 0; i < 300; i++) {
        uniformIntegerOperator.doOperation();
        countParaValueFrequency(uniformIntegerOperator.getVariable());
    }
    printCount("Integer Parameter using Staircase Bound");
    //        assertTrue("Expected count[0][0] > 0", count[0][0] > 0);
    assertTrue("Expected count[1][0] && [1][1] > 0", count[1][0] > 0 && count[1][1] > 0);
    assertTrue("Expected count[2][0] && [2][1] && [2][2] > 0", count[2][0] > 0 && count[2][1] > 0 && count[2][2] > 0);
}
Also used : Bounds(dr.inference.model.Bounds) UniformIntegerOperator(dr.inference.operators.UniformIntegerOperator)

Example 2 with UniformIntegerOperator

use of dr.inference.operators.UniformIntegerOperator in project beast-mcmc by beast-dev.

the class UniformIntegerOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    Variable parameter = (Variable) xo.getChild(Variable.class);
    int count = 1;
    if (xo.hasAttribute("count"))
        count = xo.getIntegerAttribute("count");
    if (parameter instanceof Parameter) {
        int lower = (int) (double) ((Parameter) parameter).getBounds().getLowerLimit(0);
        if (xo.hasAttribute("lower"))
            lower = xo.getIntegerAttribute("lower");
        int upper = (int) (double) ((Parameter) parameter).getBounds().getUpperLimit(0);
        if (xo.hasAttribute("upper"))
            upper = xo.getIntegerAttribute("upper");
        if (upper == lower || lower == (int) Double.NEGATIVE_INFINITY || upper == (int) Double.POSITIVE_INFINITY) {
            throw new XMLParseException(this.getParserName() + " boundaries not found in parameter " + parameter.getId() + " Use operator lower and upper !");
        }
        return new UniformIntegerOperator((Parameter) parameter, lower, upper, weight, count);
    } else {
        // Variable<Integer>, Bounds.Staircase
        return new UniformIntegerOperator(parameter, weight, count);
    }
}
Also used : Variable(dr.inference.model.Variable) Parameter(dr.inference.model.Parameter) UniformIntegerOperator(dr.inference.operators.UniformIntegerOperator)

Example 3 with UniformIntegerOperator

use of dr.inference.operators.UniformIntegerOperator in project beast-mcmc by beast-dev.

the class UniformIntegerOperatorTest method testParameterBound.

public void testParameterBound() {
    // 4 vaules {0, 1, 2, 3}
    count = new int[dimension][4];
    Parameter parameter = new Parameter.Default(new double[] { 1.0, 0.0, 3.0 });
    parameter.addBounds(new Parameter.DefaultBounds(new double[] { 3.0, 3.0, 3.0 }, new double[dimension]));
    UniformIntegerOperator uniformIntegerOperator = new UniformIntegerOperator(parameter, 0, 3, 10, 1);
    for (int i = 0; i < 300; i++) {
        uniformIntegerOperator.doOperation();
        countParaValueFrequency(uniformIntegerOperator.getVariable());
    }
    printCount("Parameter (Double) lower = 0, upper = 3");
    assertTrue("Expected count[0][0-3] > 0", count[0][0] > 0 && count[0][1] > 0 && count[0][2] > 0 && count[0][3] > 0);
    assertTrue("Expected count[1][0-3] > 0", count[1][0] > 0 && count[1][1] > 0 && count[1][2] > 0 && count[1][3] > 0);
    assertTrue("Expected count[2][0-3] > 0", count[2][0] > 0 && count[2][1] > 0 && count[2][2] > 0 && count[2][3] > 0);
}
Also used : Parameter(dr.inference.model.Parameter) UniformIntegerOperator(dr.inference.operators.UniformIntegerOperator)

Aggregations

UniformIntegerOperator (dr.inference.operators.UniformIntegerOperator)3 Parameter (dr.inference.model.Parameter)2 Bounds (dr.inference.model.Bounds)1 Variable (dr.inference.model.Variable)1