| 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.NegativeBinomialDistributionModel; |
| 29 |
import dr.inference.distribution.PoissonDistributionModel; |
| 30 |
import dr.inference.model.Parameter; |
| 31 |
import dr.xml.*; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class NegativeBinomialDistributionModelParser extends AbstractXMLObjectParser { |
| 37 |
|
| 38 |
public static final String NEGATIVE_BINOMIAL_DISTRIBUTION_MODEL = "negativeBinomialDistributionModel"; |
| 39 |
public static final String MEAN = "mean"; |
| 40 |
public static final String ALPHA = "alpha"; |
| 41 |
|
| 42 |
public String getParserName() { |
| 43 |
return NEGATIVE_BINOMIAL_DISTRIBUTION_MODEL; |
| 44 |
} |
| 45 |
|
| 46 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 47 |
|
| 48 |
Parameter meanParam, alphaParameter; |
| 49 |
|
| 50 |
XMLObject cxo = xo.getChild(MEAN); |
| 51 |
if (cxo.getChild(0) instanceof Parameter) { |
| 52 |
meanParam = (Parameter) cxo.getChild(Parameter.class); |
| 53 |
} else { |
| 54 |
meanParam = new Parameter.Default(cxo.getDoubleChild(0)); |
| 55 |
} |
| 56 |
|
| 57 |
cxo = xo.getChild(ALPHA); |
| 58 |
if (cxo.getChild(0) instanceof Parameter) { |
| 59 |
alphaParameter = (Parameter) cxo.getChild(Parameter.class); |
| 60 |
} else { |
| 61 |
alphaParameter = new Parameter.Default(cxo.getDoubleChild(0)); |
| 62 |
} |
| 63 |
|
| 64 |
return new NegativeBinomialDistributionModel(meanParam, alphaParameter); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 72 |
return rules; |
| 73 |
} |
| 74 |
|
| 75 |
private final XMLSyntaxRule[] rules = { |
| 76 |
new ElementRule(MEAN, |
| 77 |
new XMLSyntaxRule[]{ |
| 78 |
new XORRule( |
| 79 |
new ElementRule(Parameter.class), |
| 80 |
new ElementRule(Double.class) |
| 81 |
)} |
| 82 |
), |
| 83 |
new ElementRule(ALPHA, |
| 84 |
new XMLSyntaxRule[]{ |
| 85 |
new XORRule( |
| 86 |
new ElementRule(Parameter.class), |
| 87 |
new ElementRule(Double.class) |
| 88 |
)} |
| 89 |
) |
| 90 |
}; |
| 91 |
|
| 92 |
public String getParserDescription() { |
| 93 |
return "Describes a Negative Binomial distribution with a given mean and scale " + |
| 94 |
"that can be used in a distributionLikelihood element"; |
| 95 |
} |
| 96 |
|
| 97 |
public Class getReturnType() { |
| 98 |
return NegativeBinomialDistributionModel.class; |
| 99 |
} |
| 100 |
|
| 101 |
} |