| 1 |
|
| 2 |
package dr.evomodel.antigenic.phyloclustering.statistics; |
| 3 |
|
| 4 |
import dr.evomodel.tree.TreeModel; |
| 5 |
import dr.inference.model.*; |
| 6 |
import dr.xml.*; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
public class muStatistic extends Statistic.Abstract implements VariableListener { |
| 14 |
|
| 15 |
static int MAX_DIM = 30; |
| 16 |
|
| 17 |
|
| 18 |
private MatrixParameter mu; |
| 19 |
private TreeModel treeModel; |
| 20 |
private Parameter indicators; |
| 21 |
|
| 22 |
public static final String MU_STATISTIC = "muStatistic"; |
| 23 |
|
| 24 |
public muStatistic( TreeModel tree, MatrixParameter mu, Parameter indicators) { |
| 25 |
|
| 26 |
this.treeModel = tree; |
| 27 |
this.mu = mu; |
| 28 |
this.indicators = indicators; |
| 29 |
|
| 30 |
mu.addParameterListener(this); |
| 31 |
indicators.addParameterListener(this); |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public int getDimension() { |
| 37 |
return treeModel.getNodeCount()*2; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public double getStatisticValue(int dim) { |
| 45 |
|
| 46 |
int curNode = dim/2; |
| 47 |
double value = mu.getParameter(curNode).getParameterValue(dim % 2); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
return ( value ); |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public String getDimensionName(int dim) { |
| 62 |
String name = "mu_" + ((dim/2) ) + "-" + ((dim %2 ) +1 ); |
| 63 |
return name; |
| 64 |
} |
| 65 |
|
| 66 |
public void variableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 67 |
|
| 68 |
|
| 69 |
} |
| 70 |
|
| 71 |
public static XMLObjectParser PARSER = new AbstractXMLObjectParser() { |
| 72 |
|
| 73 |
public final static String MU_STRING = "mu"; |
| 74 |
public final static String INDICATORS_STRING = "indicators"; |
| 75 |
|
| 76 |
public String getParserName() { |
| 77 |
return MU_STATISTIC; |
| 78 |
} |
| 79 |
|
| 80 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 81 |
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class); |
| 82 |
MatrixParameter muParam = (MatrixParameter) xo.getElementFirstChild(MU_STRING); |
| 83 |
Parameter indicators = (Parameter) xo.getElementFirstChild(INDICATORS_STRING); |
| 84 |
|
| 85 |
return new muStatistic( treeModel, muParam, indicators); |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public String getParserDescription() { |
| 94 |
return "This element returns a statistic that shifts a matrix of locations by location drift in the first dimension."; |
| 95 |
} |
| 96 |
|
| 97 |
public Class getReturnType() { |
| 98 |
return muStatistic.class; |
| 99 |
} |
| 100 |
|
| 101 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 102 |
return rules; |
| 103 |
} |
| 104 |
|
| 105 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 106 |
new ElementRule(TreeModel.class), |
| 107 |
new ElementRule(MU_STRING, Parameter.class), |
| 108 |
new ElementRule(INDICATORS_STRING, Parameter.class) |
| 109 |
|
| 110 |
}; |
| 111 |
}; |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
} |