lsh

package
v0.0.0-...-c6ab6ab Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DistanceErr = errors.New("Distance can't be calculated")
)

Functions

func AngularToCosineDist

func AngularToCosineDist(angular float64) float64

func ConvertTo64

func ConvertTo64(ar []float32) []float64

ConvertTo64 __

func ConvertToInt

func ConvertToInt(ar []int32) []int

ConvertToInt __

func CosineDistToAngular

func CosineDistToAngular(cosine float64) float64

func GetMeanStdSampled

func GetMeanStdSampled(data [][]float64, sampleSize int) ([]float64, []float64, error)

GetMeanStd returns mean and std based on incoming NxM matrix

func GetMeanStdSampledRecords

func GetMeanStdSampledRecords(vecs [][]float64, sampleSize int) ([]float64, []float64, error)

GetMeanStdSampledRecords duplucate of GetMeanStdSample but for the Record data type, must be refactored later

func NewVec

func NewVec(data []float64) blas64.Vector

NewVec creates new blas vector

Types

type Angular

type Angular bool

Angular calculates cosine distance between two given vectors

func NewAngular

func NewAngular() Angular

func (Angular) GetDist

func (c Angular) GetDist(l, r []float64) float64

NOTE: just regular cosine distance

func (Angular) IsAngular

func (c Angular) IsAngular() bool

type Config

type Config struct {
	IndexConfig
	HasherConfig
}

Config holds all needed constants for creating the Hasher instance

type Hasher

type Hasher struct {
	Config HasherConfig
	// contains filtered or unexported fields
}

Hasher holds N_PERMUTS number of trees

func NewHasher

func NewHasher(config HasherConfig) *Hasher

type HasherConfig

type HasherConfig struct {
	NTrees   int
	KMinVecs int
	Dims     int
	// contains filtered or unexported fields
}

type IndexConfig

type IndexConfig struct {
	BatchSize     int
	MaxCandidates int
	// contains filtered or unexported fields
}

IndexConfig ...

type Indexer

type Indexer interface {
	Train(vecs [][]float64, ids []string) error
	Search(query []float64, maxNN int, distanceThrsh float64) ([]Neighbor, error)
}

Indexer holds implementation of NN search index

type L2

type L2 bool

L2 calculates l2-distance between two vectors

func NewL2

func NewL2() L2

func (L2) GetDist

func (l2 L2) GetDist(l, r []float64) float64

func (L2) IsAngular

func (l2 L2) IsAngular() bool

type LSHIndex

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

LSHIndex holds buckets with vectors and hasher instance

func NewLsh

func NewLsh(config Config, store store.Store, metric Metric) (*LSHIndex, error)

New creates new instance of hasher and index, where generated hashes will be stored

func (*LSHIndex) DumpHasher

func (lsh *LSHIndex) DumpHasher() ([]byte, error)

DumpHasher serializes hasher

func (*LSHIndex) LoadHasher

func (lsh *LSHIndex) LoadHasher(inp []byte) error

LoadHasher fills hasher from byte array

func (*LSHIndex) Search

func (lsh *LSHIndex) Search(query []float64, maxNN int, distanceThrsh float64) ([]Neighbor, error)

Search returns NNs for the query point

func (*LSHIndex) Train

func (lsh *LSHIndex) Train(vecs [][]float64, ids []string) error

Train fills new search index with vectors

type Metric

type Metric interface {
	GetDist(l, r []float64) float64
	IsAngular() bool
}

Metric holds implementation of needed distance metric

type Neighbor

type Neighbor struct {
	Vec  []float64
	ID   string
	Dist float64
}

Neighbor represent neighbor vector with distance to the query vector

type NeighborMinHeap

type NeighborMinHeap []*Neighbor

func (NeighborMinHeap) Len

func (h NeighborMinHeap) Len() int

func (NeighborMinHeap) Less

func (h NeighborMinHeap) Less(i, j int) bool

func (*NeighborMinHeap) Pop

func (h *NeighborMinHeap) Pop() interface{}

func (*NeighborMinHeap) Push

func (h *NeighborMinHeap) Push(x interface{})

func (NeighborMinHeap) Swap

func (h NeighborMinHeap) Swap(i, j int)

type StandartScaler

type StandartScaler struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

StandartScaler ...

func NewStandartScaler

func NewStandartScaler(mean, std []float64, nDims int) *StandartScaler

func (*StandartScaler) Scale

func (s *StandartScaler) Scale(vec []float64) blas64.Vector

type StringSet

type StringSet struct {
	Items map[string]bool
	// contains filtered or unexported fields
}

func NewStringSet

func NewStringSet() *StringSet

func (*StringSet) Get

func (s *StringSet) Get(key string) bool

func (*StringSet) Remove

func (s *StringSet) Remove(key string)

func (*StringSet) Set

func (s *StringSet) Set(key string)

Jump to

Keyboard shortcuts

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