A General Analytic Matrix Program for constructing Zero of spark MLlib
When using spark MLlib, it is sometimes necessary to use some basic matrices (vectors), such as all-zero matrices, all-one matrices, and operations between matrices. Here are some common matrix manipulation methods:
Matrix:
Package utils
Import java.util.Random
/ * *
* dense matrix for encapsulating model parameters
, /
Class DenseMatrix (rowNum: Int, columnNum: Int) extends Serializable {
Var matrix = Array.ofDim [Double] (rowNum, columnNum)
Def rows (): Int = {
RowNum
}
Def columns (): Int = {
ColumnNum
}
Def apply (I: Int): Array [Double] = {
Matrix (I)
}
/ * *
* construct 0 matrix
, /
Def zeros (): DenseMatrix = {
For (I)