# Distance matrix inside a neural net

So what I would like to do is to create a NetGraph that takes in an $$n\times 3$$ (with $$n$$ varying in length) list of 3D coordinates as an input and creates an $$n \times n$$ distance matrix or an $$\frac{n (n-1)}{2}$$ list of distances between these points. I would run this net for two lists of 3D coordinates and feed the results into a MeanSquaredLossLayer. This would allow the neural net to learn to reproduce an arrangement of points with the loss invariant with respect to translations and rotations in 3D. However, I only have vague ideas what modules I should use. Maybe NetMapOperators and NetMapThreadOperators? If these, then how? Thank you for the answer in forward!

Edit: Normally, without the NN framework I would do the following to obtain the pairwise distances in a list and then calculate the loss:

distances[x_] :=
Flatten@Table[
Table[Norm[x[[i]] - x[[j]]], {i, 1, j-1}], {j, 1, Length@x}]
coordList1 = {{1, 2, 3}, {2, 3, 4}, {3, 4, 5}}; (*Small examples*)
coordList2 = {{1, 5, 3}, {2, 3, 10}, {11, 4, 5}};
loss = Sqrt@
Mean[#^2 & /@ (distances[coordList1] - distances[coordList2])]

• Do you think you could add some code to your question, explaining how you would do some of your operation normally (ie, without the NN framework)? That way, a potential answerer can be sure of the veracity of their solution. – Carl Lange Nov 14 '19 at 10:51
• Thanks, edited! – fazekaszs Nov 14 '19 at 12:11
• Sorry to be a pain, could you also add a small version of coordList1 and coordList2? Thanks! – Carl Lange Nov 14 '19 at 12:19