Code Monkey home page Code Monkey logo

dbscan's Introduction

DBSCAN

Implementation of DBSCAN Algorithm in C++,This implementation can cluster data of any dimension. The distance of data points is Euclidean distance, but you can also modify it to your own distance. In order to speed up the algorithm, I applied the ANN library and used the kd_tree data structure to increase the search speed.

BUILD

cd project_dir
mkdir build
cd build
cmake ..
make -j12

then a libary file will genrate in lib directory, The header file is in the include directory。

OPTIONS

I also wrote a sample, you can open the compilation option BUILD_DBSCAN_SAMPLE through the ccmake command. After compilation, a dbscan executable file will be generated in the bin directory, run the executable file in the bin directory, the program will read the test data from the dataset directory test_data.pts file, and then cluster and write the results to the dataset The dbscan-res.pts file is in the directory.

cd project_dir
mkdir build
cd build
cmake ..
ccmake .
Configure BUILD_DBSCAN_SAMPLE to ON
make -j12
cd ../bin
./dbscan

Visualize the results

cd ../python
python vis_result.py

The result will be drawn res

EXAMPLE

#include <cstdlib>						// C standard library
#include <cstdio>						// C I/O (for sscanf)
#include <cstring>						// string manipulation
#include <fstream>	                    // file I/O
#include <iostream>
#include <vector>
#include "ANN/impl/dbscan.hpp"

int	main(int argc, char **argv)
{
    std::string data_file = "../dataset/test_data.pts";
    std::fstream data_in ;
    data_in.open(data_file, std::ios::in);

    std::vector<std::vector<double>> pts;
    for(int i = 0; i < 500; i++)
    {
        double x, y;
        data_in>>x;
        data_in>>y;
        std::vector<double> pt;
        pt.push_back(x);
        pt.push_back(y);
        pts.push_back(pt);
    }

    dbscan::Dbscan<double> scan = dbscan::Dbscan<double>(2,0.0576,20);
    scan.Run(pts);
    std::vector<std::vector<std::vector<double>>>  res;
    scan.GetCluster(res);
    std::fstream data_out;
    data_out.open("../dataset/dbscan-res.pts", std::ios::out);
    for(std::vector<std::vector<double>> cluter : res)
    {
        data_out<<"@@##@@"<<std::endl;
        for(std::vector<double> pt : cluter)
        {
            data_out<<pt[0]<<" "<<pt[1]<<std::endl;
        }

    }
    data_out.close();
    data_in.close();
   // system("pause");
    return 0;
}

Q&A

If you have any questions, please send me an email at [email protected]

dbscan's People

Contributors

mesh-pch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.