Bonjour à tous,

je suis en train d'écrire un programme sur Scilab pour créer un réseau de neurones. Le but est de faire retrouver au réseau la fonction f(x;y)=x²*y.

Mon problème est que durant la phase d'apprentissage l'erreur ne converge pas.

Nom : Figure n°2.png
Affichages : 609
Taille : 8,2 Ko

J'ai revérifié le programme et je ne comprends pas pourquoi ça ne marche pas.

Peut-être que l'un d'entre vous saura trouver le problème. Voici le code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
clear
clc
 
// Chargement de la base de donnée
 
[fd,SST,Sheetnames,Sheetpos] = xls_open('C:\Users\personne\Desktop\Indicateurs de confort\Algo\Base de données TEST2.xls')
//Read first data sheet
[Value,TextInd] = xls_read(fd,Sheetpos(1))
//close the spreadsheet stream
mclose(fd)
 
A=Value(2:201,3:4)
A1=A'
B=Value(2:201,7)
B1=B'
 
// Création des variables 
 
n=3 // nb de couches
j=2 // variables en entrée
k=2 // nb neurones sur la couche suivante
i=2
 
///////////////////////////////////////////////////////////////////////////////////
 
Wi(:,:,1)=2.4/j*(2*rand(j,i)-ones(j,i)) // Couche 1
for l=2:n-1
    Wi(:,:,l)=2.4/i*(2*rand(i,k)-ones(i,k)) // Couche 2 jusqu'à n-1
end
Wi(:,1,n)=2.4/k*(2*rand(k,1)-ones(k,1)) // Couche n
 
///////////////////////////////////////////////////////////////////////////////////
 
function Y=prodscalaire(Wi,Xie,n)
 
[i,k] = size(Wi)
//disp(i)
//disp(k)
[a,b]=size(Xie)
//disp(a)
//disp(b)
if a<k then
    for m=1:k-a
    Xie(a+m,1)=0
    end
end
//disp(Xie)
//disp(Wi(:,:,n))
for p=1:i
    for m=1:k
        P(p,m)=Wi(p,m,n)*Xie(p,1)
    end
end
 
Y1=sum(P,1)
 
for h=1:k
Y(h,1,n)=Y1(1,h)
end
 
endfunction
 
///////////////////////////////////////////////////////////////////////////////////
 
function O=sigmoide(Y,n)
    [i,b]=size(Y)
    for k=1:i
        O(k,1,n)=1/(1+exp(-1*Y(k,1,n)))
    end
endfunction
 
///////////////////////////////////////////////////////////////////////////////////
 
function d=delta(O,Wi,d1,n)
 
    [a,b]=size(Wi)
 
    for m=1:a
        for h=1:b
            Wi1(h,m,n)=Wi(m,h,n)
        end
    end
 
    S=prodscalaire(Wi1,d1,n)
 
    for k=1:i
        d(k,1,n)=O(k,1,n)*(1-O(k,1,n))*S(k,1,n)
    end
 
endfunction
 
///////////////////////////////////////////////////////////////////////////////////
 
function [Wi1,D0]=poids(d,Xie,D1,Wi,n,u,E)
 
    [x,y]=size(d)
    [z,w]=size(Xie)
 
    for m=1:x
        for h=1:z
            D0(h,m,n)=E*Xie(h,1,n)*d(m,1)+u*D1(h,m,n)
        end
    end
 
    for m=1:x
        for h=1:z
            Wi1(h,m,n)=Wi(h,m,n)+D0(h,m,n)
        end
    end
 
endfunction
 
///////////////////////////////////////////////////////////////////////////////////
 
function [S,Xie]=calcul(s)
 
    // couche 1 jusqu'à n-1
 
    Xie(:,1,1)=A1(:,s) // Initialisation
//disp(Wi)
//disp(Xie)
    Y=prodscalaire(Wi,Xie,1)
    O=sigmoide(Y,1)
//disp(Xie)
//disp(O)
    [a,b]=size(O)
 
    for m=1:a
    Xie(m,1,2)=O(m,1,1)
    end
 
    for l=2:n-1
        Y=prodscalaire(Wi,Xie,l)
        O=sigmoide(Y,l)
 
        Xie(:,1,l+1)=O(:,1,l)
    end
 
    // couche n
 
    Y=prodscalaire(Wi,Xie,n)
    O=sigmoide(Y,n)
 
    S=O(1,1,n)
 
