locked
Simple Multinomial Model RRS feed

  • Question

  • I'm trying to compile this simple model:

                var trialOutcomes = new Range(2);
                var trialRange = new Range(5);
                var trial = Variable.New<int>();
                trial.Name = "trial";
                trial.ObservedValue=5;
                trial.SetValueRange(trialRange);
                var pi = Variable.Dirichlet(trialOutcomes,new double[] { 1.0, 1.0 });
                var md = Variable.Multinomial(trial, pi);
                md.SetValueRange(trialOutcomes);
                //md.ObservedValue = new int[] { 1, 2 };
                md.Name = "MultinomialDistribution";
                var ie = new InferenceEngine();
                var res = ie.Infer<Bernoulli>(md[0]>md[1]).GetProbTrue();

    The main idea is that given a multinomial distribution I'd like to be able to assess some probabilities given some constrains.
    The model is not compiling (seems because the infer engine is not able to determine range of "md" and marginal distribution of "md[0]" and "md[1]") unless i give some observed values for md (and then of course the resulting probability is not random anymore.....).
    This for me is just an exercise to try to learn more about Infer.Net that I find briliant!
    Thank You for any suggestions You may come up with.
    Alessandro


    Sunday, December 4, 2016 10:59 AM

Answers

  • The problem is that Infer.NET does not have a Multinomial distribution implemented as a message type, so you cannot perform operations on the output of Variable.Multinomial (other than observing it).  In your example, there are only two outcomes so you can use a Binomial distribution instead and that should work.
    Monday, December 5, 2016 6:34 AM
    Owner

All replies

  • The problem is that Infer.NET does not have a Multinomial distribution implemented as a message type, so you cannot perform operations on the output of Variable.Multinomial (other than observing it).  In your example, there are only two outcomes so you can use a Binomial distribution instead and that should work.
    Monday, December 5, 2016 6:34 AM
    Owner
  • Thank You for Your quick replay!
    I'm using two outcomes as an example but the real application I'm thinking of require more. Is there a way I can "mimic" the multinomial distribution in order afterward to express this kind of costrain?
    Thank You again for Your time.
    Best Regards
    Alessandro
    Monday, December 5, 2016 7:12 AM
  • I don't understand the question. 
    Monday, December 5, 2016 10:59 AM
    Owner
  • Hi Tom,
    what I meant was somethings along this line:

                ///---------------------------------
                ///Model definition
                ///---------------------------------
                var trialOutcomes = new Range(5);
                var trialRange = new Range(100);
                var trial = Variable.New<int>();
                trial.Name = "trial";
                trial.ObservedValue=100;
                trial.SetValueRange(trialRange);
                var pi = Variable.Dirichlet(trialOutcomes,new double[] { 1.0, 1.0 , 1.0, 1.0, 1.0 });
                var md= Variable.Multinomial(trial, pi);
                md.SetValueRange(trialOutcomes);
                md.Name = "MultinomialDistribution";
    
                ///---------------------------------
                ///Make some observations here....
                ///---------------------------------
    
                ///---------------------------------
                ///Infer some probabilities
                ///---------------------------------
                var ie = new InferenceEngine();
                var bernoulli1 = ie.Infer<Bernoulli>((md[0]>md[1]) & (md[2] > md[3])).GetProbTrue();
    
                ///---------------------------------
                ///Make some costrains and the infer Posterior Dirichlet
                ///---------------------------------
                Variable.ConstrainTrue(md[0] > md[1]);
                var dirichlet1 = ie.Infer<Dirichlet>(pi);
    But again here I'm just playing to trying to become more confident with the framework. So I'll accept Your first replay and I'll keep playing with other distributions.
    Thank You
    Alessandro



    Monday, December 5, 2016 5:54 PM