Creating a simple perception algorithm
5 次查看(过去 30 天)
显示 更早的评论
I am trying to do a simple perception model using Rosenblatt’s training algorithm. Z is my data set where column 1 is my x value, 2 is my y value and 3 is my random weight. Each object (x,y) in Z is either assigned 1 or 2 in the vector labels. I have started with a small data set, easily separable to test so it should run quickly, according to the count I have placed in the if-statement though it goes on far longer than expected and does not exit the loop. I think there may be an issue in the updating of the weights, and also the if-statement expression. If anyone could help me with how I should be updating the weights with x,y values as well as what expression I should use for the if-statement that would be a big help.
Thanks.
while errors > 0
errors = 0;
v = sum(Z(:,1).*Z(:,2).*Z(:,3)) %x * y * weight for each object
if v >= 0
v = 1;
else
v = 0;
end
for i = 1:sizea % for each object in dataset
if(v == 0 && labels(i) == 2 || v == 1 && labels(i) == 1)
errors = 1;
count = count + 1
Z(i,3) = Z(i,3) - (2*v-1) * eta * Z(i,1);
end
end
end
This is the data I am using. It is split with a backwards facing horizontal line, points above are red, points below are black. The shape is more pronounced when using a few thousand points instead of 10. As you can see the labels 1 or 2 are assigned depending on if the points are above or below the line. I want to adjust the weights so that I get no errors when classifying the points.
d = rand(10,2);
figure
hold on
labels = ones(10,1);
diff = d(:,1) + d(:,2) - 1;
labels( diff + 1 >= 1) = 2;
pathWidth = 0.05;
labels( abs(diff) < pathWidth) = [];
d(abs(diff) < pathWidth,:) = [];
plot(d(labels == 1,1),d(labels == 1,2),'k.','MarkerSize',10)
plot(d(labels == 2,1),d(labels == 2,2),'r.','MarkerSize',10)
axis square
2 个评论
sixwwwwww
2013-12-4
can you share your data? and how you like to introduce the conditions on Z based on the values of X and Y?
回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!