preception_m

来源:互联网 发布:java就业培训教程豆瓣 编辑:程序博客网 时间:2024/06/07 02:17

 

function [W b e] = perceptron(P,T,repeat)
switch nargin
    case 0
    case 1
        error('Please input P and T');
    case 2
        repeat = 10000;
end

for i=1:n
    [r i] = size(P,i);

s = size(T,1);
W = ones(s,r);
b = ones(s,1);
e = ones(s,n);
for i=1:repeat
    index = mod(i,n)
    if(index==0)
        index = 4;
    end
    p = P(:,index);
    t = T(:,index);
    a = W*p+b;
    for j=1:a
        if a(j)>=0
            a(j) = 1;
        else
            a(j) = 0;
        end
    end
    %e:s by n
    e(:,index) = (t-a)*0.5;
    W = W+e(:,index)*p';
    b = b+e(:,index);
    if(e==0)
        break;
    end
end
end

原创粉丝点击