| 1 | package dr.inferencexml.operators; |
| 2 | |
| 3 | import dr.inference.model.MatrixParameterInterface; |
| 4 | import dr.inference.operators.LoadingsGibbsTruncatedOperator; |
| 5 | import dr.inference.operators.LoadingsSparsityOperator; |
| 6 | import dr.xml.*; |
| 7 | |
| 8 | public class LoadingsSparsityOperatorParser extends AbstractXMLObjectParser { |
| 9 | public static final String LOADINGS_SPARSITY_OPERATOR = "loadingsSparsityOperator"; |
| 10 | public static final String WEIGHT = "weight"; |
| 11 | |
| 12 | @Override |
| 13 | public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 14 | LoadingsGibbsTruncatedOperator operator = (LoadingsGibbsTruncatedOperator) xo.getChild(LoadingsGibbsTruncatedOperator.class); |
| 15 | MatrixParameterInterface sparseness = (MatrixParameterInterface) xo.getChild(MatrixParameterInterface.class); |
| 16 | double weight = xo.getDoubleAttribute(WEIGHT); |
| 17 | |
| 18 | return new LoadingsSparsityOperator(weight, operator, sparseness); |
| 19 | } |
| 20 | |
| 21 | @Override |
| 22 | public XMLSyntaxRule[] getSyntaxRules() { |
| 23 | return rules; |
| 24 | } |
| 25 | |
| 26 | XMLSyntaxRule[] rules = { |
| 27 | new ElementRule(LoadingsGibbsTruncatedOperator.class), |
| 28 | new ElementRule(MatrixParameterInterface.class), |
| 29 | }; |
| 30 | |
| 31 | @Override |
| 32 | public String getParserDescription() { |
| 33 | return "Sparseness operator for the sparseness on the loadings of a latent factor model"; |
| 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public Class getReturnType() { |
| 38 | return LoadingsSparsityOperator.class; |
| 39 | } |
| 40 | |
| 41 | @Override |
| 42 | public String getParserName() { |
| 43 | return LOADINGS_SPARSITY_OPERATOR; |
| 44 | } |
| 45 | } |