SG++
sgpp::base::DataMatrixSP Class Reference

A class to store two-dimensional data. More...

#include <DataMatrixSP.hpp>

Public Member Functions

void abs ()
 Sets all elements to their absolute value. More...
 
void add (const DataMatrixSP &matr)
 Adds the values from another DataMatrixSP to the current values. More...
 
void addReduce (DataVectorSP &reduction)
 Reduce the DataMatrixSP along the columns by adding all entries in one row. More...
 
void addReduce (DataVectorSP &reduction, DataVectorSP &beta, size_t start_beta)
 Reduce the DataMatrixSP along the columns by adding all entries in one row. More...
 
void addSize (size_t inc_nrows)
 Reserves memory for potentially inc_nrows new rows; the actual number of rows remains unchanged. More...
 
size_t appendRow ()
 Appends a new row and returns index of it. More...
 
size_t appendRow (const DataVectorSP &vec)
 Appends a new row with data contained in DataVectorSP vec and returns index of new row. More...
 
void componentwise_div (const DataMatrixSP &matr)
 Divides the current DataMatrixSP component-wise by another DataMatrixSP. More...
 
void componentwise_mult (const DataMatrixSP &matr)
 Multiplies the current DataMatrixSP component-wise with another DataMatrixSP. More...
 
void copyFrom (const DataMatrixSP &matr)
 Copies the data from another DataMatrixSP matr. More...
 
 DataMatrixSP (size_t nrows, size_t ncols)
 Create a two-dimensional DataMatrixSP with nrows rows and ncols columns (uninitialized values). More...
 
 DataMatrixSP (size_t nrows, size_t ncols, float value)
 Create a two-dimensional DataMatrixSP with nrows rows and ncols columns and initializes all elements with the same value. More...
 
 DataMatrixSP (const DataMatrixSP &matr)
 Create a new DataMatrixSP that is a copy of matr. More...
 
 DataMatrixSP (float *input, size_t nrows, size_t ncols)
 Create a new DataMatrixSP from a float array. More...
 
void expand (const DataVectorSP &expand)
 expands a given DataVectorSP into a DataMatrixSP. More...
 
float get (size_t row, size_t col) const
 Returns the value of the element at position [row,col]. More...
 
void getColumn (size_t col, DataVectorSP &vec) const
 Copies the values of a column to the DataVectorSP vec. More...
 
size_t getInc () const
 Get the current number of rows by which the DataMatrixSP is extended, if appendRow() is called and no unused rows are left. More...
 
size_t getNcols () const
 Returns the number of columns of the DataMatrixSP. More...
 
size_t getNrows () const
 Returns the number of rows of the DataMatrixSP. More...
 
size_t getNumberNonZero () const
 Determines the number of non-zero elements in the vector. More...
 
float * getPointer ()
 Returns pointer to float array containing underlying data. More...
 
const float * getPointer () const
 Returns const pointer to float array containing underlying data. More...
 
void getRow (size_t row, DataVectorSP &vec) const
 Copies the values of a row to the DataVectorSP vec. More...
 
void getRow (size_t row, std::vector< float > &vec) const
 Copies the values of a row to the std::vector vec. More...
 
size_t getSize () const
 Returns the total number of (used) elements, i.e., getNrows()*getNCols() More...
 
size_t getUnused () const
 Returns the number of unused rows. More...
 
float max (size_t col) const
 Returns the maximum value of column col. More...
 
float max () const
 Returns the maximum over all entries. More...
 
float min (size_t col) const
 Returns the minimum value of column col. More...
 
float min () const
 Returns the minimum over all entries. More...
 
void minmax (size_t col, float *min, float *max) const
 Determines minimum and maximum of column col. More...
 
void minmax (float *min, float *max) const
 Determines minimum and maximum over all entries. More...
 
void mult (const DataVectorSP &x, DataVectorSP &y)
 Multiplies the matrix with a vector x and stores the result in another vector y. More...
 
void mult (float scalar)
 Multiplies all elements by a constant factor. More...
 
void normalizeDimension (size_t d)
 Normalizes the d-th dimension (entries in the d-th column) to \([0,1]\). More...
 
