def get_parameters(self): """ This function creates some parameters to be used with DBScan. @return: A tuple with the generated parameters and an empty list corresponding to the clusterings. """ run_parameters = [] # (minpts, eps tuples) if "max" in self.parameters["clustering"]["algorithms"]["dbscan"]: max_eps_tries = self.parameters["clustering"]["algorithms"]["dbscan"]["max"] else: max_eps_tries = 10 num_elements = self.distance_matrix.row_length klist = k_scale_gen(math.log(num_elements)) buffer = numpy.empty(num_elements) kdist_matrix = k_dist(klist, buffer, self.distance_matrix) dbscan_param_pairs = dbscanTools.dbscan_param_space_search(self.parameters["clustering"]["evaluation"]["maximum_noise"], max_eps_tries, num_elements, klist, kdist_matrix) +\ zhou_adaptative_determination(kdist_matrix, self.distance_matrix) for (minpts, eps) in dbscan_param_pairs: run_parameter = ParametersGenerator.get_base_parameters() run_parameter["minpts"] = minpts run_parameter["eps"] = eps run_parameters.append(run_parameter) return run_parameters, []
def test_zhou_adaptative_determination(self): distances = CondensedMatrix([ 0., 0., 2., 2., 0., 2., 2., 2., 2., 0.]) buffer = numpy.empty(distances.row_length) k_dist_matrix = k_dist(numpy.array([2,4]), buffer, distances) zhou_params = zhou_adaptative_determination(k_dist_matrix, distances) self.assertItemsEqual(zhou_params,[(1.0, 0.8), (4.0, 2.0)])
def test_k_dist(self): distances = CondensedMatrix([ 17.46, 9.21, 4.47, 3.16, 4.47, 5.65, 12.36, 5.83, 9.43, 12.52, 15.65, 5., 8.06, 11.18, 13.15, 3.16, 6.35, 8.24, 3.16, 5.10, 2. ]) buffer = numpy.empty(distances.row_length) result = k_dist(numpy.array([2, 4]), buffer, distances) # [[ 4.47 5.65] # [ 9.43 12.52] # [ 8.06 11.18] # [ 4.47 5.83] # [ 3.16 5.1 ] # [ 3.16 6.35] # [ 5.1 8.24]] expected = [ sorted([4.47, 9.43, 8.06, 4.47, 3.16, 3.16, 5.1]), sorted([5.65, 12.52, 11.18, 5.83, 5.1, 6.35, 8.24]) ] numpy.testing.assert_array_almost_equal(result, expected, decimal=2)
def test_k_dist(self): distances = CondensedMatrix([17.46, 9.21, 4.47, 3.16, 4.47, 5.65, 12.36, 5.83, 9.43, 12.52, 15.65, 5., 8.06, 11.18, 13.15, 3.16, 6.35, 8.24, 3.16, 5.10, 2. ]) buffer = numpy.empty(distances.row_length) result = k_dist(numpy.array([2,4]), buffer, distances) # [[ 4.47 5.65] # [ 9.43 12.52] # [ 8.06 11.18] # [ 4.47 5.83] # [ 3.16 5.1 ] # [ 3.16 6.35] # [ 5.1 8.24]] expected = [sorted([ 4.47, 9.43, 8.06, 4.47, 3.16, 3.16, 5.1]), sorted([ 5.65, 12.52, 11.18, 5.83, 5.1, 6.35, 8.24])] numpy.testing.assert_array_almost_equal(result,expected,decimal = 2)
def test_zhou_adaptative_determination(self): distances = CondensedMatrix([0., 0., 2., 2., 0., 2., 2., 2., 2., 0.]) buffer = numpy.empty(distances.row_length) k_dist_matrix = k_dist(numpy.array([2, 4]), buffer, distances) zhou_params = zhou_adaptative_determination(k_dist_matrix, distances) self.assertItemsEqual(zhou_params, [(1.0, 0.8), (4.0, 2.0)])