/** * shift * * <p>store the s and y vectors. */ private void shift() { double[] nextS = null; double[] nextY = null; int listSize = sList.size(); if (listSize < m) { nextS = new double[dim + 1]; nextY = new double[dim + 1]; } if (nextS == null) { nextS = sList.firstElement(); sList.remove(0); nextY = yList.firstElement(); yList.remove(0); roList.remove(0); } addMultInto(nextS, newW, w, -1); addMultInto(nextY, newGrad, grad, -1); double ro = ArrayUtils.dot(nextS, nextY); sList.add(nextS); yList.add(nextY); roList.add(ro); ArrayUtils.copy(newW, w); ArrayUtils.copy(newGrad, grad); iter++; }
/** * get value * * @return */ private double getValue() { double retVal = Double.MAX_VALUE; if (prevVals.size() > m / 2) { double prevVal = prevVals.firstElement(); if (prevVals.size() == m) { prevVals.remove(0); } double averageImprovement = (prevVal - this.value) / prevVals.size(); double relAvgImpr = averageImprovement / Math.abs(this.value); retVal = relAvgImpr; } else { if (DEBUG || verbose) { stderr.println(" (wait for five iters) "); } } prevVals.add(this.value); return retVal; }