gaussian

How to generate normally distributed random from an integer range?

隐身守侯 提交于 2019-11-30 02:23:39
Given the start and the end of an integer range, how do I calculate a normally distributed random integer between this range? I realize that the normal distribution goes into -+ infinity. I guess the tails can be cutoff, so when a random gets computed outside the range, recompute. This elevates the probability of integers in the range, but as long as the this effect is tolerable (<5%), it's fine. public class Gaussian { private static bool uselast = true; private static double next_gaussian = 0.0; private static Random random = new Random(); public static double BoxMuller() { if (uselast) {

Gaussian filter in scipy

北城余情 提交于 2019-11-30 01:54:39
I want to apply a Gaussian filter of dimension 5x5 pixels on an image of 512x512 pixels. I found a scipy function to do that: scipy.ndimage.filters.gaussian_filter(input, sigma, truncate=3.0) How I choose the parameter of sigma to make sure that my Gaussian window is 5x5 pixels? Check out the source code here: https://github.com/scipy/scipy/blob/master/scipy/ndimage/filters.py You'll see that gaussian_filter calls gaussian_filter1d for each axis. In gaussian_filter1d , the width of the filter is determined implicitly by the values of sigma and truncate . In effect, the width w is w = 2*int

How to generate 2D gaussian with Python?

戏子无情 提交于 2019-11-29 23:31:49
I can generate Gaussian data with random.gauss(mu, sigma) function, but how can I generate 2D gaussian? Is there any function like that? Since the standard 2D Gaussian distribution is just the product of two 1D Gaussian distribution, if there are no correlation between the two axes (i.e. the covariant matrix is diagonal), just call random.gauss twice. def gauss_2d(mu, sigma): x = random.gauss(mu, sigma) y = random.gauss(mu, sigma) return (x, y) If you can use numpy , there is numpy.random.multivariate_normal(mean, cov[, size]) . For example, to get 10,000 2D samples: np.random.multivariate

How to generate random numbers from a normal distribution with specific mean and variance?

时间秒杀一切 提交于 2019-11-29 22:56:45
问题 I need to generate a Gaussian random sample of n numbers, with mean 0 and variance 1, using the randn function. In general, how would I generate a Gaussian random sample X of n numbers, with mean mu and variance v , using the randn function? 回答1: A standard normal distribution already has mean 0 and variance 1. If you want to change the mean, just "translate" the distribution, i.e., add your mean value to each generated number. Similarly, if you want to change the variance, just "scale" the

Sample from multivariate normal/Gaussian distribution in C++

假装没事ソ 提交于 2019-11-29 20:26:36
I've been hunting for a convenient way to sample from a multivariate normal distribution. Does anyone know of a readily available code snippet to do that? For matrices/vectors, I'd prefer to use Boost or Eigen or another phenomenal library I'm not familiar with, but I could use GSL in a pinch. I'd also like it if the method accepted nonnegative -definite covariance matrices rather than requiring positive-definite (e.g., as with the Cholesky decomposition). This exists in MATLAB, NumPy, and others, but I've had a hard time finding a ready-made C/C++ solution. If I have to implement it myself, I

Un-normalized Gaussian curve on histogram

最后都变了- 提交于 2019-11-29 20:14:37
问题 I have data which is of the gaussian form when plotted as histogram. I want to plot a gaussian curve on top of the histogram to see how good the data is. I am using pyplot from matplotlib. Also I do NOT want to normalize the histogram. I can do the normed fit, but I am looking for an Un-normalized fit. Does anyone here know how to do it? Thanks! Abhinav Kumar 回答1: As an example: import pylab as py import numpy as np from scipy import optimize # Generate a y = np.random.standard_normal(10000)

Gaussian Mixture Models of an Image's Histogram

◇◆丶佛笑我妖孽 提交于 2019-11-29 19:51:38
问题 I am attempting to do automatic image segmentation of the different regions of a 2D MR image based on pixel intensity values. The first step is implementing a Gaussian Mixture Model on the image's histogram. I need to plot the resulting gaussian obtained from the score_samples method onto the histogram. I have tried following the code in the answer to (Understanding Gaussian Mixture Models). However, the resulting gaussian fails to match the histogram at all. How do I get the gaussian to

Implementing Gaussian Blur - How to calculate convolution matrix (kernel)

限于喜欢 提交于 2019-11-29 19:21:37
My question is very close to this question: How do I gaussian blur an image without using any in-built gaussian functions? The answer to this question is very good, but it doesn't give an example of actually calculating a real Gaussian filter kernel. The answer gives an arbitrary kernel and shows how to apply the filter using that kernel but not how to calculate a real kernel itself. I am trying to implement a Gaussian blur in C++ or Matlab from scratch, so I need to know how to calculate the kernel from scratch. I'd appreciate it if someone could calculate a real Gaussian filter kernel using

multivariate normal cdf in C, C++, or Fortran [closed]

你离开我真会死。 提交于 2019-11-29 19:08:09
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . Is there an open source to calculate multivariate (where dimension is large > 3, not bivariate or trivariate ) numerical cdf of gaussian distributions in C, C++ or Fortran? I believe IMSL does it; http://www.roguewave.com/portals/0/products/imsl-numerical-libraries/c-library/docs/7.0/html/cstat/default.htm?turl

Fit data to normal distribution

主宰稳场 提交于 2019-11-29 17:06:36
I want some data to fit the corresponding Gaussian distribution. The data is meant to be Gaussian already, but for some filtering reasons, they will not perfectly match the prescribed and expected Gaussian distribution. I therefore aim to reduce the existing scatter between data and desired distribution. For example, my data fit the Gaussian distribution as follows (the expected mean value is 0 and the standard deviation 0.8): The approximation is already decent, but I really want to crunch the still tangible scatter between simulated data and expected distribution. How can I achieve this?