Coverage for src/mlstatpy/image/detection_segment/queue_binom.py: 100%
11 statements
« prev ^ index » next coverage.py v7.1.0, created at 2023-02-27 05:59 +0100
« prev ^ index » next coverage.py v7.1.0, created at 2023-02-27 05:59 +0100
1# -*- coding: utf-8 -*-
2"""
3@file
4@brief Ce module construit les probabilités d'une loi binomiale :math:`B(n,p)`.
5"""
8def tabule_queue_binom(n, p):
9 """
10 Retourne un dictionnaire dont la clé est couple d'entiers *(a,b)*
11 si *t* est le resultat, alors :math:`t=[(a,b)]` est la probabilité
12 qu'il y ait *b* événements parmi *a* sachant que la probabilité d'un
13 événement est *p* : :math:`t [ (a,b) ] = C_a^b p^b (1-p)^ {(a-b)}`
15 Pour aller plus vite, ces probabilités sont estimées par récurrence :
17 * :math:`\\forall m, \\; t [(m,0)] = 1.0`
18 * :math:`\\forall m, \\; t [(m,m+1)] = 0.0`
19 et :math:`t[(m,k)] = p * t [ (m-1, k-1)] + (1-p) * t [ (m-1,k) ]`
21 Cette fonction calcule tous les coefficients :math:`t [ (a,b) ]` pour une
22 probabilité :math:`p` donnée et :math:`b \\infegal a \\infegal n`.
24 Ces probabilités sont stockées dans un dictionnaire car s'ils étaient
25 stockées dans une matrice, celle-ci serait triangulaire inférieure.
26 """
27 t = {}
28 t[(0, 0)] = 1.0
29 t[(0, 1)] = 0.0
30 for m in range(1, n + 1):
31 t[(m, 0)] = 1.0
32 t[(m, m + 1)] = 0.0
33 for k in range(1, m + 1):
34 t[(m, k)] = p * t[(m - 1, k - 1)] + (1 - p) * t[(m - 1, k)]
35 return t