Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Naive implementation of the Mahalanobis distance using go.matrix
Go
tree: 2d66203b8a

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
README.txt
mahalanobis.go
mahalanobis_test.go

README.txt

PACKAGE

package mahalanobis
    import "github.com/ant0ine/go.mahalanobis"

    Naive implementation of the Mahalanobis distance using go.matrix
    (https://en.wikipedia.org/wiki/Mahalanobis_distance)

    This is me learning Go, it's probably broken, don't use it.

    Example:

	package main
	import (
	    "fmt"
	    "github.com/skelterjohn/go.matrix"
	    "github.com/ant0ine/go.mahalanobis"
	)
	func main() {
	    points, err := matrix.ParseMatlab("[1 4 3 4;4 2 3 4]")
	    if err != nil {
	    panic(err)
	    }
	    fmt.Println("4 points:\n", points)
	    target, err := matrix.ParseMatlab("[3;4]")
	    if err != nil {
	        panic(err)
	    }
	    fmt.Println("the target point:\n", target)
	    distance, err := mahalanobis.Distance(points, target)
	    if err != nil {
	        panic(err)
	    }
	    fmt.Println("Mahalanobis distance=", distance)
	}

FUNCTIONS

func CovarianceMatrix(points *matrix.DenseMatrix) *matrix.DenseMatrix
    Return the covariance matrix for this set of points (sample covariance
    is used)

func Distance(points, target *matrix.DenseMatrix) (float64, error)
    Return the Mahalanobis distance

func DistanceSquare(points, target *matrix.DenseMatrix) (float64, error)
    Return the square of the Mahalanobis distance

func MeanVector(points *matrix.DenseMatrix) *matrix.DenseMatrix
    Given a set a points, return the mean vector.


Something went wrong with that request. Please try again.