# Newbie questions for creating a simple net.

• ### Question

• I've been reading the intro and tutorial info on the site, and it's all great, but I'm still struggling to build what, to me, would be a good "hello world" application by myself (rather than review sample code as in the intro). So I went to my old grad-school text (Intro. to Probability) and to one of the simplest examples (ex 3.19 p 179):

"A light bulb produced by the General Illumonation Company is known to have an exponentially distributed lifetime Y. However, the company has been experiencing quality control problems. On any given day, the paramater [lambda - the equivalent of the Gamma scale parameter, I believe] of the PDF of Y us actually a rendom variable, uniformly distributed in the interval [1, 3/2]. We test the a lightbulb and record its lifetime T. What can we say about the underlying paramater (lambda)?"

As noted, I did get the fact that the Gamma distribition can represent the exponential distribution but I'm less clear on how to create a simple continuous uniform PDF for Y. Also, even substituting different distributions for this, I simply don't 'get' how to create the model (uniform PDF for Y then having that as a prior on the exponential lifetime rabdom variable and then set the observed time T and infer back to the Y PDF posterior.

This should be simple - i.e. 10 lines of code - right?

Tuesday, January 24, 2012 5:57 PM

• There is no fundamental reason why a uniform PDF cannot be added to Infer.NET.  We just haven't needed one yet.  TruncatedGaussian should suffice for most cases, but not for the problem you mentioned.  We do need better documentation of which function arguments can be random and which cannot.  At the moment, the best place is the List of factors and constraints.  Looking at the VMP column, you see that GammaFromShapeAndRate has "Full Support" (i.e. all arguments can be random) while GammaFromShapeAndScale isn't there (meaning it doesn't allow any random arguments).  Gamma.Sample is listed and equivalent to GammaFromShapeAndScale but this also doesn't allow any random arguments.
• Marked as answer by Thursday, January 26, 2012 4:45 PM
Thursday, January 26, 2012 10:21 AM

### All replies

• Seems like I should at least show what code I do have and show where I think I'm stuck per the note above (TODO1 and TODO2 below):

// TODO1: Want a uniform PDF of [1.0, 1.5] rather than a Gaussian here
Variable<Gaussian> meanBulbLifePrior = Variable.New<Gaussian>();
meanBulbLifePrior.ObservedValue = new Gaussian(1.25, 0.1);
Variable<double> meanBulbLife = Variable.Random<double, Gaussian>(meanBulbLifePrior);

// TODO2: Eant an Exponential PDF here rather than a Gaussian. The commented out lines using Gamma crash.

InferenceEngine engine = new InferenceEngine(new VariationalMessagePassing());

// Get the marginal

// Retrieve the posterior distribution
Gaussian posteriorMeanBulbLife = engine.Infer<Gaussian>(meanBulbLife);
Console.WriteLine("posteriorMeanBulbLife=" + posteriorMeanBulbLife);

Dr Striate
• Edited by Tuesday, January 24, 2012 9:33 PM
Tuesday, January 24, 2012 9:15 PM
• This question cannot be answered in its original form with Infer.NET.  You can express a continuous uniform PDF using a TruncatedGaussian distribution with large variance but this is only compatible with factors that accept a TruncatedGaussian argument (and Gamma isn't one of them).  The primitive that (at first glance) seems to correspond best with the definition of lifetime is GammaFromShapeAndScale but this doesn't allow either of its arguments to be random.  A better choice is GammaFromShapeAndRate which allows the rate argument to be random (specifically, Gamma distributed).  This argument would correspond to 1/lambda.  If you give the rate a Gamma distribution then inference will work but this isn't quite the prior distribution given in the question.
Wednesday, January 25, 2012 5:29 PM
• Most helpful reply, Tom. Thank you. Can you enlighten me on a couple of questions it raises, though? 1) Is there some fundamental reason (e.g. around the inference engine itself, for instance) that obviates having as fundamental a distribution class as a uniform PDF in Infer.Net and 2) are the limitations on when can be a random variable be passed as an argument to the PDF functions and work properly clearly documented somewhere I shoudl be reading? Seems like perhaps a documentation and/or compile time issue (I only got an exception at run time at the Infer step and it just basically said "try something else"). I've got Infer.Net 101 and the Introduction To Infer.net docs. Should I be moving on to a more comprehensive doc for this kind of info and if so, what is it (hopefully not the online User Guide or API reference, neither of which seemed to get me there)?