最適化計算における反復表記のフォーマットについて

以下のオプションを設定し、最適化計算の収束履歴を出力したいのですが、
表示されるf(x)の値が「1.234e8」というような指数表記となり、全体の数値を確認できません。
options = optimoptions('particleswarm','Display','iter');
数値の詳細まで見るために表示フォーマットを変更する方法はないでしょうか。

 Risposta accettata

michio
michio il 7 Lug 2020

0 voti

コマンドウィンドウに表示される数値のフォーマットを変えるといかがでしょう。
例えば
format long
と実行した後、最適化を試してみて頂けますでしょか?

4 Commenti

YT
YT il 7 Lug 2020
回答ありがとうございます。
最適化を実行する際、
options = optimoptions('particleswarm','Display','iter');
format long
[X,fval,exitFlag,Output] = particleswarm(fun,NoV,lb,ub,options);
と実行しましたが、以下のような結果となります。
値が小数点以下第3位までしか表示されません。
Best Mean Stall
Iteration f-count f(x) f(x) Iterations
0 50 1.54e+04 2.787e+08 0
1 100 1.54e+04 2.687e+08 0
2 150 1.54e+04 2.297e+08 0
3 200 1.539e+04 1.991e+08 0
4 250 1.539e+04 1.692e+08 0
5 300 1.539e+04 1.692e+08 1
また、コマンドウインドウの設定画面から数値形式を変更してみても、
同様の結果でした。
ちなみに計算終了後に、改めて変数を表示させた場合は、
以下のようにきちんとlong型になりました。
fval =
1.538501415081424e+04
この表示設定を収束履歴に反映させることはできれば良いのですが…。
michio
michio il 7 Lug 2020
補足頂きありがとうございます。勘違いしておりました。
その表示桁数を操作するオプションは無いようです。開発チームにフィードバックいたします。
fmincon のオプションで OutputFcn という項目がありますので、ここで表示させるようコードを組むことで桁数を増やして表示させることはできるかと考えています。
例えば、iter と f(x) だけ表示させる簡易的なものでございますが・・
fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
x0 = [-1,2];
A = [1,2];
b = 1;
options = optimoptions('fmincon','Display','none','OutputFcn', @outfun);
x = fmincon(fun,x0,A,b,[],[],[],[],[],options)
ここで outfun.m として以下の関数を別途定義ください。
function stop = outfun(x,optimValues,state)
stop = false;
switch state
case 'iter'
% Make updates to plot or guis as needed
disp([sprintf('%d',optimValues.iteration),' ', ...
sprintf('%0.15e',optimValues.fval)])
case 'interrupt'
% Probably no action here. Check conditions to see
% whether optimization should quit.
case 'init'
% Setup for plots or guis
disp('Iter f(x)');
case 'done'
% Cleanup of plots, guis, or final plot
stop = true;
otherwise
end
YT
YT il 8 Lug 2020
ご提示いただいたようにOutputFcn を自分で定義することで、
各反復における最良値f(x)を任意のフォーマットで示すことができました。
おかげさまでOutputFcnに関する勉強にもなりました。ありがとうございました。
michio
michio il 8 Lug 2020
よかったです!ご連絡頂きありがとうございました。

Accedi per commentare.

Più risposte (0)

Richiesto:

YT
il 6 Lug 2020

Commentato:

il 8 Lug 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!