| 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.AbstractDistributionLikelihood; |
| 29 |
import dr.inference.distribution.CachedDistributionLikelihood; |
| 30 |
import dr.inference.distribution.DistributionLikelihood; |
| 31 |
import dr.inference.model.Variable; |
| 32 |
import dr.xml.*; |
| 33 |
|
| 34 |
import java.util.logging.Logger; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class CachedDistributionLikelihoodParser extends AbstractXMLObjectParser { |
| 40 |
|
| 41 |
public static final String CACHED_PRIOR = "cachedPrior"; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public String getParserName() { |
| 47 |
return CACHED_PRIOR; |
| 48 |
} |
| 49 |
|
| 50 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 51 |
|
| 52 |
final String name = xo.hasId() ? xo.getId() : CACHED_PRIOR; |
| 53 |
|
| 54 |
final AbstractDistributionLikelihood likelihood = (AbstractDistributionLikelihood) xo.getChild(AbstractDistributionLikelihood.class); |
| 55 |
final Variable variable = (Variable) xo.getChild(Variable.class); |
| 56 |
|
| 57 |
final Logger logger = Logger.getLogger("dr.inference"); |
| 58 |
logger.info("Constructing a cache around likelihood '" + likelihood.getId() + "', signal = " + variable.getVariableName()); |
| 59 |
|
| 60 |
return new CachedDistributionLikelihood(name, likelihood, variable); |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 69 |
return rules; |
| 70 |
} |
| 71 |
|
| 72 |
private final XMLSyntaxRule[] rules = { |
| 73 |
new ElementRule(AbstractDistributionLikelihood.class), |
| 74 |
new ElementRule(Variable.class), |
| 75 |
}; |
| 76 |
|
| 77 |
public String getParserDescription() { |
| 78 |
return "Calculates a cached likelihood of some data given some parametric or empirical distribution."; |
| 79 |
} |
| 80 |
|
| 81 |
public Class getReturnType() { |
| 82 |
return DistributionLikelihood.class; |
| 83 |
} |
| 84 |
} |