org.mymedialite.datatype
Class SymmetricMatrix<T>

java.lang.Object
  extended by org.mymedialite.datatype.SymmetricMatrix<T>
Type Parameters:
T - the type of the matrix entries
All Implemented Interfaces:
IMatrix<T>
Direct Known Subclasses:
CorrelationMatrix

public class SymmetricMatrix<T>
extends java.lang.Object
implements IMatrix<T>

Class for storing dense matrices. The data is stored in row-major mode. Indexes are zero-based.


Field Summary
protected  java.lang.Object[][] data
          Data array: data is stored in columns..
 int dim
          Dimension, the number of rows and columns.
 
Constructor Summary
SymmetricMatrix(int dim, T d)
          Initializes a new instance of the SymmetricMatrix class.
 
Method Summary
 IMatrix<T> createMatrix(int num_rows, int num_columns)
          Create a matrix with a given number of rows and columns.
 T get(int i, int j)
          Get the value at (i,j)
 void grow(int num_rows, int num_columns)
          Grows the matrix to the requested size, if necessary.
 void init(T d)
          Initialize the matrix with a default value
 boolean isSymmetric()
          True if the matrix is symmetric, false otherwise.
 int numberOfColumns()
          Get the number of columns of the matrix.
 int numberOfRows()
          Get the number of rows of the matrix.
 void set(int i, int j, T value)
          Set the value at (i,j)
 IMatrix<T> transpose()
          Get the transpose of the matrix, i.e.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

protected java.lang.Object[][] data
Data array: data is stored in columns..


dim

public int dim
Dimension, the number of rows and columns.

Constructor Detail

SymmetricMatrix

public SymmetricMatrix(int dim,
                       T d)
Initializes a new instance of the SymmetricMatrix class.

Parameters:
dim - the number of rows and columns
d - the default value for elements, or null
Method Detail

isSymmetric

public boolean isSymmetric()
Description copied from interface: IMatrix
True if the matrix is symmetric, false otherwise.

Specified by:
isSymmetric in interface IMatrix<T>
Returns:
true if the matrix is symmetric, false otherwise

numberOfRows

public int numberOfRows()
Description copied from interface: IMatrix
Get the number of rows of the matrix.

Specified by:
numberOfRows in interface IMatrix<T>
Returns:
the number of rows of the matrix

numberOfColumns

public int numberOfColumns()
Description copied from interface: IMatrix
Get the number of columns of the matrix.

Specified by:
numberOfColumns in interface IMatrix<T>
Returns:
rhe number of columns of the matrix

createMatrix

public IMatrix<T> createMatrix(int num_rows,
                               int num_columns)
Description copied from interface: IMatrix
Create a matrix with a given number of rows and columns.

Specified by:
createMatrix in interface IMatrix<T>
Parameters:
num_rows - the number of rows
num_columns - the number of columns
Returns:
a matrix with num_rows rows and num_column columns

init

public void init(T d)
Initialize the matrix with a default value

Parameters:
d - the default value

transpose

public IMatrix<T> transpose()
Description copied from interface: IMatrix
Get the transpose of the matrix, i.e. a matrix where rows and columns are interchanged.

Specified by:
transpose in interface IMatrix<T>
Returns:
the transpose of the matrix (copy)

get

public T get(int i,
             int j)
Description copied from interface: IMatrix
Get the value at (i,j)

Specified by:
get in interface IMatrix<T>
Parameters:
i - the row ID
j - the column ID
Returns:
the value at (i,j)

set

public void set(int i,
                int j,
                T value)
Description copied from interface: IMatrix
Set the value at (i,j)

Specified by:
set in interface IMatrix<T>
Parameters:
i - the row ID
j - the column ID
value - the value

grow

public void grow(int num_rows,
                 int num_columns)
Description copied from interface: IMatrix
Grows the matrix to the requested size, if necessary. The new entries are filled with zeros.

Specified by:
grow in interface IMatrix<T>
Parameters:
num_rows - the minimum number of rows
num_columns - the minimum number of columns