| 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.operators; |
| 27 |
|
| 28 |
import dr.inference.distribution.DistributionLikelihood; |
| 29 |
import dr.inference.model.LatentFactorModel; |
| 30 |
import dr.inference.operators.LatentFactorModelPrecisionGibbsOperator; |
| 31 |
import dr.xml.*; |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public class LatentFactorModelPrecisionGibbsOperatorParser extends AbstractXMLObjectParser { |
| 37 |
public final String LATENT_FACTOR_MODEL_PRECISION_OPERATOR = "latentFactorModelPrecisionOperator"; |
| 38 |
public final String WEIGHT = "weight"; |
| 39 |
public final String RANDOM_SCAN = "randomScan"; |
| 40 |
public final String PATH_PARAMETER = "pathParameter"; |
| 41 |
|
| 42 |
|
| 43 |
@Override |
| 44 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 45 |
String weightTemp = (String) xo.getAttribute(WEIGHT); |
| 46 |
double weight = Double.parseDouble(weightTemp); |
| 47 |
LatentFactorModel LFM = (LatentFactorModel) xo.getChild(LatentFactorModel.class); |
| 48 |
DistributionLikelihood prior = (DistributionLikelihood) xo.getChild(DistributionLikelihood.class); |
| 49 |
boolean randomScan = xo.getAttribute(RANDOM_SCAN, true); |
| 50 |
LatentFactorModelPrecisionGibbsOperator lfmOp = new LatentFactorModelPrecisionGibbsOperator(LFM, prior, weight, randomScan); |
| 51 |
if(xo.hasAttribute(PATH_PARAMETER)){ |
| 52 |
System.out.println("WARNING: Setting Path Parameter is intended for debugging purposes only!"); |
| 53 |
lfmOp.setPathParameter(xo.getDoubleAttribute(PATH_PARAMETER)); |
| 54 |
} |
| 55 |
|
| 56 |
return lfmOp; |
| 57 |
|
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
@Override |
| 62 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 63 |
return rules; |
| 64 |
} |
| 65 |
|
| 66 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 67 |
new ElementRule(LatentFactorModel.class), |
| 68 |
new ElementRule(DistributionLikelihood.class), |
| 69 |
|
| 70 |
AttributeRule.newDoubleRule(WEIGHT), |
| 71 |
AttributeRule.newDoubleRule(PATH_PARAMETER, true), |
| 72 |
}; |
| 73 |
|
| 74 |
@Override |
| 75 |
public String getParserDescription() { |
| 76 |
return "Gibbs sampler for the precision of a factor analysis model"; |
| 77 |
} |
| 78 |
|
| 79 |
@Override |
| 80 |
public Class getReturnType() { |
| 81 |
return LatentFactorModelPrecisionGibbsOperator.class; |
| 82 |
} |
| 83 |
|
| 84 |
@Override |
| 85 |
public String getParserName() { |
| 86 |
return LATENT_FACTOR_MODEL_PRECISION_OPERATOR; |
| 87 |
} |
| 88 |
} |