How to plot a mean line on a kdeplot between 0 and the y value of the mean

Update for the latest versions of matplotlib (3.3.4) and seaborn (0.11.1): the kdeplot with shade=True now doesn’t create a line object anymore. To get the same outcome as before, setting shade=False will still create the line object. The curve can then be filled with ax.fill_between(). The code below is changed accordingly. (Use the revision history … Read more

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

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

Draw random numbers from pre-specified probability mass function in Matlab

Using the Statistics Toolbox The randsample function can do that directly: result = randsample(supp_epsilon, n, true, pr_mass_epsilon); Without using toolboxes Manual approach: Generate n samples of a uniform random variable in the interval (0,1). Compare each sample with the distribution function (cumulative sum of mass function). See in which interval of the distribution function each … 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