Hello,
Thank you very much for creating this library. Its been really useful in my research so far and I really appreciate the level of documentation provided. I am interested in using libDAI to perform inference on a large discrete DAG. I need to learn the conditional probabilities of this graph which I want to learn using EM. In order to test out the API on a simpler example, I have implemented a toy example based on the problem detailed here:
The implementation works, however, I am running into some scaling issues when moving to a more complex problem using a larger graph. I am wondering if I can reduce the number of calculations in the sum product algorithm by supplying the evidence as a binomial random variable rather than a set of categorical variables. The code below is how I currently define a single run of belief propagation in the case where the factor values are known and do not need to be learned.
std::vector<Var> Xs;
for (int i=0; i<11; i++){
Xs.push_back(Var(i,2));
}
std::vector<Factor> CoinFactors = {Factor(Xs[0])};
CoinFactors[0].set(0, 0.5);
CoinFactors[0].set(1, 0.5);
for (int i=1; i < Xs.size(); i++) {
Factor factor( VarSet(Xs[0], Xs[i]) );
factor.set(0, 0.6);
factor.set(1, 0.5);
factor.set(2, 0.4);
factor.set(3, 0.5);
CoinFactors.push_back( factor );
}
FactorGraph fg( CoinFactors );
fg.clamp(1, 0);
fg.clamp(2, 1);
fg.clamp(3, 1);
fg.clamp(4, 1);
fg.clamp(5, 0);
fg.clamp(6, 0);
fg.clamp(7, 1);
fg.clamp(8, 0);
fg.clamp(9, 1);
fg.clamp(10,0);
PropertySet opts;
opts.set("inference", string("SUMPROD"));
opts.set("updates",string("PARALL"));
opts.set("logdomain", true);
opts.set("tol", 1e-9);
opts.set("maxiter", string("1"));
opts.set("verbose", string("2"));
BP bp = BP( fg, opts );
bp.init();
bp.run();
This code corresponds to learning the posterior probability of the first coin chosen being A or B given that from a single set of coin flips 5 heads and 5 tails are observed (the first outcome in the linked example). I achieve this by defining each of the 10 flips to be a categorical random variable and clamp them to a specific state (H=0, T=1). I wonder if there is any possibility of me defining a single binomial variable where I set state 0 to 5, set state 1 to 5 and then run BP. My larger problem involves evidence as multinomial random variables but understanding how I can implement the binomial case will provide the guidance that I need.
Any ideas on how I can achieve this with libDAI?
Thanks!