Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hyperplane ¶
type Hyperplane struct {
// contains filtered or unexported fields
}
An Hyperplane is defined as the set of points H = { x : w.(x-x0) = 0 }
func NewHyperplane ¶
func NewHyperplane(vector []float64, origin []float64) (*Hyperplane, error)
NewHyperplane returns an hyperplane as defined above.
func (*Hyperplane) Side ¶
func (h *Hyperplane) Side(sim float64) Side
Side returns the side of the vector.
func (*Hyperplane) Similarity ¶
func (h *Hyperplane) Similarity(vector []float64) (float64, error)
Similarity returns the similarity between a vector and the hyperplane.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
An Index provides methods to efficiently store items and search among them for approximate nearest neighbors.
func (*Index) Build ¶
Build creates several random projections trees containing the dataset of Items.
func (*Index) Search ¶
func (i *Index) Search(vector []float64, k int) (*SearchResult, error)
Search looks up into the random projection trees to find the nearest neighbors of the input vector.
First, it reaches the leaves containing the nearest candidates. Then it computes the distance of all the candidates.
type Item ¶
type Item struct { ID string // the identifier of the vector Vector []float64 // the vector itself }
An Item wraps a vector with an identifier to store into an index.
type Neighbor ¶
type Neighbor struct { ID string // the identifier Distance float64 // the distance between the neighbor and the search vector }
A Neighbor represents a neighbor found during the search.
type Partitionner ¶
type Partitionner interface { // Partition splits a set of items into two subsets. Partition(Items) (*Hyperplane, Items, Items, error) }
A Partitionner is responsible of partitionning a vector space.
type PriorityQueue ¶
type PriorityQueue []*Element
func NewPriorityQueue ¶
func NewPriorityQueue() PriorityQueue
func (PriorityQueue) Len ¶
func (pq PriorityQueue) Len() int
func (PriorityQueue) Less ¶
func (pq PriorityQueue) Less(i, j int) bool
func (*PriorityQueue) Pop ¶
func (pq *PriorityQueue) Pop() interface{}
func (*PriorityQueue) Push ¶
func (pq *PriorityQueue) Push(el interface{})
func (PriorityQueue) Swap ¶
func (pq PriorityQueue) Swap(i, j int)
type RPTree ¶
type RPTree struct {
// contains filtered or unexported fields
}
An RPTree stands for a random partition tree. It is a data structure which provides quick approximate nearest neighbors lookup.
It is built recursively by partitionning a vector space into two subspaces. The recursion is stopped when all subspaces contain less than a fixed number of items.
func NewRPTree ¶
func NewRPTree(partitionner Partitionner) *RPTree
NewRPTree instantiates an RPTree with a partitionner.
type RandomPartitionner ¶
type RandomPartitionner struct{}
A RandomPartitionner is a partitionner which splits data with a random hyperplane.
func NewRandomPartitionner ¶
func NewRandomPartitionner() *RandomPartitionner
NewRandomPartitionner creates a random partitionner.
func (*RandomPartitionner) Partition ¶
func (p *RandomPartitionner) Partition(items Items) (*Hyperplane, Items, Items, error)
Partition splits the vector space of the items into two subspaces separated by an hyperplane.