Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. def update_theta(self, X, R):
  2. """Compute the update for the Bernoulli parameters in the M-step of the E-M algorithm.
  3. You should derive the optimal value of theta (the one which maximizes the expected log
  4. probability) by setting the partial derivatives to zero. You should implement this in
  5. terms of NumPy matrix and vector operations, rather than a for loop."""
  6.  
  7. ######################## Your code here #########################
  8. a = self.prior.a_pixels
  9. b = self.prior.b_pixels
  10. sumR = np.sum(R, axis=0) + (a-b) # sum over all examples (e.g. sum columns)
  11. RprimeX = np.dot(R.transpose(),X) + a - 1
  12. # in numpy, elements of column 0 are divided by the divisor's element 0.
  13. # we want each row to be divided by the same number
  14. # so we transpose so that rows become columns, do the division, then transpose back
  15. theta = np.true_divide(RprimeX.transpose(), sumR).transpose()
  16. return theta
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement