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

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

#include <LearnerBaseSP.hpp>

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::DataMatrixSP &testDataset, const sgpp::base::DataVectorSP &classesReference, const float threshold=0.0)
 compute the accuracy for given testDataset. More...
 
virtual double getAccuracy (const sgpp::base::DataVectorSP &classesComputed, const sgpp::base::DataVectorSP &classesReference, const float threshold=0.0)
 compute the accuracy for given testDataset. More...
 
virtual ClassificatorQuality getCassificatorQuality (sgpp::base::DataMatrixSP &testDataset, const sgpp::base::DataVectorSP &classesReference, const float 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::DataVectorSP &classesComputed, const sgpp::base::DataVectorSP &classesReference, const float threshold=0.0)
 compute the quality for given testDataset, classification ONLY! More...
 
bool getIsRegression () const
 determines the current mode More...
 
bool getIsVerbose () const
 determines the current verbose mode of learner More...
 
 LearnerBaseSP (const bool isRegression, const bool isVerbose=true)
 Constructor. More...
 
 LearnerBaseSP (std::string tGridFilename, std::string tAlphaFilename, const bool isRegression, const bool isVerbose=true)
 Constructor. More...
 
 LearnerBaseSP (const LearnerBaseSP &copyMe)
 Copy-Constructor. More...
 
virtual sgpp::base::DataVectorSP predict (sgpp::base::DataMatrixSP &testDataset)
 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 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::DataMatrixSP &testDataset, sgpp::base::DataVectorSP &classes, const sgpp::base::RegularGridConfiguration &GridConfig, const sgpp::solver::SLESolverSPConfiguration &SolverConfigRefine, const sgpp::solver::SLESolverSPConfiguration &SolverConfigFinal, const sgpp::base::AdaptivityConfiguration &AdaptConfig, bool testAccDuringAdapt, const float lambdaRegularization)
 Learning a dataset with spatially adaptive sparse grids. More...
 
LearnerTiming train (sgpp::base::DataMatrixSP &testDataset, sgpp::base::DataVectorSP &classes, const sgpp::base::RegularGridConfiguration &GridConfig, const sgpp::solver::SLESolverSPConfiguration &SolverConfig, const float lambdaRegularization)
 Learning a dataset with regular sparse grids. More...
 
virtual ~LearnerBaseSP ()
 Destructor. More...
 

Protected Member Functions

virtual sgpp::datadriven::DMSystemMatrixBaseSPcreateDMSystem (sgpp::base::DataMatrixSP &trainDataset, float lambdaRegularization)=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::DataMatrixSP &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

sgpp::base::DataVectorSPalpha_
 the grid's coefficients More...
 
double execTime_
 execution time More...
 
double GByte_
 number of transferred Gbytes More...
 
double GFlop_
 number of executed Floating Point operations More...
 
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...
 

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.

This versions supports single precision datatypes.

Constructor & Destructor Documentation

◆ LearnerBaseSP() [1/3]

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

Constructor.

Parameters
isRegressionflag for regression
isVerboseflag for verbose output

◆ LearnerBaseSP() [2/3]

sgpp::datadriven::LearnerBaseSP::LearnerBaseSP ( std::string  tGridFilename,
std::string  tAlphaFilename,
const bool  isRegression,
const bool  isVerbose = true 
)

Constructor.

Parameters
tGridFilenamepath to file that contains a serialized grid
tAlphaFilenamepath to file that contains the grid's coefficients
isRegressionset to true if a regression task should be executed
isVerboseset to true in order to allow console output

◆ LearnerBaseSP() [3/3]

sgpp::datadriven::LearnerBaseSP::LearnerBaseSP ( const LearnerBaseSP copyMe)

Copy-Constructor.

Parameters
copyMeLearnerBase that should be duplicated

References alpha_, grid_, isRegression_, sgpp::base::Grid::serialize(), and sgpp::base::Grid::unserialize().

◆ ~LearnerBaseSP()

sgpp::datadriven::LearnerBaseSP::~LearnerBaseSP ( )
virtual

Destructor.

References alpha_, and grid_.

Member Function Documentation

◆ createDMSystem()

virtual sgpp::datadriven::DMSystemMatrixBaseSP* sgpp::datadriven::LearnerBaseSP::createDMSystem ( sgpp::base::DataMatrixSP trainDataset,
float  lambdaRegularization 
)
protectedpure virtual

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

Parameters
trainDatasettraining dataset
lambdaRegularizationlambda regularization parameter

Referenced by train().

◆ dumpFunction()

void sgpp::datadriven::LearnerBaseSP::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_, sgpp::base::PrecisionConverter::convertDataVectorSPToDataVector(), sgpp::base::Grid::getDimension(), sgpp::base::DataVectorSP::getSize(), grid_, and sgpp::base::GridPrinter::printGrid().

◆ dumpGrid()

void sgpp::datadriven::LearnerBaseSP::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_, sgpp::base::PrecisionConverter::convertDataVectorSPToDataVector(), sgpp::base::DataVectorSP::getSize(), grid_, and sgpp::base::GridPrinter::printSparseGrid().

◆ getAccuracy() [1/2]

double sgpp::datadriven::LearnerBaseSP::getAccuracy ( sgpp::base::DataMatrixSP testDataset,
const sgpp::base::DataVectorSP classesReference,
const float  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 predict().

Referenced by train().

◆ getAccuracy() [2/2]

double sgpp::datadriven::LearnerBaseSP::getAccuracy ( const sgpp::base::DataVectorSP classesComputed,
const sgpp::base::DataVectorSP classesReference,
const float  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::DataVectorSP::get(), sgpp::base::DataVectorSP::getSize(), python.statsfileInfo::i, sgpp::base::DataVectorSP::sqr(), sgpp::base::DataVectorSP::sub(), sgpp::base::DataVectorSP::sum(), and analyse_erg::tmp.

◆ getCassificatorQuality() [1/2]

ClassificatorQuality sgpp::datadriven::LearnerBaseSP::getCassificatorQuality ( sgpp::base::DataMatrixSP testDataset,
const sgpp::base::DataVectorSP classesReference,
const float  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 predict().

◆ getCassificatorQuality() [2/2]

ClassificatorQuality sgpp::datadriven::LearnerBaseSP::getCassificatorQuality ( const sgpp::base::DataVectorSP classesComputed,
const sgpp::base::DataVectorSP classesReference,
const float  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::DataVectorSP::get(), sgpp::base::DataVectorSP::getSize(), python.statsfileInfo::i, sgpp::datadriven::ClassificatorQuality::trueNegative_, and sgpp::datadriven::ClassificatorQuality::truePositive_.

◆ getIsRegression()

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

determines the current mode

Returns
returns whether the current mode is regression or not

References isRegression_.

◆ getIsVerbose()

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

determines the current verbose mode of learner

Returns
returns whether the current learner has verbose output

References isVerbose_.

◆ InitializeGrid()

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

◆ postProcessing()

void sgpp::datadriven::LearnerBaseSP::postProcessing ( const sgpp::base::DataMatrixSP 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 set
solversolver
numNeededIterationsnumber of required iterations

Referenced by train().

◆ predict()

◆ preProcessing()

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

Hook-Method for pre-processing before starting learning.

can be overwritten by derived classes

Referenced by train().

◆ setIsVerbose()

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

sets the current verbose mode of learner

Parameters
isVerbosethe current learner's verbose output

◆ store()

void sgpp::datadriven::LearnerBaseSP::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::LearnerBaseSP::train ( sgpp::base::DataMatrixSP testDataset,
sgpp::base::DataVectorSP classes,
const sgpp::base::RegularGridConfiguration GridConfig,
const sgpp::solver::SLESolverSPConfiguration SolverConfigRefine,
const sgpp::solver::SLESolverSPConfiguration SolverConfigFinal,
const sgpp::base::AdaptivityConfiguration AdaptConfig,
bool  testAccDuringAdapt,
const float  lambdaRegularization 
)
virtual

Learning a dataset with spatially adaptive sparse grids.

Parameters
testDatasetthe 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

References alpha_, chess::b, sgpp::solver::BiCGSTAB, sgpp::solver::CG, sgpp::base::PrecisionConverter::convertDataVectorSPToDataVector(), createDMSystem(), sgpp::solver::SLESolverSPConfiguration::eps_, execTime_, sgpp::datadriven::LearnerTiming::GByte_, GByte_, sgpp::datadriven::DMSystemMatrixBaseSP::generateb(), getAccuracy(), sgpp::base::Grid::getGenerator(), sgpp::base::DataMatrixSP::getNrows(), sgpp::solver::SGSolverSP::getNumberIterations(), sgpp::solver::SGSolverSP::getResiduum(), sgpp::base::DataVectorSP::getSize(), sgpp::base::Grid::getSize(), sgpp::datadriven::DMSystemMatrixBaseSP::getTimers(), GFlop_, sgpp::datadriven::LearnerTiming::GFlop_, grid_, python.statsfileInfo::i, InitializeGrid(), sgpp::solver::SLESolverSPConfiguration::maxIterations_, sgpp::base::AdaptivityConfiguration::noPoints_, sgpp::base::AdaptivityConfiguration::numRefinements_, postProcessing(), preProcessing(), sgpp::datadriven::DMSystemMatrixBaseSP::rebuildLevelAndIndex(), sgpp::base::GridGenerator::refine(), sgpp::base::DataVectorSP::resizeZero(), sgpp::solver::SGSolverSP::setEpsilon(), sgpp::solver::SGSolverSP::setMaxIterations(), sgpp::solver::SLESolverSP::solve(), sgpp::base::SGppStopwatch::start(), sgpp::base::SGppStopwatch::stop(), 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::SLESolverSPConfiguration::type_.

Referenced by train().

◆ train() [2/2]

LearnerTiming sgpp::datadriven::LearnerBaseSP::train ( sgpp::base::DataMatrixSP testDataset,
sgpp::base::DataVectorSP classes,
const sgpp::base::RegularGridConfiguration GridConfig,
const sgpp::solver::SLESolverSPConfiguration SolverConfig,
const float  lambdaRegularization 
)

Learning a dataset with regular sparse grids.

Parameters
testDatasetthe 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_

sgpp::base::DataVectorSP* sgpp::datadriven::LearnerBaseSP::alpha_
protected

◆ execTime_

double sgpp::datadriven::LearnerBaseSP::execTime_
protected

execution time

Referenced by train().

◆ GByte_

double sgpp::datadriven::LearnerBaseSP::GByte_
protected

number of transferred Gbytes

Referenced by train().

◆ GFlop_

double sgpp::datadriven::LearnerBaseSP::GFlop_
protected

number of executed Floating Point operations

Referenced by train().

◆ grid_

sgpp::base::Grid* sgpp::datadriven::LearnerBaseSP::grid_
protected

◆ isRegression_

bool sgpp::datadriven::LearnerBaseSP::isRegression_
protected

is regression selected

Referenced by getIsRegression(), and LearnerBaseSP().

◆ isTrained_

bool sgpp::datadriven::LearnerBaseSP::isTrained_
protected

is the grid trained

◆ isVerbose_

bool sgpp::datadriven::LearnerBaseSP::isVerbose_
protected

is verbose output enabled

Referenced by getIsVerbose().


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