TheWind Posted October 28, 2017 Share Posted October 28, 2017 I've been working to learn about the Gaussian Function, Probability Density Functions, and Cumulative Distribution Functions. https://en.wikipedia.org/wiki/Gaussian_function https://en.wikipedia.org/wiki/Probability_density_function https://en.wikipedia.org/wiki/Cumulative_distribution_function From my understanding you have the Gaussian function: and the integral of the Gaussian function is only equal to 1 when a = 1/(c * sqrt(2pi)) In this case, it can be used as a probability density function with normally distributed values. (This form is used for statistical analysis) b = mu (mean) c^2 = sigma^2 (standard deviation squared or the variance) The above is the relation of the variables of the regular Gaussian function to that of the Normal Distribution (as it's used in statistics). I've never taken a statistics class, so forgive me if I'm wrong on something. Most of the information here is from the wiki page or other resources I was reading to learn from. My goal is to write a function which utilizes the normalized Gaussian function to make a method that returns a random Gaussian number. By doing so it would return numbers closer to the mean more often than those that are farther away. What I tried to do was write a function for the standard Gaussian function, another function for the normalized Gaussian function and then a function that returns a random Gaussian number: /** * * @param a - Absolute maximum * @param b - Mean or center point * @param c - Standard deviation or width * @param x - x-value along the gaussian function * @return corresponding y-value along the gaussian function */ public static double gaussian(double a, double b, double c, double x) { return a * Math.exp( -Math.pow(x-b, 2) / (2 * Math.pow(c, 2)) ); } /** * * @param mu - Mean or center point * @param sigma - Standard deviation or width * @param x - x-value along the gaussian function * @return corresponding y-value along the gaussian function */ public static double gaussianNormalized(double mu, double sigma, double x) { return gaussian( 1 / (sigma * Math.sqrt(2 * Math.PI)), mu, sigma, x); } My issue is that the numbers it provides will always be distributed in an equal fashion to that of the Java Random class which is not what I'm looking for. How can I go about returning numbers that conform to a normalized Gaussian function distribution? am I going about this in the wrong way? Quote Link to comment Share on other sites More sharing options...
HunterRS Posted October 28, 2017 Share Posted October 28, 2017 Correct me if I am wrong, you are trying to write Random.nextGaussian() by only using java's normal random generator? Quote Link to comment Share on other sites More sharing options...
TheWind Posted October 28, 2017 Author Share Posted October 28, 2017 (edited) 4 hours ago, HunterRS said: Correct me if I am wrong, you are trying to write Random.nextGaussian() by only using java's normal random generator? Yes, something like that. From reading through a few more articles it appears the easiest way to achieve something like this is to simply use the Random.nextGaussian() method and adjust the output based on the parameters you want the function to follow. Although I would prefer to solve it the other way using a random double or int Edited October 28, 2017 by TheWind Quote Link to comment Share on other sites More sharing options...
Explv Posted October 28, 2017 Share Posted October 28, 2017 11 hours ago, TheWind said: I've been working to learn about the Gaussian Function, Probability Density Functions, and Cumulative Distribution Functions. https://en.wikipedia.org/wiki/Gaussian_function https://en.wikipedia.org/wiki/Probability_density_function https://en.wikipedia.org/wiki/Cumulative_distribution_function From my understanding you have the Gaussian function: and the integral of the Gaussian function is only equal to 1 when a = 1/(c * sqrt(2pi)) In this case, it can be used as a probability density function with normally distributed values. (This form is used for statistical analysis) b = mu (mean) c^2 = sigma^2 (standard deviation squared or the variance) The above is the relation of the variables of the regular Gaussian function to that of the Normal Distribution (as it's used in statistics). I've never taken a statistics class, so forgive me if I'm wrong on something. Most of the information here is from the wiki page or other resources I was reading to learn from. My goal is to write a function which utilizes the normalized Gaussian function to make a method that returns a random Gaussian number. By doing so it would return numbers closer to the mean more often than those that are farther away. What I tried to do was write a function for the standard Gaussian function, another function for the normalized Gaussian function and then a function that returns a random Gaussian number: /** * * @param a - Absolute maximum * @param b - Mean or center point * @param c - Standard deviation or width * @param x - x-value along the gaussian function * @return corresponding y-value along the gaussian function */ public static double gaussian(double a, double b, double c, double x) { return a * Math.exp( -Math.pow(x-b, 2) / (2 * Math.pow(c, 2)) ); } /** * * @param mu - Mean or center point * @param sigma - Standard deviation or width * @param x - x-value along the gaussian function * @return corresponding y-value along the gaussian function */ public static double gaussianNormalized(double mu, double sigma, double x) { return gaussian( 1 / (sigma * Math.sqrt(2 * Math.PI)), mu, sigma, x); } My issue is that the numbers it provides will always be distributed in an equal fashion to that of the Java Random class which is not what I'm looking for. How can I go about returning numbers that conform to a normalized Gaussian function distribution? am I going about this in the wrong way? Consider having a read of the Java Random.nextGaussian method: https://docs.oracle.com/javase/8/docs/api/java/util/Random.html#nextGaussian-- Quote Link to comment Share on other sites More sharing options...