mirror of
https://github.com/github/semantic.git
synced 2024-12-20 21:31:48 +03:00
Compute random Doubles instead.
This commit is contained in:
parent
686f94d53e
commit
51f3d3d11d
@ -16,16 +16,13 @@ serialize gram = stem gram <> base gram
|
||||
type Bag = DList
|
||||
|
||||
|
||||
featureVector :: Hashable label => Bag (Gram label) -> Int -> Vector Rational
|
||||
featureVector :: Hashable label => Bag (Gram label) -> Int -> Vector Double
|
||||
featureVector bag d = sumVectors $ unitDVector . hash <$> bag
|
||||
where unitDVector hash = normalize . (`evalRand` mkQCGen hash) $ Prologue.sequence (Vector.replicate d getRandom)
|
||||
normalize vec = fmap (/ magnitude vec) vec
|
||||
magnitude vec = toRational (sqrtDouble (fromRational (Vector.sum (fmap (^^ (2 :: Integer)) vec))))
|
||||
magnitude vec = sqrtDouble (Vector.sum (fmap (** 2) vec))
|
||||
sumVectors = DList.foldr (Vector.zipWith (+)) (Vector.replicate d 0)
|
||||
|
||||
instance Hashable label => Hashable (Gram label) where
|
||||
hashWithSalt _ = hash
|
||||
hash = hash . serialize
|
||||
|
||||
instance (Random a, Integral a) => Random (Ratio a) where
|
||||
random = first (% 1) . random
|
||||
|
Loading…
Reference in New Issue
Block a user