不动点迭代优化问题求助:收敛结果受初始值影响+Casadi实现可行性咨询
不动点迭代优化问题求助:收敛结果受初始值影响+Casadi实现可行性咨询
大家好,我现在在做一个结合不动点迭代(FPI)和数值优化的问题,遇到了两个棘手的卡点,想请教下社区的大佬们:
不动点迭代结果依赖初始值的问题
我用不动点迭代求解y12和y21,但发现收敛结果会随着y12的初始猜测值变化——不同初始值会得到不同的收敛解,这让我没法确定哪个是符合问题要求的解,也直接影响了后续的优化效果。Casadi结合不动点迭代的可行性
最开始我想使用Casadi来实现这个"不动点迭代+优化"的流程,但翻了官方文档也没找到清晰的实现路径,现在改用Scipy的minimize来做,但还是不太顺利,想知道有没有办法用Casadi来完成这个组合任务?
下面是我目前的Scipy代码,麻烦大家帮忙看看哪里出了问题,或者有没有优化方向:
import numpy as np from scipy.optimize import minimize # Constants b = 3 d = 3.5 tolerance = 1e-6 max_iterations = 10000 # Define the nonlinear functions a(x1) and c(x2) def a_func(x1): return 0.25/(1 + np.exp(x1)) + 0.5 def c_func(x2): return -(1/(1 + np.exp(x2)) + 0.5) # Fixed-point iteration to solve for y12 and y21 given x def fixed_point_iteration(x): x1, x2 = x a = a_func(x1) c = c_func(x2) y12_old = -1.44 # 这里的初始值修改后,收敛结果会变化 for _ in range(max_iterations): y21_new = a*(y12_old - b)**2 y12_new = c*y21_new + d if abs(y12_new - y12_old) < tolerance: return y12_new, y21_new y12_old = y12_new raise RuntimeError("Fixed-point iteration did not converge") # Objective function to minimize def objective(x): try: y12, y21 = fixed_point_iteration(x) print(y12, y21) return y12**2 - 100*y21 + 0.1*(x[0]**2 + x[1]**2) except RuntimeError: return np.inf # Penalize non-converging points # Initial guess for x x0 = np.array([5.82409222, 7.73955672]) y12, y21 = fixed_point_iteration(x0) print(y12, y21) # 原代码这里的x未定义,已修正为x0 print(y21-(0.25/(1+np.exp(x0[0]))+0.5)*(y12-b)**2) print(y12-(-(1/(1+np.exp(x0[1]))+0.5)*y21 + d)) # Perform optimization(目前注释是因为迭代收敛不稳定) # result = minimize(objective, x0, method="BFGS", tol = 1e-8) # Extract optimal values # x_opt = result.x # y12_opt, y21_opt = fixed_point_iteration(x_opt) # f_opt = objective(x_opt) # Print results # print(f"Optimal x: {x_opt}") # print(f"Optimal y12: {y12_opt}") # print(f"Optimal y21: {y21_opt}") # print(f"Optimal objective value: {f_opt}")
另外我还发现,运行优化的时候,部分x的取值会导致不动点迭代直接不收敛,只能返回inf,这也让优化过程很难推进。麻烦大家帮忙分析下问题所在,谢谢啦!
内容来源于stack exchange
相关产品推荐
相关产品推荐

