Advertisement
Guest User

Untitled

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