How to do a parameter sweep in activate?
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
Answers
-
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:
Which is declared in your Diagram Home as a static variable:
Instead of having a single value, you can sweep multiple values of x by simply doing a loop like this:
Your response under Scope block will show the results for all x values:
Regards,
Roberta
0 -
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.
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
0 -
Nils,
The difference is the activation of Use subplots parameter in the Scope block, as per the screenshot below:
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:
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
0 -
Thanks Roberta,
the watertank example works fine /emoticons/default_smile.png' srcset='/emoticons/smile@2x.png 2x' title=':)' width='20' />
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?
Regards
Nils
0 -
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
endIf 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.
Regards
Nils
0 -
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:
https://community.altair.com/community?id=community_question&sys_id=bd96c07a1b2bd0908017dc61ec4bcb13May help you to achieve your goal!
Regards,
Roberta
0 -
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
0