Vary range of uniform_int_distribution

Distribution objects are lightweight. Simply construct a new distribution when you need a random number. I use this approach in a game engine, and, after benchmarking, it’s comparable to using good old rand(). Also, I’ve asked how to vary the range of distribution on GoingNative 2013 live stream, and Stephen T. Lavavej, a member of … Read more

Fitting a gamma distribution with (python) Scipy

Generate some gamma data: import scipy.stats as stats alpha = 5 loc = 100.5 beta = 22 data = stats.gamma.rvs(alpha, loc=loc, scale=beta, size=10000) print(data) # [ 202.36035683 297.23906376 249.53831795 …, 271.85204096 180.75026301 # 364.60240242] Here we fit the data to the gamma distribution: fit_alpha, fit_loc, fit_beta=stats.gamma.fit(data) print(fit_alpha, fit_loc, fit_beta) # (5.0833692504230008, 100.08697963283467, 21.739518937816108) print(alpha, loc, … Read more

Uniform distribution of truncated md5?

Yes, not exhibiting any bias is a design requirement for a cryptographic hash. MD5 is broken from a cryptographic point of view however the distribution of the results was never in question. If you still need to be convinced, it’s not a huge undertaking to hash a bunch of files, truncate the output and use … Read more

How to find probability distribution and parameters for real data? (Python 3)

Use this approach import scipy.stats as st def get_best_distribution(data): dist_names = [“norm”, “exponweib”, “weibull_max”, “weibull_min”, “pareto”, “genextreme”] dist_results = [] params = {} for dist_name in dist_names: dist = getattr(st, dist_name) param = dist.fit(data) params[dist_name] = param # Applying the Kolmogorov-Smirnov test D, p = st.kstest(data, dist_name, args=param) print(“p value for “+dist_name+” = “+str(p)) dist_results.append((dist_name, … Read more

Plot with fewer markers than data points (or a better way to plot CDFs?) [matplotlib, or general plotting help]

You can do plot(x,y,marker=”o”,markevery=5) to mark every fifth point, but I don’t think there is any built-in support for setting marks at even intervals. You could decide on the x locations where you want the marks, use e.g. numpy.searchsorted to find which data points the locations fall between, and then interpolate between the neighboring points … Read more

What do all the distributions available in scipy.stats look like?

Visualizing all scipy.stats distributions Based on the list of scipy.stats distributions, plotted below are the histograms and PDFs of each continuous random variable. The code used to generate each distribution is at the bottom. Note: The shape constants were taken from the examples on the scipy.stats distribution documentation pages. alpha(a=3.57, loc=0.00, scale=1.00) anglit(loc=0.00, scale=1.00) arcsine(loc=0.00, … Read more

Cumulative Normal Distribution Function in C/C++

Theres is no straight function. But since the gaussian error function and its complementary function is related to the normal cumulative distribution function (see here, or here) we can use the implemented c-function erfc (complementary error function): double normalCDF(double value) { return 0.5 * erfc(-value * M_SQRT1_2); } Which considers the relation of erfc(x) = … Read more

JavaScript Math.random Normal distribution (Gaussian bell curve)?

Since this is the first Google result for “js gaussian random” in my experience, I feel an obligation to give an actual answer to that query. The Box-Muller transform converts two independent uniform variates on (0, 1) into two standard Gaussian variates (mean 0, variance 1). This probably isn’t very performant because of the sqrt, … Read more

Two-sample Kolmogorov-Smirnov Test in Python Scipy

You are using the one-sample KS test. You probably want the two-sample test ks_2samp: >>> from scipy.stats import ks_2samp >>> import numpy as np >>> >>> np.random.seed(12345678) >>> x = np.random.normal(0, 1, 1000) >>> y = np.random.normal(0, 1, 1000) >>> z = np.random.normal(1.1, 0.9, 1000) >>> >>> ks_2samp(x, y) Ks_2sampResult(statistic=0.022999999999999909, pvalue=0.95189016804849647) >>> ks_2samp(x, z) Ks_2sampResult(statistic=0.41800000000000004, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)