Bayesian inference of normal distribution

14
- 1 - Bayesian inference of normal distribution Problem statement Objective is to estimate unknown two parameters q={m,s 2 } of normal distribution based on observations y = {y 1 , y 2 , …}. • Prior Joint pdf of non-informative prior Joint posterior distribution This is function of two variables, which can be plotted as a surface or contour. 1 2 2 , p ms s 2 2 2 2 2 1 , | exp 1 2 n p y n s ny ms s m s = { } 2 2 2 1 1 2 2 2 2 2 2 2 1 1 1 | | exp 2 1 1 exp exp 2 2 n n n i i i i n n n n i i i i p y py y y y y y y ny q q s m s s m s m s s = = = = = = 2 2 1 w here 1 i s y n m =

description

Bayesian inference of normal distribution. Problem statement Objective is to estimate unknown two parameters q ={m,s 2 } of normal distribution based on observations y = {y 1 , y 2 , …}. Prior Joint pdf of non-informative prior Joint posterior distribution - PowerPoint PPT Presentation

Transcript of Bayesian inference of normal distribution

Page 1: Bayesian inference of normal distribution

- 1 -

Bayesian inference of normal distribution

• Problem statement– Objective is to estimate unknown two parameters q={m,s2} of normal

distribution based on observations y = {y1, y2, …}.

• Prior– Joint pdf of non-informative prior

• Joint posterior distribution

• This is function of two variables, which can be plotted as a surface or contour.

12 2,p m s s

22 2 22

1, | exp 12

np y n s n ym s s ms

=

{ }

222

11

2 2 22 22 2

1 1

1| | exp2

1 1exp exp2 2

n nn

i iii

n nn n

i ii i

p y p y y

y y y y y n y

q q s ms

s m s ms s

==

= =

= =

22 1where 1 is y

nm=

Page 2: Bayesian inference of normal distribution

- 2 -

Joint posterior distribution

• Distribution– There is no inherent pdf function by matlab in this case.

• This is function of two variables, which can be plotted as a surface or contour.

– Let’s consider a case with n=20; y =2.9; s=0.2;

• Remark– Analysis of posterior pdf: mean, median & confidence bounds.

• Marginal distribution

• Once we have the marginal pdf, we can evaluate its mean and confidence bounds.

– Posterior prediction: predictive distribution of new y based on observed y.

22 2 22

1, | exp 12

np y n s n ym s s ms

=

2 2 2| | , , |p y y p y p y d dm s m s m s=

2 2 2 2| , | , | , |p y p y d p y p y dm m s s s m s m= =

This is posterior pdf of m & s2 This is likelihood of new y

Page 3: Bayesian inference of normal distribution

- 3 -

• Analytical solutions– Marginal mean

– Marginal variance

• How to evaluate marginal distributions– Before doing this, note that in normal dist., variable y can be transformed to

standard normal variable z.

– Marginal mean & variance can be evaluated in the same manner.– One can evaluate various characteristics using the matlab functions.

Marginal distributions

2

2 2 22| , | 1 ~ 1sp y p y d n ns m s m

s=

2 2| , |p y p y dm m s s=

~ , , ~ 0,1yy N z z Nmm ss

=

, ~ 1/yz z t n

s nmm

=

2

2 221 , ~ 1sz n z ns

s =

22 2 22

1, | exp 12

np y n s n ym s s ms

=

2

212

z

f z e

=

Page 4: Bayesian inference of normal distribution

- 4 -

Marginal distributions

• Supplementary information for normal pdf– The original pdf fY(y) and normalized pdf fZ(z) have following relation.

– Therefore, – If we want use f(z) instead of f(y), use this relation.

• Supplementary information for chi2 pdf– The original pdf fY(y) and normalized pdf fZ(z) have following relation.

– Therefore,

1Y Zf y f z

s=

z y y yZ

z Z Z Y y

f zyF f z dz f z d dy f y dy Fms s

= = = = =

22

2Zzf f z

ss

s=

2

2 22

2 2 22

b a

a b

z

z Z Zz

zF f z dz f z d f d Fs

s sss s s

s= = = =

Page 5: Bayesian inference of normal distribution

- 5 -

Posterior prediction

• Predictive distribution of new y based on observed y

• Analytical solution

– One can evaluate characteristics of this using the matlab function.– Compare with the marginal mean.

• Marginal mean: t-distribution with location y and variance s^2/n with n-1 dof.• Predictive distribution: t-distribution with location y and variance s^2*(1+1/n) with n-1

dof.

2 2 2| | , , |p y y p y p y d dm s m s m s=

posterior pdf of m & s2 Likelihood of new y

22 2 22

1, | exp 12

np y n s n ym s s ms

= 2

22

1| , exp22y

p ym

m sss

=

| ~ 111

y yp y y z z t ns

n

=

