I've created a lower triangular distance matrix (because of size issues) as jagged array Note: Distances between objects are symmetric
var dm = new double[size][]
for (var i = 0; i < size; i++)
{
dm[i] = new double[i+1];
for (var j = 0; j < i+1; j++)
{
dm[i][j] = distance(data[i], data[j]);
}
}
I need to access this matrix very often so I made the following method for it
private double GetValueOfDM(int row, int column, double[][] dm)
{
return column <= row ? distanceMatrix[row][column] : distanceMatrix[column][row];
}
With the Visual Studio performance analysis one sees the major speed issue lies in the only row of the GetValueOfDM
method.
Has someone a good idea how to speed this up?