Microsoft Research Community

dirichlet with non uniform prior

rated by 0 users
This post has 1 Reply | 2 Followers

Top 50 Contributor
Posts 14
freddycct Posted: 08-20-2009 4:39 AM

 

Hi, I try to create an array of dirichlet distribution with non uniform priors but it wouldn't compile at all with these errors. Please help me. Thanks all.

 

 

Error 1 The best overloaded method match for 'MicrosoftResearch.Infer.Models.Variable.Dirichlet(double[])' has some invalid arguments C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\CPT\CPT\Program.cs 38 44 CPT

Error 2 Argument '1': cannot convert from 'MicrosoftResearch.Infer.Models.Variable<double[]>' to 'double[]' C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\CPT\CPT\Program.cs 38 64 CPT

 

 

static void Main(string[] args)

        {

            Range two = new Range(2).Named("two");

            Range five = new Range(5).Named("five");

            VariableArray2D<Vector> behaviour = Variable.Array<Vector>(two, five);

            double[,][] alpha = new double[,][] { { 

                                                    new double[]{ 1, 0, 0, 0, 0 }, 

                                                    new double[]{ 2, 1, 0, 0, 0 }, 

                                                    new double[]{ 3, 2, 1, 0, 0 }, 

                                                    new double[]{ 4, 3, 2, 1, 0 },

                                                    new double[]{ 5, 4, 3, 2, 1 } 

                                                 }, 

                                                 { 

                                                    new double[]{ 1, 2, 3, 4, 5 },

                                                    new double[]{ 0, 1, 2, 3, 4 },

                                                    new double[]{ 0, 0, 1, 2, 3 },

                                                    new double[]{ 0, 0, 0, 1, 2 },

                                                    new double[]{ 0, 0, 0, 0, 1 }

                                                 } };

            VariableArray2D<double[]> alph = Variable.Constant<double[]>(alpha, two, five).Named("alph");

            using (Variable.ForEach(two))

            {

                using (Variable.ForEach(five))

                {

                    behaviour[two, five] = Variable.Dirichlet( alph[two, five] );

                }

            }

            Console.WriteLine("Press any key to exit.");

            System.Console.ReadKey();

        }

 

Top 10 Contributor
Posts 56

Hi Freddy

There is no short cut method for Variable.Dirichlet which takes a variable argument. Recommended method is as below which uses the unary ‘Random’ factor. (In addition, it is better to make prior an Observed rather than a Constant, so it doesn’t get compiled into the code – let me know if you need help with that).

 

John

 

        static void Main(string[] args)

        {

            Range two = new Range(2).Named("two");

            Range five = new Range(5).Named("five");

            VariableArray2D<Vector> behaviour = Variable.Array<Vector>(two, five);

 

            Dirichlet[,] dir = new Dirichlet[,]

            {

                {

                    new Dirichlet(new double[]{ 1, 0, 0, 0, 0 }),

                    new Dirichlet(new double[]{ 2, 1, 0, 0, 0 }),

                    new Dirichlet(new double[]{ 3, 2, 1, 0, 0 }),

                    new Dirichlet(new double[]{ 4, 3, 2, 1, 0 }),

                    new Dirichlet(new double[]{ 5, 4, 3, 2, 1 })

                }, {

                    new Dirichlet(new double[]{ 1, 2, 3, 4, 5 }),

                    new Dirichlet(new double[]{ 0, 1, 2, 3, 4 }),

                    new Dirichlet(new double[]{ 0, 0, 1, 2, 3 }),

                    new Dirichlet(new double[]{ 0, 0, 0, 1, 2 }),

                    new Dirichlet(new double[]{ 0, 0, 0, 0, 1 })

                }

            };

            VariableArray2D<Dirichlet> prior = Variable.Constant(dir, two, five).Named("prior");

 

            using (Variable.ForEach(two))

            {

                using (Variable.ForEach(five))

                {

                    behaviour[two, five] = Variable.Random<Vector, Dirichlet>(prior[two,five]);

                }

            }

 

            Console.WriteLine("Press any key to exit.");

            System.Console.ReadKey();

        }

Page 1 of 1 (2 items) | RSS
©2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Feedback