15 #include <unordered_map>
18 #include "mlpack/methods/dbscan.hpp"
29 template <
typename track_container_t,
typename traj_t,
30 template <
typename>
class holder_t>
32 std::multimap<
int, std::pair<
int, std::vector<int>>>& trackMap,
34 float epsilon = 0.07,
int minPoints = 2) {
37 std::unordered_map<int, std::vector<int>> cluster;
40 std::unordered_map<int, int> hitToTrack;
43 mlpack::DBSCAN dbscan(epsilon, minPoints);
45 arma::mat
data(2, trackMap.size());
47 arma::Row<size_t> assignments;
50 for (
const auto& [key, val] : trackMap) {
51 auto traj = tracks.getTrack(val.first);
56 size_t clusterNb = dbscan.Cluster(
data, assignments);
60 std::vector<std::multimap<int, std::pair<int, std::vector<int>>>>
61 dbscanClusters(clusterNb);
62 for (
const auto& [key, val] : trackMap) {
63 int clusterID = assignments(trackID);
64 if (assignments(trackID) == SIZE_MAX) {
65 cluster.emplace(val.first, std::vector<int>(1, val.first));
67 dbscanClusters[clusterID].emplace(key, val);
74 for (
const auto& dbscanCluster : dbscanClusters) {
76 cluster.merge(subCluster);
77 if (!subCluster.empty()) {
78 std::cout <<
"Overlapping track ID, there must be an error" << std::endl;