Page 6: Bayesian inference of normal distribution

- 6 -

Simulation of joint posterior distribution

• Why ?– Even when analytic solutions available, some are not easy to evaluate.– Once exercised, may find it more convenient and more general.– Practice simulation & validate with analytic solution.

• Factorization approach– Review: joint probability of A & B

– Likewise, joint posterior pdf of m & s2

• The two at the right are marginal pdfs.

• Simulation by drawing random samples– We can evaluate characteristics of joint posterior pdf using simulation

techniques.

S

A

B

Pr(A | B)

, | |P A B P A B P B P B A P A= =

2 2 2 2, | | , | | , |p y p y p y p y p ym s m s s s m m= =

Page 7: Bayesian inference of normal distribution

- 7 -

Simulation of joint posterior distribution

• Approach 1: use marginal variance.

– Conditional pdf of m on s2 is already derived, which is the pdf of mean with known variance. (page 10 of Lec. #4)

– Marginal pdf of s2 is given in this lecture.

– In order to sample the posterior pdf of p(m,s2|y)1. Draw s2 from the marginal pdf 2. Draw m from the conditional pdf

2 2 2, | | , |p y p y p ym s m s s=

2 2| ~ , /N y nm s s

2 2 2| ~ Inv 1, or y n ss 2

221 ~ 1sz n n

s=

2 2 2| ~ Inv 1,y n ss

2 2| ~ , /N y nm s s

Marginal pdf of s2Conditional pdf of m on s2

Page 8: Bayesian inference of normal distribution

- 8 -

Simulation of joint posterior distribution

• Approach 1: use marginal variance.

– Once you have obtained samples of joint pdf, compare (validate) the results with the analytic solution.

1. Compare the samples of (M,S2) with the analytic joint pdf.• In terms of scattered pot & contour.• In terms of 3-D histogram & surface (mesh).

2. Compare the samples of M with the marginal pdf, which is t distribution.3. Compare the samples of S2 with the marginal pdf which is inv-chi2 dis-

tribution.4. Extract features of the samples M and compare with analytic solution.5. Extract features of the samples S2 and compare with analytic solution.

Page 9: Bayesian inference of normal distribution

- 9 -

Simulation of joint posterior distribution

• Approach 2: use marginal mean.

– Conditional pdf of s2 on m is already derived, which is the pdf of variance with known mean. (page 13 of Lec. #4)

– Marginal pdf of m is given in this lecture.

– In order to sample the posterior pdf of p(m,s2|y)1. Draw m from the marginal pdf 2. Draw s2 from the conditional pdf

– Compare (validate) the resulting samples with the analytic solution.

Marginal pdf of mConditional pdf of s2 on m 2 2, | | , |p y p y p ym s s m m=

2 2| ~ Inv , orn vs m 2

22 22

1~ where 1z n n v n s n yn

ms

= =

21| ~ , / or ny t y s nm ~ 1

/yz t n

s nm

=

21| ~ , /ny t y s nm

2 2| ~ Inv ,n vs m

Page 10: Bayesian inference of normal distribution

- 10 -

Simulation of joint posterior distribution

• Approach 2: use marginal mean.

– Once you have obtained samples of joint pdf, compare (validate) the results with the analytic solution.

– Details are omitted for limited time.

Page 11: Bayesian inference of normal distribution

- 11 -

Posterior prediction by simulation

• Analytic approach

– Result of analytic solution by double integral over infinity to get

• Simulation– In practice, posterior predictive distribution is obtained by random

draws. – Once we have posterior distribution for m & s2 in the form of samples,

the predictive new y are easily obtained by drawing each one from conditional on each individual m & s2.

– Mean & conf. intervals of posterior prediction can be obtained easily.

2 2 2| | , , |p y y p y p y d dm s m s m s=

22 2 22

1, | exp 12

np y n s n ym s s ms

= 2

22

1| , exp22y

p ym

m sss

=

| ~ 111

y yp y y z z t ns

n

=

2| ,p y m s

Page 12: Bayesian inference of normal distribution

- 12 -

Homework

Page 13: Bayesian inference of normal distribution

- 13 -

Homework

Page 14: Bayesian inference of normal distribution

- 14 -

Homework

• Problems 11) Use the approach 1 to obtain samples of joint pdf (M,S2).2) Compare scattered dots with contour of analytic solution.

Compare 3-D histogram with mesh shape of analytic solution.3) Compare the samples of M with the marginal pdf, which is t distribution.4) Compare the samples of S2 with the marginal pdf which is inv-chi2 dist.5) Obtain mean, 95% conf. interval of M, & compare with analytic solution.6) Obtain mean, 95% conf. interval of S2, & compare with analytic solu-

tion.7) Obtain samples of posterior prediction, and

obtain mean, 95% conf. interval of ynew & compare with analytic solu-tion.