56 template < GUM_Numeric GUM_SCALAR >
60 for (
const auto& n: names) {
66 template < GUM_Numeric GUM_SCALAR >
69 const DAG dag =
_cm.causalDAG();
70 auto checkObserved = [&](
const NodeSet& S) {
71 for (
const auto&
id: S) {
74 "CausalFormula: variable id " + std::to_string(
id)
75 +
" is not an observed variable of the model.");
84 template < GUM_Numeric GUM_SCALAR >
87 for (
const auto&
id:
_on) {
93 for (
const auto&
id:
_doing) {
101 template < GUM_Numeric GUM_SCALAR >
103 std::unique_ptr< ASTtree< GUM_SCALAR > >
root,
115 template < GUM_Numeric GUM_SCALAR >
117 std::unique_ptr< ASTtree< GUM_SCALAR > >
root,
128 template < GUM_Numeric GUM_SCALAR >
136 template < GUM_Numeric GUM_SCALAR >
138 return static_cast< bool >(
_root);
141 template < GUM_Numeric GUM_SCALAR >
147 template < GUM_Numeric GUM_SCALAR >
151 "CausalFormula::eval() called on a non-identified formula.");
153 return _root->eval(
_cm.observationalBN());
156 template < GUM_Numeric GUM_SCALAR >
158 if (!
_root)
return "[unidentifiable]";
159 return _root->toString();
162 template < GUM_Numeric GUM_SCALAR >
164 std::string_view doOperatorSuffix)
const {
165 if (!
_root)
return "[unidentifiable]";
170 auto addNames = [&](
const NodeSet& S) {
171 for (
const auto&
id: S) {
172 const auto name =
_cm.nameFromId(
id);
180 return latexQuery(doOperatorPrefix, doOperatorSuffix) +
" = " +
_root->toLatex(nameOccur);
183 template < GUM_Numeric GUM_SCALAR >
185 std::string_view doOperatorSuffix)
const {
186 auto namesSorted = [&](
const NodeSet& S) {
187 std::vector< std::string > res;
188 res.reserve(S.size());
189 for (
const auto&
id: S)
190 res.emplace_back(
_cm.nameFromId(
id));
191 std::sort(res.begin(), res.end());
199 std::stringstream ss;
202 for (
size_t i = 0; i <
onNames.size(); ++i) {
204 if (i + 1 <
onNames.size()) ss <<
",";
212 for (
size_t i = 1; i <
doingNames.size(); ++i)
214 ss << doOperatorSuffix;
229 template < GUM_Numeric GUM_SCALAR >
231 return std::make_unique< CausalFormula< GUM_SCALAR > >(
_cm,
240 template < GUM_Numeric GUM_SCALAR >
242 std::vector< std::string > out;
243 out.reserve(
_on.size());
244 for (
const auto&
id:
_on)
245 out.emplace_back(
_cm.nameFromId(
id));
246 std::sort(out.begin(), out.end());
250 template < GUM_Numeric GUM_SCALAR >
252 std::vector< std::string > out;
253 out.reserve(
_doing.size());
254 for (
const auto&
id:
_doing)
255 out.emplace_back(
_cm.nameFromId(
id));
256 std::sort(out.begin(), out.end());
260 template < GUM_Numeric GUM_SCALAR >
262 std::vector< std::string > out;
265 out.emplace_back(
_cm.nameFromId(
id));
266 std::sort(out.begin(), out.end());
272 template < GUM_Numeric GUM_SCALAR >
277 template < GUM_Numeric GUM_SCALAR >
282 template < GUM_Numeric GUM_SCALAR >
287 template < GUM_Numeric GUM_SCALAR >
292 template < GUM_Numeric GUM_SCALAR >
A causal model pairing a causal DAG with an optional observational BayesNet.
NodeId idFromName(std::string_view name) const
Node id from variable name (observed or latent).
The class for generic Hash Tables.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
Exception : the element we looked for cannot be found.
Exception : operation not allowed.
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
void insert(const Key &k)
Inserts a new element into the set.
#define GUM_ERROR(type, msg)
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities