开发者

Run a function in between each iteration of fsolve in MATLAB

I am using fsolve to minimise an energy function in MATLAB. The algorithm I am using fits a grid to noisy lattice data, with costs for the distances of the grid from each data point.

The objective function is formulated with squared error terms, to allow for the Gauss–Newton algorithm to be used. However, the program reverts to Levenberg-Marquardt:

Warning: Trust-region-dogleg algorithm of FSOLVE cannot handle non-square systems;
using Levenberg-Marquardt algorithm instead. 

I realised this is probably due to the fact that while the costs have squared errors, there is a stage in the objective (cost) function that chooses the nearest grid centre to each data point, thus making the algorithm non-square.

What I would like to do is to perform this assignment update of nearest grid centres separately to the evaluation of the Jacobian of the cost function. I believe this would then allow Gauss-Newton to be used, and significantly improve the speed of the algorithm.

Currently, I believe there开发者_开发技巧 is something like this going on:

while i < options.MaxIter && threshold has not been met
    Compute Jacobian of cost function (which includes assignment routine)
    Move down the slope in the direction of highest gradient
end

What i would like to happen instead:

while i < options.MaxIter && threshold has not been met
    Perform assignment routine
    Compute Jacobian of cost function (which is now square, as no assignment occurs)
    Move down the slope
end

Is there a way to insert a function like this into the iterations without picking apart the whole of the fsolve algorithm? Even if I manually edited fsolve, would the nature of the Gauss-Newton algorithm allow me to add in this extra step?

Thanks


Since you're working with squared errors, anyway, you could use LSQNONLIN instead of fsovle. This allows you to compute the Jacobian (as well as all necessary preparations) in your objective function. The Jacobian is then returned as second output argument.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