endfunction
 
///////////////////////////////////////////////////////////////////////////////////
 
function [T,Wi]=apprentissage(Wi,n,i,E,u)
 
    // Chargement de la base de donnée
 
    [fd,SST,Sheetnames,Sheetpos] = xls_open('C:\Users\personne\Desktop\Indicateurs de confort\Algo\Base de données TEST2.xls')
    //Read first data sheet
    [Value,TextInd] = xls_read(fd,Sheetpos(1))
    //close the spreadsheet stream
    mclose(fd)
 
    A=Value(2:201,3:4)
    A1=A'
    B=Value(2:201,7)
    B1=B'
 
    // Initialisation 
 
    j=2
    i=k
 
//    E=0.8
//    u=0.95
 
//    Wi(:,:,1)=2.4/j*(2*rand(j,i)-ones(j,i)) // Couche 1
//    for l=2:n-1
//        Wi(:,:,l)=2.4/i*(2*rand(i,k)-ones(i,k)) // Couche 2 jusqu'à n-1
//    end
//    Wi(:,1,n)=2.4/k*(2*rand(k,1)-ones(k,1)) // Couche n
 
    D1(:,:,1)=zeros(j,i)
    D1(1:i,1:k,2:n-1)=zeros(i,k)
    D1(:,1,n)=zeros(i,1)
 
    for s=1:200
 
        // Calcul de l'erreur
 
        C=B1(:,s)
        [S,Xie]=calcul(s)
 
        for l=2:n
        O(:,:,l)=Xie(:,:,l-1)
        end
 
        // couche n
 
        e=(C-S) // delta en sortie
        T(s)=e
 
        [Wi1,D0]=poids(e,Xie,D1,Wi,n,u,E)
        Wi(:,1,n)=Wi1(:,1,n)
        D1(:,1,n)=D0(:,1,n)
 
        // couches de n-1 à 1
 
        d=delta(O,Wi,e,n)
        d1=d(:,1,n)
 
        for l=n-1:2
 
            [Wi2,D0]=poids(d1,Xie,D1,Wi,l,u,E)
            Wi(:,:,l)=Wi2(:,:,l)
            D1(:,:,l)=D0(:,:,l)
            d=delta(O,Wi,d1,l)
            d1=d(:,:,l)
 
        end
 
        // couche 1
 
        [Wi3,D0]=poids(d1,Xie,D1,Wi,1,u,E)
        Wi(:,:,1)=Wi3(:,:,1)
        D1(:,:,1)=D0(:,:,1)
 
        //if e(s)<0.0001
        //    break
        //end
 
    end
 
//    R=[1:1:s]
 
//    figure(0)
//    plot(R,T)
 
endfunction
 
///////////////////////////////////////////////////////////////////////////////////
 
function []=principal()
 
    n=3
    i=6
    k=i
    E=0.2
    u=0.96
 
    Wi(:,:,1)=0.01*(2*rand(j,i)-ones(j,i)) // Couche 1
//    disp(Wi(:,:,1))
    for l=2:n-1
        Wi(1:i,1:k,l)=0.01*(2*rand(i,k)-ones(i,k)) // Couche 2 jusqu'à n-1
    end
 
    Wi(:,1,n)=0.01/k*(2*rand(k,1)-ones(k,1)) // Couche n
 
//    Wi(:,:,1)=2.4/j*(2*rand(j,i)-ones(j,i)) // Couche 1
////    disp(Wi(:,:,1))
//    for l=2:n-1
//        Wi(1:i,1:k,l)=2.4/i*(2*rand(i,k)-ones(i,k)) // Couche 2 jusqu'à n-1
//    end
//    
//    Wi(:,1,n)=2.4/k*(2*rand(k,1)-ones(k,1)) // Couche n
////    disp(Wi)
    e=1
 
    while e>0.0001
    //for a=1:10
 
        [T,Wi]=apprentissage(Wi,n,i,E,u)
        Wi1=Wi
        [T,Wi]=apprentissage(Wi1,n,i,E,u)
 
        e=T(200)
        disp(Wi)
    end
 
    R=[1:1:200]
 
    figure(0)
    plot(R,T)
 
endfunction
 
principal()