![]() |
SG++-Doxygen-Documentation
|
A class to store one-dimensional data. More...
#include <DataVectorSP.hpp>
Public Member Functions | |
void | abs () |
Sets all elements to their absolute value. | |
void | accumulate (const DataVectorSP &vec) |
void | add (const DataVectorSP &vec) |
Adds the values from another DataVectorSP to the current values. | |
size_t | append () |
Appends a new element and returns index of it. | |
size_t | append (float value) |
Appends a new element and returns index of new element. | |
void | axpy (float a, DataVectorSP &x) |
Adds a*x to current vector. | |
void | componentwise_div (const DataVectorSP &vec) |
Divides the current DataVectorSP component-wise by another DataVectorSP. | |
void | componentwise_mult (const DataVectorSP &vec) |
Multiplies the current DataVectorSP component-wise with another DataVectorSP. | |
void | copyFrom (const DataVectorSP &vec) |
Copies the data from another DataVectorSP vec. | |
DataVectorSP () | |
Create an empty DataVectorSP. | |
DataVectorSP (const DataVectorSP &)=default | |
Copy constructor. | |
DataVectorSP (DataVectorSP &&)=default | |
Move constructor. | |
DataVectorSP (float *input, size_t size) | |
Create a new DataVectorSP from a float array with size elements. | |
DataVectorSP (size_t size) | |
Create a DataVectorSP with size elements (uninitialized values). | |
DataVectorSP (size_t size, float value) | |
Create a DataVectorSP with size elements and initializes all elements with the same value. | |
DataVectorSP (std::initializer_list< float > input) | |
Create a new DataVector from a std::initializer_list<float>. | |
DataVectorSP (std::vector< float > input) | |
Create a new DataVectorSP from a std::vector<float>. | |
DataVectorSP (std::vector< int > input) | |
Create a new DataVectorSP from a std::vector<int>. | |
float | dotProduct (const DataVectorSP &vec) const |
Returns the dot product of the two vectors. | |
float | get (size_t i) const |
Returns the i-th element. | |
size_t | getNumberNonZero () const |
Determines the number of non-zero elements in the vector. | |
float * | getPointer () |
gets a pointer to the data array | |
const float * | getPointer () const |
gets a const pointer to the data array | |
size_t | getSize () const |
gets the elements stored in the vector | |
void | insert (size_t index, float value) |
Inserts a new element at the given index. | |
float | l2Norm () const |
Returns the vector's \(l^2\)-norm, i.e., \(\sqrt{ \sum_i x_i^2 }\). | |
float | max () const |
Returns the maximum over all entries. | |
float | maxNorm () const |
calculates the vector's max norm | |
float | min () const |
Returns the minimum over all entries. | |
void | minmax (float *min, float *max) const |
Determines minimum and maximum over all entries. | |
void | mult (float scalar) |
multiplies all elements by a constant factor | |
void | normalize () |
Normalizes vector entries to [0,1]. | |
void | normalize (float border) |
Normalizes vector entries to [border, 1-border]. | |
DataVectorSP & | operator= (const DataVectorSP &)=default |
Copy assignment operator. | |
DataVectorSP & | operator= (DataVectorSP &&)=default |
Move assignment operator. | |
void | partitionClasses (float threshold) |
Partitions vector into two classes using a choosen border. | |
void | remove (std::vector< size_t > &indexesToRemove) |
Removes indexes form the vector. | |
void | resizeZero (size_t nrows) |
Resizes the DataVectorSP to size elements. | |
void | restructure (std::vector< size_t > &remainingIndex) |
Resizes the DataVectorSP by removing entries. | |
float | RMSNorm () const |
Returns the vector's root mean square (RMS)-norm, i.e., \(\sqrt{ 1/N \sum_{i=1}^N x_i^2 }\). | |
void | set (size_t i, float value) |
Sets the element at index i to value. | |
void | setAll (float value) |
Sets all values of DataVectorSP to value. | |
void | sqr () |
Squares all elements of the DataVectorSP. | |
void | sqrt () |
Takes the square root of all elements of the DataVectorSP. | |
void | sub (const DataVectorSP &vec) |
Subtracts the values from another DataVectorSP 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 DataVectorSP as a string. | |
void | toString (std::string &text) const |
Writes the data stored in the DataVectorSP into a string. | |
~DataVectorSP ()=default | |
Destructor. | |
Static Public Member Functions | |
static DataVectorSP | fromFile (const std::string &fileName) |
static DataVectorSP | fromString (const std::string &serializedVector) |
A class to store one-dimensional data.
Typically, an object of type DataVectorSP will contain an array of (hierarchical) coefficients (or surplusses), or the coordinates of a data point at which a sparse grid function should be evaluated.
This is an re-implementation of the standard DataVector for single precision floating point numbers in order to increase support for GPUs.
sgpp::base::DataVectorSP::DataVectorSP | ( | ) |
Create an empty DataVectorSP.
|
default |
Copy constructor.
|
default |
Move constructor.
|
default |
Destructor.
|
explicit |
Create a DataVectorSP with size elements (uninitialized values).
size | Number of elements |
sgpp::base::DataVectorSP::DataVectorSP | ( | size_t | size, |
float | value | ||
) |
Create a DataVectorSP with size elements and initializes all elements with the same value.
size | Number of elements |
value | Value for all entries |
sgpp::base::DataVectorSP::DataVectorSP | ( | float * | input, |
size_t | size | ||
) |
Create a new DataVectorSP from a float array with size elements.
input | float array that contains the data |
size | number of elements |
|
explicit |
Create a new DataVectorSP from a std::vector<float>.
input | std::vector<float> that contains the data |
|
explicit |
Create a new DataVector from a std::initializer_list<float>.
input | std::initializer_list<float> that contains the data |
|
explicit |
Create a new DataVectorSP from a std::vector<int>.
input | std::vector<int> that contains the data |
void sgpp::base::DataVectorSP::abs | ( | ) |
Sets all elements to their absolute value.
void sgpp::base::DataVectorSP::accumulate | ( | const DataVectorSP & | vec | ) |
void sgpp::base::DataVectorSP::add | ( | const DataVectorSP & | vec | ) |
Adds the values from another DataVectorSP to the current values.
Modifies the current values.
vec | The DataVectorSP which is added to the current values |
Referenced by sgpp::solver::ConjugateGradientsSP::solve().
size_t sgpp::base::DataVectorSP::append | ( | ) |
Appends a new element and returns index of it.
References append().
Referenced by append(), sgpp::base::DataMatrixSP::fromString(), and fromString().
size_t sgpp::base::DataVectorSP::append | ( | float | value | ) |
Appends a new element and returns index of new element.
value | Value of new element |
void sgpp::base::DataVectorSP::axpy | ( | float | a, |
DataVectorSP & | x | ||
) |
Adds a*x to current vector.
BLAS Level 1 (elementary vector operations) operation: axpy.
a | A scalar |
x | Reference to the DataVectorSP |
Referenced by sgpp::solver::BiCGStabSP::solve().
void sgpp::base::DataVectorSP::componentwise_div | ( | const DataVectorSP & | vec | ) |
Divides the current DataVectorSP component-wise by another DataVectorSP.
Modifies the current values. Performs
Note: No check for division by zero!
vec | the DataVectorSP which the current DataVectorSP is divided by |
void sgpp::base::DataVectorSP::componentwise_mult | ( | const DataVectorSP & | vec | ) |
Multiplies the current DataVectorSP component-wise with another DataVectorSP.
Modifies the current values. Performs
vec | the DataVectorSP which is multiplied to current DataVectorSP |
Referenced by l2Norm().
void sgpp::base::DataVectorSP::copyFrom | ( | const DataVectorSP & | vec | ) |
Copies the data from another DataVectorSP vec.
Disregards the number of entries set for the two vectors, i.e., just copies the data entry by entry. If the size matches, the current DataVectorSP is an exact copy of vec. If not, as many elements as possible are copied, and everything else is left untouched.
vec | The source DataVectorSP containing the data |
float sgpp::base::DataVectorSP::dotProduct | ( | const DataVectorSP & | vec | ) | const |
Returns the dot product of the two vectors.
vec | Reference to another vector |
References sum().
Referenced by sgpp::solver::BiCGStabSP::solve(), and sgpp::solver::ConjugateGradientsSP::solve().
|
static |
References f, fileName, and fromString().
|
static |
References append().
Referenced by fromFile().
|
inline |
Returns the i-th element.
i | position of the element |
Referenced by sgpp::base::PrecisionConverter::convertDataVectorSPToDataVector(), sgpp::datadriven::LearnerBaseSP::getAccuracy(), sgpp::datadriven::LearnerBaseSP::getCassificatorQuality(), sgpp::base::DataMatrixSP::setColumn(), and sgpp::base::DataMatrixSP::setRow().
size_t sgpp::base::DataVectorSP::getNumberNonZero | ( | ) | const |
Determines the number of non-zero elements in the vector.
float * sgpp::base::DataVectorSP::getPointer | ( | ) |
gets a pointer to the data array
const float * sgpp::base::DataVectorSP::getPointer | ( | ) | const |
gets a const pointer to the data array
|
inline |
gets the elements stored in the vector
Referenced by sgpp::base::DataMatrixSP::addReduce(), sgpp::base::DataMatrixSP::addReduce(), sgpp::base::DataMatrixSP::appendCol(), sgpp::base::DataMatrixSP::appendRow(), python.uq.uq_setting.UQSetting.UQSetting::convert(), sgpp::base::PrecisionConverter::convertDataVectorSPToDataVector(), sgpp::datadriven::LearnerBaseSP::dumpFunction(), sgpp::datadriven::LearnerBaseSP::dumpGrid(), sgpp::base::DataMatrixSP::fromString(), sgpp::datadriven::LearnerBaseSP::getAccuracy(), sgpp::datadriven::LearnerBaseSP::getCassificatorQuality(), sgpp::base::DataMatrixSP::getColumn(), sgpp::base::DataMatrixSP::getRow(), python.uq.uq_setting.UQSetting.UQSetting::getTimeDependentResults(), sgpp::base::DataMatrixSP::mult(), RMSNorm(), python.uq.uq_setting.UQSetting.UQSetting::runSamples(), python.uq.uq_setting.UQSetting.UQSetting::runSamples_withoutDistribution(), sgpp::base::DataMatrixSP::setColumn(), sgpp::base::DataMatrixSP::setRow(), and sgpp::datadriven::LearnerBaseSP::train().
void sgpp::base::DataVectorSP::insert | ( | size_t | index, |
float | value | ||
) |
float sgpp::base::DataVectorSP::l2Norm | ( | ) | const |
Returns the vector's \(l^2\)-norm, i.e., \(\sqrt{ \sum_i x_i^2 }\).
References componentwise_mult(), l2Norm(), and sum().
Referenced by l2Norm().
float sgpp::base::DataVectorSP::max | ( | ) | const |
Returns the maximum over all entries.
References max().
Referenced by max(), maxNorm(), and normalize().
float sgpp::base::DataVectorSP::maxNorm | ( | ) | const |
float sgpp::base::DataVectorSP::min | ( | ) | const |
Returns the minimum over all entries.
References min().
Referenced by min(), and normalize().
void sgpp::base::DataVectorSP::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 |
Referenced by normalize().
void sgpp::base::DataVectorSP::mult | ( | float | scalar | ) |
multiplies all elements by a constant factor
scalar | the constant |
Referenced by sgpp::solver::ConjugateGradientsSP::solve().
void sgpp::base::DataVectorSP::normalize | ( | ) |
void sgpp::base::DataVectorSP::normalize | ( | float | border | ) |
|
default |
Copy assignment operator.
|
default |
Move assignment operator.
void sgpp::base::DataVectorSP::partitionClasses | ( | float | threshold | ) |
Partitions vector into two classes using a choosen border.
threshold | value of the border |
void sgpp::base::DataVectorSP::remove | ( | std::vector< size_t > & | indexesToRemove | ) |
Removes indexes form the vector.
Throws an exception if the boundaries are violated
indexesToRemove | a vector if indexes that will be removed from the vector |
Referenced by python.uq.uq_setting.UQSetting.UQSetting::cleanUp().
void sgpp::base::DataVectorSP::resizeZero | ( | size_t | nrows | ) |
Resizes the DataVectorSP to size elements.
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 DataVectorSP |
Referenced by sgpp::datadriven::LearnerBaseSP::train().
void sgpp::base::DataVectorSP::restructure | ( | std::vector< size_t > & | remainingIndex | ) |
Resizes the DataVectorSP by removing entries.
Throws an exception if boundaries a violated.
remainingIndex | vector that contains the remaining indices of the DataVectorSP |
float sgpp::base::DataVectorSP::RMSNorm | ( | ) | const |
Returns the vector's root mean square (RMS)-norm, i.e., \(\sqrt{ 1/N \sum_{i=1}^N x_i^2 }\).
If the vector's entries correspond to function values on a full grid, this is the discrete \(L^2\)-norm of the corresponding function.
void sgpp::base::DataVectorSP::set | ( | size_t | i, |
float | value | ||
) |
Sets the element at index i to value.
i | Index |
value | New value for element |
Referenced by sgpp::base::DataMatrixSP::addReduce(), and sgpp::base::DataMatrixSP::addReduce().
void sgpp::base::DataVectorSP::setAll | ( | float | value | ) |
Sets all values of DataVectorSP to value.
value | New value for all entries |
Referenced by sgpp::datadriven::LearnerBaseSP::InitializeGrid(), and sgpp::solver::ConjugateGradientsSP::solve().
void sgpp::base::DataVectorSP::sqr | ( | ) |
Squares all elements of the DataVectorSP.
Referenced by RMSNorm().
void sgpp::base::DataVectorSP::sqrt | ( | ) |
Takes the square root of all elements of the DataVectorSP.
void sgpp::base::DataVectorSP::sub | ( | const DataVectorSP & | vec | ) |
Subtracts the values from another DataVectorSP of the current values.
Modifies the current values.
vec | The DataVectorSP which is subtracted from the current values |
float sgpp::base::DataVectorSP::sum | ( | ) | const |
Returns the sum of all elements.
Referenced by dotProduct(), l2Norm(), and RMSNorm().
void sgpp::base::DataVectorSP::toFile | ( | const std::string & | fileName | ) | const |
References f, fileName, and toString().
std::string sgpp::base::DataVectorSP::toString | ( | ) | const |
Returns a description of the DataVectorSP 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::DataVectorSP::toString | ( | std::string & | text | ) | const |
Writes the data stored in the DataVectorSP 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().