private boolean isConverged(DataBundle data) { DoubleArray deltaX = data.getDeltaX(); DoubleArray x = data.getX(); int n = deltaX.size(); double diff, scale; for (int i = 0; i < n; i++) { diff = Math.abs(deltaX.get(i)); scale = Math.abs(x.get(i)); if (diff > _absoluteTol + scale * _relativeTol) { return false; } } return (Math.sqrt(data.getG0()) < _absoluteTol); }
protected void updatePosition(DoubleArray p, Function<DoubleArray, DoubleArray> function, DataBundle data) { double lambda0 = data.getLambda0(); DoubleArray deltaX = (DoubleArray) _algebra.scale(p, -lambda0); DoubleArray xNew = (DoubleArray) _algebra.add(data.getX(), deltaX); DoubleArray yNew = function.apply(xNew); data.setDeltaX(deltaX); data.setDeltaY((DoubleArray) _algebra.subtract(yNew, data.getY())); data.setG2(data.getG1()); data.setG1(_algebra.getInnerProduct(yNew, yNew)); }
return data.getX(); // this can happen if the starting position is the root estimate = _initializationFunction.getInitializedMatrix(jacobianFunction, data.getX()); jacReconCount = 1; } else { estimate = _updateFunction.getUpdatedMatrix( jacobianFunction, data.getX(), data.getDeltaX(), data.getDeltaY(), estimate); jacReconCount++; estimate = _initializationFunction.getInitializedMatrix(jacobianFunction, data.getX()); jacReconCount = 1; if (!getNextPosition(function, estimate, data)) { return data.getX(); return data.getX();
DoubleArray deltaY = data.getDeltaY(); data.setG0(data.getG1()); data.setX((DoubleArray) _algebra.add(data.getX(), deltaX)); data.setY((DoubleArray) _algebra.add(data.getY(), deltaY)); return true;