comirva.data
Class DataMatrix

java.lang.Object
  extended by comirva.data.DataMatrix
All Implemented Interfaces:
Serializable, Cloneable

public class DataMatrix
extends Object
implements Serializable, Cloneable

This class implements a data matrix containing double values. The data structure is created using a Vector of Vectors.

See Also:
Serialized Form

Constructor Summary
DataMatrix()
          Creates an empty DataMatrix-instance and initializes rows- and columns-Vectors.
DataMatrix(int rows, int cols, Double initValue)
          Creates an empty DataMatrix-instance and with rows rows and cols cols.
DataMatrix(String name)
          Creates an empty DataMatrix-instance, initializes rows- and columns-Vectors, and sets the name of the DataMatrix to the name argument.
 
Method Summary
 void addRowValues(Vector<Double> data, int row)
          Adds the values of the Vector data to the row-values of the matrix indicated by the argument row.
 void addValue(Double value)
          Inserts the Double-instance value into the DataMatrix-instance at the current row.
 void addValue(Double value, boolean boolNewRow)
          Inserts the Double-instance value into the DataMatrix-instance.
 void addValue(Double value, int row)
          Inserts the Double-instance value into the DataMatrix-instance at row row.
 Object clone()
          Implements the clone() function, so we can easily produce copies of DataMatrices. vecColCurrent set to the Vector which represents the first row.
static Jama.Matrix dataMatrixToJamaMatrix(DataMatrix dm)
          Converts a DataMatrix to a Jama Matrix.
static DataMatrix doubleArrayToDataMatrix(double[][] data)
          Converts a double[][] into a DataMatrix.
 Vector<Double> getColumn(int col)
          Returns the Vector of the column given by the argument col.
 String getName()
          Returns the name of the DataMatrix.
 int getNumberOfColumns()
          Returns the number of columns in the DataMatrix.
 int getNumberOfRows()
          Returns the number of rows in the DataMatrix.
 Vector<Double> getRow(int row)
          Returns the Vector of the row given by the argument row.
 Double getValueAtPos(int row, int col)
          Returns the value of the element that can be found at column col and row row in the DataMatrix-instance.
 void insertRow(Vector<Double> data, int index)
          Inserts a row at the given index.
 boolean isBooleanMatrix()
          Checks whether the DataMatrix contains only the values 0 and 1.
static DataMatrix jamaMatrixToDataMatrix(Jama.Matrix m)
          Converts a Jama Matrix into a DataMatrix.
 void normalize(double lowerBound, double upperBound)
          Normalizes the DataMatrix linearly using the complete data matrix as scope.
 void normalize(double lowerBound, double upperBound, boolean isLinear)
          Normalizes the DataMatrix using the complete data matrix as scope.
 void normalize(double lowerBound, double upperBound, boolean isLinear, int scope)
          Normalizes the DataMatrix.
 void printMatrix()
          Prints the DataMatrix-instance to java.lang.System.out.
 void removeLastAddedElement()
          Removes the latest added Vector in the DataMatrix.
 void setName(String name)
          Sets the name of DataMatrix to the value of the parameter name.
 void setRowValues(Vector<Double> data, int row)
          Sets a specific row in the DataMatrix.
 void setValueAtPos(Double value, int row, int col)
          Sets the value at a specific position of the DataMatrix-instance.
 void startNewRow()
          Starts a new row in the DataMatrix.
 void startNewRow(int count)
          Starts count new rows in the DataMatrix.
 double[][] toDoubleArray()
          Returns a double[][] representation of the DataMatrix.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DataMatrix

public DataMatrix()
Creates an empty DataMatrix-instance and initializes rows- and columns-Vectors.


DataMatrix

public DataMatrix(String name)
Creates an empty DataMatrix-instance, initializes rows- and columns-Vectors, and sets the name of the DataMatrix to the name argument.

Parameters:
name - a String representing the name of the DataMatrix

DataMatrix

public DataMatrix(int rows,
                  int cols,
                  Double initValue)
Creates an empty DataMatrix-instance and with rows rows and cols cols. So after the creation of the DataMatrix you can easily fill the matrix with several setValueAtPos()s. created by MSt

Method Detail

doubleArrayToDataMatrix

public static DataMatrix doubleArrayToDataMatrix(double[][] data)
Converts a double[][] into a DataMatrix.

Parameters:
data - the input as double[][]
Returns:
a DataMatrix holding the data

jamaMatrixToDataMatrix

public static DataMatrix jamaMatrixToDataMatrix(Jama.Matrix m)
Converts a Jama Matrix into a DataMatrix.

Parameters:
data - a Matrix holding the input data
Returns:
a DataMatrix holding the data

dataMatrixToJamaMatrix

public static Jama.Matrix dataMatrixToJamaMatrix(DataMatrix dm)
Converts a DataMatrix to a Jama Matrix.

Parameters:
dm - a DataMatrix holding the input data
Returns:
a Matrix holding the data

addValue

public void addValue(Double value)
Inserts the Double-instance value into the DataMatrix-instance at the current row.

Parameters:
value - the Double-instance which should be inserted into the matrix

addValue

