locked
EP on a custom factor returning a Gamma RRS feed

  • Question

  • I'm playing around with adding custom factors, for now just implementing some very simple factors to get the syntax down (as explained in the user guide).

    My model is simply:

    shape = Variable.New<double>().Named("shape");
    rate = Variable.New<double>().Named("rate");
    x = Variable<double>.Factor(MyFactor.MyGamma,shape,rate).Named("x");

    Given values for shape and rate, inferring x generates the following error:

    Error 0: This model is not supported with ExpectationPropagation due to MyFactor.MyGamma(double sample, double shape, double rate). Try using a different algorithm or expressing the model differently in MyFactor.MyGamma(shape, rate) 

    Details: System.ArgumentException: Gaussian is not assignable from Gamma for result of method MyFactor.MyGammaOp.sampleAverageConditional

    So while my operator method returns a Gamma, EP is somehow expecting a Gaussian? When I change the operator method to (wrongly) return a Gaussian, it runs without error.


    Wednesday, June 5, 2013 1:58 PM

Answers

  • Try adding a MarginalPrototype attribute to your variable:

    x.AddAttribute(new MarginalPrototype(new Gamma()));

    • Marked as answer by AlexHW Monday, June 10, 2013 5:11 PM
    Monday, June 10, 2013 8:32 AM
    Owner

All replies

  • Try adding a MarginalPrototype attribute to your variable:

    x.AddAttribute(new MarginalPrototype(new Gamma()));

    • Marked as answer by AlexHW Monday, June 10, 2013 5:11 PM
    Monday, June 10, 2013 8:32 AM
    Owner
  • Yes thanks, that fixes it.
    Monday, June 10, 2013 5:12 PM
  • Hi

    I had the same question.

    Now for inverse-Gamma I also can use Gamma? I didn't get the point here...

    I need a double-exponential distribution. I shouldn't use GaussianFromMeanAndVariance(0, Variable.GammaFromShapeAndRate(1,1)) ?

    Many thanks

    Zahra

    Wednesday, June 4, 2014 3:39 PM
  • I don't understand your question. If you can achieve what you need with already existing factors, you don't need to add a new factor. What's the problem with modelling a Laplacian as a Gaussian with a Gamma distributed variance?
    Thursday, June 5, 2014 11:06 AM