Debian Codegraph @

src/dr/geo/ManyUniformGeoDistributionModelParser.java

raw symbols SCIP
1 /*
2 * ManyUniformGeoDistributionModelParser.java
3 *
4 * Copyright (c) 2002-2016 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
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 // AbstractXMLObjectParser implementation
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 }