tongqingliu

保持学习的态度

ADALINE小demo

线性逼近

clear;clc;close all
x = [1,0.5;
    1.5,1.1;
    3,3;
    -1.2,-1];
y = x(:,2);
x = [ones(size(x,1),1),x(:,1)];

w0 = [0.2;1];
ita = 0.1;
tol = 0.608; % ??人为设定的……
err = inf;
k = 0;
while err > tol & k<20
    k = k+1;
    i = mod(k,4)+1;
    w = w0+ita*(y(i,:)-x(i,:)*w0);
    err = norm(y-x*w);
    w0 = w;
end
k
err

yy = x*w;
figure;
plot(x(:,2),y,'o')
hold on
plot(x(:,2),yy,'*-')

posted on 2017-03-13 17:43  tongqingliu  阅读(133)  评论(0编辑  收藏  举报

导航