SparseVector is an n-dimension sparse vector.
Very simple implementation with just the functions I needed at the time for Lunrelm.
Model stored in Dict with index as key.
Dimension of vector is not held, so there is no way to check that dot or cosineSimilarity are both using the same dimension vector.
Dict Basics.Int Basics.Float
SparseVector type alias
empty : SparseVector
Empty SparseVector
isEmpty : SparseVector -> Basics.Bool
Return true if vector is empty
insert : Basics.Int -> Basics.Float -> SparseVector -> SparseVector
Insert value in vector.
insertList : List ( Basics.Int, Basics.Float ) -> SparseVector -> SparseVector
Insert list of values in vector.
magnitude : SparseVector -> Basics.Float
Calculates magnitude of vector.
Sqrt of Sum of Squares of each dimension value.
dot : SparseVector -> SparseVector -> Basics.Float
Calculates the dot product between vectors.
cosineSimilarity : SparseVector -> SparseVector -> Basics.Float
Calculates the cosine similarity between vectors.