1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 04:51:57 +03:00

Move vmagnitude into unitVector.

This commit is contained in:
Rob Rix 2016-08-09 14:39:00 -04:00
parent 0cfa23fcc2
commit b966b56494

View File

@ -107,6 +107,7 @@ decorateTermWithFeatureVector d = cata $ \ (RCons gram rest :< functor) ->
unitVector :: Int -> Int -> Vector.Vector Double
unitVector d hash = normalize ((`evalRand` mkQCGen hash) (sequenceA (Vector.replicate d getRandom)))
where normalize vec = fmap (/ vmagnitude vec) vec
vmagnitude = sqrtDouble . Vector.sum . fmap (** 2)
-- | Annotates a term with a feature vector at each node.
featureVectorDecorator :: (Hashable label, Traversable f) => (forall b. CofreeF f (Record fields) b -> label) -> Int -> Int -> Int -> Cofree f (Record fields) -> Cofree f (Record (Vector.Vector Double ': fields))
@ -119,10 +120,6 @@ featureVectorDecorator getLabel p q d
padToSize :: Alternative f => Int -> [f a] -> [f a]
padToSize n list = take n (list <> repeat empty)
-- | The magnitude of a Euclidean vector, i.e. its distance from the origin.
vmagnitude :: Vector.Vector Double -> Double
vmagnitude = sqrtDouble . Vector.sum . fmap (** 2)
-- Instances