![]() |
aGrUM 3.0.0
a C++ library for (probabilistic) graphical models
|
Summation (marginalization) over one or more variables. More...
#include <doAST.h>
Public Member Functions | |
| ASTsum (std::string_view var, std::unique_ptr< ASTtree< GUM_SCALAR > > term) | |
| Single-variable summation ( \sum_{\text{var}} \text{term} ). | |
| ASTsum (const std::vector< std::string > &vars, std::unique_ptr< ASTtree< GUM_SCALAR > > term) | |
| Multi-variable overload: recursively builds nested sums in the order of vars[0], vars[1], .... | |
| const std::string & | var () const |
| const ASTtree< GUM_SCALAR > & | term () const |
| std::string | toString (std::string_view prefix="") const override |
| Human-readable multi-line rendering (for debugging / logs). | |
| std::string | protectToLatex (HashTable< std::string, int > &nameOccur) const override |
| LaTeX rendering with full name protection. | |
| std::string | fastToLatex (HashTable< std::string, int > &nameOccur) const override |
| Fast LaTeX rendering (lighter protection). | |
| std::unique_ptr< ASTtree< GUM_SCALAR > > | copy () const override |
| Deep clone of the sub-tree. | |
| Tensor< GUM_SCALAR > | eval (const IBayesNet< GUM_SCALAR > &contextual_bn) const override |
| Evaluate the expression against a contextual BN. | |
| const std::string & | type () const noexcept |
| std::string | toLatex (HashTable< std::string, int > nameOccur=HashTable< std::string, int >()) const |
| Convenience wrapper using an empty occurrence table. | |
Static Protected Member Functions | |
| static std::string | _latexCorrect (std::string_view srcName, HashTable< std::string, int > &nameOccur) |
| Sanitize a single variable name for LaTeX and ensure uniqueness. | |
| static std::vector< std::string > | _latexCorrect (const Set< std::string > &srcNames, HashTable< std::string, int > &nameOccur) |
| Sanitize a set of variable names for LaTeX and ensure uniqueness. | |
Protected Attributes | |
| std::string | _type |
Static Protected Attributes | |
| static constexpr const char * | CONTINUE_PREFIX = "| " |
| Prefix used to draw tree branches in toString. | |
Private Attributes | |
| std::string | _var |
| variable to eliminate | |
| std::unique_ptr< ASTtree< GUM_SCALAR > > | _term |
| sub-expression | |
Summation (marginalization) over one or more variables.
Represents ( \sum_{v} \text{term} ) or a nested version for several variables. Operationally, eval marginalizes the variable(s) from the evaluated subterm tensor.
| gum::ASTsum< GUM_SCALAR >::ASTsum | ( | std::string_view | var, |
| std::unique_ptr< ASTtree< GUM_SCALAR > > | term ) |
Single-variable summation ( \sum_{\text{var}} \text{term} ).
Definition at line 530 of file doAST_tpl.h.
References gum::ASTtree< GUM_SCALAR >::ASTtree(), _term, _var, term(), and var().
Referenced by fastToLatex().
| gum::ASTsum< GUM_SCALAR >::ASTsum | ( | const std::vector< std::string > & | vars, |
| std::unique_ptr< ASTtree< GUM_SCALAR > > | term ) |
Multi-variable overload: recursively builds nested sums in the order of vars[0], vars[1], ....
Definition at line 535 of file doAST_tpl.h.
References gum::ASTtree< GUM_SCALAR >::ASTtree(), _var, and term().
|
staticprotectedinherited |
Sanitize a set of variable names for LaTeX and ensure uniqueness.
Definition at line 89 of file doAST_tpl.h.
References _latexCorrect().
|
staticprotectedinherited |
Sanitize a single variable name for LaTeX and ensure uniqueness.
Definition at line 79 of file doAST_tpl.h.
References gum::HashTable< Key, Val >::getWithDefault().
Referenced by _latexCorrect(), gum::ASTjointProba< GUM_SCALAR >::fastToLatex(), gum::ASTposteriorProba< GUM_SCALAR >::fastToLatex(), gum::ASTsum< GUM_SCALAR >::fastToLatex(), gum::ASTjointProba< GUM_SCALAR >::toString(), and gum::ASTposteriorProba< GUM_SCALAR >::toString().
|
overridevirtual |
Deep clone of the sub-tree.
Implements gum::ASTtree< GUM_SCALAR >.
Definition at line 613 of file doAST_tpl.h.
|
overridevirtual |
Evaluate the expression against a contextual BN.
| contextual_bn | Bayesian network providing CPTs and variable domains |
Implements gum::ASTtree< GUM_SCALAR >.
Definition at line 619 of file doAST_tpl.h.
References _term, _var, gum::DiscreteGraphicalModel::idFromName(), gum::Set< Key >::insert(), and gum::DiscreteGraphicalModel::variable().
|
overridevirtual |
Fast LaTeX rendering (lighter protection).
Assumes prior hygiene of names; typically avoids heavier bookkeeping performed in protectToLatex.
| nameOccur | symbol occurrence table (may be consulted/updated) |
Implements gum::ASTtree< GUM_SCALAR >.
Definition at line 575 of file doAST_tpl.h.
References ASTsum(), gum::ASTtree< GUM_SCALAR >::_latexCorrect(), gum::HashTable< Key, Val >::exists(), gum::HashTable< Key, Val >::insert(), and gum::Set< Key >::insert().
Referenced by protectToLatex().
|
overridevirtual |
LaTeX rendering with full name protection.
Produces LaTeX with variable-name disambiguation, using nameOccur as a registry of encountered names and their occurrence counts.
| nameOccur | symbol occurrence table (updated in place) |
Implements gum::ASTtree< GUM_SCALAR >.
Definition at line 570 of file doAST_tpl.h.
References fastToLatex().
| const ASTtree< GUM_SCALAR > & gum::ASTsum< GUM_SCALAR >::term | ( | ) | const |
|
inherited |
Convenience wrapper using an empty occurrence table.
Definition at line 73 of file doAST_tpl.h.
References fastToLatex().
Referenced by fastToLatex().
|
overridevirtual |
Human-readable multi-line rendering (for debugging / logs).
| prefix | indentation prefix propagated to children |
Implements gum::ASTtree< GUM_SCALAR >.
Definition at line 561 of file doAST_tpl.h.
References _term, _var, and gum::ASTtree< GUM_SCALAR >::CONTINUE_PREFIX.
|
noexceptinherited |
Definition at line 68 of file doAST_tpl.h.
References _type.
Referenced by gum::ASTBinaryOp< GUM_SCALAR >::ASTBinaryOp(), ASTtree(), and operator=().
|
nodiscard |
Definition at line 551 of file doAST_tpl.h.
References _var.
Referenced by ASTsum().
|
private |
|
protectedinherited |
Definition at line 154 of file doAST.h.
Referenced by ASTtree(), gum::ASTBinaryOp< GUM_SCALAR >::toString(), and type().
|
private |
|
staticconstexprprotectedinherited |
Prefix used to draw tree branches in toString.
Definition at line 153 of file doAST.h.
Referenced by gum::ASTBinaryOp< GUM_SCALAR >::toString(), and gum::ASTsum< GUM_SCALAR >::toString().