From f5c3c1425727bae9403856f613acd8c8f4d7e49e Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Fri, 10 Jan 2020 19:45:47 -0800 Subject: [PATCH] Reducing eps if count > 5*minPts Signed-off-by: James Ketrenos --- scanner/scanner.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/scanner/scanner.c b/scanner/scanner.c index 062de1f..d301a57 100644 --- a/scanner/scanner.c +++ b/scanner/scanner.c @@ -42,6 +42,7 @@ typedef struct Face { typedef struct FaceLink { struct FaceLink *pNext; + long double distance; Face *pFace; } FaceLink; @@ -145,6 +146,7 @@ FaceLink *RangeQuery(Face **ppFaces, long int faceCount, Face *pQ, double eps) { if (pQ->distances[i] > 0.0 && pQ->distances[i] <= eps) { FaceLink *pLink = malloc(sizeof(*pLink)); memset(pLink, 0, sizeof(*pLink)); + pLink->distance = pQ->distances[i]; pLink->pFace = pFace; pLink->pNext = pNeighbors; pNeighbors = pLink; @@ -170,8 +172,6 @@ long int chainLength(FaceLink *pLink) { return count; } -long int maxPts = 0; - long int DBSCAN(Face **ppFaces, long int faceCount, double eps, int minPts) { long int C = 0; for (long int i = 0; i < faceCount; i++) { @@ -184,18 +184,22 @@ long int DBSCAN(Face **ppFaces, long int faceCount, double eps, int minPts) { continue; } + double threshold = eps; FaceLink *pNeighbors = RangeQuery(ppFaces, faceCount, pFace, eps); long neighborCount = chainLength(pNeighbors); - if (neighborCount > maxPts) { - maxPts = neighborCount; - fprintf(stderr, "New max with id %ld: %ld\n", pFace->faceId, maxPts); + while (neighborCount > minPts * 5) { + fprintf(stderr, "\nWith eps of %f, %ld has %ld neighbors.", threshold, pFace->faceId, neighborCount); + threshold *= 0.9; + freeChain(pNeighbors); + pNeighbors = RangeQuery(ppFaces, faceCount, pFace, threshold); + neighborCount = chainLength(pNeighbors); } + if (neighborCount < minPts) { pFace->clusterType = NOISE; freeChain(pNeighbors); - continue; + break; } - //printf("%ld has %ld neighbors.\n", pFace->faceId, neighborCount); C++; @@ -224,11 +228,15 @@ long int DBSCAN(Face **ppFaces, long int faceCount, double eps, int minPts) { FaceLink *pSubNeighbors = RangeQuery(ppFaces, faceCount, pQ, eps); neighborCount = chainLength(pSubNeighbors); + while (neighborCount > minPts * 5) { + fprintf(stderr, "\nWith eps of %f, %ld has %ld neighbors.", threshold, pFace->faceId, neighborCount); + threshold *= 0.9; + freeChain(pNeighbors); + pNeighbors = RangeQuery(ppFaces, faceCount, pFace, threshold); + neighborCount = chainLength(pNeighbors); + } + if (neighborCount >= minPts) { - if (neighborCount > maxPts) { - maxPts = neighborCount; - fprintf(stderr, "New max with id %ld: %ld\n", pFace->faceId, maxPts); - } pQ->clusterType = CORE; /* Append these neighbors to the end of the chain */ FaceLink *pTmp = pLink; @@ -376,7 +384,7 @@ int main(int argc, char *argv[]) { } if (profileDistance <= 0.5) { - fprintf(stderr, "Face id %ld distance from profile face: %Lf\n", + fprintf(stderr, "\nFace id %ld distance from profile face: %Lf", ppFaces[processed]->faceId, profileDistance); /* This entry will be skipped */ entries--;