Skip to content
Snippets Groups Projects
Commit aade3839 authored by Tobias Winkler's avatar Tobias Winkler
Browse files

implemented Dist.marginal with list of variables

parent 139c5c68
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,7 @@ PYBIND11_MODULE(pygin, m) {
.def("mass", [](const Dist& dist) { return toString(dist.mass()); })
.def("normalize", &Dist::normalize)
.def("marginal", [](const Dist& dist, const string& x) {return dist.marginal(x);})
.def("marginal", [](const Dist& dist, const std::vector<string>& vars) {return dist.marginal(vars);})
.def("is_zero", &Dist::isZero)
.def("is_trivial", &Dist::isTrivial)
.def("update", &Dist::update)
......
......@@ -158,12 +158,14 @@ namespace prodigy {
return Dist{res};
}
Dist Dist::marginal(std::initializer_list<std::string> vars) const {
Dist Dist::marginal(const std::vector<std::string>& vars) const {
for (const auto &v : vars) {
EXPECTS(!isKnownAsParam(v), "given symbol is considered a parameter");
}
ex res{_gf};
// go over all variables v we currently know
for (const auto &v : _vars) {
// if v is not in the given list vars then project it away
if (std::find(vars.begin(), vars.end(), v.first) == vars.end()) {
res = res.subs(v.second == 1);
}
......
......@@ -144,7 +144,8 @@ namespace prodigy {
* returns marginal distribution in given variable(s)
*/
Dist marginal(const std::string& x) const;
Dist marginal(std::initializer_list<std::string> vars) const;
Dist marginal(const std::vector<std::string>& vars) const;
Dist marginal(std::initializer_list<std::string> vars) const { return this->marginal(std::vector<std::string>{vars}); }
/*
* attempts to prove that *this is the zero distribution (mass 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment