[Numpy-discussion] mtrand normal sigma >= 0 too restrictive

Robert Kern robert.kern at gmail.com
Mon Apr 7 15:36:17 EDT 2014

On Thu, Apr 3, 2014 at 2:35 PM, Neal Becker <ndbecker2 at gmail.com> wrote:
> Traceback (most recent call last):
>   File "./test_inroute_frame.py", line 1694, in <module>
>     run_line (sys.argv)
>   File "./test_inroute_frame.py", line 1690, in run_line
>     return run (opt, cmdline)
>   File "./test_inroute_frame.py", line 1115, in run
>     burst.tr (xbits, freq=freqs[i]+burst.freq_offset, tau=burst.time_offset,
> phase=burst.phase)
>   File "/home/nbecker/hn-inroute-fixed/transmitter.py", line 191, in __call__
>     self.channel_out, self.complex_channel_gain = self.channel (mix_out)
>   File "./test_inroute_frame.py", line 105, in __call__
>     ampl = 10**(0.05*self.pwr_gen())
>   File "./test_inroute_frame.py", line 148, in __call__
>     pwr = self.gen()
>   File "./test_inroute_frame.py", line 124, in __call__
>     x = self.gen()
>   File "/home/nbecker/sigproc.ndarray/normal.py", line 11, in __call__
>     return self.rs.normal (self.mean, self.std, size)
>   File "mtrand.pyx", line 1479, in mtrand.RandomState.normal
> (numpy/random/mtrand/mtrand.c:9359)
> ValueError: scale <= 0
> I believe this restriction is too restrictive, and should be
> scale < 0
> There is nothing wrong with scale == 0 as far as I know.  It's a convenient way
> to turn off the noise in my simulation.

That argument rings a bell, so I think I considered it at the time. I
*think* that I ended up deciding that in general this approach would
only work for normally-distributed noise, so one *ought* to write
their code in the more general way (different `if:` branches) anyways
to turn off noise. Thus, excluding scale=0 would help catch some
errors at the expense of making some others do some work to do "the
right thing" instead of the expedient thing.

That was nearly a decade ago, and I don't hang so many consequences on
those kinds of principles anymore. scale=0 is formally valid, so I
think it's reasonable to allow. Considering I specifically implemented
multivariate_normal() to allow non-negative semidefinite covariance
matrices instead of restricting it to positive semidefinite covariance
matrices, this is an odd inconsistency.

Robert Kern

More information about the NumPy-Discussion mailing list