Stopping simulation early on event

7 ビュー (過去 30 日間)
Abed Alnaif
Abed Alnaif 2019 年 11 月 25 日
コメント済み: Abed Alnaif 2019 年 12 月 3 日
Hello,
Is there a good way to stop a simulation early if an event occurs; i.e., stop the simulation as soon as the event is triggered? Also, I'd like to do this in a way that causes the objective function value to be infinite when using 'sbiofit'.
Thank you,
Abed

採用された回答

Arthur Goldsipe
Arthur Goldsipe 2019 年 11 月 26 日
Hi Abed,
Interesting question. The only way an event can stop a simulation early is if the event errors. sbiofit would handle such a siutation by returning Inf for the objective function value. Since you mentioned fitting, I generally recommend setting MaximumWallClock during fitting to ensure that things don't get stuck if a fit encounters a bad parameter value that results in a really long running simulation.
Ok, back to a simulation that errors. The only tricky thing with that is creating an event that is compatible with SimBiology's acceleration (that is, with the subset of the MATLAB language that can be used for code generation). Here's an example of modifying the Lotka-Volterra model to end early due to an event:
First, save the following function to myfunction.m:
function time = myfunction(time)
if time >= 0
error("Ending simulation at time " + time);
end
Then, execute the following:
sbioloadproject('lotka');
threshold = m1.addparameter('threshold',1e6);
m1.addevent('y1 > threshold', 'z = myfunction(time)');
sbioaccelerate(m1); % Ensure this model can be accelerated
simdata = sbiosimulate(m1); % Runs to completion
threshold.Value = 1e3;
simdata = sbiosimulate(m1); % Simulation errors
  1 件のコメント
Abed Alnaif
Abed Alnaif 2019 年 12 月 3 日
Thank you, Arthur.

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

その他の回答 (0 件)

コミュニティ

その他の回答  SimBiology コミュニティ

カテゴリ

Help Center および File ExchangeScan Parameter Ranges についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by