0% found this document useful (0 votes)
16 views58 pages

Lecture2 2015

Uploaded by

hu jack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views58 pages

Lecture2 2015

Uploaded by

hu jack
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

STA

 414/2104:    
Machine  Learning    

Russ  Salakhutdinov  
Department of Computer Science!
Department of Statistics!
rsalakhu@cs.toronto.edu!
h0p://www.cs.toronto.edu/~rsalakhu/  

Lecture 2  
Linear  Least  Squares  
From  last  class:  Minimize  the  sum  of  the  squares  of  the  errors  between  
the  predicAons                                      for  each  data  point  xn  and  the  corresponding  
real-­‐valued    targets  tn.      

Loss  funcAon:  sum-­‐of-­‐squared  error  


funcAon:  

Source:  Wikipedia  
Linear  Least  Squares  
If                            is  nonsingular,  then  the  unique  soluAon  is  given  by:  

opAmal   vector  of  


weights   target  values  

the  design  matrix  has  one  


input  vector  per  row  

Source:  Wikipedia  

•  At  an  arbitrary  input            ,  the  predicAon  is                                                                  


•  The  enAre  model  is  characterized  by  d+1  parameters  w*.  
Example:  Polynomial  Curve  FiQng  
Consider  observing  a  training  set  consisAng  of  N  1-­‐dimensional  observaAons:                              
                                                                                   together  with  corresponding  real-­‐valued  targets:  

Goal:  Fit  the  data  using  a  polynomial  funcAon  of  the  form:  

Note:  the  polynomial  funcAon  is  a  nonlinear  funcAon  of  x,  but  it  is  a  linear  
funcAon  of  the  coefficients  w  !  Linear  Models.    
Example:  Polynomial  Curve  FiQng  
•  As  for  the  least  squares  example:    we  can  minimize  the  sum  of  the  
squares  of  the  errors  between  the  predicAons                                    for  each  data  
point  xn  and  the  corresponding  target  values  tn.      

Loss  funcAon:  sum-­‐of-­‐squared  


error  funcAon:  

•  Similar  to  the  linear  least  squares:  Minimizing  sum-­‐of-­‐squared  error  


funcAon  has  a  unique  soluAon  w*.    
ProbabilisAc  PerspecAve  
•  So  far  we  saw  that  polynomial  curve  fiQng  can  be  expressed  in  terms  
of  error  minimizaAon.  We  now  view  it  from  probabilisAc  perspecAve.    
•  Suppose  that  our  model  arose  from  a  staAsAcal  model:  

where  ²  is  a  random  error  having  Gaussian  distribuAon  with  zero  


mean,  and  is  independent  of  x.    
Thus  we  have:  

where  ¯  is  a  precision  parameter,  


corresponding  to  the  inverse  variance.      

I will use probability distribution and


probability density interchangeably. It
should be obvious from the context.!
Maximum  Likelihood  
If  the  data  are  assumed  to  be  independently  and  idenAcally  
distributed  (i.i.d  assump*on),  the  likelihood  funcAon  takes  form:      

It  is  oXen  convenient  to  maximize  the  log  of  the  likelihood  funcAon:  

•  Maximizing  log-­‐likelihood  with  respect  to  w  (under  the  assumpAon  of  a  


Gaussian  noise)  is  equivalent  to  minimizing  the  sum-­‐of-­‐squared  error  
funcAon.    
•  Determine                        by  maximizing  log-­‐likelihood.  Then  maximizing  
w.r.t.  ¯:    
PredicAve  DistribuAon  
Once  we  determined  the  parameters  w  and  ¯,  we  can  make  predicAon  
for  new  values  of  x:      

Later  we  will  consider  Bayesian  linear  regression.    


Bernoulli  DistribuAon  
•  Consider  a  single  binary  random  variable                                                    For  example,  x  
can  describe  the  outcome  of  flipping  a  coin:                                                  
Coin  flipping:  heads  =  1,  tails  =  0.                                                    

