the perceptron ask?(Create a set of 2D data ( d=2, features: x=(x_1,x_2) ))
1 次查看(过去 30 天)
显示 更早的评论
Create a set of 2D data ( d=2, features: x=(x_1,x_2) )
1-Randomly create a set of 20 data points (N=20) such that for each point x=(x_1,x_2), the coordinates x_1,x_2 be integers. x_1,x_2 are to be limited to the [-30,+30] range and uncorrelated.
2-Choose the line x_1+2x_2 - 1.1 = 0 as your target function, where the points on one side of the line map to y=+1
(f=x_1+2x_2-1.5>0) and the other points map to y=-1
(f=x_1+2x_2-1.5<0). Now, you have a set of 20 data points (x,y) as your separable data points.
3-Plot the points on the 2D plane labeling them with “+” or “-“ or Red and Blue.
5-Implement and run the simple perceptron algorithm. You must write the perceptron code from scratch as opposed to using the code in software packages. Make sure to include declarations next to code lines for ease of readability. How many iterations does it take to arrive at the solution boundary (estimated target function)? Plot 4 iterations including the final one showing the boundary line at each iteration. Draw function f line on the last plot and explain why they are different. Is there any solution that could be better than others?
I write thiscode but it's not working.could you help me?
ThemeCopy
x_1=[17,-8,-25,8,-19,-27,13,-9,10,-7,8,-29,25,18,15,19,-7,7,5,2];
x_2 =[-1,-15,-3,-16,18,29,-28,2,-25,18,29,-26,26,-29,11,17,2,23,24,8];
a=[17,-8,-25,8,-19,-27,13,-9,10,-7,8,-29,25,18,15,19,-7,7,5,2];
b =[-1,-15,-3,-16,18,29,-28,2,-25,18,29,-26,26,-29,11,17,2,23,24,8];
x_1=-2*x_2+1.1
f = a + 2 * b - 1.5;
plot(x_1,x_2)
hold on
for i = 1:20
if f(i) > 0
scatter(a(i), b(i), 'r');
else if f(i)<0
scatter(a(i), b(i), 'b');
end
end
end
hold on
w = [1, 2, -1.1];
learning_rate = 0.1;
iterations = 10;
while true classified = true;
for i = 1:1000
x = [a(i), b(i), 1];
if sign(dot(w, x)) ~= y(i)
classified = false;
w = w + learning_rate * y(i) * x;
end
end
end
2 个评论
Fifteen12
2023-2-7
What problems have you encountered? It's a lot easier for us to help you out when we know what you're question is or what errors you're facing.
回答(1 个)
Sugandhi
2023-2-15
Hi Kamran,
I understand that you are trying to implement the Perceptron algorithm.
MATLAB commands can help you for implementing this. On the higher level, you can implement the Perceptron algorithm using the matrix, plot function, loops and conditional statements by following the required logical steps. For more information on syntax, and various available functions in MATLAB, kindly go through this documentation - https://www.mathworks.com/help/matlab/language-fundamentals.html
Regards,
Sugandhi.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!