Question:

I have also got the following code .... for the sigmoid function but it just gives a single spike at the very front of the 3d graph:

Answer:

The problem is that you should use y = 1./(1+exp(-a)); instead of y = (1/(1+exp(-a)));
The difference between ./ (element-wise division) and / (matrix division) is explained in the on-line help.
type help rdivide and help mrdivide for details.


Question:

There's a part in lab sheet 1 which says "Try to set the parameters of the single neuron by hand to classify the data", data being the sample of ballet dancers and rugby players. I understood this as meaning that I should modify the the weights and bias of the neuron so that given 1 set of data, passing this through the neuron and then through the threshing function should give a different answer to when done for the other set of data. I used the 'sign' threshing function, passing the Ballet dancers data through the neuron & 'sign' I got an output of '-1', passing the Rugby players through the neuron and 'sign' I got output '1'. This I assume is good. The thing I am not sure how to do is to actually use this info to plot a line through the plot of ballet dancers and rugby players, I tried a way based on the lecture notes, but it didn't seem to work at all.

A. OK, what you can do is either plot a 3d figure using the mesh or surf commands,then using 'hold' plot the data using plot3() - assigning -1 to the rugby players, and 1 to the ballet dancers , or if you prefer, you could use a 2d plot, and the 'contour' command which would give you a line (or lines, depending on how you call it) through the data which reflected the change in network response.. An example 3D plot in eps-format


Question:

Rod, I'm working through the NC4 lab, and I'm at the stage of coming up with example weights and offsets to simulate AND, OR and NOT functions. I've probably missed the point, but, are we supposed to use on the sign(a) function along with the a = w0 + X*W' and simply decide on the values to go into W and w0 such that the result from sign(a) is 0 or 1 as appropriate, or use other functions as well?

A. you can take the simple option you describe, setting weights by hand, and using sign(a). Note that sign(a) will give -1 for anything less than 0, but 0 for 0, and 1 for inputs > 0, so for implementing logic gates you might want to implement your own threshold function f(x) which returns1 for x >0, and 0 for x <=0

In this example we don't care about what the network says at points other than (0,0),(1,0),(0,1),(1,1).

If this is the case I can see that with W = [1 1] and w0 = 0, the OR function is simulated, but I am struggling with the AND. I think I am just having problems getting going with matlab, so any pointers would be appreciated.

Think about drawing out the truth table results on a two-d graph. The only point which should give a 1 is x = 1, y = 1, so any plane which separates 1,1 from the other three points (0,0),(1,0),(0,1) will provide the AND function. try to set the weights to achieve this.


Question:

I am currently trying to work through the first NC4 lab and am running into some problems. I'm not sure of exactly how the function surf displays it's results. Each input parameter seems to be an nxn array and I'm not sure how this translates into the graph that gets shown. Clearly displaying results of what is hapenning in MatLab is one of the most important parts and I would like to have a firm grasp of what is going on before the next lab.

Answer:

if you use help surf you will be given useful information. The meshgrid command creates n x n samples on a grid in the X,Y space. You then have to evaluate your function at every one of these points and pass that to the surf command in the form of an n x n matrix (see the reshape example I used in the lab.


Question:

I have been trying to do the first lab again (after stopping after friday) and I am still having problems. Basically I can understand the lecture notes and so the first part you implement where a = w0 + sum xiwi I understand the theory behind it, but I connot find how to implement this. I have found the sum function and I think that the xi relates to the Xin (the same as the exaple on the first page) but I do not know where the weightings come from. I currently have the code:

you create weightings yourself

xrange = [0:0.01:1];

[Xin, Yin] = meshgrid(xrange);

output = Yin + sum(Xin.*Yin);

surf(Xin, Yin, output)

but it keeps giving an error saying that the matrix dimensions must agree. I used the Yin in place of the weightings because of my uncertainty as to what the relate to.

you don't need the sum() function - use matrix multiplication if you note the example on the lab note, I reshape the matrix Xin and Yin to be an N x 2 matrix by using inputs = [ Xin(:) Yin(:)]; this can then be provided as input (each row of inputs would be the xi vector in the notes) i.e. xi = inputs(43,:); would create a 1 x 2 vector xi which could be passed to the weights, so to do the operation above we have: a = w0 + inputs*w where inputs is N x 2, w is 2 x 1 and w0 is 1 x 1. a should then be N x 1.