cMHN 1.2
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
cMHN::nonTT Namespace Reference

Classes

class  MHNOperator
 Class storing an MHN operator represented by a theta matrix (for non TT calculations) More...
 

Functions

template<pRC::Operator::Transform OT = pRC::Operator::Transform::None, class T , class X , pRC::Size D, class RX = pRC::RemoveConstReference<X>>
jacobi (nonTT::MHNOperator< T, D > const &op, X const &b)
 Solves the linear system (1-Q)x=b or (1-Q)^Tx=b.
 
template<class T , pRC::Size D, class S >
std::tuple< pRC::Tensor< T, D, D >, std::map< std::string, std::string >, std::map< std::string, double > > learnTheta (pRC::Tensor< T, D, D > const &theta, std::string const &header, std::string const &output, std::map< S, T > const &pD, cMHN::Score< T > const &Score, cMHN::Regulator< T, D > const &Regulator, T const &toleranceOptimizer, T const &toleranceSolverQ)
 Optimizes an MHN represented by a theta matrix to best describe a given data distribution.
 
template<pRC::Operator::Transform OT = pRC::Operator::Transform::None, pRC::Operator::Restrict OR = pRC::Operator::Restrict::None, pRC::Operator::Hint OH = pRC::Operator::Hint::None, class T1 , pRC::Size D, class T2 , pRC::Size... Ns>
requires (OR == pRC::Operator::Restrict::None) && (OT == pRC::Operator::Transform::None)
static constexpr auto applyDerivative (MHNOperator< T1, D > const &op, pRC::Tensor< T2, Ns... > const &x, pRC::Index const &i)
 apply the derivative of an MHN Q wrt to theta_ii to a vector x
 
template<pRC::Operator::Transform OT = pRC::Operator::Transform::None, pRC::Operator::Restrict OR = pRC::Operator::Restrict::None, pRC::Operator::Hint OH = pRC::Operator::Hint::None, class T1 , pRC::Size D, class T2 , pRC::Size... Ns>
requires (OR == pRC::Operator::Restrict::None)
static constexpr auto apply_diag (MHNOperator< T1, D > const &op, pRC::Tensor< T2, Ns... > const &x)
 apply the diagonal part of (1-Q) to a vector x, given an MHN Q
 
template<pRC::Operator::Transform OT = pRC::Operator::Transform::None, pRC::Operator::Restrict OR = pRC::Operator::Restrict::None, pRC::Operator::Hint OH = pRC::Operator::Hint::None, class T1 , pRC::Size D, class T2 , pRC::Size... Ns>
requires (OR == pRC::Operator::Restrict::None)
static constexpr auto apply_offdiag (MHNOperator< T1, D > const &op, pRC::Tensor< T2, Ns... > const &x)
 apply the off-diagonal part of Q or its transposed to a vector x, given an MHN Q
 
template<pRC::Operator::Transform OT = pRC::Operator::Transform::None, pRC::Operator::Restrict OR = pRC::Operator::Restrict::None, pRC::Operator::Hint OH = pRC::Operator::Hint::None, class T1 , pRC::Size D, class T2 , pRC::Size... Ns>
requires (OR == pRC::Operator::Restrict::None)
static constexpr auto apply (MHNOperator< T1, D > const &op, pRC::Tensor< T2, Ns... > const &x)
 apply (1-Q) or its transposed to a vector x, given an MHN Q
 

Function Documentation

◆ apply()

template<pRC::Operator::Transform OT = pRC::Operator::Transform::None, pRC::Operator::Restrict OR = pRC::Operator::Restrict::None, pRC::Operator::Hint OH = pRC::Operator::Hint::None, class T1 , pRC::Size D, class T2 , pRC::Size... Ns>
requires (OR == pRC::Operator::Restrict::None)
static constexpr auto cMHN::nonTT::apply ( MHNOperator< T1, D > const & op,
pRC::Tensor< T2, Ns... > const & x )
inlinestaticconstexpr

apply (1-Q) or its transposed to a vector x, given an MHN Q

Template Parameters
T1type used for calculations (from MHN Operator, inferred)
T2type used for calculations (from vector x, inferred)
Dnumber of events of the dataset (inferred)
Ns...Mode sizes of the D events (usually D instances of 2, inferred)
Parameters
opMHN Operator to apply
xvector to apply (1-Q) (or its transposed) to

◆ apply_diag()

template<pRC::Operator::Transform OT = pRC::Operator::Transform::None, pRC::Operator::Restrict OR = pRC::Operator::Restrict::None, pRC::Operator::Hint OH = pRC::Operator::Hint::None, class T1 , pRC::Size D, class T2 , pRC::Size... Ns>
requires (OR == pRC::Operator::Restrict::None)
static constexpr auto cMHN::nonTT::apply_diag ( MHNOperator< T1, D > const & op,
pRC::Tensor< T2, Ns... > const & x )
inlinestaticconstexpr

