SG++-Doxygen-Documentation
sgpp::datadriven::LearnerBase Class Referenceabstract

Abstract class that implements a regression/classification learner based on spatial adaptive Sparse Grids. More...

#include <LearnerBase.hpp>

Inheritance diagram for sgpp::datadriven::LearnerBase:
sgpp::datadriven::Learner sgpp::datadriven::LearnerLeastSquaresIdentity

Public Member Functions

void dumpFunction (std::string tFilename, size_t resolution)
 simple dump of sparse grid function into file, e.g. More...
 
void dumpGrid (std::string tFilename)
 simple dump of grid points into file, e.g. More...
 
virtual double getAccuracy (sgpp::base::DataMatrix &testDataset, const sgpp::base::DataVector &classesReference, const double threshold=0.0)
 compute the accuracy for given testDataset. More...
 
virtual double getAccuracy (const sgpp::base::DataVector &classesComputed, const sgpp::base::DataVector &classesReference, const double threshold=0.0)
 compute the accuracy for given testDataset. More...
 
sgpp::base::DataVectorgetAlpha ()
 
virtual ClassificatorQuality getCassificatorQuality (sgpp::base::DataMatrix &testDataset, const sgpp::base::DataVector &classesReference, const double threshold=0.0)
 compute the quality for given testDataset, classification ONLY! test is automatically called in order to determine the regression values of the current learner More...
 
virtual ClassificatorQuality getCassificatorQuality (const sgpp::base::DataVector &classesComputed, const sgpp::base::DataVector &classesReference, const double threshold=0.0)
 compute the quality for given testDataset, classification ONLY! More...
 
sgpp::base::GridgetGrid ()
 
bool getIsRegression () const
 determines the current mode More...
 
bool getIsVerbose () const
 determines the current verbose mode of learner More...
 
std::vector< std::pair< size_t, double > > getRefinementExecTimes ()
 
 LearnerBase (const bool isRegression, const bool isVerbose=true)
 Constructor. More...
 
 LearnerBase (const LearnerBase &copyMe)
 Copy-Constructor. More...
 
virtual void multTranspose (sgpp::base::DataMatrix &dataset, sgpp::base::DataVector &multiplier, sgpp::base::DataVector &result)
 
virtual void predict (sgpp::base::DataMatrix &testDataset, sgpp::base::DataVector &classesComputed)
 executes a Regression test for a given dataset and returns the result More...
 
void setIsVerbose (const bool isVerbose)
 sets the current verbose mode of learner More...
 
void setReuseCoefficients (bool reuseCoefficients)
 
void setSolverVerbose (bool solverVerbose)
 
void store (std::string tGridFilename, std::string tAlphaFilename)
 store the grid and its current coefficients into files for further usage. More...
 
virtual LearnerTiming train (sgpp::base::DataMatrix &trainDataset, sgpp::base::DataVector &classes, const sgpp::base::RegularGridConfiguration &GridConfig, const sgpp::solver::SLESolverConfiguration &SolverConfigRefine, const sgpp::solver::SLESolverConfiguration &SolverConfigFinal, const sgpp::base::AdaptivityConfiguration &AdaptConfig, bool testAccDuringAdapt, const double lambdaRegularization, sgpp::base::DataMatrix *testDataset=nullptr, sgpp::base::DataVector *testClasses=nullptr)
 Learning a dataset with spatially adaptive sparse grids. More...
 
LearnerTiming train (sgpp::base::DataMatrix &trainDataset, sgpp::base::DataVector &classes, const sgpp::base::RegularGridConfiguration &GridConfig, const sgpp::solver::SLESolverConfiguration &SolverConfig, const double lambdaRegularization)
 Learning a dataset with regular sparse grids. More...
 
virtual ~LearnerBase ()
 Destructor. More...
 

Protected Member Functions

virtual std::unique_ptr< sgpp::datadriven::DMSystemMatrixBasecreateDMSystem (sgpp::base::DataMatrix &trainDataset, double lambda)=0
 abstract method that constructs the corresponding system of linear equations Derived classes MUST overwrite this functions! More...
 
virtual void InitializeGrid (const sgpp::base::RegularGridConfiguration &GridConfig)
 Initialize the grid and its coefficients. More...
 
virtual void postProcessing (const sgpp::base::DataMatrix &trainDataset, const sgpp::solver::SLESolverType &solver, const size_t numNeededIterations)
 Hook-Method for post-processing after each refinement learning. More...
 
