Posted by
Michael Schmid on
URL: http://imagej.273.s1.nabble.com/Gaussian-Random-Number-Generation-tp5021203p5021206.html
Hi Greg,
when programming in Java or JavaScript:
the Java Random generator has a method to create random numbers with a
Gaussian distribution, standard deviation 1, and mean=0.
https://docs.oracle.com/javase/7/docs/api/java/util/Random.html#nextGaussian()
As usual for generating Gaussian-distributed random numbers, it uses the
polar method to generate the final random number from two independent
random numbers, one for the 'radius' and one for the 'angle'
https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transformSo, you can translate the code for the polar method from one of the two
links above to the macro language.
As an alternative, call JavaScript in the macro (rather slow).
seed=round(random()*2e9);
a=eval("script", "rnd=new java.util.Random("+seed+");
rnd.nextGaussian()");
print(a);
[Note that the 2nd line of the macro should be one line starting with
'a=' and ending with 'nextGaussian()");']
Or as a further possibility, if you need n random numbers, create a
32-bit image with n pixels and 'random' initial values, then access them
pixel by pixel.
In any case, multiply by the desired stddev and add the desired mean.
Michael
________________________________________________________________
On 19/09/2018 14:09, JAMES, gregory (SANDWELL AND WEST BIRMINGHAM
HOSPITALS NHS TRUST) wrote:
> Dear ImageJ community,
>
>
> You are an intelligent group of people so I would like to ask this...
>
>
> Does anyone have a clever way of generating a random set of numbers that conform to a normal (Gaussian) distribution for a given mean and standard deviation using the 'random' macro function? I acknowledge that the ImageJ macro language is a slightly strange place to do this but I cannot use Excel because my data sets are so large and I would rather not learn a new scripting language (e.g. R).
>
>
> For what it's worth, it is quite straightforward to do in Excel using =NORMINV(RAND(), mean, stdev). Does anyone have a clever way of replicating this function in ImageJ?
>
>
> Many thanks,
>
>
> Greg.
>
>
> __________________________________________
> Gregory James
> Clinical Scientist (Nuclear Medicine)
> Department of Physics and Nuclear Medicine
> City Hospital
> Dudley Road
> Birmingham
> B18 7QH
>
> 0121 507 4043
>
>
> ********************************************************************************************************************
>
> This message may contain confidential information. If you are not the intended recipient please inform the
> sender that you have received the message in error before deleting it.
> Please do not disclose, copy or distribute information in this e-mail or take any action in relation to its contents. To do so is strictly prohibited and may be unlawful. Thank you for your co-operation.
>
> NHSmail is the secure email and directory service available for all NHS staff in England and Scotland. NHSmail is approved for exchanging patient data and other sensitive information with NHSmail and other accredited email services.
>
> For more information and to find out how you can switch,
https://portal.nhs.net/help/joiningnhsmail>
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html