-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoissonmle.py
More file actions
23 lines (17 loc) · 879 Bytes
/
poissonmle.py
File metadata and controls
23 lines (17 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import torch
from torch.distributions.poisson import Poisson
def generate_poisson_random_variables(poisson_parameter, sample_size):
poisson_instance = Poisson(poisson_parameter, validate_args=None)
samples_vec = poisson_instance.sample(sample_shape=torch.Size([1, sample_size]))
return samples_vec
def estimate_poisson_parameter_with_mle(observations):
mle_estimator = torch.mean(observations)
return mle_estimator
if __name__ == '__main__':
given_sample_size = 250
given_poisson_parameter = 4
samples = generate_poisson_random_variables(poisson_parameter=given_poisson_parameter,
sample_size=given_sample_size)
the_mle_estimator = estimate_poisson_parameter_with_mle(samples)
print('given_poisson_parameter :', given_poisson_parameter)
print('mle_estimator :', the_mle_estimator)