•  The  probability  of  x=1  will  be  denoted  by  the  parameter  µ,  so  that:  

•  The  probability  distribuAon,  known  as  Bernoulli  distribuAon,    can  be  


wri0en  as:  
Parameter  EsAmaAon    
•  Suppose  we  observed  a  dataset    
•  We  can  construct  the  likelihood  funcAon,  which  is  a  funcAon  of  µ.    

•  Equivalently,  we  can  maximize  the  log  of  the  likelihood  funcAon:    

•  Note  that  the  likelihood  funcAon  depends  on  the  N  observaAons  xn  only  
through  the  sum        
Sufficient  
StaAsAc  
Parameter  EsAmaAon    
•  Suppose  we  observed  a  dataset    

•  SeQng  the  derivaAve  of  the  log-­‐likelihood  funcAon  w.r.t  µ  to  zero,  we  
obtain:  

where  m  is  the  number  of  heads.    


Binomial  DistribuAon    
•  We  can  also  work  out  the  distribuAon  of  the  number  m  of  observaAons  
of  x=1  (e.g.  the  number  of  heads).    

•  The  probability  of  observing  m  heads  given  N  coin  flips  and  a  


parameter  µ  is  given  by:      

•  The  mean  and  variance  can  be  easily  derived  as:    


Example  
•  Histogram  plot  of  the  Binomial  distribuAon  as  a  funcAon  of  m  for  N=10  
and  µ  =  0.25.    
Beta  DistribuAon    
•  We  can  define  a  distribuAon  over                                            (e.g.  it  can  be  used  a  prior  
over  the  parameter  µ  of  the  Bernoulli  distribuAon).    

where  the  gamma  funcAon  is  defined  as:    

and  ensures  that  the  Beta  distribuAon  is  normalized.      


Beta  DistribuAon    
MulAnomial  Variables  
•  Consider  a  random  variable  that  can  take  on  one  of  K  possible  mutually  
exclusive  states  (e.g.  roll  of  a  dice).    
•  We  will  use  so-­‐called  1-­‐of-­‐K  encoding  scheme.    

•    If  a  random  variable  can  take  on  K=6  states,  and  a  parAcular  
observaAon  of  the  variable  corresponds  to  the  state  x3=1,  then  x  will  be  
resented  as:      

1-­‐of-­‐K  coding  scheme:  

•  If  we  denote  the  probability  of  xk=1    by  the  parameter  µk,  then  the  
distribuAon  over  x  is  defined  as:  
MulAnomial  Variables  
•  MulAnomial  distribuAon  can  be  viewed  as  a  generalizaAon  of  Bernoulli  
distribuAon  to  more  than  two  outcomes.  

•  It  is  easy  to  see  that  the  distribuAon  is  normalized:    

and  
Maximum  Likelihood  EsAmaAon    
•  Suppose  we  observed  a  dataset    
•  We  can  construct  the  likelihood  funcAon,  which  is  a  funcAon  of  µ.    

•  Note  that  the  likelihood  funcAon  depends  on  the  N  data  points  only  
though  the  following  K  quanAAes:    

which  represents  the  number  of  observaAons  of  xk=1.        

•  These  are  called  the  sufficient  staAsAcs  for  this  distribuAon.    


Maximum  Likelihood  EsAmaAon    

•  To  find  a  maximum  likelihood  soluAon  for  µ,  we  need  to  maximize  the  
log-­‐likelihood  taking  into  account  the  constraint  that      

•  Forming  the  Lagrangian:      

which  is  the  fracAon  of  observaAons  for  which  xk=1.  


MulAnomial  DistribuAon    
•  We  can  construct  the  joint  distribuAon  of  the  quanAAes  {m1,m2,…,mk}  
given  the  parameters  µ  and  the  total  number  N  of  observaAons:  

•  The  normalizaAon  coefficient  is  the  number  of  ways  of  parAAoning  N  
objects  into  K  groups    of  size  m1,m2,…,mK.    

•  Note  that    
Dirichlet  DistribuAon    
•  Consider  a  distribuAon  over  µk,  subject  to  constraints:    

