Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pieceDefec.py
- import random
- from itertools import islice
- from collections import namedtuple
- Piece = namedtuple("Piece", ('machine', 'etat'))
- def gen_machine():
- #machines = ("A","A","A","A","A","B","B","B","C","C")
- machines = ("A", "B", "C")
- weights = (.5, .3, .2)
- machine, = random.choices(machines,weights)
- return machine
- def est_fonctionnel(machine):
- r = random.random()
- tx_reussite = {"A": .97, "B": .98, "C": .95}
- return r <= tx_reussite[machine]
- def gen_sample():
- while True:
- m = gen_machine()
- f = est_fonctionnel(m)
- p = Piece(m,f)
- yield p
- def prog():
- N = 10000
- pieces = islice(gen_sample(), N)
- piecesFalse = []
- for p in pieces:
- if(p.etat == False):
- piecesFalse.append(p)
- cpt = 0
- cptA = 0
- for p in piecesFalse:
- cpt = cpt+1
- if(p.machine == 'A'):
- cptA = cptA+1
- obs = cptA/cpt
- th = .03*.5/ (.03*.5 + .02*.3 + .05*.2)
- print("Taux théorique")
- print(th)
- print("Taux Observable")
- print(obs)
- prog()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement