| 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.evomodelxml.operators; |
| 27 |
|
| 28 |
import dr.evomodel.operators.RateVarianceScaleOperator; |
| 29 |
import dr.evomodel.tree.TreeModel; |
| 30 |
import dr.inference.model.Parameter; |
| 31 |
import dr.inference.operators.AdaptableMCMCOperator; |
| 32 |
import dr.inference.operators.AdaptationMode; |
| 33 |
import dr.inference.operators.MCMCOperator; |
| 34 |
import dr.xml.*; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public class RateVarianceScaleOperatorParser extends AbstractXMLObjectParser { |
| 39 |
|
| 40 |
public static final String SCALE_OPERATOR = "rateVarianceScaleOperator"; |
| 41 |
public static final String SCALE_FACTOR = "scaleFactor"; |
| 42 |
|
| 43 |
public String getParserName() { |
| 44 |
return SCALE_OPERATOR; |
| 45 |
} |
| 46 |
|
| 47 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 48 |
|
| 49 |
AdaptationMode mode = AdaptationMode.parseMode(xo); |
| 50 |
|
| 51 |
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT); |
| 52 |
final double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR); |
| 53 |
|
| 54 |
if (scaleFactor <= 0.0 || scaleFactor >= 1.0) { |
| 55 |
throw new XMLParseException("scaleFactor must be between 0.0 and 1.0"); |
| 56 |
} |
| 57 |
|
| 58 |
final TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class); |
| 59 |
|
| 60 |
final Parameter variance = (Parameter) xo.getChild(Parameter.class); |
| 61 |
if (variance.getDimension() != 1) { |
| 62 |
throw new XMLParseException("dimension of the variance parameter should be 1"); |
| 63 |
} |
| 64 |
|
| 65 |
RateVarianceScaleOperator operator = new RateVarianceScaleOperator(treeModel, variance, scaleFactor, mode); |
| 66 |
operator.setWeight(weight); |
| 67 |
return operator; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public String getParserDescription() { |
| 75 |
return "This element returns a rateScale operator on a given parameter."; |
| 76 |
} |
| 77 |
|
| 78 |
public Class getReturnType() { |
| 79 |
return RateVarianceScaleOperator.class; |
| 80 |
} |
| 81 |
|
| 82 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 83 |
return rules; |
| 84 |
} |
| 85 |
|
| 86 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 87 |
AttributeRule.newDoubleRule(SCALE_FACTOR), |
| 88 |
AttributeRule.newDoubleRule(MCMCOperator.WEIGHT), |
| 89 |
AttributeRule.newBooleanRule(AdaptableMCMCOperator.AUTO_OPTIMIZE, true), |
| 90 |
new ElementRule(TreeModel.class), |
| 91 |
new ElementRule(Parameter.class), |
| 92 |
}; |
| 93 |
} |