(DataPoint dataPoint, int targetClass)
| 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; |
nothing calls this directly
no test coverage detected