1
1
mirror of https://github.com/github/semantic.git synced 2024-12-19 12:51:52 +03:00

📝 vmagnitude.

This commit is contained in:
Rob Rix 2016-07-05 09:26:34 -04:00
parent cf6a5d77a6
commit 9632bea377

View File

@ -88,6 +88,7 @@ featureVector d bag = sumVectors $ unitDVector . hash <$> bag
normalize vec = fmap (/ vmagnitude vec) vec
sumVectors = DList.foldr (Vector.zipWith (+)) (Vector.replicate d 0)
-- | The magnitude of a Euclidean vector, i.e. its distance from the origin.
vmagnitude :: Vector.Vector Double -> Double
vmagnitude = sqrtDouble . Vector.sum . fmap (** 2)