lsh

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2017 License: MIT Imports: 5 Imported by: 1

README

LSH for Go

Build Status GoDoc DOI

Documentation

Install: go get github.com/ekzhu/lsh

This library includes various Locality Sensitive Hashing (LSH) algorithms for the approximate nearest neighbour search problem in L2 metric space. The family of LSH functions for L2 is the work of Mayur Datar et.al.

Currently includes:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicLsh

type BasicLsh struct {
	// contains filtered or unexported fields
}

BasicLsh implements the original LSH algorithm for L2 distance.

func NewBasicLsh

func NewBasicLsh(dim, l, m int, w float64) *BasicLsh

NewBasicLsh creates a basic LSH for L2 distance. dim is the diminsionality of the data, l is the number of hash tables to use, m is the number of hash values to concatenate to form the key to the hash tables, w is the slot size for the family of LSH functions.

func (*BasicLsh) Insert

func (index *BasicLsh) Insert(point Point, id string)

Insert adds a new data point to the LSH. id is the unique identifier for the data point.

func (*BasicLsh) Query

func (index *BasicLsh) Query(q Point) []string

Query finds the ids of approximate nearest neighbour candidates, in un-sorted order, given the query point,

type LshForest

type LshForest struct {
	// contains filtered or unexported fields
}

LshForest implements the LSH Forest algorithm by Mayank Bawa et.al. It supports both nearest neighbour candidate query and k-NN query.

func NewLshForest

func NewLshForest(dim, l, m int, w float64) *LshForest

NewLshForest creates a new LSH Forest for L2 distance. dim is the diminsionality of the data, l is the number of hash tables to use, m is the number of hash values to concatenate to form the key to the hash tables, w is the slot size for the family of LSH functions.

func (*LshForest) Insert

func (index *LshForest) Insert(point Point, id string)

Insert adds a new data point to the LSH Forest. id is the unique identifier for the data point.

func (*LshForest) Query

func (index *LshForest) Query(q Point, k int) []string

Query finds at top-k ids of approximate nearest neighbour candidates, in unsorted order, given the query point.

type MultiprobeLsh

type MultiprobeLsh struct {
	*BasicLsh
	// contains filtered or unexported fields
}

MultiprobeLsh implements the Multi-probe LSH algorithm by Qin Lv et.al. The Multi-probe LSH does not support k-NN query directly.

func NewMultiprobeLsh

func NewMultiprobeLsh(dim, l, m int, w float64, t int) *MultiprobeLsh

NewMultiprobeLsh creates a new Multi-probe LSH for L2 distance. dim is the diminsionality of the data, l is the number of hash tables to use, m is the number of hash values to concatenate to form the key to the hash tables, and w is the slot size for the family of LSH functions. t is the number of perturbation vectors that will be applied to each query. Increasing t increases the running time of the Query function.

func (*MultiprobeLsh) Query

func (index *MultiprobeLsh) Query(q Point) []string

Query finds the ids of nearest neighbour candidates, given the query point

type Point

type Point []float64

Point is a vector in the L2 metric space.

func (Point) Dot

func (p Point) Dot(q Point) float64

Dot returns the dot product of two points.

func (Point) L2

func (p Point) L2(q Point) float64

L2 returns the L2 distance of two points.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL