Where to chat about modeling with Bayesian Networks and integrating with agrum/pyAgrum (https://www.agrum.org)
Hi MÃ©lanie, from the error you show The translation of ""[45,65]"" could not be found
, the problem seems to be the "
that are somehow included at the beginning and at the end of the labels ...
It is true that we do not accept missing data in our MIIC's implementation. The reason is that we are not very keen on that very solution which consists in just dropping the lines when NA is involved in the computation. It allows learning any base but it is easy to show how bad the result can be if the number of NA is important enough ...
When you say "taking into account latent variables" do you mean "detecting latent variables" ? If yes, this is a part of the MIIC algorithm and you can check learner.latentVariables()
to see if any has been detected during the learning phase.
I guess that by "filtering arcs", you mean "selecting allowed and forbidden arcs" ? If yes, we have the same problem as for missing values : even if, of course, we could do so, we are not able to find a correct interpretation of such an operation:
For score-based algorithms, it is obvious that you can do such filtering : the learning process exactly consists in selecting arcs so you can change the set of "selectable arcs". However, for constraint-based algorithms, the algo does not select arcs but infer conditional independence. If you find a conditional independence, you HAVE TO remove some arcs, if you do not find such CI, you HAVE TO keep the arcs. We do not find any good way to conciliate a user saying that the arc A->B is not possible whereas his/her own data say that this very arc has to be in the model (and vice versa).
We prefer to give to the user the responsibility to do such horrible things :-) So, after learning a BN with MIIC, you still can add/remove some arcs and then learn the parameters (even with missing value using a correct, proved and sound EM algorithm :-) )
latentVariables()
, see for instance http://webia.lip6.fr/~phw/aGrUM/docs/current/notebooks/54-CausalityAndLearning.ipynb.html (cell 13)
ie=gum.LazyPropagation(bn)
ie.makeInference()
toberemoved=[a for a in bn.arcs() if ie.I(*a)<1e-3] # threshold=1e-3
for a in toberemoved:
bn.eraseArc(*a)
#learn parameters
[...]
Hello Melanie, this is well described in the MIIC's papers.
In a nutshell, constraint-based algorithms try to find V-structures : X->Y<-Z
.
The trace of latent variables in such algorithms comes from the identification of 2 V-structures : A->B<-C
and B->C<-D
... So the arc (B,C) should be bi-oriented. MIIC and other constraint-based algorithms propose then to interpret B<->C
as the "proof" of a latent common parent : B<-?->C
.
So one can just detect from time to time the trace of a latent variable if this variable has at least 2 observable children (and then "confoundingly" correlated).
Hi, agrumery/aGrUM#52 is closed. Thanks @CasseNoisette_gitlab and Francisco Camacho
(you will be able to test it by pip install pyAgrum-nightly
tomorrow or by waiting for the next tag)
hi there. Is there any known reason why your C++ Inference example produces this compiler error?
error: no matching conversion for functional-style cast from 'gum::BayesNet<float>' to 'ShaferShenoyInference<float>' `
Hi Xavier, can you be a bit more precise about the code that does not work ?
another question: on Osx (both using clang and gcc), when linking, I got this error too:
ld: library not found for -lodbc
I actually solved this one only by changing "odbc" into "iodbc" in agrum-targets.cmake
thanks for that.
last question from today: is there any reference were we can learn how to use the classes for learning parmeters (CPTs mainly)?
You mean, I guess, in C++ ?
and the testsuite (see above)
Hi Xavier, can you be a bit more precise about the code that does not work ?
Sure here it is:
auto ln_net = BayesNet<float>("Net");
this is the definition of the network and then, if follow your examples and I write something like this:
auto inference = LazyPropagation<float>( ln_net);
I get the error (I tried with differen Algortims to be sure...)
another question: on Osx (both using clang and gcc), when linking, I got this error too:
ld: library not found for -lodbc
I actually solved this one only by changing "odbc" into "iodbc" in agrum-targets.cmake
thanks for that.
Is there any chance you can put that into the next release? I tried to figure out in your repository who is responsible for that one but I did not find the right place, and making the change in the final .cmake is not very effective. I'm also trying to maintain (feel free to use it) a repo for homebrew formula (for this reason I was looking at least for a patch to apply to the code once downloaded): https://github.com/xavier7179/homebrew-research_libs.git
Ok, for the error, it is just that we forced the constructor to be explicit (and to use a pointer of a BN). So the code :
auto ln_net = gum::BayesNet< float >("Net");
gum::LazyPropagation< float > inference(&ln_net);
should work fine. If you could tell me where you find the erroneous code, I wil change it.
@phwuill_gitlab
should work fine. If you could tell me where you find the erroneous code, I wil change it.
Here it is the full error chain hoping it helps (for me was on all inference algorithm I selected):
main.cpp:122:19: error: no matching conversion for functional-style cast from 'gum::BayesNet<float>' to 'LazyPropagation<float>'
auto inference = LazyPropagation<float>( ln_net_o);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/Cellar/agrum/0.18.1/include/agrum/BN/inference/lazyPropagation.h:81:14: note: candidate constructor not viable: no known conversion from 'gum::BayesNet<float>' to 'const IBayesNet<float> *' for 1st argument; take the address of the argument with &
explicit LazyPropagation(
^
/usr/local/Cellar/agrum/0.18.1/include/agrum/BN/inference/lazyPropagation.h:89:5: note: candidate constructor not viable: no known conversion from 'gum::BayesNet<float>' to 'const LazyPropagation<float>' for 1st argument
LazyPropagation(const LazyPropagation< GUM_SCALAR >&) = delete;
^
Have you tried to change the code as I wrote it ?
I tried but the deleted constructor is still giving an error on your first line:/src/main.cpp:122:7: error: call to deleted constructor of 'gum::LazyPropagation<float>' gum::LazyPropagation< float > inference = LazyPropagation<float>(&ln_net); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/local/Cellar/agrum/HEAD-65e7441/include/agrum/BN/inference/lazyPropagation.h:89:5: note: 'LazyPropagation' has been explicitly marked deleted here LazyPropagation(const LazyPropagation< GUM_SCALAR >&) = delete;
My second line is (solid basic old-fashioned constructor :-) ) :gum::LazyPropagation< float > inference(&ln_net);
and not (new modern C++ i)
gum::LazyPropagation< float > inference = LazyPropagation<float>(&ln_net);
(that you should write auto inference = gum::LazyPropagation<float>(&ln_net);
Indeed, in order to avoid erroneous conversion, we made the default constructor 'explicit' (and deleted the copy constructor). So you have to build an inference engine that old-fashioned way...
As you can see in the CPTs, the labels of the variables are "yes" and "no" ... In the csv, the labels are "0" and "1" ...
When you pass a bn as a parameter to a BNLearner, it is exactly to give it the labels (and their orders) that will be found in the csv ... Thge error "unknown label found" is then understandable :-) A "1" or a "0" is found for a variable which can be "yes" or "no" ...