pattern recognition lab 2 ta : nouf al-harbi::

Post on 20-Jan-2018

223 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Theoretical Concept Part 1 3

TRANSCRIPT

PATTERN RECOGNITION

LAB 2TA : Nouf Al-Harbi :: nouf200@hotmail.com

2

Lab objective: Illustrate the uniform distribution of a

random variable using Matlab

3

Theoretical Concept

Part 1

4

Suppose a die is rolled. What is the probability that the die will land on 5 ?

On 4 , on 2?.…

Dice Experiment

5

Dice Experiment When a die is rolled there are 6 possible outcomes represented by: X = { 1, 2, 3, 4, 5, 6 }. Each outcome is equally likely to occur

If a die is rolled 1200 times Then , each of outcome should occur

1200/6 = 200 times

FrequencyF(X)

Outcome x

200 1200 2200 3200 4200 5200 6

Frequency distribution

6

Dice Experiment What’s the probability for occurring each

outcome ..? P(X = 6) = 200/1200 =1/6 P(X=3)=P(X=1)=200/1200=1/6

A probability distribution is a table or an equation that links each outcome of a statistical experiment with its probability of occurrence

If each outcome has the same probability then probability density function is called

“uniform distribution”

Probability P(X=x) Outcome x

1/6 11/6 21/6 31/6 41/6 51/6 6

probability distribution

7

What’s uniform distribution?..

We obtain a uniform density function when the outcomes of an experiment (random process) are equally likely to occur.

1 2 3 4 5 6

1outcome

Prob. Of occurrence

8

Practical Applying

Part 2

9

Applying dice experiment by Matlab

1. Generate N random values uniformly distributed in the closed range [1,6].

2. Find the frequency distribution of each outcome (1-6)

(i.e. how many times each outcome occur?)

3. Find the probability density function p(x)

4. Plot p

10

Generate N random values uniformly distributed in the closed range [1,6].

Step 1

11

rand functionrand(1,N)

Generates N random values uniformly distributed in the open range ]0,1[.

Write the following in Matlab & see the result: r = rand(1,20) generates 1-D array of one row and 20 columns Random values range between 0 and 1

To change the period we can use fix function

12

fix function x = fix( 6 * r ) + 1; Writing the previous line converts r

into random values in the closed period [1,6]

For Dice Experiment, What are the values of vector x represent..?

13

Find the frequency distribution of each outcome (1-6)

Step 2

14

Find the frequency distribution of outcome we’ll make a counter for each outcome

1 2 3 4 5 6120 191 199 210 300 180f

Event no. 1 2 3 4 5 6 7 … 1200

outcome 2 1 1 2 5 6 6 … 2

N

x

15

Find the probability density function p(x)

Step 3

16

Find the probability density function p(x)

We can easily calculate the probability the outcome frequency divided by the no.

of events P=f/N

17

Plot the probability density function p(x)

Step 4

18

plot p(x) plot function has different forms , depending on

input arguments. If you have two vectors y and x

plot (x,y) produces a graph of y versus x If you have one vector x

plot(x) produces a graph of columns of x versus their index

To change the axis scale, that is x starts from xmin to xmax and y starts from ymin to ymax use the command:

axis([xmin xmax ymin ymax])

19

plot p(x) If we have more than one graph, we

can use figure command to create a new figure window It’s useful to avoid draw the new graph

over the previous one For more information about plot

function and its forms type help plot on command window

20 1. N = 100;2. r = rand(1,N); 3. x = fix( 6 * r ) + 1;4. f = zeros(1,6);5. for i = 1 : N6. if x(i) == 1 f(1) = f(1) + 1;7. elseif x(i) == 2 f(2) = f(2) + 1;8. elseif x(i) == 3 f(3) = f(3) + 1;9. elseif x(i) == 4 f(4) = f(4) + 1;10.elseif x(i) == 5 f(5) = f(5) + 1;11.else f(6) = f(6) + 1;12.end13.end14.F15.plot(f)16.axis([0 7 0 1.5])17.p = f /N18.figure, plot(p)19.axis([0 7 0 0.3])

Full code

Try larger values of N:

(1000,10000 )and notice the graph

21

•Write a Matlab function to illustrate a uniform distribution of coin experiment .•A function should take the number of events N as an argument

Exercise 1

top related