public void addValue(Double value,
                     boolean boolNewRow)
Inserts the Double-instance value into the DataMatrix-instance.
If boolNewRow is true, a new row is created and value is inserted as first element into the new row. If boolNewRow is false, value is inserted into the current row.

Parameters:
value - the Double-instance which should be inserted into the matrix
boolNewRow - a boolean indicating if value should be inserted into a new row or into the current row

addValue

public void addValue(Double value,
                     int row)
Inserts the Double-instance value into the DataMatrix-instance at row row. It is inserted in the Row-Vector.

Parameters:
row - the row into which the value is inserted created by MSt

startNewRow

public void startNewRow()
Starts a new row in the DataMatrix.


startNewRow

public void startNewRow(int count)
Starts count new rows in the DataMatrix.

Parameters:
count - the number of new rows to be inserted into the DataMatrix created by MS

removeLastAddedElement

public void removeLastAddedElement()
Removes the latest added Vector in the DataMatrix.
It is necessary in order to delete the empty element which is added by the MatrixDataFileLoaderThread.


toDoubleArray

public double[][] toDoubleArray()
Returns a double[][] representation of the DataMatrix.

Returns:
a double[][] containing the values of the DataMatrix

printMatrix

public void printMatrix()
Prints the DataMatrix-instance to java.lang.System.out.


getValueAtPos

public Double getValueAtPos(int row,
                            int col)
Returns the value of the element that can be found at column col and row row in the DataMatrix-instance.

Parameters:
row - the row of the requested value in the matrix
col - the column of the requested value in the matrix
Returns:
a Double containing the value of the requested element

getRow

public Vector<Double> getRow(int row)
Returns the Vector of the row given by the argument row.

Parameters:
row - the row in the matrix that should be returned as a Vector
Returns:
a Vector representing the requested row in the matrix

getColumn

public Vector<Double> getColumn(int col)
Returns the Vector of the column given by the argument col.

Parameters:
col - the column in the matrix that should be returned as a Vector
Returns:
a Vector representing the requested column in the matrix

setValueAtPos

public void setValueAtPos(Double value,
                          int row,
                          int col)
                   throws SizeMismatchException
Sets the value at a specific position of the DataMatrix-instance.

Parameters:
value - a Double representing the value
row - the row within the DataMatrix of the value that should be set
col - the column within the DataMatrix of the value that should be set
Throws:
SizeMismatchException

setRowValues

public void setRowValues(Vector<Double> data,
                         int row)
                  throws SizeMismatchException
Sets a specific row in the DataMatrix. The Vector data is inserted at row row. The original data is discarded.

Parameters:
data - a Vector containing the data to be inserted
row - the row where the data is inserted
Throws:
SizeMismatchException

addRowValues

public void addRowValues(Vector<Double> data,
                         int row)
                  throws SizeMismatchException
Adds the values of the Vector data to the row-values of the matrix indicated by the argument row.

Parameters:
data - a Vector containing the values to be added
row - the row indicating the position where the values are added
Throws:
SizeMismatchException

normalize

public void normalize(double lowerBound,
                      double upperBound)
Normalizes the DataMatrix linearly using the complete data matrix as scope.

Parameters:
lowerBound - the lower bound of the projection range
upperBound - the upper bound of the projection range

normalize

public void normalize(double lowerBound,
                      double upperBound,
                      boolean isLinear)
Normalizes the DataMatrix using the complete data matrix as scope.

Parameters:
lowerBound - the lower bound of the projection range
upperBound - the upper bound of the projection range
isLinear - linear or logarithmic normalization

normalize

public void normalize(double lowerBound,
                      double upperBound,
                      boolean isLinear,
                      int scope)
Normalizes the DataMatrix.

Parameters:
lowerBound - the lower bound of the projection range
upperBound - the upper bound of the projection range
isLinear - linear or logarithmic normalization
scope - indicates whether the normalization scope is the complete data matrix, normalization is performed for every row, or for every column separately

getNumberOfRows

public int getNumberOfRows()
Returns the number of rows in the DataMatrix.

Returns:
the number of rows in the matrix

isBooleanMatrix

public boolean isBooleanMatrix()
Checks whether the DataMatrix contains only the values 0 and 1. If this is the case, true is returned, if not, false.

Returns:
true if the instance of DataMatrix only contains the values 0 and 1, false otherwise

getNumberOfColumns

public int getNumberOfColumns()
Returns the number of columns in the DataMatrix.

Returns:
the number of columns in the matrix

setName

public void setName(String name)
Sets the name of DataMatrix to the value of the parameter name.

Parameters:
name - the name that is to be given to the matrix

getName

public String getName()
Returns the name of the DataMatrix.

Returns:
a String containing the name of the DataMatrix

clone

public Object clone()
Implements the clone() function, so we can easily produce copies of DataMatrices. vecColCurrent set to the Vector which represents the first row. created by MSt

Overrides:
clone in class Object

insertRow

public void insertRow(Vector<Double> data,
                      int index)
               throws SizeMismatchException
Inserts a row at the given index.

Parameters:
data -
index - has to be equal or greater than 0, and less than or equal to the number of rows.
Throws:
SizeMismatchException