![]() |
SG++-Doxygen-Documentation
|
A class to store two-dimensional data. More...
#include <DataMatrixSP.hpp>
Public Member Functions | |
void | abs () |
Sets all elements to their absolute value. | |
void | add (const DataMatrixSP &matr) |
Adds the values from another DataMatrixSP to the current values. | |
void | addReduce (DataVectorSP &reduction) |
Reduce the DataMatrixSP along the columns by adding all entries in one row. | |
void | addReduce (DataVectorSP &reduction, DataVectorSP &beta, size_t start_beta) |
Reduce the DataMatrixSP along the columns by adding all entries in one row. | |
size_t | appendCol (const DataVectorSP &vec) |
Appends a new Col with data contained in DataVectorSP vec and returns index of new col. | |
size_t | appendRow () |
Appends a new row and returns index of it. | |
size_t | appendRow (const DataVectorSP &vec) |
Appends a new row with data contained in DataVectorSP vec and returns index of new row. | |
void | componentwise_div (const DataMatrixSP &matr) |
Divides the current DataMatrixSP component-wise by another DataMatrixSP. | |
void | componentwise_mult (const DataMatrixSP &matr) |
Multiplies the current DataMatrixSP component-wise with another DataMatrixSP. | |
void | copyFrom (const DataMatrixSP &matr) |
Copies the data from another DataMatrixSP matr. | |
DataMatrixSP () | |
Creates an empty two-dimensional DataMatrixSP. | |
DataMatrixSP (const DataMatrixSP &)=default | |
Copy constructor. | |
DataMatrixSP (const float *input, size_t nrows, size_t ncols) | |
Create a new DataMatrixSP from a float array. | |
DataMatrixSP (DataMatrixSP &&)=default | |
Move constructor. | |
DataMatrixSP (size_t nrows, size_t ncols) | |
Create a two-dimensional DataMatrixSP with nrows rows and ncols columns (uninitialized values). | |
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. | |
DataMatrixSP (std::initializer_list< float > input, size_t nrows) | |
Create a new DataMatrixSP from a std::initializer_list<float>. | |
DataMatrixSP (std::vector< float > input, size_t nrows) | |
Create a new DataMatrixSP from a std::vector<float>. | |
void | expand (const DataVectorSP &expand) |
expands a given DataVectorSP into a DataMatrixSP. | |
float | get (size_t row, size_t col) const |
Returns the value of the element at position [row,col]. | |
size_t | getAdditionallyReservedRows () const |
Returns the number of unused rows. | |
void | getColumn (size_t col, DataVectorSP &vec) const |
Copies the values of a column to the DataVectorSP vec. | |
size_t | getNcols () const |
Returns the number of columns of the DataMatrixSP. | |
size_t | getNrows () const |
Returns the number of rows of the DataMatrixSP. | |
size_t | getNumberNonZero () const |
Determines the number of non-zero elements in the vector. | |
float * | getPointer () |
Returns pointer to float array containing underlying data. | |
const float * | getPointer () const |
Returns const pointer to float array containing underlying data. | |
void | getRow (size_t row, DataVectorSP &vec) const |
Copies the values of a row to the DataVectorSP vec. | |
void | getRow (size_t row, std::vector< float > &vec) const |
Copies the values of a row to the std::vector vec. | |
size_t | getSize () const |
Returns the total number of (used) elements, i.e., getNrows()*getNCols() | |
float | max () const |
Returns the maximum over all entries. | |
float | max (size_t col) const |
Returns the maximum value of column col. | |
float | min () const |
Returns the minimum over all entries. | |
float | min (size_t col) const |
Returns the minimum value of column col. | |
void | minmax (float *min, float *max) const |
Determines minimum and maximum over all entries. | |
void | minmax (size_t col, float *min, float *max) const |
Determines minimum and maximum of column col. | |
void | mult (const DataVectorSP &x, DataVectorSP &y) const |
Multiplies the matrix with a vector x and stores the result in another vector y. | |
void | mult (float scalar) |
Multiplies all elements by a constant factor. | |
void | normalizeDimension (size_t d) |
Normalizes the d-th dimension (entries in the d-th column) to \([0,1]\). | |
void | normalizeDimension (size_t d, float border) |
Normalizes the d-th dimension (entries in the d-th column) to \([border,1-border]\). | |
float & | operator() (size_t row, size_t col) |
Returns the value of the element at position [row,col]. | |
const float & | operator() (size_t row, size_t col) const |
Returns the value of the element at position [row,col]. | |
DataMatrixSP & | operator= (const DataMatrixSP &)=default |
Copy assignment operator. | |
DataMatrixSP & | operator= (DataMatrixSP &&)=default |
Move assignment operator. | |
void | reserveAdditionalRows (size_t inc_nrows) |
Reserves memory for potentially inc_nrows new rows; the actual number of rows remains unchanged. | |
void | resize (size_t nrows) |
Resizes the DataMatrixSP to nrows rows. | |
void | resize (size_t nrows, size_t ncols) |
Resizes the DataMatrixSP to nrows rows and ncols columns. | |
void | resizeQuadratic (size_t size) |
Resizes the quadratic DataMatrixSP to size rows and size columns. | |
void | resizeRows (size_t nrows) |
Resizes the DataMatrixSP to nrows rows. | |
void | resizeRowsCols (size_t nrows, size_t ncols) |
Resizes the DataMatrixSP to nrows rows and ncols columns. | |
void | resizeToSubMatrix (size_t row_1, size_t col_1, size_t row_2, size_t col_2) |
Resize current matrix to the submatrix Mat[row_1:row_2, col_1:col_2]. | |
void | resizeZero (size_t nrows) |
Resizes the DataMatrixSP to nrows rows. | |
void | resizeZero (size_t nrows, size_t ncols) |
Resizes the DataMatrixSP to nrows rows and ncols columns. | |
void | set (size_t row, size_t col, float value) |
Sets the element at position [row,col] to value. | |
void | setAll (float value) |
Sets all entries of DataMatrixSP to value. | |
void | setColumn (size_t col, const DataVectorSP &vec) |
Sets a column of the DataMatrixSP to the values of a DataVectorSP vec. | |
void | setRow (size_t row, const DataVectorSP &vec) |
Sets a row of the DataMatrixSP to the values of a DataVectorSP vec. | |
void | sqr () |
Squares all elements of the DataMatrixSP. | |
void | sqrt () |
Takes the square root of all elements of the DataMatrixSP. | |
void | sub (const DataMatrixSP &matr) |
Subtracts the values from another DataMatrixSP of the current values. | |
float | sum () const |
Returns the sum of all elements. | |
void | toFile (const std::string &fileName) const |
std::string | toString () const |
Returns a description of the DataMatrixSP as a string. | |
void | toString (std::string &text) const |
Writes the data stored in the DataMatrixSP into a string. | |
void | transpose () |
Transposes this DataMatrixSP. | |
~DataMatrixSP ()=default | |
Destructor. | |
Static Public Member Functions | |
static DataMatrixSP | fromFile (const std::string &fileName) |
static DataMatrixSP | fromString (const std::string &serializedVector) |
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.
sgpp::base::DataMatrixSP::DataMatrixSP | ( | ) |
Creates an empty two-dimensional DataMatrixSP.
|
default |
Copy constructor.
|
default |
Move constructor.
|
default |
Destructor.
sgpp::base::DataMatrixSP::DataMatrixSP | ( | size_t | nrows, |
size_t | ncols | ||
) |
Create a two-dimensional DataMatrixSP with nrows rows and ncols columns (uninitialized values).
nrows | Number of rows |
ncols | Number 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.
nrows | Number of rows |
ncols | Number of columns |
value | Value for all entries |
sgpp::base::DataMatrixSP::DataMatrixSP | ( | const 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
input | float array that contains the data |
nrows | number of rows |
ncols | number of columns |
|
explicit |
Create a new DataMatrixSP from a std::vector<float>.
input | std::vector<float> that contains the data |
nrows | number of rows |
|
explicit |
Create a new DataMatrixSP from a std::initializer_list<float>.
input | std::initializer_list<float> that contains the data |
nrows | number of rows |
void sgpp::base::DataMatrixSP::abs | ( | ) |
Sets all elements to their absolute value.
void sgpp::base::DataMatrixSP::add | ( | const DataMatrixSP & | matr | ) |
Adds the values from another DataMatrixSP to the current values.
Modifies the current values.
matr | The DataMatrixSP which is added to the current values |
void sgpp::base::DataMatrixSP::addReduce | ( | DataVectorSP & | reduction | ) |
Reduce the DataMatrixSP along the columns by adding all entries in one row.
reduction | DataVectorSP into which the reduce columns are stored |
References sgpp::base::DataVectorSP::getSize(), and sgpp::base::DataVectorSP::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.
reduction | DataVectorSP to which the reduce columns are added |
beta | vector with length of number of columns beta[i] is multiplied to each element row[j][i] |
start_beta | where to start using the beta coefficients |
References sgpp::base::DataVectorSP::getSize(), and sgpp::base::DataVectorSP::set().
size_t sgpp::base::DataMatrixSP::appendCol | ( | const DataVectorSP & | vec | ) |
Appends a new Col with data contained in DataVectorSP vec and returns index of new col.
vec | DataVectorSP (length has to match getNcols()) with data |
References sgpp::base::DataVectorSP::getSize().
size_t sgpp::base::DataMatrixSP::appendRow | ( | ) |
Appends a new row and returns index of it.
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.
vec | DataVectorSP (length has to match getNcols()) with data |
References 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
Note: No check for division by zero!
matr | the DataMatrixSP which the current DataMatrixSP is divided by |
void sgpp::base::DataMatrixSP::componentwise_mult | ( | const DataMatrixSP & | matr | ) |
Multiplies the current DataMatrixSP component-wise with another DataMatrixSP.
Modifies the current values. Performs
matr | the DataMatrixSP which is multiplied to current DataMatrixSP |
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.
matr | The source DataMatrixSP containing the data |
void sgpp::base::DataMatrixSP::expand | ( | const DataVectorSP & | expand | ) |
expands a given DataVectorSP into a DataMatrixSP.
expand | DataVectorSP that should be expanded |
References expand().
Referenced by expand().
|
static |
References f, fileName, and fromString().
|
static |
References sgpp::base::DataVectorSP::append(), sgpp::base::DataVectorSP::getSize(), and m.
Referenced by fromFile().
|
inline |
Returns the value of the element at position [row,col].
row | Row |
col | Column |
Referenced by sgpp::base::PrecisionConverter::convertDataMatrixSPToDataMatrix().
|
inline |
Returns the number of unused rows.
void sgpp::base::DataMatrixSP::getColumn | ( | size_t | col, |
DataVectorSP & | vec | ||
) | const |
Copies the values of a column to the DataVectorSP vec.
col | The column |
vec | DataVectorSP into which the data is written |
References sgpp::base::DataVectorSP::getSize().
|
inline |
Returns the number of columns of the DataMatrixSP.
Referenced by sgpp::base::PrecisionConverter::convertDataMatrixSPToDataMatrix(), and sgpp::datadriven::LearnerBaseSP::predict().
|
inline |
Returns the number of rows of the DataMatrixSP.
Referenced by sgpp::base::PrecisionConverter::convertDataMatrixSPToDataMatrix(), sgpp::datadriven::LearnerBaseSP::predict(), and sgpp::datadriven::LearnerBaseSP::train().
size_t sgpp::base::DataMatrixSP::getNumberNonZero | ( | ) | const |
Determines the number of non-zero elements in the vector.
float * sgpp::base::DataMatrixSP::getPointer | ( | ) |
Returns pointer to float array containing underlying data.
const float * sgpp::base::DataMatrixSP::getPointer | ( | ) | const |
Returns const pointer to float array containing underlying data.
void sgpp::base::DataMatrixSP::getRow | ( | size_t | row, |
DataVectorSP & | vec | ||
) | const |
Copies the values of a row to the DataVectorSP vec.
row | The row |
vec | DataVectorSP into which the data is written |
References sgpp::base::DataVectorSP::getSize().
void sgpp::base::DataMatrixSP::getRow | ( | size_t | row, |
std::vector< float > & | vec | ||
) | const |
Copies the values of a row to the std::vector vec.
row | The row |
vec | std::vector into which the data is written |
|
inline |
Returns the total number of (used) elements, i.e., getNrows()*getNCols()
Referenced by python.uq.uq_setting.UQSetting.UQSetting::convert(), python.uq.uq_setting.UQSetting.UQSetting::getTimeDependentResults(), python.uq.uq_setting.UQSetting.UQSetting::runSamples(), and python.uq.uq_setting.UQSetting.UQSetting::runSamples_withoutDistribution().
float sgpp::base::DataMatrixSP::max | ( | ) | const |
float sgpp::base::DataMatrixSP::max | ( | size_t | col | ) | const |
Returns the maximum value of column col.
col | Number of the column |
References max().
float sgpp::base::DataMatrixSP::min | ( | ) | const |
float sgpp::base::DataMatrixSP::min | ( | size_t | col | ) | const |
Returns the minimum value of column col.
col | Number of the column |
References min().
void sgpp::base::DataMatrixSP::minmax | ( | float * | min, |
float * | max | ||
) | const |
Determines minimum and maximum over all entries.
min | Reference variable for the minimum |
max | Reference variable for the maximum |
void sgpp::base::DataMatrixSP::minmax | ( | size_t | col, |
float * | min, | ||
float * | max | ||
) | const |
Determines minimum and maximum of column col.
col | Number of the column |
min | Reference variable for the minimum |
max | Reference variable for the maximum |
Referenced by normalizeDimension().
void sgpp::base::DataMatrixSP::mult | ( | const DataVectorSP & | x, |
DataVectorSP & | y | ||
) | const |
Multiplies the matrix with a vector x and stores the result in another vector y.
[in] | x | vector to be multiplied |
[out] | y | vector in which the result should be stored |
References sgpp::base::DataVectorSP::getSize().
void sgpp::base::DataMatrixSP::mult | ( | float | scalar | ) |
Multiplies all elements by a constant factor.
scalar | the 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.
d | The dimension (column) that should be normalized (starting with 0) |
References normalizeDimension().
Referenced by normalizeDimension().
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.
d | The dimension (column) that should be normalized (starting with 0) |
border | Width of the border |
References minmax().
|
inline |
Returns the value of the element at position [row,col].
row | Row |
col | Column |
|
inline |
Returns the value of the element at position [row,col].
row | Row |
col | Column |
|
default |
Copy assignment operator.
|
default |
Move assignment operator.
void sgpp::base::DataMatrixSP::reserveAdditionalRows | ( | 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.
inc_nrows | Number of additional rows for which storage is to be reserved. |
Referenced by resizeToSubMatrix().
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.
nrows | New number of rows of the DataMatrixSP |
References resizeRows().
Referenced by resizeQuadratic(), resizeToSubMatrix(), and transpose().
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.
nrows | New number of rows of the DataMatrixSP |
ncols | New number of columns of the DataMatrixSP |
References resizeRowsCols().
void sgpp::base::DataMatrixSP::resizeQuadratic | ( | size_t | size | ) |
Resizes the quadratic DataMatrixSP to size rows and size columns.
All new additional entries are uninitialized. If size is smaller than the current size of the quadratic DataMatrixSP, all superfluous entries are removed.
size | New dimension of quadratic data DataMatrixSP |
References resize().
void sgpp::base::DataMatrixSP::resizeRows | ( | 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.
nrows | New number of rows of the DataMatrixSP |
Referenced by resize(), and resizeZero().
void sgpp::base::DataMatrixSP::resizeRowsCols | ( | 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.
nrows | New number of rows of the DataMatrixSP |
ncols | New number of columns of the DataMatrixSP |
Referenced by resize(), and resizeZero().
void sgpp::base::DataMatrixSP::resizeToSubMatrix | ( | size_t | row_1, |
size_t | col_1, | ||
size_t | row_2, | ||
size_t | col_2 | ||
) |
Resize current matrix to the submatrix Mat[row_1:row_2, col_1:col_2].
row_1,col_1 | corresponding to left upper index of desired submatrix |
row_2,col_2 | corresponding to right lower index of desired submatrix |
References reserveAdditionalRows(), and resize().
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.
nrows | New number of rows of the DataMatrixSP |
References resizeRows().
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.
nrows | New number of rows of the DataMatrixSP |
ncols | New number of columns of the DataMatrixSP |
References resizeRowsCols().
|
inline |
Sets the element at position [row,col] to value.
row | Row |
col | Column |
value | New value for element |
Referenced by sgpp::base::HashGridStorage::getLevelIndexArraysForEval(), and sgpp::base::HashGridStorage::getLevelIndexMaskArraysForModEval().
void sgpp::base::DataMatrixSP::setAll | ( | float | value | ) |
Sets all entries of DataMatrixSP to value.
value | New value for all entries |
void sgpp::base::DataMatrixSP::setColumn | ( | size_t | col, |
const DataVectorSP & | vec | ||
) |
Sets a column of the DataMatrixSP to the values of a DataVectorSP vec.
col | The column which is to be overwritten |
vec | DataVectorSP containing the data of the column |
References sgpp::base::DataVectorSP::get(), and sgpp::base::DataVectorSP::getSize().
void sgpp::base::DataMatrixSP::setRow | ( | size_t | row, |
const DataVectorSP & | vec | ||
) |
Sets a row of the DataMatrixSP to the values of a DataVectorSP vec.
row | The row which is to be overwritten |
vec | DataVectorSP containing the data of the row |
References sgpp::base::DataVectorSP::get(), and sgpp::base::DataVectorSP::getSize().
void sgpp::base::DataMatrixSP::sqr | ( | ) |
Squares all elements of the DataMatrixSP.
void sgpp::base::DataMatrixSP::sqrt | ( | ) |
Takes the square root of all elements of the DataMatrixSP.
void sgpp::base::DataMatrixSP::sub | ( | const DataMatrixSP & | matr | ) |
Subtracts the values from another DataMatrixSP of the current values.
Modifies the current values.
matr | The DataMatrixSP which is subtracted from the current values |
float sgpp::base::DataMatrixSP::sum | ( | ) | const |
Returns the sum of all elements.
void sgpp::base::DataMatrixSP::toFile | ( | const std::string & | fileName | ) | const |
References f, fileName, and toString().
std::string sgpp::base::DataMatrixSP::toString | ( | ) | const |
Returns a description of the DataMatrixSP as a string.
References toString().
Referenced by python.controller.LearnerEventController.LearnerEventController::__repr__(), python.controller.SolverEventController.SolverEventController::__repr__(), python.learner.Learner.Learner::createMemento(), python.uq.learner.Learner.Learner::createMemento(), python.learner.formatter.GridFormatter.GridFormatter::serialize(), toFile(), and toString().
void sgpp::base::DataMatrixSP::toString | ( | std::string & | text | ) | const |
Writes the data stored in the DataMatrixSP into a string.
text | String to which the data is written |
Referenced by python.controller.LearnerEventController.LearnerEventController::__repr__(), python.controller.SolverEventController.SolverEventController::__repr__(), python.learner.Learner.Learner::createMemento(), python.uq.learner.Learner.Learner::createMemento(), and python.learner.formatter.GridFormatter.GridFormatter::serialize().
void sgpp::base::DataMatrixSP::transpose | ( | ) |
Transposes this DataMatrixSP.
References resize().