Context
We are trying to predict the formation of discs of intermediate mass black hole orbiting super massive black holes in galactic centres. This involves finding calorific curves in energy and angular momentum space.
Problem
I am trying to identify sets of curves from a (very large) sets of points in order to produce a lighter figure.
For instance I want to be able to redo such figure, but with less points (without loosing the poorly sampled lines).
The challenge is that these points are found by some complex optimisation routine and are over-numerous in places. So by lighter figure, I mean remove sets of point very close to each other while keeping more sparsely sampled points in order to draw curves through them.
Question
How can one achieve this simultaneous downsampling and curve matching procedure?
Attempt
Let me define a toy problem as follows: let me produce two curves:
data = Flatten[{Table[{x, Sin[x^2/15]}, {x, 0, 20, 0.01}],
Table[{x, 2 + Cos[x]}, {x, 0, 20, 0.1}]}, 1];
and draw random points from those.
pts = RandomChoice[data, Length[data]];
ListPlot[pts]
Note that on purpose the sampling is not the same for the two curves.
I found on this site and in the documentation a couple of partial solutions to this problem, but none does both the curve identification and downsampling properly.
The first method relies on Nearest (from the documentation) but does neither job (interpolation or downsampling) particularly well:
p = Nearest[pts];
pts1 = p[#, 2][[2]] & /@ pts;
Graphics[{Line[{##}] & @@@ Transpose[{pts, pts1}]}, Axes -> True,
AspectRatio -> 2/3]
From this answer I tried also ListCurvePathPlot which seems like a good start
but does not down sample.
pl = ListCurvePathPlot[pts, Mesh -> All,
MeshStyle -> Directive[ColorData[97][2], PointSize[Large]],
AspectRatio -> 1]
Finally FindShortestTour doesnt do as good a job, but lets me downsample by brute
force (which is clearly sub optimal).
ListLinePlot[pts[[FindShortestTour[pts][[2]][[;; ;; 20]]]],
PlotMarkers -> {Automatic, 10}, InterpolationOrder -> 1]
I am optimistic that this question has a Mathematica answer since it can be done by hand relatively easily (?)










FindShortestTourshould be post-processed with additional criteria. Jump from one fork to another is conjugated with significant change of the distance. So, you need go along the sorted points looking on the value of current distance and cut the array for segments. Further you can downsample them as you wish. – Rom38 Jul 07 '21 at 09:35