![]() |
向量的最大努力分类算法
给定代表“类”的四个二进制向量:
[1,0,0,0,0,0,0,0,0,0] [0,0,0,0,0,0,0,0,0,1] [0,1,1,1,1,1,1,1,1,0] [0,1,0,0,0,0,0,0,0,0] 有哪些方法可以将浮点值的向量分类为这些“类”之一? 在大多数情况下,基本的舍入工作: round([0.8,0,0,0,0.3,0,0.1,0,0,0]) = [1 0 0 0 0 0 0 0 0 0] 但是如何处理一些干扰? round([0.8,0,0,0,0.6,0,0.1,0,0,0]) != [1 0 0 0 0 1 0 0 0 0] 第二种情况应该更好地匹配1000000000,但是由于没有明确的匹配项,我完全失去了解决方案。 我想将MATLAB用于此任务。 回答: 找到每个“类别”的测试向量的[URL="http://en.wikipedia.org/wiki/Sum_of_squares"]SSD(平方差之和)[/URL] ,然后使用SSD最少的那个。 这是一些代码:我在您提供的测试向量的末尾添加了0 ,因为它只有9位数字,而类只有10位数字。 CLASSES = [1,0,0,0,0,0,0,0,0,0 0,0,0,0,0,0,0,0,0,1 0,1,1,1,1,1,1,1,1,0 0,1,0,0,0,0,0,0,0,0]; TEST = [0.8,0,0,0,0.6,0,0.1,0,0,0]; % Find the difference between the TEST vector and each row in CLASSES difference = bsxfun(@minus,CLASSES,TEST); % Class differences class_diff = sum(difference.^2,2); % Store the row index of the vector with the minimum difference from TEST [val CLASS_ID] = min(class_diff); % Display disp(CLASSES(CLASS_ID,:)) 出于说明目的, difference如下所示: 0.2 0 0 0 -0.6 0 -0.1 0 0 0 -0.8 0 0 0 -0.6 0 -0.1 0 0 1 -0.8 1 1 1 0.4 1 0.9 1 1 0 -0.8 1 0 0 -0.6 0 -0.1 0 0 0 每个类与TEST的距离如下class_diff : class_diff : 0.41 2.01 7.61 2.01 显然,第一个是最佳匹配,因为它的差异最小。 [url=https://stackoverflow.com/questions/1576129]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 23:21。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.