PATTERN RECOGNITION LAB 3 TA Nouf AlHarbi nouf
PATTERN RECOGNITION LAB 3 TA : Nouf Al-Harbi : : nouf 200@hotmail. com
Lab objective: 2 Illustrate the normal distribution of a random variable Draw two normal functions using the Gaussian formula
3 Part 1 Theoretical Concept
What’s Normal distribution. . ? 4 A normal distribution is a very important statistical data distribution pattern occurring in many natural phenomena � Height, weight , people age
Normal distribution 5 Certain data, when graphed as a histogram (data on the horizontal axis, amount of data on the vertical axis), creates a bellshaped curve known as a normal curve, or normal distribution.
6 Normal distribution A normal distribution of data means that most of the examples in a set of data are close to the "average, " while relatively few examples tend to one extreme or the other.
Normal distribution 7 Normal distributions are symmetrical a single central peak at the mean (average), (μ) of the data. 50% of the distribution lies to the left of the mean 50% lies to the right of the mean. The spread of a normal distribution is controlled by the standard deviation, (σ). � The smaller the standard deviation the more concentrated the data.
8 Normal Distribution form
9 Part 2 Practical Applying A. Using randn function
Normal distribution using randn 10 1. 2. 3. Generate N random values normally distributed where mu=20 , sigma=2 Find the frequency distribution of each outcome (i. e. how many times each outcome occur? ) Find the probability density function p(x)
randn 11 generates random numbers drawn from the normal distribution N(0, 1), i. e. , with mean (μ) = 0 and standard deviation (σ) =1 Write the following in Matlab & see the result: �r = randn(1, 6) � generates 1 -D array of one row and 6 columns To change the normal parameters we can use fix function
fix 12 x=fix(σ * r + μ ) x = fix( 2* r + 20); Writing the previous line convert r into random values normally distributed with � mean (μ) = 20 � standard deviation (σ) =2
Full code 13 N=1000000; mu = 20; % mean. sigma = 2; % standard deviation. r = randn(1, N); x = fix( sigma * r + mu ); xmax = max(x); f=zeros(1, xmax); for i=1: N j = x(i); f(j) = f(j)+1; end plot(f) p = f / N; figure, plot(p)
14 Part 2 Practical Applying B. Using Gaussian(normal) formula
15 Using Gaussian(normal) formula Instead of generating random values normally distributed (using randn), we can use: � Gaussian formula :
16 Draw 2 normal functions using Gaussian formula 1. For first normal function : N(20, 2) � � � 2. For second normal function : N(15, 1. 5) � � � 3. Mu 1=20 sigma 1=2 X=1: 40 Apply Gaussian Formula Mu 2=15 sigma 2=1. 5 X=1: 40 Apply Gaussian Formula Plot the normal functions
Full code 17 1 mu 1 = 20; sigma 1 = 2; p 1 = zeros(1, 40); for x = 1: 40 p 1(x) = (1/sqrt(2*pi*sigma 1))*exp(-(x-mu 1)^2/(2*sigma 1)); End mu 2 = 30; sigma 2 = 1. 5; p 2 = zeros(1, 40); for x = 1: 40 p 2(x) = (1/sqrt(2*pi*sigma 2))*exp(-(x-mu 2)^2/(2*sigma 2)); end x=1: 40; plot(x, p 1, 'r-', x, p 2, 'b-')
18 H. W 2 Write a Matlab function that compute the value of the Gaussian distribution for a given x. That is a function that accept the values of x, mu, and sigma, then return the value of N(mu, sigma) at the value of x. For example: call the function normalfn(x, mu, sigma). Then use it by issuing the command >>normalfn(15, 20, 3). %this should return the values of this pdf at x =15. Then, use this function to write another function to draw the normal distribution N(20, 2), i. e. , with normal distribution with mean = 20 and standard deviation = 2.
- Slides: 18