cosine

package
v0.0.0-...-392332c Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckCUDA

func CheckCUDA() bool

CheckCUDA checks if CUDA is available on the system.

func CosineSimilarity

func CosineSimilarity(v1, v2 *Vector, useGPU bool) (float64, error)

CosineSimilarity calculates the cosine similarity between two vectors. If CUDA is available, it will use GPU for computation.

func GPUDotProduct

func GPUDotProduct(v1, v2 *gorgonia.Node) (*gorgonia.Node, error)

GPUDotProduct calculates the dot product using GPU (if available).

func TextSimilarity

func TextSimilarity(text1, text2 string) (float64, error)

TextSimilarity calculates the cosine similarity between two texts by converting them into vectors first.

Types

type Vector

type Vector struct {
	mat.Sparse
}

Vector represents a vector in n-dimensional space.

func NewVectorFromText

func NewVectorFromText(text string) *Vector

NewVectorFromText creates a new vector from a given text by tokenizing it into words and counting their occurrences.

func (*Vector) DotProduct

func (v *Vector) DotProduct(other *Vector) float64

DotProduct calculates the dot product of two vectors.

func (*Vector) Magnitude

func (v *Vector) Magnitude() float64

Magnitude calculates the magnitude (Euclidean norm) of a vector.

func (*Vector) String

func (v *Vector) String() string

String returns a string representation of the vector.

Jump to

Keyboard shortcuts

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