Dr. Iyad Jafar. Adapted from the publisher slides

Similar documents
Chapter 7 Statistics, Probability, and Interpolation

Properties of Continuous Probability Distributions The graph of a continuous probability distribution is a curve. Probability is represented by area

( x) ( ) F ( ) ( ) ( ) Prob( ) ( ) ( ) X x F x f s ds

Probability and Statisitcs

Random variables, Expectation, Mean and Variance. Slides are adapted from STAT414 course at PennState

Computer Applications for Engineers ET 601

Week 4 Concept of Probability

Notes for Math 450 Lecture Notes 1

Discrete-Time Signals and Systems

Design of Engineering Experiments

In this course, we will be examining large data sets coming from different sources. There are two basic types of data:

Lecture 7 Random Signal Analysis

Probability Distributions

Topic 6 Continuous Random Variables

Math Review Sheet, Fall 2008

Continuous Random Variables

Recall the Basics of Hypothesis Testing

2007 Winton. Empirical Distributions

Poisson population distribution X P(

1. Exploratory Data Analysis

Lecture 10: Probability distributions TUESDAY, FEBRUARY 19, 2019

Companion. Jeffrey E. Jones

Naive Bayes & Introduction to Gaussians

L2: Review of probability and statistics

ECO220Y Continuous Probability Distributions: Uniform and Triangle Readings: Chapter 9, sections

TELECOMMUNICATIONS ENGINEERING

Review of Probability. CS1538: Introduction to Simulations

Chapter 3. Chapter 3 sections

MATHEMATICS-IIA. 1. Calculate the variance and standard deviation of the following continuous frequency distribution

functions Poisson distribution Normal distribution Arbitrary functions

Session 2: Probability distributionsand density functions p. 1

Continuous Probability Distributions. Uniform Distribution

Probability theory for Networks (Part 1) CS 249B: Science of Networks Week 02: Monday, 02/04/08 Daniel Bilar Wellesley College Spring 2008

Introduction to Generating Functions

ECE 650. Some MATLAB Help (addendum to Lecture 1) D. Van Alphen (Thanks to Prof. Katz for the Histogram PDF Notes!)

Economics 573 Problem Set 4 Fall 2002 Due: 20 September

CIVL Continuous Distributions

Outline PMF, CDF and PDF Mean, Variance and Percentiles Some Common Distributions. Week 5 Random Variables and Their Distributions

Chapter 2. Random Variable. Define single random variables in terms of their PDF and CDF, and calculate moments such as the mean and variance.

STAT 516: Basic Probability and its Applications

ST2004 Week 8 Probability Distributions

MIDTERM EXAMINATION (Spring 2011) STA301- Statistics and Probability

SUMMARIZING MEASURED DATA. Gaia Maselli

Describing Distributions with Numbers

Outline. Random Variables. Examples. Random Variable

Machine Learning. Theory of Classification and Nonparametric Classifier. Lecture 2, January 16, What is theoretically the best classifier

(Ch 3.4.1, 3.4.2, 4.1, 4.2, 4.3)

2.3 Estimating PDFs and PDF Parameters

Random Variables. Saravanan Vijayakumaran Department of Electrical Engineering Indian Institute of Technology Bombay

Applied Numerical Analysis Homework #3

1. Poisson Distribution

MIT Spring 2015

(Ch 3.4.1, 3.4.2, 4.1, 4.2, 4.3)

Random Variables and Their Distributions

Deep Learning for Computer Vision

Moments. Raw moment: February 25, 2014 Normalized / Standardized moment:

9.07 MATLAB Tutorial. Camilo Lamus. October 1, 2010

Chapter 7: Theoretical Probability Distributions Variable - Measured/Categorized characteristic

Data Analysis I. Dr Martin Hendry, Dept of Physics and Astronomy University of Glasgow, UK. 10 lectures, beginning October 2006

Random variable X is a mapping that maps each outcome s in the sample space to a unique real number x, < x <. ( ) X s. Real Line

Hands-on Generating Random

National Workshop on LaTeX and MATLAB for Beginners

SDS 321: Introduction to Probability and Statistics

Math 105 Course Outline

Chapter 4: Monte Carlo Methods. Paisan Nakmahachalasint

Introduction to Statistics and Error Analysis II

2 (Statistics) Random variables

Introduction to Probability and Statistics Slides 3 Chapter 3

Introduction to Measurement Physics 114 Eyres

Statistical Methods: Introduction, Applications, Histograms, Ch

Laboratory Project 1: Introduction to Random Processes

RVs and their probability distributions

Joint Distribution of Two or More Random Variables

INF FALL NATURAL LANGUAGE PROCESSING. Jan Tore Lønning

Math 180A. Lecture 16 Friday May 7 th. Expectation. Recall the three main probability density functions so far (1) Uniform (2) Exponential.

Lesson B1 - Probability Distributions.notebook

Math Numerical Analysis Mid-Term Test Solutions

Modeling Uncertainty in the Earth Sciences Jef Caers Stanford University

Introduction to Basic Statistics Version 2

SECTION 7: CURVE FITTING. MAE 4020/5020 Numerical Methods with MATLAB

Complex Systems Methods 11. Power laws an indicator of complexity?

Joint Probability Distributions and Random Samples (Devore Chapter Five)

Descriptive Statistics

A Probability Primer. A random walk down a probabilistic path leading to some stochastic thoughts on chance events and uncertain outcomes.

2. A Basic Statistical Toolbox

Chapter 3, 4 Random Variables ENCS Probability and Stochastic Processes. Concordia University

Week 9, 10/15/12-10/19/12, Notes: Continuous Distributions in General and the Uniform Distribution

Probability Theory. Prof. Dr. Martin Riedmiller AG Maschinelles Lernen Albert-Ludwigs-Universität Freiburg.

ECE Homework Set 2

Chapter 7 Probability Basics

Lecture 6. Probability events. Definition 1. The sample space, S, of a. probability experiment is the collection of all

Random Variables. Statistics 110. Summer Copyright c 2006 by Mark E. Irwin

Calculus with Algebra and Trigonometry II Lecture 21 Probability applications

Random Number Generation. CS1538: Introduction to simulations

Recitation 2: Probability

Machine Learning: Probability Theory

Discrete Random Variables

Section 4.3: Continuous Data Histograms

Chapter 1 Statistical Reasoning Why statistics? Section 1.1 Basics of Probability Theory

Unit 4 Probability. Dr Mahmoud Alhussami

Transcription:

Computer Applications Lab Lab 9 Probability, Statistics, Interpolation, and Calculus Chapter 7 Dr. Iyad Jafar Adapted from the publisher slides

Outline Statistics and Probability Histograms Normal and Uniform Distributions Random Number Generation Interpolation 2

Common Statistical Functions MATALB provides several functions to compute statistical properties of any set of numerical data Function Description mean(x) Computes the average value for the elements of vector x. median(x) Computes the median value for the elements in vector x. std(x) Computes the standard deviation of the elements in vector x. cumsum(x) Returns a vector the same size of x containing the cumulative sum of the elements in x. For the first three commands, if x is a matrix, Matlab returns a raw vector in which each element is the result of applying these function to its columns. cumsum returns a matrix that contains cumulative sums of the columns. 3

Examples >> x =[ones(1,5)*3,ones(1,4),ones(1,6)*(2)]; >> mean(x) ans = 31 >> median(x) ans = 2 >> std(x) ans = 0.7988 >> cumsum(x) ans = 3 6 9 12 15 16 17 18 19 21 23 25 27 29 31 4

Histograms Given a set of data values stored in vector x, the histogram of x is a display of statistical information that uses rectangles to show the frequency of data items in successive numerical intervals of equal size. Histograms are useful in studying data properties and distribution as they can be used to approximate the probability function. Suppose x = [1,1,1,3,4,4,5,5,5,6,6,7,7,7,7,7,7], the histogram of Histogram of x 7 these values is shown below. 6 5 Absolute Frequency 4 3 2 1 0 0 1 2 3 4 5 6 7 8 x 5

Histograms To generate histograms in MATALB, use the hist(x) function or its variants (discussed later) bar(x,y), where x is a vector containing the centers of the bars (counts) and y is a vector containing the frequencies of the values in each bar. Example >> x = [1,1,1,3,4,4,5,5,5,6,6,7,7,7,7,7,7]; >> hist(x,[0:8]); % here we specified the bin centers. If not provided, Matlab default is 10 bins between the min and max of input data OR >> x = [0:8] ; % specify bar centers >> y = [0,3,0,1,2,3,2,6,0]; % absolute frequencies manually computed >> bar(x,y); 6

Histograms Command Description bar(x,y) Creates a bar chart of y versus x. hist(y) hist(y,n) hist(y,x) [z,x] = hist(y) [z,x] = hist(y,n) [z,x] = hist(y,x) Aggregates the data in the vector y into 10 bins evenly spaced between the minimum and maximum values in y. Aggregates the data in the vector y into n bins evenly spaced between the minimum and maximum values in y. Aggregates the data in the vector y into bins whose center locations are specified by the vector x. The bin widths are the distances between the centers. Same as hist(y) but returns two vectors z and x that contain the frequency count and the bin locations. Same as hist(y,n) but returns two vectors z and x that contain the frequency count and the bin locations. Same as hist(y,x) but returns two vectors z and x that contain the frequency count and the bin locations. The returned vector x is the same as the user-supplied vector x 7

Probability In any experiment or phenomena, the probability of an event is a number between 0 and 1 that indicates the likelihood of that event to occur if the experiment is repeated infinitely Example: Rolling a dice. The probability of obtaining any of the number on the dice is 1/6. Random variable is often the term used to express the outcome of an experiment. In rolling a dice, the random variable may take any of the values 1,2,3,4,5,6. Based on the experiment, these random variables could be continuous or discrete. 8

Probability -Example 9

Probability Probability Functions Random variables are usually associated with functions or distributions to characterize the experiment they come from. Such functions are called probability density functions (pdf). If available, these distributions can be used to calculate the probability of the random variable to take certain value(s). The area under pdf is always equal to 1. this is based on the fact that we will obtain any of the possible outcomes if we run the experiment. 10

Common Distributions Uniform Distribution pdf (x) 1, a x b = b a 0, otherwise 1 b - a Normal Distribution a b 0.45 0.4 1 pdf (x) = e 2πσ (x µ ) 2 2σ 2 0.35 0.3 0.25 0.2 0.15 0.1 0.05 0-6 -4-2 0 2 4 6 11

Computing Probability of an Event The probability that a random variable x is less than or equal than some value b is computed from the pdf by b P(x b) = pdf (x)dx = CDF(x) Continuous RV P(x x k) = pdf (x i) k i= Discrete RV This is usually referred as the cumulative distribution function CDF. For continuous random variables, the probability P(x=b) = 0. For discrete random variables, the probability P(x=x k ) = pdf(x k ) 12

Histograms as pdf For practical experiments, it is common to use the normalized histogram to represent the pdf of the experiment. The normalized histogram is defined as the absolute frequency histogram divided by total number of frequencies. 13

Example Suppose that x = [1,1,1,1,1,2,2,3,3,3,3,5,5,5,5,7,7,7,7,7,7,7,8] The following commands generates the normalized histogram of x with bin centers at 1 through 8. >> [y,binlocations] = hist(x,[1:8]) ; >> normhist = y / sum(y) ; % or could use normhist = y / numel(x) >> label( x ) >> ylabel( Normalized Histogram ) The probability of obtaining a number less than or equal to 3 can be found by >> cdf = cumsum(normhist) >> prob = cdf(3) 0.35 0.3 0.25 Normalized Histogram 0.2 0.15 0.1 0.05 0 1 2 3 4 5 6 7 8 x 14

Sums and Differences of Random Variables It can be proved that the mean of the sum (or difference) of two independent normally distributed random variables equals the sum (or difference) of their means, but the variance is always the sum of the two variances. That is, if x and y are normally distributed with means µ x and µ y, and variances σ x and σ y, and if u = x + y and υ = x y, then µ u = µ x + µ y µ υ = µ x µ y σ u2 = σ υ2 = σ x2 + σ y 2 15

Random Numbers Random numbers are extensively used in simulation and game programming. Matlab provides several functions to generate random numbers based on a given distribution. 16

Random Numbers rand rand(n) rand(m,n) Command s = rand( state ) Description Generates a single uniformly distributed random number between 0 and 1. Generates an n x n matrix containing uniformly distributed random numbers between 0 and 1. Generates an m x n matrix containing uniformly distributed random numbers between 0 and 1. Returns a 35-element vector s containing the current state of the uniformly distributed generator. rand( state,s) Sets the state of the uniformly distributed generator to s. rand( state,0) rand( state,j) rand( state,sum(100*clock)) Resets the uniformly distributed generator to its initial state. Resets the uniformly distributed generator to state j, for integer j. Resets the uniformly distributed generator to a different state each time it is executed. 17

Random Numbers randn randn(n) randn(m,n) Command s = randn( state ) randn( state,s) randn( state,0) randn( state,j) randn( state,sum(100*clo ck)) Description Generates a single normally distributed random number having a mean of 0 and a standard deviation of 1. Generates an n n matrix containing normally distributed random numbers having a mean of 0 and a standard deviation of 1. Generates an m n matrix containing normally distributed random numbers having a mean of 0 and a standard deviation of 1. Like rand( state ) but for the normally distributed generator Like rand( state,s) but for the normally distributed generator. Like rand( state,0) but for the normally distributed generator. Like rand( state,j) but for the normally distributed generator. Like rand( state,sum(100*clock)) but for the normally distributed generator. 18

Random Numbers Example: check the operation of randn >> x = randn(1,10000); >> [y,bins] = hist(x,[-4:0.01:4])); >> y = y / numel(x) >> Bar(bins,y) >> axis([-5 5 0 max(y)*1.1]) x 10-3 5 4 3 2 1 0-5 -4-3 -2-1 0 1 2 3 4 5 19

