| 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.LocationScaleJeffreysPrior; |
| 29 |
import dr.inference.model.Parameter; |
| 30 |
import dr.xml.*; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class LocationScaleJeffreysPriorParser extends AbstractXMLObjectParser { |
| 37 |
|
| 38 |
public static final String PARSER_NAME = "locationScaleJeffreysPrior"; |
| 39 |
public static final String LOCATION = TwoPieceLocationScaleDistributionModelParser.LOCATION; |
| 40 |
public static final String SIGMA = TwoPieceLocationScaleDistributionModelParser.SIGMA; |
| 41 |
public static final String GAMMA = TwoPieceLocationScaleDistributionModelParser.GAMMA; |
| 42 |
public static final String PARAMETERIZATION = TwoPieceLocationScaleDistributionModelParser.PARAMETERIZATION; |
| 43 |
|
| 44 |
public static final String ALPHA_0 = "alpha0"; |
| 45 |
public static final String BETA_0 = "beta0"; |
| 46 |
|
| 47 |
public String getParserName() { |
| 48 |
return PARSER_NAME; |
| 49 |
} |
| 50 |
|
| 51 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 52 |
|
| 53 |
Parameter location = (Parameter) xo.getChild(LOCATION).getChild(Parameter.class); |
| 54 |
Parameter sigma = (Parameter) xo.getChild(SIGMA).getChild(Parameter.class); |
| 55 |
Parameter gamma = (Parameter) xo.getChild(GAMMA).getChild(Parameter.class); |
| 56 |
|
| 57 |
Parameter alpha0 = (Parameter) xo.getChild(ALPHA_0).getChild(Parameter.class); |
| 58 |
Parameter beta0 = (Parameter) xo.getChild(BETA_0).getChild(Parameter.class); |
| 59 |
|
| 60 |
String typeString = xo.getStringAttribute(PARAMETERIZATION); |
| 61 |
LocationScaleJeffreysPrior.Type type = LocationScaleJeffreysPrior.Type.parseFromString( |
| 62 |
typeString |
| 63 |
); |
| 64 |
if (type == null) { |
| 65 |
throw new XMLParseException("Unable to parse location-scale Jeffrey priors type " + typeString); |
| 66 |
} |
| 67 |
|
| 68 |
return new LocationScaleJeffreysPrior(location, sigma, gamma, alpha0, beta0, type); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 76 |
return rules; |
| 77 |
} |
| 78 |
|
| 79 |
private final XMLSyntaxRule[] rules = { |
| 80 |
AttributeRule.newStringArrayRule(PARAMETERIZATION), |
| 81 |
new ElementRule(LOCATION, |
| 82 |
new XMLSyntaxRule[]{ |
| 83 |
new ElementRule(Parameter.class), |
| 84 |
}), |
| 85 |
new ElementRule(SIGMA, |
| 86 |
new XMLSyntaxRule[]{ |
| 87 |
new ElementRule(Parameter.class), |
| 88 |
}), |
| 89 |
new ElementRule(GAMMA, |
| 90 |
new XMLSyntaxRule[]{ |
| 91 |
new ElementRule(Parameter.class), |
| 92 |
}), |
| 93 |
new ElementRule(ALPHA_0, |
| 94 |
new XMLSyntaxRule[]{ |
| 95 |
new ElementRule(Parameter.class), |
| 96 |
}, true), |
| 97 |
|
| 98 |
new ElementRule(BETA_0, |
| 99 |
new XMLSyntaxRule[]{ |
| 100 |
new ElementRule(Parameter.class), |
| 101 |
}, true), |
| 102 |
}; |
| 103 |
|
| 104 |
public String getParserDescription() { |
| 105 |
return "Calculates the likelihood of hyperparameters of the two-piece location-scale model."; |
| 106 |
} |
| 107 |
|
| 108 |
public Class getReturnType() { |
| 109 |
return LocationScaleJeffreysPrior.class; |
| 110 |
} |
| 111 |
} |