| 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 |
package dr.evomodel.antigenic.phyloclustering.statistics; |
| 26 |
|
| 27 |
import dr.inference.model.*; |
| 28 |
import dr.xml.*; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 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 |
|
| 43 |
this.locationsParameter = locationsParameter; |
| 44 |
locationsParameter.addParameterListener(this); |
| 45 |
|
| 46 |
|
| 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 |
|
| 59 |
public int getColumnIndex(int dim) { |
| 60 |
return dim / locationsParameter.getRowDimension(); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 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 |
|
| 74 |
int x = getColumnIndex(dim); |
| 75 |
int y = getRowIndex(dim); |
| 76 |
Parameter loc = locationsParameter.getParameter(x); |
| 77 |
|
| 78 |
if (y == 0) { |
| 79 |
|
| 80 |
val = loc.getParameterValue(y)* mu1ScaleParameter.getParameterValue(0); |
| 81 |
} |
| 82 |
else { |
| 83 |
|
| 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 |
|
| 98 |
} |
| 99 |
|
| 100 |
public static XMLObjectParser PARSER = new AbstractXMLObjectParser() { |
| 101 |
|
| 102 |
public final static String LOCATIONS = "locations"; |
| 103 |
|
| 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 |
|
| 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 |
|
| 127 |
return new DriftedTreeClusterLocationsStatistic(locations, mu1Scale, mu2Scale); |
| 128 |
|
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 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 |
|
| 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 |
|
| 156 |
private Parameter mu1ScaleParameter; |
| 157 |
private Parameter mu2ScaleParameter; |
| 158 |
} |