| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package dr.evomodel.antigenic.phyloclustering.statistics; |
| 6 |
|
| 7 |
import dr.inference.model.*; |
| 8 |
import dr.xml.*; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
public class KStatistic extends Statistic.Abstract implements VariableListener { |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public static final String K_STATISTIC = "kStatistic"; |
| 22 |
|
| 23 |
public KStatistic(Parameter indicators) { |
| 24 |
this.indicatorsParameter = indicators; |
| 25 |
indicatorsParameter.addParameterListener(this); |
| 26 |
} |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public int getDimension() { |
| 31 |
return 1; |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
public double getStatisticValue(int dim) { |
| 39 |
|
| 40 |
double count = 0; |
| 41 |
for(int i=0; i < indicatorsParameter.getDimension(); i++){ |
| 42 |
if( (int) indicatorsParameter.getParameterValue(i) == 1 ){ |
| 43 |
count++; |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
return count; |
| 48 |
|
| 49 |
} |
| 50 |
|
| 51 |
public String getDimensionName(int dim) { |
| 52 |
String name = "K"; |
| 53 |
return name; |
| 54 |
} |
| 55 |
|
| 56 |
public void variableChangedEvent(Variable variable, int index, Parameter.ChangeType type) { |
| 57 |
|
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
public static XMLObjectParser PARSER = new AbstractXMLObjectParser() { |
| 62 |
|
| 63 |
public final static String INDICATORS = "indicators"; |
| 64 |
|
| 65 |
public String getParserName() { |
| 66 |
return K_STATISTIC; |
| 67 |
} |
| 68 |
|
| 69 |
public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 70 |
Parameter indicators = (Parameter) xo.getElementFirstChild(INDICATORS); |
| 71 |
return new KStatistic(indicators); |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public String getParserDescription() { |
| 80 |
return "This element returns a statistic that shifts a matrix of locations by location drift in the first dimension."; |
| 81 |
} |
| 82 |
|
| 83 |
public Class getReturnType() { |
| 84 |
return KStatistic.class; |
| 85 |
} |
| 86 |
|
| 87 |
public XMLSyntaxRule[] getSyntaxRules() { |
| 88 |
return rules; |
| 89 |
} |
| 90 |
|
| 91 |
private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 92 |
new ElementRule(INDICATORS, Parameter.class) |
| 93 |
}; |
| 94 |
}; |
| 95 |
|
| 96 |
private Parameter indicatorsParameter; |
| 97 |
|
| 98 |
} |