Debian Codegraph @

src/dr/evomodel/antigenic/phyloclustering/operators/serumPrecisionSerumLocOperator.java

raw symbols SCIP
1
2 package dr.evomodel.antigenic.phyloclustering.operators;
3
4 import dr.inference.model.MatrixParameter;
5 import dr.inference.model.Parameter;
6 import dr.inference.operators.AbstractAdaptableOperator;
7 import dr.inference.operators.AdaptationMode;
8 import dr.inference.operators.MCMCOperator;
9 import dr.inference.operators.OperatorUtils;
10 import dr.math.MathUtils;
11 import dr.xml.AbstractXMLObjectParser;
12 import dr.xml.AttributeRule;
13 import dr.xml.ElementRule;
14 import dr.xml.XMLObject;
15 import dr.xml.XMLObjectParser;
16 import dr.xml.XMLParseException;
17 import dr.xml.XMLSyntaxRule;
18
19 public class serumPrecisionSerumLocOperator extends AbstractAdaptableOperator {
20
21
22
23 private Parameter serumPrecision = null;
24 private MatrixParameter serumLocations = null;
25
26 private double scaleFactor;
27
28 public serumPrecisionSerumLocOperator(double weight, MatrixParameter serumLocations, Parameter serumPrec, double scale){
29
30 super(AdaptationMode.ADAPTATION_ON);
31
32 setWeight(weight);
33 this.serumLocations = serumLocations;
34 this.serumPrecision = serumPrec;
35 this.scaleFactor = scale;
36
37 }
38
39
40
41 public double doOperation() {
42
43
44 final double scale = (scaleFactor + (MathUtils.nextDouble() * ((1.0 / scaleFactor) - scaleFactor)));
45
46 double original_serumPrec_Val = serumPrecision.getParameterValue(0);
47 double new_serumPrec_Val = scale * original_serumPrec_Val;
48
49
50 serumPrecision.setParameterValue(0, new_serumPrec_Val);
51
52
53 for(int i=0; i < serumLocations.getColumnDimension(); i++){
54 for(int j=0; j < 2; j++){
55 double oldValue = serumLocations.getParameter(i).getParameterValue(j);
56 double newValue = oldValue * Math.sqrt( original_serumPrec_Val/new_serumPrec_Val);
57 serumLocations.getParameter(i).setParameterValue(j, newValue);
58 }
59
60 }
61
62
63 double logq = -Math.log(scale);
64 return logq;
65 }
66
67
68
69
70
71 //copied from the original ScaleOperator
72 public double getAdaptableParameter() {
73 return Math.log(1.0 / scaleFactor - 1.0);
74 }
75
76 //copied from the original ScaleOperator
77 public void setAdaptableParameter(double value) {
78 scaleFactor = 1.0 / (Math.exp(value) + 1.0);
79 }
80
81 //copied from the original ScaleOperator
82 public double getRawParameter() {
83 return scaleFactor;
84 }
85
86
87 public String getAdaptableParameterName() {
88 return "scaleFactor";
89 }
90
91
92 public final static String SERUMPRECSCALEALLSERUMLOC = "serumPrecScaleAllSerumLoc";
93
94 public final String getOperatorName() {
95 return SERUMPRECSCALEALLSERUMLOC;
96 }
97
98
99
100
101
102
103
104 public static XMLObjectParser PARSER = new AbstractXMLObjectParser() {
105
106
107 public final static String SERUMLOCATIONS = "serumLocations";
108 public final static String SERUMPREC = "serumPrec";
109
110 public final static String SCALE = "scaleFactor";
111
112
113 public String getParserName() {
114 return SERUMPRECSCALEALLSERUMLOC;
115 }
116
117 /* (non-Javadoc)
118 * @see dr.xml.AbstractXMLObjectParser#parseXMLObject(dr.xml.XMLObject)
119 */
120 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
121
122
123 double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
124 double scale = xo.getDoubleAttribute(SCALE);
125
126
127 XMLObject cxo = xo.getChild(SERUMLOCATIONS);
128 MatrixParameter serumLocations = (MatrixParameter) cxo.getChild(MatrixParameter.class);
129
130
131 cxo = xo.getChild(SERUMPREC);
132 Parameter serumPrec = (Parameter) cxo.getChild(Parameter.class);
133
134 return new serumPrecisionSerumLocOperator(weight, serumLocations, serumPrec, scale);
135
136
137 }
138
139 //************************************************************************
140 // AbstractXMLObjectParser implementation
141 //************************************************************************
142
143 public String getParserDescription() {
144 return "changes serum drift and make sure the first dimension of the active drifted mus stay the same";
145 }
146
147 public Class getReturnType() {
148 return serumPrecisionSerumLocOperator.class;
149 }
150
151
152 public XMLSyntaxRule[] getSyntaxRules() {
153 return rules;
154 }
155
156 private final XMLSyntaxRule[] rules = {
157 AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
158 AttributeRule.newDoubleRule(SCALE),
159 new ElementRule(SERUMLOCATIONS, Parameter.class),
160 new ElementRule(SERUMPREC, Parameter.class),
161 };
162
163 };
164
165
166
167 public int getStepCount() {
168 return 1;
169 }
170
171
172 }