X.addToEntry(row, columnId, -mean);
public static RealMatrix averageHankelMatrix(RealMatrix hankelMat, int windowSize) { int k = hankelMat.getRowDimension(); int m = hankelMat.getColumnDimension() / windowSize; int n = k + windowSize - 1; RealMatrix result = MatrixUtils.createRealMatrix(n, m); for (int t = 0; t < n; ++t) { int i = (t < windowSize) ? 0 : (t - windowSize + 1); int j = (t < windowSize) ? t : (windowSize - 1); int counter = 0; for (; i < k && j >= 0; ++i, --j, ++counter) { for (int h = 0; h < m; ++h) { result.addToEntry(t, h, hankelMat.getEntry(i, j * m + h)); } } for (int h = 0; h < m; ++h) { result.setEntry(t, h, result.getEntry(t, h) / counter); } } return result; }
gammaShpNext.addToEntry(user, k, value); lambdaShpNext.addToEntry(item, k, value);
/** * @param M tall, skinny matrix * @return MT * M as a dense matrix */ public static RealMatrix transposeTimesSelf(Collection<float[]> M) { if (M == null || M.isEmpty()) { return null; } int features = 0; RealMatrix result = null; for (float[] vector : M) { if (result == null) { features = vector.length; result = new Array2DRowRealMatrix(features, features); } for (int row = 0; row < features; row++) { float rowValue = vector[row]; for (int col = 0; col < features; col++) { result.addToEntry(row, col, rowValue * vector[col]); } } } return result; }
public void addToA(State a, State b, double v) { if (a == null || b == null) return; A.addToEntry(a.getId(), b.getId(), v); //Adata[a.getId()][b.getId()] += v; }
/** * @param M tall, skinny matrix * @return MT * M as a dense matrix */ public static RealMatrix transposeTimesSelf(FastByIDMap<float[]> M) { if (M == null || M.isEmpty()) { return null; } RealMatrix result = null; for (FastByIDMap.MapEntry<float[]> entry : M.entrySet()) { float[] vector = entry.getValue(); int dimension = vector.length; if (result == null) { result = new Array2DRowRealMatrix(dimension, dimension); } for (int row = 0; row < dimension; row++) { float rowValue = vector[row]; for (int col = 0; col < dimension; col++) { result.addToEntry(row, col, rowValue * vector[col]); } } } Preconditions.checkNotNull(result); return result; }
/** * Like * {@link MatrixUtils#transposeTimesSelf(com.cloudera.oryx.common.collection.LongObjectMap)}, * but instead of computing MT * M, * it computes MT * C * M, where C is a diagonal matrix of 1s and 0s. This is like pretending some * rows of M are 0. * * @see MatrixUtils#transposeTimesSelf(com.cloudera.oryx.common.collection.LongObjectMap) */ private static RealMatrix partialTransposeTimesSelf(LongObjectMap<float[]> M, int dimension, LongPrimitiveIterator keys) { RealMatrix result = new Array2DRowRealMatrix(dimension, dimension); while (keys.hasNext()) { long key = keys.next(); float[] vector = M.get(key); for (int row = 0; row < dimension; row++) { float rowValue = vector[row]; for (int col = 0; col < dimension; col++) { result.addToEntry(row, col, rowValue * vector[col]); } } } return result; }
/** * Like {@link MatrixUtils#transposeTimesSelf(FastByIDMap)}, but instead of computing MT * M, * it computes MT * C * M, where C is a diagonal matrix of 1s and 0s. This is like pretending some * rows of M are 0. * * @see MatrixUtils#transposeTimesSelf(FastByIDMap) * @see #LOSS_IGNORES_UNSPECIFIED */ private static RealMatrix partialTransposeTimesSelf(FastByIDMap<float[]> M, int dimension, LongPrimitiveIterator keys) { RealMatrix result = new Array2DRowRealMatrix(dimension, dimension); while (keys.hasNext()) { long key = keys.next(); float[] vector = M.get(key); for (int row = 0; row < dimension; row++) { float rowValue = vector[row]; for (int col = 0; col < dimension; col++) { result.addToEntry(row, col, rowValue * vector[col]); } } } return result; }