Note that there are some explanatory texts on larger screens.

plurals
  1. POcreating a train perceptron in MATLAB for gender clasiffication
    primarykey
    data
    text
    <p>I am coding a perceptron to learn to categorize gender in pictures of faces. I am very very new to MATLAB, so I need a lot of help. I have a few questions:</p> <ol> <li><p>I am trying to code for a function:</p> <pre><code>function [y] = testset(x,w) %y = sign(sigma(x*w-threshold)) </code></pre> <p>where y is the predicted results, x is the training/testing set put in as a very large matrix, and w is weight on the equation. The part after the <code>%</code> is what I am trying to write, but I do not know how to write this in MATLAB code. Any ideas out there?</p></li> <li><p>I am trying to code a second function: </p> <pre><code>function [err] = testerror(x,w,y) %err = sigma(max(0,-w*x*y)) </code></pre> <p>w, x, and y have the same values as stated above, and err is my function of error, which I am trying to minimize through the steps of the perceptron.</p></li> <li><p>I am trying to create a step in my perceptron to lower the percent of error by using gradient descent on my original equation. Does anyone know how I can increment w using gradient descent in order to minimize the error function using an if then statement?</p></li> </ol> <p>I can put up the code I have up till now if that would help you answer these questions.</p> <p>Thank you!</p> <p>edit-------------------------- </p> <p>OK, so I am still working on the code for this, and would like to put it up when I have something more complete. My biggest question right now is: </p> <p>I have the following function: </p> <pre><code>function [y] = testset(x,w) y = sign(sum(x*w-threshold)) </code></pre> <p>Now I know that I am supposed to put a threshold in, but cannot figure out what I am supposed to put in as the threshold! any ideas out there?</p> <p>edit----------------------------<br> this is what I have so far. Changes still need to be made to it, but I would appreciate input, especially regarding structure, and advice for making the changes that need to be made!</p> <pre><code>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) &gt; 0.1 &amp;&amp; loopcounter &lt; 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 &gt; 0 %wrong (structure is correct, test is wrong) w(j) = w(j) - 0.1 %wrong elseif err &lt; 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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload