Maldonado
Redes Neuronales
Artificiales
Práctica 2 Práctica 2
EL PERCEPTRON MULTICAPA
Desarrollo
REPORTE
CODIGO
clear all;
clc;
f_1 (1:400) = 0 ;
x_1 = f_1 ;
y_1 = x_1 ;
f1_1 (1:400) = 0 ;
x1_1 = f_1 ;
y1_1 = x_1 ;
x = 0 : 0.1*pi : 1.9*pi ;
y = 0 : 0.1*pi : 1.9*pi ;
x1 = 0 : 0.2*pi : 1.8*pi ;
y1 = 0 : 0.2*pi : 1.8*pi ;
for s=1:1:20
for s1=1:1:20
f(s,s1) = cos(x(s))-3.*sin(y(s1));
h = 20*(s-1) + s1;
x_1 (h)= x(s1);
y_1 (h)= y(s);
f_1 (h)= f(s,s1);
hold on
end
end
for s=1:1:10
for s1=1:1:10
f1(s,s1) = cos(x1(s))-3.*sin(y1(s1));
h= 10*(s-1) + s1;
x1_1 (h)= x1(s1);
y1_1 (h)= y1(s);
f1_1 (h)= f1(s,s1);
hold on
end
end
net=newff(minmax([x_1;y_1]),[7,7,7,1],{'tansig','tansig','tansig','purelin'
},'traingd');
net.trainParam.epochs = 2000;
net.trainParam.goal=1e-4;
[net,tr]=train(net,[x_1;y_1],f_1);
Y=sim(net,[x_1;y_1]);
Y1=sim(net,[x1_1;y1_1]);
figure
plot3(x_1,y_1,Y,'ro')
hold on
mesh(x,y,f)
figure
plot3(x1_1,y1_1,Y1,'ko')
hold on
mesh(x1,y1,f1)
VENTANA DE ENTRENAMIENTO
GRAFICA DE LA FUNCIÓN REAL CONTRA EL ENTRENAMIENTO
>> net.b{1}
ans =
-8.6115
-6.8972
6.3613
3.2058
-2.1491
2.3403
2.6844
VECTOR DE PESOS
>> net.IW{1}
ans =
1.2606 0.8418
2.0274 0.4762
-1.2112 -0.2038
-0.3384 -1.4042
-0.4898 0.9913
-1.5553 -0.6913
1.0139 -0.6300
>> net.IW
ans =
[7x2 double]
[]
[]
[]
Si obervamos la ventana del entrenamiento de red, notaremos que se agotaron las iteraciones
antes de alcanzar el error deseado. Podemos notar esto al observar en la gráfica anterior que
existen pequeñas discrepancias entre los valores arrojados por la red (círculos negros) y los
valores reales esperados (malla).
CODIGO
clear all;
clc;
f_1 (1:400) = 0 ;
x_1 = f_1 ;
y_1 = x_1 ;
f1_1 (1:400) = 0 ;
x1_1 = f_1 ;
y1_1 = x_1 ;
x = 0 : 0.1*pi : 1.9*pi ;
y = 0 : 0.1*pi : 1.9*pi ;
x1 = 0 : 0.2*pi : 1.8*pi ;
y1 = 0 : 0.2*pi : 1.8*pi ;
for s=1:1:20
for s1=1:1:20
f(s,s1) = cos(x(s))-3.*sin(y(s1));
h = 20*(s-1) + s1;
x_1 (h)= x(s1);
y_1 (h)= y(s);
f_1 (h)= f(s,s1);
hold on
end
end
for s=1:1:10
for s1=1:1:10
f1(s,s1) = cos(x1(s))-3.*sin(y1(s1));
h= 10*(s-1) + s1;
x1_1 (h)= x1(s1);
y1_1 (h)= y1(s);
f1_1 (h)= f1(s,s1);
hold on
end
end
net=newff(minmax([x_1;y_1]),[7,7,7,1],{'tansig','tansig','tansig','purelin'
},'trainlm');
net.trainParam.epochs = 2000;
net.trainParam.goal=1e-4;
[net,tr]=train(net,[x_1;y_1],f_1);
Y=sim(net,[x_1;y_1]);
Y1=sim(net,[x1_1;y1_1]);
figure
plot3(x_1,y_1,Y,'ro')
hold on
mesh(x,y,f)
figure
plot3(x1_1,y1_1,Y1,'ko')
hold on
mesh(x1,y1,f1)
VENTANA DE ENTRENAMIENTO
GRAFICA DE LA FUNCIÓN REAL CONTRA EL ENTRENAMIENTO
BIAS
>> net.b{1}
ans =
5.2519
-0.6889
-4.9063
0.6297
-1.2405
0.0741
-1.8155
VECTOR DE PESOS
>> net.IW{1}
ans =
-0.8813 -0.0458
-0.0225 -1.1113
-0.0017 0.9992
0.2070 -0.5231
0.5173 -0.0631
0.3298 -0.0205
0.0360 0.5094
>> net.IW
ans =
[7x2 double]
[]
[]
[]
OBSERVACIONES
El entrenamiento Levenberg-Marquardt fue mucho más rápido que el de tipo gradiente. Al
comparar las gráficas del error podemos observar claramente que el decaimiento es mucho
más abrupto.
La gráfica del error medio cuadrático podemos observamos que los valores deseados y los
arrojados por la red son prácticamente los mismo.
1. Conclusiones y observaciones.