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

Method update

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

Source from the content-addressed store, hash-verified

281 }
282
283 @Override
284 public void update(DataPoint dataPoint, int targetClass)
285 {
286 final Vec x_t = dataPoint.getNumericalValues();
287 final double y_t = targetClass*2-1;
288
289 final List<Double> qi = k.getQueryInfo(x_t);
290 final double score = score(x_t, qi);
291 final double lossD = lossC.getDeriv(score, y_t);
292
293 if(lossD == 0)
294 {
295 alphas.getVecView().mutableMultiply(1-eta*reg);
296 }
297 else
298 {
299 if(vecs.size() < budget)
300 {
301 alphas.getVecView().mutableMultiply(1-eta*reg);
302 alphas.add(-eta*lossD);
303 selfK.add(Math.sqrt(k.eval(0, 0, Arrays.asList(x_t), qi)));
304 if(k.supportsAcceleration())
305 accelCache.addAll(qi);
306 vecs.add(x_t);
307 }
308 else//budget maintinance
309 {
310 final int toRemove;
311 final double normalize;
312 if(uniformSampling)
313 {
314 toRemove = rand.nextInt(budget);
315 normalize = 1;
316 }
317 else
318 {
319 double s = 0;
320 for(int i = 0; i < budget; i++)
321 s += Math.abs(alphas.get(i))*selfK.get(i);
322 s = (budget-1)/s;
323 final double target = rand.nextDouble();
324 double cur = 0;
325 int i = -1;
326 while(cur < target)
327 {
328 i++;
329 cur += dist[i] = 1-s*alphas.get(i)*selfK.get(i);
330 }
331 toRemove = i++;
332 while(i < budget)
333 cur += dist[i] = 1-s*alphas.get(i)*selfK.get(i++);
334 normalize = cur;
335 }
336
337 for(int i = 0; i < budget; i++)
338 {
339 if(i == toRemove)
340 continue;

Callers

nothing calls this directly

Calls 15

scoreMethod · 0.95
getNumericalValuesMethod · 0.80
getQueryInfoMethod · 0.65
getDerivMethod · 0.65
sizeMethod · 0.65
evalMethod · 0.65
supportsAccelerationMethod · 0.65
mutableMultiplyMethod · 0.45
getVecViewMethod · 0.45
addMethod · 0.45
addAllMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected