locked
multinomial distribution? (Migrated from community.research.microsoft.com) RRS feed

  • Question

  • Junming Huang posted on 03-03-2009 4:13 AM

    Hi, I'm a beginner of Infer.NET. I've got a problem when trying to model a multinomial distribution with Infer.NET: I cannot find multinomial distribution neither in Infer.Distributions nor in any documents. Is multinomial distribution not a built-in one? If not, it seems I have to manully realize it in code.

    Thanks very much.

    Friday, June 3, 2011 5:11 PM

Answers

  • minka replied on 08-07-2009 10:42 AM

    Multinomial and Binomial observations are now supported in Infer.NET 2.3.

    Friday, June 3, 2011 5:12 PM

All replies

  • John Guiver replied on 03-03-2009 4:34 AM

    Hi Junming

    Infer.NET does not currently include a binomial or multinomial distribution. However, it does include Bernoulli and discrete (categorical) distributions which give the outcome probabilities of individual trials. So it depends on what problem you are trying to solve. If you want to infer the probabilty of each outcome, given a bunch of observations, then you can do this easily using the current factors and distributions. Perhaps you could outline your problem so I can give you more focused advice.

    John

    Friday, June 3, 2011 5:11 PM
  • Junming Huang replied on 03-03-2009 4:55 AM

    Thanks John,

    Yes my task is to infer probabilities of each outcome in [0, K-1], given a series of observations. Thus I guess the Discrete distribution does meet my need.

    Best wishes.

    Junming

    Friday, June 3, 2011 5:11 PM
  • John Guiver replied on 03-03-2009 5:28 AM

    OK, if that is what you need, then the following C# code will do the job.

    // Sample data from the true discrete
    Vector trueProbs = new Vector(0.1, 0.2, 0.3, 0.4);
    Discrete trueDistrib = new Discrete(trueProbs);
    int[] data = new int[1000];
    for (int i = 0; i < data.Length; i++)
    data[ i ] = Rand.Sample(trueProbs);
    int K = trueProbs.Count;

    // The model
    Variable<Vector> probs = Variable.Dirichlet(new Vector(K, 1.0));
    Range dataRange = new Range(data.Length);
    VariableArray<int> x = Variable.Array<int>(dataRange);
    x[dataRange] = Variable.Discrete(probs).ForEach(dataRange);
    x.ObservedValue = data;

    // Create an inference engine for VMP
    InferenceEngine engine = new InferenceEngine();
    // Retrieve the posterior distribution over probabilities
    Dirichlet posterior = engine.Infer<Dirichlet>(probs);
    Console.WriteLine("probs =" + posterior.GetMean());

    Friday, June 3, 2011 5:11 PM
  • Junming Huang replied on 03-03-2009 9:47 PM

    Oh cool, that code really helps a lot. Thanks John.

    Junming

    Friday, June 3, 2011 5:11 PM
  • minka replied on 08-07-2009 10:42 AM

    Multinomial and Binomial observations are now supported in Infer.NET 2.3.

    Friday, June 3, 2011 5:12 PM