numpyro icon indicating copy to clipboard operation
numpyro copied to clipboard

Added Gompertz distribution class, sampling utilities

Open jackpot-nfer opened this issue 4 years ago • 8 comments

Added the ability to sample from the Gompertz distribution by implementing a Gompertz class under numpyro.dist.continuous

https://www.tandfonline.com/doi/abs/10.1080/03461238.2012.687697

jackpot-nfer avatar Aug 19 '21 19:08 jackpot-nfer

There are approximations for the expectation and variance in

Lenart A. The moments of the Gompertz distribution and maximum likelihood estimation of its parameters. Scand Actuar J. 2014;2014: 255–277. doi:10.1080/03461238.2012.687697

that may be useful.

cameronraysmith avatar Aug 19 '21 19:08 cameronraysmith

will add tests / docs shortly

jackpot-nfer avatar Aug 20 '21 21:08 jackpot-nfer

hi, I fixed the usage of log1p and expm1. I also undid my accidental edit to Laplace. I swapped the order of rate and concentration now to reflect the gamma distribution args, and set rate = 1.0 by default.

How can I get started with adding tests and docs?

jackpot-nfer avatar Aug 24 '21 21:08 jackpot-nfer

hi, I fixed the usage of log1p and expm1. I also undid my accidental edit to Laplace. I swapped the order of rate and concentration now to reflect the gamma distribution args, and set rate = 1.0 by default.

How can I get started with adding tests and docs?

I'm confused by the T(<Class>, <Vals> idiom and don't write to write a trivial test suite

jackpot-nfer avatar Aug 24 '21 21:08 jackpot-nfer

Hi @jackpot-nfer, for testing, you will need to add Gompertz to init (and also docs), and add a couple of entries to here:

    T(dist.Gompertz, jnp.array([1.7]), jnp.array([[2.0], [3.0]])),
    T(dist.Gompertz, jnp.array([0.5, 1.3]), jnp.array([[1.0], [3.0]])),

fehiepsi avatar Aug 25 '21 03:08 fehiepsi

@fehiepsi I believe all the necessary tests and docs edits have been made.

jackpot-nfer avatar Sep 02 '21 14:09 jackpot-nfer

@jackpot-nfer There are also a couple of lint issues. You can run make lint locally to see them. I guess you need two \\ like this example.

fehiepsi avatar Sep 03 '21 18:09 fehiepsi

Hey @fehiepsi, I've reparametrized the distribution as requested. It now takes concentration and rate=1.0 as args. I also added a scale argument and attribute. If it's provided (None by default), it sets rate = 1 / scale. If not, the scale parameter is set to 1 / rate as you'd expect. I figured this was a good compromise between sticking to the wikipedia derivation (which uses a scale parameter) and also matching the Gamma distribution (by having rate=1.0 as a default). rate attribute is used in all calculations, but scale attribute is accessible in any case.

I'm having trouble to get the tests to run right now -- tried running from a fresh venv and still didn't work. Not sure what is causing that. Could you try running them?

I manually blackened and isorted the change files, so all should be good to go on that front.

jackpot-nfer avatar Sep 23 '21 20:09 jackpot-nfer

@jackpot-nfer It has been a while but I guess we're only blocked by missing some tests. Can I add a commit for it in this PR?

fehiepsi avatar Nov 03 '22 14:11 fehiepsi

@fehiepsi I don't want to speak for @jackpotrykus , but I'm quite certain this would be fine.

cameronraysmith avatar Feb 17 '23 02:02 cameronraysmith

We just merged #1551. Thanks @jackpot-nfer and @cameronraysmith !!

fehiepsi avatar Mar 19 '23 12:03 fehiepsi