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

Method update

JSAT/src/jsat/classifiers/linear/SPA.java:219–256  ·  view source on GitHub ↗
(DataPoint dataPoint, int targetClass)

Source from the content-addressed store, hash-verified

217 }
218
219 @Override
220 public void update(DataPoint dataPoint, int targetClass)
221 {
222 Vec x = dataPoint.getNumericalValues();
223 final double w_y_dot_x = w[targetClass].dot(x) + bias[targetClass];
224 for (int v = 0; v < w.length; v++)
225 if (v != targetClass)
226 loss[v] = max(0, 1 - (w_y_dot_x - w[v].dot(x) - bias[v]));
227 else
228 loss[v] = Double.POSITIVE_INFINITY;//set in Inft so its ends up in index 0, and gets skipped
229 final double xNorm = pow(x.pNorm(2) + (useBias ? 1 : 0), 2);
230
231 it.sortR(loss);
232
233 int k = 1;
234
235 double T31 = 0;//Theorem 3.1
236
237 while (k < loss.length && T31 < getSupportClassGoal(xNorm, k, loss[it.index(k)]))
238 T31 += loss[it.index(k++)];
239
240 double supportLossSum = 0;
241 for (int j = 1; j < k; j++)
242 supportLossSum += loss[it.index(j)];
243
244 for (int j = 1; j < k; j++)
245 {
246 final int v = it.index(j);
247 double tau = getStepSize(loss[v], xNorm, k, supportLossSum);
248 w[targetClass].mutableAdd(tau, x);
249 w[v].mutableSubtract(tau, x);
250 if (useBias)
251 {
252 bias[targetClass] += tau;
253 bias[v] -= tau;
254 }
255 }
256 }
257
258 @Override
259 public CategoricalResults classify(DataPoint data)

Callers

nothing calls this directly

Calls 11

pNormMethod · 0.95
getSupportClassGoalMethod · 0.95
getStepSizeMethod · 0.95
getNumericalValuesMethod · 0.80
sortRMethod · 0.80
indexMethod · 0.80
dotMethod · 0.45
maxMethod · 0.45
powMethod · 0.45
mutableAddMethod · 0.45
mutableSubtractMethod · 0.45

Tested by

no test coverage detected