Little Red Riding Hood
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% aqui se entrena al perceptron
global W1;
global W2;
set(handles.edit3,'String','Procesando');
coefApre = rand;
input = [ 1, 1, 1, 0, 0, 0;
1, 0, 0, 1, 0, 1;
0, 0, 1, 0, 1, 1];
output = [1, 1, 1, 0, 0, 0, 0;
0, 0, 0, 1, 1, 0, 1;
0, 0, 0, 1, 0, 1, 1];
out1 = [0, 0, 0, 0, 0, 0, 0];
out2 = [0, 0, 0, 0, 0, 0, 0];
E = [0, 0, 0, 0, 0, 0, 0];
A = [0, 0, 0, 0, 0, 0, 0];
W1 = rand(6,7);
W2 = rand(7);
error = 1;
while error > 0.08%cada ciclo es una etapa
error = 0;
for e =1:1:3% cada ciclo es el calculo de una entrada
%calcula salidas de capa oculta
for i = 1:1:7
in = input(e,:) * W1(:,i);
out1(i) = 1 / (1 + exp(-1*in));
end
%calcula salida de utlima capa
for i = 1:1:7
in = out1 * W2(:,i);
out2(i) = 1 / (1 + exp(-1*in));
end
%AJUSTE DE PESOS
%pesos de la ultima capa
for i = 1:1:7
E(i) = output(e,i) - out2(i); %error
end
errorSuma = 0;
for i = 1:1:7
errorSuma = errorSuma + abs(E(i)); %error
end
if error < errorSuma;
error = errorSuma;
end
for i = 1:1:7
A(i) = E(i) * out2(i) * (1 - out2(i)); %calculo de retropropagacion
for j = 1:1:7
W2(j,i) = W2(j,i) + (coefApre * out1(j) * A(i));
end
end
%pesos para la capa oculta
for i = 1:1:7
delta = 0;
for k = 1:1:7
delta = delta + W2(k,i)*A(k);
end
delta = out1(i) * (1 - out1(i)) * (delta); %calculo de retropropagacion
for j = 1:1:6
W1(j,i) = W1(j,i) + (coefApre * input(e,j) * delta);
end
end
end
end
set(handles.edit3,'String','Finalizo Entrenamiento');Last updated