
Hi all, One part of the DSP library that I am working on is a module for generating sequences of Gaussian random variables. Since this may be of use to people outside the DSP community, I wanted to get some suggestions on the interface. Right now, I have a few different methods for generating white gaussian noise. They all behave the same, but have different ranges and efficiencies. 1. Should the functions generate the necessary uniforms, or accept a list of uniforms? In other words, shuld the signature be wgn :: Int -- ^ seed to generate the uniforms -> [Double] -- ^ list of Gaussian random variables or wgn :: [Double] -- ^ list of uniform random variables -> [Double] -- ^ list of Gaussian random variables The first is what I currently have implemented, but the second is more flexible. 2. Should the functions accept mean and/or variance parameters, or should they generate unit normals? For those who forget X' = mean + sqrt var * X or X' = mean + stddev * X For a point of reference, the GNU scientific library function for WGN has a stddev parameter. I will probably be sending out a bunch of other emails in the next week or two. Thanks. -- Matthew Donadio (m.p.donadio@ieee.org)

Hi Matthew, I look forward to your library, and I'm not even a DSP guy :).
1. Should the functions generate the necessary uniforms, or accept a list of uniforms? In other words, shuld the signature be
I don't particularly have an opinion on this one.
2. Should the functions accept mean and/or variance parameters, or should they generate unit normals? For those who forget
I would be in favor of them taking mean and variance parameters. If they don't, everyone is going to end up wrapping them up anyway. If you want, perhaps have two versions, but I think it will be beneficial (efficiency-wise) to not have to wrap. If nothing else, provide variance. - Hal

On Wed, May 07, 2003 at 11:18:01AM -0400, Matthew Donadio wrote:
1. Should the functions generate the necessary uniforms, or accept a list of uniforms? In other words, shuld the signature be
wgn :: Int -- ^ seed to generate the uniforms -> [Double] -- ^ list of Gaussian random variables
or
wgn :: [Double] -- ^ list of uniform random variables -> [Double] -- ^ list of Gaussian random variables
The first is what I currently have implemented, but the second is more flexible.
I'd say the second. I wasted a month or two one summer due to the cruddy random number generator in Numerical Recipes first edition, and don't trust most random number generators. Generators optimized for speed (which I imagine is what you want for DSP work) often have severe flaws in the quality of their random numbers. -- David Roundy http://civet.berkeley.edu/droundy/

G'day. On Wed, May 07, 2003 at 11:18:01AM -0400, Matthew Donadio wrote:
1. Should the functions generate the necessary uniforms, or accept a list of uniforms? In other words, shuld the signature be
wgn :: Int -- ^ seed to generate the uniforms -> [Double] -- ^ list of Gaussian random variables
or
wgn :: [Double] -- ^ list of uniform random variables -> [Double] -- ^ list of Gaussian random variables
IMO, the first is unacceptable because I may want to plug in my own random numbers. In addition, I may not want to seed my random number generator from a simple Int (e.g. if I need cryptographically strong Gaussian random numbers; no idea why, of course). OTOH, if you're using the algorithm I'm thinking of, wgn turns two uniform random numbers into two Gaussian random numbers. The type declaration above suggests that if I give you an odd number of uniform random variables, I'll get the same number of Gaussian random variables. Speaking as someone who uses random numbers regularly, though, what I want to do is not plug in random numbers, but rather plug in a random number generator. Something like this perhaps: class (Monad m) => RNG rng m | rng -> m where getUniformRand :: rng -> m Double wgn :: (Monad m, RNG rng m) => rng -> m [Double]
2. Should the functions accept mean and/or variance parameters, or should they generate unit normals?
Is there a reason not to provide both? Cheers, Andrew Bromage

Matthew Donadio
One part of the DSP library that I am working on is a module for generating sequences of Gaussian random variables. Since this may be of use to people outside the DSP community, I wanted to get some suggestions on the interface.
Any reason not to mimic the Random interface? I.e. provide both randomN :: StdGen -> Double and randomNs :: StdGen -> [Double] BTW, can it be made more general, and parametrise the distribution function?
2. Should the functions accept mean and/or variance parameters, or should they generate unit normals? For those who forget
Contrary to (all?) others, I think the *sigma+mu pattern is so ingrained into everybody wanting this, that the standard normal approach is sufficient. -kzm -- If I haven't seen further, it is by standing in the footprints of giants

1. Should the functions generate the necessary uniforms, or accept a list of uniforms? In other words, shuld the signature be
wgn :: Int -- ^ seed to generate the uniforms -> [Double] -- ^ list of Gaussian random variables
I don't like this approach (better to pass in a list of uniforms, or a generator), but if you take it, Int isn't good enough. I might want to provide more than 31 bits of entropy to start off the generator! The Linux random(3) function uses 1984 bits of entropy, for example. --KW 8-)
participants (6)
-
Andrew J Bromage
-
David Roundy
-
Hal Daume III
-
Keith Wansbrough
-
ketil@ii.uib.no
-
Matthew Donadio