|
cMHN 1.2
C++ library for learning MHNs with pRC
|
Namespaces | |
| namespace | nonTT |
| namespace | TT |
Classes | |
| class | KLScore |
| Class storing a KL Score, specializes the Score class. More... | |
| class | L1Regulator |
| Class storing an L1 Regulator, specializes the Regulator class. More... | |
| class | L2Regulator |
| Class storing an L2 Regulator, specializes the Regulator class. More... | |
| class | Regulator |
| Class storing all relevant information for a regulator. More... | |
| class | Score |
| Class storing all relevant information for a score. More... | |
| class | sKLdynScore |
| Class storing a dynamic sKL-Divergence Score, specializes the Score class. More... | |
| class | sKLScore |
| Class storing a static sKL-Divergence Score, specializes the Score class. More... | |
Functions | |
| template<class T , pRC::Size D> | |
| decltype(expand(pRC::makeConstantSequence< pRC::Size, D, 2 >(), [](auto const ... Ns) { return pRC::Tensor< T, Ns... >{};})) | calculatePTheta (nonTT::MHNOperator< T, D > const &op) |
| Calculates the vector pTheta given a nonTT MHN Operator. | |
| template<pRC::Size R, class T , class X , pRC::Size D> | |
| X | calculatePTheta (TT::MHNOperator< T, D > const &op, X const &pInit, T const &toleranceSolver) |
| Calculates the vector pTheta (as a TT) given a TT MHN Operator and a tolerance. | |
| template<pRC::Size R, class T , pRC::Size D> | |
| auto | calculatePTheta (TT::MHNOperator< T, D > const &op, T const &toleranceSolver) |
| Calculates the vector pTheta (as a TT) given a TT MHN Operator and a tolerance. | |
| template<class T , pRC::Size D, class S > | |
| T | calculateScore (nonTT::MHNOperator< T, D > const &op, std::map< S, T > const &pD, cMHN::Score< T > const &Score, cMHN::Regulator< T, D > const &Regulator) |
| Calculate score of a theta matrix given some data distribution pD. | |
| template<pRC::Size RP, class T , pRC::Size D, class S > | |
| T | calculateScore (TT::MHNOperator< T, D > const &op, std::map< S, T > const &pD, cMHN::Score< T > const &Score, cMHN::Regulator< T, D > const &Regulator, T const &toleranceSolverP=1e-4) |
| Calculate score of a theta matrix given some data distribution pD (using TTs) | |
| template<class T , pRC::Size D, class S > | |
| std::tuple< T, pRC::Tensor< T, D, D > > | calculateScoreAndGradient (nonTT::MHNOperator< T, D > const &op, std::map< S, T > const &pD, cMHN::Score< T > const &Score, cMHN::Regulator< T, D > const &Regulator, T const &toleranceSolverQ=1e-8) |
| Calculate score and gradient of a theta matrix given some data distribution pD. | |
| template<pRC::Size RP, pRC::Size RQ, class T , pRC::Size D, class S , class X > | |
| std::tuple< T, pRC::Tensor< T, D, D > > | calculateScoreAndGradient (TT::MHNOperator< T, D > const &op, std::map< S, T > const &pD, cMHN::Score< T > const &Score, cMHN::Regulator< T, D > const &Regulator, X &pInit, T const &toleranceSolverP=1e-4, T const &toleranceSolverQ=1e-4) |
| Calculate score and gradient of a theta matrix given some distribution pD (using TTs) | |
| template<pRC::Size RP, pRC::Size RQ, class T , pRC::Size D, class S > | |
| std::tuple< T, pRC::Tensor< T, D, D > > | calculateScoreAndGradient (TT::MHNOperator< T, D > const &op, std::map< S, T > const &pD, cMHN::Score< T > const &Score, cMHN::Regulator< T, D > const &Regulator, T const &toleranceSolverP=1e-4, T const &toleranceSolverQ=1e-4) |
| Calculate score and gradient of a theta matrix given some distribution pD (using TTs) | |
| template<class T , class S > | |
| static auto | learnIndependenceModel (std::map< S, T > const &pD) |
| Calculate the theta matrix corresponding to the independence model for a given data distribution. | |
| template<class T , class S > | |
| static auto | combinePDs (std::vector< std::map< S, T > > const &pDs, std::vector< pRC::Index > const &lengths) |
| Combines multiple data distributions into a single distribution. | |
| template<class T , pRC::Size D, class F > | |
| static auto | generateData (pRC::RandomEngine< F > &rng, pRC::Tensor< T, D, D > const &smallThetaGT, pRC::Size const &size, std::string const &header, std::string const &filename) |
| Generates a data file from a given ground truth model. | |
| template<class T , pRC::Size D> | |
| static auto | generateData (pRC::Tensor< T, D, D > const &smallThetaGT, pRC::Size const &size, std::string const &header, std::string const &filename) |
| Generates a data file from a given ground truth model. | |
| template<class T , pRC::Size D, class F > | |
| static auto | generatePD (pRC::RandomEngine< F > &rng, pRC::Tensor< T, D, D > const &smallThetaGT, pRC::Size const &size) |
| Generates a data distribution from a given ground truth model. | |
| template<class T , pRC::Size D> | |
| static auto | generatePD (pRC::Tensor< T, D, D > const &smallThetaGT, pRC::Size const &size) |
| Generates a data distribution from a given ground truth model. | |
| template<pRC::Size D, class T = pRC::Float<>, class F > | |
| static auto | generateTheta (pRC::RandomEngine< F > &rng, pRC::Float<> const &fullness=0.5, T const &diagonalMean=-2, T const &diagonalStd=2, T const &offDiagonalMean=0, T const &offDiagonalB=0.75) |
| Generates a random theta matrix according to given distributions, and with given fullness. | |
| template<pRC::Size D, class T = pRC::Float<>> | |
| static auto | generateTheta (pRC::Float<> const &fullness=0.5, T const &diagonalMean=-2, T const &diagonalStd=2, T const &offDiagonalMean=0, T const &offDiagonalB=0.75) |
| Generates a random theta matrix according to given distributions, and with given fullness. | |
| template<class T , pRC::Size D> | |
| static auto | getCrossValSplits (std::string const &filename, pRC::Index const &k) |
| Splits the samples in a dataset into k as equal as possible sized sets that can be used for k-fold cross-validated training. | |
| template<class T , pRC::Size D> | |
| static auto | readData (std::string const &filename) |
| Reads a dataset from file, where the first line is the header (containing event names) and all subsequent lines contain one sample, with entries separated by commas or spaces. | |
| static auto | readHeader (std::string const &filename) |
| Reads the header of a dataset from file. | |
| template<class T , pRC::Size D> | |
| static auto | readTheta (std::string const &filename) |
| Reads a theta matrix from file, discarding its header. | |
| template<class S > | |
| static auto | getRandomSubscripts () |
| Generates a uniformly distributed random Subscripts element for a Tensor or a TT. | |
| template<class T , pRC::Size D> | |
| static auto | writeTheta (std::string const &filename, std::string const &header, pRC::Tensor< T, D, D > const &theta, std::map< std::string, std::string > const &logInfoNames={}, std::map< std::string, double > const &logInfoNumbers={}) |
| Writes a theta matrix to file, including additional logging information at the bottom. | |
| decltype(expand(pRC::makeConstantSequence< pRC::Size, D, 2 >(),[](auto const ... Ns) { return pRC::Tensor< T, Ns... >{}; })) cMHN::calculatePTheta | ( | nonTT::MHNOperator< T, D > const & | op | ) |
Calculates the vector pTheta given a nonTT MHN Operator.
This solves the linear equation (1-Q)*pTheta = p0, where Q is an MHN Operator and p0 is the initial distribution, i.e. (100%, 0%, ..., 0%). This operation is exact, so no tolerance can be provided.
| T | type used for calculations (inferred) |
| D | number of events of the dataset (inferred) |
| op | nonTT MHN Operator constructed from a theta matrix |
| auto cMHN::calculatePTheta | ( | TT::MHNOperator< T, D > const & | op, |
| T const & | toleranceSolver ) |
Calculates the vector pTheta (as a TT) given a TT MHN Operator and a tolerance.
This solves the linear equation (1-Q)*pTheta = p0, where Q is an MHN Operator and p0 is the initial distribution, i.e. (100%, 0%, ..., 0%).
| R | max TT rank of pTheta |
| T | type used for calculations (inferred) |
| D | number of events of the dataset (inferred) |
| op | TT MHN Operator constructed from a theta matrix |
| toleranceSolver | tolerance passed to the solver of the linear system |
| X cMHN::calculatePTheta | ( | TT::MHNOperator< T, D > const & | op, |
| X const & | pInit, | ||
| T const & | toleranceSolver ) |
Calculates the vector pTheta (as a TT) given a TT MHN Operator and a tolerance.
This solves the linear equation (1-Q)*pTheta = p0, where Q is an MHN Operator and p0 is the initial distribution, i.e. (100%, 0%, ..., 0%).
| R | max TT rank of pTheta |
| T | type used for calculations (inferred) |
| X | class of pTheta (inferred) |
| D | number of events of the dataset (inferred) |
| op | TT MHN Operator constructed from a theta matrix |
| pInit | initial value for linear equation |
| toleranceSolver | tolerance passed to the solver of the linear system |
| T cMHN::calculateScore | ( | nonTT::MHNOperator< T, D > const & | op, |
| std::map< S, T > const & | pD, | ||
| cMHN::Score< T > const & | Score, | ||
| cMHN::Regulator< T, D > const & | Regulator ) |
Calculate score of a theta matrix given some data distribution pD.
| T | type used for calculations (inferred) |
| D | number of events of the dataset (inferred) |
| S | Subscripts type used as keys in data distributions (inferred) |
| T cMHN::calculateScore | ( | TT::MHNOperator< T, D > const & | op, |
| std::map< S, T > const & | pD, | ||
| cMHN::Score< T > const & | Score, | ||
| cMHN::Regulator< T, D > const & | Regulator, | ||
| T const & | toleranceSolverP = 1e-4 ) |
Calculate score of a theta matrix given some data distribution pD (using TTs)
| RP | max TT rank of pTheta |
| T | type used for calculations (inferred) |
| D | number of events of the dataset (inferred) |
| S | Subscripts type used as keys in data distributions (inferred) |
| std::tuple< T, pRC::Tensor< T, D, D > > cMHN::calculateScoreAndGradient | ( | nonTT::MHNOperator< T, D > const & | op, |
| std::map< S, T > const & | pD, | ||
| cMHN::Score< T > const & | Score, | ||
| cMHN::Regulator< T, D > const & | Regulator, | ||
| T const & | toleranceSolverQ = 1e-8 ) |
Calculate score and gradient of a theta matrix given some data distribution pD.
| T | type used for calculations (inferred) |
| D | number of events of the dataset (inferred) |
| S | Subscripts type used as keys in data distributions (inferred) |
| std::tuple< T, pRC::Tensor< T, D, D > > cMHN::calculateScoreAndGradient | ( | TT::MHNOperator< T, D > const & | op, |
| std::map< S, T > const & | pD, | ||
| cMHN::Score< T > const & | Score, | ||
| cMHN::Regulator< T, D > const & | Regulator, | ||
| T const & | toleranceSolverP = 1e-4, | ||
| T const & | toleranceSolverQ = 1e-4 ) |
| std::tuple< T, pRC::Tensor< T, D, D > > cMHN::calculateScoreAndGradient | ( | TT::MHNOperator< T, D > const & | op, |
| std::map< S, T > const & | pD, | ||
| cMHN::Score< T > const & | Score, | ||
| cMHN::Regulator< T, D > const & | Regulator, | ||
| X & | pInit, | ||
| T const & | toleranceSolverP = 1e-4, | ||
| T const & | toleranceSolverQ = 1e-4 ) |
Calculate score and gradient of a theta matrix given some distribution pD (using TTs)
pInit is used as the starting point of the calculation of pTheta. Beware that it is updated in place to the solution pTheta after it is obtained.
| RP | max TT rank of pTheta |
| RQ | max TT rank of q |
| T | type used for calculations (inferred) |
| D | number of events of the dataset (inferred) |
| S | Subscripts type used as keys in data distributions (inferred) |
| X | class of pInit (inferred) |
| op | MHNOperator to calculate score and gradient of |
| pD | data distribution |
| Score | Score to use |
| Regulator | Regulator to use |
| pInit | initial value for linear equation |
| toleranceSolverP | tolerance to use when calculating pTheta (default: 1e-4) |
| toleranceSolverQ | tolerance to use when calculating q (default: 1e-4) |
|
inlinestatic |
Combines multiple data distributions into a single distribution.
| T | type used for calculations (inferred) |
| S | Subscripts type used as keys in data distribution (inferred) |
| pDs | data distributions to combine |
|
inlinestatic |
Generates a data file from a given ground truth model.
| T | type used for calculations (inferred) |
| D | number of events of the dataset (inferred) |
| F | base class of pRC::RandomEngine (inferred) |
| rng | RandomEngine to use for generating random numbers (needed not to get the same rng every time) |
| smallThetaGT | small theta matrix of ground truth model (pRC::Tensor<T, D, D> object) |
| size | number of samples to take into account when constructing the data distribution pTheta |
| header | header of the output file, i.e. event names |
| filename | output filename |
|
inlinestatic |
Generates a data file from a given ground truth model.
| T | type used for calculations (inferred) |
| D | number of events of the dataset (inferred) |
| smallThetaGT | small theta matrix of ground truth model (pRC::Tensor<T, D, D> object) |
| size | number of samples to take into account when constructing the data distribution |
| header | header of the output file, i.e. event names |
| filename | output filename |
|
inlinestatic |
Generates a data distribution from a given ground truth model.
| T | type used for calculations (inferred) |
| D | number of events of the dataset (inferred) |
| F | base class of pRC::RandomEngine (inferred) |
| rng | RandomEngine to use for generating random numbers (needed not to get the same rng every time) |
| smallThetaGT | small theta matrix of ground truth model (pRC::Tensor<T, D, D> object) |
| size | number of samples to take into account when constructing the data distribution |
|
inlinestatic |
Generates a data distribution from a given ground truth model.
| T | type used for calculations (inferred) |
| D | number of events of the dataset (inferred) |
| smallThetaGT | small theta matrix of ground truth model (pRC::Tensor<T, D, D> object) |
| size | number of samples to take into account when constructing the data distribution |
| toleranceSolverP | tolerance passed to the solver calculating pTheta |
|
inlinestatic |
Generates a random theta matrix according to given distributions, and with given fullness.
This function is used when no pRC::RandomEngine is passed.
Diagonal entries of the theta matrix (small thetas!) are generated using a Gaussian distribution, whose mean and standard deviation can be specified. Off diagonal entries are generated using a Laplace distribution, whose mean and b-parameter can be specified. The distribution's standard deviation is given by sqrt(2)*b.
| D | number of events of the dataset |
| T | type used for calculations (inferred) |
| fullness | Percentage of entries in theta matrix that are allowed to differ from 0 (stochastically) |
| diagonalMean | mean of the distribution generating the diagonal entries |
| diagonalStd | standard deviation of the distribution generating the diagonal entries |
| offDiagonalMean | mean of the distribution generating the off diagonal entries |
| offDiagonalB | B parameter of the distribution generating the off diagonal entries |
|
inlinestatic |
Generates a random theta matrix according to given distributions, and with given fullness.
Diagonal entries of the theta matrix (small thetas!) are generated using a Gaussian distribution, whose mean and standard deviation can be specified. Off diagonal entries are generated using a Laplace distribution, whose mean and b-parameter can be specified. The distribution's standard deviation is given by sqrt(2)*b.
| D | number of events of the dataset |
| T | type used for calculations (inferred) |
| F | base class of pRC::RandomEngine (inferred) |
| rng | RandomEngine to use for generating random numbers (needed not to get the same rng every time) |
| fullness | Percentage of entries in theta matrix that are allowed to differ from 0 (stochastically) |
| diagonalMean | mean of the distribution generating the diagonal entries |
| diagonalStd | standard deviation of the distribution generating the diagonal entries |
| offDiagonalMean | mean of the distribution generating the off diagonal entries |
| offDiagonalB | B parameter of the distribution generating the off diagonal entries |
|
inlinestatic |
Splits the samples in a dataset into k as equal as possible sized sets that can be used for k-fold cross-validated training.
| T | type used for calculations (usually pRC::Float<>) |
| D | number of events of the dataset |
| filename | name of the file containing the dataset |
| k | number of equally sized sets to produce |
|
inlinestatic |
Generates a uniformly distributed random Subscripts element for a Tensor or a TT.
| S | Subscripts Class to generate random element of |
Calculate the theta matrix corresponding to the independence model for a given data distribution.
| T | type used for calculations (inferred) |
| S | Subscripts type used as keys in data distributions (inferred) |
| pD | data distribution |
|
inlinestatic |
Reads a dataset from file, where the first line is the header (containing event names) and all subsequent lines contain one sample, with entries separated by commas or spaces.
| T | type used for calculations (usually pRC::Float<>) |
| D | number of events of the dataset |
| filename | name of the file containing the dataset |
|
inlinestatic |
Reads the header of a dataset from file.
| filename | name of the file to read |
|
inlinestatic |
Reads a theta matrix from file, discarding its header.
| T | type used for calculations |
| D | number of events of the dataset |
| filename | name of the file to read from |
|
inlinestatic |
Writes a theta matrix to file, including additional logging information at the bottom.
| T | type used for calculations (inferred) |
| D | number of events of the dataset (inferred) |
| filename | name of the file to write to |
| header | header of the input file, i.e. event names |
| theta | theta matrix |
| logInfoNames | logging information as a map string -> string (usually used for score and regulator names) |
| logInfoNumbers | logging information as a map string -> double (usually used for score, time, etc.) |