56 template < GUM_Numeric GUM_SCALAR >
60 const auto& bn =
cm.observationalBN();
61 for (
const auto& n: names) {
62 ids.
insert(bn.idFromName(n));
67 template < GUM_Numeric GUM_SCALAR >
69 const auto& bn =
_cm.observationalBN();
71 for (
const auto&
id:
_on)
72 (void)bn.variable(
id);
73 for (
const auto&
id:
_doing)
74 (void)bn.variable(
id);
76 (void)bn.variable(
id);
79 template < GUM_Numeric GUM_SCALAR >
82 for (
const auto&
id:
_on) {
88 for (
const auto&
id:
_doing) {
96 template < GUM_Numeric GUM_SCALAR >
98 std::unique_ptr< ASTtree< GUM_SCALAR > >
root,
110 template < GUM_Numeric GUM_SCALAR >
112 std::unique_ptr< ASTtree< GUM_SCALAR > >
root,
123 template < GUM_Numeric GUM_SCALAR >
131 template < GUM_Numeric GUM_SCALAR >
133 return static_cast< bool >(
_root);
136 template < GUM_Numeric GUM_SCALAR >
142 template < GUM_Numeric GUM_SCALAR >
146 "CausalFormula::eval() called on a non-identified formula.");
148 return _root->eval(
_cm.observationalBN());
151 template < GUM_Numeric GUM_SCALAR >
153 if (!
_root)
return "[unidentifiable]";
154 return _root->toString();
157 template < GUM_Numeric GUM_SCALAR >
159 std::string_view doOperatorSuffix)
const {
160 if (!
_root)
return "[unidentifiable]";
165 const auto& bn =
_cm.observationalBN();
166 auto addNames = [&](
const NodeSet& S) {
167 for (
const auto&
id: S) {
168 const auto& v = bn.variable(
id);
169 const auto& name = v.name();
177 return latexQuery(doOperatorPrefix, doOperatorSuffix) +
" = " +
_root->toLatex(nameOccur);
180 template < GUM_Numeric GUM_SCALAR >
182 std::string_view doOperatorSuffix)
const {
183 const auto& bn =
_cm.observationalBN();
185 auto namesSorted = [&](
const NodeSet& S) {
186 std::vector< std::string > res;
187 res.reserve(S.size());
188 for (
const auto&
id: S)
189 res.emplace_back(bn.variable(
id).name());
190 std::sort(res.begin(), res.end());
198 std::stringstream ss;
201 for (
size_t i = 0; i <
onNames.size(); ++i) {
203 if (i + 1 <
onNames.size()) ss <<
",";
211 for (
size_t i = 1; i <
doingNames.size(); ++i)
213 ss << doOperatorSuffix;
228 template < GUM_Numeric GUM_SCALAR >
230 return std::make_unique< CausalFormula< GUM_SCALAR > >(
_cm,
239 template < GUM_Numeric GUM_SCALAR >
241 const auto& bn =
_cm.observationalBN();
242 std::vector< std::string > out;
243 out.reserve(
_on.size());
244 for (
const auto&
id:
_on)
245 out.emplace_back(bn.variable(
id).name());
246 std::sort(out.begin(), out.end());
250 template < GUM_Numeric GUM_SCALAR >
252 const auto& bn =
_cm.observationalBN();
253 std::vector< std::string > out;
254 out.reserve(
_doing.size());
255 for (
const auto&
id:
_doing)
256 out.emplace_back(bn.variable(
id).name());
257 std::sort(out.begin(), out.end());
261 template < GUM_Numeric GUM_SCALAR >
263 const auto& bn =
_cm.observationalBN();
264 std::vector< std::string > out;
267 out.emplace_back(bn.variable(
id).name());
268 std::sort(out.begin(), out.end());
274 template < GUM_Numeric GUM_SCALAR >
279 template < GUM_Numeric GUM_SCALAR >
284 template < GUM_Numeric GUM_SCALAR >
289 template < GUM_Numeric GUM_SCALAR >
294 template < GUM_Numeric GUM_SCALAR >
A causal model pairing an observational BayesNet with a causal DAG.
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.
Exception : operation not allowed.
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