简体   繁体   English

比较三个对角线数组,找出最相似的两个

[英]comparing three diagonal array and find which two are most similar

I have three diagonal arrays A,B,C all are double of size 508X508 . 我有三个对角阵列A,B,C都是double尺寸的508X508 All the values above the principal diagonal are non-zero, and every other cell holds zero. 主对角线上的所有值都不为零,每个其他像元都为零。

Data in both A and B are collected from sensor in Day-1 and then Day-2. A and B中的数据均在第1天和第2天从传感器收集。 Meanwhile, the optimal data are stored in C . 同时,最佳数据存储在C

My question is how to find which of the arrays A,B is more similar to C ??? 我的问题是如何找到数组A,B哪个更类似于C

What is the best statistical method to achieve that, if possible maybe a C# code snap ? 如果可能的话,最好的统计方法是什么?

I think Corak pointed you to the right way. 我认为Corak为您指明了正确的方向。 Just select a distance measure, compute the total sum of distances for each matrix. 只需选择一个距离度量,计算每个矩阵的距离总和即可。

Try something like this 试试这个

    public double ComputeArrayDistance(double[,] firstArray, double[,] secondArray)
    {
        // some quick and dirty guardClauses to prevent hedaches 
        if (firstArray.GetLength(0) != firstArray.GetLength(1)) throw new ArgumentException("the first array is not squared ..");
        if (secondArray.GetLength(0) != secondArray.GetLength(1)) throw new ArgumentException("the second array is not squared ..");
        if (firstArray.GetLength(0) != secondArray.GetLength(0)) throw new ArgumentException("the size of two array don't match");

        double totalDistance = 0; 

        // if the array(matrix) is lower triangular
        for(int i = 0; i < firstArray.GetLength(0); i++)
        {
            for(int j = 0; j <= i; j++ )
            {
                totalDistance += this.GetDistance(firstArray[i, j], secondArray[i, j]);
            }
        }

        return totalDistance;
    }

    private double GetDistance(double elemOne, double elemTwo)
    {
        // an acceptable measure should be the square of the difference  
        return Math.Pow((elemOne - elemTwo), 2);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM