| 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.DistributionLikelihood; |
| 29 |
import dr.inference.distribution.TwoPartsDistributionLikelihood; |
| 30 |
import dr.inference.model.Parameter; |
| 31 |
import dr.xml.*; |
| 32 |
import dr.math.distributions.Distribution; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class TwoPartsDistributionLikelihoodParser extends AbstractXMLObjectParser{ |
| 40 |
public static final String TWO_PART_DISTRIBUTION_LIKELIHOOD = "twoPartDistribution"; |
| 41 |
public static final String PRIOR = "priorLik"; |
| 42 |
public static final String PSEUDO_PRIOR = "pseudoPriorLik"; |
| 43 |
public static final String PARAMETER_VECTOR = "parameterVector"; |
| 44 |
public static final String PARAMETER_INDEX = "paramIndex"; |
| 45 |
public static final String SELECTED_VARIABLE = "selectedVariable"; |
| 46 |
|
| 47 |
|
| 48 |
public String getParserName() { |
| 49 |
return TWO_PART_DISTRIBUTION_LIKELIHOOD; |
| 50 |
} |
| 51 |
|
| 52 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 53 |
DistributionLikelihood priorLikelihood = (DistributionLikelihood)xo.getElementFirstChild(PRIOR); |
| 54 |
DistributionLikelihood pseudoPriorLikelihood = (DistributionLikelihood)xo.getElementFirstChild(PSEUDO_PRIOR); |
| 55 |
Distribution prior = priorLikelihood.getDistribution(); |
| 56 |
Distribution pseudoPrior = pseudoPriorLikelihood.getDistribution(); |
| 57 |
Parameter bitVector = (Parameter)xo.getElementFirstChild(PARAMETER_VECTOR); |
| 58 |
int paramIndex = xo.getIntegerAttribute(PARAMETER_INDEX); |
| 59 |
Parameter selectedVariable = (Parameter)xo.getElementFirstChild(SELECTED_VARIABLE); |
| 60 |
|
| 61 |
|
| 62 |
TwoPartsDistributionLikelihood likelihood = |
| 63 |
new TwoPartsDistributionLikelihood( |
| 64 |
prior, |
| 65 |
pseudoPrior, |
| 66 |
bitVector, |
| 67 |
paramIndex |
| 68 |
); |
| 69 |
likelihood.addData(selectedVariable); |
| 70 |
|
| 71 |
return likelihood; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 79 |
return rules; |
| 80 |
} |
| 81 |
|
| 82 |
private final XMLSyntaxRule[] rules = { |
| 83 |
|
| 84 |
}; |
| 85 |
|
| 86 |
public String getParserDescription() { |
| 87 |
return "Calculates the likelihood of some data given some parametric or empirical distribution."; |
| 88 |
} |
| 89 |
|
| 90 |
public Class getReturnType() { |
| 91 |
return TwoPartsDistributionLikelihood.class; |
| 92 |
} |
| 93 |
} |