Answered by:
Product of Two Bernoulli raise exception when one is absolute true and the other is absolute false
Question

Hi, Infer.net people,
I found that "Bernoulli(1) & Bernoulli(0)" will raise exception because the internal function (below) try to sum their logodd , in this case, one logodd is infinity and the other logodd is infinity. I think "Bernoulli(1) & Bernoulli(0)" should be "Bernoulli(0)" by the boolean logic. Is there a way to play around it? or did I miss sth here?
BTW, "LogOdds = a.LogOdds + b.LogOdds;" seems wrong, suppose p=p1*p2, then the oddRatio p/(1p) should be p1*p2/(1p1*p2) instead of (p1/(1p1))*(p2/(1p2))
public void SetToProduct(Bernoulli a, Bernoulli b)
{
if (a.IsPointMass && b.IsPointMass && a.Point != b.Point) throw new AllZeroException();
LogOdds = a.LogOdds + b.LogOdds;
}Thank you
 Edited by Zhizhuo Wednesday, October 22, 2014 3:37 PM
Wednesday, October 22, 2014 3:25 PM
Answers

So what you are saying is that you are not running inference in a model, but directly calling the SetToProduct function? This is quite different from the AND operation, because it is multiplying the distribution functions in a pointwise manner. Bernoulli(1) corresponds to the function p(T)=1, p(F)=0. Bernoulli(0) corresponds to the function p(T)=0, p(F)=1. The product of these two is p(T)=1*0=0, p(F)=0*1=0 which is all zero hence the exception.
 Marked as answer by Zhizhuo Friday, October 24, 2014 9:10 PM
Wednesday, October 22, 2014 6:39 PMOwner
All replies

Actually, it works fine:
var x = Variable.Bernoulli(1) & Variable.Bernoulli(0); var engine = new InferenceEngine(); Console.WriteLine(engine.Infer(x)); // result is Bernoulli(0)
Perhaps you can clarify what model you are running to get this exception.
Wednesday, October 22, 2014 4:18 PMOwner 
Hi, Tom,
Thanks for the quick reply. In fact, the exception is from "AllZeroException" , from " SetToProduct(Bernoulli a, Bernoulli b)". Basically, during the inference, the program try to evaluate Bernoulli(1)*Bernoulli(0) and cause this exception.
And it seems to me the product of Bernoulli distribution means sth else rather than the "AND" operation. Can you help me to understand this?
Thank you very much again.
Wednesday, October 22, 2014 5:42 PM 
So what you are saying is that you are not running inference in a model, but directly calling the SetToProduct function? This is quite different from the AND operation, because it is multiplying the distribution functions in a pointwise manner. Bernoulli(1) corresponds to the function p(T)=1, p(F)=0. Bernoulli(0) corresponds to the function p(T)=0, p(F)=1. The product of these two is p(T)=1*0=0, p(F)=0*1=0 which is all zero hence the exception.
 Marked as answer by Zhizhuo Friday, October 24, 2014 9:10 PM
Wednesday, October 22, 2014 6:39 PMOwner 
Thanks again. Yes, the exeption comes from the SetToProduct function, and I debug and found the input variables is Bernoulli(0) and Bernoulli(1). Although I didnt directly calling the SetToProduct function, but that function is being calling during the inference. Maybe some part of my model is ill poised according to your explaination.
Thank you very much again.
Friday, October 24, 2014 7:21 PM