•  The  Dirichlet  distribuAon  is  defined  as:  

where  ®1,…,®k  are  the  parameters  of  the  


distribuAon,  and  ¡(x)  is  the  gamma  funcAon.      

•  The  Dirichlet  distribuAon  is  confined  to  a  simplex  as  a  consequence  of  
the  constraints.    
Dirichlet  DistribuAon    
•  Plots  of  the  Dirichlet  distribuAon  over  three  variables.    
Gaussian  Univariate  DistribuAon    
•  In  the  case  of  a  single  variable  x,  the  Gaussian  distribuAon  takes  form:  

which  is  governed  by  two  parameters:  


-  µ  (mean)  
-  ¾2  (variance)  

• The  Gaussian  distribuAon  saAsfies:  


MulAvariate  Gaussian  DistribuAon    
•  For  a  D-­‐dimensional  vector  x,  the  Gaussian  distribuAon  takes  form:  

which  is  governed  by  two  parameters:  

-  µ  is  a  D-­‐dimensional  mean  vector.    


-  §  is  a  D  by  D  covariance  matrix.      

and  |§|  denotes  the  determinant  of  §.    

• Note  that  the  covariance  matrix  is  a  symmetric  posiAve  definite  


matrix.        
Central  Limit  Theorem    
•  The  distribuAon  of  the  sum  of  N  i.i.d.  random  variables  becomes  
increasingly  Gaussian  as  N  grows.    
•  Consider  N  variables,  each  of  which  has  a  uniform  distribuAon  over  the  
interval  [0,1].    
•  Let  us  look  at  the  distribuAon  over  the  mean:    

•  As  N  increases,  the  distribuAon  tends  towards  a  Gaussian  distribuAon.      


Geometry  of  the  Gaussian  DistribuAon  
•  For  a  D-­‐dimensional  vector  x,  the  Gaussian  distribuAon  takes  form:  

•  Let  us  analyze  the  funcAonal  dependence  of  the  Gaussian  on  x  through  
the  quadraAc  form:    

•  Here  ¢  is  known  as  Mahalanobis  distance.      

•  The  Gaussian  distribuAon  will  be  constant  on  


surfaces  in  x-­‐space  for  which  ¢  is  constant.    
Geometry  of  the  Gaussian  DistribuAon  
•  For  a  D-­‐dimensional  vector  x,  the  Gaussian  distribuAon  takes  form:  

•  Consider  the  eigenvalue  equaAon  for  the  covariance  matrix:  

•  The  covariance  can  be  expressed  in  terms  of  its  eigenvectors:  

•  The  inverse  of  the    covariance:  


Geometry  of  the  Gaussian  DistribuAon  
•  For  a  D-­‐dimensional  vector  x,  the  Gaussian  distribuAon  takes  form:  

•  Remember:  

•  Hence:  

•  We  can  interpret  {yi}  as  a  new  coordinate  system  defined  by  the  
orthonormal  vectors  ui  that  are  shiXed  and  rotated  .    
Geometry  of  the  Gaussian  DistribuAon  

•  Red  curve:  surface  of  


constant  probability  density    

•  The  axis  are  defined  by  the  


eigenvectors  ui  of  the  
covariance  matrix  with  
corresponding  eigenvalues.    
Moments  of  the  Gaussian  DistribuAon  
•  The  expectaAon  of  x  under  the  Gaussian  distribuAon:    

The  term  in  z  in  the  factor  (z+µ)  


will  vanish  by  symmetry.    
Moments  of  the  Gaussian  DistribuAon  
•  The  second  order  moments  of  the  Gaussian  distribuAon:    

•  The  covariance  is  given  by:  

•  Because  the  parameter  matrix  §  governs  the  covariance  of  x  under  the  
Gaussian  distribuAon,  it  is  called  the  covariance  matrix.    
Moments  of  the  Gaussian  DistribuAon  
•  Contours  of  constant  probability  density:    

Covariance   Diagonal,  axis-­‐ Spherical  


