Accord.Math.Distance.SquareEuclidean(Sparse<double> x, Sparse<double> y)

8 views
Skip to first unread message

Jerry

unread,
May 1, 2017, 11:38:53 AM5/1/17
to Accord.NET Framework
I'd appreciate a little help here. Please excuse my ignorance.

Accord.Math.Distance.SquareEuclidean(Sparse<double> x, Sparse<double> y) iterates through the indices of x and y, referencing them by index (i, j).

Doesn't this mean that the indices of x and y need to be of equal length?

In this case what's the point of using Sparse<double>?


int i = 0, j = 0;

while (i < x.Indices.Length && j < y.Indices.Length)
{
int posx = x.Indices[i];
int posy = y.Indices[j];

if (posx == posy)
{
double d = x.Values[i] - y.Values[j];
sum += d * d;
i++;
j++;
}
else if (posx < posy)
{
double d = x.Values[j];
sum += d * d;
i++;
}
else if (posx > posy)
{
double d = y.Values[j];
sum += d * d;
j++;
}
}

Thanks!

Reply all
Reply to author
Forward
0 new messages