MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / update

Method update

JSAT/src/jsat/classifiers/linear/kernelized/DUOL.java:203–309  ·  view source on GitHub ↗
(DataPoint dataPoint, int targetClass)

Source from the content-addressed store, hash-verified

201 }
202
203 @Override
204 public synchronized void update(DataPoint dataPoint, int targetClass)
205 {
206 final Vec x_t = dataPoint.getNumericalValues();
207 final double y_t = targetClass*2-1;
208 final List<Double> qi = k.getQueryInfo(x_t);
209 double score = score(x_t, qi, true);
210
211 final double loss_t = max(0, 1-y_t*score);
212
213 if(loss_t <= 0)
214 return;
215
216 //start of line 8:
217 int b = -1;
218 double w_min = Double.POSITIVE_INFINITY;
219 for(int i = 0; i < S.size(); i++)
220 {
221 if(f_s.get(i) <= 1)
222 {
223 double tmp = signum(alphas.get(i))*y_t*kTmp.get(i);
224 if(tmp <= w_min)
225 {
226 w_min = tmp;
227 b = i;
228 }
229 }
230 }
231
232 final double k_t = k.eval(0, 0, Arrays.asList(x_t), qi);
233 if(w_min <= -rho)
234 {
235
236 final double k_b = k.eval(b, b, S, accelCache);
237 final double k_tb = kTmp.get(b);
238 final double alpha_b = alphas.get(b);
239 final double w_tb = y_t*signum(alpha_b)*k_tb;
240 final double gamma_hat_b = abs(alpha_b);
241 final double loss_b = 1-signum(alpha_b)*f_s.get(b);
242
243 //(C-gamma_hat_b) is common expression bellow, so use this insted
244 final double CmGhb = (C-gamma_hat_b);
245
246 final double gamma_t;
247 final double gamma_b;
248 final double gamma_b_delta;
249
250 if(k_t*C +w_tb*CmGhb-loss_t < 0 && k_b*CmGhb+w_tb*C-loss_b < 0)
251 {
252 gamma_t = C;
253 gamma_b_delta = CmGhb;
254 }
255 else if( (w_tb*w_tb*C-w_tb*loss_b-k_t*k_b*C+k_b*loss_t)/k_b > 0 && isIn((loss_b-w_tb*C)/k_b, -gamma_hat_b, CmGhb) )
256 {
257 gamma_t = C;
258 gamma_b_delta = (loss_b-w_tb*C)/k_b;
259 }
260 else if( isIn((loss_t-w_tb*CmGhb)/k_t, 0, C) && loss_b-k_b*CmGhb-w_tb*(loss_t-w_tb*CmGhb)/k_t > 0 )

Callers

nothing calls this directly

Calls 12

scoreMethod · 0.95
isInMethod · 0.95
getNumericalValuesMethod · 0.80
getQueryInfoMethod · 0.65
sizeMethod · 0.65
evalMethod · 0.65
maxMethod · 0.45
getMethod · 0.45
addMethod · 0.45
addAllMethod · 0.45
setMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected