def _dbscan_caller(cluster_candidates): print("CLUESTER CAND", [p for p in cluster_candidates]) line_seg_index = BestAvailableClusterCandidateIndex(cluster_candidates, epsilon) print("LINE SSEG INDEX", line_seg_index) return dbscan(cluster_candidates_index=line_seg_index, #TrajectoryLineSegmentCandidateIndex(cluster_candidates), \ min_neighbors=min_neighbors, \ cluster_factory=TrajectoryClusterFactory())
def _dbscan_caller(cluster_candidates): line_seg_index = BestAvailableClusterCandidateIndex(cluster_candidates, epsilon) print("return dbscan") # print(line_seg_index) return dbscan(cluster_candidates_index=line_seg_index, #TrajectoryLineSegmentCandidateIndex(cluster_candidates), \ min_neighbors=min_neighbors, \ cluster_factory=TrajectoryClusterFactory())
def run_traclus(trajs, eps, min_lns, min_traj, min_vline, min_prev_dist): # Cleaning trajs = [[Point(**pt) for pt in traj] for traj in trajs] trajs = get_cleaned_trajectories(trajs) print('Number of trajectories after clean : {}'.format(len(trajs))) trajs = [Trajectory(traj, tid) for tid, traj in enumerate(trajs)] # Partitioning cluster_candidates_tls = [] tls_factory = TrajectoryLineSegmentFactory() for traj in trajs: p_indices = call_partition_trajectory(traj.pts) p_pts = filter_by_indices(p_indices, traj.pts) traj.p_pts = p_pts ls_list = get_ls_list(p_pts) if len(ls_list) <= 0: raise Exception() for ls in ls_list: tls = tls_factory.create(ls, traj.tid) cluster_candidates_tls.append(tls) print('Number of segments (cluster candidates) : {}'.format( len(cluster_candidates_tls))) # Clustering (DBSCAN) tls_index = BestAvailableClusterCandidateIndex(cluster_candidates_tls, eps) tcluster_factory = TrajectoryClusterFactory() tclusters = dbscan(tls_index, min_lns, tcluster_factory) print('Number of clusters : {}'.format(len(tclusters))) # Representative trajectory rtrajs = [] for tc in tclusters: if tc.get_num_of_trajs() >= min_traj: tls_list = tc.get_members() r_pts = get_rline_pts(tls_list, min_vline, min_prev_dist) rtraj = RepresentativeTrajectory(r_pts, tc.cid) rtrajs.append(rtraj) print('Number of representative trajectories : {}'.format(len(rtrajs))) result = { 'partitioned_trajectories': trajs, 'clusters': tclusters, 'representative_trajectories': rtrajs } return result
def test_dbscan(self): cluster_factory = ClusterFactory() for test_ob in self.test_cases: clusters = dbscan(test_ob['test_points'], test_ob['epsilon'], \ test_ob['min_neighbors'], cluster_factory) for expected in test_ob['expected_clusters']: self.assertTrue(self.find_single_matching_cluster(expected, clusters), \ "couldn't find matching cluster in " + str(test_ob) + \ " in clusters: " + str(clusters)) for point in test_ob['test_points']: self.assertTrue(point.is_classified()) for point in test_ob['expected_noise']: self.assertTrue(point.is_noise()) for single_cluster in clusters: for point in single_cluster.members: self.assertEqual(single_cluster, point.cluster) self.assertFalse(point.is_noise())
def _dbscan_caller(cluster_candidates): return dbscan(cluster_candidates=cluster_candidates, epsilon=epsilon, min_neighbors=min_neighbors, \ cluster_factory=TrajectoryClusterFactory())
def _dbscan_caller(cluster_candidates): line_seg_index = BestAvailableClusterCandidateIndex(cluster_candidates, epsilon) return dbscan(cluster_candidates_index=line_seg_index, #TrajectoryLineSegmentCandidateIndex(cluster_candidates), \ min_neighbors=min_neighbors, \ cluster_factory=TrajectoryClusterFactory())
def dbscan_caller(cluster_candidates): line_seg_index = TrajectoryLineSegmentCandidateIndex( cluster_candidates, epsilon) return dbscan(cluster_candidates_index=line_seg_index, #TrajectoryLineSegmentCandidateIndex(cluster_candidates), \ min_neighbors=min_neighbors, \ cluster_factory=TrajectoryClusterFactory())