Documentation
¶
Index ¶
- func CosineDistance(p1, p2 *Point) float32
- func EuclideanDistance(p1, p2 *Point) float32
- type BoundStrategy
- type DistanceFunc
- type DistanceFunction
- type Neighbor
- type Neighbors
- type Node
- type Point
- type Tree
- func (t *Tree[T]) DecodeBinary(r io.Reader, decodeValue func(io.Reader) (T, error)) error
- func (t *Tree[T]) DistanceFunction() DistanceFunction
- func (t *Tree[T]) EncodeBinary(w io.Writer, encodeValue func(io.Writer, T) error) error
- func (t *Tree[T]) FindPointByIndex(index int32) *Point
- func (t *Tree[T]) ForEach(fn func(value T, point *Point))
- func (t *Tree[T]) Insert(value T, point *Point) int32
- func (t *Tree[T]) KNearestNeighbors(point *Point, k int) []*Neighbor
- func (t *Tree[T]) KNearestNeighborsBestFirst(point *Point, k int) []*Neighbor
- func (t *Tree[T]) SetBoundStrategy(s BoundStrategy)
- func (t *Tree[T]) Value(point *Point) T
- func (t *Tree[T]) Values(points []*Point) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CosineDistance ¶
CosineDistance returns the cosine distance (1 - cosine similarity).
func EuclideanDistance ¶
EuclideanDistance returns the Euclidean distance between two points.
Types ¶
type BoundStrategy ¶
type BoundStrategy int
BoundStrategy selects which lower-bound radius to use when pruning.
const ( // BoundPerNode uses cached per-node subtree radius (tighter pruning). BoundPerNode BoundStrategy = iota // BoundLevel uses a geometric bound derived from the node level. BoundLevel )
type DistanceFunc ¶
DistanceFunc computes the distance between two points.
type DistanceFunction ¶
type DistanceFunction string
DistanceFunction enumerates supported distance metrics for the cover tree.
const ( DistanceFunctionCosine DistanceFunction = "cosine" DistanceFunctionEuclidean DistanceFunction = "euclidean" )
func (DistanceFunction) Function ¶
func (d DistanceFunction) Function() DistanceFunc
Function resolves the callable distance implementation.
type Neighbors ¶
type Neighbors []Neighbor
Neighbors implements heap.Interface sorted by descending distance (max-heap).
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node represents a cover-tree node.
type Point ¶
Point represents a vector in the cover tree.
type Tree ¶
type Tree[T any] struct { // contains filtered or unexported fields }
Tree represents a cover tree for cosine/euclidean kNN queries.
func NewTree ¶
func NewTree[T any](base float32, distanceFn DistanceFunction) *Tree[T]
NewTree constructs a cover tree with the provided base and distance metric.
func (*Tree[T]) DecodeBinary ¶
DecodeBinary reconstructs the tree from the binary stream.
func (*Tree[T]) DistanceFunction ¶
func (t *Tree[T]) DistanceFunction() DistanceFunction
DistanceFunction reports the configured distance metric.
func (*Tree[T]) EncodeBinary ¶
EncodeBinary writes the tree (structure + values) using the provided encoder.
func (*Tree[T]) FindPointByIndex ¶
FindPointByIndex returns the point for a stored index.
func (*Tree[T]) KNearestNeighbors ¶
KNearestNeighbors runs a depth-first kNN search.
func (*Tree[T]) KNearestNeighborsBestFirst ¶
KNearestNeighborsBestFirst performs a best-first search with a node priority queue.
func (*Tree[T]) SetBoundStrategy ¶
func (t *Tree[T]) SetBoundStrategy(s BoundStrategy)
SetBoundStrategy switches the pruning strategy at runtime.