void normalizeDimension (size_t d, float border)
 Normalizes the d-th dimension (entries in the d-th column) to \([border,1-border]\). More...
 
float & operator() (size_t row, size_t col)
 Returns the value of the element at position [row,col]. More...
 
const float & operator() (size_t row, size_t col) const
 Returns the value of the element at position [row,col]. More...
 
DataMatrixSPoperator= (const DataMatrixSP &matr)
 Copies the data from another DataMatrixSP. More...
 
void resize (size_t nrows)
 Resizes the DataMatrixSP to nrows rows. More...
 
void resize (size_t nrows, size_t ncols)
 Resizes the DataMatrixSP to nrows rows and ncols columns. More...
 
void resizeZero (size_t nrows)
 Resizes the DataMatrixSP to nrows rows. More...
 
void resizeZero (size_t nrows, size_t ncols)
 Resizes the DataMatrixSP to nrows rows and ncols columns. More...
 
void set (size_t row, size_t col, float value)
 Sets the element at position [row,col] to value. More...
 
void setAll (float value)
 Sets all entries of DataMatrixSP to value. More...
 
void setColumn (size_t col, const DataVectorSP &vec)
 Sets a column of the DataMatrixSP to the values of a DataVectorSP vec. More...
 
void setInc (size_t inc_rows)
 Sets the current number of rows by which the DataMatrixSP is extended, if appendRow() is called and no unused rows are left. More...
 
void setRow (size_t row, const DataVectorSP &vec)
 Sets a row of the DataMatrixSP to the values of a DataVectorSP vec. More...
 
void sqr ()
 Squares all elements of the DataMatrixSP. More...
 
void sqrt ()
 Takes the square root of all elements of the DataMatrixSP. More...
 
void sub (const DataMatrixSP &matr)
 Subtracts the values from another DataMatrixSP of the current values. More...
 
float sum () const
 Returns the sum of all elements. More...
 
void toString (std::string &text) const
 Writes the data stored in the DataMatrixSP into a string. More...
 
std::string toString () const
 Returns a description of the DataMatrixSP as a string. More...
 
void transpose ()
 Transposes this DataMatrixSP. More...
 
virtual ~DataMatrixSP ()
 Destructor. More...
 

Detailed Description

A class to store two-dimensional data.

Typically, DataMatrixSP would contain a set of (d-dimensional) data or evaluation points, i.e., the DataMatrixSP consists of d columns, and each row is one of the points. Thus, typical functionality like obtaining the maximum for a certain dimension (or attribute), or normalizing all data points to the unit interval for a certain dimension are provided.

This is an re-implementation of the standard DataMatrix for single precision floating point numbers in order to increase support for GPUs.

Constructor & Destructor Documentation

sgpp::base::DataMatrixSP::DataMatrixSP ( size_t  nrows,
size_t  ncols 
)

Create a two-dimensional DataMatrixSP with nrows rows and ncols columns (uninitialized values).

Parameters
nrowsNumber of rows
ncolsNumber of columns
sgpp::base::DataMatrixSP::DataMatrixSP ( size_t  nrows,
size_t  ncols,
float  value 
)

Create a two-dimensional DataMatrixSP with nrows rows and ncols columns and initializes all elements with the same value.

Parameters
nrowsNumber of rows
ncolsNumber of columns
valueValue for all entries

References setAll().

sgpp::base::DataMatrixSP::DataMatrixSP ( const DataMatrixSP matr)

Create a new DataMatrixSP that is a copy of matr.

Parameters
matrReference to another instance of DataMatrixSP
sgpp::base::DataMatrixSP::DataMatrixSP ( float *  input,
size_t  nrows,
size_t  ncols 
)

Create a new DataMatrixSP from a float array.

The float array contains the entries row-wise: x0_0,x0_1,...,x0_ncol-1, x1_0,x1_1,... ... xnrow_0, xnrow_1,...,xnrow_ncol-1

Parameters
inputfloat array that contains the data
nrowsnumber of rows
ncolsnumber of columns
sgpp::base::DataMatrixSP::~DataMatrixSP ( )
virtual

Destructor.

Referenced by setInc().

Member Function Documentation

void sgpp::base::DataMatrixSP::abs ( )

Sets all elements to their absolute value.

Referenced by set().

