Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return the number of point within a radius #21

Open
Xiaojieqiu opened this issue May 25, 2017 · 7 comments
Open

return the number of point within a radius #21

Xiaojieqiu opened this issue May 25, 2017 · 7 comments

Comments

@Xiaojieqiu
Copy link

Xiaojieqiu commented May 25, 2017

In page 10 of the manual of ANN (https://www.cs.umd.edu/~mount/ANN/Files/1.1.2/ANNmanual_1.1.pdf) . It mentioned that we can return the number of points within a radius when setting the ANNdist to sqRad and k = 0. This is very useful when we are trying to count the number of points for each sample whose distance is within the radius. Can you help to also return this value?

I think ANNkdFRPtsInRange is actually the value we want. But I don't know how can we return that value in the get_NN_2Set and nn2 function

int ANNkd_tree::annkFRSearch(
	ANNpoint			q,				// the query point
	ANNdist				sqRad,			// squared radius search bound
	int					k,				// number of near neighbors to return
	ANNidxArray			nn_idx,			// nearest neighbor indices (returned)
	ANNdistArray		dd,				// the approximate nearest neighbor
	double				eps)			// the error bound
{
	ANNkdFRDim = dim;					// copy arguments to static equivs
	ANNkdFRQ = q;
	ANNkdFRSqRad = sqRad;
	ANNkdFRPts = pts;
	ANNkdFRPtsVisited = 0;				// initialize count of points visited
	ANNkdFRPtsInRange = 0;				// ...and points in the range

	ANNkdFRMaxErr = ANN_POW(1.0 + eps);
	ANN_FLOP(2)							// increment floating op count

	ANNkdFRPointMK = new ANNmin_k(k);	// create set for closest k points
										// search starting at the root
	root->ann_FR_search(annBoxDistance(q, bnd_box_lo, bnd_box_hi, dim));

	for (int i = 0; i < k; i++) {		// extract the k-th closest points
		if (dd != NULL)
			dd[i] = ANNkdFRPointMK->ith_smallest_key(i);
		if (nn_idx != NULL)
			nn_idx[i] = ANNkdFRPointMK->ith_smallest_info(i);
	}

	delete ANNkdFRPointMK;				// deallocate closest point set
	return ANNkdFRPtsInRange;			// return final point count
}
@Xiaojieqiu
Copy link
Author

@jefferis
Copy link
Member

jefferis commented May 26, 2017 via email

@romanzenka
Copy link

@jefferis I just ran into the same problem. I am trying to implement a particular 2D clustering algorithm that would benefit from locating "most dense" areas. I cannot spare storing a full matrix (100 million points), but I could use an array listing number of closest points within a certain radius.

I will try to look into making this happen and doing a PR if I can...

@jefferis
Copy link
Member

jefferis commented May 4, 2018

OK. Thank you @romanzenka. I'm happy to answer questions.

@jefferis
Copy link
Member

jefferis commented May 4, 2018

PS @romanzenka if you found a patch against https://github.com/jefferis/RANN2 considerably easier (it uses RCpp) then I might consider a CRAN submission for that.

@romanzenka
Copy link

@jefferis Okay, I will look into RANN2 first.

@romanzenka
Copy link

I sent a preliminary PR into RANN2 just to show what I'm thinking - with your approval I can finish this up in a more complete fashion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants