Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我正在编码一个感知器,以学习对面部图片中的性别进行分类。我对MATLAB非常陌生,因此我需要很多帮助。我有几个问题:
谢谢! 编辑 - - - - - - - - - - - - - 好的,因此我仍在为此编写代码,并希望在我有更完整的内容后再提出。我现在最大的问题是: 我有以下功能: function [y] = testset(x,w) y = sign(sum(x*w-threshold)) 现在,我知道应该设定一个阈值,但无法弄清楚应该设定的阈值!有什么想法吗? 编辑 - - - - - - - - - - - - - - 这是我到目前为止所拥有的。仍然需要对其进行更改,但是我将不胜感激,尤其是在结构方面的意见,以及提出需要进行更改的建议! function [y] = Perceptron_Aviva(X,w) y = sign(sum(X*w-1)); end function [err] = testerror(X,w,y) err = sum(max(0,-w*X*y)); end %function [w] = perceptron(X,Y,w_init) %w = w_init; %end %------------------------------ % input samples X = X_train; % output class [-1,+1]; Y = y_train; % init weigth vector w_init = zeros(size(X,1)); w = w_init; %--------------------------------------------- loopcounter = 0 while abs(err) > 0.1 && loopcounter < 100 for j=1:size(X,1) approx_y(j) = Perceptron_Aviva(X(j),w(j)) err = testerror(X(j),w(j),approx_y(j)) if err > 0 %wrong (structure is correct, test is wrong) w(j) = w(j) - 0.1 %wrong elseif err < 0 %wrong w(j) = w(j) + 0.1 %wrong end % ----------- % if sign(w'*X(:,j)) ~= Y(j) %wrong decision? % w = w + X(:,j) * Y(j); %then add (or subtract) this point to w end 回答: 您可以阅读我前一段时间做的这个问题 。 我使用Matlab代码和功能感知器 function [w] = perceptron(X,Y,w_init) w = w_init; for iteration = 1 : 100 % |
![]() |
![]() |