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