Create custom element-wise operations between two matrices

I’m trying to figure out how to compute a similarity matrix using a Gaussian similarity score between every data point (row, that is) in an INDArray matrix.

In a for loop, that’d look something like this psuedocode:

for row_i in matrix:
    for row_j in matrix:
        if row_i != row_j:
            sim_matrix[i][j] = score(row_i, row_j)

Is there anyway to use something like this to get that job done with ND4J:

Nd4j.getExecutioner().execAndReturn(SimilarityFunction.compute(simMatrix, simMatrix));


@wcneill we generally impleement those ops as c++ for performance reasons deeplearning4j/ at master · eclipse/deeplearning4j · GitHub

we have manhattan, euclidean and cosine similarity. Using the relationship described here:

You might be able to get away with manipulating the output from euclidean distance.

1 Like