# Empreinte de la trace complete quantifiee a 1e-8 ; aucune sortie de modele n'est inventee.
import hashlib
def trace_digest(values):
return hashlib.sha256(",".join(str(int(np.rint(float(v)*1e8))) for v in values).encode()).hexdigest()
# Exercice ouvert : les trois ecarts correspondent a des contraintes distinctes.
def ecarts_equite(y, prediction, groupe):
# TODO : retourner [DPD, abs(TPR_A-TPR_B), max(abs(dTPR),abs(dFPR))].
return None
fixtures_equite = [{'y': [1, 1, 0, 0, 1, 1, 0, 0], 'p': [1, 0, 1, 0, 1, 1, 0, 0], 'g': [0, 0, 0, 0, 1, 1, 1, 1], 'expected': [0.0, 0.5, 0.5]}, {'y': [1, 0, 1, 0, 1, 0, 1, 0], 'p': [0, 0, 1, 1, 0, 1, 0, 1], 'g': [0, 0, 0, 0, 1, 1, 1, 1], 'expected': [0.0, 0.5, 0.5]}, {'y': [1, 0, 0, 1, 0, 0], 'p': [1, 0, 0, 0, 0, 0], 'g': [0, 0, 0, 1, 1, 1], 'expected': [0.3333333333333333, 1.0, 1.0]}, {'y': [1, 0, 1, 0], 'p': [1, 0, 1, 0], 'g': [0, 0, 1, 1], 'expected': [0.0, 0.0, 0.0]}, {'y': [1, 0, 0, 1, 0, 0], 'p': [1, 1, 1, 1, 0, 0], 'g': [0, 0, 0, 1, 1, 1], 'expected': [0.6666666666666666, 0, 1]}]
resultats_ex1 = [ecarts_equite(np.array(f['y']),np.array(f['p']),np.array(f['g'])) for f in fixtures_equite]
if all(r is None for r in resultats_ex1):
print("Exercice 1 a completer : calculer les trois ecarts.")
else:
for f,r in zip(fixtures_equite,resultats_ex1):
v=np.asarray(r,dtype=float)
assert v.shape==(3,) and np.isfinite(v).all(), "Trois ecarts finis requis"
assert np.allclose(v,f['expected'],atol=1e-12,rtol=0), "Definition ou table incorrecte"
print("Contrat equite satisfait ; justifier le cas TPR egaux/FPR differents.")