Package org.apache.spark.mllib.linalg
Class DenseMatrix
Object
org.apache.spark.mllib.linalg.DenseMatrix
- All Implemented Interfaces:
- Serializable,- Matrix
Column-major dense matrix.
 The entry values are stored in a single array of doubles with columns listed in sequence.
 For example, the following matrix
 
   1.0 2.0
   3.0 4.0
   5.0 6.0
 [1.0, 3.0, 5.0, 2.0, 4.0, 6.0].
 
 param:  numRows number of rows
 param:  numCols number of columns
 param:  values matrix entries in column major if not transposed or in row major otherwise
 param:  isTransposed whether the matrix is transposed. If true, values stores the matrix in
                     row major.
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionDenseMatrix(int numRows, int numCols, double[] values) Column-major dense matrix.DenseMatrix(int numRows, int numCols, double[] values, boolean isTransposed) 
- 
Method SummaryModifier and TypeMethodDescriptiondoubleapply(int i, int j) Gets the (i, j)-th element.asML()Convert this matrix to the new mllib-local representation.scala.collection.Iterator<Vector>colIter()Returns an iterator of column vectors.copy()Get a deep copy of the matrix.static DenseMatrixGenerate a diagonal matrix inDenseMatrixformat from the supplied values.booleanstatic DenseMatrixeye(int n) Generate an Identity Matrix inDenseMatrixformat.static DenseMatrixConvert new linalg type to spark.mllib type.inthashCode()booleanFlag that keeps track whether the matrix is transposed or not.intFind the number of values stored explicitly.intnumCols()Number of columns.intFind the number of non-zero active values.intnumRows()Number of rows.static DenseMatrixones(int numRows, int numCols) Generate aDenseMatrixconsisting of ones.static DenseMatrixGenerate aDenseMatrixconsisting ofi.i.d.uniform random numbers.static DenseMatrixGenerate aDenseMatrixconsisting ofi.i.d.gaussian random numbers.toSparse()Generate aSparseMatrixfrom the givenDenseMatrix.Transpose the Matrix.double[]values()static DenseMatrixzeros(int numRows, int numCols) Generate aDenseMatrixconsisting of zeros.
- 
Constructor Details- 
DenseMatrixpublic DenseMatrix(int numRows, int numCols, double[] values, boolean isTransposed) 
- 
DenseMatrixpublic DenseMatrix(int numRows, int numCols, double[] values) Column-major dense matrix. The entry values are stored in a single array of doubles with columns listed in sequence. For example, the following matrix
 is stored as1.0 2.0 3.0 4.0 5.0 6.0[1.0, 3.0, 5.0, 2.0, 4.0, 6.0].- Parameters:
- numRows- number of rows
- numCols- number of columns
- values- matrix entries in column major
 
 
- 
- 
Method Details- 
zerosGenerate aDenseMatrixconsisting of zeros.- Parameters:
- numRows- number of rows of the matrix
- numCols- number of columns of the matrix
- Returns:
- DenseMatrixwith size- numRowsx- numColsand values of zeros
 
- 
onesGenerate aDenseMatrixconsisting of ones.- Parameters:
- numRows- number of rows of the matrix
- numCols- number of columns of the matrix
- Returns:
- DenseMatrixwith size- numRowsx- numColsand values of ones
 
- 
eyeGenerate an Identity Matrix inDenseMatrixformat.- Parameters:
- n- number of rows and columns of the matrix
- Returns:
- DenseMatrixwith size- nx- nand values of ones on the diagonal
 
- 
randGenerate aDenseMatrixconsisting ofi.i.d.uniform random numbers.- Parameters:
- numRows- number of rows of the matrix
- numCols- number of columns of the matrix
- rng- a random number generator
- Returns:
- DenseMatrixwith size- numRowsx- numColsand values in U(0, 1)
 
- 
randnGenerate aDenseMatrixconsisting ofi.i.d.gaussian random numbers.- Parameters:
- numRows- number of rows of the matrix
- numCols- number of columns of the matrix
- rng- a random number generator
- Returns:
- DenseMatrixwith size- numRowsx- numColsand values in N(0, 1)
 
- 
diagGenerate a diagonal matrix inDenseMatrixformat from the supplied values.- Parameters:
- vector- a- Vectorthat will form the values on the diagonal of the matrix
- Returns:
- Square DenseMatrixwith sizevalues.lengthxvalues.lengthandvalueson the diagonal
 
- 
fromMLConvert new linalg type to spark.mllib type. Light copy; only copies references- Parameters:
- m- (undocumented)
- Returns:
- (undocumented)
 
- 
numRowspublic int numRows()Description copied from interface:MatrixNumber of rows.
- 
numColspublic int numCols()Description copied from interface:MatrixNumber of columns.
- 
valuespublic double[] values()
- 
isTransposedpublic boolean isTransposed()Description copied from interface:MatrixFlag that keeps track whether the matrix is transposed or not. False by default.- Specified by:
- isTransposedin interface- Matrix
 
- 
equals
- 
hashCodepublic int hashCode()
- 
applypublic double apply(int i, int j) Description copied from interface:MatrixGets the (i, j)-th element.
- 
copyDescription copied from interface:MatrixGet a deep copy of the matrix.
- 
transposeDescription copied from interface:MatrixTranspose the Matrix. Returns a newMatrixinstance sharing the same underlying data.
- 
numNonzerospublic int numNonzeros()Description copied from interface:MatrixFind the number of non-zero active values.- Specified by:
- numNonzerosin interface- Matrix
- Returns:
- (undocumented)
 
- 
numActivespublic int numActives()Description copied from interface:MatrixFind the number of values stored explicitly. These values can be zero as well.- Specified by:
- numActivesin interface- Matrix
- Returns:
- (undocumented)
 
- 
toSparseGenerate aSparseMatrixfrom the givenDenseMatrix. The new matrix will have isTransposed set to false.- Returns:
- (undocumented)
 
- 
colIterDescription copied from interface:MatrixReturns an iterator of column vectors. This operation could be expensive, depending on the underlying storage.
- 
asMLDescription copied from interface:MatrixConvert this matrix to the new mllib-local representation. This does NOT copy the data; it copies references.
 
-