1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 15:35:14 +03:00

Compute random numbers using the Mersenne twister.

This commit is contained in:
Rob Rix 2017-02-03 15:27:37 -05:00
parent a9c55f9b93
commit 72a32ff289
2 changed files with 4 additions and 2 deletions

View File

@ -82,6 +82,7 @@ library
, hashable , hashable
, kdt , kdt
, leancheck , leancheck
, mersenne-random-pure64
, MonadRandom , MonadRandom
, mtl , mtl
, optparse-applicative , optparse-applicative

View File

@ -33,8 +33,8 @@ import Info
import Patch import Patch
import Prologue as P import Prologue as P
import qualified SES import qualified SES
import System.Random.Mersenne.Pure64
import Term (termSize, zipTerms, Term, TermF) import Term (termSize, zipTerms, Term, TermF)
import Test.QuickCheck.Random (mkQCGen)
type Label f fields label = forall b. TermF f (Record fields) b -> label type Label f fields label = forall b. TermF f (Record fields) b -> label
type DiffTerms f fields = Term f (Record fields) -> Term f (Record fields) -> Maybe (Diff f (Record fields)) type DiffTerms f fields = Term f (Record fields) -> Term f (Record fields) -> Maybe (Diff f (Record fields))
@ -286,8 +286,9 @@ pqGramDecorator getLabel p q = cata algebra
unitVector :: Int -> Int -> FeatureVector unitVector :: Int -> Int -> FeatureVector
unitVector d hash = fmap (/ magnitude) uniform unitVector d hash = fmap (/ magnitude) uniform
where where
uniform = evalRand (listArray (0, d - 1) . take d <$> getRandoms) (mkQCGen hash) uniform = listArray (0, d - 1) (evalRand components (pureMT (fromIntegral hash)))
magnitude = sqrtDouble (sum (fmap (** 2) uniform)) magnitude = sqrtDouble (sum (fmap (** 2) uniform))
components = sequenceA (replicate d (liftRand randomDouble))
-- | Strips the head annotation off a term annotated with non-empty records. -- | Strips the head annotation off a term annotated with non-empty records.
stripTerm :: Functor f => Term f (Record (h ': t)) -> Term f (Record t) stripTerm :: Functor f => Term f (Record (h ': t)) -> Term f (Record t)