matrix  is  of   aligned  covariance   (proporAonal  to  
general  form.     matrix.   idenAty)  covariance  
matrix.    
ParAAoned  Gaussian  DistribuAon  
•  Consider  a  D-­‐dimensional  Gaussian  distribuAon:  
•  Let  us  parAAon  x  into  two  disjoint  subsets  xa  and  xb:  

•  In  many  situaAons,  it  will  be  more  convenient  to  work  with  the  
precision  matrix  (inverse  of  the  covariance  matrix):    

•  Note  that  ¤aa  is  not  given  by  the  inverse  of  §aa.  
CondiAonal  DistribuAon  
•  It  turns  out  that  the  condiAonal  distribuAon  is  also  a  Gaussian  
distribuAon:    

Covariance  does  not  


depend  on  xb.    

Linear  funcAon  
of  xb.  
Marginal  DistribuAon  
•  It  turns  out  that  the  marginal  distribuAon  is  also  a  Gaussian  distribuAon:    

•  For  a  marginal  distribuAon,  the  mean  and  covariance  are  most  simply  
expressed  in  terms  of  parAAoned  covariance  matrix.      
CondiAonal  and  Marginal  DistribuAons  
Maximum  Likelihood  EsAmaAon    
•  Suppose  we  observed  i.i.d  data  
•  We  can  construct  the  log-­‐likelihood  funcAon,  which  is  a  funcAon  of  
µ  and  §:  

•  Note  that  the  likelihood  funcAon  depends  on  the  N  data  points  only  
though  the  following  sums:    

Sufficient  StaBsBcs  
Maximum  Likelihood  EsAmaAon    
•  To  find  a  maximum  likelihood  esAmate  of  the  mean,  we  set  the  
derivaAve  of  the  log-­‐likelihood  funcAon  to  zero:    

and  solve  to  obtain:  

•  Similarly,  we  can  find  the  ML  esAmate  of  §:  


Maximum  Likelihood  EsAmaAon    
•  EvaluaAng  the  expectaAon  of  the  ML  esAmates  under  the  true  
distribuAon,  we  obtain:     Unbiased  esAmate  

Biased  esAmate  

•  Note  that  the  maximum  likelihood  esAmate  of  §  is  biased.    

•  We  can  correct  the  bias  by  defining  a  different  esAmator:    


SequenAal  EsAmaAon    
•  SequenAal  esAmaAon  allows  data  points  to  be  processed  one  at  a  Ame  
and  then  discarded.    Important  for  on-­‐line  applicaAons.      
•  Let  us  consider  the  contribuAon  of  the  Nth  data  point  xn:  

correcAon  given  xN    


correcAon  weight  
old  esAmate  
Student’s  t-­‐DistribuAon    
•  Consider  Student’s  t-­‐DistribuAon    

Infinite  mixture  
where   of  Gaussians    

SomeAmes  called   Degrees  of  freedom  


the  precision  
parameter.    
Student’s  t-­‐DistribuAon    
•  SeQng  º  =  1  recovers  Cauchy  distribuAon      
•  The  limit  º  !  1    corresponds  to  a  Gaussian  distribuAon.      
Student’s  t-­‐DistribuAon    
•  Robustness  to  outliners:  Gaussian  vs.  t-­‐DistribuAon.    
Student’s  t-­‐DistribuAon    
•  The  mulAvariate  extension  of  the  t-­‐DistribuAon:    

where  

•  ProperAes:    
Mixture  of  Gaussians  
•    When  modeling  real-­‐world  data,  Gaussian  assumpAon  may  not  be  
appropriate.    
•  Consider  the  following  example:  Old  Faithful  Dataset  

Single  Gaussian   Mixture  of  two  


Gaussians  
Mixture  of  Gaussians  
•  We  can  combine  simple  models  into  a  complex  model  by  defining  a  
superposiAon  of  K  Gaussian  densiAes  of  the  form:      

Component  
Mixing  coefficient  

K=3

