Download presentation
Presentation is loading. Please wait.
Published byCarmella Gilmore Modified over 9 years ago
1
PATTERN RECOGNITION LAB 3 TA : Nouf Al-Harbi:: nouf200@hotmail.com
2
Lab objective: Illustrate the normal distribution of a random variable Draw two normal functions using the Gaussian formula 2
3
Theoretical Concept Part 1 3
4
What’s Normal distribution..? A normal distribution is a very important statistical data distribution pattern occurring in many natural phenomena Height, weight, people age 4
5
Normal distribution Certain data, when graphed as a histogram (data on the horizontal axis, amount of data on the vertical axis), creates a bell- shaped curve known as a normal curve, or normal distribution. 5
6
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 6
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. 7
8
Normal Distribution form 8
9
Practical Applying A. Using randn function Part 2 9
10
Normal distribution using randn 1. Generate N random values normally distributed where mu=20, sigma=2 2. Find the frequency distribution of each outcome (i.e. how many times each outcome occur?) 3. Find the probability density function p(x) 10
11
randn 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 6columns To change the normal parameters we can use fix function 11
12
fix 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 12
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) Full code 13
14
Practical Applying B. Using Gaussian(normal) formula Part 2 14
15
Using Gaussian(normal) formula 15 Instead of generating random values normally distributed (using randn), we can use: Gaussian formula :
16
Draw 2 normal functions using Gaussian formula 16 1. For first normal function : N(20,2) Mu1=20 sigma1=2 X=1:40 Apply Gaussian Formula 2. For second normal function :N(15,1.5) Mu2=15 sigma2=1.5 X=1:40 Apply Gaussian Formula 3. Plot the normal functions
17
mu1 = 20; sigma1 = 2; p1 = zeros(1,40); for x = 1:40 p1(x) = (1/sqrt(2*pi*sigma1))*exp(-(x-mu1)^2/(2*sigma1)); End mu2 = 30; sigma2 = 1.5; p2 = zeros(1,40); for x = 1:40 p2(x) = (1/sqrt(2*pi*sigma2))*exp(-(x-mu2)^2/(2*sigma2)); end x=1:40; plot(x,p1,'r-',x,p2,'b-') Full code 17
18
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. H.W 2 18
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.