virtual void preProcessing ()
 Hook-Method for pre-processing before starting learning. More...
 

Protected Attributes

std::unique_ptr< sgpp::base::DataVectoralpha
 the grid's coefficients More...
 
size_t currentRefinementStep
 the current refinment step during training More...
 
double execTime
 execution time More...
 
std::vector< std::pair< size_t, double > > ExecTimeOnStep
 
double GByte
 number of transferred Gbytes More...
 
double GFlop
 number of executed Floating Point operations More...
 
std::unique_ptr< sgpp::base::Gridgrid
 sparse grid object More...
 
bool isRegression
 is regression selected More...
 
bool isTrained
 is the grid trained More...
 
bool isVerbose
 is verbose output enabled More...
 
bool reuseCoefficients
 shall the coefficients be reused between refinement steps More...
 
bool solverVerbose
 sets the verbose option for the solver More...
 
double stepExecTime
 execution time for current refinement to calculate the GFlops at the current timestep only otherwise accumulated GFlops (all refinement steps) are calculated More...
 
double stepGByte
 number of transferred Gbytes in the current refinement step More...
 
double stepGFlop
 number of executed Floating Point operations in the current refinement step More...
 

Detailed Description

Abstract class that implements a regression/classification learner based on spatial adaptive Sparse Grids.

Furthermore this class is intended to provide a framework for adavanded regression and classification methods by allowing to override basic routines like train and test.

Constructor & Destructor Documentation

◆ LearnerBase() [1/2]

sgpp::datadriven::LearnerBase::LearnerBase ( const bool  isRegression,
const bool  isVerbose = true 
)
explicit

Constructor.

Parameters
isRegressionflag for regression
isVerboseflag for verbose output

◆ LearnerBase() [2/2]

sgpp::datadriven::LearnerBase::LearnerBase ( const LearnerBase copyMe)

◆ ~LearnerBase()

sgpp::datadriven::LearnerBase::~LearnerBase ( )
virtual

Destructor.

Member Function Documentation

◆ createDMSystem()

virtual std::unique_ptr<sgpp::datadriven::DMSystemMatrixBase> sgpp::datadriven::LearnerBase::createDMSystem ( sgpp::base::DataMatrix trainDataset,
double  lambda 
)
protectedpure virtual

abstract method that constructs the corresponding system of linear equations Derived classes MUST overwrite this functions!

Parameters
trainDatasettraining dataset
lambdalambda regularization parameter

Implemented in sgpp::datadriven::LearnerLeastSquaresIdentity, and sgpp::datadriven::Learner.

Referenced by train().

◆ dumpFunction()

void sgpp::datadriven::LearnerBase::dumpFunction ( std::string  tFilename,
size_t  resolution 
)

simple dump of sparse grid function into file, e.g.

used to plot with gnuplot.

only executed if grid is trained and number of dimensions <= 2.

Parameters
tFilenamefilename to store the dump to
resolutionresolution of function plot

References alpha, grid, isTrained, and sgpp::base::GridPrinter::printGrid().

◆ dumpGrid()

void sgpp::datadriven::LearnerBase::dumpGrid ( std::string  tFilename)

simple dump of grid points into file, e.g.

used to plot with gnuplot

only executed if grid is trained

Parameters
tFilenamefilename to store the dump to

References alpha, grid, isTrained, and sgpp::base::GridPrinter::printSparseGrid().

◆ getAccuracy() [1/2]

double sgpp::datadriven::LearnerBase::getAccuracy ( sgpp::base::DataMatrix testDataset,
const sgpp::base::DataVector classesReference,
const double  threshold = 0.0 
)
virtual

compute the accuracy for given testDataset.

test is automatically called in order to determine the regression values of the current learner

In case if classification (isRegression == false) this routine returns the learner's accuracy In case of regressions (isRegression == true) this routine returns the learner's MSE

Parameters
testDatasetdataset to be tested
classesReferencereference labels of the test dataset
thresholdthreshold used for classification, ignored when performing regressions
Returns
accuracy, percent or MSE, depending on the execution mode

References sgpp::base::DataMatrix::getNrows(), and predict().

Referenced by train().

◆ getAccuracy() [2/2]

