MC++
mc::FFGraph Class Reference

C++ class representing the DAG of factorable functions. More...

#include <ffunc.hpp>

Classes

class  Exceptions
 Exceptions of mc::FFGraph. More...
 

Protected Member Functions

bool _remove_operation (FFOp *op)
 Erase operation op in set _Ops
 
void _clear_operations ()
 Erase all operations in set _Ops
 
void _reset_operations () const
 Reset all operations in set _Ops
 
FFOp_insert_operation (const typename FFOp::TYPE top, FFVar *lop, FFVar *rop=0)
 Looks for the operation of type top with left and right operands lop, rop in set _Ops and adds it if not found.
 
FFVar_add_auxiliary (const FFDep &dep, FFOp *pOp)
 Adds the auxiliary variable with dependency dep from operation op
 
FFVar_add_constant (const double x)
 Looks for the real constant x and adds it if not found.
 
FFVar_add_constant (const int n)
 Looks for the integer constant n and adds it if not found.
 
void _clear_variables ()
 Erase all variables in _Vars.
 
void _append_aux (FFVar *pAux, typename FFOp::TYPE tOp)
 Appends the auxiliary variable pAux and define it in _Ops with type tOp
 
virtual void _append_aux (FFVar *pAux)
 Appends new auxiliary variable.
 
virtual void _append_var (FFVar *pVar)
 Appends new original variable.
 
FFVar_find_var (const typename FFVar::pt_idVar &id)
 Search for the variable with identify id in _Vars
 

Static Protected Member Functions

static FFVar_insert_binary_operation (const typename FFOp::TYPE top, const FFDep &dep, const FFVar &Var1, const FFVar &Var2)
 Looks for the binary operation of type top with left and right operands Var1, Var2 in set _Ops and adds it if not found; also adds new auxiliary variable in set _Vars and update list of dependencies in both operands in _Vars
 
template<typename U >
static FFVar_insert_binary_operation (const typename FFOp::TYPE top, const FFDep &dep, const U &Cst1, const FFVar &Var2)
 Looks for the binary operation of type top with left and right operands Cst1, Var2 in set _Ops and adds it if not found; also adds new auxiliary variable as well as constant Cst1 in set _Vars and update list of dependencies in both operands in _Vars
 
template<typename U >
static FFVar_insert_binary_operation (const typename FFOp::TYPE top, const FFDep &dep, const FFVar &Var1, const U &Cst2)
 Looks for the binary operation of type top with left and right operands Var1, Cst2 in set _Ops and adds it if not found; also adds new auxiliary variable as well as constant Cst2 in set _Vars and update list of dependencies in both operands in _Vars
 
static FFVar_insert_unary_operation (const typename FFOp::TYPE top, const FFDep &dep, const FFVar &Var)
 Looks for the unary operation of type top with operand Var1, Var2 in set _Ops and adds it if not found; also adds new auxiliary variable in set _Vars and update list of dependencies in both operands in _Vars
 

Protected Attributes

unsigned long _nvar
 Number of original variables in DAG.
 
unsigned long _naux
 Number of auxiliary variables in DAG.
 
t_Vars _Vars
 Set of variables in DAG.
 
t_Ops _Ops
 Set of operations in DAG.
 
 FFGraph ()
 Default Constructor.
 
virtual ~FFGraph ()
 Destructor.
 
unsigned long nvar () const
 Number of original variables in DAG.
 
unsigned long naux () const
 Number of auxiliary variables in DAG.
 
const t_Vars & Vars () const
 Reference to set of (all) variables in factorable function.
 
void clear ()
 Clear DAG (all variables and operations)
 
std::list< const FFOp * > subgraph (const unsigned int nDep, const FFVar *pDep) const
 Extract list of operations corresponding to nDep dependents in array pDep
 
std::list< const FFOp * > subgraph (const std::vector< const FFVar * > &vDep) const
 Extract list of operations corresponding to dependents vDep
 
CPPL::dssmatrix depmap (const unsigned nDep, const FFVar *const pDep, const unsigned nIndep, const FFVar *const pIndep)
 Create dependency map corresponding to nDep dependents in array pDep and nIndep independents in array pIndep
 
CPPL::dssmatrix depmap (std::list< const FFOp * > &opDep, const unsigned nDep, const FFVar *const pDep, const unsigned nIndep, const FFVar *const pIndep)
 Create dependency map corresponding to nDep dependents in array pDep and nIndep independents in array pIndep – This function uses the subgraph for the dependents given in opDep
 
CPPL::dssmatrix depmap (const std::vector< const FFVar * > &vDep, const std::vector< const FFVar * > &vIndep)
 Create dependency map corresponding to the dependent variables pDep and independent variables pIndep
 
CPPL::dssmatrix depmap (std::list< const FFOp * > &opDep, const std::vector< const FFVar * > &vDep, const std::vector< const FFVar * > &vIndep)
 Create dependency map corresponding to the dependent variables pDep and independent variables pIndep – This function uses the subgraph for the dependents given in opDep
 
void dot_script (const unsigned int nDep, const FFVar *pDep, std::ostream &os=std::cout) const
 Generate script for DAG visualization of factors *F using DOT.
 
void dot_script (const std::vector< const FFVar * > &vDep, std::ostream &os=std::cout) const
 Generate script for DAG visualization of factors *F using DOT.
 
std::vector< const FFVar * > FAD (const std::vector< const FFVar * > &vDep, const std::vector< const FFVar * > &vIndep)
 Expand DAG with derivatives of dependents vDep with respect to independents vIndep using fadbad::F – Returns a vector with the entries of the Jacobian matrix ordered row-wise.
 
