locked
How to use posterior for testing in the LDA model (Migrated from community.research.microsoft.com) RRS feed

  • Question

  • shakey posted on 11-21-2009 7:42 AM

    I want to test the lda model on new documents, I take the method on the baysian point machine example:

    setting the phi in the test model   to the posterior phi from the training model.  However, I always get errors indicating violation of type constrain. Can anyone give me some help on this ?  It seems SharedVariable is another kind of solution, but I cannot get it right either.

    part of the code:

    post_phi=engine.Infer[DistributionRefArray[Dirichlet,Vector]](phi)
    test_post_phi=Variable[Vector].Random[DistributionRefArray[Dirichlet,Vector]](post_phi )


    with (Variable.ForEach(test_CorpusSize)) as forBlock :


        with (Variable.ForEach(test_DocSize)) as forBlock :


            test_Z[test_CorpusSize][test_DocSize] = Variable.Discrete(test_theta[test_CorpusSize]).Attrib( ValueRange(TopicsNum))


            with (Variable.Switch(test_Z[test_CorpusSize][test_DocSize])) as swBlock :


                test_W[test_CorpusSize][test_DocSize] = Variable.Discrete(test_post_phi[ test_Z[test_CorpusSize][ test_DocSize] ])

     

    Friday, June 3, 2011 5:26 PM

Answers

  • shakey replied on 11-21-2009 11:52 PM

    Thanks for the reply.

    I tried as you said using the SetTo method ,but the VariableArray[Vector].SetTo  in IronPython does't seems to accept params other than the VariableArray[Vector]

    type,I tried many times but failed. However, I find another way around:

    post_phi=engine.Infer(phi)
    test_post_phi = Variable.Array[Vector](TopicsNum).Named("test_post_phi")
    test_post_phi.ObservedValue =System.Array[Vector]([post_phi[k].GetMean() for k in range(K)])

    and break symmetry by initialising  theta marginals of the test data,i get my result.

    Friday, June 3, 2011 5:27 PM

All replies

  • minka replied on 11-21-2009 10:53 AM

    The problem is that the first part of the code defines test_post_phi as an ordinary variable (not an array).  The last part of the code tries to use test_post_phi as an array.  You need to define test_post_phi using Variable.Array, then use SetTo to set its distribution.  The SetTo method is described on this page: http://research.microsoft.com/en-us/um/cambridge/projects/infernet/docs/Working%20with%20arrays%20and%20ranges.aspx

    Friday, June 3, 2011 5:27 PM
  • shakey replied on 11-21-2009 11:52 PM

    Thanks for the reply.

    I tried as you said using the SetTo method ,but the VariableArray[Vector].SetTo  in IronPython does't seems to accept params other than the VariableArray[Vector]

    type,I tried many times but failed. However, I find another way around:

    post_phi=engine.Infer(phi)
    test_post_phi = Variable.Array[Vector](TopicsNum).Named("test_post_phi")
    test_post_phi.ObservedValue =System.Array[Vector]([post_phi[k].GetMean() for k in range(K)])

    and break symmetry by initialising  theta marginals of the test data,i get my result.

    Friday, June 3, 2011 5:27 PM