double sgpp::datadriven::LearnerBase::getAccuracy ( const sgpp::base::DataVector classesComputed,
const sgpp::base::DataVector classesReference,
const double  threshold = 0.0 
)
virtual

compute the accuracy for given testDataset.

In case if classification (isRegression == false) this routine returns the learner's accuracy In case of regressions (isRegression == true) this routine returns the learner's MSE

Parameters
classesComputedregression results of the test dataset
classesReferencereference labels of the test dataset
thresholdthreshold used for classification, ignored when performing regressions
Returns
accuracy, percent or MSE, depending on the execution mode

References sgpp::base::DataVector::get(), sgpp::base::DataVector::getSize(), python.statsfileInfo::i, isRegression, sgpp::base::DataVector::sqr(), sgpp::base::DataVector::sub(), sgpp::base::DataVector::sum(), and analyse_erg::tmp.

◆ getAlpha()

sgpp::base::DataVector & sgpp::datadriven::LearnerBase::getAlpha ( )

References alpha.

◆ getCassificatorQuality() [1/2]

ClassificatorQuality sgpp::datadriven::LearnerBase::getCassificatorQuality ( sgpp::base::DataMatrix testDataset,
const sgpp::base::DataVector classesReference,
const double  threshold = 0.0 
)
virtual

compute the quality for given testDataset, classification ONLY! test is automatically called in order to determine the regression values of the current learner

Parameters
testDatasetdataset to be tested
classesReferencereference labels of the test dataset
thresholdthreshold used for classification, ignored when performing regressions
Returns
quality structure containing tp, tn, fp, fn counts

References sgpp::base::DataMatrix::getNrows(), and predict().

◆ getCassificatorQuality() [2/2]

ClassificatorQuality sgpp::datadriven::LearnerBase::getCassificatorQuality ( const sgpp::base::DataVector classesComputed,
const sgpp::base::DataVector classesReference,
const double  threshold = 0.0 
)
virtual

compute the quality for given testDataset, classification ONLY!

Parameters
classesComputedregression results of the test dataset
classesReferencereference labels of the test dataset
thresholdthreshold used for classification, ignored when performing regressions
Returns
quality structure containing tp, tn, fp, fn counts

References sgpp::datadriven::ClassificatorQuality::falseNegative_, sgpp::datadriven::ClassificatorQuality::falsePositive_, sgpp::base::DataVector::get(), sgpp::base::DataVector::getSize(), python.statsfileInfo::i, isRegression, sgpp::datadriven::ClassificatorQuality::trueNegative_, and sgpp::datadriven::ClassificatorQuality::truePositive_.

◆ getGrid()

sgpp::base::Grid & sgpp::datadriven::LearnerBase::getGrid ( )

References grid.

◆ getIsRegression()

bool sgpp::datadriven::LearnerBase::getIsRegression ( ) const

determines the current mode

Returns
returns whether the current mode is regression or not

References isRegression.

◆ getIsVerbose()

bool sgpp::datadriven::LearnerBase::getIsVerbose ( ) const

determines the current verbose mode of learner

Returns
returns whether the current learner has verbose output

References isVerbose.

◆ getRefinementExecTimes()

std::vector< std::pair< size_t, double > > sgpp::datadriven::LearnerBase::getRefinementExecTimes ( )

References ExecTimeOnStep.

◆ InitializeGrid()

void sgpp::datadriven::LearnerBase::InitializeGrid ( const sgpp::base::RegularGridConfiguration GridConfig)
protectedvirtual

◆ multTranspose()

void sgpp::datadriven::LearnerBase::multTranspose ( sgpp::base::DataMatrix dataset,
sgpp::base::DataVector multiplier,
sgpp::base::DataVector result 
)
virtual

◆ postProcessing()

void sgpp::datadriven::LearnerBase::postProcessing ( const sgpp::base::DataMatrix trainDataset,
const sgpp::solver::SLESolverType solver,
const size_t  numNeededIterations 
)
protectedvirtual

Hook-Method for post-processing after each refinement learning.

can be overwritten by derived classes

Parameters
trainDatasetmatrix with training data
solversolver
numNeededIterationsnumber of required iterations

Reimplemented in sgpp::datadriven::LearnerLeastSquaresIdentity.

References execTime, and isVerbose.

Referenced by train().

◆ predict()

void sgpp::datadriven::LearnerBase::predict ( sgpp::base::DataMatrix testDataset,
sgpp::base::DataVector classesComputed 
)
virtual