•  Note  that  each  Gaussian  component  has  its  own  mean  µk  and  
covariance  §k.  The  parameters  ¼k  are  called  mixing  coefficients.    
•  Mote  generally,  mixture  models  can  comprise  linear  combinaAons  of  
other  distribuAons.    
Mixture  of  Gaussians  
•  IllustraAon  of  a  mixture  of  3  Gaussians  in  a  2-­‐dimensional  space:    

(a)  Contours  of  constant  density  of  each  of  the  mixture  components,  
along  with  the  mixing  coefficients  
(b)  Contours  of  marginal  probability  density      

(c)  A  surface  plot  of  the  distribuAon  p(x).    


Maximum  Likelihood  EsAmaAon  
•  Given  a  dataset  D,  we  can  determine  model  parameters  µk.  §k,  ¼k  by  
maximizing  the  log-­‐likelihood  funcAon:    

Log  of  a  sum:  no  closed  form  soluAon  

•  SoluBon:  use  standard,  iteraAve,  numeric  opAmizaAon  methods  or  the  


ExpectaAon  MaximizaAon  algorithm.    
The  ExponenAal  Family    
•  The  exponenAal  family  of  distribuAons  over  x  is  defined  to  be  a  set  of  
destrucAons  for  the  form:      

where    
-  ´  is  the  vector  of  natural  parameters    
-  u(x)  is  the  vector  of  sufficient  staAsAcs  

•  The  funcAon  g(´)  can  be  interpreted  the  coefficient  that  ensures  
that  the  distribuAon  p(x|´)  is  normalized:    
Bernoulli  DistribuAon    
•  The  Bernoulli  distribuAon  is  a  member  of  the  exponenAal  family:    

•  Comparing  with  the  general  form  of  the  exponenAal  family:  

we  see  that    

and  so    

LogisAc  sigmoid  
Bernoulli  DistribuAon    
•  The  Bernoulli  distribuAon  is  a  member  of  the  exponenAal  family:    

•  The  Bernoulli  distribuAon  can  therefore  be  wri0en  as:  

where  
MulAnomial  DistribuAon    
•  The  MulAnomial  distribuAon  is  a  member  of  the  exponenAal  family:    

where  

and  
NOTE:  The  parameters  ´k  
are  not  independent  since  
the  corresponding  µk  must  
saAsfy  

•  In  some  cases  it  will  be  convenient  to  remove  the  constraint  by  
expressing  the  distribuAon  over  the  M-­‐1  parameters.    
MulAnomial  DistribuAon    
•  The  MulAnomial  distribuAon  is  a  member  of  the  exponenAal  family:    

•  Let    

•  This  leads  to:  

and  

•  Here  the  parameters  ´k  are  independent.       SoXmax  funcAon    


•  Note  that:    
and  
MulAnomial  DistribuAon    
•  The  MulAnomial  distribuAon  is  a  member  of  the  exponenAal  family:    

•  The  MulAnomial  distribuAon  can  therefore  be  wri0en  as:    

where  
Gaussian  DistribuAon    
•  The  Gaussian  distribuAon  can  be  wri0en  as:    

where  
ML  for  the  ExponenAal  Family    
•  Remember  the  ExponenAal  Family:    

•  From  the  definiAon  of  the  normalizer  g(´):    

•  We  can  take  a  derivaAve  w.r.t  ´:    

•  Thus    
ML  for  the  ExponenAal  Family    
•  Remember  the  ExponenAal  Family:    

•  We  can  take  a  derivaAve  w.r.t  ´:    

•  Thus    

•    Note  that  the  covariance  of  u(x)  can  be  expressed  in  terms  of  the  
second  derivaAve  of  g(´),  and  similarly  for  the  higher  moments.    
ML  for  the  ExponenAal  Family    
•  Suppose  we  observed  i.i.d  data  
•  We  can  construct  the  log-­‐likelihood  funcAon,  which  is  a  funcAon  of  
the  natural  parameter  ´.    

•  Therefore  we  have    

Sufficient  StaAsAc    

You might also like