void sgpp::base::DataMatrixSP::add ( const DataMatrixSP matr)

Adds the values from another DataMatrixSP to the current values.

Modifies the current values.

Parameters
matrThe DataMatrixSP which is added to the current values

Referenced by set().

void sgpp::base::DataMatrixSP::addReduce ( DataVectorSP reduction)

Reduce the DataMatrixSP along the columns by adding all entries in one row.

Parameters
reductionDataVectorSP into which the reduce columns are stored

References sgpp::base::DataVectorSP::getSize(), sgpp::base::DataVectorSP::set(), and analyse_erg::tmp.

Referenced by set().

void sgpp::base::DataMatrixSP::addReduce ( DataVectorSP reduction,
DataVectorSP beta,
size_t  start_beta 
)

Reduce the DataMatrixSP along the columns by adding all entries in one row.

Parameters
reductionDataVectorSP to which the reduce columns are added
betavector with length of number of columns beta[i] is multiplied to each element row[j][i]
start_betawhere to start using the beta coefficients

References sgpp::base::DataVectorSP::getSize(), sgpp::base::DataVectorSP::set(), and analyse_erg::tmp.

void sgpp::base::DataMatrixSP::addSize ( size_t  inc_nrows)

Reserves memory for potentially inc_nrows new rows; the actual number of rows remains unchanged.

Corresponds to a resize to nrows+inc_nrows new rows while leaving the current matrix' size unchanged.

Parameters
inc_nrowsNumber of additional rows for which storage is to be reserved.

Referenced by appendRow().

size_t sgpp::base::DataMatrixSP::appendRow ( )

Appends a new row and returns index of it.

If the new row does not fit into the reserved memory, reserves memory for getIncRows() additional rows.

Returns
Index of new row

References addSize().

Referenced by appendRow().

size_t sgpp::base::DataMatrixSP::appendRow ( const DataVectorSP vec)

Appends a new row with data contained in DataVectorSP vec and returns index of new row.

If the new row does not fit into the reserved memory, reserves memory for getIncRows() additional rows.

Parameters
vecDataVectorSP (length has to match getNcols()) with data
Returns
Index of new row

References appendRow(), sgpp::base::DataVectorSP::getPointer(), and sgpp::base::DataVectorSP::getSize().

void sgpp::base::DataMatrixSP::componentwise_div ( const DataMatrixSP matr)

Divides the current DataMatrixSP component-wise by another DataMatrixSP.

Modifies the current values. Performs

for i from 1 to this.getTotalSize()
this[i] /= matr[i]

Note: No check for division by zero!

Parameters
matrthe DataMatrixSP which the current DataMatrixSP is divided by

Referenced by set().

void sgpp::base::DataMatrixSP::componentwise_mult ( const DataMatrixSP matr)

Multiplies the current DataMatrixSP component-wise with another DataMatrixSP.

Modifies the current values. Performs

for i from 1 to this.getSize()
this[i] *= matr[i]
Parameters
matrthe DataMatrixSP which is multiplied to current DataMatrixSP

Referenced by set().

void sgpp::base::DataMatrixSP::copyFrom ( const DataMatrixSP matr)

Copies the data from another DataMatrixSP matr.

Disregards the number of rows and columns set for the two matrices, i.e., just copies the data entry by entry (and row by row). If the dimensions match (nrows, ncols), the current DataMatrixSP is an exact copy of matr. If not, as many elements as possible are copied, and everything else is left untouched.

Parameters
matrThe source DataMatrixSP containing the data
void sgpp::base::DataMatrixSP::expand ( const DataVectorSP expand)

expands a given DataVectorSP into a DataMatrixSP.

Parameters
expandDataVectorSP that should be expanded

References sgpp::base::DataVectorSP::get(), and sgpp::base::DataVectorSP::getSize().

Referenced by set().

float sgpp::base::DataMatrixSP::get ( size_t  row,
size_t  col 
) const
inline

Returns the value of the element at position [row,col].

Parameters
rowRow
colColumn
Returns
Value of the element

Referenced by sgpp::base::PrecisionConverter::convertDataMatrixSPToDataMatrix().

void sgpp::base::DataMatrixSP::getColumn ( size_t  col,
DataVectorSP vec 
) const

