@Override protected void init(AbstractStochasticCachingDiffFunction func) { sList = new ArrayList<double[]>(); yList = new ArrayList<double[]>(); dir = new double[func.domainDimension()]; }
@Override protected void takeStep(AbstractStochasticCachingDiffFunction dfunction) { try { computeDir(dir, newGrad); } catch (SQNMinimizer.SurpriseConvergence s) { clearStuff(); } double thisGain = gain * gainSchedule(k, 5 * numBatches); for (int i = 0; i < x.length; i++) { newX[i] = x[i] + thisGain * dir[i]; } // Get a new pair... say(" A "); if (M > 0 && sList.size() == M || sList.size() == M) { s = sList.remove(0); y = yList.remove(0); } else { s = new double[x.length]; y = new double[x.length]; } dfunction.recalculatePrevBatch = true; System.arraycopy(dfunction.derivativeAt(newX, bSize), 0, y, 0, grad.length); // compute s_k, y_k ro = 0; for (int i = 0; i < x.length; i++) { s[i] = newX[i] - x[i]; y[i] = y[i] - newGrad[i] + lambda * s[i]; ro += s[i] * y[i]; } ro = 1.0 / ro; sList.add(s); yList.add(y); roList.add(ro); }