亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

編程作業: Regularization梯度值計算出錯

編程作業: Regularization梯度值計算出錯

無無法師 2017-09-13 21:02:02
#?GRADED?FUNCTION:?gradient_check def?gradient_check(x,?theta,?epsilon?=?1e-7): ????""" ????Implement?the?backward?propagation?presented?in?Figure?1. ???? ????Arguments: ????x?--?a?real-valued?input ????theta?--?our?parameter,?a?real?number?as?well ????epsilon?--?tiny?shift?to?the?input?to?compute?approximated?gradient?with?formula(1) ???? ????Returns: ????difference?--?difference?(2)?between?the?approximated?gradient?and?the?backward?propagation?gradient ????""" ???? ????#?Compute?gradapprox?using?left?side?of?formula?(1).?epsilon?is?small?enough,?you?don't?need?to?worry?about?the?limit. ????###?START?CODE?HERE?###?(approx.?5?lines) ????thetaplus?=?theta+0.01???????????????????????????????#?Step?1 ????thetaminus?=?theta-0.01??????????????????????????????#?Step?2 ????J_plus?=?forward_propagation(x,thetaplus)??????????????????????????????????#?Step?3 ????J_minus?=?forward_propagation(x,thetaminus)?????????????????????????????????#?Step?4 ????gradapprox?=?(J_plus-J_minus)/(2*0.01)??????????????????????????????#?Step?5 ????###?END?CODE?HERE?### ???? ????#?Check?if?gradapprox?is?close?enough?to?the?output?of?backward_propagation() ????###?START?CODE?HERE?###?(approx.?1?line) ????grad?=?backward_propagation(x,theta) ????###?END?CODE?HERE?### ???? ????###?START?CODE?HERE?###?(approx.?1?line) ????numerator?=?np.linalg.norm(gradapprox-grad)???????????????????????????????#?Step?1' ????denominator?=?np.linalg.norm(grad)+np.linalg.norm(gradapprox)?????????????????????????????#?Step?2' ????difference?=?numerator/denominator??????????????????????????????#?Step?3' ????###?END?CODE?HERE?### ???? ????if?difference?<?1e-7: ????????print?("The?gradient?is?correct!") ????else: ????????print?("The?gradient?is?wrong!") ???? ????return?difference我懷疑是下面圖的地方出錯了,但不知道怎么修改呀?解決:epsilon?=?1e-7應該被使用,而不是0.01
查看完整描述

目前暫無任何回答

  • 0 回答
  • 0 關注
  • 2114 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號