So, I am using a linearized version of a non-linear cost. I run the optimization until the difference between two consecutive cvx_optval reduces below a threshold. For every new optimization, the solution of previous optimization is used as the linearization points. However, the difference never reaches below the threshold (and threshold is not too high or too low). On debugging I observed that the cvx_optval follows a pattern in my program ie cvx_optval over 10 runs is
1.0e+03 *
Columns 1 through 10
You need to provide more information for anyone to help you beyond the general statement below… Preferably a reproducible problem
Anyhow, your iterative algorithm may not necessarily converge at all, let alone to a local optimum of your original nonlinear problem. In your case, it appears that the algorithm may never converge.In general, some type of control on step size, such as line search or trust region, might be necessary to guarantee convergence to a stationary point. Your algorithm evidently omits such control, hence may not converge to anything. It is easy to be seduced when you see only examples where a heuristic algorithm converges to a correct answer, and don’t see examples where it doesn’t.
Okay, so here is the linearized cost function
cost = (xl(n) - robo_px(n))^2 + (yl(n) - robo_py(n))^2 + 2*(xl(n) - robo_px(n))(Px(n) - xl(n)) + 2(yl(n) - robo_py(n))*(Py(n) - yl(n));
where xl,yl are the linearization points, Px,Py are the optimization variable and robo_px, robo_py are the initial parameters provided as input to the optimization algo.
I minimize the cost given constraints on the optimization variables. Before iterating over the optimization routine the linearization points are updates as
xl = Px;
yl = Py;
Also if the difference between consecutive cvx_optval is not below a threshold the optimization over same horizon set is repeated but with updated linearization points.
if (optvalt(i) - optval(i-1) > 0.1) || (optval(i) - optval(i-1) < -0.1)
accept the solution
else
repeat
end
As a matter of safety and protocol, everything, including inputs, needs to be provided on this forum, not on google drive. Anyhow, I suggest you do some reading along the lines I suggested.
helping you debug or analyze a heuristic algorithm built on top of CVX is really outside the scope of this forum though. I.e., if your heuristic algorithm doesn’t converge, that’s your problem to deal with, and it is a “bonus” if any readers choose to provide such help.
I suggest that given your immaturity in the filed, you may be better off using an off-the-shelf nonlinear optimization code to solve your problem, rather than trying to write your own algorithm. I’m not clear on what specific problem type your problem is, so can not recommend any particular code.