Python code problem

Joined
Mar 31, 2023
Messages
95
Reaction score
8
Hello I have a possible error that I will not find in my code come to my secour please
Python:
import random as rd
w1 = ((rd.randint(0, 400)-200)/100)
w2 = ((rd.randint(0, 400)-200)/100)
w3 = ((rd.randint(0, 400)-200)/100)
w4 = ((rd.randint(0, 400)-200)/100)
w5 = ((rd.randint(0, 400)-200)/100)
w6 = ((rd.randint(0, 400)-200)/100)
w7 = ((rd.randint(0, 400)-200)/100)
w8 = ((rd.randint(0, 400)-200)/100)
w9 = ((rd.randint(0, 400)-200)/100)
w10 = ((rd.randint(0, 400)-200)/100)
w11 = ((rd.randint(0, 400)-200)/100)
w12 = ((rd.randint(0, 400)-200)/100)
w13 = ((rd.randint(0, 400)-200)/100)
w14 = ((rd.randint(0, 400)-200)/100)
w15 = ((rd.randint(0, 400)-200)/100)
w16 = ((rd.randint(0, 400)-200)/100)
w17 = ((rd.randint(0, 400)-200)/100)
w18 = ((rd.randint(0, 400)-200)/100)
w19 = ((rd.randint(0, 400)-200)/100)
w20 = ((rd.randint(0, 400)-200)/100)
w21 = ((rd.randint(0, 400)-200)/100)
w22 = ((rd.randint(0, 400)-200)/100)
w23 = ((rd.randint(0, 400)-200)/100)
w24 = ((rd.randint(0, 400)-200)/100)
w25 = ((rd.randint(0, 400)-200)/100)
w26 = ((rd.randint(0, 400)-200)/100)
w27 = ((rd.randint(0, 400)-200)/100)
w28 = ((rd.randint(0, 400)-200)/100)
w29 = ((rd.randint(0, 400)-200)/100)
w30 = ((rd.randint(0, 400)-200)/100)
w31 = ((rd.randint(0, 400)-200)/100)
w32 = ((rd.randint(0, 400)-200)/100)
w33 = ((rd.randint(0, 400)-200)/100)
w34 = ((rd.randint(0, 400)-200)/100)
w35 = ((rd.randint(0, 400)-200)/100)
w36 = ((rd.randint(0, 400)-200)/100)
w37 = ((rd.randint(0, 400)-200)/100)
w38 = ((rd.randint(0, 400)-200)/100)
w39 = ((rd.randint(0, 400)-200)/100)
w40 = ((rd.randint(0, 400)-200)/100)
w41 = ((rd.randint(0, 400)-200)/100)
w42 = ((rd.randint(0, 400)-200)/100)
w43 = ((rd.randint(0, 400)-200)/100)
w44 = ((rd.randint(0, 400)-200)/100)
w45 = ((rd.randint(0, 400)-200)/100)
w46 = ((rd.randint(0, 400)-200)/100)
w47 = ((rd.randint(0, 400)-200)/100)
w48 = ((rd.randint(0, 400)-200)/100)
w49 = ((rd.randint(0, 400)-200)/100)
w50 = ((rd.randint(0, 400)-200)/100)


w51 = ((rd.randint(0, 400)-200)/100)
w52 = ((rd.randint(0, 400)-200)/100)
w53 = ((rd.randint(0, 400)-200)/100)
w54 = ((rd.randint(0, 400)-200)/100)
w55 = ((rd.randint(0, 400)-200)/100)
w56 = ((rd.randint(0, 400)-200)/100)
w57 = ((rd.randint(0, 400)-200)/100)
w58 = ((rd.randint(0, 400)-200)/100)
w59 = ((rd.randint(0, 400)-200)/100)
w60 = ((rd.randint(0, 400)-200)/100)
w61 = ((rd.randint(0, 400)-200)/100)
w62 = ((rd.randint(0, 400)-200)/100)
w63 = ((rd.randint(0, 400)-200)/100)
w64 = ((rd.randint(0, 400)-200)/100)
w65 = ((rd.randint(0, 400)-200)/100)
w66 = ((rd.randint(0, 400)-200)/100)
w67 = ((rd.randint(0, 400)-200)/100)
w68 = ((rd.randint(0, 400)-200)/100)
w69 = ((rd.randint(0, 400)-200)/100)
w70 = ((rd.randint(0, 400)-200)/100)
w71 = ((rd.randint(0, 400)-200)/100)

w72 = ((rd.randint(0, 400)-200)/100)
w73 = ((rd.randint(0, 400)-200)/100)
w74 = ((rd.randint(0, 400)-200)/100)
w75 = ((rd.randint(0, 400)-200)/100)
w76 = ((rd.randint(0, 400)-200)/100)
w77 = ((rd.randint(0, 400)-200)/100)
w78 = ((rd.randint(0, 400)-200)/100)
w79 = ((rd.randint(0, 400)-200)/100)
w80 = ((rd.randint(0, 400)-200)/100)
w81 = ((rd.randint(0, 400)-200)/100)
w82 = ((rd.randint(0, 400)-200)/100)
w83 = ((rd.randint(0, 400)-200)/100)
w84 = ((rd.randint(0, 400)-200)/100)
w85 = ((rd.randint(0, 400)-200)/100)
w86 = ((rd.randint(0, 400)-200)/100)
w87 = ((rd.randint(0, 400)-200)/100)
w88 = ((rd.randint(0, 400)-200)/100)
w89 = ((rd.randint(0, 400)-200)/100)
w90 = ((rd.randint(0, 400)-200)/100)
w91 = ((rd.randint(0, 400)-200)/100)
w92 = ((rd.randint(0, 400)-200)/100)
w93 = ((rd.randint(0, 400)-200)/100)
w94 = ((rd.randint(0, 400)-200)/100)
w95 = ((rd.randint(0, 400)-200)/100)
w96 = ((rd.randint(0, 400)-200)/100)
w97 = ((rd.randint(0, 400)-200)/100)
w98 = ((rd.randint(0, 400)-200)/100)
w99 = ((rd.randint(0, 400)-200)/100)
w100 = ((rd.randint(0, 400)-200)/100)
w101 = ((rd.randint(0, 400)-200)/100)
w102 = ((rd.randint(0, 400)-200)/100)
w103 = ((rd.randint(0, 400)-200)/100)
w104 = ((rd.randint(0, 400)-200)/100)
w105 = ((rd.randint(0, 400)-200)/100)
w106 = ((rd.randint(0, 400)-200)/100)
w107 = ((rd.randint(0, 400)-200)/100)
w108 = ((rd.randint(0, 400)-200)/100)
w109 = ((rd.randint(0, 400)-200)/100)
w110 = ((rd.randint(0, 400)-200)/100)
w111 = ((rd.randint(0, 400)-200)/100)
w112 = ((rd.randint(0, 400)-200)/100)
w113 = ((rd.randint(0, 400)-200)/100)
w114 = ((rd.randint(0, 400)-200)/100)
w115 = ((rd.randint(0, 400)-200)/100)
w116 = ((rd.randint(0, 400)-200)/100)
w117 = ((rd.randint(0, 400)-200)/100)
w118 = ((rd.randint(0, 400)-200)/100)
w119 = ((rd.randint(0, 400)-200)/100)
w120 = ((rd.randint(0, 400)-200)/100)
w121 = ((rd.randint(0, 400)-200)/100)
w122 = ((rd.randint(0, 400)-200)/100)
w123 = ((rd.randint(0, 400)-200)/100)
w124 = ((rd.randint(0, 400)-200)/100)
w125 = ((rd.randint(0, 400)-200)/100)
w126 = ((rd.randint(0, 400)-200)/100)
w127 = ((rd.randint(0, 400)-200)/100)
w128 = ((rd.randint(0, 400)-200)/100)
w129 = ((rd.randint(0, 400)-200)/100)
w130 = ((rd.randint(0, 400)-200)/100)
w131 = ((rd.randint(0, 400)-200)/100)
w132 = ((rd.randint(0, 400)-200)/100)
w133 = ((rd.randint(0, 400)-200)/100)
w134 = ((rd.randint(0, 400)-200)/100)
w135 = ((rd.randint(0, 400)-200)/100)
w136 = ((rd.randint(0, 400)-200)/100)
w137 = ((rd.randint(0, 400)-200)/100)
w138 = ((rd.randint(0, 400)-200)/100)
w139 = ((rd.randint(0, 400)-200)/100)
w140 = ((rd.randint(0, 400)-200)/100)
w141 = ((rd.randint(0, 400)-200)/100)
w142 = ((rd.randint(0, 400)-200)/100)
w143 = ((rd.randint(0, 400)-200)/100)
w144 = ((rd.randint(0, 400)-200)/100)
w145 = ((rd.randint(0, 400)-200)/100)
w146 = ((rd.randint(0, 400)-200)/100)
w147 = ((rd.randint(0, 400)-200)/100)
w148 = ((rd.randint(0, 400)-200)/100)
w149 = ((rd.randint(0, 400)-200)/100)
w150 = ((rd.randint(0, 400)-200)/100)
w151 = ((rd.randint(0, 400)-200)/100)
w152 = ((rd.randint(0, 400)-200)/100)
w153 = ((rd.randint(0, 400)-200)/100)
w154 = ((rd.randint(0, 400)-200)/100)
w155 = ((rd.randint(0, 400)-200)/100)
w156 = ((rd.randint(0, 400)-200)/100)
w157 = ((rd.randint(0, 400)-200)/100)
w158 = ((rd.randint(0, 400)-200)/100)
w159 = ((rd.randint(0, 400)-200)/100)
w160 = ((rd.randint(0, 400)-200)/100)
w161 = ((rd.randint(0, 400)-200)/100)
w162 = ((rd.randint(0, 400)-200)/100)
w163 = ((rd.randint(0, 400)-200)/100)
w164 = ((rd.randint(0, 400)-200)/100)
w165 = ((rd.randint(0, 400)-200)/100)
w166 = ((rd.randint(0, 400)-200)/100)
w167 = ((rd.randint(0, 400)-200)/100)
w168 = ((rd.randint(0, 400)-200)/100)
w169 = ((rd.randint(0, 400)-200)/100)
w170 = ((rd.randint(0, 400)-200)/100)
w171 = ((rd.randint(0, 400)-200)/100)
w172 = ((rd.randint(0, 400)-200)/100)
w173 = ((rd.randint(0, 400)-200)/100)
w174 = ((rd.randint(0, 400)-200)/100)
w175 = ((rd.randint(0, 400)-200)/100)
w176 = ((rd.randint(0, 400)-200)/100)
w177 = ((rd.randint(0, 400)-200)/100)
w178 = ((rd.randint(0, 400)-200)/100)
w179 = ((rd.randint(0, 400)-200)/100)
w180 = ((rd.randint(0, 400)-200)/100)
w181 = ((rd.randint(0, 400)-200)/100)
w182 = ((rd.randint(0, 400)-200)/100)
w183 = ((rd.randint(0, 400)-200)/100)
w184 = ((rd.randint(0, 400)-200)/100)
w185 = ((rd.randint(0, 400)-200)/100)
w186 = ((rd.randint(0, 400)-200)/100)
w187 = ((rd.randint(0, 400)-200)/100)
w188 = ((rd.randint(0, 400)-200)/100)
w189 = ((rd.randint(0, 400)-200)/100)
w190 = ((rd.randint(0, 400)-200)/100)
w191 = ((rd.randint(0, 400)-200)/100)
w192 = ((rd.randint(0, 400)-200)/100)
w193 = ((rd.randint(0, 400)-200)/100)
w194 = ((rd.randint(0, 400)-200)/100)
w195 = ((rd.randint(0, 400)-200)/100)
w196 = ((rd.randint(0, 400)-200)/100)
w197 = ((rd.randint(0, 400)-200)/100)
w198 = ((rd.randint(0, 400)-200)/100)
w199 = ((rd.randint(0, 400)-200)/100)
w200 = ((rd.randint(0, 400)-200)/100)

b1 = ((rd.randint(0, 400)-200)/100)
b2 = ((rd.randint(0, 400)-200)/100)
b3 = ((rd.randint(0, 400)-200)/100)
b4 = ((rd.randint(0, 400)-200)/100)
b5 = ((rd.randint(0, 400)-200)/100)
b6 = ((rd.randint(0, 400)-200)/100)
b7 = ((rd.randint(0, 400)-200)/100)
b8 = ((rd.randint(0, 400)-200)/100)
b9 = ((rd.randint(0, 400)-200)/100)
b10 = ((rd.randint(0, 400)-200)/100)
b11 = ((rd.randint(0, 400)-200)/100)
b12 = ((rd.randint(0, 400)-200)/100)
b13 = ((rd.randint(0, 400)-200)/100)
b14 = ((rd.randint(0, 400)-200)/100)
b15 = ((rd.randint(0, 400)-200)/100)
b16 = ((rd.randint(0, 400)-200)/100)
b17 = ((rd.randint(0, 400)-200)/100)
b18 = ((rd.randint(0, 400)-200)/100)
b19 = ((rd.randint(0, 400)-200)/100)
b20 = ((rd.randint(0, 400)-200)/100)
b21 = ((rd.randint(0, 400)-200)/100)
b22 = ((rd.randint(0, 400)-200)/100)
b23 = ((rd.randint(0, 400)-200)/100)
b24 = ((rd.randint(0, 400)-200)/100)
b25 = ((rd.randint(0, 400)-200)/100)
b26 = ((rd.randint(0, 400)-200)/100)
b27 = ((rd.randint(0, 400)-200)/100)
b28 = ((rd.randint(0, 400)-200)/100)
b29 = ((rd.randint(0, 400)-200)/100)
b30 = ((rd.randint(0, 400)-200)/100)
b31 = ((rd.randint(0, 400)-200)/100)
b32 = ((rd.randint(0, 400)-200)/100)
# =============================================================================
# vtesse et présision de l'aprentissage
# =============================================================================
learning_rate = 0.001
nombre_iteration = 1000
alphabet = [('a',1), ('b',2), ('c',3), ('d',4), ('e',5), ('f',6), ('g',7), ('h',8), ('i',9), ('j',10), ('k',11), ('l',12), ('m',13), ('n',14), ('o',15), ('p',16), ('q',17), ('r',18), ('s',19), ('t',20), ('u',21), ('v',22), ('w',23), ('x',24), ('y',25), ('z',26),(' ',27)]
# =============================================================================
# donner a récolter (chaque entrée = une letre)
# =============================================================================
XM1 = [0.6931471805599453, 2.5649493574615367, 2.5649493574615367, 2.772588722239781, 0, 0, 0, 0]
XM2 = [1.0986122886681098, 2.772588722239781, 2.70805020110221, 2.3978952727983707, 2.772588722239781, 3.091042453358316, 2.9444389791664403, 0]
x1 = [XM1[0],XM2[0]]
x2 = [XM1[1],XM2[1]]
x3 = [XM1[2],XM2[2]]
x4 = [XM1[3],XM2[3]]
x5 = [XM1[4],XM2[4]]
x6 = [XM1[5],XM2[5]]
x7 = [XM1[6],XM2[6]]
x8 = [XM1[7],XM2[7]]
yT = [8.5956346177228,17.785216639573008]
mot = []
# =============================================================================
# dessente de gradiant
# =============================================================================
Ni = len(yT)
for i in range(0,nombre_iteration):
    R = []
    mot = []
    for i in range(0,Ni):
        F1 = (w1*x1[i])+(w2*x2[i])+(w3*x3[i])+(w4*x4[i])+(w5*x5[i])+(w6*x6[i])+(w7*x7[i])+(w8*x8[i])+b1
        if F1 > 0:
            F1 = 1
        else:
            F1 = 0
        F2 = (w9*x1[i])+(w10*x2[i])+(w11*x3[i])+(w12*x4[i])+(w13*x5[i])+(w14*x6[i])+(w15*x7[i])+(w16*x8[i])+b2

        if F2 > 0:
            F2 = 1
        else:
            F2 = 0
        F3 = (w17*x1[i])+(w18*x2[i])+(w19*x3[i])+(w20*x4[i])+(w21*x5[i])+(w22*x6[i])+(w23*x7[i])+(w24*x8[i])+b3
        if F3 > 0:
            F3 = 1
        else:
            F3 = 0
        F4 = (w25*x1[i])+(w26*x2[i])+(w27*x3[i])+(w38*x4[i])+(w39*x5[i])+(w30*x6[i])+(w31*x7[i])+(w32*x8[i])+b4
        if F4 > 0:
            F4 = 1
        else:
            F4 = 0
        F5 = (w33*x1[i])+(w34*x2[i])+(w35*x3[i])+(w36*x4[i])+(w47*x5[i])+(w48*x6[i])+(w49*x7[i])+(w40*x8[i])+b5
        if F5 > 0:
            F5 = 1
        else:
            F5 = 0
# =============================================================================
#             alfphabet
# =============================================================================
        F6 = (w41*F1)+(w42*F2)+(w43*F3)+(w44*F4)+(w45*F5)+b6#a
        if F6 > 0:
            F6 = 0.6931471805599453
            mot.append('a')
        else:
            F6 = 0
        F7 = (w46*F1)+(w47*F2)+(w48*F3)+(w49*F4)+(w50*F5)+b7#b
        if F7 > 0:
            F7 = 1.0986122886681098
            mot.append('b')
        else:
            F7 = 0
        F8 = (w51*F1)+(w52*F2)+(w53*F3)+(w54*F4)+(w55*F5)+b8#c
        if F8 > 0:
            F8 = 1.3862943611198906
            mot.append('c')
        else:
            F8 = 0
        F9 = (w56*F1)+(w57*F2)+(w58*F3)+(w59*F4)+(w60*F5)+b9#d
        if F9 > 0:
            F9 = 1.6094379124341003
            mot.append('d')
        else:
            F9 = 0
        F10 = (w61*F1)+(w62*F2)+(w63*F3)+(w64*F4)+(w65*F5)+b10#e
        if F10 > 0:
            F10 = 1.791759469228055
            mot.append('e')
        else:
            F10 = 0
        F11 = (w66*F1)+(w67*F2)+(w68*F3)+(w69*F4)+(w70*F5)+b11#f
        if F11 > 0:
            F11 = 1.9459101490553132
            mot.append('f')
        else:
            F11 = 0
        F12 = (w71*F1)+(w72*F2)+(w73*F3)+(w74*F4)+(w75*F5)+b12#g
        if F12 > 0:
            F12 = 2.0794415416798357
            mot.append('g')
        else:
            F12 = 0
        F13 = (w76*F1)+(w77*F2)+(w78*F3)+(w79*F4)+(w80*F5)+b13#h
        if F13 > 0:
            F13 = 2.1972245773362196
            mot.append('h')
        else:
            F13 = 0
        F14 = (w81*F1)+(w82*F2)+(w83*F3)+(w84*F4)+(w85*F5)+b14#i
        if F14 > 0:
            F14 = 2.302585092994046
            mot.append('i')
        else:
            F14 = 0
        F15 = (w86*F1)+(w87*F2)+(w88*F3)+(w89*F4)+(w90*F5)+b15#j
        if F15 > 0:
            F15 = 2.3978952727983707
            mot.append('j')
        else:
            F15 = 0
        F16 = (w91*F1)+(w92*F2)+(w93*F3)+(w94*F4)+(w95*F5)+b16#k
        if F16 > 0:
            F16 =  2.4849066497880004
            mot.append('k')
        else:
            F16 = 0
        F17 = (w96*F1)+(w97*F2)+(w98*F3)+(w99*F4)+(w100*F5)+b17#l
        if F17 > 0:
            F17 = 2.5649493574615367
            mot.append('l')
        else:
            F17 = 0
        F18 = (w101*F1)+(w102*F2)+(w103*F3)+(w104*F4)+(w105*F5)+b18#m
        if F18 > 0:
            F18 = 2.6390573296152584
            mot.append('m')
        else:
            F18 = 0
        F19 = (w106*F1)+(w107*F2)+(w108*F3)+(w109*F4)+(w110*F5)+b19#n
        if F19 > 0:
            F19 = 2.70805020110221
            mot.append('n')
        else:
            F19 = 0
        F20 = (w111*F1)+(w112*F2)+(w113*F3)+(w114*F4)+(w115*F5)+b20#o
        if F20 > 0:
            F20 = 2.772588722239781
            mot.append('o')
        else:
            F20 = 0
        F21 = (w116*F1)+(w117*F2)+(w118*F3)+(w119*F4)+(w120*F5)+b21#p
        if F21 > 0:
            F21 = 2.833213344056216
            mot.append('p')
        else:
            F21 = 0
        F22 = (w121*F1)+(w122*F2)+(w123*F3)+(w124*F4)+(w125*F5)+b22#q
        if F22 > 0:
            F22 = 2.8903717578961645
            mot.append('q')
        else:
            F22 = 0
        F23 = (w126*F1)+(w127*F2)+(w128*F3)+(w129*F4)+(w130*F5)+b23#r
        if F23 > 0:
            F23 = 2.9444389791664403
            mot.append('r')
        else:
            F23 = 0
        F24 = (w131*F1)+(w132*F2)+(w133*F3)+(w134*F4)+(w135*F5)+b24#s
        if F24 > 0:
            F24 = 2.995732273553991
            mot.append('s')
        else:
            F24 = 0
        F25 = (w136*F1)+(w137*F2)+(w138*F3)+(w139*F4)+(w140*F5)+b25#t
        if F25 > 0:
            F25 = 3.044522437723423
            mot.append('t')
        else:
            F25 = 0
        F26 = (w141*F1)+(w142*F2)+(w143*F3)+(w144*F4)+(w145*F5)+b26#u
        if F26 > 0:
            F26 = 3.091042453358316
            mot.append('u')
        else:
            F26 = 0
        F27 = (w146*F1)+(w147*F2)+(w148*F3)+(w149*F4)+(w150*F5)+b27#v
        if F27 > 0:
            F27 = 3.1354942159291497
            mot.append('v')
        else:
            F27 = 0
        F28 = (w151*F1)+(w152*F2)+(w153*F3)+(w154*F4)+(w155*F5)+b28#w
        if F28 > 0:
            F28 = 3.1780538303479458
            mot.append('w')
        else:
            F28 = 0
        F29 = (w156*F1)+(w157*F2)+(w158*F3)+(w159*F4)+(w160*F5)+b29#x
        if F29 > 0:
            F29 = 3.2188758248682006
            mot.append('x')
        else:
            F29 = 0
        F30 = (w161*F1)+(w162*F2)+(w163*F3)+(w164*F4)+(w165*F5)+b30#y
        if F30 > 0:
            F30 = 3.258096538021482
            mot.append('y')
        else:
            F30 = 0
        F31 = (w166*F1)+(w167*F2)+(w168*F3)+(w169*F4)+(w170*F5)+b31#z
        if F31 > 0:
            F31 = 3.295836866004329
            mot.append('z')
        else:
            F31 = 0
        F32 = (w171*F1)+(w172*F2)+(w173*F3)+(w174*F4)+(w175*F5)+b32#
        if F31 > 0:
            F31 = 3.332204510175204
            mot.append(' ')
        else:
            F31 = 0
        
        y = F6+F7+F8+F9+F10+F11+F12+F13+F14+F15+F16+F17+F18+F19+F20+F21+F22+F23+F24+F25+F26+F27+F28+F29+F30+F31+F32
