computabonal&physicsparticle.korea.ac.kr/class/2016/phys461/cphy_stat-ch02.pdf · 2016. 6. 11. ·...
TRANSCRIPT
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
ComputaBonal PhysicsExamples of Probability FuncBons
Korea University Eunil Won
1
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
Binomial distribuBon
2
• Binomial distribuBon Consider a series of N independent trials with only two possible outcomes. When the desired outcome of one trial is p, the probability of finding n desired outcome from N trials is governed by the binomial distribuBon.
The probability to have n desired outcomes in N events is
f(n;N, p) =N !
n!(N � n)!pn(1� p)N�n
The expectaBon and the variance are
V [n] = E[n2]� (E[n])2 = Np(1� p)
Can you prove them?
E[n] =NX
n=0
nN !
n!(N � n)!pn(1� p)N�n = Np
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
Binomial distribuBon -‐ proof 1
3
The expectaBon value can be found as
E[n] =NX
n=0
nN !
n!(N � n)!pn(1� p)N�n
= NpNX
n=1
(N � 1)!(n� 1)!
�(N � 1)� (n� 1)
�!p(n�1)(1� p)(N�1)�(n�1)
with m = n� 1, M = N � 1,
= NpMX
m=0
M !
m!(M �m)!pm(1� p)M�m
= Np
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
Binomial distribuBon -‐ proof 2
4
The variance can be found as
E[n(n� 1)] =NX
n=0
n(n� 1) N !n!(N � n)!p
n(1� p)N�n
=NX
n=2
N !
(n� 2)!(N � n)!pn(1� p)N�n
= N(N � 1)p2NX
n=2
(N � 2)!(n� 2)!
�(N � 2)� (n� 2)
�!pn�2(1� p)(N�2)�(n�2)
= N(N � 1)p2
E[n2] = E[n(n� 1) + n] = E[n(n� 1)] + E[n]
) V [n] = E[n2]� (E[n])2 = N(N � 1)p2 +Np� (Np)2 = Np(1� p)
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
Binomial distribuBon -‐ example
5
N= 5, p=0.5 N=10, p=0.5
N=20, p=0.2 N=20, p=0.5
Can you write ROOT C++ code that draws this?
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
Binomial distribuBon
6
#include //// Drawing a binomial function//// E. Won ([email protected])
Double_t f1(Int_t n, Int_t N, Double_t p) { Double_t fac = TMath::Power(p,n)*TMath::Power((1.0-p),N-n); for (Int_t i=1;iSetStyle("Plain"); gROOT->ForceStyle();
TCanvas* c = new TCanvas("c","",200,10,600,400); c->Divide(2,2); h1 = new TH1F("h1","",20,0.0,20); h1->SetMaximum(0.4); h2 = new TH1F("h2","",20,0.0,20); h2->SetMaximum(0.4); h3 = new TH1F("h3","",20,0.0,20); h3->SetMaximum(0.4); h4 = new TH1F("h4","",20,0.0,20); h4->SetMaximum(0.4); h1->SetFillColor(3);h2->SetFillColor(3); h3->SetFillColor(3);h4->SetFillColor(3); for (Int_t i=0;iFill(i,f1(i, 5,0.5)); h2->Fill(i,f1(i,10,0.5)); h3->Fill(i,f1(i,20,0.2)); h4->Fill(i,f1(i,20,0.5)); } c->cd(1); h1->Draw(); c->cd(2); h2->Draw(); c->cd(3); h3->Draw(); c->cd(4); h4->Draw();}
- the source code
The funcBon f1 returns the binomial distribuBon
mailto:[email protected]
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
Binomial distribuBon -‐ example
7
• Histogram Suppose we are interested in one parBcular bin of a compound histogram. Then “success” may correspond to geVng an entry in this parBcular bin, and “failure” corresponds to an entry in any other bin of the histogram -‐ so it is related with the binomial distribuBon.
The probability p for a success is p = n/N when n and N are entries in the bin and the total number of events in the histogram.
V [n] = Np(1� p) = N nN
⇣1� n
N
⌘= n
⇣1� n
N
⌘
�[n] =
rn⇣1� n
N
⌘⇡
pn for p ! 0 (or N ! 1)
Half size of the verBcal bar shows the “error of yi”
�yi : error of yi�yi =
pyi
We did this when we discussed histogram errors!
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
MulBnomial distribuBon
8
• MulBnomial distribuBon GeneralizaBon of the binomial distribuBon with m different possible outcomes. For a parBcular outcome has the probability pi, and of course
mX
i=1
pi = 1
f(n1, ..., nm;N, p1, ..., pm) =N !
n1!n2!..nm!pn11 p
n22 ...p
nmm
The expectaBon and the variance areE[ni] = Npi and V [ni] = Npi(1� pi)
ex) For three possible outcomes
f(ni, nj ;N, pi, pj) =N !
ni!nj !(N � ni � nj)!pnii p
njj (1� pi � pj)
N�ni�nj
The covariance becomescov[ni, nj ] = �Npipj
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
Poisson DistribuBon
9
• Poisson distribuBon LimiBng case of the binomial distribuBon when N becomes large, p very small but the product Np (i.e. the expectaBon value) remains a finite value ν
f(n; ⌫) =⌫n
n!e�⌫
E[n] =1X
n=0
n⌫n
n!e�⌫ = ⌫ V [n] =
1X
n=0
(n� ⌫)2 ⌫n
n!e�⌫ = ⌫
The expectaBon and the variance are
ν=2 ν=10
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
Poisson DistribuBon
10
• Poisson distribuBon LimiBng case of the binomial distribuBon when N becomes large, p very small but the product Np (i.e. the expectaBon value) remains a finite value ν -‐ proof
Np = ⌫ and SBrling’s formula gives N ! ⇡p2⇡NNNe�N
so,N !
n!(N � n)!pn(1� p)N�n = 1
n!
p2⇡NNNe�Np
2⇡(N � n)(N � n)(N�n)e�(N�n)⇣ ⌫N
⌘n⇣1� ⌫
N
⌘N�n
⇡ 1n!
N (N�n)e�N
(N � n)(N�n)e�(N�n)⌫n
⇣1� ⌫
N
⌘N�n
⇡ 1n!
1
(1� nN )(N�n)en⌫n
⇣1� ⌫
N
⌘N�n
⇡ 1n!
1
(1� nN )Nen⌫n
⇣1� ⌫
N
⌘N (1� ⌫N )�n
(1� nN )�n
⇡ e�⌫⌫n
n!
limN!1
⇣1 +
✏
N
⌘N= e✏
is used.
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
Uniform DistribuBon
11
• Uniform distribuBon The uniform p.d.f. for the conBnuous variable is defined by
f(x;↵,�) =
⇢ 1��↵ ↵ x �0 otherwise
E[x] =
Z �
↵
x
� � ↵dx =1
2(↵+ �)
V [x] =
Z �
↵[x� 1
2(↵+ �)]2
1
� � ↵dx =1
12(� � ↵)2
The expectaBon and the variance are
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
ExponenBal DistribuBon
12
• ExponenBal distribuBon The exponenBal p.d.f. for the conBnuous variable is defined by
f(x, ⇠) =1
⇠
e
�x/⇠ (0 x < 1)
The expectaBon and the variance are
E[x] =1
⇠
Z 1
0xe
�x/⇠dx = ⇠
V [x] =1
⇠
Z 1
0(x� ⇠)2e�x/⇠dx = ⇠2
ξ=1ξ=2ξ=5
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
ExponenBal DistribuBon
13
• ExponenBal distribuBon : the source code
ξ=1ξ=2ξ=5
//// Drawing exponential functions//// E. Won ([email protected])
Double_t f1(Double_t *x, Double_t *xi) { return TMath::Exp(-1.0*x[0]/xi[0])/xi[0]; }
void exp(){ gROOT->SetStyle("Plain"); gROOT->ForceStyle(); TF1 *fun1 = new TF1("fun1",f1,0.0,5.0,1); TF1 *fun2 = new TF1("fun2",f1,0.0,5.0,1); TF1 *fun3 = new TF1("fun3",f1,0.0,5.0,1); fun1->SetParameter(0,1.0); fun1->Draw(); fun2->SetLineColor(kBlue); fun2->SetParameter(0,2.0); fun2->Draw("LSAME"); fun3->SetLineColor(kRed); fun3->SetParameter(0,5.0); fun3->Draw("LSAME");}
ξ=1ξ=2ξ=5
mailto:[email protected]
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
Gaussian DistribuBon
14
• Gaussian distribuBon The gaussian p.d.f. for the conBnuous variable is defined by
f(x;µ,�
2) =
1p2⇡�
2exp
⇣� (x� µ)
2
2�
2
⌘
E[x] = µ
V [x] = �2
The expectaBon and the variance are
μ=0,σ=2μ=4,σ=3μ=0,σ=6Can you prove them?
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
N-‐dim. Gaussian DistribuBon
15
• Generalized N-‐dimensional gaussian distribuBon The N-‐dim. gaussian p.d.f. for the conBnuous variables x is defined by
f(x;µ, V ) =1
(2⇡)N/2|V |1/2exp
h� 1
2
(x� µ)TV �1(x� µ)i
where x and μ are column vectors containing x1,...,xn and μ1,...,μn, xT and μT are the corresponding row vectors, and |V| is the determinant of a symmetric NxN matrix V.
The expectaBon and the (co)variance are
E[xi] = µi, V [xi] = Vii, cov[xi, xj ] = Vij
The two dimensional example becomesf(x1, x2;µ1, µ2,�1,�2, ⇢) =
1
2⇡�1�2
p1� ⇢2
⇥ exp(
� 12(1� ⇢2)
h⇣x1 � µ1
�1
⌘2+
⇣x2 � µ2
�2
⌘2� 2⇢
⇣x1 � µ1
�1
⌘⇣x2 � µ2
�2
⌘i)
where is the correlaBon coefficient ⇢ = cov[x1, x2]/(�1�2)
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
Chi-‐square DistribuBon
16
• The χ2(chi-‐square) distribuBon The χ2(chi-‐square) distribuBon of the conBnuous variable z is defined by
f(z;n) =1
2n/2�(n/2)zn/2�1e�z/2, n = 1, 2, ... (0 z < 1)
where the parameter n is called the number of degrees of freedom and the gamma funcBon is defined by
�(x) =
Z 1
0e
�tt
x�1dt
The expectaBon and the variance are found to be
E[z] =
Z 1
0z
1
2n/2�(n/2)zn/2�1e�z/2 dz = n,
V [z] =
Z 1
0(z � n)2 1
2n/2�(n/2)zn/2�1e�z/2 dz = 2n
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
Chi-‐square DistribuBon
17
//// E. Won ([email protected])//// gammln from Numerical Recipes
float gammln(float xx){ double x,y,tmp,ser; static double cof[6]={76.18009172947146,-86.50532032941677, 24.01409824083091,-1.231739572450155, 0.1208650973866179e-2,-0.5395239384953e-5}; int j;
y=x=xx; tmp=x+5.5; tmp -= (x+0.5)*log(tmp); ser=1.000000000190015; for (j=0;jSetStyle("Plain"); gROOT->ForceStyle(); TH2F *h2 = new TH2F("h2","",2,0.0,20.0,2,0.0,0.5); h2->Draw(); TF1 *fun1 = new TF1("fun1",f1,0.0,20.0,1); TF1 *fun2 = new TF1("fun2",f1,0.0,20.0,1); TF1 *fun3 = new TF1("fun3",f1,0.0,20.0,1); TF1 *fun4 = new TF1("fun4",f1,0.0,20.0,1); fun1->SetParameter(0, 1); fun1->Draw("LSAME"); // rest of lines skipped ...
n=1n=2n=5n=10
Can you understand how it is done? (I took the logarithm first!)
mailto:[email protected]
-
Korea U/Dept. Physics, Prof. Eunil Won (All rights are reserved)
Binomial, Poisson, and Gaussian PDF
18
Binomial Poisson
Gaussian
N ! 1, Np = µ
N ! 1 µ ! 1