Channge the stop criterion:

20 views
Skip to first unread message

LY

unread,
Jul 2, 2025, 5:01:44 AMJul 2
to Manopt
Dear Prof.:

I want to change the stop function of my problem. For example, I hope the optimization can be stopped when |f_{k+1} -f_{k}|<1%|f_{k}|, where f_{k} is the cost function at step k. How could I do this thing in Manopt? Thanks for you help!

Best,

Nicolas Boumal

unread,
Jul 2, 2025, 5:25:02 AMJul 2
to Manopt
This is explained in the documentation here:

There is a general example code, and a specific one which is close to what you want.

ChatGPT can help with the necessary adjustments I believe. Here is what it proposes when I ask it to read the docs and then feed it your question (I didn't run this, but looks good to me):

options.stopfun = @mystopfun;

[x, xcost, info, options] = mysolver(problem, [], options);

function [stopnow, reason] = mystopfun(problem, x, info, last)
    stopnow = false;
    reason = '';
    if numel(info) >= 2
        f_k   = info(last-1).cost;
        f_kp1 = info(last).cost;
        if abs(f_kp1 - f_k) < 0.01 * abs(f_k)
            stopnow = true;
            reason = sprintf('|f_{k+1}–f_k| < 1%% |f_k| ( %.3g )', abs(f_kp1 - f_k));
        end
    end
end

Reply all
Reply to author
Forward
0 new messages