TRyignt o speeed back up
Signed-off-by: James Ketrenos <james_gitlab@ketrenos.com>
This commit is contained in:
parent
55ea7ed515
commit
abd2986f2a
@ -14,9 +14,9 @@ typedef enum {
|
|||||||
} ClusterTypes;
|
} ClusterTypes;
|
||||||
|
|
||||||
typedef struct Face {
|
typedef struct Face {
|
||||||
long faceId;
|
|
||||||
long double descriptor[128];
|
long double descriptor[128];
|
||||||
long int clusterId;
|
long int clusterId;
|
||||||
|
long faceId;
|
||||||
ClusterTypes clusterType;
|
ClusterTypes clusterType;
|
||||||
double *distances;
|
double *distances;
|
||||||
} Face;
|
} Face;
|
||||||
@ -111,10 +111,10 @@ RangeQuery(DB, distFunc, Q, eps) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
FaceLink *RangeQuery(Face *pFaces, long int faceCount, Face *pQ, double eps) {
|
FaceLink *RangeQuery(Face **ppFaces, long int faceCount, Face *pQ, double eps) {
|
||||||
FaceLink *pNeighbors = NULL;
|
FaceLink *pNeighbors = NULL;
|
||||||
for (long int i = 0; i < faceCount; i++) {
|
for (long int i = 0; i < faceCount; i++) {
|
||||||
Face *pFace = &pFaces[i];
|
Face *pFace = ppFaces[i];
|
||||||
if (pFace->faceId == pQ->faceId) {
|
if (pFace->faceId == pQ->faceId) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -147,15 +147,15 @@ long int chainLength(FaceLink *pLink) {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
long int DBSCAN(Face *faces, long int faceCount, double eps, int minPts) {
|
long int DBSCAN(Face **ppFaces, long int faceCount, double eps, int minPts) {
|
||||||
long int C = 0;
|
long int C = 0;
|
||||||
for (long int i = 0; i < faceCount; i++) {
|
for (long int i = 0; i < faceCount; i++) {
|
||||||
Face *pFace = &faces[i];
|
Face *pFace = ppFaces[i];
|
||||||
if (pFace->clusterType != UNDEFINED) {
|
if (pFace->clusterType != UNDEFINED) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
FaceLink *pNeighbors = RangeQuery(faces, faceCount, pFace, eps);
|
FaceLink *pNeighbors = RangeQuery(ppFaces, faceCount, pFace, eps);
|
||||||
long neighborCount = chainLength(pNeighbors);
|
long neighborCount = chainLength(pNeighbors);
|
||||||
if (neighborCount < minPts) {
|
if (neighborCount < minPts) {
|
||||||
pFace->clusterType = NOISE;
|
pFace->clusterType = NOISE;
|
||||||
@ -190,7 +190,7 @@ long int DBSCAN(Face *faces, long int faceCount, double eps, int minPts) {
|
|||||||
pQ->clusterId = C;
|
pQ->clusterId = C;
|
||||||
pQ->clusterType = EDGE;
|
pQ->clusterType = EDGE;
|
||||||
|
|
||||||
FaceLink *pSubNeighbors = RangeQuery(faces, faceCount, pQ, eps);
|
FaceLink *pSubNeighbors = RangeQuery(ppFaces, faceCount, pQ, eps);
|
||||||
neighborCount = chainLength(pSubNeighbors);
|
neighborCount = chainLength(pSubNeighbors);
|
||||||
if (neighborCount >= minPts) {
|
if (neighborCount >= minPts) {
|
||||||
pQ->clusterType = CORE;
|
pQ->clusterType = CORE;
|
||||||
@ -241,19 +241,23 @@ int main(int argc, char *argv[]) {
|
|||||||
closedir(faceDir);
|
closedir(faceDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
Face *pFaces = malloc(sizeof(Face) * entries);
|
Face **ppFaces = malloc(sizeof(Face *) * entries);
|
||||||
if (!pFaces) {
|
if (!ppFaces) {
|
||||||
fprintf(stderr, "Unable to allocate storage face descriptors.");
|
fprintf(stderr, "Unable to allocate storage face descriptors.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(pFaces, 0, sizeof(Face) * entries);
|
|
||||||
for (i = 0; i < entries; i++) {
|
for (i = 0; i < entries; i++) {
|
||||||
pFaces[i].distances = malloc(sizeof(*pFaces[i].distances) * entries);
|
ppFaces[i] = malloc(sizeof(Face));
|
||||||
if (!pFaces[i].distances) {
|
memset(ppFaces[i], 0, sizeof(Face));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < entries; i++) {
|
||||||
|
ppFaces[i]->distances = malloc(sizeof(*ppFaces[i]->distances) * entries);
|
||||||
|
if (!ppFaces[i]->distances) {
|
||||||
fprintf(stderr, "Unable to allocate storage for distance dictionary.");
|
fprintf(stderr, "Unable to allocate storage for distance dictionary.");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(pFaces[i].distances, 0, sizeof(*pFaces[i].distances) * entries);
|
memset(ppFaces[i]->distances, 0, sizeof(*ppFaces[i]->distances) * entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
long int count = 0;
|
long int count = 0;
|
||||||
@ -281,7 +285,7 @@ int main(int argc, char *argv[]) {
|
|||||||
char path[1028*2];
|
char path[1028*2];
|
||||||
sprintf(path, "%s/%s", pathBuf, ent->d_name);
|
sprintf(path, "%s/%s", pathBuf, ent->d_name);
|
||||||
maxId = maxId > id ? maxId : id;
|
maxId = maxId > id ? maxId : id;
|
||||||
if (!readFaceDescriptor(&pFaces[count], id, path)) {
|
if (!readFaceDescriptor(ppFaces[count], id, path)) {
|
||||||
fprintf(stderr, "Unable to read %s.\n", path);
|
fprintf(stderr, "Unable to read %s.\n", path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -297,9 +301,9 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
long double total = 0.0;
|
long double total = 0.0;
|
||||||
for (long i = 0; i < entries; i++) {
|
for (long i = 0; i < entries; i++) {
|
||||||
Face *pLink = &pFaces[i];
|
Face *pLink = ppFaces[i];
|
||||||
for (long j = 0; j < entries; j++) {
|
for (long j = 0; j < entries; j++) {
|
||||||
Face *pTarget = &pFaces[j];
|
Face *pTarget = ppFaces[j];
|
||||||
if (i == j) {
|
if (i == j) {
|
||||||
pLink->distances[i] = 0.0;
|
pLink->distances[i] = 0.0;
|
||||||
pTarget->distances[j] = 0.0;
|
pTarget->distances[j] = 0.0;
|
||||||
@ -319,10 +323,10 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
fprintf(stderr, "Average distance: %Lf\n", 1. * total / (entries * entries));
|
fprintf(stderr, "Average distance: %Lf\n", 1. * total / (entries * entries));
|
||||||
|
|
||||||
long int clusters = DBSCAN(pFaces, entries, 0.44L, 2);
|
long int clusters = DBSCAN(ppFaces, entries, 0.44L, 2);
|
||||||
long int undefined = 0, outlier = 0, core = 0, reachable = 0;
|
long int undefined = 0, outlier = 0, core = 0, reachable = 0;
|
||||||
for (i = 0; i < entries; i++) {
|
for (i = 0; i < entries; i++) {
|
||||||
switch (pFaces[i].clusterType) {
|
switch (ppFaces[i]->clusterType) {
|
||||||
case NOISE:
|
case NOISE:
|
||||||
outlier++;
|
outlier++;
|
||||||
break;
|
break;
|
||||||
@ -349,11 +353,11 @@ int main(int argc, char *argv[]) {
|
|||||||
long nodes = 0;
|
long nodes = 0;
|
||||||
fprintf(stdout, "/* %ld. */ [", i);
|
fprintf(stdout, "/* %ld. */ [", i);
|
||||||
for (long int j = 0; j < entries; j++) {
|
for (long int j = 0; j < entries; j++) {
|
||||||
if (pFaces[j].clusterId == i) {
|
if (ppFaces[j]->clusterId == i) {
|
||||||
if (nodes == 0) {
|
if (nodes == 0) {
|
||||||
fprintf(stdout, "%ld", pFaces[j].faceId);
|
fprintf(stdout, "%ld", ppFaces[j]->faceId);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stdout, ",%ld", pFaces[j].faceId);
|
fprintf(stdout, ",%ld", ppFaces[j]->faceId);
|
||||||
}
|
}
|
||||||
nodes++;
|
nodes++;
|
||||||
}
|
}
|
||||||
@ -396,10 +400,10 @@ int main(int argc, char *argv[]) {
|
|||||||
char sqlBuf[1024];
|
char sqlBuf[1024];
|
||||||
int sourceIndex = 0, lines = 0;
|
int sourceIndex = 0, lines = 0;
|
||||||
for (long i = 0; i < entries; i++) {
|
for (long i = 0; i < entries; i++) {
|
||||||
Face *pLink = &pFaces[i];
|
Face *pLink = ppFaces[i];
|
||||||
int targetIndex = 0;
|
int targetIndex = 0;
|
||||||
for (long j = 0; j < entries; j++) {
|
for (long j = 0; j < entries; j++) {
|
||||||
Face *pTarget = &pFaces[j];
|
Face *pTarget = ppFaces[j];
|
||||||
if (i == j) {
|
if (i == j) {
|
||||||
pLink->distances[i] = 0.0;
|
pLink->distances[i] = 0.0;
|
||||||
pTarget->distances[j] = 0.0;
|
pTarget->distances[j] = 0.0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user