locked
Variable is not defined in all cases RRS feed

  • Question

  • Hi, 

    I know for conditional cases I have to use Variable.SetTo instead of simple '='. 

    Now I have a SetTo and Constrain on variable in the two branches of my conditional case, and I get Variable is not defined in all cases error. I don't know what am I missing here. Does somebody have any idea?

    Gaussian wDist = Gaussian.FromMeanAndVariance(0, 100);
    using (Variable.ForEach(nodeRange))
                {
                    using (Variable.ForEach(wRange))
                    {
                        using (Variable.If(selector[nodeRange][wRange]))
                        {
                            Variable.ConstrainEqualRandom(w[nodeRange][wRange], wDist);
                        }
                        using (Variable.IfNot(selector[nodeRange][wRange]))
                        {
                            w[nodeRange][wRange] .SetTo( Variable.GaussianFromMeanAndVariance(0, 0.0000001));
                        }
                    }
                }




    • Edited by Capli19 Monday, February 9, 2015 4:14 PM
    Monday, February 9, 2015 4:12 PM

All replies

  • Variable.ConstrainEqualRandom is not considered a definition.  Use Variable.Random instead.
    Monday, February 9, 2015 6:26 PM
    Owner
  • W is not really fixed. It is just a wide distribution. If I use Variable.Random, then its posterior converges to a distribution with narrow peak. 

    This is not the case for my model. I want to discover weather an edge (non-zero w) exists or not. But the value of w is not really important. 

    By this code I mean, w can be zero, or it can be from a wide distribution. How can I show this?


    • Edited by Capli19 Tuesday, February 10, 2015 12:52 PM
    Tuesday, February 10, 2015 12:52 PM
  • It sounds like you want w to come from a mixture distribution.  That is exactly what happens in the above code (with the stated change).
    Tuesday, February 10, 2015 1:33 PM
    Owner
  • Thank you Tom. I think my problem is from something else. I multiply this w array (for each node in its first dimension) by an array of my observed data, and it is set to another variable for which I observe the value also.

    Because of the problem for "*" operator, I use "engine.Compiler.GivePriorityTo(typeof(GaussianProductOp_SHG09))" and also "experimentRange.AddAttribute(new Sequential())" but still I have problem in the result.

    When my observed input data (for input variables which is multiplied by w) is generated from Gaussian(0,1), my code works, but when I change the distribution of my input data, it does not work any more.

    To summarize, I have a model (w * X = Y ) for which X and Y are observed and Y is noisy. w is defined using the above definition, and it selects a sparse set from input variables. Now when I use any distribution on my input (except this Gaussian(0,1)) I don't get the result and always there is this error:

    An unhandled exception of type 'MicrosoftResearch.Infer.Factors.ImproperMessageException' occurred in Infer.Runtime.dll
    Additional information: Improper distribution during inference (Gamma(22.5, Infinity)).  Cannot perform inference on this model.

    My question is, what can I understand from this error? How is it possible that the code works for the N(0,1) but not for other distributions? I'm really confused.

    Wednesday, February 11, 2015 12:51 PM
  • You should make a new post for this question, and include the code that doesn't work.
    Wednesday, February 11, 2015 4:54 PM
    Owner