Matlab保持忙碌,乘以矩阵

时间:2015-03-22 18:01:18

标签: matlab neural-network

我的代码有问题。我不得不写一个人工神经网络的反向传播。几乎每次运行代码时,Matlab都会保持忙碌,我认为它是关于矩阵乘法的,尽管它们不是很大。知道如何解决这个问题吗?

close all;clear all;clc;
w1 = rand()*5;
w2 = rand()*5;
w3 = rand()*5;
w4=rand()*5;
w5=rand()*5;
w6=rand()*5;
w7=rand()*5;
w8=rand()*5;
w11 = w1;
w21 = w2;
w31 = w3;
w41=w4;
w51=w5;
w61=w6;
w71=w7;
w81=w8;
m = [0 0 1;
1 0 1;
0 1 1;
1 1 1];

d = [0 1 1 0];

n=0.1;
e=1;
beta=1;
s=0;
s1=0;
s2=0;
licznik = 0;

while e > 0.2

licznik=licznik+1;

for k=1:4
    s1=m(k,1)*w1 + m(k,2)*w2 + w3;
    s2=m(k,1)*w4+m(k,2)*w5+w6;
    s1=1/(1+exp(-s1));
    s2=1/(1+exp(-s2));
    s=s1*w7+s2*w8;
    s=1/(1+exp(-s));
    E(k)=(s-d(k))*(s-d(k));

    if(k==4)
        e=0.5*sum(E(:));
    end

    w7=w7-n*(s-d(k))*beta*s*(1-s)*s1;
    w8=w8-n*(s-d(k))*beta*s*(1-s)*s2;

    w1=w1-n*(s-d(k))*beta*s*(1-s)*beta*s1*(1-s1)*m(k,1)*w7;
    w2=w2-n*(s-d(k))*beta*s*(1-s)*beta*s1*(1-s1)*m(k,2)*w7;
    w3=w3-n*(s-d(k))*beta*s*(1-s)*beta*s1*(1-s1)*m(k,3)*w7;

    w4=w4-n*(s-d(k))*beta*s*(1-s)*beta*s2*(1-s2)*m(k,1)*w8;
    w5=w5-n*(s-d(k))*beta*s*(1-s)*beta*s2*(1-s2)*m(k,2)*w8;
    w6=w6-n*(s-d(k))*beta*s*(1-s)*beta*s2*(1-s2)*m(k,3)*w8;

    end

    end


    licznik


     for k=1:4
     sp1(k)=m(k,1)*w1 + m(k,2)*w2 + w3;
     sp2(k)=m(k,1)*w4 + m(k,2)*w5 + w6;
     sp1(k)=1/(1+exp(-sp1(k)));
     sp2(k)=1/(1+exp(-sp2(k)));
     sp(k)=sp1(k)*w7+sp2(k)*w8;
     sp(k)=1/(1+exp(-sp(k)));
     sp(k)
     end

0 个答案:

没有答案