| 1 |
package dr.inferencexml.distribution; |
| 2 |
|
| 3 |
import dr.inference.distribution.RandomWalkGenerator; |
| 4 |
import dr.inference.model.Parameter; |
| 5 |
import dr.xml.*; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
public class RandomWalkGeneratorParser extends AbstractXMLObjectParser { |
| 11 |
public static final String RANDOM_WALK_GENERATOR = "randomWalkGenerator"; |
| 12 |
public static final String DATA = "data"; |
| 13 |
public static final String FIRST_ELEM_PREC = "firstElementPrecision"; |
| 14 |
public static final String PREC = "precision"; |
| 15 |
public static final String DIM = "dimension"; |
| 16 |
|
| 17 |
@Override |
| 18 |
public String getParserName() { return RANDOM_WALK_GENERATOR; } |
| 19 |
|
| 20 |
@Override |
| 21 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 22 |
XMLObject cxo = xo.getChild(FIRST_ELEM_PREC); |
| 23 |
Parameter firstElementPrecision = (Parameter) cxo.getChild(Parameter.class); |
| 24 |
|
| 25 |
cxo = xo.getChild(PREC); |
| 26 |
Parameter prec = (Parameter) cxo.getChild(Parameter.class); |
| 27 |
|
| 28 |
cxo = xo.getChild(DATA); |
| 29 |
Parameter data = (Parameter) cxo.getChild(Parameter.class); |
| 30 |
|
| 31 |
return new RandomWalkGenerator(data, firstElementPrecision, prec); |
| 32 |
} |
| 33 |
|
| 34 |
@Override |
| 35 |
public String getParserDescription() { |
| 36 |
return "This element generates a regular Gaussian random walk."; |
| 37 |
} |
| 38 |
|
| 39 |
@Override |
| 40 |
public Class getReturnType() { |
| 41 |
return RandomWalkGenerator.class; |
| 42 |
} |
| 43 |
|
| 44 |
@Override |
| 45 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 46 |
return rules; |
| 47 |
} |
| 48 |
|
| 49 |
private final XMLSyntaxRule[] rules = { |
| 50 |
new ElementRule(DATA, new XMLSyntaxRule[]{ |
| 51 |
new ElementRule(Parameter.class) |
| 52 |
}, "The data to evaluate the density"), |
| 53 |
|
| 54 |
|
| 55 |
new ElementRule(FIRST_ELEM_PREC, new XMLSyntaxRule[]{ |
| 56 |
new ElementRule(Parameter.class) |
| 57 |
}, "The precision for the first element of the regular random walk"), |
| 58 |
|
| 59 |
new ElementRule(PREC, new XMLSyntaxRule[]{ |
| 60 |
new ElementRule(Parameter.class) |
| 61 |
}, "The precision for the relationship between adjacent elements in the random walk"), |
| 62 |
|
| 63 |
|
| 64 |
}; |
| 65 |
} |