utils

package
v0.0.0-...-e444672 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToInts

func BytesToInts(bys []byte) []int

func CalcDist

func CalcDist(set1, set2 mapset.Set) float32

func DeleteSlice

func DeleteSlice(list []string, ele string) []string

func FloatsToBytes

func FloatsToBytes(n []float64) []byte

func GenSet

func GenSet(s []string) mapset.Set

func IntsToBytes

func IntsToBytes(n []int) []byte

func ListAdd

func ListAdd(db *leveldb.DB, key []byte, item string) error

func ListDelete

func ListDelete(db *leveldb.DB, key []byte, item string) error

func ListExist

func ListExist(list []string, item string) bool

func PointInfo

func PointInfo(point Point, k int) string

func StringIn

func StringIn(strings string) []byte

func StringListToBytesList

func StringListToBytesList(strlist []string) [][]byte

func StringOut

func StringOut(bye []byte) string

Types

type Item

type Item struct {
	Id       string
	Distance float32
}

type ItemList

type ItemList []Item

func NewItemList

func NewItemList(len int) ItemList

func (*ItemList) Add

func (sl *ItemList) Add(id string, distance float32)

func (ItemList) Len

func (sl ItemList) Len() int

func (ItemList) Less

func (sl ItemList) Less(i, j int) bool

func (ItemList) Swap

func (sl ItemList) Swap(i, j int)

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) Close

func (index *LshForest) Close() error

func (*LshForest) Delete

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

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 Minhash

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

Minhash represents a MinHash object

func NewMinhash

func NewMinhash(seed int64, numHash int) *Minhash

NewMinhash initialize a MinHash object with a seed and the number of hash functions.

func (*Minhash) Merge

func (m *Minhash) Merge(o *Minhash)

Merge combines the signature of the other Minhash with this one, making this one carry the signature of the union.

func (*Minhash) Push

func (m *Minhash) Push(b []byte)

Push a new value to the MinHash object. The value should be serialized to byte slice.

func (*Minhash) Signature

func (m *Minhash) Signature() []uint64

Signature exports the MinHash as a list of hash values.

type Point

type Point []float64

func CompHash

func CompHash(taglist []string, size int) Point

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