180 likes | 296 Views
Pattern recognition lab 3. TA : Nouf Al-Harbi :: nouf200@hotmail.com. Lab objective:. Illustrate the normal distribution of a random variable Draw two normal functions using the Gaussian formula. Part 1. Theoretical Concept. What’s Normal distribution ..?.
E N D
Pattern recognition lab 3 TA : Nouf Al-Harbi :: nouf200@hotmail.com
Lab objective: • Illustrate the normal distribution of a random variable • Draw two normal functions using the Gaussian formula
Part 1 Theoretical Concept
What’s Normal distribution ..? • A normal distribution is a very important statistical data distribution pattern occurring in many natural phenomena • Height, weight , people age
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.
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 • 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.
Part 2 Practical Applying Using randn function
Normal distribution using randn • 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 • 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
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
Full code 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)
Part 2 Practical Applying Using Gaussian(normal) formula
Using Gaussian(normal) formula • Instead of generating random values normally distributed (using randn), we can use: • Gaussian formula :
Draw 2 normal functions using Gaussian formula • For first normal function : N(20,2) • Mu1=20 sigma1=2 • X=1:40 • Apply Gaussian Formula • For second normal function :N(15,1.5) • Mu2=15 sigma2=1.5 • X=1:40 • Apply Gaussian Formula • Plot the normal functions
Full code 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-') 1 2 3
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.