Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:56

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Utilities/DBScan.hpp"
0012 
0013 #include <algorithm>
0014 #include <array>
0015 #include <cstddef>
0016 #include <iterator>
0017 #include <string>
0018 #include <utility>
0019 #include <vector>
0020 
0021 namespace {
0022 // Test vector of 2D points generated from the make_blobs function of
0023 // scikit-learn to correspond to 4 clusters with a standard deviation of 0.3
0024 std::vector<std::array<double, 2>> test_vector{
0025     {-2.83739915, 2.62792556},  {-2.02847331, -1.90722196},
0026     {4.42609249, -2.42439165},  {-2.54167208, -1.31586441},
0027     {-2.74072011, 1.88175176},  {-2.44805173, -1.72270269},
0028     {4.32373114, -3.04946856},  {-3.02908065, 3.05502207},
0029     {4.21551681, -2.72367792},  {6.94454243, -8.26702198},
0030     {4.57729285, -2.98832874},  {-2.05999536, -1.60664607},
0031     {7.29942963, -7.49254664},  {-1.76560555, -1.94316957},
0032     {-3.08697607, 2.38012823},  {-2.68133439, -1.96863594},
0033     {-3.04707961, 2.42381653},  {-1.6693666 - 1.98996212},
0034     {4.87565038, -2.42067792},  {6.57829525 - 8.14269767},
0035     {-1.89777458, -1.71029565}, {-2.82010574, 2.27963425},
0036     {-1.8938416, -1.76676642},  {-2.8088788, 2.14373147},
0037     {-2.7111892, 2.7343114},    {5.00997563, -3.03311654},
0038     {-3.00272791, 1.59086316},  {-2.69800242, 2.19671366},
0039     {5.35757875, -2.98359632},  {6.41134781, -7.79582109},
0040     {5.06123223, -2.84952632},  {6.33969189, -7.83811637},
0041     {5.11101701, -2.80965778},  {7.01442234, -7.47047664},
0042     {6.82239627, -7.97467806},  {6.82647513, -7.64299033},
0043     {-2.02651791, -1.81791892}, {-2.53859699, -2.20157508},
0044     {5.07240334, -2.48183097},  {-1.58869273, -2.30974576},
0045     {5.24011121, -2.78045434},  {4.89256735, -2.98154234},
0046     {-2.61589554, -1.38994103}, {-2.37898031, 2.02633106},
0047     {6.71148996, -7.87697906},  {-2.24310299, -2.01958434},
0048     {4.80875851, -3.00716459},  {-2.20240163, -1.45942015},
0049     {5.0317719, -3.33571147},   {4.68497184, -2.2794554},
0050     {6.57950453, -7.84613618},  {-2.39557904, -0.97990746},
0051     {4.89489222, -3.31597619},  {5.22670358, -2.79577779},
0052     {4.87625814, -2.70562793},  {5.37121464, -2.78439938},
0053     {6.48510206, -7.89652351},  {-2.78153003, 1.79940689},
0054     {6.80163025, -7.7267214},   {-2.42494396, -1.95543603},
0055     {7.01502605, -7.93922357},  {-2.00219795, -1.95198446},
0056     {-2.82690524, 1.83749478},  {-2.81153684, 2.30020325},
0057     {-1.46316156, -1.70854783}, {-2.36754202, -1.62836379},
0058     {-3.12179904, 1.86079695},  {-2.80228975, 2.16674687},
0059     {7.25447808, -7.87780152},  {6.34182023, -7.72244414},
0060     {6.85296593, -7.6565112},   {6.40782187, -7.95817435},
0061     {4.60981662, -2.6214774},   {6.82470403, -7.8453859},
0062     {-2.94909893, 2.4408267},   {6.48588252, -8.42529572},
0063     {6.55194867, -7.54354929},  {-2.64178285, 2.28031333},
0064     {-1.95664147, -2.44817923}, {-2.00957937, -2.01412199},
0065     {-2.24603999, 2.48964234},  {4.73274418, -2.89077558},
0066     {-2.47534453, 1.85935482},  {-2.35722712, -1.99652695},
0067     {5.15661108, -2.88549784},  {6.68114631, -7.73743642},
0068     {4.93268708, -2.97510717},  {6.54260932, -8.82618456},
0069     {-3.57448792, 2.06852256},  {6.63296723, -8.32752766},
0070     {-3.58610661, 2.2761471},   {-2.73077783, 1.8138345},
0071     {-2.14150912, 1.94984708},  {-2.27235876, -1.67574786},
0072     {6.92208545, -8.46326386},  {4.58953972, -3.22764749},
0073     {-3.36912131, 2.58470911},  {5.28526348, -2.55723196},
0074     {6.55276593, -7.81387909},  {-1.79854507, -2.10170986}};
0075 }  // namespace
0076 
0077 namespace Acts::Test {
0078 
0079 BOOST_AUTO_TEST_CASE(ClusteringTest2D) {
0080   using DBSCAN = Acts::DBScan<2, double, 4>;
0081   DBSCAN dbscan(0.3, 3, false);
0082 
0083   DBSCAN dbscan_onePoint(0, 3, true);
0084 
0085   std::vector<int> clusteredPoints;
0086 
0087   // Test the clustering we expect 4 clusters
0088   int clusterNb = dbscan.cluster(test_vector, clusteredPoints);
0089   BOOST_CHECK_EQUAL(clusterNb, 4);
0090 
0091   clusteredPoints.clear();
0092 
0093   // Check that it works with empty input
0094   std::vector<std::array<double, 2>> empty_vector;
0095   clusterNb = dbscan.cluster(empty_vector, clusteredPoints);
0096   BOOST_CHECK_EQUAL(clusterNb, 0);
0097 
0098   clusteredPoints.clear();
0099 
0100   clusterNb = dbscan_onePoint.cluster(test_vector, clusteredPoints);
0101   BOOST_CHECK_EQUAL(clusterNb, test_vector.size());
0102 
0103   clusteredPoints.clear();
0104 }
0105 
0106 }  // namespace Acts::Test