用于确定共性/相似性的对象/阵列比较算法

时间:2014-08-08 17:17:45

标签: javascript algorithm compare similarity

我试图找出确定各种对象或数组之间的共性或相似性的最佳方法,并且有兴趣获得社区的输入。我目前正在用javascript构建一个早期的研究原型,我需要采用一种比较对象的智能方法来识别新兴的模式或趋势。通过识别模式,我正在处理的应用程序将能够做出更明智的决策。

例如,给出了6个简化对象:

A_obj = {w: 0.66, x: 0.36, y: 0.88, z: 0.34},
B_obj = {w: 0.46, x: 0.29, y: 0.91, z: 0.37},
C_obj = {w: 0.69, x: 0.40, y: 0.95, z: 0.38},
D_obj = {w: 0.78, x: 0.37, y: 0.84, z: 0.43},
E_obj = {w: 0.14, x: 0.41, y: 0.85, z: 0.53},
F_obj = {w: 0.85, x: 0.33, y: 0.96, z: 0.22};

通过观察上述情况,很明显x和y特征存在更大程度的共性,而w和z特征的差异更大。

我希望找到一个相对轻量级的解决方案,也很容易在其他语言中复制。欢迎所有的想法和意见。

1 个答案:

答案 0 :(得分:1)

如果特征是独立的,您可以单独计算每个特征的variance。由于你想要独立于语言,这里有一些伪代码:

for each trait
    for each object
        add the current trait value to a variable to get a cumulative total
    divide the total by the number of objects to get the mean
    for each object
        subtract the trait value from the mean, and square the result
        add the result to a variable to get a cumulative total
    divide by the number of objects to get the mean of the squared differences

这将为您提供每个特征的差异。方差是正值的平均值,因此它总是正的。较低的值意味着较小的方差,较高的值意味着更多的方差。