flanders

package module
v0.0.0-...-7234ff7 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2016 License: MIT Imports: 7 Imported by: 0

README

Flanders

🚧 🚧 🚧

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Element

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

func NewElement

func NewElement(node *Node, priority float64) *Element

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 NewIndex

func NewIndex(dim int) *Index

NewIndex contructs a new empty index able to store vectors of dimension 'dim'.

func (*Index) Add

func (i *Index) Add(item Item) error

Add adds an item prior the construction of the random projections trees.

func (*Index) Build

func (i *Index) Build(numTrees int) error

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 Items

type Items []*Item

Items is a slice of items.

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 Neighbors

type Neighbors []*Neighbor

Neighbors is a slice of neighbors.

func (Neighbors) Len

func (n Neighbors) Len() int

func (Neighbors) Less

func (n Neighbors) Less(i, j int) bool

func (Neighbors) Swap

func (n Neighbors) Swap(i, j int)

type Node

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

func (*Node) Ids

func (n *Node) Ids() []string

func (*Node) IsLeaf

func (n *Node) IsLeaf() bool

func (*Node) Left

func (n *Node) Left() *Node

func (*Node) Name

func (n *Node) Name() string

func (*Node) Right

func (n *Node) Right() *Node

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.

func (*RPTree) Build

func (t *RPTree) Build(items Items) error

Build is the method which builds recursively the random partition tree given all the items to store.

func (*RPTree) GetCandidates

func (t *RPTree) GetCandidates(vector []float64, k int) ([]string, error)

GetCandidates returns a set of identifier of items prone to be near neighbors.

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.

type SearchResult

type SearchResult struct {
	Neighbors Neighbors     // the approximate nearest neighbors found
	Evaluated int           // number of evaluated vectors
	Duration  time.Duration // the duration of the search
}

SearchResult contains approximate neighbors and metadata.

type Side

type Side int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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