1,211 reputation
319
bio website
location
age
visits member for 1 year, 8 months
seen 2 days ago

Dec
11
comment Interactively extract points from a plot (ListPlot or SmoothDensityHistogram)
@SparsePine and an "undo" button is also useful, Button["undo", poly = Drop[poly, -1]]
Dec
10
comment efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
Sorry, I found bugs. See this ps list here pastebin.com/GXtnVxYi This ps list contains Sqrt, and if you try ps=N@ps and add small offset to d respectively, you will find their result is different. And I can confirm, add offset gives right result, because the right result will compatible with my other code. But merely add small offset without ps=N@ps will effect the performance much. So I conclude that ps=N@ps and a small offset, None is dispensable for correct and efficient code. I hope you could check this to see if my statement is right. Thank you
Dec
10
comment efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
I mean if the coordinates of points contain Sqrt, then to make the code most general and correct, either to add ps=N@ps, or add a little offset to d in your code. And in terms of the identity of your code and mine, I'm not claim any precedence here, because anyway you enlightened me to use NearestFunction first. But I read through your code and test it, so I am sure we had the same idea. And finally, if I had know that you would post an answer, I wouldn't spend a whole afternoon to design a code myself :). especially when yours is more general and efficient than mine. Thank you so much!
Dec
10
comment efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
Ok, are you considering to improve your answer with N? Though my method is identical to yours, but I make the label a little complex, so I'll accept yours, if there is no better method
Dec
10
revised efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
added 172 characters in body
Dec
10
comment efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
Well, you can try this ps={{0, 0}, {Sqrt[2], 0}, {0, Sqrt[2]}, {Sqrt[2], Sqrt[2]}}. Very odd,.but it's true, offset is necessary.
Dec
10
comment efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
Thank you for your answer! I am testing now, and I also found the EuclideanDistance problem, so I use N and add small offset 0.0000001 to it, I found this small offset is necessary, see my answer.
Dec
10
comment efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
Thank you for your method! I also posted mine :)
Dec
10
answered efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
Dec
10
revised efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
added 67 characters in body
Dec
10
comment efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
@Silvia No, You didn't use my code properly:). You should set coolist={{1, 2}, {1, 0}, {2, 2}, {2, 1}} and Do[p[i] = coolist[[i]], {i, 1, 4}]
Dec
10
revised efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
added 21 characters in body
Dec
10
comment efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
@Silvia Oh, my god! I made a mistake, I am so sorry. I have corrected it. But the code I write is right, I think.
Dec
10
revised efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
deleted 3 characters in body
Dec
10
comment efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
@RahulNarain I'm glad I made myself clear and thank you for your interest in this question. But I don't have a fixed third nearest distance, it varies from point to point.
Dec
10
comment efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
@Silvia I want two list, one list contain nearest point labels, the other list contains next nearest point labels. Since p[2] is the "next nearest point" to p[3], so it should not be contained in the nearestlist
Dec
10
comment efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
OK, return to my 4 point toy example. Let nnn = Nearest[{p[1], p[2], p[3], p[4]}] . Then nnn[p[1], 1] gives{{0, 0}}, nnn[p[1], 2] gives {{0, 0}, {0, 1}}, and nnn[p[1], 3] gives {{0, 0}, {0, 1}, {1, 0}}. But actually {0,1} and {1,0} has the same distance to p[1], so in this case p[1] has two nearest point. But if you see p[4], it only has one nearest point.
Dec
10
comment efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
@RahulNarain but the environment of every point is different. I can't set a fixed n?
Dec
10
comment efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
@RahulNarain I lookup in the doc. I found that NearestFunction may not be working well in this case. because the number of nearest point is not fixed, maybe one and maybe two, even three....
Dec
10
comment efficient way to give nearest neighbour and next nearest neighbour of every point in a point set
@RahulNarain Oh, thank you. NearestFunction! Let me see it.