| 1 |
package dr.inferencexml.operators; |
| 2 |
|
| 3 |
import dr.inference.operators.GibbsOperator; |
| 4 |
import dr.inference.operators.JointGibbsOperator; |
| 5 |
import dr.inference.operators.SimpleMCMCOperator; |
| 6 |
import dr.xml.*; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
public class JointGibbsOperatorParser extends AbstractXMLObjectParser { |
| 12 |
|
| 13 |
public static final String JOINT_GIBBS_OPERATOR = "jointGibbsOperator"; |
| 14 |
public static final String WEIGHT = "weight"; |
| 15 |
public static final String TARGET_ACCEPTANCE = "targetAcceptance"; |
| 16 |
|
| 17 |
public String getParserName() { |
| 18 |
return JOINT_GIBBS_OPERATOR; |
| 19 |
} |
| 20 |
|
| 21 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 22 |
|
| 23 |
final double weight = xo.getDoubleAttribute(WEIGHT); |
| 24 |
|
| 25 |
JointGibbsOperator operator = new JointGibbsOperator(weight); |
| 26 |
|
| 27 |
for (int i = 0; i < xo.getChildCount(); i++) { |
| 28 |
if (xo.getChild(i) instanceof GibbsOperator) |
| 29 |
operator.addOperator((SimpleMCMCOperator) xo.getChild(i)); |
| 30 |
else |
| 31 |
throw new RuntimeException("Operator list must consist only of GibbsOperators"); |
| 32 |
} |
| 33 |
|
| 34 |
return operator; |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public String getParserDescription() { |
| 42 |
return "This element represents a list of Gibbs Operators"; |
| 43 |
} |
| 44 |
|
| 45 |
public Class getReturnType() { |
| 46 |
return JointGibbsOperator.class; |
| 47 |
} |
| 48 |
|
| 49 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 50 |
return rules; |
| 51 |
} |
| 52 |
|
| 53 |
private final XMLSyntaxRule[] rules = { |
| 54 |
new ElementRule(SimpleMCMCOperator.class, 1, Integer.MAX_VALUE), |
| 55 |
AttributeRule.newDoubleRule(WEIGHT), |
| 56 |
AttributeRule.newDoubleRule(TARGET_ACCEPTANCE, true) |
| 57 |
}; |
| 58 |
} |