Normal Distribution

  1. Child: Imagine you and your friends are lining up according to your heights. If most of you are of average height, you’d be in the middle, with the shorter and taller ones at the ends. If we drew a line above your heads, it would look like a bell or a hill. That’s what we call a “normal distribution”.

  2. Teenager: Think about grades in your class. Some students get high grades, some get low grades, but most get grades somewhere in the middle, right? If you draw a graph with grades on the bottom and the number of students on the side, the graph will look like a hill or a bell shape. This is what we call a normal distribution.

  3. Undergrad majoring in the same subject: In statistics, a normal distribution is a type of continuous probability distribution for a real-valued random variable. The graph of the normal distribution is characterized by its bell shape, with the peak at the mean value, and it is symmetric around the mean. A lot of natural phenomena follow a normal distribution, like people’s heights or IQ scores.

  4. Grad student: The normal distribution, or Gaussian distribution, is a fundamental concept in statistics and is often used in the natural and social sciences for real-valued random variables. It’s characterized by two parameters, the mean (mu) and standard deviation (sigma). The mean indicates where the bell is centered, and the standard deviation determines the width of the bell. The properties of normal distribution, such as the 68-95-99.7 rule, are crucial in hypothesis testing and confidence interval estimation.

  5. Colleague (Fellow Researcher/Engineer): As you know, the normal distribution is central to many statistical procedures and theories, thanks to the Central Limit Theorem. The CLT states that the sum of a large number of independent and identically distributed random variables, irrespective of their shape, will approximately follow a normal distribution. This property makes the normal distribution very tractable analytically, which is why it’s widely used in fields like machine learning, finance, and physics.

The normal distribution, also known as the Gaussian distribution, is a continuous probability distribution that is symmetric about the mean and defined by two parameters - the mean μ and the standard deviation σ.

Some key properties:

  • Bell shaped and symmetric about the mean
  • Mean, median and mode are all equal
  • About 68% of values fall within 1 standard deviation of the mean
  • About 95% within 2 standard deviations
  • Probabilities can be calculated using the PDF f(x) = (1/(σ√(2π)) * e^(-0.5*(x-μ/σ)^2)

It is one of the most important distributions in statistics and is used to model many natural phenomena.

Example in Java:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import java.util.Random;

class NormalDistribution {

  public static double sample(double mean, double stdDev) {
    Random rand = new Random();
    return mean + stdDev * rand.nextGaussian();
  }

  public static void main(String[] args) {
    double x = sample(10, 2);
    System.out.println(x); 
  }

}

This samples a random value from a N(10, 4) distribution by using the Gaussian distribution in Java’s Random class.

Examples in C++ and Python follow a similar approach of using inbuilt random number generators for normal distribution. The standard normal can be generated and transformed to any normal distribution.

Description

The normal distribution, also known as the Gaussian distribution, is a probability distribution that is symmetric about the mean, showing up in the form of a bell curve.

It is characterized by two parameters - mean and standard deviation. About 68% of values lie within 1 standard deviation of the mean.

Normal distribution occurs frequently in natural processes due to the central limit theorem. Many measurements like heights and test scores follow normal distribution.

It is useful for modeling phenomena like measurement errors.

Solution

Here is code to generate normally distributed random numbers:

Java

1
2
3
4
5
6
7
8
9
double[] normalDist(int n, double mean, double stdDev) {
  double[] result = new double[n];
  Random rand = new Random();
  
  for(int i=0; i<n; i++) {
    result[i] = mean + stdDev * rand.nextGaussian();
  }
  return result;
}

C++

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
vector<double> normalDist(int n, double mean, double stdDev) {
  vector<double> result(n);
  default_random_engine generator;
  normal_distribution<double> distribution(mean, stdDev);

  for(int i=0; i<n; i++) {
    result[i] = distribution(generator);
  }
  return result;
}

Python

1
2
3
4
5
6
7
8
from random import normalvariate

def normal_dist(n, mean, std_dev):
  result = []
  for i in range(n):
    num = normalvariate(mean, std_dev)
    result.append(num)
  return result

Normal distribution provides a good model for natural phenomena like heights, errors etc.

Description: Normal Distribution

The Normal Distribution, also known as the Gaussian distribution, is a probability distribution that is symmetric about the mean. It’s often represented by a bell-shaped curve. It is fully characterized by its mean and standard deviation. In a normal distribution, about 68% of the data falls within one standard deviation from the mean, 95% within two standard deviations, and 99.7% within three standard deviations.

Solution:

You can generate a set of numbers that follow a normal distribution using programming languages. Let’s look at how to generate a series of random numbers that form a normal distribution in Java, C++, and Python.

Java

In Java, you can use the Random class to generate normally distributed numbers.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import java.util.Random;

public class NormalDistribution {
    public static void main(String[] args) {
        Random random = new Random();
        double mean = 0.0;
        double stdDev = 1.0;

        for (int i = 0; i < 10; i++) {
            double val = mean + stdDev * random.nextGaussian();
            System.out.println(val);
        }
    }
}

C++

In C++, you can use the <random> library to generate normally distributed numbers.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include <iostream>
#include <random>

int main() {
    std::default_random_engine generator;
    std::normal_distribution<double> distribution(0.0, 1.0);

    for (int i=0; i<10; ++i) {
        double val = distribution(generator);
        std::cout << val << std::endl;
    }

    return 0;
}

Python

In Python, you can use the numpy library to generate normally distributed numbers easily.

1
2
3
4
5
6
7
8
import numpy as np

mean = 0.0
stdDev = 1.0
size = 10

values = np.random.normal(mean, stdDev, size)
print(values)

Key Takeaways:

  • The Normal Distribution is defined by its mean and standard deviation.
  • Different programming languages provide ways to generate normally-distributed random numbers.
  • Libraries like numpy in Python make it very easy to generate these numbers.
  • In C++ and Java, you will often have to use additional libraries or built-in functions to achieve the same.