SG++-Doxygen-Documentation
sgpp::datadriven::Harmonica Class Reference

Class to host all methods required to perform the harmonica algorithm. More...

#include <Harmonica.hpp>

Public Member Functions

bool addConstraint (size_t idx, int bias)
 Adds a constraint based on an entry in the parity row. More...
 
void calculateConstrainedSpace (const DataVector &transformedScores, double lambda, int shrink)
 Second step of the harmonica algorithm. More...
 
bool checkConstraints ()
 Tests all constraints for validity in the current bit configuration. More...
 
void createRandomConfigs (size_t nBits, std::vector< int > &configIDs, int seed, size_t start)
 Function to create a vector of random numbers within the valid range of possible configurations without duplicates. More...
 
void fixConfigBits (bool resetFree)
 resolves constraints, fixing free and dependent bits More...
 
 Harmonica (FitterFactory *fitterFactory)
 Constructor. More...
 
int moveToNewSpace (int configID, std::vector< ConfigurationBit *> oldFreeBits)
 Recalculates a configID to the new constrained binary space. More...
 
void prepareConfigs (std::vector< ModelFittingBase *> &fitters, int seed, std::vector< std::string > &configStrings)
 First step in harmonica. More...
 
void resetBits ()
 resets bits to be able to resolve constraints again More...
 
void setParameters (int configID, size_t matrixrow)
 Sets bits and the resulting parameter configuration based on a configID while simultaneously creating one row of the parity function matrix. More...
 
void transformScores (const DataVector &source, DataVector &target)
 Transforms scores to accentuate the optimum. More...
 

Protected Attributes

std::vector< ConfigurationBit * > configBits
 all configuration bits More...
 
std::vector< int > configIDs
 binary configurations as integers More...
 
std::vector< std::unique_ptr< ConfigurationRestriction > > constraints
 all constraints that currently exist More...
 
FitterFactoryfitterFactory
 pointer to the fitterFactory to produce fitters for each configuration More...
 
std::vector< ConfigurationBit * > freeBits
 bits that are not dependent on other bits More...
 
base::DataMatrix paritymatrix
 matrix that holds the values of the parity function (predictors for regression) for all samples More...
 
std::vector< std::vector< ConfigurationBit * > > parityrow
 row to create the parity matrix and the constraints More...
 
DataVector savedScores
 Scores saved for moving configurations to new space. More...
 

Detailed Description

Class to host all methods required to perform the harmonica algorithm.

Constructor & Destructor Documentation

◆ Harmonica()

sgpp::datadriven::Harmonica::Harmonica ( FitterFactory fitterFactory)
explicit

Constructor.

Parameters
fitterFactoryto produce fitter type objects

References configBits, freeBits, and sgpp::datadriven::FitterFactory::getConfigBits().

Member Function Documentation

◆ addConstraint()

bool sgpp::datadriven::Harmonica::addConstraint ( size_t  idx,
int  bias 
)

Adds a constraint based on an entry in the parity row.

Parameters
idxindex of the parity row that holds pointers to the bits that will be constrained
biasbias value of the constraint

References checkConstraints(), constraints, fixConfigBits(), parityrow, and resetBits().

Referenced by calculateConstrainedSpace().

◆ calculateConstrainedSpace()

void sgpp::datadriven::Harmonica::calculateConstrainedSpace ( const DataVector transformedScores,
double  lambda,
int  shrink 
)

Second step of the harmonica algorithm.

Calculates relavance of ConfigurationBits and introduces constraints to reduce the search space

Parameters
transformedScoresinput (possibly transformed) scores after evaluation
lambdaused for regression
shrinknumber of constraints to introduce

References addConstraint(), alpha, configIDs, DEFAULT_RES_THRESHOLD, freeBits, g, sgpp::base::DataMatrix::getNcols(), python.statsfileInfo::i, moveToNewSpace(), sgpp::base::DataVector::normalize(), paritymatrix, parityrow, and savedScores.

◆ checkConstraints()

bool sgpp::datadriven::Harmonica::checkConstraints ( )

Tests all constraints for validity in the current bit configuration.

Returns
true when all constraints are met

References constraints.

Referenced by addConstraint(), and moveToNewSpace().

◆ createRandomConfigs()

void sgpp::datadriven::Harmonica::createRandomConfigs ( size_t  nBits,
std::vector< int > &  configIDs,
int  seed,
size_t  start 
)

Function to create a vector of random numbers within the valid range of possible configurations without duplicates.

Parameters
nBitsnumber of bits a configuration consists of
configIDscontainer to store generated random configuration ID's
seedto use in random generator
startto offset newly generated ID's from existing ones from previous iterations

