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

Method update

JSAT/src/jsat/regression/KernelRLS.java:201–292  ·  view source on GitHub ↗
(DataPoint dataPoint, final double y_t)

Source from the content-addressed store, hash-verified

199 }
200
201 @Override
202 public void update(DataPoint dataPoint, final double y_t)
203 {
204 /*
205 * TODO a lot of temporary allocations are done in this code, but
206 * potentially change size - investigate storing them as well.
207 */
208 Vec x_t = dataPoint.getNumericalValues();
209
210 final List<Double> qi = k.getQueryInfo(x_t);
211 final double k_tt = k.eval(0, 0, Arrays.asList(x_t), qi);
212
213 if(K == null)//first point to be added
214 {
215 K = new SubMatrix(KExpanded, 0, 0, 1, 1);
216 K.set(0, 0, k_tt);
217 InvK = new SubMatrix(InvKExpanded, 0, 0, 1, 1);
218 InvK.set(0, 0, 1/k_tt);
219 P = new SubMatrix(PExpanded, 0, 0, 1, 1);
220 P.set(0, 0, 1);
221 alphaExpanded[0] = y_t/k_tt;
222 vecs.add(x_t);
223 if(kernelAccel != null)
224 kernelAccel.addAll(qi);
225 return;
226 }
227
228
229 //Normal case
230 DenseVector kxt = new DenseVector(K.rows());
231
232 for (int i = 0; i < kxt.length(); i++)
233 kxt.set(i, k.eval(i, x_t, qi, vecs, kernelAccel));
234
235 //ALD test
236 final Vec alphas_t = InvK.multiply(kxt);
237 final double delta_t = k_tt-alphas_t.dot(kxt);
238 final int size = K.rows();
239 final double alphaConst = kxt.dot(new DenseVector(alphaExpanded, 0, size));
240 if(delta_t > errorTolerance)//add to the dictionary
241 {
242 vecs.add(x_t);
243 if(kernelAccel != null)
244 kernelAccel.addAll(qi);
245
246 if(size == KExpanded.rows())//we need to grow first
247 {
248 KExpanded.changeSize(size*2, size*2);
249 InvKExpanded.changeSize(size*2, size*2);
250 PExpanded.changeSize(size*2, size*2);
251
252 alphaExpanded = Arrays.copyOf(alphaExpanded, size*2);
253 }
254
255 Matrix.OuterProductUpdate(InvK, alphas_t, alphas_t, 1/delta_t);
256 K = new SubMatrix(KExpanded, 0, 0, size+1, size+1);
257 InvK = new SubMatrix(InvKExpanded, 0, 0, size+1, size+1);
258 P = new SubMatrix(PExpanded, 0, 0, size+1, size+1);

Callers 1

trainMethod · 0.95

Calls 15

lengthMethod · 0.95
setMethod · 0.95
multiplyMethod · 0.95
dotMethod · 0.95
dotMethod · 0.95
OuterProductUpdateMethod · 0.95
getMethod · 0.95
getMethod · 0.95
mutableDivideMethod · 0.95
getNumericalValuesMethod · 0.80
copyOfMethod · 0.80
getQueryInfoMethod · 0.65

Tested by

no test coverage detected