sigmoidGradient.m 751 B

12345678910111213141516171819202122232425262728293031323334
  1. function g = sigmoidGradient(z)
  2. %SIGMOIDGRADIENT returns the gradient of the sigmoid function
  3. %evaluated at z
  4. % g = SIGMOIDGRADIENT(z) computes the gradient of the sigmoid function
  5. % evaluated at z. This should work regardless if z is a matrix or a
  6. % vector. In particular, if z is a vector or matrix, you should return
  7. % the gradient for each element.
  8. g = zeros(size(z));
  9. % ====================== YOUR CODE HERE ======================
  10. % Instructions: Compute the gradient of the sigmoid function evaluated at
  11. % each value of z (z can be a matrix, vector or scalar).
  12. sz = sigmoid(z);
  13. g = sz .* ( 1 .- sz);
  14. % =============================================================
  15. end