sudi
sudi

Reputation: 21

Poisson distribution for floating value of mean

I am relatively new to Python and has been using np library. I am facing some problem in generating spikes following a Poisson distribution. You can see the details using the following link.

Random number generation following a Poisson distribution

The basic problem is that if we use an integer value for mean of Poisson distribution, we get a nice distribution (using code below). However for floating value of mean, we don't get a distribution.

spkt= np.random.poisson(5,1000)   # Mean of 5 for 1000 samples
plt.hist(spkt)
plt.show()

Upvotes: 1

Views: 1600

Answers (2)

ozturkib
ozturkib

Reputation: 1643

If you are dealing with Spiking Neural Networks, I strongly advise you to have a look those packages on python. Particularly, I used brian2 over a long time in order to implement various SNNs. To point your question with brian2 package:

P = PoissonGroup(100, np.arange(100)*Hz + 10*Hz)

More details here.

Upvotes: 0

Severin Pappadeux
Severin Pappadeux

Reputation: 20080

You could definitely sample using non-integer mean. Code below samples and computes PMF for Poisson distribution and plots the together, Win 10 x64, Anaconda Python 3.7

import numpy as np
from matplotlib import pyplot as plt
from scipy.stats import poisson

μ = 3.5
min = 0
max = 20

spkt = np.random.poisson(μ, 10000)

h, bins = np.histogram(spkt, bins = int(max-min+1), range=(min-0.5,max+0.5))
#print(h)
#print(bins)

mean = np.mean(spkt)
print(f"Mean value {mean} versus mu {μ}")

# Poisson PMF for given mu
x = [k for k in range(min, max+1)]
y = [poisson.pmf(k, μ) for k in range(min, max+1)]

# plot sampled vs computed PMF
plt.hist(spkt, bins = bins, density=True)
plt.plot(x, y, "ro")
plt.title("Poisson")
plt.show()

with picture like this

enter image description here

UPDATE

If you want very small μ sampled, the same code works for me, but it is pretty much zeroes all the way.

μ = 2.0e-5

output is

enter image description here

Upvotes: 1

Related Questions