executes a Regression test for a given dataset and returns the result

Parameters
testDatasetdataset that is evaluated with the current learner
classesComputedresult of the evaluation of the data set
Returns
regression values of testDataset

Reimplemented in sgpp::datadriven::LearnerLeastSquaresIdentity.

References alpha, sgpp::op_factory::createOperationMultipleEval(), sgpp::base::DataMatrix::getNrows(), grid, and sgpp::base::OperationMultipleEval::mult().

Referenced by getAccuracy(), getCassificatorQuality(), and train().

◆ preProcessing()

void sgpp::datadriven::LearnerBase::preProcessing ( )
protectedvirtual

Hook-Method for pre-processing before starting learning.

can be overwritten by derived classes

Referenced by train().

◆ setIsVerbose()

void sgpp::datadriven::LearnerBase::setIsVerbose ( const bool  isVerbose)

sets the current verbose mode of learner

Parameters
isVerbosethe current learner's verbose output

References isVerbose.

◆ setReuseCoefficients()

void sgpp::datadriven::LearnerBase::setReuseCoefficients ( bool  reuseCoefficients)

References reuseCoefficients.

◆ setSolverVerbose()

void sgpp::datadriven::LearnerBase::setSolverVerbose ( bool  solverVerbose)

References solverVerbose.

◆ store()

void sgpp::datadriven::LearnerBase::store ( std::string  tGridFilename,
std::string  tAlphaFilename 
)

store the grid and its current coefficients into files for further usage.

Parameters
tGridFilenamefilename of grid file
tAlphaFilenamefilename of coefficient file

◆ train() [1/2]

LearnerTiming sgpp::datadriven::LearnerBase::train ( sgpp::base::DataMatrix trainDataset,
sgpp::base::DataVector classes,
const sgpp::base::RegularGridConfiguration GridConfig,
const sgpp::solver::SLESolverConfiguration SolverConfigRefine,
const sgpp::solver::SLESolverConfiguration SolverConfigFinal,
const sgpp::base::AdaptivityConfiguration AdaptConfig,
bool  testAccDuringAdapt,
const double  lambdaRegularization,
sgpp::base::DataMatrix testDataset = nullptr,
sgpp::base::DataVector testClasses = nullptr 
)
virtual

Learning a dataset with spatially adaptive sparse grids.

Parameters
trainDatasetthe training dataset
classesclasses corresponding to the training dataset
GridConfigconfiguration of the regular start grid
SolverConfigRefineconfiguration of the SLE solver during the adaptive refinements of the grid
SolverConfigFinalconfiguration of the final SLE solving step on the refined grid
AdaptConfigconfiguration of the adaptivity strategy
testAccDuringAdaptset to true if the training accuracy should be determined in evert refinement step
lambdaRegularizationregularization parameter lambda
testDatasetthe test dataset (for accuracy output, nullptr if no output is wished)
testClassesclasses corresponding to the testing dataset (for accuracy output, nullptr if no output is wished)

References alpha, chess::b, sgpp::solver::BiCGSTAB, sgpp::solver::CG, sgpp::base::DataVector::componentwise_mult(), createDMSystem(), currentRefinementStep, sgpp::solver::SLESolverConfiguration::eps_, sgpp::base::AdaptivityConfiguration::errorBasedRefinement, execTime, GByte, sgpp::datadriven::LearnerTiming::GByte_, sgpp::datadriven::DMSystemMatrixBase::generateb(), getAccuracy(), sgpp::base::DataMatrix::getNrows(), sgpp::solver::SGSolver::getNumberIterations(), sgpp::solver::SGSolver::getResiduum(), sgpp::base::DataVector::getSize(), sgpp::datadriven::DMSystemMatrixBase::getTimers(), GFlop, sgpp::datadriven::LearnerTiming::GFlop_, grid, python.statsfileInfo::i, InitializeGrid(), isRegression, isTrained, isVerbose, sgpp::solver::SLESolverConfiguration::maxIterations_, multTranspose(), sgpp::base::AdaptivityConfiguration::noPoints_, sgpp::base::AdaptivityConfiguration::numRefinements_, postProcessing(), predict(), sgpp::datadriven::DMSystemMatrixBase::prepareGrid(), preProcessing(), reuseCoefficients, sgpp::solver::SGSolver::setEpsilon(), sgpp::solver::SGSolver::setMaxIterations(), sgpp::solver::SLESolver::solve(), solverVerbose, sgpp::base::DataVector::sqr(), sgpp::base::SGppStopwatch::start(), stepExecTime, sgpp::base::SGppStopwatch::stop(), sgpp::base::DataVector::sub(), sgpp::base::AdaptivityConfiguration::threshold_, sgpp::datadriven::LearnerTiming::timeComplete_, sgpp::datadriven::LearnerTiming::timeMultComplete_, sgpp::datadriven::LearnerTiming::timeMultCompute_, sgpp::datadriven::LearnerTiming::timeMultTransComplete_, sgpp::datadriven::LearnerTiming::timeMultTransCompute_, sgpp::datadriven::LearnerTiming::timeRegularization_, and sgpp::solver::SLESolverConfiguration::type_.

