Hi there, I am trying to implement a loss function that depends on pairwise distances of output data.  Specifically I have neural network f which take X as input and the output is $Y = {y_i}_{i=1}^N$.  My error function has following form:
$E = | d_{ij} - c_{ij} | ^2$
where d_{ij} is distance between y_i and y_j, and c_{ij} is the target value for this distance.
I know how to write “vectorized” loss function like MSE, softmax which would take a complete vector to compute the loss.  But in my case, it seems that I have to do “atomistic” operations on each entry of the output vector, does anyone know what would be a good way to do it?
Thanks!