Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pts = Partition[RandomReal[1, 10000], 2];
- ListPlot[pts]
- pts2 = {pts[[1]]};
- Table[If[Min[Map[Norm[pts[[i]] - #] &, pts2]] > 0.05,
- AppendTo[pts2, pts[[i]]]], {i, 2, Length[pts],
- 1}]; // AbsoluteTiming (* -> 1.35 *)
- ListPlot[pts2]
- pts = RandomReal[1, {10000, 2}];
- f = Nearest[pts];
- k[{}, r_] := r
- k[ptsaux_, r_: {}] := Module[{x = RandomChoice[ptsaux]},
- k[Complement[ptsaux, f[x, {Infinity, .05}]], Append[r, x]]]
- ListPlot@k[pts]
- ops[pts_] := Module[{pts2},
- pts2 = {pts[[1]]};
- Table[If[Min[Map[Norm[pts[[i]] - #] &, pts2]] > 0.05,
- AppendTo[pts2, pts[[i]]]], {i, 2, Length[pts], 1}];
- pts2]
- bobs[pts_] := Union[pts, SameTest -> (Norm[#1 - #2] < 0.05 &)]
- belis[pts_] := Module[{f, k},
- f = Nearest[pts];
- k[{}, r_] := r;
- k[ptsaux_, r_: {}] := Module[{x = RandomChoice[ptsaux]},
- k[Complement[ptsaux, f[x, {Infinity, .05}]], Append[r, x]]];
- k[pts]]
- lens = {1000, 3000, 5000, 10000};
- pts = RandomReal[1, {#, 2}] & /@ lens;
- ls = First /@ {Timing[ops@#;], Timing[bobs@#;], Timing[belis@#;]} & /@ pts;
- ListLogLinePlot[ MapThread[List, {ConstantArray[lens, 3], Transpose@ls}, 2],
- PlotLegends -> {"OP", "BOB", "BELI"}, Joined ->True]
- pts = Partition[RandomReal[1, 10000], 2];
- ListPlot[pts]
- pts2 = Union[pts, SameTest -> (Norm[#1 - #2] < 0.05 &)];
- Length[pts2]
- 326
- ListPlot[pts2]
- pts = Partition[RandomReal[1, 10000], 2];
- nearestOnGrid[points_, d_] := Nearest[points, Outer[List, Range[0, 1, d], Range[0, 1, d]]~Flatten~1]~Flatten~1
- testDistances[grid_, leastD_] := Min[EuclideanDistance @@@ grid~Subsets~{2}] < leastD
- grid = nearestOnGrid[pts, 0.074]; // AbsoluteTiming
- testDistances[grid, 0.05] // AbsoluteTiming
- (* {0.000957, Null} *)
- (* {0.016401, True} *)
- GraphicsRow[{ListPlot[pts], ListPlot[grid]}, ImageSize -> 600]
- result = NestWhile[
- Nest[ Complement[#, Rest@Nearest[ # , RandomChoice[#] ,
- { Infinity, .05}]] & , #, Ceiling[(Length@#)/100] ] &, pts,
- Min[EuclideanDistance @@@ Nearest[#, #, 2]] < .05 & ];
- pts = Last[NestWhile[{Complement[First[#],
- Nearest[First[#], x = RandomChoice[First[#]], {All, .1}]],
- Append[Last[#], x]} &, {RandomReal[1, {10000, 2}], {}},Length@First[ #] != 0 &]];
- ListPlot[pts]
Add Comment
Please, Sign In to add comment