Referenced by train().

◆ train() [2/2]

LearnerTiming sgpp::datadriven::LearnerBase::train ( sgpp::base::DataMatrix trainDataset,
sgpp::base::DataVector classes,
const sgpp::base::RegularGridConfiguration GridConfig,
const sgpp::solver::SLESolverConfiguration SolverConfig,
const double  lambdaRegularization 
)

Learning a dataset with regular sparse grids.

Parameters
trainDatasetthe training dataset
classesclasses corresponding to the training dataset
GridConfigconfiguration of the regular grid
SolverConfigconfiguration of the SLE solver
lambdaRegularizationregularization parameter lambda

References sgpp::base::AdaptivityConfiguration::maxLevelType_, sgpp::base::AdaptivityConfiguration::noPoints_, sgpp::base::AdaptivityConfiguration::numRefinements_, sgpp::base::AdaptivityConfiguration::percent_, sgpp::base::AdaptivityConfiguration::threshold_, and train().

Member Data Documentation

◆ alpha

◆ currentRefinementStep

size_t sgpp::datadriven::LearnerBase::currentRefinementStep
protected

the current refinment step during training

Referenced by LearnerBase(), and train().

◆ execTime

◆ ExecTimeOnStep

std::vector<std::pair<size_t, double> > sgpp::datadriven::LearnerBase::ExecTimeOnStep
protected

Referenced by getRefinementExecTimes().

◆ GByte

double sgpp::datadriven::LearnerBase::GByte
protected

◆ GFlop

double sgpp::datadriven::LearnerBase::GFlop
protected

number of executed Floating Point operations

Referenced by LearnerBase(), sgpp::datadriven::LearnerLeastSquaresIdentity::postProcessing(), and train().

◆ grid

std::unique_ptr<sgpp::base::Grid> sgpp::datadriven::LearnerBase::grid
protected

◆ isRegression

bool sgpp::datadriven::LearnerBase::isRegression
protected

is regression selected

Referenced by getAccuracy(), getCassificatorQuality(), getIsRegression(), LearnerBase(), and train().

◆ isTrained

bool sgpp::datadriven::LearnerBase::isTrained
protected

is the grid trained

Referenced by dumpFunction(), dumpGrid(), LearnerBase(), and train().

◆ isVerbose

bool sgpp::datadriven::LearnerBase::isVerbose
protected

◆ reuseCoefficients

bool sgpp::datadriven::LearnerBase::reuseCoefficients
protected

shall the coefficients be reused between refinement steps

Referenced by LearnerBase(), sgpp::datadriven::LearnerLeastSquaresIdentity::postProcessing(), setReuseCoefficients(), and train().

◆ solverVerbose

bool sgpp::datadriven::LearnerBase::solverVerbose
protected

sets the verbose option for the solver

Referenced by LearnerBase(), setSolverVerbose(), and train().

◆ stepExecTime

double sgpp::datadriven::LearnerBase::stepExecTime
protected

execution time for current refinement to calculate the GFlops at the current timestep only otherwise accumulated GFlops (all refinement steps) are calculated

Referenced by LearnerBase(), and train().

◆ stepGByte

double sgpp::datadriven::LearnerBase::stepGByte
protected

number of transferred Gbytes in the current refinement step

Referenced by LearnerBase().

◆ stepGFlop

double sgpp::datadriven::LearnerBase::stepGFlop
protected

number of executed Floating Point operations in the current refinement step

Referenced by LearnerBase().


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