References python.statsfileInfo::i, and sgpp::combigrid::pow().

Referenced by prepareConfigs().

◆ fixConfigBits()

void sgpp::datadriven::Harmonica::fixConfigBits ( bool  resetFree)

resolves constraints, fixing free and dependent bits

Returns
whether bits were fixed or just given values

References configBits, constraints, and freeBits.

Referenced by addConstraint(), moveToNewSpace(), and setParameters().

◆ moveToNewSpace()

int sgpp::datadriven::Harmonica::moveToNewSpace ( int  configID,
std::vector< ConfigurationBit *>  oldFreeBits 
)

Recalculates a configID to the new constrained binary space.

Parameters
configIDbinary configuration in old space as integer
oldFreeBitsbits that received the old binary values
Returns
binary configuartion in new space as integer

References checkConstraints(), fixConfigBits(), freeBits, m, and resetBits().

Referenced by calculateConstrainedSpace().

◆ prepareConfigs()

void sgpp::datadriven::Harmonica::prepareConfigs ( std::vector< ModelFittingBase *> &  fitters,
int  seed,
std::vector< std::string > &  configStrings 
)

First step in harmonica.

Configurations are prepared for evaluation and the parity function matrix is constructed for later use.

Parameters
fitterscontainer to store fitters for evaluation outside the class
seedfor random sampling
configStringscontainer to store information about the configurations in string form
Returns

References sgpp::datadriven::FitterFactory::buildFitter(), configIDs, createRandomConfigs(), fitterFactory, freeBits, python.statsfileInfo::i, m, paritymatrix, parityrow, sgpp::datadriven::FitterFactory::printConfig(), chess::seed, and setParameters().

◆ resetBits()

void sgpp::datadriven::Harmonica::resetBits ( )

resets bits to be able to resolve constraints again

References configBits, and constraints.

Referenced by addConstraint(), moveToNewSpace(), and setParameters().

◆ setParameters()

void sgpp::datadriven::Harmonica::setParameters ( int  configID,
size_t  matrixrow 
)

Sets bits and the resulting parameter configuration based on a configID while simultaneously creating one row of the parity function matrix.

Parameters
configIDbits of the configuration as an integer
matrixrowindex of the row of the parity matrix to be filled

References fitterFactory, fixConfigBits(), freeBits, python.statsfileInfo::i, paritymatrix, parityrow, resetBits(), sgpp::base::DataMatrix::set(), sgpp::datadriven::FitterFactory::setHarmonica(), and analyse_erg::tmp.

Referenced by prepareConfigs().

◆ transformScores()

void sgpp::datadriven::Harmonica::transformScores ( const DataVector source,
DataVector target 
)

Transforms scores to accentuate the optimum.

Parameters
source
target

References python.statsfileInfo::i, and sgpp::combigrid::pow().

Member Data Documentation

◆ configBits

std::vector<ConfigurationBit *> sgpp::datadriven::Harmonica::configBits
protected

all configuration bits

Referenced by fixConfigBits(), Harmonica(), and resetBits().

◆ configIDs

std::vector<int> sgpp::datadriven::Harmonica::configIDs
protected

binary configurations as integers

Referenced by calculateConstrainedSpace(), and prepareConfigs().

◆ constraints

std::vector<std::unique_ptr<ConfigurationRestriction> > sgpp::datadriven::Harmonica::constraints
protected

all constraints that currently exist

Referenced by addConstraint(), checkConstraints(), fixConfigBits(), and resetBits().

◆ fitterFactory

FitterFactory* sgpp::datadriven::Harmonica::fitterFactory
protected

pointer to the fitterFactory to produce fitters for each configuration

Referenced by prepareConfigs(), and setParameters().

◆ freeBits

std::vector<ConfigurationBit *> sgpp::datadriven::Harmonica::freeBits
protected

bits that are not dependent on other bits

Referenced by calculateConstrainedSpace(), fixConfigBits(), Harmonica(), moveToNewSpace(), prepareConfigs(), and setParameters().

◆ paritymatrix

base::DataMatrix sgpp::datadriven::Harmonica::paritymatrix
protected

matrix that holds the values of the parity function (predictors for regression) for all samples

Referenced by calculateConstrainedSpace(), prepareConfigs(), and setParameters().

◆ parityrow

std::vector<std::vector<ConfigurationBit *> > sgpp::datadriven::Harmonica::parityrow
protected

row to create the parity matrix and the constraints

Referenced by addConstraint(), calculateConstrainedSpace(), prepareConfigs(), and setParameters().

◆ savedScores

DataVector sgpp::datadriven::Harmonica::savedScores
protected

Scores saved for moving configurations to new space.

Referenced by calculateConstrainedSpace().


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