|
Boost-Commit : |
From: franklin.jonathan_at_[hidden]
Date: 2008-05-14 18:55:40
Author: jfranklin
Date: 2008-05-14 18:55:40 EDT (Wed, 14 May 2008)
New Revision: 45374
URL: http://svn.boost.org/trac/boost/changeset/45374
Log:
Added a naive test program for dbscan.
Added:
sandbox/cluster/libs/algorithm/cluster/src/dbscan.cpp (contents, props changed)
Added: sandbox/cluster/libs/algorithm/cluster/src/dbscan.cpp
==============================================================================
--- (empty file)
+++ sandbox/cluster/libs/algorithm/cluster/src/dbscan.cpp 2008-05-14 18:55:40 EDT (Wed, 14 May 2008)
@@ -0,0 +1,86 @@
+#include <boost/algorithm/cluster/dbscan.hpp>
+#include <boost/test/minimal.hpp>
+#include <vector>
+#include <cmath>
+
+using namespace boost::algorithm::cluster;
+using namespace std;
+
+typedef pair<float, float> two_tuple;
+
+static float norm2_dist(two_tuple const & p1, two_tuple const & p2)
+{
+ float const d = ::sqrt(
+ ::pow(static_cast<double>(p2.first - p1.first), 2.) +
+ ::pow(static_cast<double>(p2.second - p1.second), 2.));
+
+ return d;
+}
+
+int test_main(int, char *[])
+{
+ typedef vector<two_tuple> tuple_data;
+ typedef tuple_data::iterator tuple_data_iter;
+ typedef vector<tuple_data_iter> cluster;
+ typedef cluster_data<cluster> cluster_data;
+
+ tuple_data tuples(10);
+ BOOST_CHECK(10 == tuples.size());
+
+ for (size_t n = 0; n < 5; ++n)
+ tuples[n].second = 1.f;
+
+ cluster_data clustering;
+ BOOST_CHECK(clustering.empty());
+
+ float eps1 = 0.2f;
+ size_t min_points = 3;
+ clustering = dbscan<cluster>(
+ tuples.begin(), tuples.end(), eps1, min_points, norm2_dist);
+#if 0
+ cerr << "clusters=" << clustering.size() << "\n";
+ size_t c = 1;
+
+ for (cluster_data::iterator citer = clustering.begin();
+ citer != clustering.end();
+ ++citer)
+ {
+ cerr << "CLUSTER: " << c << "\n";
+ for (cluster::iterator it = citer->begin();
+ it != citer->end();
+ ++it)
+ {
+ cerr << " (" << (*it)->first << ", " << (*it)->second << ")\n";
+ }
+ ++c;
+ }
+#endif
+ BOOST_CHECK(2 == clustering.size());
+
+ float eps2 = 1.01f;
+ clustering = dbscan<cluster>(
+ tuples.begin(), tuples.end(), eps2, min_points, norm2_dist);
+
+#if 0
+ cerr << "clusters=" << clustering.size() << "\n";
+ c = 0;
+
+ for (cluster_data::iterator citer = clustering.begin();
+ citer != clustering.end();
+ ++citer)
+ {
+ cerr << "CLUSTER: " << c << "\n";
+ for (cluster::iterator it = citer->begin();
+ it != citer->end();
+ ++it)
+ {
+ cerr << " (" << (*it)->first << ", " << (*it)->second << ")\n";
+ }
+ ++c;
+ }
+#endif
+
+ BOOST_CHECK(1 == clustering.size());
+
+ return 0;
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk