Skip to content

Commit 61f9930

Browse files
committed
Fixed problem with null pointer values in reachability slice
1 parent 08144f6 commit 61f9930

3 files changed

Lines changed: 24 additions & 32 deletions

File tree

dbscan.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import (
55
)
66

77
type dbscanClusterer struct {
8-
minpts int
9-
workers int
10-
eps float64
8+
minpts, workers int
9+
eps float64
1110

1211
distance DistanceFunc
1312

14-
// slices holding the cluster mapping and sizes
13+
// slices holding the cluster mapping and sizes. Access is synchronized to avoid read during computation.
1514
mu sync.RWMutex
1615
a, b []int
1716

kmeans.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ const (
1515

1616
/* Implementation of k-means++ algorithm with online learning */
1717
type kmeansClusterer struct {
18-
iterations int
19-
number int
18+
iterations, number int
2019

2120
// variables keeping count of changes of points' membership every iteration. User as a stopping condition.
2221
changes, oldchanges, counter, threshold int
@@ -27,7 +26,7 @@ type kmeansClusterer struct {
2726

2827
distance DistanceFunc
2928

30-
// slices holding the cluster mapping and sizes
29+
// slices holding the cluster mapping and sizes. Access is synchronized to avoid read during computation.
3130
mu sync.RWMutex
3231
a, b []int
3332

optics.go

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ type clusterJob struct {
1515
}
1616

1717
type opticsClusterer struct {
18-
minpts int
19-
workers int
20-
eps float64
21-
22-
xi, x float64
18+
minpts, workers int
19+
eps, xi, x float64
2320

2421
distance DistanceFunc
2522

26-
// slices holding the cluster mapping and sizes
23+
// slices holding the cluster mapping and sizes. Access is synchronized to avoid read during computation.
2724
mu sync.RWMutex
2825
a, b []int
2926

@@ -254,18 +251,13 @@ func (c *opticsClusterer) update(p int, d float64, l *int, r *[]int, q *priority
254251

255252
func (c *opticsClusterer) extract() {
256253
var (
257-
i, e, us, ue, cs, ce, s, k int
258-
mib, d float64
259-
areas []*steepDownArea = make([]*steepDownArea, 0)
260-
clusters map[int]bool = make(map[int]bool)
254+
i, k, e, ue, cs, ce, s, p int = 1, 1, 0, 0, 0, 0, 0, 0
255+
mib, d float64
256+
areas []*steepDownArea = make([]*steepDownArea, 0)
257+
clusters map[int]bool = make(map[int]bool)
261258
)
262259

263-
for i < c.l-1 {
264-
if c.re[c.so[i]] == nil || c.re[c.so[i+1]] == nil {
265-
i++
266-
continue
267-
}
268-
260+
for i < c.l-2 {
269261
mib = math.Max(mib, c.re[c.so[i]].p)
270262

271263
if c.isSteepDown(i, &e) {
@@ -291,7 +283,6 @@ func (c *opticsClusterer) extract() {
291283
i = e + 1
292284
mib = c.re[c.so[i]].p
293285
} else if c.isSteepUp(i, &e) {
294-
us = i
295286
ue = e + 1
296287

297288
as := areas[:0]
@@ -308,9 +299,6 @@ func (c *opticsClusterer) extract() {
308299
}
309300
areas = as
310301

311-
i = e + 1
312-
mib = c.re[c.so[i]].p
313-
314302
for j := 0; j < len(areas); j++ {
315303
if c.re[c.so[ue]].p*c.x < areas[j].mib {
316304
continue
@@ -331,24 +319,27 @@ func (c *opticsClusterer) extract() {
331319
ce = ue
332320
} else {
333321
cs = areas[j].start
334-
for k := us; k < ue-1; k++ {
335-
if math.Abs((c.re[c.so[k]].p-c.re[c.so[us]].p)/c.re[c.so[k]].p) <= c.xi {
322+
for k := i; k < e; k++ {
323+
if math.Abs((c.re[c.so[k]].p-c.re[c.so[i]].p)/c.re[c.so[k]].p) <= c.xi {
336324
ce = k
337325
break
338326
}
339327
}
340328
}
341329

342-
if ce-cs < c.minpts {
330+
p = ce - cs
331+
332+
if p < c.minpts {
343333
continue
344334
}
345335

346-
s = cs + ce
336+
s = ce + cs
347337

348338
if !clusters[s] {
349339
clusters[s] = true
350340

351-
c.b[k] = ce - cs
341+
c.b = append(c.b, 0)
342+
c.b[k] = p
352343

353344
c.w.Add(1)
354345

@@ -361,6 +352,9 @@ func (c *opticsClusterer) extract() {
361352
k++
362353
}
363354
}
355+
356+
i = ue
357+
mib = c.re[c.so[i]].p
364358
} else {
365359
i++
366360
}

0 commit comments

Comments
 (0)