Answered by:
question about marginal distribution calculation (Migrated from community.research.microsoft.com)

amchiclet posted on 03042010 12:02 AM
I'm trying to run a simple example. Here's how I thought it would work.
I have 2 variables, each with 3 discrete values, namely {0, 1, 2}.
I'm trying to define the following truth table where F(x,y) returns 2 only when both x and y are 0; otherwise 1;
X Y F(X,Y)
0 0 2
0 1 1
0 2 1
1 0 1
1 1 1
1 2 1
2 0 1
2 1 1
2 2 1The marginalization of X should be <0.4,0.3,0.3> and Y's should be <0.4,0.3,0.3>
Here's the code I used.
Variable<int> x = Variable.DiscreteUniform(3);
Variable<int> y = Variable.DiscreteUniform(3);Variable<bool> x0 = (x == 0);
Variable<bool> y0 = (y == 0);Variable.ConstrainEqualRandom(x0 & y0, Bernoulli.FromLogOdds(Math.Log(2.0/8.0)));
InferenceEngine engine = new InferenceEngine();
Console.WriteLine("x = {0}", engine.Infer(x));
Console.WriteLine("y = {0}", engine.Infer(y));The output I got was x=<0.2727,0.3636,0.3636>, y=<0.2727,0.3636,0.3636>
Can you tell me what I did wrong? Thank you.
Question
Answers

amchiclet replied on 03042010 1:50 PM
Ahhhh, I see. Thank you John.
 Marked as answer by Microsoft ResearchOwner Friday, June 03, 2011 5:36 PM
All replies

jwinn replied on 03042010 1:12 AM
You are close. What you are trying to achieve is to upweight the case where X=0 and Y=0 by 2. So you just use an odds ratio of 2.0 in this case:
Variable .ConstrainEqualRandom(x0 & y0, Bernoulli.FromLogOdds(Math.Log(2.0)));
This gives your desired answer.
To understand why, consider sampling from your unconstrained uniform model and keeping only samples where the expression (X=0&Y=0) match a biased coin (the Bernoulli in ConstraintEqualRandom). If the coin is unbiased (i.e. an odds ratio of 1) then you throw away half of the tails and half of the heads so the overal marginals are unchanged and remain uniform. If the bias is 2/3 probability of heads (i.e. an odds ratio of 2) then you will keep twice as many heads as tails and you get your desired marginals. An odds ratio of 2/8 is equivalent to having a bias in favor of tails and is a model with F=0.25 for the X=0, Y=0 case, rather than 2.
Hope that makes sense,
Best,
John W. 
amchiclet replied on 03042010 1:50 PM
Ahhhh, I see. Thank you John.
 Marked as answer by Microsoft ResearchOwner Friday, June 03, 2011 5:36 PM