| 1 |
package dr.inferencexml.distribution; |
| 2 |
|
| 3 |
import dr.inference.distribution.IndependentInverseGammaDistributionModel; |
| 4 |
import dr.inference.model.Parameter; |
| 5 |
import dr.xml.*; |
| 6 |
|
| 7 |
public class IndependentInverseGammaDistributionModelParser extends AbstractXMLObjectParser{ |
| 8 |
public final static String INDEPENDENT_INVERSE_GAMMA_DISTRIBUTION_MODEL = "independentInverseGammaDistributionModel"; |
| 9 |
public final static String ID = "id"; |
| 10 |
public final static String SHAPE = "shape"; |
| 11 |
public final static String SCALE = "scale"; |
| 12 |
public final static String DATA = "data"; |
| 13 |
|
| 14 |
@Override |
| 15 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 16 |
String id = xo.getStringAttribute(ID); |
| 17 |
Parameter shape = (Parameter) xo.getChild(SHAPE).getChild(Parameter.class); |
| 18 |
Parameter scale = (Parameter) xo.getChild(SCALE).getChild(Parameter.class); |
| 19 |
Parameter data = (Parameter) xo.getChild(DATA).getChild(Parameter.class); |
| 20 |
|
| 21 |
|
| 22 |
return new IndependentInverseGammaDistributionModel(id, shape, scale, data); |
| 23 |
} |
| 24 |
|
| 25 |
@Override |
| 26 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 27 |
return rules; |
| 28 |
} |
| 29 |
|
| 30 |
XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 31 |
new ElementRule(SHAPE, new XMLSyntaxRule[]{ |
| 32 |
new ElementRule(Parameter.class) |
| 33 |
}), |
| 34 |
new ElementRule(SCALE, new XMLSyntaxRule[]{ |
| 35 |
new ElementRule(Parameter.class) |
| 36 |
}), |
| 37 |
new ElementRule(DATA, new XMLSyntaxRule[]{ |
| 38 |
new ElementRule(Parameter.class) |
| 39 |
}) |
| 40 |
}; |
| 41 |
|
| 42 |
|
| 43 |
@Override |
| 44 |
public String getParserDescription() { |
| 45 |
return "Independent inverse gamma distributions with different parameters"; |
| 46 |
} |
| 47 |
|
| 48 |
@Override |
| 49 |
public Class getReturnType() { |
| 50 |
return IndependentInverseGammaDistributionModel.class; |
| 51 |
} |
| 52 |
|
| 53 |
@Override |
| 54 |
public String getParserName() { |
| 55 |
return INDEPENDENT_INVERSE_GAMMA_DISTRIBUTION_MODEL; |
| 56 |
} |
| 57 |
} |