Cosine returns the cosine similarity between a vector and another.
(b *Record)
| 96 | |
| 97 | // Cosine returns the cosine similarity between a vector and another. |
| 98 | func (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. |
| 107 | func (w *Record) CosineSub(b *Record, elems uint) float64 { |