Calculation of standard deviation

I need to make an algorithm for calculating the integral by the Monte Carlo method, and for modeling purposes, I need to calculate the standard deviation of the sample generated in my program. My problem is that when I increase the number of elements in my sample, my standard deviation does not break up, as you would expect. At first I thought that my function was wrong, but using the predefined numpy function to calculate the standard deviation, I saw that the values ​​were the same and did not decrease as I expected. So I wondered what was the error in my sample, so I did the following simulation to check if the standard deviation was decreasing, as it should be:

list = [random.uniform(0,1) for i in range(100)]
print np.std(list)

received standard deviation: 0.289

list = [random.uniform(0,1) for i in range(1000)]
print np.std(list)

received standard deviation: 0.287

Doesn't that decrease as my n increases? Because I need this to be used as a stopping criterion in my simulation, and I was excluded from this to reduce with a large sample. What is wrong with my mathematical concept?

Thanks in advance!

+4
source share
2 answers

The standard deviation of the distribution is independent of the sample size. The standard deviation for uniform distribution is (b - a)/sqrt(12)where aand bare the limits of your distribution. In your case a = 0and b = 1therefore you should expect std = 1/sqrt(12) = 0.288675for any sample size.

, , std/sqrt(N) :

In [9]: sample = np.random.uniform(0, 1, 100)

In [10]: sample.std()/np.sqrt(sample.size)
Out[10]: 0.029738347511343809

In [11]: sample = np.random.uniform(0, 1, 1000)

In [12]: sample.std()/np.sqrt(sample.size)
Out[12]: 0.0091589707054713591
+8

, , n. , AHuman, , : list - , python. my_list .

[edit] , ; , . : http://planetmath.org/montecarlosimulation

+4

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


All Articles