09-Probabilities#
Event Probability from Poisson Distribution#
Multiple Event Probability Estimates#
Monte-Carlo#
Example Monte-Carlo Simulation
#import needed packages
import numpy as np
import matplotlib.pyplot as plt
# Number of random numbers to generate
N = int(1e4)
MTBF_A = 1 # mean time between failures, unit time for Event A
muA = 1/MTBF_A # average events per unit time for A
1-np.exp(-muA) # probability of at least one event in unit time (poisson process)
0.6321205588285577
muA*np.exp(-muA) # probability of exactly one event in unit time (poisson process)
0.36787944117144233
unif = np.random.uniform(0, 1, N) # generate N random numbers between 0 and 1
# 1 if event, 0 if no event, where the if statement is the Monte Carlo approach
eventA = [1 if x < 1-np.exp(-muA) else 0 for x in unif]
Each entry in that list is an “event” over a duration of unit time and it can either be a failure or a success.
pA = sum(eventA)/len(eventA) # fraction of time with at least one event, probability of event in time unit
pA
0.6305
#determine the average rate of events per unit time
-np.log(1-pA)
0.9956045385938804
# now let's do the same thing for a Poisson process with a second 'event'
unif = np.random.uniform(0,1,N) #generate new random numbers
MTBF_B = 2 # mean time between failures
muB = 1/MTBF_B # average events per unit time
eventB = [ 1 if x < 1-np.exp(-muB) else 0 for x in unif ]
# now consider eventA and eventB as two independent Poisson processes in an OR gate
eventAorB = [min(1,sum([a,b])) for a,b in zip(eventA, eventB)]
pAorB = sum(eventAorB)/len(eventAorB) # fraction of time with at least one event
pAorB
0.7722
#combination of the two events for the average rate of events per unit time (mu)
-np.log(1-pAorB)
1.4792872279690552
# now consider eventA and eventB as two independent Poisson processes in an AND gate
eventAandB = [a*b for a,b in zip(eventA, eventB)]
pAandB = sum(eventAandB)/len(eventAandB) # fraction of time with at least one event
pAandB
0.2515
#Calculation of the probability of A and B occurring at the same time (product of the two probabilities)
pab = (1-np.exp(-muB))*(1-np.exp(-muA))
pab
0.2487200592643541
#combination of the two events for the average rate of events per unit time (mu) from simulation
-np.log(1-pAandB)
0.2896840751224541
#combination of the two events for the average rate of events per unit time (mu) from product of probabilities
-np.log(1-pab)
0.28597693937029134