给定四个表示“类”的二进制向量:
[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 完成这项任务。
最佳答案
找到 SSD (sum of squared differences)每个“类”的测试向量,并使用 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,:))
为了便于说明,差异
如下所示:
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
:
0.41
2.01
7.61
2.01
显然,第一个是最佳匹配,因为它的差异最小。
关于matlab - 向量尽力分类算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1576129/