Copies the values of a column to the DataVectorSP vec.

Parameters
colThe column
vecDataVectorSP into which the data is written

References sgpp::base::DataVectorSP::getSize().

Referenced by set().

size_t sgpp::base::DataMatrixSP::getInc ( ) const
inline

Get the current number of rows by which the DataMatrixSP is extended, if appendRow() is called and no unused rows are left.

Returns
Row increment
size_t sgpp::base::DataMatrixSP::getNcols ( ) const
inline
size_t sgpp::base::DataMatrixSP::getNumberNonZero ( ) const

Determines the number of non-zero elements in the vector.

Returns
The number of non-zero elements

Referenced by getUnused().

float * sgpp::base::DataMatrixSP::getPointer ( )

Returns pointer to float array containing underlying data.

Returns
Pointer to data

Referenced by set().

const float * sgpp::base::DataMatrixSP::getPointer ( ) const

Returns const pointer to float array containing underlying data.

Returns
Const pointer to data
void sgpp::base::DataMatrixSP::getRow ( size_t  row,
DataVectorSP vec 
) const

Copies the values of a row to the DataVectorSP vec.

Parameters
rowThe row
vecDataVectorSP into which the data is written

References sgpp::base::DataVectorSP::getSize().

Referenced by set().

void sgpp::base::DataMatrixSP::getRow ( size_t  row,
std::vector< float > &  vec 
) const

Copies the values of a row to the std::vector vec.

Parameters
rowThe row
vecstd::vector into which the data is written
size_t sgpp::base::DataMatrixSP::getSize ( ) const
inline
size_t sgpp::base::DataMatrixSP::getUnused ( ) const
inline

Returns the number of unused rows.

Returns
number of unused rows

References getNumberNonZero().

float sgpp::base::DataMatrixSP::max ( size_t  col) const

Returns the maximum value of column col.

Parameters
colNumber of the column
Returns
Maximum value

References max().

float sgpp::base::DataMatrixSP::max ( ) const

Returns the maximum over all entries.

Returns
Maximal value of all entries

Referenced by max(), and set().

float sgpp::base::DataMatrixSP::min ( size_t  col) const

Returns the minimum value of column col.

Parameters
colNumber of the column
Returns
Minimum value

References min().

float sgpp::base::DataMatrixSP::min ( ) const

Returns the minimum over all entries.

Returns
Minimal value of all entries

Referenced by min(), and set().

void sgpp::base::DataMatrixSP::minmax ( size_t  col,
float *  min,
float *  max 
) const

Determines minimum and maximum of column col.

Parameters
colNumber of the column
minReference variable for the minimum
maxReference variable for the maximum

Referenced by normalizeDimension(), and set().

void sgpp::base::DataMatrixSP::minmax ( float *  min,
float *  max 
) const

Determines minimum and maximum over all entries.

Parameters
minReference variable for the minimum
maxReference variable for the maximum
void sgpp::base::DataMatrixSP::mult ( const DataVectorSP x,
DataVectorSP y 
)

Multiplies the matrix with a vector x and stores the result in another vector y.

Parameters
[in]xvector to be multiplied
[out]yvector in which the result should be stored

References sgpp::base::DataVectorSP::getSize().

Referenced by set().

void sgpp::base::DataMatrixSP::mult ( float  scalar)

Multiplies all elements by a constant factor.

Parameters
scalarthe constant
void sgpp::base::DataMatrixSP::normalizeDimension ( size_t  d)

Normalizes the d-th dimension (entries in the d-th column) to \([0,1]\).

Considers contents of DataMatrixSP as a d-dimensional dataset, one data point per row.

Parameters
dThe dimension (column) that should be normalized (starting with 0)

Referenced by setInc().

void sgpp::base::DataMatrixSP::normalizeDimension ( size_t  d,
float  border 
)

Normalizes the d-th dimension (entries in the d-th column) to \([border,1-border]\).

Considers contents of DataMatrixSP as a d-dimensional dataset, one data point per row.

Parameters
dThe dimension (column) that should be normalized (starting with 0)
borderWidth of the border

References minmax().

float& sgpp::base::DataMatrixSP::operator() ( size_t  row,
size_t  col 
)
inline

