Debian Codegraph @

src/dr/evomodel/continuous/MixtureCartogramDiffusionModel.java

raw symbols SCIP
1 /*
2 * MixtureCartogramDiffusionModel.java
3 *
4 * Copyright (c) 2002-2015 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.evomodel.continuous;
27
28 import dr.geo.cartogram.CartogramMapping;
29 import dr.inference.model.Parameter;
30 import dr.xml.*;
31
32 import java.awt.geom.Rectangle2D;
33 import java.util.ArrayList;
34 import java.util.List;
35 import java.util.logging.Logger;
36
37 /**
38 * @author Marc Suchard
39 */
40
41 public class MixtureCartogramDiffusionModel extends CartogramDiffusionModel {
42
43 public static final String DIFFUSION_PROCESS = "mixtureCartogramDiffusionModel";
44 public static final String MIXTURE = "mixture";
45 public static final String MAP = "map";
46
47 // public MixtureCartogramDiffusionModel(String name, Parameter precision) {
48 // super(name, precision);
49 // }
50
51 public MixtureCartogramDiffusionModel(String name, Parameter precision, Parameter mixture) {
52 super(name, precision);
53 this.mixture = mixture;
54 Logger.getLogger("dr.evomodel.continuous").info(
55 "\tMixture: " + mixture.getId()
56 );
57 addVariable(mixture);
58 }
59
60 public void addMapping(CartogramMapping mapping) {
61
62 if (mappingList == null)
63 mappingList = new ArrayList<CartogramMapping>();
64
65 mappingList.add(mapping);
66 Logger.getLogger("dr.evomodel.continuous").info(
67 "\tMapping : " + mapping.toString() + " with density "+mapping.getAverageDensity()
68 );
69 }
70
71 protected CartogramMapping getMapping() {
72 final int index = (int)mixture.getParameterValue(0)-1;
73 // System.err.println("index = "+index);
74 // if (index > 0)
75 // System.exit(-1);
76
77 return mappingList.get(index);
78 }
79
80 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
81
82 public String getParserName() {
83 return DIFFUSION_PROCESS;
84 }
85
86 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
87
88 Rectangle2D boundingBox = parseRectangle2D(xo);
89
90 Parameter diffusionParam = (Parameter) xo.getChild(Parameter.class);
91
92 Parameter mixtureParam = (Parameter) xo.getChild(MIXTURE).getChild(Parameter.class);
93
94 MixtureCartogramDiffusionModel model = new MixtureCartogramDiffusionModel(xo.getId(),
95 diffusionParam, mixtureParam);
96
97 for(int i=0; i<xo.getChildCount(); i++) {
98 if (xo.getChildName(i).equals(MAP)) {
99 XMLObject cxo = (XMLObject) xo.getChild(i);
100 CartogramMapping mapping = parseCartogramMapping(cxo,boundingBox);
101 model.addMapping(mapping);
102 }
103 }
104
105 return model;
106 }
107
108 //************************************************************************
109 // AbstractXMLObjectParser implementation
110 //************************************************************************
111
112 public String getParserDescription() {
113 return "Describes a bivariate diffusion process using cartogram distances.";
114 }
115
116 public XMLSyntaxRule[] getSyntaxRules() {
117 return rules;
118 }
119
120 private final XMLSyntaxRule[] rules = {
121 new ElementRule(Parameter.class),
122 new ElementRule(MIXTURE, new XMLSyntaxRule[] {
123 new ElementRule(Parameter.class)
124 }),
125 // new ElementRule(MAP,1,Integer.MAX_VALUE),
126 // AttributeRule.newStringRule(FILENAME,true),
127 // AttributeRule.newIntegerRule(XSIZE),
128 // AttributeRule.newIntegerRule(YSIZE),
129 boundingBoxRules,
130 };
131
132 public Class getReturnType() {
133 return MultivariateDiffusionModel.class;
134 }
135 };
136
137 private final Parameter mixture;
138 private List<CartogramMapping> mappingList;
139 }