vptree

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Metric

type Metric func(a, b interface{}) float64

A Metric is a function that measures the distance between two provided interface{}-values. The function *must* be a metric in the mathematical sense, that is, the metric d must fullfill the following requirements:

  • d(x, y) >= 0
  • d(x, y) = 0 if and only if x = y
  • d(x, y) = d(y, x)
  • d(x, z) <= d(x, y) + d(y, z) (triangle inequality)

type TreeItem

type TreeItem interface {
	Distance(TreeItem) float64
}

type VPTree

type VPTree struct {
	Root   *node
	Length int
}

A VPTree struct represents a Vantage-point tree. Vantage-point trees are useful for nearest-neighbour searches in high-dimensional metric spaces.

func New

func New(items []TreeItem) (t *VPTree)

New creates a new VP-tree using the metric and items provided. The metric measures the distance between two items, so that the VP-tree can find the nearest neighbour(s) of a target item.

func (*VPTree) Search

func (vp *VPTree) Search(target TreeItem, k int) (results []TreeItem, distances []float64)

Search searches the VP-tree for the k nearest neighbours of target. It returns the up to k narest neighbours and the corresponding distances in order of least distance to largest distance.

Jump to

Keyboard shortcuts

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