Debian Codegraph @

src/dr/evomodel/antigenic/phyloclustering/statistics/DriftedTreeClusterLocationsStatistic.java

raw symbols SCIP
1 /*
2 * DriftedTreeClusterLocationsStatistic.java
3 *
4 *
5 * This file is part of BEAST.
6 * See the NOTICE file distributed with this work for additional
7 * information regarding copyright ownership and licensing.
8 *
9 * BEAST is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * BEAST is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with BEAST; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 * Boston, MA 02110-1301 USA
23 */
24
25 package dr.evomodel.antigenic.phyloclustering.statistics;
26
27 import dr.inference.model.*;
28 import dr.xml.*;
29
30 /**
31 * @author Charles Cheung
32 *
33 * adapted from the code:
34 * @author Trevor Bedford
35 * @author Marc A. Suchard
36 */
37 public class DriftedTreeClusterLocationsStatistic extends Statistic.Abstract implements VariableListener {
38
39 public static final String DRIFTED_TREE_CLUSTER_LOCATIONS_STATISTIC = "driftedTreeClusterLocationsStatistic";
40
41 public DriftedTreeClusterLocationsStatistic(MatrixParameter locationsParameter, Parameter mu1Scale, Parameter mu2Scale) {
42 //public DriftedTreeClusterLocationsStatistic(MatrixParameter locationsParameter, Parameter locationDriftParameter, Parameter mu1Scale, Parameter mu2Scale) {
43 this.locationsParameter = locationsParameter;
44 locationsParameter.addParameterListener(this);
45 // this.locationDriftParameter = locationDriftParameter;
46 // locationDriftParameter.addParameterListener(this);
47
48 this.mu1ScaleParameter = mu1Scale;
49 mu1ScaleParameter.addParameterListener(this);
50 this.mu2ScaleParameter = mu2Scale;
51 mu2ScaleParameter.addParameterListener(this);
52 }
53
54 public int getDimension() {
55 return locationsParameter.getDimension();
56 }
57
58 // strain index
59 public int getColumnIndex(int dim) {
60 return dim / locationsParameter.getRowDimension();
61 }
62
63 // dimension index
64 public int getRowIndex(int dim) {
65 int x = getColumnIndex(dim);
66 return dim - x * locationsParameter.getRowDimension();
67 }
68
69 public double getStatisticValue(int dim) {
70
71 double val;
72
73 // x is location count, y is location dimension
74 int x = getColumnIndex(dim);
75 int y = getRowIndex(dim);
76 Parameter loc = locationsParameter.getParameter(x);
77
78 if (y == 0) {
79 //val = loc.getParameterValue(y)* locationDriftParameter.getParameterValue(0);
80 val = loc.getParameterValue(y)* mu1ScaleParameter.getParameterValue(0);
81 }
82 else {
83 //val = loc.getParameterValue(y);
84 val = loc.getParameterValue(y)* mu2ScaleParameter.getParameterValue(0);
85 }
86
87
88 return val;
89
90 }
91
92 public String getDimensionName(int dim) {
93 return locationsParameter.getDimensionName(dim);
94 }
95
96 public void variableChangedEvent(Variable variable, int index, Parameter.ChangeType type) {
97 // do nothing
98 }
99
100 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
101
102 public final static String LOCATIONS = "locations";
103 //public final static String LOCATION_DRIFT = "locationDrift";
104
105 public final static String MU1_SCALE_PARAMETER = "mu1Scale";
106 public final static String MU2_SCALE_PARAMETER = "mu2Scale";
107
108 public String getParserName() {
109 return DRIFTED_TREE_CLUSTER_LOCATIONS_STATISTIC;
110 }
111
112 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
113
114 MatrixParameter locations = (MatrixParameter) xo.getElementFirstChild(LOCATIONS);
115 //Parameter locationDrift = (Parameter) xo.getElementFirstChild(LOCATION_DRIFT);
116 Parameter mu1Scale = null;
117 if (xo.hasChildNamed(MU1_SCALE_PARAMETER)) {
118 mu1Scale = (Parameter) xo.getElementFirstChild(MU1_SCALE_PARAMETER);
119 }
120
121 Parameter mu2Scale = null;
122 if (xo.hasChildNamed(MU2_SCALE_PARAMETER)) {
123 mu2Scale = (Parameter) xo.getElementFirstChild(MU2_SCALE_PARAMETER);
124 }
125
126 // return new DriftedTreeClusterLocationsStatistic(locations, locationDrift, mu1Scale, mu2Scale);
127 return new DriftedTreeClusterLocationsStatistic(locations, mu1Scale, mu2Scale);
128
129 }
130
131 //************************************************************************
132 // AbstractXMLObjectParser implementation
133 //************************************************************************
134
135 public String getParserDescription() {
136 return "This element returns a statistic that shifts a matrix of locations by location drift in the first dimension.";
137 }
138
139 public Class getReturnType() {
140 return DriftedTreeClusterLocationsStatistic.class;
141 }
142
143 public XMLSyntaxRule[] getSyntaxRules() {
144 return rules;
145 }
146
147 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
148 new ElementRule(LOCATIONS, MatrixParameter.class),
149 // new ElementRule(LOCATION_DRIFT, Parameter.class, "TO BECOME OBSOLETE", true),
150 new ElementRule(MU1_SCALE_PARAMETER, Parameter.class, "Optional parameter for scaling the first dimension of mu"),
151 new ElementRule(MU2_SCALE_PARAMETER, Parameter.class, "Optional parameter for scaling the second dimension of mu"), };
152 };
153
154 private MatrixParameter locationsParameter;
155 // private Parameter locationDriftParameter;
156 private Parameter mu1ScaleParameter;
157 private Parameter mu2ScaleParameter;
158 }