How to handle stiffness parameter using Try and Catch?

1 回表示 (過去 30 日間)
Jinsu Kim
Jinsu Kim 2020 年 9 月 3 日
コメント済み: Mohammad Sami 2020 年 9 月 3 日
Hi all,
I'm trying to do parameter estimation (using GA) in my stiffness 1D ODE system.
When GA automatically try various parameter values to fit data, some parameter cases are so sensitive that main function were shut down due to stiffness problem.
In this case, how to handling exception case using "try and catch" ?
In my system, I solve 95 ODEs simultaneously. Among them a parameter affects several ODEs and it cause stiffness problem.
I want to change setting parameter value as zero in case of stiffness problem.
Regards,
Kim.

採用された回答

Mohammad Sami
Mohammad Sami 2020 年 9 月 3 日
編集済み: Mohammad Sami 2020 年 9 月 3 日
You can perhaps try a for loop over the various parameters.
% assuming you have 5 parameters needed for your function
% and you have 20 different combinations you want to try
parameters = cell(20,5);
% assign parameters
errors = cell(20,1);
for i = 1:size(parameters,1)
try
somefunction(parameters{i,1},parameters{i,2},parameters{i,3},parameters{i,4},parameters{i,5});
% or short form
%somefunction(parameters{i,:});
catch ME
errors{i} = ME;
end
end
  2 件のコメント
Jinsu Kim
Jinsu Kim 2020 年 9 月 3 日
Thanks for your opinion. Actually it's good way to try.
I have one more question. I want to handle exception case more automatically. How can I apply your idea when using GA (Genetic Algorithm) ?
This is the full code of GA.m
fitness = @Main ;
parameter = 5 ;
LB = [ 1*10^(-7), 40, 1*10^(-7), 40, 1*10^(-7) ] ;
UB = [ 1.0*10^(-5), 100, 1.0*10^(-5), 100, 1.0*10^(-5) ] ;
[x, fval] = ga (fitness, parameter, [], [], [], [], LB, UB ) ;
Mohammad Sami
Mohammad Sami 2020 年 9 月 3 日
If the error is thrown by the function you are optimizing, you can put try catch inside the function. In the catch you can assign an output value such as 0 or Inf depending on your use case.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by