SG++-Doxygen-Documentation
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

◆ DataMatrixSP() [1/4]

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

◆ DataMatrixSP() [2/4]

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().

◆ DataMatrixSP() [3/4]

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

Create a new DataMatrixSP that is a copy of matr.

Parameters
matrReference to another instance of DataMatrixSP

◆ DataMatrixSP() [4/4]

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

◆ ~DataMatrixSP()

sgpp::base::DataMatrixSP::~DataMatrixSP ( )
virtual

Destructor.

Referenced by setInc().

Member Function Documentation

◆ abs()

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

Sets all elements to their absolute value.

References python.statsfileInfo::i.

Referenced by set().

◆ add()

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

References python.statsfileInfo::i.

Referenced by set().

◆ addReduce() [1/2]

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(), python.statsfileInfo::i, python.utils.statsfile2gnuplot::j, sgpp::base::DataVectorSP::set(), and analyse_erg::tmp.

Referenced by set().

◆ addReduce() [2/2]

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(), python.statsfileInfo::i, python.utils.statsfile2gnuplot::j, sgpp::base::DataVectorSP::set(), and analyse_erg::tmp.

◆ addSize()

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().

◆ appendRow() [1/2]

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().

◆ appendRow() [2/2]

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().

◆ componentwise_div()

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

References python.statsfileInfo::i.

Referenced by set().

◆ componentwise_mult()

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

References python.statsfileInfo::i.

Referenced by set().

◆ copyFrom()

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

◆ expand()

void sgpp::base::DataMatrixSP::expand ( const DataVectorSP expand)

◆ get()

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().

◆ getColumn()

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(), and python.utils.statsfile2gnuplot::j.

Referenced by set().

◆ getInc()

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

◆ getNcols()

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

◆ getNrows()

◆ getNumberNonZero()

size_t sgpp::base::DataMatrixSP::getNumberNonZero ( ) const

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

Returns
The number of non-zero elements

References python.statsfileInfo::i.

Referenced by getUnused().

◆ getPointer() [1/2]

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

Returns pointer to float array containing underlying data.

Returns
Pointer to data

Referenced by set().

◆ getPointer() [2/2]

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

Returns const pointer to float array containing underlying data.

Returns
Const pointer to data

◆ getRow() [1/2]

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(), and python.statsfileInfo::i.

Referenced by set().

◆ getRow() [2/2]

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

References python.statsfileInfo::i.

◆ getSize()

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

◆ getUnused()

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

Returns the number of unused rows.

Returns
number of unused rows

References getNumberNonZero().

◆ max() [1/2]

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 python.statsfileInfo::i, and max().

◆ max() [2/2]

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

Returns the maximum over all entries.

Returns
Maximal value of all entries

References python.statsfileInfo::i.

Referenced by max(), and set().

◆ min() [1/2]

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 python.statsfileInfo::i, and min().

◆ min() [2/2]

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

Returns the minimum over all entries.

Returns
Minimal value of all entries

References python.statsfileInfo::i.

Referenced by min(), and set().

◆ minmax() [1/2]

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

References python.statsfileInfo::i.

Referenced by normalizeDimension(), and set().

◆ minmax() [2/2]

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

References python.statsfileInfo::i.

◆ mult() [1/2]

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(), python.statsfileInfo::i, and python.utils.statsfile2gnuplot::j.

Referenced by set().

◆ mult() [2/2]

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

Multiplies all elements by a constant factor.

Parameters
scalarthe constant

References python.statsfileInfo::i.

◆ normalizeDimension() [1/2]

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().

◆ normalizeDimension() [2/2]

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 python.statsfileInfo::i, and minmax().

◆ operator()() [1/2]

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

◆ operator()() [2/2]

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

◆ operator=()

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

◆ resize() [1/2]

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

◆ resize() [2/2]

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

◆ resizeZero() [1/2]

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

References python.statsfileInfo::i.

◆ resizeZero() [2/2]

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

References python.statsfileInfo::i.

◆ set()

void sgpp::base::DataMatrixSP::set ( size_t  row,
size_t  col,
float  value 
)
inline

◆ setAll()

void sgpp::base::DataMatrixSP::setAll ( float  value)

Sets all entries of DataMatrixSP to value.

Parameters
valueNew value for all entries

References python.statsfileInfo::i.

Referenced by DataMatrixSP().

◆ setColumn()

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(), sgpp::base::DataVectorSP::getSize(), and python.utils.statsfile2gnuplot::j.

Referenced by set().

◆ setInc()

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().

◆ setRow()

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(), sgpp::base::DataVectorSP::getSize(), and python.statsfileInfo::i.

Referenced by set().

◆ sqr()

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

Squares all elements of the DataMatrixSP.

References python.statsfileInfo::i.

Referenced by set().

◆ sqrt()

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

Takes the square root of all elements of the DataMatrixSP.

References python.statsfileInfo::i.

Referenced by set().

◆ sub()

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

References python.statsfileInfo::i.

Referenced by set().

◆ sum()

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

Returns the sum of all elements.

Returns
The sum of all elements

References python.statsfileInfo::i.

Referenced by set().

◆ toString() [1/2]

◆ toString() [2/2]

◆ transpose()

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

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