locked
Strange algorithm behavior (Migrated from community.research.microsoft.com) RRS feed

  • Question

  • Lato posted on 04-28-2011 7:19 AM

    Hi,

    I found a strange behavior in my code.
    using Gibbs sampling algorithm to infer on my model I get an error, like the size of the CPT is wrong,but using EP or VMP 
    this does not happen. So I suppose my definition of the model is correct.

    I enclose link to my code. To see this behavior is sufficient to change the algorithm used in the Model class at line 231

    http://dl.dropbox.com/u/20337898/Infer.zip

    Thanks and regards

    Alessandro

     

    Friday, June 3, 2011 6:47 PM

Answers

All replies

  • minka replied on 05-02-2011 11:44 AM

    The error message here ("Uses.Length != 1") is a limitation of the current Gibbs sampler.  You cannot use a variable twice in the same condition context.  Your model does this in these two lines:

    h1 = AddChildFromOneParent(s1, cpt_h1);
    o1 = AddChildFromTwoParents(s1, h1, cpt_o1);

     

    Here h1 is being used twice, conditional on s1 each time.  This limitation will be removed in the next version of Infer.NET.  Meanwhile, you can work around this limitation in different ways.  In your case, the simplest way is to change cpt_o1 so that h1 is first and s1 is second:

    //o1 = AddChildFromTwoParents(s1, h1, cpt_o1);
    o1 = AddChildFromTwoParents(h1, s1, cpt_o1);

    Note this requires changing the definition of cpt_o1.  With this change, the model runs.  Another work around is to make a copy of h1 (outside of s1) and use the copy when defining o1:

     

     

     

     

    VariableArray<int> h1_copy = Variable.Array<int>(n);
    h1_copy[n] =
    Variable.Copy(h1[n]);
    o1 = AddChildFromTwoParents(s1, h1_copy, cpt_o1);

    Friday, June 3, 2011 6:48 PM
  • Lato replied on 05-04-2011 3:08 AM

    Thanks a lot!

    Friday, June 3, 2011 6:48 PM