# =============================================================================
#             y = frase
# =============================================================================
        import math as mt
        
        alphabet = [('a',1), ('b',2), ('c',3), ('d',4), ('e',5), ('f',6), ('g',7), ('h',8), ('i',9), ('j',10), ('k',11), ('l',12), ('m',13), ('n',14), ('o',15), ('p',16), ('q',17), ('r',18), ('s',19), ('t',20), ('u',21), ('v',22), ('w',23), ('x',24), ('y',25), ('z',26),(' ',27)]
        X = ['x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8']
        def code(T):
            XN = []
            n = 0
            for i in range(len(T)):
                E = T[i]
                for j in range(len(alphabet)):
                    A = alphabet[j]
                    if E == A[0]:
                        n = n + 1
                        CODE = mt.log(A[-1]+1)
                        x = "x"+ str(n)
                        XN.append((x, CODE))
            return XN
        mot = "".join(mot)
        N = [mot]

        T = N[-1]
        CODE = code(T)

        X_list = []
        for i in range(len(X)):
            found = False
            for j in range(len(CODE)):
                if X[i] == CODE[j][0]:
                    X_list.append(CODE[j][1])
                    found = True
                    break
            if not found:
                X_list.append(0)
        y = sum(X_list)
        erreur = (y-yT[i])
        print(erreur)
        M = len(yT)
        dW1 = (1 / M) *(erreur)*x1[i]
        dW2 = (1 / M) *(erreur)*x2[i]
        dW3 = (1 / M) *(erreur)*x3[i]
        dW4 = (1 / M) *(erreur)*x4[i]
        dW5 = (1 / M) *(erreur)*x5[i]
        dW6 = (1 / M) *(erreur)*x6[i]
        dW7 = (1 / M) *(erreur)*x7[i]
        dW8 = (1 / M) *(erreur)*x8[i]
        
        dW9 = (1 / M) *(erreur)*x1[i]
        dW10 = (1 / M) *(erreur)*x2[i]
        dW11 = (1 / M) *(erreur)*x3[i]
        dW12 = (1 / M) *(erreur)*x4[i]
        dW13 = (1 / M) *(erreur)*x5[i]
        dW14 = (1 / M) *(erreur)*x6[i]
        dW15 = (1 / M) *(erreur)*x7[i]
        dW16 = (1 / M) *(erreur)*x8[i]
        
        dW17 = (1 / M) *(erreur)*x1[i]
        dW18 = (1 / M) *(erreur)*x2[i]
        dW19 = (1 / M) *(erreur)*x3[i]
        dW20 = (1 / M) *(erreur)*x4[i]
        dW21 = (1 / M) *(erreur)*x5[i]
        dW22 = (1 / M) *(erreur)*x6[i]
        dW23 = (1 / M) *(erreur)*x7[i]
        dW24 = (1 / M) *(erreur)*x8[i]
        
        dW25 = (1 / M) *(erreur)*x1[i]
        dW26 = (1 / M) *(erreur)*x2[i]
        dW27 = (1 / M) *(erreur)*x3[i]
        dW28 = (1 / M) *(erreur)*x4[i]
        dW29 = (1 / M) *(erreur)*x5[i]
        dW30 = (1 / M) *(erreur)*x6[i]
        dW31 = (1 / M) *(erreur)*x7[i]
        dW32 = (1 / M) *(erreur)*x8[i]
        
        dW33 = (1 / M) *(erreur)*x1[i]
        dW34 = (1 / M) *(erreur)*x2[i]
        dW35 = (1 / M) *(erreur)*x3[i]
        dW36 = (1 / M) *(erreur)*x4[i]
        dW37 = (1 / M) *(erreur)*x5[i]
        dW38 = (1 / M) *(erreur)*x6[i]
        dW39 = (1 / M) *(erreur)*x7[i]
        dW40 = (1 / M) *(erreur)*x8[i]
        
        dW41 = (1 / M) *(erreur)*F1
        dW42 = (1 / M) *(erreur)*F2
        dW43 = (1 / M) *(erreur)*F3
        dW44 = (1 / M) *(erreur)*F4
        dW45 = (1 / M) *(erreur)*F5
        dW46 = (1 / M) *(erreur)*F1
        dW47 = (1 / M) *(erreur)*F2
        dW48 = (1 / M) *(erreur)*F3
        dW49 = (1 / M) *(erreur)*F4
        dW50 = (1 / M) *(erreur)*F5
        dW51 = (1 / M) *(erreur)*F1
        dW52 = (1 / M) *(erreur)*F2
        dW53 = (1 / M) *(erreur)*F3
        dW54 = (1 / M) *(erreur)*F4
        dW55 = (1 / M) *(erreur)*F5
        dW56 = (1 / M) *(erreur)*F1
        dW57 = (1 / M) *(erreur)*F2
        dW58 = (1 / M) *(erreur)*F3
        dW59 = (1 / M) *(erreur)*F4
        dW60 = (1 / M) *(erreur)*F5
        dW61 = (1 / M) *(erreur)*F1
        dW62 = (1 / M) *(erreur)*F2
        dW63 = (1 / M) *(erreur)*F3
        dW64 = (1 / M) *(erreur)*F4
        dW65 = (1 / M) *(erreur)*F5
        dW66 = (1 / M) *(erreur)*F1
        dW67 = (1 / M) *(erreur)*F2
        dW68 = (1 / M) *(erreur)*F3
        dW69 = (1 / M) *(erreur)*F4
        dW70 = (1 / M) *(erreur)*F5
        dW71 = (1 / M) *(erreur)*F1
        dW72 = (1 / M) *(erreur)*F2
        dW73 = (1 / M) *(erreur)*F3
        dW74 = (1 / M) *(erreur)*F4
        dW75 = (1 / M) *(erreur)*F5
        dW76 = (1 / M) *(erreur)*F1
        dW77 = (1 / M) *(erreur)*F2
        dW78 = (1 / M) *(erreur)*F3
        dW79 = (1 / M) *(erreur)*F4
        dW80 = (1 / M) *(erreur)*F5
        dW81 = (1 / M) *(erreur)*F1
        dW82 = (1 / M) *(erreur)*F2
        dW83 = (1 / M) *(erreur)*F3
        dW84 = (1 / M) *(erreur)*F4
        dW85 = (1 / M) *(erreur)*F5
        dW86 = (1 / M) *(erreur)*F1
        dW87 = (1 / M) *(erreur)*F2
        dW88 = (1 / M) *(erreur)*F3
        dW89 = (1 / M) *(erreur)*F4
        dW90 = (1 / M) *(erreur)*F5
        dW91 = (1 / M) *(erreur)*F1
        dW92 = (1 / M) *(erreur)*F2
        dW93 = (1 / M) *(erreur)*F3
        dW94 = (1 / M) *(erreur)*F4
        dW95 = (1 / M) *(erreur)*F5
        dW96 = (1 / M) *(erreur)*F1
        dW97 = (1 / M) *(erreur)*F2
        dW98 = (1 / M) *(erreur)*F3
        dW99 = (1 / M) *(erreur)*F4
        dW100 = (1 / M) *(erreur)*F5
        dW101 = (1 / M) *(erreur)*F1
        dW102 = (1 / M) *(erreur)*F2
        dW103 = (1 / M) *(erreur)*F3
        dW104 = (1 / M) *(erreur)*F4
        dW105 = (1 / M) *(erreur)*F5
        dW106 = (1 / M) *(erreur)*F1
        dW107 = (1 / M) *(erreur)*F2
        dW108 = (1 / M) *(erreur)*F3
        dW109 = (1 / M) *(erreur)*F4
        dW110 = (1 / M) *(erreur)*F5
        dW111 = (1 / M) *(erreur)*F1
        dW112 = (1 / M) *(erreur)*F2
        dW113 = (1 / M) *(erreur)*F3
        dW114 = (1 / M) *(erreur)*F4
        dW115 = (1 / M) *(erreur)*F5
        dW116 = (1 / M) *(erreur)*F1
        dW117 = (1 / M) *(erreur)*F2
        dW118 = (1 / M) *(erreur)*F3
        dW119 = (1 / M) *(erreur)*F4
        dW120 = (1 / M) *(erreur)*F5
        dW121 = (1 / M) *(erreur)*F1
        dW122 = (1 / M) *(erreur)*F2
        dW123 = (1 / M) *(erreur)*F3
        dW124 = (1 / M) *(erreur)*F4
        dW125 = (1 / M) *(erreur)*F5
        dW126 = (1 / M) *(erreur)*F1
        dW127 = (1 / M) *(erreur)*F2
        dW128 = (1 / M) *(erreur)*F3
        dW129 = (1 / M) *(erreur)*F4
        dW130 = (1 / M) *(erreur)*F5
        dW131 = (1 / M) *(erreur)*F1
        dW132 = (1 / M) *(erreur)*F2
        dW133 = (1 / M) *(erreur)*F3
        dW134 = (1 / M) *(erreur)*F4
        dW135 = (1 / M) *(erreur)*F5
        dW136 = (1 / M) *(erreur)*F1
        dW137 = (1 / M) *(erreur)*F2
        dW138 = (1 / M) *(erreur)*F3
        dW139 = (1 / M) *(erreur)*F4
        dW140 = (1 / M) *(erreur)*F5
        dW141 = (1 / M) *(erreur)*F1
        dW142 = (1 / M) *(erreur)*F2
        dW143 = (1 / M) *(erreur)*F3
        dW144 = (1 / M) *(erreur)*F4
        dW145 = (1 / M) *(erreur)*F5
        dW146 = (1 / M) *(erreur)*F1
        dW147 = (1 / M) *(erreur)*F2
        dW148 = (1 / M) *(erreur)*F3
        dW149 = (1 / M) *(erreur)*F4
        dW150 = (1 / M) *(erreur)*F5
        dW151 = (1 / M) *(erreur)*F1
        dW152 = (1 / M) *(erreur)*F2
        dW153 = (1 / M) *(erreur)*F3
        dW154 = (1 / M) *(erreur)*F4
        dW155 = (1 / M) *(erreur)*F5
        dW156 = (1 / M) *(erreur)*F1
        dW157 = (1 / M) *(erreur)*F2
        dW158 = (1 / M) *(erreur)*F3
        dW159 = (1 / M) *(erreur)*F4
        dW160 = (1 / M) *(erreur)*F5
        dW161 = (1 / M) *(erreur)*F1
        dW162 = (1 / M) *(erreur)*F2
        dW163 = (1 / M) *(erreur)*F3
        dW164 = (1 / M) *(erreur)*F4
        dW165 = (1 / M) *(erreur)*F5
        dW166 = (1 / M) *(erreur)*F1
        dW167 = (1 / M) *(erreur)*F2
        dW168 = (1 / M) *(erreur)*F3
        dW169 = (1 / M) *(erreur)*F4
        dW170 = (1 / M) *(erreur)*F5
        
        dW171 = (1 / M) *(erreur)*F6
        dW172 = (1 / M) *(erreur)*F7
        dW173 = (1 / M) *(erreur)*F8
        dW174 = (1 / M) *(erreur)*F9
        dW175 = (1 / M) *(erreur)*F10
        dW176 = (1 / M) *(erreur)*F11
        dW177 = (1 / M) *(erreur)*F12
        dW178 = (1 / M) *(erreur)*F13
        dW179 = (1 / M) *(erreur)*F14
        dW180 = (1 / M) *(erreur)*F15
        dW181 = (1 / M) *(erreur)*F16
        dW182 = (1 / M) *(erreur)*F17
        dW183 = (1 / M) *(erreur)*F18
        dW184 = (1 / M) *(erreur)*F19
        dW185 = (1 / M) *(erreur)*F20
        dW186 = (1 / M) *(erreur)*F21
        dW187 = (1 / M) *(erreur)*F22
        dW188 = (1 / M) *(erreur)*F23
        dW189 = (1 / M) *(erreur)*F24
        dW190 = (1 / M) *(erreur)*F25
        dW191 = (1 / M) *(erreur)*F26
        dW192 = (1 / M) *(erreur)*F27
        dW193 = (1 / M) *(erreur)*F28
        dW194 = (1 / M) *(erreur)*F29
        dW195 = (1 / M) *(erreur)*F30
        dW196 = (1 / M) *(erreur)*F31
        
        db1 = (1 / M) *(erreur)
        db2 = (1 / M) *(erreur)
        db3 = (1 / M) *(erreur)
        db4 = (1 / M) *(erreur)
        db5 = (1 / M) *(erreur)
        db6 = (1 / M) *(erreur)
        db7 = (1 / M) *(erreur)
        db8 = (1 / M) *(erreur)
        db9 = (1 / M) *(erreur)
        db10 = (1 / M) *(erreur)
        db11 = (1 / M) *(erreur)
        db12 = (1 / M) *(erreur)
        db13 = (1 / M) *(erreur)
        db14 = (1 / M) *(erreur)
        db15 = (1 / M) *(erreur)
        db16 = (1 / M) *(erreur)
        db17 = (1 / M) *(erreur)
        db18 = (1 / M) *(erreur)
        db19 = (1 / M) *(erreur)
        db20 = (1 / M) *(erreur)
        db21 = (1 / M) *(erreur)
        db22 = (1 / M) *(erreur)
        db23 = (1 / M) *(erreur)
        db24 = (1 / M) *(erreur)
        db25 = (1 / M) *(erreur)
        db26 = (1 / M) *(erreur)
        db27 = (1 / M) *(erreur)
        db28 = (1 / M) *(erreur)
        db29 = (1 / M) *(erreur)
        db30 = (1 / M) *(erreur)
        db31 = (1 / M) *(erreur)
        db32 = (1 / M) *(erreur)
        
        w1 -= learning_rate * dW1
        w2 -= learning_rate * dW2
        w3 -= learning_rate * dW3
        w4 -= learning_rate * dW4
        w5 -= learning_rate * dW5
        w6 -= learning_rate * dW6
        w7 -= learning_rate * dW7
        w8 -= learning_rate * dW8
        w9 -= learning_rate * dW9
        w10 -= learning_rate * dW10
        w11 -= learning_rate * dW11
        w12 -= learning_rate * dW12
        w13 -= learning_rate * dW13
        w14 -= learning_rate * dW14
        w15 -= learning_rate * dW15
        w16 -= learning_rate * dW16
        w17 -= learning_rate * dW17
        w18 -= learning_rate * dW18
        w19 -= learning_rate * dW19
        w20 -= learning_rate * dW20
        w21 -= learning_rate * dW21
        w22 -= learning_rate * dW22
        w23 -= learning_rate * dW23
        w24 -= learning_rate * dW24
        w25 -= learning_rate * dW25
        w26 -= learning_rate * dW26
        w27 -= learning_rate * dW27
        w28 -= learning_rate * dW28
        w29 -= learning_rate * dW29
        w30 -= learning_rate * dW30
        w31 -= learning_rate * dW31
        w32 -= learning_rate * dW32
        w33 -= learning_rate * dW33
        w34 -= learning_rate * dW34
        w35 -= learning_rate * dW35
        w36 -= learning_rate * dW36
        w37 -= learning_rate * dW37
        w38 -= learning_rate * dW38
        w39 -= learning_rate * dW39
        w40 -= learning_rate * dW40
        w41 -= learning_rate * dW41
        w42 -= learning_rate * dW42
        w43 -= learning_rate * dW43
        w44 -= learning_rate * dW44
        w45 -= learning_rate * dW45
        w46 -= learning_rate * dW46
        w47 -= learning_rate * dW47
        w48 -= learning_rate * dW48
        w49 -= learning_rate * dW49
        w50 -= learning_rate * dW50
        w51 -= learning_rate * dW51
        w52 -= learning_rate * dW52
        w53 -= learning_rate * dW53
        w54 -= learning_rate * dW54
        w55 -= learning_rate * dW55
        w56 -= learning_rate * dW56
        w57 -= learning_rate * dW57
        w58 -= learning_rate * dW58
        w59 -= learning_rate * dW59
        w60 -= learning_rate * dW60
        w61 -= learning_rate * dW61
        w62 -= learning_rate * dW62
        w63 -= learning_rate * dW63
        w64 -= learning_rate * dW64
        w65 -= learning_rate * dW65
        w66 -= learning_rate * dW66
        w67 -= learning_rate * dW67
        w68 -= learning_rate * dW68
        w69 -= learning_rate * dW69
        w70 -= learning_rate * dW70
        w71 -= learning_rate * dW71
        w72 -= learning_rate * dW72
        w73 -= learning_rate * dW73
        w74 -= learning_rate * dW74
        w75 -= learning_rate * dW75
        w76 -= learning_rate * dW76
        w77 -= learning_rate * dW77
        w78 -= learning_rate * dW78
        w79 -= learning_rate * dW79
        w80 -= learning_rate * dW80
        w81 -= learning_rate * dW81
        w82 -= learning_rate * dW82
        w83 -= learning_rate * dW83
        w84 -= learning_rate * dW84
        w85 -= learning_rate * dW85
        w86 -= learning_rate * dW86
        w87 -= learning_rate * dW87
        w88 -= learning_rate * dW88
        w89 -= learning_rate * dW89
        w90 -= learning_rate * dW90
        w91 -= learning_rate * dW91
        w92 -= learning_rate * dW92
        w93 -= learning_rate * dW93
        w94 -= learning_rate * dW94
        w95 -= learning_rate * dW95
        w96 -= learning_rate * dW96
        w97 -= learning_rate * dW97
        w98 -= learning_rate * dW98
        w99 -= learning_rate * dW99
        w100 -= learning_rate * dW100
        w101 -= learning_rate * dW101
        w102 -= learning_rate * dW102
        w103 -= learning_rate * dW103
        w104 -= learning_rate * dW104
        w105 -= learning_rate * dW105
        w106 -= learning_rate * dW106
        w107 -= learning_rate * dW107
        w108 -= learning_rate * dW108
        w109 -= learning_rate * dW109
        w110 -= learning_rate * dW110
        w111 -= learning_rate * dW111
        w112 -= learning_rate * dW112
        w113 -= learning_rate * dW113
        w114 -= learning_rate * dW114
        w115 -= learning_rate * dW115
        w116 -= learning_rate * dW116
        w117 -= learning_rate * dW117
        w118 -= learning_rate * dW118
        w119 -= learning_rate * dW119
        w120 -= learning_rate * dW120
        w121 -= learning_rate * dW121
        w122 -= learning_rate * dW122
        w123 -= learning_rate * dW123
        w124 -= learning_rate * dW124
        w125 -= learning_rate * dW125
        w126 -= learning_rate * dW126
        w127 -= learning_rate * dW127
        w128 -= learning_rate * dW128
        w129 -= learning_rate * dW129
        w130 -= learning_rate * dW130
        w131 -= learning_rate * dW131
        w132 -= learning_rate * dW132
        w133 -= learning_rate * dW133
        w134 -= learning_rate * dW134
        w135 -= learning_rate * dW135
        w136 -= learning_rate * dW136
        w137 -= learning_rate * dW137
        w138 -= learning_rate * dW138
        w139 -= learning_rate * dW139
        w140 -= learning_rate * dW140
        w141 -= learning_rate * dW141
        w142 -= learning_rate * dW142
        w143 -= learning_rate * dW143
        w144 -= learning_rate * dW144
        w145 -= learning_rate * dW145
        w146 -= learning_rate * dW146
        w147 -= learning_rate * dW147
        w148 -= learning_rate * dW148
        w149 -= learning_rate * dW149
        w150 -= learning_rate * dW150
        w151 -= learning_rate * dW151
        w152 -= learning_rate * dW152
        w153 -= learning_rate * dW153
        w154 -= learning_rate * dW154
        w155 -= learning_rate * dW155
        w156 -= learning_rate * dW156
        w157 -= learning_rate * dW157
        w158 -= learning_rate * dW158
        w159 -= learning_rate * dW159
        w160 -= learning_rate * dW160
        w161 -= learning_rate * dW151
        w162 -= learning_rate * dW162
        w163 -= learning_rate * dW163
        w164 -= learning_rate * dW164
        w165 -= learning_rate * dW165
        w166 -= learning_rate * dW166
        w167 -= learning_rate * dW167
        w168 -= learning_rate * dW168
        w169 -= learning_rate * dW169
        w170 -= learning_rate * dW170
        w171 -= learning_rate * dW171
        w172 -= learning_rate * dW172
        w173 -= learning_rate * dW173
        w174 -= learning_rate * dW174
        w175 -= learning_rate * dW175
        w176 -= learning_rate * dW176
        w117 -= learning_rate * dW177
        w178 -= learning_rate * dW178
        w179 -= learning_rate * dW179
        w180 -= learning_rate * dW180
        w181 -= learning_rate * dW181
        w182 -= learning_rate * dW182
        w183 -= learning_rate * dW183
        w184 -= learning_rate * dW184
        w185 -= learning_rate * dW185
        w186 -= learning_rate * dW186
        w187 -= learning_rate * dW187
        w188 -= learning_rate * dW188
        w189 -= learning_rate * dW189
        w190 -= learning_rate * dW190
        w191 -= learning_rate * dW191
        w192 -= learning_rate * dW192
        w193 -= learning_rate * dW193
        w194 -= learning_rate * dW194
        w195 -= learning_rate * dW195
        w196 -= learning_rate * dW196
        
        
        b1 -= learning_rate * db1 
        b2 -= learning_rate * db2
        b3 -= learning_rate * db3
        b4 -= learning_rate * db4
        b5 -= learning_rate * db5 
        b6 -= learning_rate * db6
        b7 -= learning_rate * db7
        b8 -=  learning_rate * db8
        b9 -=  learning_rate * db9 
        b10 -= learning_rate * db10
        b11 -= learning_rate * db11 
        b12 -= learning_rate * db12
        b13 -= learning_rate * db13
        b14 -= learning_rate * db14
        b15 -= learning_rate * db15 
        b16 -= learning_rate * db16
        b17 -= learning_rate * db17
        b18 -= learning_rate * db18
        b19 -= learning_rate * db19 
        b20 -= learning_rate * db20 
        b21 -= learning_rate * db21
        b22 -= learning_rate * db22 
        b23 -= learning_rate * db23
        b24 -= learning_rate * db24
        b25 -= learning_rate * db25
        b26 -= learning_rate * db26 
        b27 -= learning_rate * db27
        b28 -= learning_rate * db28
        b29 -= learning_rate * db29
        b30 -= learning_rate * db30 
        b31 -= learning_rate * db31 
        b32 -= learning_rate * db32
        if y == yT[i]:
            R.append(y)
        P = (len(R)/len(yT))*100
