please help in this assignment i put my try here
Show older comments
*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
Walter Roberson
on 12 May 2012
You forgot to include your question.
arwa alkibsi
on 12 May 2012
Walter Roberson
on 12 May 2012
Then the answer to that question is No, if you run that code you will get a MATLAB error.
arwa alkibsi
on 12 May 2012
Walter Roberson
on 12 May 2012
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.
Answers (3)
Walter Roberson
on 12 May 2012
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
arwa alkibsi
on 12 May 2012
Walter Roberson
on 12 May 2012
If you run your code then it will certainly crash.
arwa alkibsi
on 12 May 2012
Image Analyst
on 12 May 2012
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.
arwa alkibsi
on 12 May 2012
John D'Errico
on 12 May 2012
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.
arwa alkibsi
on 12 May 2012
arwa alkibsi
on 12 May 2012
5 Comments
Walter Roberson
on 12 May 2012
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.
arwa alkibsi
on 12 May 2012
Image Analyst
on 12 May 2012
That is a one row matrix, so it must be referring to something else.
Walter Roberson
on 12 May 2012
Please show your current code, and show the exact error message that is being produced.
Image Analyst
on 12 May 2012
I can't help you - missing some toolboxes that you have. Can you show us what "ver" reports back for you?
arwa alkibsi
on 12 May 2012
2 Comments
Walter Roberson
on 13 May 2012
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.
Walter Roberson
on 13 May 2012
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?
Categories
Find more on Parallel and Cloud in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!