feat: adds bug fixes and Vitterbi algorithm

This commit is contained in:
Namu
2026-05-23 21:42:27 +02:00
parent 76121b8c68
commit 73a940ae20
3 changed files with 64 additions and 8 deletions

View File

@@ -6,7 +6,12 @@ from HMM import HMM
def normalize_probabilities(prob_fr: float, prob_en: float, prob_it: float, searched: float) -> float:
sum = prob_fr + prob_en + prob_it
return searched / sum
# si on utilise une matrice identité en tant que matrice d'émission il y a de forte change d'avoir une somme à 0.
if sum != 0:
return searched / sum
else:
return searched # retourne 0
def forward_detection(hmm_fr: HMM, hmm_en: HMM, hmm_it: HMM, O: list[int]) -> tuple[str, float, list[float]]:
@@ -95,7 +100,7 @@ def forward_detection_with_text(hmm_fr: HMM, hmm_en: HMM, hmm_it: HMM, O: list[l
french_prob_count = english_prob_count = italian_prob_count = 0
for word in O:
lang, _ = forward_detection(hmm_fr, hmm_en, hmm_it, word)
lang, _, _ = forward_detection(hmm_fr, hmm_en, hmm_it, word)
match lang:
case 'Français':
french_prob_count += 1