![]() |
在MATLAB中创建训练感知器以进行性别识别
我正在编码一个感知器,以学习对面部图片中的性别进行分类。我对MATLAB非常陌生,因此我需要很多帮助。我有几个问题:
[LIST=1][*]我正在尝试为功能编写代码: function [y] = testset(x,w) %y = sign(sigma(x*w-threshold)) 其中y是预测结果,x是作为非常大的矩阵放入的训练/测试集,w是方程式的权重。 %之后的部分是我要编写的内容,但是我不知道如何在MATLAB代码中编写此内容。有什么想法吗? [*]我正在尝试编写第二个函数: function [err] = testerror(x,w,y) %err = sigma(max(0,-w*x*y)) w,x和y具有与上述相同的值,而err是我的误差函数,我正在尝试通过感知器的步骤将其最小化。 [*]我正在尝试在感知器中创建一个台阶,以通过对原始方程式使用梯度下降来降低误差百分比。有谁知道我该如何使用梯度下降来递增w,以便使用if then语句使误差函数最小化? [/LIST]如果可以帮助您回答这些问题,我可以提供到目前为止的代码。 谢谢! 编辑 - - - - - - - - - - - - - 好的,因此我仍在为此编写代码,并希望在我有更完整的内容后再提出。我现在最大的问题是: 我有以下功能: 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 [B]回答:[/B] 您可以阅读我前一段时间做的这个[URL="https://stackoverflow.com/questions/4882367/implementing-and-ploting-a-perceptron-in-matlab"]问题[/URL] 。 我使用Matlab代码和功能感知器 function [w] = perceptron(X,Y,w_init) w = w_init; for iteration = 1 : 100 % |
所有时间均为北京时间。现在的时间是 23:31。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.