From Bugs to Infer.net (Migrated from community.research.microsoft.com)
-
Friday, June 03, 2011 6:48 PMOwner
tpena posted on 05-19-2011 9:01 AM
Hello
I am learning how to use Infer.Net, so a bit of help translating the following BUGS lines of code into .Net doce would help. Suppose I want to model a Poisson process in which the rate of arrivals is drawn from a Uniform distribution. In BUGS you would do something like this:
lambda ~ dunif(a, b) # Where a,b
process ~ poisson(lambda, k)
In Infer.Net I am trying to model the same hierarchy, by first creating a uniform distribution:
Range lambdaRange = new Range(b-a);
Variable lambda = Variable.DiscreteUniform(lambdaRange);
And then distributing lambda as a Poisson:
Variable
process = Variable.Poisson(lambda);
However lambda is typed as an <int> variable whereas the Poisson requires a <double> variable. What can be done in this type of situation?
Regards,
Tpena
All Replies
-
Friday, June 03, 2011 6:48 PMOwner
John Guiver replied on 05-20-2011 12:33 PM
'Range' is an index type for graphical model plates, not a way to restrict the domain of a uniform distribution.
To use Poisson with a random variable rate, use a Gamma-distributed random variable. Here would be a typical usage.
John
static void Main(string[] args)
{
// The model
var lambda = Variable.GammaFromShapeAndRate(2.0, 2.0);
var numData = Variable.New<int>();
Range N = new Range(numData);
var x = Variable.Array<int>(N);
x[N] = Variable.Poisson(lambda).ForEach(N);
// Hook up the data
int[] data = { 3, 5, 4, 8 };
numData.ObservedValue = data.Length;
x.ObservedValue = data;
// The inference
var engine = new InferenceEngine();
var lambdaPosterior = engine.Infer<Gamma>(lambda);
Console.WriteLine(lambdaPosterior);
Console.ReadLine();
}
- Marked As Answer by Microsoft ResearchOwner Friday, June 03, 2011 6:48 PM