| 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.geo; |
| 27 |
|
| 28 |
import dr.geo.operators.UniformGeoSpatialOperator; |
| 29 |
import dr.inference.distribution.AbstractDistributionLikelihood; |
| 30 |
import dr.inference.distribution.CachedDistributionLikelihood; |
| 31 |
import dr.inference.distribution.MultivariateDistributionLikelihood; |
| 32 |
import dr.inference.model.Likelihood; |
| 33 |
import dr.inference.model.Parameter; |
| 34 |
import dr.inference.operators.MCMCOperator; |
| 35 |
import dr.inference.operators.UniformOperator; |
| 36 |
import dr.math.distributions.MultivariateDistribution; |
| 37 |
import dr.xml.*; |
| 38 |
|
| 39 |
import java.util.ArrayList; |
| 40 |
import java.util.List; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public class ManyUniformGeoDistributionModelParser extends AbstractXMLObjectParser { |
| 45 |
|
| 46 |
public final static String MANY_PARSER = "geoDistributionCollection"; |
| 47 |
|
| 48 |
public String getParserName() { |
| 49 |
return MANY_PARSER; |
| 50 |
} |
| 51 |
|
| 52 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 53 |
|
| 54 |
List<GeoSpatialDistribution> distributions = new ArrayList<GeoSpatialDistribution>(); |
| 55 |
List<Parameter> parameters = new ArrayList<Parameter>(); |
| 56 |
List<Likelihood> oldLikelihood = new ArrayList<Likelihood>(); |
| 57 |
|
| 58 |
for (int i = 0; i < xo.getChildCount(); ++i) { |
| 59 |
Object cxo = xo.getChild(i); |
| 60 |
MultivariateDistributionLikelihood ab = null; |
| 61 |
|
| 62 |
if (cxo instanceof MultivariateDistributionLikelihood) { |
| 63 |
ab = (MultivariateDistributionLikelihood) cxo; |
| 64 |
} else if (cxo instanceof CachedDistributionLikelihood) { |
| 65 |
ab = (MultivariateDistributionLikelihood) |
| 66 |
((CachedDistributionLikelihood) cxo).getDistributionLikelihood(); |
| 67 |
} |
| 68 |
|
| 69 |
if (ab != null) { |
| 70 |
parameters.add(ab.getDataParameter()); |
| 71 |
MultivariateDistribution md = ab.getDistribution(); |
| 72 |
oldLikelihood.add((Likelihood)cxo); |
| 73 |
|
| 74 |
if (md instanceof GeoSpatialDistribution) { |
| 75 |
distributions.add((GeoSpatialDistribution)md); |
| 76 |
} else { |
| 77 |
throw new XMLParseException("Unhandled distribution type in '" + xo.getId() + "'"); |
| 78 |
} |
| 79 |
|
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
return new ManyUniformGeoDistributionModel(xo.getId(), parameters, distributions, oldLikelihood); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public String getParserDescription() { |
| 91 |
return "An operator that picks new parameter values uniformly at random."; |
| 92 |
} |
| 93 |
|
| 94 |
public Class getReturnType() { |
| 95 |
return UniformOperator.class; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 100 |
return rules; |
| 101 |
} |
| 102 |
|
| 103 |
private final XMLSyntaxRule[] rules = { |
| 104 |
new ElementRule(MultivariateDistributionLikelihood.class, 0, Integer.MAX_VALUE), |
| 105 |
new ElementRule(CachedDistributionLikelihood.class, 0, Integer.MAX_VALUE), |
| 106 |
}; |
| 107 |
} |