Answered by:
How to create a discrete variable with 3 outcome?
Question

Say, I have a gaussian variable
var x = Variable.GaussianFromMeanAndVariance(y,1);
I would like to create a variable that have outcome 1, 0, 1 when x < 1, 1 <=x<1, 1 <= x.
So that if I want to make some inference about y, it would not have to recompile each time if I observe 'x < 1', '1 <= x', '1 <=x<1'
 Edited by colinfang Friday, September 19, 2014 5:08 PM
Friday, September 19, 2014 4:34 PM
Answers

If outcome is always going to be observed, then the best approach is:
using(Variable.Case(outcome,1)) { Variable.ConstrainTrue(x < 1); } using(Variable.Case(outcome,0)) { Variable.ConstrainBetween(x,1,1); } using(Variable.Case(outcome,1)) { Variable.ConstrainTrue(1 <= x); }
 Edited by Tom MinkaMicrosoft employee, Owner Monday, September 22, 2014 6:44 PM
 Marked as answer by colinfang Monday, September 22, 2014 7:23 PM
Monday, September 22, 2014 6:36 PMOwner
All replies

If outcome is always going to be observed, then the best approach is:
using(Variable.Case(outcome,1)) { Variable.ConstrainTrue(x < 1); } using(Variable.Case(outcome,0)) { Variable.ConstrainBetween(x,1,1); } using(Variable.Case(outcome,1)) { Variable.ConstrainTrue(1 <= x); }
 Edited by Tom MinkaMicrosoft employee, Owner Monday, September 22, 2014 6:44 PM
 Marked as answer by colinfang Monday, September 22, 2014 7:23 PM
Monday, September 22, 2014 6:36 PMOwner 
This is what I tried. However, then I can no longer make inference about variable outcome if outcome is not observed.
Generally in Infer.Net, it seems that I always encounter the problem that I have to build 2 almost identical models, one is used for outcome observation / inference, the other for outcome prediction.
Monday, September 22, 2014 7:23 PM 
That is because Infer.NET does not support a discrete distribution over the values (1,0,1). If you change outcome to range over (0,1,2) then you can do it. Just add in the following:
var outcome = Variable.DiscreteUniform(3);
That is one way to do it. There are a few different ways to express this model, each with their own advantages depending on your goals.
Tuesday, September 23, 2014 11:34 AMOwner 
Thank you for the reply. I am really grateful that I can get help from the author of the software I am using and the paper I am studying.
If I do var outcome = Variable.DiscreteUniform(3), and try to infer outcome (without any observation), it seems I would then get a "posterior" distribution of outcome by taking uniform as a prior (however in this case the difference from true value is almost 0. I suspect it might always be equal to the true value, why is that?).
Evidence:
e.g. if I do var outcome = Variable.Discrete(new double[]{1.0/4, 1.0/4, 1.0/2}), the inference of outcome is different. Since there is no observed value at all, I would expect the distribution of outcome should be fixed, as some compound / mixture distribution.
Generally, I would like a model that takes a variable A and get a output variable B.
Ideally, when I want to do inference, I can: B.ObservedValue = b, A.ClearObservedValue(), so I can Infer(A).
And when I want to do forecasting, I can: B.ClearObservedValue(), A.OberservedValue = a, so I can Infer(B).
Surely building model for either of the above 2 tasks is not too hard. I am just curious if there exists one model that can fit them both.
Wednesday, September 24, 2014 2:57 PM 
The approach I described can do exactly what you are asking. If outcome is observed, then you can infer y. If y is observed, then you can infer outcome. If this is not sufficient, then tell me what are the variables "A" and "B" that you have in mind.Wednesday, September 24, 2014 3:11 PMOwner

The approach you described works.
I am just not understanding why it would have worked, and not sure if I can apply this technique to other similar situations without any assumption.
Wednesday, September 24, 2014 4:26 PM 
Ok, I figured out. The message passed from uniform discrete variable is trivial.Friday, September 26, 2014 3:58 PM