| 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.HierarchicalBitFlipOperator; |
| 30 |
import dr.inference.operators.MCMCOperator; |
| 31 |
import dr.xml.*; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class HierarchicalBitFlipOperatorParser extends AbstractXMLObjectParser { |
| 39 |
|
| 40 |
public static final String HIERARCHICAL_BIT_FLIP_OPERATOR = "HierarchicalBitFlipOperator"; |
| 41 |
public static final String USES_SUM_PRIOR = "usesPriorOnSum"; |
| 42 |
public static final String H_PARAMETER = "hParameter"; |
| 43 |
public static final String STRATA_PARAMETERS = "strataParameters"; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public String getParserName() { |
| 48 |
return HIERARCHICAL_BIT_FLIP_OPERATOR; |
| 49 |
} |
| 50 |
|
| 51 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 52 |
|
| 53 |
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT); |
| 54 |
boolean usesPriorOnSum = xo.getAttribute(USES_SUM_PRIOR,false); |
| 55 |
|
| 56 |
XMLObject cxo = xo.getChild(H_PARAMETER); |
| 57 |
Parameter hParameter = (Parameter) cxo.getChild(Parameter.class); |
| 58 |
|
| 59 |
cxo = xo.getChild(STRATA_PARAMETERS); |
| 60 |
int NStrata = cxo.getChildCount(); |
| 61 |
|
| 62 |
Parameter[] strataParameters = new Parameter[NStrata]; |
| 63 |
for (int i = 0; i < NStrata; i++) { |
| 64 |
Parameter parameter = (Parameter) cxo.getChild(i); |
| 65 |
strataParameters[i] = parameter; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
return new HierarchicalBitFlipOperator(hParameter, strataParameters,NStrata, weight, usesPriorOnSum); |
| 70 |
} |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public String getParserDescription() { |
| 77 |
return "This element returns a bit-flip operator on a set of hierarchical and strata parameters simulatneously."; |
| 78 |
} |
| 79 |
|
| 80 |
public Class getReturnType() { |
| 81 |
return HierarchicalBitFlipOperator.class; |
| 82 |
} |
| 83 |
|
| 84 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 85 |
return rules; |
| 86 |
} |
| 87 |
|
| 88 |
private final XMLSyntaxRule[] rules = { |
| 89 |
AttributeRule.newDoubleRule(MCMCOperator.WEIGHT), |
| 90 |
AttributeRule.newBooleanRule(USES_SUM_PRIOR,true), |
| 91 |
new ElementRule(H_PARAMETER, |
| 92 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class)}), |
| 93 |
new ElementRule(STRATA_PARAMETERS, |
| 94 |
new XMLSyntaxRule[]{new ElementRule(Parameter.class, 1, Integer.MAX_VALUE)}), |
| 95 |
}; |
| 96 |
|
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|