| 1 |
package dr.inferencexml.distribution; |
| 2 |
|
| 3 |
import dr.evomodel.continuous.FullyConjugateMultivariateTraitLikelihood; |
| 4 |
import dr.evomodel.continuous.GibbsSampleFromTreeInterface; |
| 5 |
import dr.inference.distribution.DistributionLikelihood; |
| 6 |
import dr.inference.distribution.MomentDistributionModel; |
| 7 |
import dr.inference.model.LatentFactorModel; |
| 8 |
import dr.inference.operators.FactorTreeGibbsOperator; |
| 9 |
import dr.xml.*; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
public class FactorTreeGibbsOperatorParser extends AbstractXMLObjectParser { |
| 15 |
public static final String FACTOR_TREE_GIBBS_OPERATOR_PARSER = "factorTreeGibbsOperator"; |
| 16 |
public static final String WEIGHT = "weight"; |
| 17 |
public static final String RANDOM_SCAN = "randomScan"; |
| 18 |
public static final String WORKING_PRIOR = "workingPrior"; |
| 19 |
public final String PATH_PARAMETER = "pathParameter"; |
| 20 |
|
| 21 |
@Override |
| 22 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 23 |
String weightTemp = (String) xo.getAttribute(WEIGHT); |
| 24 |
double weight = Double.parseDouble(weightTemp); |
| 25 |
LatentFactorModel lfm= (LatentFactorModel) xo.getChild(LatentFactorModel.class); |
| 26 |
GibbsSampleFromTreeInterface tree = (GibbsSampleFromTreeInterface) xo.getChild(GibbsSampleFromTreeInterface.class); |
| 27 |
GibbsSampleFromTreeInterface workingTree = null; |
| 28 |
if(xo.getChild(WORKING_PRIOR) != null){ |
| 29 |
workingTree = (GibbsSampleFromTreeInterface) xo.getChild(WORKING_PRIOR).getChild(GibbsSampleFromTreeInterface.class); |
| 30 |
} |
| 31 |
boolean randomScan = xo.getAttribute(RANDOM_SCAN, true); |
| 32 |
|
| 33 |
FactorTreeGibbsOperator lfmOp = new FactorTreeGibbsOperator(weight, lfm, tree, randomScan); |
| 34 |
if(xo.hasAttribute(PATH_PARAMETER)){ |
| 35 |
System.out.println("WARNING: Setting Path Parameter is intended for debugging purposes only!"); |
| 36 |
lfmOp.setPathParameter(xo.getDoubleAttribute(PATH_PARAMETER)); |
| 37 |
} |
| 38 |
|
| 39 |
return lfmOp; |
| 40 |
} |
| 41 |
|
| 42 |
@Override |
| 43 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 44 |
return rules; |
| 45 |
} |
| 46 |
|
| 47 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 48 |
new ElementRule(LatentFactorModel.class), |
| 49 |
new ElementRule(GibbsSampleFromTreeInterface.class), |
| 50 |
AttributeRule.newDoubleRule(WEIGHT), |
| 51 |
AttributeRule.newBooleanRule(RANDOM_SCAN, true), |
| 52 |
new ElementRule(WORKING_PRIOR, new XMLSyntaxRule[]{ |
| 53 |
new ElementRule(GibbsSampleFromTreeInterface.class) |
| 54 |
}, true), |
| 55 |
AttributeRule.newDoubleRule(PATH_PARAMETER, true), |
| 56 |
}; |
| 57 |
|
| 58 |
|
| 59 |
@Override |
| 60 |
public String getParserDescription() { |
| 61 |
return "Gibbs sample a factor row (tip) on a tree"; |
| 62 |
} |
| 63 |
|
| 64 |
@Override |
| 65 |
public Class getReturnType() { |
| 66 |
return FactorTreeGibbsOperator.class; |
| 67 |
} |
| 68 |
|
| 69 |
@Override |
| 70 |
public String getParserName() { |
| 71 |
return FACTOR_TREE_GIBBS_OPERATOR_PARSER; |
| 72 |
} |
| 73 |
} |