| 1 |
package dr.inferencexml.distribution; |
| 2 |
|
| 3 |
import dr.inference.distribution.RowDimensionMultinomialPrior; |
| 4 |
import dr.inference.model.AdaptableSizeFastMatrixParameter; |
| 5 |
import dr.inference.model.Parameter; |
| 6 |
import dr.xml.*; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
public class RowDimensionMultinomialPriorParser extends AbstractXMLObjectParser { |
| 12 |
public static final String ROW_DIMENSION_MULTINOMIAL_PRIOR = "rowDimensionMultinomialPrior"; |
| 13 |
public static final String PROBABILITIES = "probabilities"; |
| 14 |
public static final String TRANSPOSE = "transpose"; |
| 15 |
|
| 16 |
|
| 17 |
@Override |
| 18 |
public String getParserName() { |
| 19 |
return ROW_DIMENSION_MULTINOMIAL_PRIOR; |
| 20 |
} |
| 21 |
|
| 22 |
@Override |
| 23 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 24 |
AdaptableSizeFastMatrixParameter data = (AdaptableSizeFastMatrixParameter) xo.getChild(AdaptableSizeFastMatrixParameter.class); |
| 25 |
Parameter probabilities = (Parameter) xo.getChild(PROBABILITIES).getChild(Parameter.class); |
| 26 |
boolean transpose = false; |
| 27 |
if(xo.hasAttribute(TRANSPOSE)) |
| 28 |
transpose = xo.getBooleanAttribute(TRANSPOSE); |
| 29 |
String id = xo.getId(); |
| 30 |
|
| 31 |
|
| 32 |
return new RowDimensionMultinomialPrior(id, data, probabilities, transpose); |
| 33 |
} |
| 34 |
|
| 35 |
@Override |
| 36 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 37 |
return rules; |
| 38 |
} |
| 39 |
|
| 40 |
private final XMLSyntaxRule[] rules = { |
| 41 |
new ElementRule(PROBABILITIES, |
| 42 |
new XMLSyntaxRule[]{ |
| 43 |
new ElementRule(Parameter.class) |
| 44 |
} |
| 45 |
), |
| 46 |
new ElementRule(AdaptableSizeFastMatrixParameter.class), |
| 47 |
AttributeRule.newBooleanRule(TRANSPOSE, true), |
| 48 |
}; |
| 49 |
|
| 50 |
|
| 51 |
@Override |
| 52 |
public String getParserDescription() { |
| 53 |
return null; |
| 54 |
} |
| 55 |
|
| 56 |
@Override |
| 57 |
public Class getReturnType() { |
| 58 |
return RowDimensionMultinomialPrior.class; |
| 59 |
} |
| 60 |
} |