Documentation
¶
Overview ¶
Package gann can be used for approximate nearest neighbor search.
By calling gann.CreateNewIndex function, we can obtain a search index. Its interface is defined in gann.Index:
type Index interface { GetANNbyItemID(id int64, searchNum int, bucketScale float64) (ann []int64, err error) GetANNbyVector(v []float64, searchNum int, bucketScale float64) (ann []int64, err error) }
GetANNbyItemID allows us to pass id of specific item for search execution and instead GetANNbyVector allows us to pass a vector.
See README.md for more details.
Index ¶
Constants ¶
const ( AxisX = iota AxisY AxisZ AxisEnd )
const (
RadFactor = 0.017453292519943295
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Index ¶
type Index interface { // GetANNbyVector ... search approximate nearest neighbors by a given query vector GetANNbyVector(v PointAble, searchNum int, bucketScale float64) (ann []int, err error) }
func CreateNewIndex ¶
func CreateNewIndex(rawItems PointArray, dim, nTree, k int, m Metric) (Index, error)
CreateNewIndex build a new search index for given vectors. rawItems should consist of search target vectors and its slice index corresponds to the first argument id of GetANNbyItemID. For example, if we want to search approximate nearest neighbors of rawItems[3], it can simply achieved by calling index.GetANNbyItemID(3, ...).
dim is the dimension of target spaces. nTree and k are tunable parameters which affects performances of the index (see README.md for details.)
The last argument m is type of metric.Metric and represents the metric of the target search space. See https://godoc.org/github.com/mathetake/gann/metric for details.
type Metric ¶
type Metric interface { // CalcDistance ... calculates the distance between given vectors CalcDistance(v1, v2 []float64) float64 // GetSplittingVector ... calculates the splitting vector which becomes a node's vector in the index GetSplittingVector(vs [][]float64) []float64 // CalcDirectionPriority ... calculates the priority of the children nodes which can be used for determining // which way (right or left child) should go next traversal. The return values must be contained in [-1, 1]. CalcDirectionPriority(base, target []float64) float64 }
Metric is the interface of metrics which defines target search spaces.
func NewCosineMetric ¶
NewCosineMetric returns cosineDistance. NOTE: We assume that the given vectors are already normalized, i.e. the norm equals 1
type PointArray ¶
type PointNArray ¶
type PointNArray []PointN
func (PointNArray) At ¶
func (a PointNArray) At(i int) PointAble
func (PointNArray) Len ¶
func (a PointNArray) Len() int
type PointR3Array ¶
type PointR3Array []PointR3
func (PointR3Array) At ¶
func (a PointR3Array) At(i int) PointAble
func (PointR3Array) Len ¶
func (a PointR3Array) Len() int