MCPcopy Create free account
hub / github.com/evilsocket/sum / Cosine

Method Cosine

wrapper/record.go:98–104  ·  view source on GitHub ↗

Cosine returns the cosine similarity between a vector and another.

(b *Record)

Source from the content-addressed store, hash-verified

96
97// Cosine returns the cosine similarity between a vector and another.
98func (w *Record) Cosine(b *Record) float64 {
99 cos := 0.0
100 if den := w.Magnitude() * b.Magnitude(); den != 0.0 {
101 cos = w.Dot(b) / den
102 }
103 return cos
104}
105
106// CosineSub returns the cosine similarity between a vector and another using up until the specificed number of elements.
107func (w *Record) CosineSub(b *Record, elems uint) float64 {

Calls 2

MagnitudeMethod · 0.95
DotMethod · 0.95