import pandas as pd
import matplotlib.pyplot as pl
import numpy as np

f = [100, 500, 1000, 2000, 5000, 7000, 8000, 9000, 10000]
amp = [976, 800, 560, 320, 160, 128, 120, 104, 104]
g = [2, 1.639, 1.148, 0.656, 0.328, 0.262, 0.246, 0.213, 0.213]
omega = 2*np.pi*np.array(f)
R=1000
C=.22e-6
X = 1.0/(omega*C)
Z = np.sqrt(R**2 + X**2)
G = 2.0*X/Z
pl.loglog(f, G,'r-',label='theory')
pl.loglog(f,g,'b.',label='exp')
pl.grid()
pl.legend()

G

N=10000
Tau=10.0
r = np.random.rand(N)
t = -Tau*np.log(1.0-r)
n,_,_ =pl.hist(t, bins=np.linspace(0,50,41))
pl.title("Exponentially distributed 't's")
pl.xlabel("t (min)")
pl.ylabel("Number (out of %d)" % N)

pl.plot(np.linspace(0,50,41)[:-1],np.log(n),'b.')
pl.grid()

t = -Tau*np.log(1.0-np.random.rand(100)) # get 100 intervals between defects
pl.hist(t)

print("Total time:", t.sum())
print("Average time:", t.mean())

delta2 = t[:-1] + t[1:]
pl.hist(delta2)#make it delta 2 and sum of two slices not three - Tariq
print("Minimum time between three successive defects:", min(delta2))
ThreeInLessThan10 = delta2<10#check for delta 2 less then ten - Tariq
print("times less than 10:", delta2[np.nonzero(ThreeInLessThan10)])
print("Number of times 3 defects happened in less than 10 minutes:", len(delta2[np.nonzero(ThreeInLessThan10)]))

finalTime = 480 # run for one hour
processTime = 10.0 # how long does it take to process an
currTime = 0.0 # what time is it now?
nextTime = processTime # when will the last defect be finished? (it takes 10 minutes to handle a defect)
defectsProcessed = 0 # how many defects have been processed?
defectsOccurred = 0
for delta in t:
currTime = currTime + delta # when does the next defect appear?
if currTime > finalTime:
break # OK, it's the end of the 1 hour shift, break out.
defectsOccurred += 1 # count the number of defects that have happened.
if currTime > nextTime:
nextTime = currTime + processTime # process immediately
else:
nextTime = nextTime + processTime # process after this one.
if nextTime<finalTime:
defectsProcessed += 1
print("Defects Occurred:", defectsOccurred)
print("Defects Processed:", defectsProcessed)
print("Backlog:", defectsOccurred-defectsProcessed)

!pip install pymc3

import pymc3 as pm
import arviz as az
with pm.Model() as model:
tau = pm.Uniform('tau',lower=0,upper=100) # set up a prior for tau, somewhere between 0 and 100
t_obs = pm.Exponential('t_obs',lam=1/tau, observed=t) # add the observed data
trace = pm.sample(1000, return_inferencedata=True) # check the results

az.plot_trace(trace)
az.summary(trace, kind="stats")