Random Numbers To generate uniformly distributed random numbers in the interval [a,b], use y = (b-a) * x + a Where x is a set of uniformly distributed numbers generated by rand function. Example: the following session generates 1000 uniformly distributed numbers in the interval [- 3,3]. >> x = rand(1,1000) ; >> y = (3+3) * x 3 ; >> [yhist,bins] = hist(y,[-4:0.1:4]); >> bar(bins,yhist); 20

Random Numbers 30 25 20 Distribution 15 10 Approximate Uniform 5 0-5 -4-3 -2-1 0 1 2 3 4 5 x 21

Random Numbers To generate normally distributed random numbers with a mean µ and standard deviation σ y = σ* x + µ Where x is a set of normally distributed numbers generated by randn function. Example : the following session generates 1000 normally distributed numbers with a mean of 5 and deviation of 1.5 >> x = randn(1,1000) ; >> y = 1.5* x + 5 ; >> [yhist,bins] = hist(x,[0:0.1:10]; >> bar(bins,yhist); 22

Random Numbers 35 30 25 20 15 10 Approximate Normal Distribution 5 0-2 0 2 4 6 8 10 12 x 23

Interpolation Engineering problems often require the analysis of data pairs; cause and effect, or input output relationships. It is sometimes required to estimate variable s value between the given data point. This process is known as interpolation. Plotting the data greatly aids interpolation and extrapolation. 24

Interpolation Linear and cubic spline interpolation 8 7 Linear Cubic Spline 6 5 y 4 3 2 1 0 0 1 2 3 4 5 6 x 25

Interpolation Function Y_int = interp1(x,y,x_int) Description Used to linearly interpolate a function of one variable: y = f (x). Returns a linearly interpolated vector y_int at the specified value x_int, using data stored in x and y. Z_int = interp2(x,y,z,x_int,y _int) Y_int = spline(x,y,x_int) Used to linearly interpolate a function of two variables: y = f (x, y). Returns a linearly interpolated vector z_int at the specified values x_int and y_int, using data stored in x, y, and z. Computes a cubic-spline interpolation where x and y are vectors containing the data and x_int is a vector containing the values of the independent variable x at which we wish to estimate the dependent variable y. The result Y_int is a vector the same size as x_int containing the interpolated values of y that correspond to x_int. 26

Interpolation When using interp1 or splinefunctions, note that x should be sorted in ascending order and x_intvalues should be within the range of x. Example: assume that x = [1,2,3,4,5] and y = [2,5,8,10,6]. Estimate the value of y when x_int = [2.5,3.5]. % using linear >> y_int = interp1(x,y,x_int) y_int = 6.5000 9.0000 % using cubic spline >> y_int = spline(x,y,x_int) y_int = 6.5000 9.3750 27