Jump to content
NilsWaap

How to do a parameter sweep in activate?

Recommended Posts

Hello community,

how can I do a parameter sweep in activate?

 

I want to simulate a controller with different parameters for the gain.

Afterwards I want to overlay the different system responses in a plot.

 

I defined a vector with different values for the controller gain "KR" and use it in a "MatrixGain"-block.

KR = [1 .1 .06 .01 .02];

I hoped that could work but it doesnt. Another approch could be to do it by doing multiple simulations with different parameters.

 

best regards

 

Nils

Share this post


Link to post
Share on other sites

Nils,

 

If you open a Water Tank tutorial model (attached) to give it a try, you will see that the constant is assigned to a certain variable x:

image.png.f333f9b3aa2a31a426c25b003b5e49c4.png

 

Which is declared in your Diagram Home as a static variable:

image.png.89adadb8f58c3bc5563db78e7d6b9f32.png

 

Instead of having a single value, you can sweep multiple values of x by simply doing a loop like this:

image.png.94abe26def169a4b68cd2512d66920b0.png

 

Your response under Scope block will show the results for all x values:

image.png.930e1739db6896b11b5305acba7dea3a.png

 

Regards,

 

Roberta

watert.scm

Share this post


Link to post
Share on other sites

Thank you Roberta!

 

I modified your "watert.scm" example as you showed me and it works fine!

If I use the watertank model from the "turtorial_models" folder the modification does not work.

image.png.2503584e405d1179491292270ef2d6b8.png

I made sure that both models are exactly the same. But for some reason there is a problem with the dimensions.

I exchanged the superblocks with the superblock from your model and then it worked fine!

 

The same problem shows up for my controller model.

 

best regards

 

Nils

Share this post


Link to post
Share on other sites

Nils,

 

The difference is the activation of Use subplots parameter in the Scope block, as per the screenshot below:

image.png.bb59ba02d3e4704f0054434d5d2c8545.png

 

This parameter was turned off in the tutorial model, whereas it was on in the file I shared. If you turn it on, you will see that it will work and generate a plot like this for i = 1:8:

image.png.f5803d894f72ea709395f302e1d95652.png

 

If Use subplots is on, we will have one plot per input. Otherwise each input is considered to be a curve (scalar inputs) in the single plot.

 

Regards,

 

Roberta

 

NilsWaap likes this

Share this post


Link to post
Share on other sites

Thanks Roberta,

the watertank example works fine :)

 

A parameter sweep still does not work in my "controller-vehicle"-model.

 

Are there any other parameters I need to change for my model?

 

I am also using "Signal Out"-blocks and "to mat"--blocks. Furthermore I use look-up-tables. Could any of these blocks be a problem for a parameter sweep?

image.png.971f5aed7734373f3f46a19e1bbce9a6.png

 

Regards

 

Nils

 

fahrer.scm M_Motor_LookUp.mat

Share this post


Link to post
Share on other sites

Solution:

Up to now the Look-Up-Tables don't support to do a sweep by running a single simulation.

Instead of doing a single simulation with a parameter vector, we have to do multiple simulations.

 

By using the code below we can change the KR value with the use of the __counter__ variable. (Counts number of simulations performed)

 

if __counter__<=length(KR_test)
    KR = KR_test(__counter__)
else
    return
end

 

If you want to use signal out for different signals, you must name the variables differently, for example:

['simout_fahrer',num2str(__counter__)]

 

And a end-block is needed that restarts the simulation at the event.

image.png.8aedfe038b6f5b640c9a772004054873.png

 

Regards

Nils

M_Motor_LookUp.mat fahrer2.scm

Share this post


Link to post
Share on other sites

Nils,

 

Another user in the forum (Livio) has a suggestion of using Compose as a master and Activate as a slave in order to run Activate in batch to perform parameter sweep.

 

This post:

May help you to achieve your goal!

 

Regards,

 

Roberta

NilsWaap likes this

Share this post


Link to post
Share on other sites

Let me add another approach that I've just learned.

 

There are many options to perform it but I’ve found this method very simple, flexible and self-explanatory.

 

Summary:

In the example, watertank.oml is the master file.

It:

  • changes the input parameters (controller gains)
  • runs (repeatedly) the file Watertank_parm.scm (slave)
  • collects results doing post-processing (plot) at the end.

 

I’ve created a quick video to summarize how to run the demo.

Present working directory must be where you save the files (the video shows how to select the pwd).

Otherwise use an absolute path in the oml file.

 

Liv

 

watertank.oml watertank_param.scm

robertavarela likes this

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...