Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我回顾了多伦多 Perceptron MATLAB代码中的代码
该代码是 function [w] = perceptron(X,Y,w_init) w = w_init; for iteration = 1 : 100 % mtimes Inner matrix dimensions must agree. Error in ==> perceptron at 15 if sign(w'*X(:,ii)) ~= Y(ii) Result = perceptron( X, Y, w' ) ??? Error using ==> ne Matrix dimensions must agree. Error in ==> perceptron at 19 sum(sign(w'*X)~=Y) / size(X,2); 谢谢 谢谢您的回答,我又得到了一个答案,如果我更改Y = [0,1],该算法会发生什么? 那么,任何这样的感知器代码对Y = [0,1]的输入数据都无效吗? - - - - - - - - - - - - - - -编辑 - - - - - - - - - - ---- 还有一个问题,如果我想绘制划分两类的线 ,我知道我们可以得到与权重有关的线性方程组求解线,但是我该怎么办?喜欢 % the initial weights w_init = [ 1 1 1]'; % the weights returned from perceptron wtag = perceptron(X,Y,w_init,15); % concatenate both Line = [wtag,w_init] % solve the linear system, am I correct doing this? rref(Line') % plot??? 回答: 您首先应该了解每个输入的含义:
X=[0 0; 0 1; 1 1]; Y=[1 -1]; w=[.5; .5; .5]; 编辑 使用以下代码调用感知器算法,并以图形方式查看结果: % input samples X1=[rand(1,100);rand(1,100);ones(1,100)]; % class '+1' X2=[rand(1,100);1+rand(1,100);ones(1,100)]; % class '-1' X=[X1,X2]; % output class [-1,+1]; Y=[-ones(1,100),ones(1,100)]; % init weigth vector w=[.5 .5 .5]'; % call perceptron wtag=perceptron(X,Y,w); % predict ytag=wtag'*X; % plot prediction over origianl data figure;hold on plot(X1(1,:),X1(2,:),'b.') plot(X2(1,:),X2(2,:),'r.') plot(X(1,ytag0),'ro') legend('class -1','class +1','pred -1','pred +1') 更多&回答... |
![]() |
![]() |