| 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.distribution; |
| 27 |
|
| 28 |
import dr.inference.distribution.MomentDistributionModel; |
| 29 |
import dr.inference.model.Parameter; |
| 30 |
import dr.xml.*; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class MomentDistributionModelParser extends AbstractXMLObjectParser { |
| 36 |
public static final String MOMENT_DISTRIBUTION_MODEL = "momentDistributionModel"; |
| 37 |
public static final String MEAN = "mean"; |
| 38 |
|
| 39 |
public static final String PREC = "precision"; |
| 40 |
public static final String CUTOFF="cutoff"; |
| 41 |
public static final String DATA="data"; |
| 42 |
|
| 43 |
@Override |
| 44 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 45 |
Parameter mean=(Parameter) xo.getChild(MEAN).getChild(0); |
| 46 |
Parameter prec=(Parameter) xo.getChild(PREC).getChild(0); |
| 47 |
Parameter cutoff=null; |
| 48 |
if(xo.getChild(CUTOFF) != null){ |
| 49 |
cutoff=(Parameter) xo.getChild(CUTOFF).getChild(0);} |
| 50 |
Parameter data=(Parameter) xo.getChild(DATA).getChild(0); |
| 51 |
String id = xo.getId(); |
| 52 |
|
| 53 |
return new MomentDistributionModel(id, mean, prec, cutoff, data); |
| 54 |
} |
| 55 |
|
| 56 |
@Override |
| 57 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 58 |
return rules; |
| 59 |
} |
| 60 |
|
| 61 |
private final XMLSyntaxRule[] rules = { |
| 62 |
new ElementRule(MEAN, |
| 63 |
new XMLSyntaxRule[]{ |
| 64 |
new ElementRule(Parameter.class) |
| 65 |
} |
| 66 |
), |
| 67 |
new ElementRule(CUTOFF, |
| 68 |
new XMLSyntaxRule[]{ |
| 69 |
new ElementRule(Parameter.class, true) |
| 70 |
},true |
| 71 |
), |
| 72 |
new ElementRule(PREC, |
| 73 |
new XMLSyntaxRule[]{ |
| 74 |
new ElementRule(Parameter.class) |
| 75 |
} |
| 76 |
), |
| 77 |
new ElementRule(DATA, |
| 78 |
new XMLSyntaxRule[]{ |
| 79 |
new ElementRule(Parameter.class) |
| 80 |
} |
| 81 |
) |
| 82 |
}; |
| 83 |
|
| 84 |
@Override |
| 85 |
public String getParserDescription() { |
| 86 |
return "Returns an internally truncated normal distribution for claculating a moment prior"; |
| 87 |
} |
| 88 |
|
| 89 |
@Override |
| 90 |
public Class getReturnType() { |
| 91 |
return MomentDistributionModel.class; |
| 92 |
} |
| 93 |
|
| 94 |
@Override |
| 95 |
public String getParserName() { |
| 96 |
return MOMENT_DISTRIBUTION_MODEL; |
| 97 |
} |
| 98 |
} |