1
1
mirror of https://github.com/github/semantic.git synced 2024-12-29 18:06:14 +03:00

Swap the d/bag arguments in featureVector.

This commit is contained in:
Rob Rix 2016-06-23 10:34:23 -04:00
parent 6c8ee2958a
commit ed552da2af
2 changed files with 3 additions and 3 deletions

View File

@ -56,8 +56,8 @@ windowed n f seed = para alg
type Bag = DList.DList
featureVector :: Hashable label => Bag (Gram label) -> Int -> Vector.Vector Double
featureVector bag d = sumVectors $ unitDVector . hash <$> bag
featureVector :: Hashable label => Int -> Bag (Gram label) -> Vector.Vector Double
featureVector d bag = sumVectors $ unitDVector . hash <$> bag
where unitDVector hash = normalize . (`evalRand` mkQCGen hash) $ Prologue.sequence (Vector.replicate d getRandom)
normalize vec = fmap (/ vmagnitude vec) vec
sumVectors = DList.foldr (Vector.zipWith (+)) (Vector.replicate d 0)

View File

@ -23,4 +23,4 @@ spec = parallel $ do
describe "featureVector" $ do
prop "produces a vector of the specified dimension" . forAll (arbitrary `suchThat` ((> 0) . snd)) $
\ (grams, d) -> length (featureVector (fromList (grams :: [Gram String])) d) `shouldBe` d
\ (grams, d) -> length (featureVector d (fromList (grams :: [Gram String]))) `shouldBe` d