# =============================================================================
# No more entry
# ============================================================================
print("fini ",P,"%")
mot = "".join(mot)
N = [mot]
print(N[-1])
 
Joined
Sep 4, 2022
Messages
125
Reaction score
16
hello,

you are lucky, you can optimize your code for more than 250 lines.

write few 'functions', use Arrays.

and for your question, do you have a 'feedback' with more informations ?
 
Joined
Dec 10, 2022
Messages
72
Reaction score
22
Here is a way to shorten some of the code a little

Python:
from random import randint
from string import ascii_lowercase

letters = ascii_lowercase

# This will change 232 lines to two
def rnd_num():
    return randint(0,200)-200/100

# My opinion a little easier
alphabet = [(letter, number+1) for number, letter in enumerate(letters)]


# Use
for i in range(5):
    print(rnd_num())

print(alphabet)

Output
Code:
157.0
16.0
148.0
42.0
96.0
[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5), ('f', 6), ('g', 7), ('h', 8), ('i', 9), ('j', 10), ('k', 11), ('l', 12), ('m', 13), ('n', 14), ('o', 15), ('p', 16), ('q', 17), ('r', 18), ('s',
19), ('t', 20), ('u', 21), ('v', 22), ('w', 23), ('x', 24), ('y', 25), ('z', 26)]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,707
Messages
2,569,343
Members
44,635
Latest member
Matt231

Latest Threads

Top