示例#1
0
 def test_cluster_extremities(self):
     """Test for method cluster_extremities"""
     model = DBICAN(4, 5)
     input_array = np.array([
         1, 2, 21, 22, 22, 22, 24, 38, 54, 54, 55, 56, 65, 65, 66, 67, 68,
         90
     ],
                            dtype=int)
     cluster_extremities = [(21, 24), (54, 56), (65, 68)]
     model.fit(input_array)
     for result, answer in zip(model.cluster_extremities(),
                               cluster_extremities):
         assert result == answer
示例#2
0
 def test_labels(self):
     """Test for method labels"""
     udc_object = DBICAN(4, 5)
     input_array = np.array([
         1, 2, 21, 22, 22, 22, 24, 38, 54, 54, 55, 56, 65, 65, 66, 67, 68,
         90
     ],
                            dtype=int)
     labels = np.array(
         [-1, -1, 0, 0, 0, 0, 0, -1, 1, 1, 1, 1, 2, 2, 2, 2, 2, -1],
         dtype=int)
     udc_object.fit(input_array)
     npt.assert_array_equal(udc_object.labels(), labels)
示例#3
0
 def test_clusters(self):
     """
     Test for method clusters.
     """
     model = DBICAN(4, 5)
     input_array = np.array([
         1, 2, 21, 22, 22, 22, 24, 38, 54, 54, 55, 56, 65, 65, 66, 67, 68,
         90
     ],
                            dtype=int)
     cluster_arrays = [
         np.array([21, 22, 22, 22, 24], dtype=int),
         np.array([54, 54, 55, 56], dtype=int),
         np.array([65, 65, 66, 67, 68], dtype=int)
     ]
     model.fit(input_array)
     for result, answer in zip(model.clusters(), cluster_arrays):
         npt.assert_array_equal(result, answer)
示例#4
0
 def test_fit(self):
     """
     Test to run class via the method fit.
     Points passed to the fit method should be copied into new array.
     New copy of points should be sorted.
     Most edge cases should be caught in tests for component methods.
     """
     model = DBICAN(4, 5)
     input_array = np.array([
         1, 2, 21, 22, 22, 22, 24, 38, 54, 54, 55, 56, 65, 65, 66, 67, 68,
         90
     ],
                            dtype=int)
     answer_array = np.array([
         1, 2, 21, 22, 22, 22, 24, 38, 54, 54, 55, 56, 65, 65, 66, 67, 68,
         90
     ],
                             dtype=int)
     answer_slices = np.array([(2, 7), (8, 12), (12, 17)],
                              dtype=DBICAN._DTYPE_SLICE)
     model.fit(input_array)
     assert model.input_array is not input_array
     npt.assert_array_equal(model.input_array, answer_array)
     npt.assert_array_equal(model.slices, answer_slices)
示例#5
0
    15, 16, 18, 23, 25, 26, 27, 27, 28, 29, 30, 31, 33
])

# variables
mpts = 10
eps = 5

# DBSCAN labels
cores, dbscan_labels = dbscan(points.reshape(-1, 1), eps=eps, min_samples=mpts)

# DBSCAN* labels are same for core points but otherwise -1
dbscanx_labels = np.zeros(len(points), dtype=np.int) - 1
dbscanx_labels[cores] = dbscan_labels[cores]

# DBICAN labels
dbican = DBICAN(min_points=mpts, epsilon=eps)
dbican.fit(points)
dbican_labels = dbican.labels()

# plotting
labels_list = [dbscan_labels, dbscanx_labels, dbican_labels]
name_list = [r'DBSCAN', r'DBSCAN*', 'DBICAN']
title = r'Comparison of Algorithms with $m_{pts}=10$ and $\varepsilon=5$'
legend_labels = ['.', '1', '2']
x_max_ofset = 2
height = 2.5
width = 6
n_row = 3
n_col = 1

rcParams['figure.figsize'] = width, height