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

Method update

JSAT/src/jsat/classifiers/linear/SCW.java:324–424  ·  view source on GitHub ↗
(DataPoint dataPoint, int targetClass)

Source from the content-addressed store, hash-verified

322 }
323
324 @Override
325 public void update(DataPoint dataPoint, int targetClass)
326 {
327 final Vec x_t = dataPoint.getNumericalValues();
328 final double y_t = targetClass*2-1;
329 double score = x_t.dot(w);
330
331 double v_t = 0;
332 if (diagonalOnly)
333 {
334 //Faster to set only the needed final values
335 for (IndexValue iv : x_t)
336 {
337 double x_t_i = iv.getValue();
338 v_t += x_t_i * x_t_i * sigmaV.get(iv.getIndex());
339 }
340
341 }
342 else
343 {
344 sigmaM.multiply(x_t, 1, Sigma_xt);
345 v_t = x_t.dot(Sigma_xt);
346 }
347
348 //Check for numerical issues
349
350 if(v_t <= 0)//semi positive definit, should not happen
351 throw new FailedToFitException("Numerical issues occured");
352
353 double m_t = y_t*score;
354
355 final double loss = max(0, phi*sqrt(v_t)-m_t);
356
357 if(loss <= 1e-15)
358 {
359 if(!diagonalOnly)
360 zeroOutSigmaXt(x_t);
361 return;
362 }
363 final double alpha_t;
364
365
366 if(mode == Mode.SCWI || mode == Mode.CW)
367 {
368 double tmp = max(0, (-m_t*psi+sqrt(m_t*m_t*phiSqrd*phiSqrd/4+v_t*phiSqrd*zeta))/(v_t*zeta) );
369 if(mode == Mode.SCWI)
370 alpha_t = min(C, tmp);
371 else
372 alpha_t = tmp;
373
374 }
375 else//SCWII
376 {
377 final double n_t = v_t+1/(2*C);
378 final double gamma = phi*sqrt(phiSqrd*v_t*v_t*m_t*m_t+4*n_t*v_t*(n_t+v_t*phiSqrd));
379 alpha_t = max(0, (-(2*m_t*n_t+phiSqrd*m_t*v_t)+gamma)/(2*(n_t*n_t+n_t*v_t*phiSqrd)));
380 }
381

Callers

nothing calls this directly

Calls 14

dotMethod · 0.95
zeroOutSigmaXtMethod · 0.95
OuterProductUpdateMethod · 0.95
getNumericalValuesMethod · 0.80
getValueMethod · 0.45
getMethod · 0.45
getIndexMethod · 0.45
multiplyMethod · 0.45
maxMethod · 0.45
minMethod · 0.45
powMethod · 0.45
incrementMethod · 0.45

Tested by

no test coverage detected