Sympy: Use variance instead of standard deviation as parameter for Normal dist

Created on 17 Jun 2019  路  5Comments  路  Source: sympy/sympy

Currently, NormalDistribution under sympy/stats/crv_types.py takes std dev. std as parameter. I propose that it should use variance instead (reference: wiki).

Reason:
For most of the purposes, there is no particular difference, but when the variance is distributed based on some other distribution then it becomes difficult to use std dev.

From wiki:

  • Compounding a normal distribution with variance distributed according to an inverse gamma distribution (or equivalently, with precision distributed as a gamma distribution) yields a non-standardized Student's t-distribution. This distribution has the same symmetrical shape as a normal distribution with the same central point but has greater variance and heavy tails.
  • Compounding a Gaussian distribution with variance distributed according to an exponential distribution whose rate parameter is itself distributed according to a gamma distribution yields a Normal-exponential-gamma distribution. (This involves two compounding stages.)
stats

Most helpful comment

We are not going to change the existing API, otherwise lots of SymPy users will start complaining.

You'll need to find a workaround.

All 5 comments

Ping @Upabjojr @sidhantnagpal

It will break the current code of the people using SymPy. Take care of that.

We are not going to change the existing API, otherwise lots of SymPy users will start complaining.

You'll need to find a workaround.

It should be possible to use
Normal(name, mean, std=None, var=None), right? In this way one may use positional arguments in the old order, or keyword arguments for variance. (One should probably check that only one of them is given or that they are consistent if both are given.)

If you change the constructor to accept either std or var, you can also change _argnames in NormalDistribution to ('mean', 'var'). Since this is internal I don't think it will break anything. You can also then implement std as a @property.

Was this page helpful?
0 / 5 - 0 ratings