| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
package dr.inferencexml.operators; |
| 27 |
|
| 28 |
import dr.inference.model.Parameter; |
| 29 |
import dr.inference.operators.MCMCOperator; |
| 30 |
import dr.inference.operators.UniformOperator; |
| 31 |
import dr.xml.*; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class UniformOperatorParser extends AbstractXMLObjectParser { |
| 36 |
public final static String UNIFORM_OPERATOR = "uniformOperator"; |
| 37 |
public static final String LOWER = "lower"; |
| 38 |
public static final String UPPER = "upper"; |
| 39 |
|
| 40 |
public String getParserName() { |
| 41 |
return UNIFORM_OPERATOR; |
| 42 |
} |
| 43 |
|
| 44 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 45 |
|
| 46 |
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT); |
| 47 |
Parameter parameter = (Parameter) xo.getChild(Parameter.class); |
| 48 |
|
| 49 |
if( parameter.getDimension() == 0 ) { |
| 50 |
throw new XMLParseException("parameter with 0 dimension."); |
| 51 |
} |
| 52 |
|
| 53 |
Double lower = null; |
| 54 |
Double upper = null; |
| 55 |
|
| 56 |
if (xo.hasAttribute(LOWER)) { |
| 57 |
lower = xo.getDoubleAttribute(LOWER); |
| 58 |
} |
| 59 |
|
| 60 |
if (xo.hasAttribute(UPPER)) { |
| 61 |
upper = xo.getDoubleAttribute(UPPER); |
| 62 |
} |
| 63 |
|
| 64 |
return new UniformOperator(parameter, weight, lower, upper); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public String getParserDescription() { |
| 72 |
return "An operator that picks new parameter values uniformly at random."; |
| 73 |
} |
| 74 |
|
| 75 |
public Class getReturnType() { |
| 76 |
return UniformOperator.class; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 81 |
return rules; |
| 82 |
} |
| 83 |
|
| 84 |
private final XMLSyntaxRule[] rules = { |
| 85 |
AttributeRule.newDoubleRule(MCMCOperator.WEIGHT), |
| 86 |
AttributeRule.newDoubleRule(LOWER, true), |
| 87 |
AttributeRule.newDoubleRule(UPPER, true), |
| 88 |
new ElementRule(Parameter.class) |
| 89 |
}; |
| 90 |
} |