probability-density

How to extract the distance and transport matrices from Scipy's wasserstein_distance?

戏子无情 提交于 2021-02-11 14:28:16
问题 The scipy.stats.wasserstein_distance function only returns the minimum distance (the solution) between two input distributions, p and q . But that distance is the result of the product of a distance matrix and an optimal transport matrix that must have been computed inside the same function. How can I extract the distance matrix and optimal transport matrix that correspond to the solution as 2nd and 3rd output arguments? 回答1: It does not seem that you can get the calculated transport matrix

How can Python use n, min, max, mean, std, 25%, 50%, 75%, Skew, Kurtosis to define a psudo-random Probability Density Estimate/Function?

試著忘記壹切 提交于 2021-02-11 12:29:27
问题 In reading and experimenting with numpy.random, I can't seem to find or create what I need; a 10 parameter Python pseudo-random value generator including count, min, max, mean, sd, 25th%ile, 50th%ile (median), 75th%ile, skew, and kurtosis. From https://docs.python.org/3/library/random.html I see these distributions uniform, normal (Gaussian), lognormal, negative exponential, gamma, and beta distributions, though I need to generate values directly to a distribution defined only by my 10

Drawing histogram of probability density function of a matrix in python [closed]

情到浓时终转凉″ 提交于 2021-01-29 20:12:30
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 days ago . Improve this question I have a 2D matrix of p-values. I want to draw a histogram of the pdf of this 2D matrix. How can I do that? 回答1: Just so you know: Seaborn's distplot does all of this. import seaborn as sns, numpy as np sns.set_palette("cividis"); np.random.seed(0) x = np.random.randn(100) ax =

Simulate from kernel density estimator with variable underlying grid

亡梦爱人 提交于 2021-01-28 05:51:02
问题 I have a dataset that I'm using to create an empirical probability distribution by estimating a kernel density. Right now I'm using R's kde2d from the MASS package. After estimating the probability distribution, I use sample to sample from slices of the 2D distribution along the x-axis. I use sample much like described here. Example code would look like this library(MASS) set.seed(123) x = rnorm(100, 1, 0.1) set.seed(456) y = rnorm(100, 1, 0.5) den <- kde2d(x, y, n = 50, lims = c(-2, 2, -2, 2

Normal density curves on multiple histograms on a same plot

巧了我就是萌 提交于 2021-01-28 05:31:21
问题 I have a dataframe, for example, as this: sample1 <- seq(120,197, length.out = 60) sample2 <- seq(113, 167, length.out = 60) sample3 <- seq(90,180, length.out = 60) sample4 <-seq(100, 160, length.out = 60) df <- as.data.frame(cbind(sample1, sample2, sample3, sample4)) I now need to create histograms for these four variables such that all of them share the same y-axis , and also need to overlay normal density curves on each of these histograms. facet_wrap() will be fine as long as the y-axis

Follow up to stat_contour_2d bins - interpretation

寵の児 提交于 2021-01-27 15:05:06
问题 This is a direct follow up to How to interpret ggplot2::stat_density2d. bins has been re-added as an argument see this thread and the corresponding github issue, but it remains a mistery to me how to interpret those bins. This answer ( answer 1 ) suggests a way to calculate contour lines based on probabilities, and this answer argues that the current use of kde2d in stat_density_2d would not mean that the bins can be interpreted as percentiles. So the question. When trying both approaches in

Calculate probability of value based on 2D density plot in R

人走茶凉 提交于 2020-08-26 02:37:51
问题 I'm looking to work out a function to calculate the likelihood of a certain combination for B and R. The current illustration of the data looks like so: ggplot(df, aes(R,B)) + geom_bin2d(binwidth = c(1,1)) Is there a way to calculate the probabilities of each combination (e.g. R = 23, B = 30) based on these two discrete correlated variables that are positively skewed? Could it be possible to use the stat_density_2d to solve or could there be a better way? Thanks. 回答1: stat_density_2d uses

Creating a mixture of probability distributions for sampling

大憨熊 提交于 2020-07-18 07:09:18
问题 Is there a general way to join SciPy (or NumPy) probability distributions to create a mixture probability distribution which can then be sampled from? I have such a distribution for display using something like: mixture_gaussian = (norm.pdf(x_axis, -3, 1) + norm.pdf(x_axis, 3, 1)) / 2 which if then plotted looks like: However, I can't sample from this generated model, as it's just a list of points which will plot as the curve. Note, this specific distribution is just a simple example. I'd

Why does scipy.integrate.quad fail for some interval of this integral?

痞子三分冷 提交于 2020-04-17 21:51:33
问题 To reproduce : # Use scipy to create random number for f(x) = 2x when x in [0,1] and 0, otherwise from scipy.stats import rv_continuous class custom_rv(rv_continuous): "custom distribution" def _pdf(self, x): if x >= 0.0 and x <=1.0: return 2*x else: return 0.0 rv = custom_rv(name='2x') from scipy.integrate import quad print(quad(rv._pdf, -10.0, 10.0)) print(quad(rv._pdf, -5.0, 5.0)) print(quad(rv._pdf, -np.inf, np.inf)) Output : (0.0, 0.0) # for [-10,10] (1.0, 1.1102230246251565e-15) # for [

Probability density function numpy histogram/scipy stats

霸气de小男生 提交于 2020-03-22 09:17:48
问题 We have the array a=range(10) . Using numpy.histogram : hist,bins=numpy.histogram(a,bins=(np.max(a)-np.min(a))/1, range=np.min(a),np.max(a)),density=True) According to numpy tutorial: If density=True, the result is the value of the probability density function at the bin, normalized such that the integral over the range is 1. The result is: array([ 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.2]) I try to do the same using scipy.stats : mean = np.mean(a) sigma = np.std(a) norm.pdf(a, mean, sigma