Git Product home page Git Product logo

dbscan's Introduction

DBSCAN

DBSCAN Clustering Algorithm C# Implementation

It is a small project that implements DBSCAN Clustering algorithm in C# and dotnet-core.

For using this you only need to define your own dataset class and create DbscanAlgorithm class to perform clustering. After that only call the ComputeClusterDbscan with desired clustering parameter.

You can check previous git tags for more primitive DBSCAN implementation.

Example:

Your dataset items (preference, feature, vector, row, etc.):

public class MyCustomFeature
{
    public double X;
    public double Y;

    public MyCustomFeature(double x, double y)
    {
        X = x;
        Y = y;
    }
}

Your Distance Function

private static double EuclidienDistance(MyFeature feature1, MyFeature feature2)
{
    return Math.Sqrt(
            ((feature1.X - feature2.X) * (feature1.X - feature2.X)) +
            ((feature1.Y - feature2.Y) * (feature1.Y - feature2.Y))
        );
}

Then for clustering with simple form

var features = new MyFeatureDataSource().GetFeatureData();

//INFO: applied euclidean distance as metric calculation function
var simpleDbscan = new DbscanAlgorithm<MyFeature>(EuclidienDistance);

//returns DbscanResult typed object of algorithm's process
var result = dbscan.ComputeClusterDbscan(allPoints: features.ToArray(), epsilon: .01, minimumPoints: 10);

If you want to get events happening inside algorithm then you can create algorithm with other constructor which takes a publisher type as instance

//INFO: second argument of constructor takes an instance implemented with IDbscanEventPublisher interface
var dbscanWithEventing = new DbscanAlgorithm<MyFeature>(
        EuclidienDistance,
        new MyFeatureConsoleLogger()
    );

var resultWithEventing = dbscanWithEventing.ComputeClusterDbscan(allPoints: features.ToArray(), epsilon: .01, minimumPoints: 10);

An example of the implementation for IDbscanEventPublisher interface:

public class DbscanLogger : IDbscanEventPublisher
{
    public void Publish(params object[] events)
    {
        foreach (var e in events)
        {
            //INFO: match the events you want to process
            var info = e switch
            {
                PointTypeAssigned<MyCustomFeature> pta => $"{pta.Point.ClusterId}: {pta.AssignedType}",
                _ => null
            };

            if (info != null)
            {
                Console.WriteLine(info);
            }
        }
    }
}

Another example of IDbscanEventPublisher could be a Pub/Sub application, like this:

var exchange = new QueueExchange<object>();

var publisher = new QueueExchangePublisher(exchange);

var dbscanAsync = new DbscanAlgorithm<MyFeature>(
    EuclidienDistance,
    publisher
);

var subscriber = new QueueExchangeSubscriber<object, MyFeature>(exchange);

var subscriptionTask = subscriber.Subscribe();

This can be anything that succeeds the Pub/Sub design. You can asyncronously build your own analytics result by subscription.

dbscan's People

Contributors

yusufuzun avatar gf-huang 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.