| 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.MicrosatelliteUpDownOperator; |
| 29 |
import dr.inference.model.Parameter; |
| 30 |
import dr.inference.operators.*; |
| 31 |
import dr.inferencexml.operators.ScaleOperatorParser; |
| 32 |
import dr.inferencexml.operators.UpDownOperatorParser; |
| 33 |
import dr.xml.*; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class MicrosatelliteUpDownOperatorParser extends AbstractXMLObjectParser { |
| 38 |
|
| 39 |
public static final String MICROSAT_UP_DOWN_OPERATOR = "microsatUpDownOperator"; |
| 40 |
public static final String UP = UpDownOperatorParser.UP; |
| 41 |
public static final String DOWN = UpDownOperatorParser.DOWN; |
| 42 |
|
| 43 |
public static final String SCALE_FACTOR = ScaleOperatorParser.SCALE_FACTOR; |
| 44 |
|
| 45 |
public String getParserName() { |
| 46 |
return MICROSAT_UP_DOWN_OPERATOR; |
| 47 |
} |
| 48 |
|
| 49 |
private Scalable.Default[] getArgs(final XMLObject list) throws XMLParseException { |
| 50 |
Scalable.Default[] args = new Scalable.Default[list.getChildCount()]; |
| 51 |
for (int k = 0; k < list.getChildCount(); ++k) { |
| 52 |
final Object child = list.getChild(k); |
| 53 |
if (child instanceof Parameter) { |
| 54 |
args[k] = new Scalable.Default((Parameter) child); |
| 55 |
} |
| 56 |
|
| 57 |
} |
| 58 |
return args; |
| 59 |
} |
| 60 |
|
| 61 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 62 |
|
| 63 |
final double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR); |
| 64 |
|
| 65 |
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT); |
| 66 |
|
| 67 |
final AdaptationMode mode = AdaptationMode.parseMode(xo); |
| 68 |
|
| 69 |
final Scalable.Default[] upArgs = getArgs(xo.getChild(UP)); |
| 70 |
final Scalable.Default[] dnArgs = getArgs(xo.getChild(DOWN)); |
| 71 |
|
| 72 |
return new MicrosatelliteUpDownOperator(upArgs, dnArgs, scaleFactor, weight, mode); |
| 73 |
} |
| 74 |
|
| 75 |
public String getParserDescription() { |
| 76 |
return "This element represents an operator that scales two parameters in different directions. " + |
| 77 |
"Each operation involves selecting a scale uniformly at random between scaleFactor and 1/scaleFactor. " + |
| 78 |
"The up parameter is multipled by this scale and the down parameter is divided by this scale."; |
| 79 |
} |
| 80 |
|
| 81 |
public Class getReturnType() { |
| 82 |
return MicrosatelliteUpDownOperator.class; |
| 83 |
} |
| 84 |
|
| 85 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 86 |
return rules; |
| 87 |
} |
| 88 |
|
| 89 |
private final XMLSyntaxRule[] ee = { |
| 90 |
new ElementRule(Parameter.class, true) |
| 91 |
}; |
| 92 |
|
| 93 |
private final XMLSyntaxRule[] rules = { |
| 94 |
AttributeRule.newDoubleRule(SCALE_FACTOR), |
| 95 |
AttributeRule.newDoubleRule(MCMCOperator.WEIGHT), |
| 96 |
AttributeRule.newBooleanRule(AdaptableMCMCOperator.AUTO_OPTIMIZE, true), |
| 97 |
|
| 98 |
|
| 99 |
new ElementRule(UP, ee, 1, Integer.MAX_VALUE), |
| 100 |
new ElementRule(DOWN, ee, 1, Integer.MAX_VALUE), |
| 101 |
}; |
| 102 |
} |