AlternatingLeastSquaresSolver { static Matrix addLambdaTimesNuiTimesE(Matrix matrix, double lambda, int nui) { Preconditions.checkArgument(matrix.numCols() == matrix.numRows(), "Must be a Square Matrix"); double lambdaTimesNui = lambda * nui; int numCols = matrix.numCols(); for (int n = 0; n < numCols; n++) { matrix.setQuick(n, n, matrix.getQuick(n, n) + lambdaTimesNui); } return matrix; } private  AlternatingLeastSquaresSolver(); static Vector solve(Iterable<Vector> featureVectors, Vector ratingVector, double lambda, int numFeatures);  }
@Test public void addLambdaTimesNuiTimesE() { int nui = 5; double lambda = 0.2; Matrix matrix = new SparseMatrix(5, 5); AlternatingLeastSquaresSolver.addLambdaTimesNuiTimesE(matrix, lambda, nui); for (int n = 0; n < 5; n++) { assertEquals(1.0, matrix.getQuick(n, n), EPSILON); } }