Copyright | David Johnson (c) 2019-2020 |
---|---|
License | BSD3 |
Maintainer | David Johnson <djohnson.m@gmail.com> |
Stability | Experimental |
Portability | GHC |
Safe Haskell | None |
Language | Haskell2010 |
RandomEngine
generation, Random Array
generation.
{-# LANGUAGE TypeApplications #-} module Main where import ArrayFire main :: IO () main = do seed <-getSeed
-- ^ Retrieves seed engine <-createRandomEngine
Mersenne
seed -- ^ Creates engine array <-randomUniform
[3,3] engine -- ^ Creates random Array from engine with uniformly distributed data print array print =<<randu
@Double
[2,2] -- ^ Shorthand for creating randomArray
ArrayFire Array
[3 3 1 1]
0.4446 0.1143 0.4283
0.5725 0.1456 0.9182
0.1915 0.1643 0.5997
ArrayFire Array
[2 2 1 1]
0.6010 0.0278
0.9806 0.2126
Synopsis
- createRandomEngine :: Int -> RandomEngineType -> IO RandomEngine
- retainRandomEngine :: RandomEngine -> IO RandomEngine
- setRandomEngine :: RandomEngine -> RandomEngineType -> IO ()
- getRandomEngineType :: RandomEngine -> IO RandomEngineType
- randomEngineSetSeed :: RandomEngine -> Int -> IO ()
- getDefaultRandomEngine :: IO RandomEngine
- setDefaultRandomEngineType :: RandomEngineType -> IO ()
- randomEngineGetSeed :: RandomEngine -> IO Int
- setSeed :: Int -> IO ()
- getSeed :: IO Int
- randn :: forall a. (AFType a, Fractional a) => [Int] -> IO (Array a)
- randu :: forall a. AFType a => [Int] -> IO (Array a)
- randomUniform :: forall a. AFType a => [Int] -> RandomEngine -> IO (Array a)
- randomNormal :: forall a. AFType a => [Int] -> RandomEngine -> IO (Array a)
Documentation
:: Int | Initial seed value of random number generator |
-> RandomEngineType | Type of random engine to employ |
-> IO RandomEngine | Opaque RandomEngine handle |
Create random number generator object.
>>> engine <- createRandomEngine 100 Philox
:: RandomEngine |
|
-> IO RandomEngine | Retained |
Retains RandomEngine
reference
>>> nextEngine <- retainRandomEngine engine
:: RandomEngine |
|
-> RandomEngineType |
|
-> IO () |
Sets RandomEngine to a new RandomEngineType
>>> setRandomEngine engine Philox
:: RandomEngine |
|
-> IO RandomEngineType |
|
Retrieves RandomEngine
>>> randomEngineType <- getRandomEngineType engine
:: RandomEngine |
|
-> Int | Seed |
-> IO () |
Sets seed on RandomEngine
>>> randomEngineSetSeed engine 100
getDefaultRandomEngine :: IO RandomEngine Source #
Retrieve default RandomEngine
>>> engine <- getDefaultRandomEngine
setDefaultRandomEngineType Source #
:: RandomEngineType |
|
-> IO () |
Set defualt RandomEngine
type
>>> setDefaultRandomEngineType Philox
:: RandomEngine | RandomEngine argument |
-> IO Int |
Retrieve seed of RandomEngine
>>> seed <- randomEngineGetSeed engine
:: (AFType a, Fractional a) | |
=> [Int] | Dimensions of random array |
-> IO (Array a) |
Generate random Array
>>>
randn @Double [2,2]
ArrayFire Array [2 2 1 1] 0.9428 -0.9523 -1.0564 -0.4199
Generate random uniform Array
>>>
randu @Double [2,2]
ArrayFire Array [2 2 1 1] 0.6010 0.0278 0.9806 0.2126
:: AFType a | |
=> [Int] | Dimensions of random array |
-> RandomEngine |
|
-> IO (Array a) |
Generate random uniform Array
>>>
randonUniform @Double [2,2] =<< getDefaultRandomEngine
ArrayFire Array [2 2 1 1] 0.0655 0.5497 0.2864 0.3410
:: AFType a | |
=> [Int] | Dimensions of random array |
-> RandomEngine |
|
-> IO (Array a) |
Generate random uniform Array
>>>
randonNormal @Double [2,2] =<< getDefaultRandomEngine
ArrayFire Array [2 2 1 1] -1.1850 -0.2946 -0.7206 -0.6813