@Override public Matrix init(int rows, int cols) { final SparseMatrix rand = (SparseMatrix) smf.createUniformRandom(rows, cols, min, max, random); final Matrix ret = smf.createMatrix(rows, cols); for (int i = 0; i < rows; i++) { if (this.random.nextDouble() > sparcity) { ret.setRow(i, rand.getRow(i)); } } return ret; } }
@Override public Matrix init(int rows, int cols) { final Matrix ret = smf.createMatrix(rows, cols); final Vector oneRow = CFMatrixUtils.plusInplace(smf.createMatrix(1, cols), 1).getRow(0); for (int i = 0; i < rows; i++) { if (this.random.nextDouble() > sparcity) { ret.setRow(i, oneRow.clone()); } } return ret; }
/** * Creates a new matrix by copying the given set of row vectors. * * @param rows * The row vectors to create a matrix from. Must all be the same * dimensionality. * @return * A new matrix whose rows are equal to the given set of rows. */ public MatrixType copyRowVectors( final Collection<? extends Vectorizable> rows) { // Create the matrix. final int numRows = rows.size(); final int numColumns = VectorUtil.safeGetDimensionality( CollectionUtil.getFirst(rows)); final MatrixType result = this.createMatrix(numRows, numColumns); // Fill in the matrix with the rows. int rowIndex = 0; for (Vectorizable row : rows) { result.setRow(rowIndex, row.convertToVector()); rowIndex++; } return result; }
/** * Creates a new matrix by copying the given set of row vectors. * * @param rows * The row vectors to create a matrix from. Must all be the same * dimensionality. * @return * A new matrix whose rows are equal to the given set of rows. */ public MatrixType copyRowVectors( final Collection<? extends Vectorizable> rows) { // Create the matrix. final int numRows = rows.size(); final int numColumns = VectorUtil.safeGetDimensionality( CollectionUtil.getFirst(rows)); final MatrixType result = this.createMatrix(numRows, numColumns); // Fill in the matrix with the rows. int rowIndex = 0; for (Vectorizable row : rows) { result.setRow(rowIndex, row.convertToVector()); rowIndex++; } return result; }
/** * Creates a new matrix by copying the given set of row vectors. * * @param rows * The row vectors to create a matrix from. Must all be the same * dimensionality. * @return * A new matrix whose rows are equal to the given set of rows. */ public MatrixType copyRowVectors( final Collection<? extends Vectorizable> rows) { // Create the matrix. final int numRows = rows.size(); final int numColumns = VectorUtil.safeGetDimensionality( CollectionUtil.getFirst(rows)); final MatrixType result = this.createMatrix(numRows, numColumns); // Fill in the matrix with the rows. int rowIndex = 0; for (Vectorizable row : rows) { result.setRow(rowIndex, row.convertToVector()); rowIndex++; } return result; }
protected void cleanupAlgorithm() { int N = this.getData().iterator().next().getDimensionality(); Matrix Umatrix = MatrixFactory.getDefault().createMatrix( this.getNumComponents(), N ); for( int i = 0; i < this.getNumComponents(); i++ ) { // Normalize each Vector by its 2-norm (unit length) Vector ui = this.components.get(i); Umatrix.setRow( i, ui.unitVector() ); } this.setResult( new PrincipalComponentsAnalysisFunction( this.mean, new MultivariateDiscriminant( Umatrix ) ) ); }
for (int i = 0; i < components.size(); i++) V.setRow(i, components.get(i));
protected void cleanupAlgorithm() { int N = this.getData().iterator().next().getDimensionality(); Matrix Umatrix = MatrixFactory.getDefault().createMatrix( this.getNumComponents(), N ); for( int i = 0; i < this.getNumComponents(); i++ ) { // Normalize each Vector by its 2-norm (unit length) Vector ui = this.components.get(i); Umatrix.setRow( i, ui.unitVector() ); } this.setResult( new PrincipalComponentsAnalysisFunction( this.mean, new MultivariateDiscriminant( Umatrix ) ) ); }
protected void cleanupAlgorithm() { int N = this.getData().iterator().next().getDimensionality(); Matrix Umatrix = MatrixFactory.getDefault().createMatrix( this.getNumComponents(), N ); for( int i = 0; i < this.getNumComponents(); i++ ) { // Normalize each Vector by its 2-norm (unit length) Vector ui = this.components.get(i); Umatrix.setRow( i, ui.unitVector() ); } this.setResult( new PrincipalComponentsAnalysisFunction( this.mean, new MultivariateDiscriminant( Umatrix ) ) ); }
for (int i = 0; i < components.size(); i++) V.setRow(i, components.get(i));
for (int i = 0; i < components.size(); i++) V.setRow(i, components.get(i));
for( Vector r : rowVectors ) retval.setRow( rowIndex, r ); rowIndex++;
for( Vector r : rowVectors ) retval.setRow( rowIndex, r ); rowIndex++;
@Override public Matrix init(int rows, int cols) { Matrix currentValues = getCurrentValues(); Vector mean = currentValues.sumOfRows().scale(1f/currentValues.getNumRows()); Matrix m = DenseMatrixFactoryMTJ.INSTANCE.createMatrix(rows, cols); for (int r = 0; r < m.getNumRows(); r++) { m.setRow(r, mean); } return m; }
@Override public Matrix predict(Matrix x) { final Matrix mult = this.u.transpose().times(x.transpose()).times(this.w); if(this.biasMode)mult.plusEquals(this.bias); final Vector ydiag = CFMatrixUtils.diag(mult); final Matrix createIdentity = SparseMatrixFactoryMTJ.INSTANCE.createIdentity(1, ydiag.getDimensionality()); createIdentity.setRow(0, ydiag); return createIdentity; } }
@Override public Matrix prox(Matrix W, double lambda) { final int nrows = W.getNumRows(); Matrix ret = SparseMatrixFactoryMTJ.INSTANCE.createMatrix(W.getNumRows(), W.getNumColumns()); final SparseRowMatrix Wrow = CFMatrixUtils.asSparseRow(W); // Matrix Wrow = W; ret = CFMatrixUtils.asSparseRow(ret); for (int r = 0; r < nrows; r++) { // Vector row = W.getRow(r); final SparseVector row = Wrow.getRow(r); final double rownorm = row.norm2(); if (rownorm > lambda) { final double scal = (rownorm - lambda) / rownorm; final Vector scaled = row.scale(scal); ret.setRow(r, scaled); } } return CFMatrixUtils.asSparseColumn(ret); }
this.factors.setRow(k, parameters.subVector(offset, offset + d - 1)); offset += d;
this.factors.setRow(k, parameters.subVector(offset, offset + d - 1)); offset += d;
this.factors.setRow(k, parameters.subVector(offset, offset + d - 1)); offset += d;