X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/16dcc.git/blobdiff_plain/e1fe6e435ee452003a7135763d26e2320756398c..8dfce25f59a57787b53e1ba55971a5c4f8d5993f:/evalPRNG/compareFonctionMixingTime.py diff --git a/evalPRNG/compareFonctionMixingTime.py b/evalPRNG/compareFonctionMixingTime.py index faaebd8..6d6e602 100644 --- a/evalPRNG/compareFonctionMixingTime.py +++ b/evalPRNG/compareFonctionMixingTime.py @@ -25,9 +25,9 @@ def dec(ch,n): acc = acc + 2**(n-i-1) return acc -""" + def MarkovMatrixUnPas(fbin,n,p2n,lp2nm1): - print p2n + #print p2n MM = np.zeros((p2n,p2n)) # diagonal for i in lp2nm1 : @@ -59,7 +59,7 @@ def MarkovMatrixUnPas(fbin,n,p2n,lp2nm1): def MarkovMatrixSaut(fbin,n,p2n,lp2nm1): - print p2n + #print p2n MM = np.zeros((p2n,p2n)) # diagonal for i in lp2nm1 : @@ -94,7 +94,7 @@ def MarkovMatrixSaut(fbin,n,p2n,lp2nm1): return MM - +""" @@ -102,7 +102,7 @@ def MarkovMatrixSaut(fbin,n,p2n,lp2nm1): lf= [] #lf +=[ [13, 10, 9, 14, 3, 11, 1, 12, 15, 4, 7, 5, 2, 6, 0, 8]] #4 #lf += [[29, 22, 25, 30, 19, 27, 24, 16, 21, 6, 5, 28, 23, 26, 1, 17, 31, 12, 15, 8, 10, 14, 13, 9, 3, 2, 7, 20, 11, 18, 0, 4]] #5 -#lf += [[55, 60, 45, 44, 58, 62, 61, 48, 53, 50, 52, 36, 59, 34, 33, 49, 15, 42, 47, 46, 35, 10, 57, 56, 7, 54, 39, 37, 51, 2, 1, 40, 63, 26, 25, 30, 19, 27, 17, 28, 31, 20, 23, 21, 18, 22, 16, 24, 13, 12, 29, 8, 43, 14, 41, 0, 5, 38, 4, 6, 11, 3, 9, 32]] #6 +lf += [[55, 60, 45, 44, 58, 62, 61, 48, 53, 50, 52, 36, 59, 34, 33, 49, 15, 42, 47, 46, 35, 10, 57, 56, 7, 54, 39, 37, 51, 2, 1, 40, 63, 26, 25, 30, 19, 27, 17, 28, 31, 20, 23, 21, 18, 22, 16, 24, 13, 12, 29, 8, 43, 14, 41, 0, 5, 38, 4, 6, 11, 3, 9, 32]] #6 #lf+= [[47, 58, 57, 44, 51, 42, 41, 60, 63, 22, 37, 53, 19, 54, 48, 32, 45, 14, 13, 46, 11, 43, 33, 8, 7, 36, 39, 4, 34, 50, 1, 40, 29, 62, 61, 30, 59, 27, 17, 56, 55, 20, 23, 52, 18, 2, 49, 24, 31, 10, 9, 28, 3, 26, 25, 12, 15, 38, 21, 5, 35, 6, 0, 16]] #lf += [[111, 94, 93, 116, 122, 90, 125, 88, 115, 126, 119, 84, 123, 98, 81, 120, 109, 106, 105, 110, 99, 107, 104, 72, 71, 118, 117, 96, 103, 102, 113, 64, 79, 86, 95, 124, 83, 91, 121, 24, 85, 22, 69, 20, 19, 114, 17, 112, 77, 76, 13, 108, 74, 10, 9, 73, 67, 66, 101, 100, 75, 82, 97, 0, 127, 54, 57, 62, 51, 59, 56, 48, 53, 38, 37, 60, 55, 58, 33, 49, 63, 44, 47, 40, 42, 46, 45, 41, 35, 34, 39, 52, 43, 50, 32, 36, 29, 28, 61, 92, 26, 18, 89, 25, 87, 30, 23, 4, 27, 2, 16, 80, 31, 78, 15, 14, 3, 11, 8, 12, 5, 70, 21, 68, 7, 6, 65, 1]] #7 @@ -112,11 +112,11 @@ lf= [] #lf +=[[223, 250, 249, 254, 187, 251, 233, 232, 183, 230, 247, 180, 227, 178, 240, 248, 237, 236, 173, 172, 171, 238, 201, 168, 229, 166, 228, 244, 235, 242, 241, 192, 215, 220, 205, 216, 218, 222, 153, 152, 151, 210, 212, 214, 219, 146, 217, 209, 239, 142, 141, 206, 195, 234, 193, 136, 231, 196, 199, 197, 194, 226, 225, 200, 63, 188, 253, 252, 59, 190, 189, 176, 191, 246, 245, 164, 243, 162, 161, 177, 143, 170, 45, 44, 43, 138, 185, 184, 135, 38, 167, 165, 179, 34, 129, 224, 31, 154, 221, 158, 147, 26, 25, 156, 159, 22, 213, 149, 211, 150, 144, 208, 207, 14, 13, 204, 203, 202, 169, 8, 133, 198, 132, 4, 139, 131, 1, 160, 255, 124, 109, 108, 122, 126, 125, 112, 117, 114, 116, 100, 123, 98, 97, 113, 79, 106, 111, 110, 99, 74, 121, 120, 71, 118, 103, 101, 115, 66, 65, 104, 127, 90, 89, 94, 83, 91, 81, 92, 95, 84, 87, 85, 82, 86, 80, 88, 77, 76, 93, 72, 107, 78, 105, 64, 69, 102, 68, 70, 75, 67, 73, 96, 55, 58, 57, 62, 51, 186, 41, 40, 119, 182, 181, 53, 35, 54, 48, 56, 175, 174, 61, 60, 11, 46, 9, 32, 37, 6, 36, 52, 163, 50, 49, 0, 23, 28, 157, 24, 155, 30, 29, 16, 21, 18, 20, 148, 27, 19, 145, 17, 47, 10, 15, 140, 3, 42, 137, 12, 39, 134, 7, 5, 2, 130, 33, 128]] #8 totally -lf +=[ - [29, 22, 21, 30, 19, 27, 24, 28, 7, 20, 5, 4, 23, 26, 25, 17, 31, 12, 15, 8, 10, 14, 13, 9, 3, 2, 1, 6, 11, 18, 0, 16],#sylvain 1 - [29, 22, 25, 30, 19, 27, 24, 16, 21, 6, 5, 28, 23, 26, 1, 17, 31, 12, 15, 8, 10, 14, 13, 9, 3, 2, 7, 20, 11, 18, 0, 4],#sylvain 2 - [29, 22, 21, 24, 31, 30, 27, 26, 7, 23, 5, 28, 3, 19, 25, 17, 13, 12, 9, 8, 15, 2, 1, 10, 6, 14, 4, 20, 11, 18, 0, 16], #mini avec 7 - [29, 22, 25, 30, 19, 27, 24, 16, 21, 6, 5, 28, 23, 26, 1, 17, 31, 12, 15, 8, 10, 14, 13, 9, 3, 2, 7, 20, 11, 18, 0, 4]] #5 +#lf +=[ +# [29, 22, 21, 30, 19, 27, 24, 28, 7, 20, 5, 4, 23, 26, 25, 17, 31, 12, 15, 8#, 10, 14, 13, 9, 3, 2, 1, 6, 11, 18, 0, 16],#sylvain 1 +# [29, 22, 25, 30, 19, 27, 24, 16, 21, 6, 5, 28, 23, 26, 1, 17, 31, 12, 15, 8, 10, 14, 13, 9, 3, 2, 7, 20, 11, 18, 0, 4],#sylvain 2 +# [29, 22, 21, 24, 31, 30, 27, 26, 7, 23, 5, 28, 3, 19, 25, 17, 13, 12, 9, 8, 15, 2, 1, 10, 6, 14, 4, 20, 11, 18, 0, 16], #mini avec 7 +# [29, 22, 25, 30, 19, 27, 24, 16, 21, 6, 5, 28, 23, 26, 1, 17, 31, 12, 15, 8, 10, 14, 13, 9, 3, 2, 7, 20, 11, 18, 0, 4]] #5 # 14 = (1,1,1,0) = f(0,0,0,0) @@ -142,19 +142,19 @@ def traite_f(f,dev): M = np.zeros((p2n,p2n)) np.copyto(M,MM) - MMs = MarkovMatrixSaut(fbin,n,p2n,lp2nm1) - Ms = np.zeros((p2n,p2n)) - np.copyto(Ms,MMs) - - - error = 1 cpt = 2 - while error > dev : + while error > dev and cpt < 1000: M = np.dot(M,MM) error =max([sqrt(sum([(M[i,j] - float(1)/p2n)**2 for i in range(p2n)])) for j in range(p2n)]) #print cpt, error, M cpt +=1 + + + """ + MMs = MarkovMatrixSaut(fbin,n,p2n,lp2nm1) + Ms = np.zeros((p2n,p2n)) + np.copyto(Ms,MMs) error = 1 @@ -167,8 +167,8 @@ def traite_f(f,dev): #print cpt, error, M cpts +=1 - - + """ + cpts=1 return n, cpt-1, cpts-1 @@ -182,9 +182,9 @@ def get_treatedlist(rf): # suppr [ et ] #print compteur, l - l = l[1:len(l)-3] + l = l[1:len(l)-2] #print l - lkm = [x for x in l.split(", ")] + lkm = [x for x in l.split(",")] #print lkm treatedlist.append([int(x) for x in lkm]) return treatedlist @@ -218,16 +218,18 @@ def main(): brut=[] cpt = 0 - for f in lf: - dev = 1E-12 + for f in lf: + #print "cpt",cpt + dev = 1E-14 n,cptM,cptS = traite_f(f,dev) brut +=[(f,cptM,cptS)] + cpt+=1 """ print f, n,cptM,cptS #print 8*n*n + 4*n*log(n+1)#,8*n*n + (n+2)*(log(n)+2) #print "Pour "+str(n)+" bits et pour eps="+str(dev)+", appels a rand moy pr 1 bit genere.", print cpt - cpt+=1 + brut.sort(cmp=compareMarche) f,cptM,cptS = brut[0] @@ -246,7 +248,15 @@ def main(): else : print "egales" """ - print brut + #print brut + brut.sort(cmp=compareMarche) + print brut + (meilleure,k,kk) = brut[0] + n,cpM,cPS = traite_f(f,1E-6) + print "Meilleure fonction :\n", f + print "CPM :", cpM + + rf = False def options(): @@ -254,6 +264,7 @@ def options(): parser = OptionParser() parser.add_option("-i", "--input", dest="i", help="file of sequences") + (options, args) = parser.parse_args() if (options.i != None): rf = options.i