Hi Charlie!



 charlieparker:

Is there any alternative you could give instead then?
I really need to use a Poisson distribution for my model.


The best I can think of is:
Find a continuous approximation to the Poisson distribution that
adequately meets you needs.  (Search for “cumulative Poisson
distribution.”)  This won’t be exactly the Poisson distribution, so
you won’t get exactly the same results as you would have with the
Poisson distribution.
Implement the inverse cumulative probability distribution for the
approximation you chose.  Let’s call this function f (u, a), where
u is understood to be a random value sampled uniformly between
zero and one, and a is your Poisson-distribution parameter
(sometimes called the Poisson “rate”).  Holding a fixed, for a uniform
deviate u, f (u, a) is a random deviate sampled from your
(approximate) Poisson distribution.
Package f() as a pytorch “custom autograd function” class.  It will
have a forward() function that calculates f (u, a).  u will be a
tensor with requires_grad = False that consists of one or more
uniform deviates , while a will be a tensor that wraps the rate
parameter and has requires_grad = True.
Now the important part:  Your custom autograd function will also have
a backward() function that calculates the derivative of f (u, a) with
respect to a.  (You have to work out the math for this and implement
it.)
You can now feed random approximate-Poisson deviates into the
calculations that lead to your loss function, and then use pytorch’s
autograd system to backpropagate and optimize your loss with respect
to your rate parameter a (as well as any other parameters you like).
Of course, any single random deviate is “noisy,” so your loss could
also be noisy, jump around, and not optimize well.  But if any given
optimization step involves averaging over many deviates, that noise
will smooth out, and you will be able to optimize in a sensible and
mathematically-legitimate way with respect to a.
Best.
K. Frank