User Tools

Site Tools


cs401r_w2016:lab13

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

cs401r_w2016:lab13 [2016/01/13 17:26]
admin
cs401r_w2016:lab13 [2021/06/30 23:42]
Line 1: Line 1:
-====Objective:​==== 
  
-To understand expectation maximization,​ and to explore how to learn the parameters of a Gaussian mixture model. 
- 
----- 
-====Deliverable:​==== 
- 
-For this lab, you will implement the Expectation Maximization algorithm on the Old Faithful dataset. ​ This involves learning the parameters of a Gaussian mixture model. ​ Your notebook should produce a visualization of the progress of the algorithm. ​ The final figure should look something like this: 
- 
-{{:​cs401r_w2016:​lab5_em.png?​direct&​600|}} 
- 
----- 
-====Grading:​==== 
-Your notebook will be graded on the following elements: 
- 
-  * 10% Data is correctly mean-centered 
-  * 20% Correctly updates responsibilities 
-  * 20% Correctly updates means 
-  * 20% Correctly updates covariances 
-  * 20% Correctly updates mixing weights 
-  * 10% Final plot is tidy and legible 
- 
----- 
-====Description:​==== 
- 
-To help our TA better grade your notebook, you should use the following initial parameters: 
- 
-<code python> 
- 
-# the Gaussian means (as column vectors -- ie, the mean for Gaussian 0 is mus[:,0] 
-mus = np.asarray( [[-1.17288986,​ -0.11642103],​ 
-                   ​[-0.16526981, ​ 0.70142713]]) 
- 
-# the Gaussian covariance matrices 
-covs = list() 
-covs.append( ​ 
-    np.asarray([[ 0.74072815, ​ 0.09252716],​ 
-                [ 0.09252716, ​ 0.5966275 ]]) ) 
-covs.append( ​ 
-    np.asarray([[ 0.39312776, -0.46488887],​ 
-                [-0.46488887, ​ 1.64990767]]) ) 
- 
-# The Gaussian mixing weights 
-mws = [ 0.68618439, 0.31381561 ] 
- 
-</​code>​ 
- 
----- 
-====Hints:​==== 
- 
-In order to visualize a covariance matrix, you should plot an ellipse representing the 95% confidence bounds of the corresponding Gaussian. ​ Here is some code that accepts as input a covariance matrix, and returns a set of points that define the correct ellipse; these points can be passed directly to the ''​plt.plot()''​ command as the ''​x''​ and ''​y''​ parameters. 
- 
-<code python> 
-import numpy as np 
- 
-def cov_to_pts( cov ): 
-    circ = np.linspace( 0, 2*np.pi, 100 ) 
-    sf = np.asarray( [ np.cos( circ ), np.sin( circ ) ] ) 
-    [u,s,v] = np.linalg.svd( cov ) 
-    pmat = u*2.447*np.sqrt(s) # 95% confidence 
-    return np.dot( ​ pmat, sf ) 
- 
-</​code>​ 
- 
-Here are some additional python functions that may be helpful to you: 
- 
-<code python> 
- 
-# compute the likelihood of a multivariate Gaussian 
-scipy.stats.multivariate_normal.pdf 
- 
-# to transpose a vector, you can use the .T operator 
-foo = np.atleast_2d( [42, 43] ) # this is a row vector 
-foo.T # this is a column vector 
- 
-import numpy as np 
-np.atleast_2d 
-np.sum 
- 
-</​code>​ 
cs401r_w2016/lab13.txt ยท Last modified: 2021/06/30 23:42 (external edit)