Group Abstract Group Abstract

Message Boards Message Boards

0
|
15.3K Views
|
22 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Generate points with density following Gaussian distribution

Posted 5 years ago

Hello,

I want to generate a collection of 1000 points (x, y), at (near) origin with their density following a Gaussian distribution on both X and Y axes. The full width half maxima (FWHM) of this Gaussian distribution should be a variable, say 5 to start with.

Will appreciate any help. Thanks

POSTED BY: S G
22 Replies
Posted 5 years ago
POSTED BY: S G

@Jim Baldwin

Indeed, he didn't ask for that. But I asked myself, whether pp2 given above follows a normal distribution. Not being a specialist in statistics I had no other idea as to check whether the densitiy follows an Exp[ - a x^2 ] - law, which I think it does.

POSTED BY: Hans Dolhaine
POSTED BY: Hans Dolhaine
Posted 5 years ago
POSTED BY: Jim Baldwin
Posted 5 years ago
POSTED BY: S G
Posted 5 years ago

You do get a peak of the density of points at the origin. The density of points for a bivariate normal distribution with mean vector (0,0) does have a peak at (0,0).

Hans introduced the distribution of the "distance" from the origin which doesn't seem to have anything to do with your question. The peak around 0.3 mentioned by Hans is the peak of the probability density function of the "distance from (0,0)" which is a univariate distribution. And that, again, is an interesting distribution but does not appear to me to something that you were asking about.

So no need to modify the Normal distribution. You can get a set of data points with the origin at (0,0) (and therefore the highest density of sample points near the origin) from two independent normal random variables in several ways. Here are 2:

sd = 5/(2 Sqrt[2 Log[2]]);
data = RandomVariate[NormalDistribution[0, sd], {500, 2}];
data = RandomVariate[BinormalDistribution[{0, 0}, {sd, sd}, 0], 500];
POSTED BY: Jim Baldwin
Posted 5 years ago

Thanks, I get your point mathematically. However, if we are using a function under RandomReal which has a peak at zero, why don't we have the highest density at origin. Can we modify the NormalDistribution in such a way (or use any other function) that can give highest density of points at origin. Because, that is what I need in the end.

POSTED BY: S G
Posted 5 years ago

OP is for "original poster". In other words, a reference to the person who asked the question or to the question being asked.

Your initial response did contain the what was asked for: how to generate the sample points. Your other response described the distribution of the distance of those points from (0,0) and I don't see that the OP asked for that.

POSTED BY: Jim Baldwin

?? what is OP? and anyway, you have your points "normally" distributed around { 0, 0 }: and what do think is "being asked for"?

POSTED BY: Hans Dolhaine
Posted 5 years ago
POSTED BY: Jim Baldwin
POSTED BY: Hans Dolhaine
Posted 5 years ago
rho = 0.8;  (* Correlation coefficient *)
FWHM = 5;  (* Your desired value for FWHM *)
sigma = FWHM/(2 Sqrt[2 Log[2]]);  (* Convert to equivalent standard deviation for a Normal *)
n = 1000;  (* Sample size *)
xy = RandomVariate[BinormalDistribution[{0, 0}, {sigma, sigma}, rho], n];
ListPlot[xy]

Plot of random sample from a bivariate normal

POSTED BY: Jim Baldwin
Posted 5 years ago

Thanks. I have not understood this code yet, but why a peak at 0.25 when the mean value for normal distribution is zero ??

POSTED BY: S G
Posted 5 years ago

True !! I have to relate a calculation with experimental data, where peak is characterized by FWHM. Thanks by the way.

POSTED BY: S G
Posted 5 years ago

So that you know while using FWHM as a parameter to characterize the Normal (i.e., Gaussian) distribution is legitimate, it is not a very common way of doing so (but maybe the standard in some specialized fields). Typically one uses the mean and variance or mean and standard deviation. Mathematica uses the mean and standard deviation.

For a Normal distribution (and only for a Normal distribution) the standard deviation is given by

$$\sigma=FWHM/(2\sqrt{2 \log2})\approx FWHM/2.35482$$

POSTED BY: Jim Baldwin

Here is another piece of code "to analyse" the density of the points obtained, using the assumption that the density is something like Exp[ - a x^2 ]

xx = RandomReal[NormalDistribution[0, .3], 500];
yy = RandomReal[NormalDistribution[0, .3], 500];
pp2 = Transpose[{xx, yy}];
ListPlot[pp2, AspectRatio -> Automatic, 
 PlotRange -> {{-1, 1}, {-1, 1}}, PlotStyle -> {Red, Blue}]
total = Length [pp2]; pts = 
 Table[{d + .05, 
   N@Length[Select[pp2, d < Sqrt[#.#] < d + .1 &]]/total}, {d, 0, 
   2, .1}]
fit = NonlinearModelFit[pts, 
   2 Pi x  b  Exp[-a x^2], {{b, .21}, {a, 6.2},}, x];
ffit = Normal[fit]
Plot[ffit, {x, 0, 2}, PlotRange -> {0, .3}, Epilog -> Point /@ pts]

Run this code several times and look at the plots

POSTED BY: Hans Dolhaine
Posted 5 years ago

Got it. FWHM = 2.35 * standard deviation. Thanks for you help.

POSTED BY: S G
Posted 5 years ago
POSTED BY: S G

What is FWHM? The 2nd variable is the standard deviation of the NomalDistribution.

As I said, I am by no means sure whether my approach is correct.

POSTED BY: Hans Dolhaine
Posted 5 years ago

Thanks.

In NormalDistribution[0, 1], first variable is the position of the Gaussian peak, defined as mean in Mathematica. However, I am not able to figure out the fact that how the second variable, which is defined as "deviation" in Mathematica, is related to FWHM ? Can you please elaborate that how the number "1" chosen by you is equivalent to the FWHM of 5.

POSTED BY: S G

or something like this?

xx = RandomReal[NormalDistribution[0, 1], 500];
yy = RandomReal[NormalDistribution[0, 1], 500];
pp1 = Transpose[{xx, yy}];
xx = RandomReal[NormalDistribution[0, .1], 500];
yy = RandomReal[NormalDistribution[0, .1], 500];
pp2 = Transpose[{xx, yy}];
ListPlot[{pp1, pp2}, AspectRatio -> Automatic, 
 PlotRange -> {{-1, 1}, {-1, 1}}, PlotStyle -> {Red, Blue}]
POSTED BY: Hans Dolhaine

I am not sure whether this does the job

xx = RandomReal[NormalDistribution[0, 1], 500];
yy = RandomReal[NormalDistribution[0, 1], 500];
pp = Transpose[{xx, yy}];
ListPlot[pp, AspectRatio -> Automatic]

but you could have a look at it.

POSTED BY: Hans Dolhaine
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard