please help in this assignment i put my try here

*this is the question of assignment :
Generate two-class data according to specifications of Assignment #1. However, each class shall have 300 points. The generated data is not linearly separable—20% of each class violating the linear separability.
Using a perceptron, do the training on 200 points with the Delta Rule (Widrow-Hoff) to determine the weights and bias, and classify the remaining 100 points.
Using an adaline, do the training on 200 points with the Delta Rule (Widrow-Hoff) to determine the weights and bias, and classify the remaining 100 points.
*What is required:
*For each type of units, plot the graph showing the speed of convergence (the Mean Square Error in the vertical axis against the number of examples in training in the horizontal axis,)
For each type of units, plot the graph showing the ratio (the percentage) of correctly classified examples against the number of examples in the training set (use 100 examples for learning and classify the 200 remaining—compute the percentage of the correctly classified data; then use 125 examples for training and classify the 175 remaining; use 150 for training and classify the 150 remaining; use 175 for training and classify the 125 remaining; use 200 for training and classify the 100 remaining)
Report the plots and compare the performance to the two models on the data set.
=======
my try
x=randint(600,1,[-1,1]);
x=x';
y=randint(600,1,[-4,4]);
y=y';
for i=1:300
class1=1;
end
for i=300
class2=0;
end
class=[class1,class2];
for i=1:200
input1=[x(1,i),y(1,i)];
t(i)=class(i);
end
net=newp(minmax(x),1);
net=inputWeight.learnFcn='learnp';
net1=train(net,inputz,t);
m=1;
for i=201:300
xtest(:,m)=[x(1,i),y(1,i)];
m=m+1;
end
ytest=sim(net1,xtest);
for i=1:300
if class(i)==1
hold on
plot(x(1,i),y(1,i),'d','MarkerFaceColor','g');
else
hold on
plot(x(1,i),y(1,i),'s','MarkerFaceColor','r');
end
end
========
please help me !!

5 Comments

You forgot to include your question.
my Q if this code correct for the assignment or there is somthing missing !?
plz help me before mondy
Then the answer to that question is No, if you run that code you will get a MATLAB error.
yes i run it and there is error in these lines :
net=inputWeight.learnFcn='learnp';
t(i)=class(i);
xtest(:,m)=[x(1,i),y(1,i)];
=======
that's why i copy the whole assignment here to let u understand the code !
and help me if my code trying is right or need somthing else !!
That first line you indicate is a syntax error. MATLAB does not support the syntax A=B=C . That line would possibly prevent MATLAB from parsing the code, but even if you were to fix that one line, MATLAB would give you a run-time error on a line before that. You need to fix the issue I indicated in my Answer below.

Sign in to comment.

Answers (3)

Your coe
for i=1:300
class1=1;
end
does the same thing 300 times: sets the scalar variable named "class1" to the value 1. Was that your intent?

7 Comments

the assignment is complicated & it confuse me :S
i actually don't know if my try correct or nor for the requirement!!
If you run your code then it will certainly crash.
I realy can't see wht is the wrong in these line:
for i=1:300
class1=1;
end
i wrote it for filling points into 2 classes !!
She probably meant
class1 = ones(1,300);
class2 = ones(1,300);
or, since those are only used to construct class (by the way, it's bad to use a built-in function name as a variable name), simply do
classes = ones(2, 300);
and then replace class with classes everywhere so she doesn't blow away the built-in class() function.
now the error after run in this line:
net1=train(net,inputz,t);
A loop around setting the scalar class1 to 1 is a good way of being absolutely positive that class1 is set to 1. However, if you increase the upper limit on the loop to inf, you will be even more certain.
plz if any one can correct my code !!
it is assignment & iam not experiment of matlab i tried as i can :(
the last time is monday morning !! please help me

Sign in to comment.

it is run after i wite by this way , but there is no figure ! :(
x=randint(600,1,[-1,1]);
x=x';
y=randint(600,1,[-4,4]);
y=y';
classes= ones(2, 300);
for i=1:200
input1=[x(1,i),y(1,i)];
t(i)=classes(i);
end
net=newp(minmax(x),1);
net1=train(net,t);
m=1;
for i=201:300
xtest(:,m)=[x(1,i),y(1,i)];
m=m+1;
end
ytest=sim(net1,xtest);
for i=1:300
if classes(i)==1
hold on
plot(x(1,i),y(1,i),'d','MarkerFaceColor','g');
else
hold on
plot(x(1,i),y(1,i),'s','MarkerFaceColor','r');
end
end

5 Comments

You create classes as two dimensional, but you use classes as one dimensional.
I think classes should have two different values in it, not be all one value.
You need to train over a subset of your data, and the data needs to include both classes. Your test set would then be the rest of the data excluding the original. Often the training subset would be chosen randomly.
mmmm what about this :
class1 = ones(1,300);
class2 = zeros(1,300);
classes=[class1,class2];
but also after run it , it is tell :
(Inputs are incorrectly sized for network.
Matrix must have 1 rows.)
T_T
That is a one row matrix, so it must be referring to something else.
Please show your current code, and show the exact error message that is being produced.
I can't help you - missing some toolboxes that you have. Can you show us what "ver" reports back for you?

Sign in to comment.

x=randint(600,1,[-1,1]);
x=x';
y=randint(600,1,[-4,4]);
y=y';
class1 = ones(1,300);
class2 = zeros(1,300);
classes=[class1,class2];
for i=1:200
input1=[x(1,i),y(1,i)];
t(i)=classes(i);
end
net=newp(minmax(x),1);
net1=train(net,t);
m=1;
for i=201:300
xtest(:,m)=[x(1,i),y(1,i)];
m=m+1;
end
ytest=sim(net1,xtest);
for i=1:300
if classes(i)==1
hold on
plot(x(1,i),y(1,i),'d','MarkerFaceColor','g');
else
hold on
plot(x(1,i),y(1,i),'s','MarkerFaceColor','r');
end
end
------------ this id the error in command window: ??? Error using ==> network.sim at 178 Inputs are incorrectly sized for network. Matrix must have 1 rows.
Error in ==> drwalilap at 19 ytest=sim(net1,xtest);

2 Comments

Consider your code,
xtest(:,m)=[x(1,i),y(1,i)];
The [x(1,i),y(1,i)] part is a vector with two elements because "i" is scalar. The xtest(:,m) part with m scalar then forces the two elements to be written into consecutive rows of a single column. The result is going to be an array with multiple rows. sim() is complaining that the array xtest has multiple rows.
*Why* sim() requires that array to have a single row has to do with the way you initialized the network and the percepteron. Go back through your code and check the sizes carefully. Be careful about row vectors compared to column vectors.
In your loop that builds "t", you compute "input1", but you overwrite the variable for each iteration of the loop, and you never use "input1" after the loop. In view of the alternatives, are you sure this is wise?

Sign in to comment.

Asked:

on 12 May 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!