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 |
Dear Greg,
the RandomJ plugin from Eric Meijering looks to me what you are asking for. https://imagescience.org/meijering/software/randomj/ The only limitation it works on images. However it is macro recordable and the source code can be found on GitHub. Best Arne -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of JAMES, gregory (SANDWELL AND WEST BIRMINGHAM HOSPITALS NHS TRUST) Sent: mercredi 19 septembre 2018 14:09 To: [hidden email] Subject: Gaussian Random Number Generation 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 |
Greg
Something like the following macro should work... var U; var V; function normal(){ S = 2; while(S >= 1){ U = -1+2*random; // uniform random no. -1..1 V = -1+2*random; S = U*U+V*V; } } X = U * sqrt(-2*log(S)/S); //or Y = V * sqrt(-2*log(S)/S); // where log in ImageJ is natural ln X and Y are independent standard normally distributed random numbers, so you can multiply by a finite standard deviation to spread beyond unit STD and add to a mean to get the Gaussian. Check against the Marsaglia polar method of generating normally distributed random numbers. Bit wasteful finding S<1, but easy to check and rather more intuitive than some. Mark -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Seitz Arne Sent: 19 September 2018 13:33 To: [hidden email] Subject: Re: Gaussian Random Number Generation Dear Greg, the RandomJ plugin from Eric Meijering looks to me what you are asking for. https://imagescience.org/meijering/software/randomj/ The only limitation it works on images. However it is macro recordable and the source code can be found on GitHub. Best Arne -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of JAMES, gregory (SANDWELL AND WEST BIRMINGHAM HOSPITALS NHS TRUST) Sent: mercredi 19 septembre 2018 14:09 To: [hidden email] Subject: Gaussian Random Number Generation 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 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by JAMES,
gregory (SANDWELL AND WEST BIRMINGHAM HOSPITALS NHS TRUST)
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_transform So, 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 |
In reply to this post by Mark Osborne
Mark’s suggestion is the Box and Muller algorithm: Box G, Muller M. A Note on the Generation of Random Normal Deviates. Ann Math Stat. 1958;29:610-611. It works well, but I’ve found that with many random number generators X and Y tend to be correlated. You can check this by plotting X vs Y for a few hundred calculations. If there is a recognizable pattern (stripes, clusters) on the plot, X and Y are correlated (and thus not random). I generally use only one of the pair if I really need a set of pseudorandom numbers that look truly random.
- Jim > On Sep 19, 2018, at 9:09 AM, Mark Osborne <[hidden email]> wrote: > > Greg > > Something like the following macro should work... > > var U; var V; > > function normal(){ > S = 2; > while(S >= 1){ > U = -1+2*random; // uniform random no. -1..1 > V = -1+2*random; > S = U*U+V*V; > } > } > > X = U * sqrt(-2*log(S)/S); //or > Y = V * sqrt(-2*log(S)/S); // where log in ImageJ is natural ln > > X and Y are independent standard normally distributed random numbers, so you can multiply by a finite standard deviation to spread beyond unit STD and add to a mean to get the Gaussian. Check against the Marsaglia polar method of generating normally distributed random numbers. Bit wasteful finding S<1, but easy to check and rather more intuitive than some. > > Mark > > -----Original Message----- > From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Seitz Arne > Sent: 19 September 2018 13:33 > To: [hidden email] > Subject: Re: Gaussian Random Number Generation > > Dear Greg, > > the RandomJ plugin from Eric Meijering looks to me what you are asking for. > https://imagescience.org/meijering/software/randomj/ > > The only limitation it works on images. However it is macro recordable and the source code can be found on GitHub. > > Best > Arne > > > -----Original Message----- > From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of JAMES, gregory (SANDWELL AND WEST BIRMINGHAM HOSPITALS NHS TRUST) > Sent: mercredi 19 septembre 2018 14:09 > To: [hidden email] > Subject: Gaussian Random Number Generation > > 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 > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by JAMES,
gregory (SANDWELL AND WEST BIRMINGHAM HOSPITALS NHS TRUST)
What about addingsubtracting or multiplying a random by a perfect Gaussian? This could also be scaled as per the distance from the mean.
Michael Cammer, Sr Research Scientist, DART Microscopy Laboratory NYU Langone Health, 540 First Avenue, SK2 Microscopy Suite, New York, NY 10016 [hidden email] http://nyulmc.org/micros http://microscopynotes.com/ Voice direct only, no text or messages: 1-914-309-3270 and 1-646-501-0567 -----Original Message----- From: JAMES, gregory (SANDWELL AND WEST BIRMINGHAM HOSPITALS NHS TRUST) [mailto:[hidden email]] Sent: Wednesday, September 19, 2018 8:09 AM To: [hidden email] Subject: Gaussian Random Number Generation 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://urldefense.proofpoint.com/v2/url?u=https-3A__portal.nhs.net_help_joiningnhsmail&d=DwIFAw&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=vfUn-WSoz3z11I1Wutm3wYYMExfQInQ6nJuvEPYzlnE&m=zwreGc0NZ6s6BW8-g5d8NGAU6igblX0VMTnh84JZN0k&s=fh4GlqAYP7AQJmuScTNK9sQRNNOp7eXHr-8GiWCECrA&e= -- ImageJ mailing list: https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.nih.gov_ij_list.html&d=DwIFAw&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=vfUn-WSoz3z11I1Wutm3wYYMExfQInQ6nJuvEPYzlnE&m=zwreGc0NZ6s6BW8-g5d8NGAU6igblX0VMTnh84JZN0k&s=G4LNDgrrjs8rfzHKQ93CIhu-xfiaUf0RSrg_3CuXS8M&e= ------------------------------------------------------------ This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email. ================================= -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |