(DataPoint dataPoint, int targetClass)
| 318 | } |
| 319 | |
| 320 | @Override |
| 321 | public void update(DataPoint dataPoint, int targetClass) |
| 322 | { |
| 323 | final Vec x_t = dataPoint.getNumericalValues(); |
| 324 | final List<Double> qi = k.getQueryInfo(x_t); |
| 325 | final double score = scoreSaveEval(x_t, qi); |
| 326 | final double y_t = targetClass*2-1; |
| 327 | //4: Compute the derivative ℓ′(yt, ft(xt)) |
| 328 | final double lossD = lossC.getDeriv(score, y_t); |
| 329 | t++; |
| 330 | // Step 5: Sample a binary random variable Zt with |
| 331 | if(rand.nextDouble() > Math.abs(lossD)/G) |
| 332 | return;//"failed", no update |
| 333 | final double alpha_t = -eta*Math.signum(lossD)*G; |
| 334 | //Update the squared norm |
| 335 | curSqrdNorm += alpha_t*alpha_t*inputKEvals.getD(0); |
| 336 | for(int i = 0; i < alphas.size(); i++) |
| 337 | curSqrdNorm += 2*alpha_t*alphas.getD(i)*inputKEvals.getD(i+1); |
| 338 | //add values |
| 339 | alphas.add(alpha_t); |
| 340 | vecs.add(x_t); |
| 341 | if(accelCache != null) |
| 342 | accelCache.addAll(qi); |
| 343 | //update online alpha averages for current & old SVs |
| 344 | alphaAveraged.add(0.0);//implicit zero for time we didn't have new SVs |
| 345 | updateAverage(); |
| 346 | //project alphas to maintain norm if needed |
| 347 | if(curSqrdNorm > R*R) |
| 348 | { |
| 349 | double coeff = R/Math.sqrt(curSqrdNorm); |
| 350 | alphas.getVecView().mutableMultiply(coeff); |
| 351 | curSqrdNorm *= coeff*coeff; |
| 352 | } |
| 353 | }; |
| 354 | |
| 355 | private double score(Vec x, List<Double> qi) |
| 356 | { |
nothing calls this directly
no test coverage detected