All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home

Class weka.core.Matrix

java.lang.Object
   |
   +----weka.core.Matrix

public class Matrix
extends Object
Class for performing operations on a matrix of floating-point values. Some of the code is adapted from Numerical Recipes in C.

Version:
$Revision: 1.3 $
Author:
Yong Wang (yongwang@cs.waikato.ac.nz), Eibe Frank (eibe@cs.waikato.ac.nz), Len Trigg (eibe@cs.waikato.ac.nz)

Constructor Index

 o Matrix(int, int)
Constructs a matrix.
 o Matrix(Reader)
Reads a matrix from a reader.

Method Index

 o getElement(int, int)
Returns the value of a cell in the matrix.
 o lubksb(int[], double[])
Performs LU backward substitution.
 o ludcmp()
Performs LU decomposition.
 o main(String[])
Main method for testing this class.
 o multiply(Matrix)
Reurns the multiplication of two matrices
 o numColumns()
Returns the number of columns in the matrix.
 o numRows()
Returns the number of rows in the matrix.
 o regression(Matrix)
Performs a (ridged) linear regression.
 o regression(Matrix, double[])
Performs a weighted (ridged) linear regression.
 o setColumn(int, double[])
Sets a column of the matrix to the given column.
 o setElement(int, int, double)
Sets an element of the matrix to the given value.
 o setRow(int, double[])
Sets a row of the matrix to the given row.
 o toString()
Converts a matrix to a string
 o transpose()
Returns the transpose of a matrix
 o write(Writer)
Writes out a matrix

Constructors

 o Matrix
 public Matrix(int nr,
               int nc)
Constructs a matrix.

Parameters:
nr - the number of rows
nc - the number of columns
 o Matrix
 public Matrix(Reader r) throws Exception
Reads a matrix from a reader. The first line in the file should contain the number of rows and columns. Subsequent lines contain elements of the matrix.

Parameters:
r - the reader containing the matrix
Throws: Exception
if an error occurs

Methods

 o write
 public void write(Writer w) throws Exception
Writes out a matrix

Parameters:
w - the output Writer
Throws: Exception
if an error occurs
 o getElement
 public final double getElement(int rowIndex,
                                int columnIndex)
Returns the value of a cell in the matrix.

Parameters:
rowIndex - the row's index
columnIndex - the column's index
Returns:
the value
 o numRows
 public final int numRows()
Returns the number of rows in the matrix.

Returns:
the number of rows
 o numColumns
 public final int numColumns()
Returns the number of columns in the matrix.

Returns:
the number of columns
 o setElement
 public final void setElement(int rowIndex,
                              int columnIndex,
                              double value)
Sets an element of the matrix to the given value.

Parameters:
rowIndex - the row's index
columnIndex - the column's index
value - the value
 o setRow
 public final void setRow(int index,
                          double newRow[])
Sets a row of the matrix to the given row. Performs a deep copy.

Parameters:
index - the row's index
newRow - an array of doubles
 o setColumn
 public final void setColumn(int index,
                             double newColumn[])
Sets a column of the matrix to the given column. Performs a deep copy.

Parameters:
index - the column's index
newColumn - an array of doubles
 o toString
 public final String toString()
Converts a matrix to a string

Returns:
the converted string
Overrides:
toString in class Object
 o transpose
 public final Matrix transpose()
Returns the transpose of a matrix

Returns:
the transposed matrix
 o multiply
 public final Matrix multiply(Matrix b)
Reurns the multiplication of two matrices

Parameters:
b - the multiplication matrix
Returns:
the product matrix
 o regression
 public final double[] regression(Matrix y) throws Exception
Performs a (ridged) linear regression.

Parameters:
y - the dependent variable vector
Returns:
the coefficients
Throws: Exception
if not successful
 o regression
 public final double[] regression(Matrix y,
                                  double w[]) throws Exception
Performs a weighted (ridged) linear regression.

Parameters:
y - the dependent variable vector
w - the array of data point weights
Returns:
the coefficients
Throws: Exception
if not successful
 o lubksb
 public final void lubksb(int indx[],
                          double b[])
Performs LU backward substitution. Adapted from Numerical Recipes in C.

Parameters:
indx - the indices of the permutation
b - the double vector, storing constant terms in the equation set; it later stores the computed coefficients' values
 o ludcmp
 public final int[] ludcmp() throws Exception
Performs LU decomposition. Adapted from Numerical Recipes in C.

Returns:
the indices of the permutation
Throws: Exception
if the matrix is singular
 o main
 public static void main(String ops[])
Main method for testing this class.


All Packages  Class Hierarchy  This Package  Previous  Next  Index  WEKA's home