Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np ## Does some shit
- import matplotlib.pyplot as plt ## Does some more shit
- def probability():
- global bad_batches ## Set as global variable so can be used outside the procedure
- bad_batches = 0 ## Reset bad_batches counter to 0
- batch = [0]*(150-bad)+[1]*bad ## Create list 'batch' with 'bad' 1's and (150-'bad') 0's
- for _ in range(0,10000): ## Loop 10000 times for each 'bad' value
- np.random.shuffle(batch) ## Shuffle batch
- if sum(batch[:20]) > 2: ## If more than two samples are bad, the sum of the random 20 samples will be greater than 2
- bad_batches += 1 ## Increase the bad_batches counter by one
- print("bad = {}...........probability = {}%".format(bad,bad_batches/100)) ## Output 'bad' value and probability of the batch being rejected (%)
- ######################### Below is for the probability against 'bad' graph #########################
- badvalues = list(range(0,151)) ## Set list of 'bad' values 0 to 150
- probabilities = [] ## Reset y-axis data list
- for bad in badvalues: ## Loop 150 times, with 'bad' starting at 0 and increasing by 1 each cycle
- probability() ## Run probability procedure for current 'bad' value
- probabilities.append(bad_batches/100) ## Append probability to y-axis values list
- plt.xlabel('"bad" value') ## Self explanatory
- plt.ylabel('probability of lot being rejected (%)') ## Self explanatory
- plt.plot(badvalues,probabilities) ## Plot graph probability against 'bad' value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement