【问题标题】:Object/Array comparison algorithms to determine commonality/similarity确定共性/相似性的对象/数组比较算法
【发布时间】:2014-08-08 17:17:44
【问题描述】:

我正在尝试找出确定各种对象或数组之间的共性或相似性的最佳方法,并且有兴趣获得社区的意见。我目前正在用 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特征的差异更大。

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

【问题讨论】:

    标签: javascript algorithm compare similarity


    【解决方案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
    

    这将为您提供每个特征的差异。方差是正值的平均值,所以它总是正的。值越小,方差越小,值越高,方差越大。

    【讨论】:

      猜你喜欢
      • 2012-04-08
      • 1970-01-01
      • 1970-01-01
      • 2015-10-08
      • 1970-01-01
      • 2010-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多