Package weka.core.matrix
Class MatrixHelper
- java.lang.Object
-
- weka.core.matrix.MatrixHelper
-
- Direct Known Subclasses:
MatrixHelper
public class MatrixHelper extends Object
Some matrix operations.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
-
-
Constructor Summary
Constructors Constructor Description MatrixHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static weka.core.matrix.Matrix
columnAsVector(weka.core.matrix.Matrix m, int columnIndex)
returns the given column as a vector (actually a n x 1 matrix)static boolean
equal(weka.core.matrix.Matrix m1, weka.core.matrix.Matrix m2)
Compares the two matrices.static boolean
equal(weka.core.matrix.Matrix m1, weka.core.matrix.Matrix m2, double epsilon)
Compares the two matrices.static weka.core.matrix.Matrix
getAll(weka.core.Instances instances)
returns the data as matrixstatic weka.core.matrix.Matrix
getDominantEigenVector(weka.core.matrix.Matrix m)
determines the dominant eigenvector for the given matrix and returns itstatic weka.core.matrix.Matrix
getVector(weka.core.matrix.Matrix m, int columnIndex)
returns the (column) vector of the matrix at the specified indexstatic weka.core.matrix.Matrix
getX(weka.core.Instance instance)
returns the data minus the class column as matrixstatic weka.core.matrix.Matrix
getX(weka.core.Instances instances)
returns the data minus the class column as matrixstatic weka.core.matrix.Matrix
getY(weka.core.Instance instance)
returns the data class column as matrixstatic weka.core.matrix.Matrix
getY(weka.core.Instances instances)
returns the data class column as matrixstatic weka.core.matrix.Matrix
getY(weka.core.Instances instances, int[] cols)
returns the data class columns as matrixstatic void
normalizeVector(weka.core.matrix.Matrix v)
normalizes the given vector (inplace)static void
setVector(weka.core.matrix.Matrix v, weka.core.matrix.Matrix m, int columnIndex)
stores the data from the (column) vector in the matrix at the specified indexstatic weka.core.Instances
toInstances(weka.core.Instances header, weka.core.matrix.Matrix x, weka.core.matrix.Matrix y)
returns the X and Y matrix again as Instances object, based on the given header (must have a class attribute set).
-
-
-
Method Detail
-
getAll
public static weka.core.matrix.Matrix getAll(weka.core.Instances instances)
returns the data as matrix- Parameters:
instances
- the data to work on- Returns:
- the data
-
getX
public static weka.core.matrix.Matrix getX(weka.core.Instances instances)
returns the data minus the class column as matrix- Parameters:
instances
- the data to work on- Returns:
- the data without class attribute
-
getX
public static weka.core.matrix.Matrix getX(weka.core.Instance instance)
returns the data minus the class column as matrix- Parameters:
instance
- the instance to work on- Returns:
- the data without the class attribute
-
getY
public static weka.core.matrix.Matrix getY(weka.core.Instances instances)
returns the data class column as matrix- Parameters:
instances
- the data to work on- Returns:
- the class attribute
-
getY
public static weka.core.matrix.Matrix getY(weka.core.Instances instances, int[] cols)
returns the data class columns as matrix- Parameters:
instances
- the data to work oncols
- the class columns- Returns:
- the class attribute
-
getY
public static weka.core.matrix.Matrix getY(weka.core.Instance instance)
returns the data class column as matrix- Parameters:
instance
- the instance to work on- Returns:
- the class attribute
-
toInstances
public static weka.core.Instances toInstances(weka.core.Instances header, weka.core.matrix.Matrix x, weka.core.matrix.Matrix y)
returns the X and Y matrix again as Instances object, based on the given header (must have a class attribute set).- Parameters:
header
- the format of the instance objectx
- the X matrix (data)y
- the Y matrix (class)- Returns:
- the assembled data
-
columnAsVector
public static weka.core.matrix.Matrix columnAsVector(weka.core.matrix.Matrix m, int columnIndex)
returns the given column as a vector (actually a n x 1 matrix)- Parameters:
m
- the matrix to work oncolumnIndex
- the column to return- Returns:
- the column as n x 1 matrix
-
setVector
public static void setVector(weka.core.matrix.Matrix v, weka.core.matrix.Matrix m, int columnIndex)
stores the data from the (column) vector in the matrix at the specified index- Parameters:
v
- the vector to store in the matrixm
- the receiving matrixcolumnIndex
- the column to store the values in
-
getVector
public static weka.core.matrix.Matrix getVector(weka.core.matrix.Matrix m, int columnIndex)
returns the (column) vector of the matrix at the specified index- Parameters:
m
- the matrix to work oncolumnIndex
- the column to get the values from- Returns:
- the column vector
-
getDominantEigenVector
public static weka.core.matrix.Matrix getDominantEigenVector(weka.core.matrix.Matrix m)
determines the dominant eigenvector for the given matrix and returns it- Parameters:
m
- the matrix to determine the dominant eigenvector for- Returns:
- the dominant eigenvector
-
normalizeVector
public static void normalizeVector(weka.core.matrix.Matrix v)
normalizes the given vector (inplace)- Parameters:
v
- the vector to normalize
-
equal
public static boolean equal(weka.core.matrix.Matrix m1, weka.core.matrix.Matrix m2)
Compares the two matrices.- Parameters:
m1
- the first matrixm2
- the second matrix- Returns:
- true if the same dimension and values, otherwise false
-
equal
public static boolean equal(weka.core.matrix.Matrix m1, weka.core.matrix.Matrix m2, double epsilon)
Compares the two matrices.- Parameters:
m1
- the first matrixm2
- the second matrixepsilon
- the minimal accepted difference between the cells- Returns:
- true if the same dimension and values, otherwise false
-
-