-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgamma.py
More file actions
41 lines (36 loc) · 1.16 KB
/
gamma.py
File metadata and controls
41 lines (36 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Code 2024-2025 by Oyin Adenekan
# edited by Peter Kasson
""" Routines for gamma fits."""
import numpy as np
import scipy
# gamma pdf
def gamma(k, N, x):
# formula for convolution of N exponentials, 1 k for each step
return ((k**N)*(x**(N-1)))*np.exp(-k*x) / scipy.special.factorial(N)
def simulate_gamma(k, N, num_times=300, upper_time_bound=500):
# set things up
lower_time_bound = 0
dwell_times = np.zeros((num_times))
prob_dwell_times = np.zeros((num_times))
successes = []
# perform simulations
total_iters = 0
idx = 0
while idx < num_times:
# propose a dwell time in the range of ks
# R = np.random.rand(lower_time_bound, upper_time_bound)
# propose a dwell time in the range of ks
R = np.random.random_sample()*upper_time_bound
prob_R = gamma(k, N, R) # get probability of dwell time according to pdf
# print(R, prob_R)
prob_accept = np.random.rand()
if prob_R > prob_accept:
# print(idx, 'success !')
dwell_times[idx] = R
prob_dwell_times[idx] = prob_R
idx = idx + 1
successes.append(True)
else:
successes.append(False)
# total_iters = total_iters + 1
return dwell_times