Git Product home page Git Product logo

go-fcm's Introduction

go-fcm

GoDoc Fuzzy C-Means Clustering for Golang allowing custom data types

Usage

import(
    "math"
    "github.com/lhhong/go-fcm/fcm"
) 

// Your current data structure
type Point struct {
	X float64
	Y float64
}

// Your current data
var points []Point = []Point{
    {X: 0.3, Y: 0.2},
    {X: 0.2, Y: 0.3},
    ...
}

// To implement Interface containing Multiply, Add and Norm
// Custom operators can be defined for different data types
type FcmPoint Point

// Multiplying a data point with a scalar weight
func (p FcmPoint) Multiply(weight float64) fcm.Interface {
	return FcmPoint{
		X: weight * p.X,
		Y: weight * p.Y,
	}
}

// Adding 2 data points together
func (p FcmPoint) Add(p2I fcm.Interface) fcm.Interface {
    p2 := p2I.(FcmPoint)
	return FcmPoint{
		X: p2.X + p.X,
		Y: p2.Y + p.Y,
	}
}

// Evaluating distance measure between 2 data points
func (p FcmPoint) Norm(p2I fcm.Interface) float64 {
    p2 := p2I.(FcmPoint)
	xDiff := p.X - p2.X
	yDiff := p.Y - p2.Y
	return math.Sqrt(math.Pow(xDiff, 2.0) + math.Pow(yDiff, 2.0))
}

func main() {

    // Map your own data slice to the structure implementing fcm.Interface
	fcmPoints := make([]fcm.Interface, len(points))
	for i, p := range points {
		fcmPoints[i] = FcmPoint(p)
	}

    // Retrieve centroids and weights of each (centroid, data point) pair
	centroids, weights := fcm.Cluster(fcmPoints, 2.0, 0.00001, 3)
}

go-fcm's People

Contributors

lhhong avatar

Stargazers

 avatar  avatar

Watchers

 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.