public class KDDMatrix extends java.lang.Object implements IAbstractMatrix<java.lang.Double>
The KDDMatrix is a class that encapsulates data representing an nxm matrix. It can be constructed from a valid IDataProvider. The IDataProvider must provide a feature list that contains three features: "Data", which corresponds to the list of IData elements of the matrix, in row major order; "Number of Rows", which corresponds to an IData element detailing the number of rows in the matrix; and "Number of Columns", which corresponds to an IData element detailing the number of columns in the matrix. KDDMatrix provides methods for matrix arithmetic, transposition, normalizing rows and columns, and scaling by an uncertainty matrix.
Constructor and Description |
---|
KDDMatrix()
The nullary constructor.
|
KDDMatrix(java.util.ArrayList<java.lang.Double> elements,
int nRows,
int nCols)
The Constructor.
|
KDDMatrix(IDataProvider data)
The constructor, takes a valid set of IData and constructs this matrix
|
KDDMatrix(int nRows,
int nCols)
This constructor creates a KDDMatrix of size nRows by nCols with all
elements equal to 0.0.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(IAbstractMatrix<java.lang.Double> matToAdd)
This method adds the given KDDMatrix to this one.
|
int |
addColumn()
This method adds a column to this KDDMatrix.
|
int |
addRow()
This method adds a row to this KDDMatrix.
|
void |
columnNormalize()
This method column normalizes the matrix, ie, sums each column and
divides each column element by that sum.
|
void |
copy(KDDMatrix other)
Create a copy of this KDDMatrix and return it.
|
boolean |
deleteColumn()
This method removes the last column from this KDDMatrix.
|
boolean |
deleteRow()
This method removes the last row from this KDDMatrix.
|
boolean |
equals(KDDMatrix matrix)
This method indicates whether or not this KDDMatrix and the given
KDDMatrix argument are equal.
|
KDDMatrix |
getColumn(int index)
Get the N-dimensional (N = nRows) column vector at the given index.
|
IDataProvider |
getDataProvider()
Return the IDataProvider used to construct this KDDMatrix.
|
java.lang.Double |
getElement(int rowIndex,
int colIndex)
Get the element value at the given row and column index.Returns null if
invalid index.
|
KDDMatrix |
getRow(int index)
Get the N-dimensional (N = nRows) row vector at the given index.
|
int |
hashCode()
This operation returns the hashcode value of the KDDMatrix.
|
int |
numberOfColumns()
Returns the number of columns in this matrix.
|
int |
numberOfRows()
Returns the number of rows in this matrix
|
void |
printMatrix() |
void |
rowNormalize()
This method row normalizes the matrix, ie, sums each row and divides each
row element by that sum.
|
boolean |
scaleByUncertainty(KDDMatrix uncertainty)
This operation scales the difference of the data by the point uncertainty
at that point.
|
void |
setData(IDataProvider data)
This method sets or resets this KDDMatrix matrix elements with the given
set of IData.
|
boolean |
setElement(int rowIndex,
int colIndex,
java.lang.Double value)
Set the value of the individual matrix element at index i,j.
|
boolean |
subtract(IAbstractMatrix<java.lang.Double> matToSubtract)
This method subtracts the given matrix from this KDDMatrix: this -
matToSubtract.
|
void |
transpose()
This method transposes this KDDMatrix.
|
void |
zeroMatrix() |
public KDDMatrix(IDataProvider data) throws java.lang.IllegalArgumentException
The constructor, takes a valid set of IData and constructs this matrix
data
- java.lang.IllegalArgumentException
public KDDMatrix()
The nullary constructor. Initializes a 1x1 matrix. Clients can set the IData for this KDDMatrix immediately after using this constructor with the setData method.
public KDDMatrix(int nRows, int nCols)
This constructor creates a KDDMatrix of size nRows by nCols with all elements equal to 0.0.
nRows
- nCols
- public KDDMatrix(java.util.ArrayList<java.lang.Double> elements, int nRows, int nCols)
The Constructor.
elements
- nRows
- nCols
- public boolean subtract(IAbstractMatrix<java.lang.Double> matToSubtract)
This method subtracts the given matrix from this KDDMatrix: this - matToSubtract.
matToSubtract
- public boolean add(IAbstractMatrix<java.lang.Double> matToAdd)
This method adds the given KDDMatrix to this one.
matToAdd
- public void rowNormalize()
This method row normalizes the matrix, ie, sums each row and divides each row element by that sum.
public void columnNormalize()
This method column normalizes the matrix, ie, sums each column and divides each column element by that sum.
public boolean scaleByUncertainty(KDDMatrix uncertainty)
This operation scales the difference of the data by the point uncertainty at that point.
uncertainty
- public java.lang.Double getElement(int rowIndex, int colIndex)
Get the element value at the given row and column index.Returns null if invalid index.
getElement
in interface IAbstractMatrix<java.lang.Double>
rowIndex
- colIndex
- public boolean setElement(int rowIndex, int colIndex, java.lang.Double value)
Set the value of the individual matrix element at index i,j.
setElement
in interface IAbstractMatrix<java.lang.Double>
rowIndex
- colIndex
- value
- public int numberOfRows()
Returns the number of rows in this matrix
numberOfRows
in interface IAbstractMatrix<java.lang.Double>
public int numberOfColumns()
Returns the number of columns in this matrix.
numberOfColumns
in interface IAbstractMatrix<java.lang.Double>
public void transpose()
This method transposes this KDDMatrix.
transpose
in interface IAbstractMatrix<java.lang.Double>
public void setData(IDataProvider data) throws java.lang.IllegalArgumentException
This method sets or resets this KDDMatrix matrix elements with the given set of IData.
data
- java.lang.IllegalArgumentException
public int addRow()
This method adds a row to this KDDMatrix. The elements are initialized to zero and it returns the rows index.
public int addColumn()
This method adds a column to this KDDMatrix. The elements are initialized to 0 and it returns the columns index.
public boolean deleteRow()
This method removes the last row from this KDDMatrix. Returns a boolean to indicate success or failure.
deleteRow
in interface IAbstractMatrix<java.lang.Double>
public boolean deleteColumn()
This method removes the last column from this KDDMatrix. Returns boolean to indicate success or failure.
deleteColumn
in interface IAbstractMatrix<java.lang.Double>
public IDataProvider getDataProvider()
Return the IDataProvider used to construct this KDDMatrix.
public KDDMatrix getRow(int index)
Get the N-dimensional (N = nRows) row vector at the given index. Returned as a KDDMatrix with number of columns equal to N and number of rows equal to 1.
index
- public KDDMatrix getColumn(int index)
Get the N-dimensional (N = nRows) column vector at the given index. Returned as a KDDMatrix with number of columns equal to 1 and number of rows equal to N.
index
- public boolean equals(KDDMatrix matrix)
This method indicates whether or not this KDDMatrix and the given KDDMatrix argument are equal.
matrix
- public int hashCode()
This operation returns the hashcode value of the KDDMatrix.
hashCode
in class java.lang.Object
The hashcode
public void copy(KDDMatrix other)
Create a copy of this KDDMatrix and return it.
other
- public void zeroMatrix()
public void printMatrix()