0

I have the attached point list and use the following script to cluster the points. The clustering should just be applied to the first three-member of each sublist so I removed the fourth element from each sublist. However, after clustering the fourth member should be added to the associated sublist. How I can do that. https://pastebin.com/SKvFEEQD

A11 = Drop[dataDCMp, None, {4}];
nng = NearestNeighborGraph[A11, 4];
ccmp = ConnectedComponents[nng];
Mehdi Ebadi
  • 501
  • 2
  • 7
  • 1
    You could try something like NearestNeighborGraph[dataDCMp, 4, DistanceFunction -> (EuclideanDistance[#1[[;; 3]], #2[[;; 3]]] &)], which may take a while to finish. – FJRA Jul 09 '20 at 02:16
  • Mehdi, can you try if Extract[dataDCMp, List /@ ConnectedComponents[IndexGraph@nng]] gives what you need? – kglr Jul 09 '20 at 12:23

1 Answers1

1

One way to do it, not efficient but overhead is small compared to generating the graph.

Import["https://pastebin.com/raw/SKvFEEQD"] // ToExpression;

(* Test on the first 100 to save time *) assoc = <|Most@# -> Last@#|> & /@ dataDCMp[[1 ;; 100]]; A11 = assoc // Keys nng = NearestNeighborGraph[A11, 4]; ccmp = ConnectedComponents[nng];

find[key_] := #[key] & /@ assoc // DeleteMissing

Map[Append[#, First@find[#]] &, ccmp, {-2}]

Rohit Namjoshi
  • 10,212
  • 6
  • 16
  • 67
  • Thank you Rohit! Your code works but I am getting extra braces. I tried to remove them by flatten function but no proper answer. Do you have any idea what the solution is? – Mehdi Ebadi Jul 09 '20 at 05:11
  • I found this "a //. {x_List} :> x " from former posts https://mathematica.stackexchange.com/questions/20180/how-to-remove-redundant-from-a-nested-list-of-lists and it modified the braces. Thank you again, Rohit! – Mehdi Ebadi Jul 09 '20 at 05:16
  • The analysis takes too long. Is there any way to do it faster? – Mehdi Ebadi Jul 09 '20 at 06:53
  • @MehdiEbadi You mean time for NearestNeighborGraph? – Rohit Namjoshi Jul 09 '20 at 17:31
  • Thank you Rohit! Now I realized that the speed is not too bad. I believe the problem was with my processor. – Mehdi Ebadi Jul 09 '20 at 18:03
  • Hi Mehdi, glad that I could help. I am curious about the data and what you are trying to do with it. I plotted the first 3 members using A11 // Flatten[#, 1] & // ListPlot3D and it looks like mountain terrain. – Rohit Namjoshi Jul 09 '20 at 18:29
  • Hi Rohit, It is part of the body torso. I could not upload it because of the capacity limitation of Pastebin. – Mehdi Ebadi Jul 09 '20 at 19:26