| 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.model; |
| 27 |
|
| 28 |
import dr.xml.*; |
| 29 |
import dr.inference.model.Statistic; |
| 30 |
import dr.inference.model.OneOnX3Prior; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class OneOnX3PriorParser extends AbstractXMLObjectParser { |
| 41 |
|
| 42 |
public static final String ONE_ONE_X_3_PRIOR = "oneOnX3Prior"; |
| 43 |
public static final String DATA = "data"; |
| 44 |
|
| 45 |
public String getParserName() { |
| 46 |
return ONE_ONE_X_3_PRIOR; |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 51 |
|
| 52 |
OneOnX3Prior likelihood = new OneOnX3Prior(); |
| 53 |
|
| 54 |
XMLObject cxo = xo; |
| 55 |
|
| 56 |
if (xo.hasChildNamed(DATA)) { |
| 57 |
cxo = xo.getChild(DATA); |
| 58 |
} |
| 59 |
|
| 60 |
for (int i = 0; i < cxo.getChildCount(); i++) { |
| 61 |
if (cxo.getChild(i) instanceof Statistic) { |
| 62 |
likelihood.addData((Statistic) cxo.getChild(i)); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
return likelihood; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 74 |
return rules; |
| 75 |
} |
| 76 |
|
| 77 |
private final XMLSyntaxRule[] rules = { |
| 78 |
new XORRule( |
| 79 |
new ElementRule(Statistic.class, 1, Integer.MAX_VALUE), |
| 80 |
new ElementRule(DATA, new XMLSyntaxRule[]{new ElementRule(Statistic.class, 1, Integer.MAX_VALUE)}) |
| 81 |
) |
| 82 |
}; |
| 83 |
|
| 84 |
public String getParserDescription() { |
| 85 |
return "Calculates the (improper) prior proportional to Prod_i (1/x_i^3) for the given statistic x."; |
| 86 |
} |
| 87 |
|
| 88 |
public Class getReturnType() { |
| 89 |
return OneOnX3Prior.class; |
| 90 |
} |
| 91 |
} |
| 92 |
|