Returns the value of the element at position [row,col].

Parameters
rowRow
colColumn
Returns
reference to the element
const float& sgpp::base::DataMatrixSP::operator() ( size_t  row,
size_t  col 
) const
inline

Returns the value of the element at position [row,col].

Parameters
rowRow
colColumn
Returns
constant reference to the element
DataMatrixSP & sgpp::base::DataMatrixSP::operator= ( const DataMatrixSP matr)

Copies the data from another DataMatrixSP.

Dimensions have to match.

Parameters
matrthe DataMatrixSP containing the data
Returns
*this
void sgpp::base::DataMatrixSP::resize ( size_t  nrows)

Resizes the DataMatrixSP to nrows rows.

All new additional entries are uninitialized. If nrows is smaller than the current number of rows, all superfluous entries are removed.

Parameters
nrowsNew number of rows of the DataMatrixSP
void sgpp::base::DataMatrixSP::resize ( size_t  nrows,
size_t  ncols 
)

Resizes the DataMatrixSP to nrows rows and ncols columns.

All new additional entries are uninitialized. If nrows*ncols is smaller than the current number of entries, all superfluous entries are removed.

Parameters
nrowsNew number of rows of the DataMatrixSP
ncolsNew number of columns of the DataMatrixSP
void sgpp::base::DataMatrixSP::resizeZero ( size_t  nrows)

Resizes the DataMatrixSP to nrows rows.

All new additional entries are set to zero. If nrows is smaller than the current number of rows, all superfluous entries are removed.

Parameters
nrowsNew number of rows of the DataMatrixSP
void sgpp::base::DataMatrixSP::resizeZero ( size_t  nrows,
size_t  ncols 
)

Resizes the DataMatrixSP to nrows rows and ncols columns.

All new additional entries are set to zero. If nrows*ncols is smaller than the current number of entries, all superfluous entries are removed.

Parameters
nrowsNew number of rows of the DataMatrixSP
ncolsNew number of columns of the DataMatrixSP
void sgpp::base::DataMatrixSP::set ( size_t  row,
size_t  col,
float  value 
)
inline
void sgpp::base::DataMatrixSP::setAll ( float  value)

Sets all entries of DataMatrixSP to value.

Parameters
valueNew value for all entries

Referenced by DataMatrixSP().

void sgpp::base::DataMatrixSP::setColumn ( size_t  col,
const DataVectorSP vec 
)

Sets a column of the DataMatrixSP to the values of a DataVectorSP vec.

Parameters
colThe column which is to be overwritten
vecDataVectorSP containing the data of the column

References sgpp::base::DataVectorSP::get(), and sgpp::base::DataVectorSP::getSize().

Referenced by set().

void sgpp::base::DataMatrixSP::setInc ( size_t  inc_rows)
inline

Sets the current number of rows by which the DataMatrixSP is extended, if appendRow() is called and no unused rows are left.

Defaults to 100.

Parameters
inc_rowsRow increment

References normalizeDimension(), toString(), and ~DataMatrixSP().

void sgpp::base::DataMatrixSP::setRow ( size_t  row,
const DataVectorSP vec 
)

Sets a row of the DataMatrixSP to the values of a DataVectorSP vec.

Parameters
rowThe row which is to be overwritten
vecDataVectorSP containing the data of the row

References sgpp::base::DataVectorSP::get(), and sgpp::base::DataVectorSP::getSize().

Referenced by set().

void sgpp::base::DataMatrixSP::sqr ( )

Squares all elements of the DataMatrixSP.

Referenced by set().

void sgpp::base::DataMatrixSP::sqrt ( )

Takes the square root of all elements of the DataMatrixSP.

Referenced by set().

void sgpp::base::DataMatrixSP::sub ( const DataMatrixSP matr)

Subtracts the values from another DataMatrixSP of the current values.

Modifies the current values.

Parameters
matrThe DataMatrixSP which is subtracted from the current values

Referenced by set().

float sgpp::base::DataMatrixSP::sum ( ) const

Returns the sum of all elements.

Returns
The sum of all elements

Referenced by set().

void sgpp::base::DataMatrixSP::transpose ( )

Transposes this DataMatrixSP.


The documentation for this class was generated from the following files: