Neighbors get added to the live Set during blob expansion
Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
parent
50ddb96e74
commit
2800430817
@ -8,13 +8,13 @@ Undefined = 0
|
|||||||
Edge = -1
|
Edge = -1
|
||||||
Noise = -2
|
Noise = -2
|
||||||
|
|
||||||
# Union of two lists of dicts
|
# Union of two lists of dicts, adding unique elements of B to
|
||||||
|
# end of A
|
||||||
def Union(A, B):
|
def Union(A, B):
|
||||||
C = A
|
|
||||||
for key in B:
|
for key in B:
|
||||||
if key not in C:
|
if key not in A:
|
||||||
C.append(key)
|
A.append(key)
|
||||||
return C
|
return A
|
||||||
|
|
||||||
# https://en.wikipedia.org/wiki/DBSCAN
|
# https://en.wikipedia.org/wiki/DBSCAN
|
||||||
#
|
#
|
||||||
@ -53,32 +53,39 @@ def DBSCAN(points, eps = MAX_DISTANCE, minPts = MIN_PTS, verbose = True):
|
|||||||
S.remove(P)
|
S.remove(P)
|
||||||
|
|
||||||
sub_perc = -1
|
sub_perc = -1
|
||||||
sub_total = len(S)
|
sub_last = 0
|
||||||
T = S.copy()
|
|
||||||
for j, Q in enumerate(S): # Process every seed point
|
for j, Q in enumerate(S): # Process every seed point
|
||||||
|
|
||||||
if verbose == True:
|
if verbose == True:
|
||||||
|
sub_total = len(S)
|
||||||
sub_new_perc = int(100 * (j+1) / sub_total)
|
sub_new_perc = int(100 * (j+1) / sub_total)
|
||||||
now = time.time()
|
sub_now = time.time()
|
||||||
if sub_new_perc != sub_perc or now - last > 5:
|
if sub_new_perc != sub_perc or sub_now - sub_last > 5:
|
||||||
sub_perc = sub_new_perc
|
sub_perc = sub_new_perc
|
||||||
print(f'... points {sub_perc}% ({j}/{sub_total} processed) complete with {len(clusters)} identities ({now - start}s).')
|
print(f'... points {sub_perc}% ({j}/{sub_total} processed [{perc}% total]) complete with {len(clusters)} identities ({now - start}s).')
|
||||||
last = now
|
sub_last = sub_now
|
||||||
|
|
||||||
if Q['cluster'] == Noise: # Change Noise to border point
|
if Q['cluster'] == Noise: # Change Noise to border point
|
||||||
Q['cluster'] = C
|
Q['cluster'] = C
|
||||||
C['faces'].append(Q)
|
C['faces'].append(Q)
|
||||||
|
|
||||||
if Q['cluster'] != Undefined: # Previously processed (border point)
|
if Q['cluster'] != Undefined: # Previously processed (border point)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
Q['cluster'] = C # Label neighbor
|
Q['cluster'] = C # Label neighbor
|
||||||
C['faces'].append(Q)
|
C['faces'].append(Q)
|
||||||
|
|
||||||
N = RangeQuery(points, Q, eps) # Find neighbors
|
N = RangeQuery(points, Q, eps) # Find neighbors
|
||||||
if len(N) >= minPts: # Density check (if Q is a core point)
|
if len(N) >= minPts: # Density check (if Q is a core point)
|
||||||
T = Union(T, N) # Add new neighbors to seed set
|
S = Union(S, N) # Add new neighbors to seed set
|
||||||
S = T
|
|
||||||
return clusters
|
return clusters
|
||||||
|
|
||||||
def RangeQuery(points, Q, eps):
|
def RangeQuery(points, Q, eps):
|
||||||
neighbors = []
|
neighbors = []
|
||||||
for P in points: # Scan all points in the database
|
for P in points: # Scan all points in the database
|
||||||
|
if P == Q:
|
||||||
|
continue
|
||||||
if P in neighbors:
|
if P in neighbors:
|
||||||
continue
|
continue
|
||||||
distance = findCosineDistance( # Compute distance and check epsilon
|
distance = findCosineDistance( # Compute distance and check epsilon
|
||||||
|
Loading…
x
Reference in New Issue
Block a user