Sep-04-2022, 07:48 AM
(This post was last modified: Sep-04-2022, 07:50 AM by Gribouillis.)
(Sep-04-2022, 12:23 AM)Skaperen Wrote: but, i want it to look about like i am using that.A bell curve has two parameters: the mean and the standard deviation. If you want something that looks like a bell curve, you need to choose the mean and the standard deviation. With your method, you always have s = sqrt(N/12).
Run the following code to visualize the distribution that my method generates for a mean value of 20 minutes and a standard dev of 1.5 minutes. The SIZE parameter is the size of the sample.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
from scipy.stats import gaussian_kde from numpy import linspace import numpy as np import random from matplotlib import pyplot as plt def sleeping_time(mu, sigma, min , max ): while True : t = random.normalvariate(mu, sigma) if min < = t < = max : return t # generate experimental data SIZE = 20000 data = np.array([sleeping_time( 20 * 60 , 90 , 16 * 60 , 24 * 60 ) / 60 for i in range (SIZE)]) # section to approximate the data's density curve # this create the kernel, given an array it will estimate the probability over that values kde = gaussian_kde( data ) # these are the values over wich your kernel will be evaluated dist_space = linspace( min (data), max (data), 100 ) # plot the results plt.plot( dist_space, kde(dist_space) ) plt.show() |