Apache Spark 2.x Machine Learning Cookbook
上QQ阅读APP看书,第一时间看更新

How it works...

  1. The signatures for this method constructor are (Column-major dense matrix):
DenseMatrix(int numRows, int numCols, double[] values)
DenseMatrix(int numRows, int numCols, double[] values, boolean isTransposed)
  1. The method inherits from the following which makes their concrete methods available to all routines:
    • interface class java.lang.Object

    • java.io.Serializable

    • Matrix

  2. There are several method calls that are of interest:
    1. Generate the diagonal matrix from the supplied values in the vector:

static DenseMatrix(Vector vector) 
    1. Create an identity matrix. An identity matrix is a matrix that has diagonals as 1 and any other element as 0:
static eye(int n) 
    1. Keep track of whether the matrix is transposed:
boolean isTransposed()
    1. Create a matrix with a set of random numbers - drawn from uniform distribution:
static DenseMatrix rand(int numRows, int numCols, java.util.Random rng) 
    1. Create a matrix with a set of random numbers - drawn from gaussian distribution:
static DenseMatrix randn(int numRows, int numCols, java.util.Random rng) 
    1. Transpose the matrix:
DenseMatrix transpose() 
    1. Make a deep copy of the vector:
DenseVector Copy() 
    1. Convert to a SparseVector. You will do this if your vector is long and the density decreases after a number of operations (for example, zero out non-contributing members):
SparseVector toSparse() 
    1. Find the number of non-zero elements. This is useful so you can convert on-the-fly to a SparseVector if the density ID is low:
Int numNonzeros()
    1. Get all the values stored in Matrix:
Double[] Values()