| 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.operators.MCMCOperator; |
| 29 |
import dr.inference.operators.TeamOperator; |
| 30 |
import dr.xml.*; |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public class TeamOperatorParser extends AbstractXMLObjectParser { |
| 36 |
|
| 37 |
public static final String TEAM_OPERATOR = "teamOperator"; |
| 38 |
public static final String SUBSET_SIZE = "size"; |
| 39 |
|
| 40 |
|
| 41 |
public String getParserName() { |
| 42 |
return TEAM_OPERATOR; |
| 43 |
} |
| 44 |
|
| 45 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 46 |
|
| 47 |
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT); |
| 48 |
final int size = xo.getIntegerAttribute(SUBSET_SIZE); |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
MCMCOperator[] o = new MCMCOperator[xo.getChildCount()]; |
| 55 |
for (int i = 0; i < o.length; i++) { |
| 56 |
o[i] = (MCMCOperator) xo.getChild(i); |
| 57 |
} |
| 58 |
|
| 59 |
return new TeamOperator(o, size, weight); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public String getParserDescription() { |
| 67 |
return "An arbitrary list of operators; A random subset of size N is aggregated in one operation." + |
| 68 |
" Operators may have unequal weights - in that case a subset probability of selection is proportional to " + |
| 69 |
"the sum of it's members weights."; |
| 70 |
} |
| 71 |
|
| 72 |
public Class getReturnType() { |
| 73 |
return TeamOperator.class; |
| 74 |
} |
| 75 |
|
| 76 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 77 |
return rules; |
| 78 |
} |
| 79 |
|
| 80 |
private final XMLSyntaxRule[] rules = { |
| 81 |
new ElementRule(MCMCOperator.class, 1, Integer.MAX_VALUE), |
| 82 |
AttributeRule.newDoubleRule(MCMCOperator.WEIGHT), |
| 83 |
AttributeRule.newIntegerRule(SUBSET_SIZE) |
| 84 |
|
| 85 |
}; |
| 86 |
} |