AlternatingLeastSquaresSolver { static Matrix createRiIiMaybeTransposed(Vector ratingVector) { Preconditions.checkArgument(ratingVector.isSequentialAccess(), "Ratings should be iterable in Index or Sequential Order"); double[][] RiIiMaybeTransposed = new double[ratingVector.getNumNondefaultElements()][1]; int index = 0; for (Vector.Element elem : ratingVector.nonZeroes()) { RiIiMaybeTransposed[index++][0] = elem.get(); } return new DenseMatrix(RiIiMaybeTransposed, true); } private  AlternatingLeastSquaresSolver(); static Vector solve(Iterable<Vector> featureVectors, Vector ratingVector, double lambda, int numFeatures);  }
@Test public void createRiIiMaybeTransposed() { Vector ratings = new SequentialAccessSparseVector(3); ratings.setQuick(1, 1.0); ratings.setQuick(3, 3.0); ratings.setQuick(5, 5.0); Matrix riIiMaybeTransposed = AlternatingLeastSquaresSolver.createRiIiMaybeTransposed(ratings); assertEquals(1, riIiMaybeTransposed.numCols(), 1); assertEquals(3, riIiMaybeTransposed.numRows(), 3); assertEquals(1.0, riIiMaybeTransposed.getQuick(0, 0), EPSILON); assertEquals(3.0, riIiMaybeTransposed.getQuick(1, 0), EPSILON); assertEquals(5.0, riIiMaybeTransposed.getQuick(2, 0), EPSILON); }
@Test public void createRiIiMaybeTransposedExceptionOnNonSequentialVector() { Vector ratings = new RandomAccessSparseVector(3); ratings.setQuick(1, 1.0); ratings.setQuick(3, 3.0); ratings.setQuick(5, 5.0); try { AlternatingLeastSquaresSolver.createRiIiMaybeTransposed(ratings); fail(); } catch (IllegalArgumentException e) {} }