将这段代码转换为伪代码:算法函数3-2:LM 1: def levenberg_marquardt(fun, grad, jacobian, x0, iterations, tol): 2: while (gnorm > tol) and (k < iterations): 3: if updateJ == 1: 4: x_log = np.append(x_log, xk.T) 5: yk = fun(xk) 6: y_log = np.append(y_log, yk) 7: H_lm = H + (lamda * np.eye(9)) 8: gfk = grad(xk) 9: pk = - np.linalg.inv(H_lm).dot(gfk) 10: pk = pk.A.reshape(1, -1)[0] 11: xk = xk + pk 12: fval = fun(xk) 13: if fval < old_fval: 14: lamda = lamda / 10 15: old_fval = fval
时间: 2024-01-20 11:03:31 浏览: 76
基于改进Levenberg-Marquardt算法的燃气轮机特性拟合优化 (2012年)
算法函数3-2:LM
输入:目标函数 fun,目标函数的梯度 grad,雅可比矩阵 jacobian,起始点 x0,最大迭代次数 iterations,收敛精度 tol
输出:最优解 xk
1. k = 0, lamda = 0.01, H = jacobian(x0),old_fval = fun(x0)
2. while (gnorm > tol) and (k < iterations) do
3. if updateJ == 1 then
4. x_log = append(x_log, xk.T)
5. yk = fun(xk)
6. y_log = append(y_log, yk)
7. end if
8. H_lm = H + (lamda * eye(9))
9. gfk = grad(xk)
10. pk = - inv(H_lm) · gfk
11. pk = pk.A.reshape(1, -1)[0]
12. xk = xk + pk
13. fval = fun(xk)
14. if fval < old_fval then
15. lamda = lamda / 10
16. old_fval = fval
17. else
18. lamda = lamda * 10
19. end if
20. H = jacobian(xk)
21. k = k + 1
22. end while
23. return xk
阅读全文