Advertisement
kilarn123

Untitled

Jan 28th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. #pieceDefec.py
  2.  
  3. import random
  4. from itertools import islice
  5. from collections import namedtuple
  6.  
  7. Piece = namedtuple("Piece", ('machine', 'etat'))
  8.  
  9. def gen_machine():
  10.     #machines = ("A","A","A","A","A","B","B","B","C","C")
  11.     machines = ("A", "B", "C")
  12.     weights = (.5, .3, .2)
  13.     machine, = random.choices(machines,weights)
  14.     return machine
  15. def est_fonctionnel(machine):
  16.     r = random.random()
  17.     tx_reussite = {"A": .97, "B": .98, "C": .95}
  18.     return r <= tx_reussite[machine]
  19.  
  20. def gen_sample():
  21.     while True:
  22.         m = gen_machine()
  23.         f = est_fonctionnel(m)
  24.         p = Piece(m,f)
  25.         yield p
  26.        
  27. def prog():
  28.     N = 10000
  29.     pieces = islice(gen_sample(), N)
  30.     piecesFalse = []
  31.     for p in pieces:
  32.         if(p.etat == False):
  33.             piecesFalse.append(p)
  34.     cpt = 0
  35.     cptA = 0
  36.     for p in piecesFalse:
  37.         cpt = cpt+1
  38.         if(p.machine == 'A'):
  39.             cptA = cptA+1
  40.    
  41.     obs = cptA/cpt
  42.    
  43.    
  44.     th = .03*.5/ (.03*.5 + .02*.3 + .05*.2)
  45.     print("Taux théorique")
  46.     print(th)
  47.     print("Taux Observable")
  48.     print(obs)
  49.  
  50. prog()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement