def gradient_descent(W, eta=0.001, tolerance=0.000001): # Variable to store the W value before update. # This will help to check for convergence. W_prev = 0 # t is an iteration counter to compute the number of steps t = 0 # Save the current weights to a new list and # append the updated weights in each iteration to the same Ws = [W] # Perform the update until convergence # Convergence is said to have taken place if # the absolute difference between the previous and # updated weight is less than the tolerance while ():空格里面应该填啥
时间: 2024-02-14 07:33:15 浏览: 158
C1_W1_Lab05_Gradient_Descent_Soln.ipynb
在这个代码段中,`while`循环的条件没有给出。根据注释,循环应该继续进行直到达到收敛状态。因此,循环的条件应该是:
```python
while (np.abs(Ws[-1] - W_prev) > tolerance):
```
这个条件检查前一次更新的权重与当前更新的权重之间的绝对差是否大于给定的容差。如果是,则继续进行更新;如果不是,则认为已经达到了收敛状态,循环结束。
阅读全文