I have three diagonal arrays A,B,C
all are double
of size 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. Meanwhile, the optimal data are stored in C
.
My question is how to find which of the arrays A,B
is more similar to 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. 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);
}