const FFVarFAD (const unsigned nDep, const FFVar *const pDep, const unsigned nIndep, const FFVar *const pIndep, const bool transp=false)
 Expand DAG with derivatives of nDep dependents in array pDep with respect to nIndep independents in array pIndep using fadbad::F – Returns an array with entries of the Jacobian matrix ordered row-wise.
 
std::vector< const FFVar * > BAD (const std::vector< const FFVar * > &vDep, const std::vector< const FFVar * > &vIndep)
 Expand DAG with derivatives of dependents vDep with respect to independents vIndep using fadbad::B – Returns a vector with the entries of the Jacobian matrix ordered row-wise.
 
const FFVarBAD (const unsigned nDep, const FFVar *const pDep, const unsigned nIndep, const FFVar *const pIndep, const bool transp=false)
 Expand DAG with derivatives of nDep dependents in array pDep with respect to nIndep independents in array pIndep using fadbad::B – Returns an array with entries of the Jacobian matrix ordered row-wise.
 
std::vector< const FFVar * > TAD (const unsigned int ordermax, const std::vector< const FFVar * > &vDep, const std::vector< const FFVar * > &vVar, const FFVar *const pIndep=0)
 Expand DAG with Taylor coefficients of dependents vDep with respect to independents vIndep using fadbad::T – Same number of dependents and independent is required, e.g. for expansion of ODE solutions – Return a vector with the 0th, 1st, ..., ordermax'th order Taylor coefficients ordered sequentially.
 
const FFVarTAD (const unsigned int ordermax, const unsigned nDep, const FFVar *const pDep, const unsigned nVar, const FFVar *const pVar, const FFVar *const pIndep=0)
 Expand DAG with Taylor coefficients of nDep dependents in array pDep with respect to nIndep independents in array pIndep using fadbad::T – Same number of dependents and independent is required, e.g. for expansion of ODE solutions – Returns an array with the 0th, 1st, ..., ordermax'th order Taylor coefficients ordered sequentially.
 
std::vector< const FFVar * > compose (const std::vector< const FFVar * > &vDepOut, const std::vector< std::pair< const FFVar *, const FFVar * > > &vDepIn)
 Compose the dependents in vDepOut with those in vDepIn – This function creates the subgraph for the outer dependent variables internally.
 
const FFVarcompose (const unsigned nDepOut, const FFVar *pDepOut, const unsigned nDepIn, const FFVar *pVarOut, const FFVar *pDepIn)
 Compose the nDepOut dependents in array pDepOut with the nDepIn dependents in array pDepIn for the variables pVarOut – This function creates the subgraph for the outer dependent variables internally.
 
template<typename U >
std::vector< U > eval (const std::vector< const FFVar * > &vDep, const std::vector< std::pair< const FFVar *, U > > &vVar)
 Evaluate the dependents in vDep in U arithmetic for the variable values specified in vVar – This function creates the subgraph for the dependent variables internally.
 
template<typename U >
std::vector< U > eval (std::list< const FFOp * > &opDep, const std::vector< const FFVar * > &vDep, const std::vector< std::pair< const FFVar *, U > > &vVar)
 Evaluate the dependents in vDep in U arithmetic for the variable values specified in vVar – This function uses the subgraph for the dependent variables given in opDep
 
template<typename U >
std::vector< U > eval (std::list< const FFOp * > &opDep, U *opRes, const std::vector< const FFVar * > &vDep, const std::vector< std::pair< const FFVar *, U > > &vVar)
 Evaluate the dependents in vDep in U arithmetic for the variable values specified in vVar – This function uses the subgraph for the dependent variables given in opDep as well as the preallocated array opRes of size opDep.size() to store intermediate results during the evaluation.
 
template<typename U >
void eval (const unsigned nDep, const FFVar *pDep, U *vDep, const unsigned nVar, const FFVar *pVar, U *vVar, const bool add=false)
 Evaluate the nDep dependents in array pDep in U arithmetic for the nVar variable in array pVar whose values are specified in vVar and write the result in vDep (or add the result to vDep if add==true) – This function creates the subgraph for the dependent variables internally.
 
template<typename U >
void eval (std::list< const FFOp * > &opDep, const unsigned nDep, const FFVar *pDep, U *vDep, const unsigned nVar, const FFVar *pVar, U *vVar, const bool add=false)
 Evaluate the nDep dependents in array pDep in U arithmetic for the nVar variable in array pVar whose values are specified in vVar and write the result in vDep (or add the result to vDep if add==true) – This function uses the subgraph for the dependent variables given in opDep
 
template<typename U >
void eval (std::list< const FFOp * > &opDep, U *opRes, const unsigned nDep, const FFVar *pDep, U *vDep, const unsigned nVar, const FFVar *pVar, U *vVar, const bool add=false)
 Evaluate the nDep dependents in array pDep in U arithmetic for the nVar variable in array pVar whose values are specified in vVar and write the result in vDep (or add the result to vDep if add==true) – This function uses the subgraph for the dependent variables given in opDep as well as the preallocated array opRes of size opDep.size() to store intermediate results during the evaluation.
 
static void output (const std::list< const FFOp * > &Ops, std::ostream &os=std::cout)
 Output list of nodes in Ops to os
 
static double cpuclock ()
 Return current clock time.
 

Detailed Description

mc::FFGraph is a C++ class representing the DAG of a factorable function, enabling basic manipulations on that DAG, and evaluating the DAG in various arithmetics.


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