Is there any way to do arithmetic with random SciPy variables?

The SciPy module statshas objects of type "random variable" (they call it rv_frozen). This simplifies the construction of, say, cdf of random variables of a given distribution. Here is a very simple example:

import scipy.stats as stats
n = stats.norm()
x = linspace(-3, 3)
y = n.cdf(x)
plot(x, y)

I wondered if there was a way to do basic arithmetic manipulations with such random variables. The next example is wishful thinking (it doesn't work).

du_list = [stats.randint(2, 5) for _ in xrange(100)]
du_avg = sum(du_list) / len(du_list)
x = linspace(0, 10)
y = du_avg.cdf(x)
plot(x, y)

This example of the desired result should produce a graph of the cumulative distribution function of a random variable, which is equal to the average value of 100 iid random variables, each of which is uniformly distributed on the set {2,3,4}.

+4
3

, , , , - . scipy rv_discrete, , PaCAL.

PaCAL - Python , , . . PyPI. Python 2.x.

+5

, , . cdf **/scipy/stats/distributions.py`. :

CDF ( 7675):

def _cdf(self, x, lambda_, N):
    k = floor(x)
    return (1-exp(-lambda_*(k+1)))/(1-exp(-lambda_*N))

MLE, cdf, . :

import scipy.stats as ss
unknown=np.random.normal(loc=1.1, scale=2.0, size=100)
Loc, Scale=ss.norm.fit_loc_scale(unknown) #making a MLE fit
unknown_cdf=lambda x: ss.norm.cdf(x, loc=Loc, scale=Scale) #the cdf of the MLE to the data
plt.plot(np.linspace(-10, 10), unknown_cdf(np.linspace(-10, 10)), '-')

enter image description here

+1

.

X , Xi, , U (2,5). , X, pdf cdf.

.

. Irwin-Hall Math-stackexchange.

0

Source: https://habr.com/ru/post/1545831/


All Articles