def analyse_faux_positif(): """ Algorithme de la Question 4.3 """ file=open('res.txt','w') #contiendra le résultat mots_testes=0 faux_positifs=0 liste_mots_aleatoires=[] for mot_a_inserer in range (2**10+1): liste_mots_aleatoires += [random_word()] #création des 2^10 mots aléatoires for nombre_fonctions in range (1,9): for taille_table in range (10,21): bf= bloomfilter.create(taille_table,code_of_string,nombre_fonctions) for mot in liste_mots_aleatoires: #insertion de tous les mots de la liste dans le filtre de Bloom bloomfilter.add(bf,mot) for mot_test in range (2**14): #test de 2^14 autres mots aléatoires mot = random_word() if mot not in liste_mots_aleatoires: mots_testes+=1 if bloomfilter.contains(bf,mot) == True: faux_positifs+=1 file.write(str(taille_table )+ " " + str(nombre_fonctions) + " " + str(mots_testes) + " " + str(faux_positifs) + " " + str(round((faux_positifs/mots_testes),6))+ "\n") #écriture de la ligne mots_testes=0 faux_positifs=0 #réinitialisation des valeurs file.write("\n\n") #séparation avant ajout d'une fonction de hachage
def test(): resultat = "" file = open('res.txt', 'w') faux_pos = 0 mot_test = 0 I = list() for i in range(0, 10): I.append(random_word()) for n in range(1, 8): for t in range(10, 20): resultat = "" bf = bloomfilter.create(t, code_of_string, n) for i in I: bloomfilter.add(bf, i) for k in range(1, 2**14): U = random_word() if not (U in I): mot_test += 1 if (bloomfilter.contains(bf, U)): faux_pos += 1 resultat += str(t) + " " + str(n) + " " + str(k) + " " + str( mot_test) + " " + str(faux_pos) + " " + str( faux_pos / k) + "\n" file.write(resultat) file.write('\n\n') file.close()
def analyse_faux_positif(): """ Algorithme de la Question 4.3 """ file = open('res.txt', 'w') mots_testes = 0 faux_positifs = 0 liste_mots_aleatoires = [] for mot_a_inserer in range(2**10 + 1): liste_mots_aleatoires += [random_word()] for n in range(1, 9): for t in range(10, 21): bf = bloomfilter.create(t, code_of_string, n) for mot in liste_mots_aleatoires: # bloomfilter.add(bf, mot) for mot_test in range(1, (2**14) + 1): mot = random_word() if mot not in liste_mots_aleatoires: mots_testes += 1 if bloomfilter.contains(bf, mot) == True: faux_positifs += 1 file.write( str(t) + " " + str(n) + " " + str(mots_testes) + " " + str(faux_positifs) + " " + str(round((faux_positifs / mots_testes), 6)) + "\n") #écriture de la ligne mots_testes = 0 faux_positifs = 0 #réinitialisation des valeurs file.write("\n\n") #séparation avant ajout d'une fonction de hachage
init_random_tab() """ bf = bloomfilter.create(4,code_of_string,8) w = random_word() bloomfilter.add(bf,"timoleon") if bloomfilter.contains(bf,"timoleon"): print("%s est present" % ("timoleon")) if bloomfilter.contains(bf,w): print("%s est present" % (w)) """ listRandomWords = [random_word() for k in range(2**10)] for n in range(1, 9): cpTested = 0 cpPositif = 0 for t in range(10, 21): bf = bloomfilter.create(t, code_of_string, n) for i in range(2**10): bloomfilter.add(bf, listRandomWords[i]) for k in range(2**14): u = random_word() if not (u in listRandomWords): cpTested += 1 if bloomfilter.contains(bf, u): cpPositif += 1 print(t, end=" ") print(n, end=" ") print(cpTested, end=" ") print(cpPositif, end=" ") print(cpPositif / cpTested) cpTested = 0 cpPositif = 0
for i in I: bloomfilter.add(bf, i) for k in range(1, 2**14): U = random_word() if not (U in I): mot_test += 1 if (bloomfilter.contains(bf, U)): faux_pos += 1 resultat += str(t) + " " + str(n) + " " + str(k) + " " + str( mot_test) + " " + str(faux_pos) + " " + str( faux_pos / k) + "\n" file.write(resultat) file.write('\n\n') file.close() if __name__ == "__main__": init_random_tab() bf = bloomfilter.create(6, code_of_string, 8) w = random_word() bloomfilter.add(bf, "timoleon") if bloomfilter.contains(bf, "timoleon"): print("%s est present" % ("timoleon")) if bloomfilter.contains(bf, w): print("%s est present" % (w)) #test code_of_string #print(code_of_string("toto",1)) test()