apply the diagonal part of (1-Q) to a vector x, given an MHN Q

Template Parameters
T1type used for calculations (from MHN Operator, inferred)
T2type used for calculations (from vector x, inferred)
Dnumber of events of the dataset (inferred)
Ns...Mode sizes of the D events (usually D instances of 2, inferred)
Parameters
opMHN Operator to apply
xvector to apply diagonal of (1-Q) (or its transposed) to

◆ apply_offdiag()

template<pRC::Operator::Transform OT = pRC::Operator::Transform::None, pRC::Operator::Restrict OR = pRC::Operator::Restrict::None, pRC::Operator::Hint OH = pRC::Operator::Hint::None, class T1 , pRC::Size D, class T2 , pRC::Size... Ns>
requires (OR == pRC::Operator::Restrict::None)
static constexpr auto cMHN::nonTT::apply_offdiag ( MHNOperator< T1, D > const & op,
pRC::Tensor< T2, Ns... > const & x )
inlinestaticconstexpr

apply the off-diagonal part of Q or its transposed to a vector x, given an MHN Q

Template Parameters
T1type used for calculations (from MHN Operator, inferred)
T2type used for calculations (from vector x, inferred)
Dnumber of events of the dataset (inferred)
Ns...Mode sizes of the D events (usually D instances of 2, inferred)
Parameters
opMHN Operator to apply
xvector to apply off-diagonal of Q (or its transposed) to

◆ applyDerivative()

template<pRC::Operator::Transform OT = pRC::Operator::Transform::None, pRC::Operator::Restrict OR = pRC::Operator::Restrict::None, pRC::Operator::Hint OH = pRC::Operator::Hint::None, class T1 , pRC::Size D, class T2 , pRC::Size... Ns>
requires (OR == pRC::Operator::Restrict::None) && (OT == pRC::Operator::Transform::None)
static constexpr auto cMHN::nonTT::applyDerivative ( MHNOperator< T1, D > const & op,
pRC::Tensor< T2, Ns... > const & x,
pRC::Index const & i )
inlinestaticconstexpr

apply the derivative of an MHN Q wrt to theta_ii to a vector x

Template Parameters
T1type used for calculations (from MHN Operator, inferred)
T2type used for calculations (from vector x, inferred)
Dnumber of events of the dataset (inferred)
Ns...Mode sizes of the D events (usually D instances of 2)
Parameters
opMHN Operator to calculate derivative of
xvector to apply derivative to
iindex of theta entry wrt which derivative is taken of

◆ jacobi()

template<pRC::Operator::Transform OT = pRC::Operator::Transform::None, class T , class X , pRC::Size D, class RX = pRC::RemoveConstReference<X>>
X cMHN::nonTT::jacobi ( nonTT::MHNOperator< T, D > const & op,
X const & b )

Solves the linear system (1-Q)x=b or (1-Q)^Tx=b.

Template Parameters
Ttype used for calculations (inferred)
Xclass of pTheta (inferred)
Dnumber of events of the dataset (inferred)
Parameters
opnonTT MHN Operator constructed from a theta matrix
pInitinitial value for linear equation
toleranceSolvertolerance passed to the solver of the linear system

◆ learnTheta()

template<class T , pRC::Size D, class S >
std::tuple< pRC::Tensor< T, D, D >, std::map< std::string, std::string >, std::map< std::string, double > > cMHN::nonTT::learnTheta ( pRC::Tensor< T, D, D > const & theta,
std::string const & header,
std::string const & output,
std::map< S, T > const & pD,
cMHN::Score< T > const & Score,
cMHN::Regulator< T, D > const & Regulator,
T const & toleranceOptimizer,
T const & toleranceSolverQ )

Optimizes an MHN represented by a theta matrix to best describe a given data distribution.

The optimization is done by LBFGS. Logging information containing Score and Regulator names, Iteration number, Time, Score and Regularization strength is written to file after every iteration.

The optimized theta is returned. Additionally, two std::maps are returned containing logging information:

  • std::map<std::string, std::string> logInfoNames: Info like Score name and Regulator name
  • std::map<std::string, double> logInfoNumbers: Info like final score and runtime
Template Parameters
Ttype used for calculations (inferred)
Dnumber of events of the dataset (inferred)
SSubscripts type used as keys in data distribution (inferred)
Parameters
thetatheta matrix representing the initial MHN
headerheader of the data (usually containing event names)
outputfile to write the theta matrix to
pDdata distribution to learn
ScoreScore object representing the score used
RegulatorRegulator object representing the regulator used
toleranceOptimizertolerance of the optimizer
toleranceSolverQtolerance of the solver for calculating q (intermediate result for calculating the derivatives)