@Override public Matrix assignColumn(int column, Vector other) { m.assignRow(column,other); return this; }
/** * Assign the other vector values to the row of the receiver * * @param row the int row to assign * @param other a Vector * @return the modified receiver * @throws org.apache.mahout.math.CardinalityException * if the cardinalities differ */ @Override public Matrix assignRow(int row, Vector other) { // note the reversed pivoting for other return base.assignRow(rowPivot[row], new PermutedVectorView(other, columnUnpivot, columnPivot)); }
@Override public Matrix cross(Vector other) { Matrix result = matrixLike(size, other.size()); Iterator<Vector.Element> it = iterateNonZero(); while (it.hasNext()) { Vector.Element e = it.next(); int row = e.index(); result.assignRow(row, other.times(getQuick(row))); } return result; }
matrix = new DenseMatrix(rows, columns); for (int row = 0; row < rows; row++) { matrix.assignRow(row, VectorWritable.readVector(in, vectorFlags, columns)); while (rowsRead++ < numNonZeroRows) { int rowIndex = in.readInt(); matrix.assignRow(rowIndex, VectorWritable.readVector(in, vectorFlags, columns));
public Vector currentTrainingProjection() { if (trainingProjections.viewRow(trainingIndex) == null) { trainingProjections.assignRow(trainingIndex, new DenseVector(currentEigens.numCols())); } return trainingProjections.viewRow(trainingIndex); }
@Test(expected = CardinalityException.class) public void testAssignRowCardinality() { double[] data = {2.1, 3.2, 4.3}; test.assignRow(1, new DenseVector(data)); }
@Override public Matrix timesRight(Matrix that) { if (that.numRows() != diagonal.size()) { throw new IllegalArgumentException("Incompatible number of rows in the right operand of matrix multiplication."); } Matrix m = that.like(); for (int row = 0; row < diagonal.size(); row++) { m.assignRow(row, that.viewRow(row).times(diagonal.getQuick(row))); } return m; }
@Test(expected = CardinalityException.class) public void testAssignRowCardinality() { double[] data = {2.1, 3.2, 4.3}; test.assignRow(1, new DenseVector(data)); }
@Override public void setQuick(int index, double value) { Vector v = rowToColumn ? matrix.viewColumn(index) : matrix.viewRow(index); if (v == null) { v = newVector(numCols); if (rowToColumn) { matrix.assignColumn(index, v); } else { matrix.assignRow(index, v); } } v.setQuick(transposeOffset, value); }
public static Matrix randomHierarchicalMatrix(int numRows, int numCols, boolean symmetric) { Matrix matrix = new DenseMatrix(numRows, numCols); // TODO rejigger tests so that it doesn't expect this particular seed Random r = new Random(1234L); for (int row = 0; row < numRows; row++) { Vector v = new DenseVector(numCols); for (int col = 0; col < numCols; col++) { double val = r.nextGaussian(); v.set(col, val); } v.assign(Functions.MULT, 1/((row + 1) * v.norm(2))); matrix.assignRow(row, v); } if (symmetric) { return matrix.times(matrix.transpose()); } return matrix; }
@Test public void testAssignRow() { double[] data = {2.1, 3.2}; test.assignRow(1, new DenseVector(data)); assertEquals("test[1][0]", 2.1, test.getQuick(1, 0), EPSILON); assertEquals("test[1][1]", 3.2, test.getQuick(1, 1), EPSILON); }
@Test public void testAssignRow() { double[] data = {2.1, 3.2}; test.assignRow(1, new DenseVector(data)); assertEquals("test[1][0]", 2.1, test.getQuick(1, 0), EPSILON); assertEquals("test[1][1]", 3.2, test.getQuick(1, 1), EPSILON); }
eigens.assignRow(i, currentEigen); eigenValues.add(eigenValue); state.setCurrentEigenValues(eigenValues);
public void renormalize() { for (int x = 0; x < numTopics; x++) { topicTermCounts.assignRow(x, topicTermCounts.viewRow(x).normalize(1)); topicSums.assign(1.0); } }
public void renormalize() { for (int x = 0; x < numTopics; x++) { topicTermCounts.assignRow(x, topicTermCounts.viewRow(x).normalize(1)); topicSums.assign(1.0); } }
@Override public Matrix cross(Vector other) { Matrix result = matrixLike(size, other.size()); Iterator<Vector.Element> it = iterateNonZero(); while (it.hasNext()) { Vector.Element e = it.next(); int row = e.index(); result.assignRow(row, other.times(getQuick(row))); } return result; }
@Override public Matrix cross(Vector other) { Matrix result = matrixLike(size, other.size()); for (int row = 0; row < size; row++) { result.assignRow(row, other.times(getQuick(row))); } return result; }
@Test(expected = CardinalityException.class) public void testAssignRowCardinality() { double[] data = {2.1, 3.2, 4.3}; test.assignRow(1, new DenseVector(data)); }
private Matrix YtransposeY(OpenIntObjectHashMap<Vector> Y) { Matrix compactedY = new DenseMatrix(Y.size(), numFeatures); IntArrayList indexes = Y.keys(); indexes.quickSort(); int row = 0; for (int index : indexes.elements()) { compactedY.assignRow(row++, Y.get(index)); } return compactedY.transpose().times(compactedY); }