| 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.evomodelxml.coalescent.operators; |
| 27 |
|
| 28 |
import dr.evomodel.coalescent.BayesianSkylineLikelihood; |
| 29 |
import dr.evomodel.coalescent.operators.BayesianSkylineGibbsOperator; |
| 30 |
import dr.inference.model.Parameter; |
| 31 |
import dr.inference.operators.MCMCOperator; |
| 32 |
import dr.xml.*; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class BayesianSkylineGibbsOperatorParser extends AbstractXMLObjectParser { |
| 37 |
public static final String BAYESIAN_SKYLINE_GIBBS_OPERATOR = "generalizedSkylineGibbsOperator"; |
| 38 |
public static final String POPULATION_SIZES = "populationSizes"; |
| 39 |
public static final String GROUP_SIZES = "groupSizes"; |
| 40 |
public static final String LOWER = "lower"; |
| 41 |
public static final String UPPER = "upper"; |
| 42 |
|
| 43 |
public static final String JEFFREYS = "Jeffreys"; |
| 44 |
public static final String EXPONENTIALMARKOV = "exponentialMarkov"; |
| 45 |
public static final String SHAPE = "shape"; |
| 46 |
public static final String REVERSE = "reverse"; |
| 47 |
public static final String ITERATIONS = "iterations"; |
| 48 |
public static final String TYPE = "type"; |
| 49 |
|
| 50 |
public static final String STEPWISE = "stepwise"; |
| 51 |
public static final String LINEAR = "linear"; |
| 52 |
public static final String EXPONENTIAL = "exponential"; |
| 53 |
|
| 54 |
public String getParserName() { |
| 55 |
return BAYESIAN_SKYLINE_GIBBS_OPERATOR; |
| 56 |
} |
| 57 |
|
| 58 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 59 |
|
| 60 |
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT); |
| 61 |
|
| 62 |
final double lowerBound = xo.getAttribute(LOWER, 0.0); |
| 63 |
final double upperBound = xo.getAttribute(UPPER, Double.MAX_VALUE); |
| 64 |
final boolean jeffreysPrior = xo.getAttribute(JEFFREYS, true); |
| 65 |
|
| 66 |
boolean exponentialMarkovPrior = xo.getAttribute(EXPONENTIALMARKOV, false); |
| 67 |
double shape = xo.getAttribute(SHAPE, 1.0); |
| 68 |
boolean reverse = xo.getAttribute(REVERSE, false); |
| 69 |
int iterations = xo.getAttribute(ITERATIONS, 1); |
| 70 |
|
| 71 |
BayesianSkylineLikelihood bayesianSkylineLikelihood = (BayesianSkylineLikelihood) xo |
| 72 |
.getChild(BayesianSkylineLikelihood.class); |
| 73 |
|
| 74 |
|
| 75 |
Parameter paramPops = (Parameter) xo.getChild(Parameter.class); |
| 76 |
|
| 77 |
Parameter paramGroups = bayesianSkylineLikelihood.getGroupSizeParameter(); |
| 78 |
|
| 79 |
final int type = bayesianSkylineLikelihood.getType(); |
| 80 |
|
| 81 |
if (type != BayesianSkylineLikelihood.STEPWISE_TYPE) { |
| 82 |
throw new XMLParseException( |
| 83 |
"Need stepwise control points (set 'linear=\"false\"' in skyline Gibbs operator)"); |
| 84 |
} |
| 85 |
|
| 86 |
return new BayesianSkylineGibbsOperator(bayesianSkylineLikelihood, |
| 87 |
paramPops, paramGroups, type, weight, lowerBound, |
| 88 |
upperBound, jeffreysPrior, exponentialMarkovPrior, |
| 89 |
shape, reverse, iterations); |
| 90 |
|
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public String getParserDescription() { |
| 98 |
return "This element returns a Gibbs operator for the joint distribution of population sizes."; |
| 99 |
} |
| 100 |
|
| 101 |
public Class getReturnType() { |
| 102 |
return BayesianSkylineGibbsOperator.class; |
| 103 |
} |
| 104 |
|
| 105 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 106 |
return rules; |
| 107 |
} |
| 108 |
|
| 109 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 110 |
AttributeRule.newBooleanRule(LINEAR, true), |
| 111 |
AttributeRule.newDoubleRule(MCMCOperator.WEIGHT), |
| 112 |
AttributeRule.newDoubleRule(LOWER), |
| 113 |
AttributeRule.newDoubleRule(UPPER), |
| 114 |
AttributeRule.newBooleanRule(JEFFREYS, true), |
| 115 |
AttributeRule.newBooleanRule(REVERSE, true), |
| 116 |
AttributeRule.newBooleanRule(EXPONENTIALMARKOV, true), |
| 117 |
AttributeRule.newDoubleRule(SHAPE), |
| 118 |
new ElementRule(BayesianSkylineLikelihood.class), |
| 119 |
new ElementRule(Parameter.class) |
| 120 |
}; |
| 121 |
|
| 122 |
} |