| 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.model.MatrixParameter; |
| 29 |
import dr.inference.operators.AdaptableMCMCOperator; |
| 30 |
import dr.inference.operators.AdaptationMode; |
| 31 |
import dr.inference.operators.MCMCOperator; |
| 32 |
import dr.inference.operators.MVOUCovarianceOperator; |
| 33 |
import dr.xml.*; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class MVOUCovarianceOperatorParser extends AbstractXMLObjectParser { |
| 39 |
|
| 40 |
public static final String MVOU_OPERATOR = "mvouOperator"; |
| 41 |
public static final String MIXING_FACTOR = "mixingFactor"; |
| 42 |
public static final String VARIANCE_MATRIX = "varMatrix"; |
| 43 |
public static final String PRIOR_DF = "priorDf"; |
| 44 |
|
| 45 |
public String getParserName() { |
| 46 |
return MVOU_OPERATOR; |
| 47 |
} |
| 48 |
|
| 49 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 50 |
|
| 51 |
AdaptationMode mode = AdaptationMode.parseMode(xo); |
| 52 |
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT); |
| 53 |
double mixingFactor = xo.getDoubleAttribute(MIXING_FACTOR); |
| 54 |
int priorDf = xo.getIntegerAttribute(PRIOR_DF); |
| 55 |
|
| 56 |
if (mixingFactor <= 0.0 || mixingFactor >= 1.0) { |
| 57 |
throw new XMLParseException("mixingFactor must be greater than 0.0 and less thatn 1.0"); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
MatrixParameter varMatrix = (MatrixParameter) xo.getChild(MatrixParameter.class); |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
if (varMatrix.getColumnDimension() != varMatrix.getRowDimension()) |
| 68 |
throw new XMLParseException("The variance matrix is not square"); |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
return new MVOUCovarianceOperator(mixingFactor, varMatrix, priorDf, weight, mode); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public String getParserDescription() { |
| 81 |
return "This element returns junk."; |
| 82 |
} |
| 83 |
|
| 84 |
public Class getReturnType() { |
| 85 |
return MVOUCovarianceOperator.class; |
| 86 |
} |
| 87 |
|
| 88 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 89 |
return rules; |
| 90 |
} |
| 91 |
|
| 92 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 93 |
AttributeRule.newDoubleRule(MIXING_FACTOR), |
| 94 |
AttributeRule.newIntegerRule(PRIOR_DF), |
| 95 |
AttributeRule.newDoubleRule(MCMCOperator.WEIGHT), |
| 96 |
AttributeRule.newBooleanRule(AdaptableMCMCOperator.AUTO_OPTIMIZE, true), |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
new ElementRule(MatrixParameter.class) |
| 102 |
|
| 103 |
}; |
| 104 |
|
| 105 |
} |