Question on experiments #93
Replies: 0 comments 10 replies
-
Hi,
Here attached an example model of what can be done (not sure it answers
your question): it runs 50 times the simulations (in batch mode) then
displays all the simulation results (for each step) and the mean value for
each step.
Cheers,
Patrick
Le jeu. 9 déc. 2021 à 07:38, Aya-Badawy89 ***@***.***> a
écrit :
… Hello GAMA team,
Do we have a possibility in GAMA to conduct a *Monte Carlo simulation*?
The agents in my model do some actions randomly during the simulation;
then, they reach an outcome.
I want to run several simulations all with the same parameters but explore
how the outcome changes as a result of the stochasticity of variables.
To be more specific: I need multiple simulations to run sequentially and
plot their results on the same chart or take their average. Is it possible?
I tried doing it by coupling the model into a macro-model which can manage
the simulations and plot their results...etc. But, is there an easier
solution?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<https://github.com/gama-platform/gama/discussions/3259>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALPWHNYBBFBTT2OWT5GBMTUP727ZANCNFSM5JVD4ZSA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Beta Was this translation helpful? Give feedback.
-
Hi,
Here the model:
```
model MonteCarlowithbatch
global {
float mean_val <- 10.0;
float standard_deviation_val <- 2.0;
float result <- gauss(mean_val,standard_deviation_val) ;
bool end <- false;
list<float> results;
reflex add_result {
result <- result + result/10.0 + (1.0 - rnd(1.0));
results << result;
end <- cycle = 10;
}
}
experiment explore_model_stochasticity type: batch until: end repeat: 50 {
list<list<float>> results_vals;
float marge <- 5.0;
reflex end_replication {
ask simulations {
myself.results_vals << self.results;
}
do update_outputs(true);
}
geometry median_lines(float min_v, float max_v, int num_c) {
list<point> pts;
loop i from: 0 to: num_c - 1 {
float v <- median(results_vals collect each[i]);
pts << {marge + i * (100 - marge * 2)/ num_c , (100 - marge) - ((100 -
marge*2) * (v - min_v) / (max_v - min_v))};
i <- i + 1;
}
return line(pts);
}
list<geometry> axis {
list<geometry> geoms;
geoms << line([{marge, 100 - marge},{100 - marge, 100 - marge}]);
geoms << line([{marge, 100 - marge},{marge, marge}]) ;
return geoms;
}
list<geometry> result_lines(float min_v, float max_v) {
list<geometry> geoms;
loop c over: results_vals{
list<point> pts;
int i <- 0;
loop v over: c {
pts << {marge + i * (100 - marge * 2)/ length(c) , (100 - marge) - ((100
- marge*2) * (v - min_v) / (max_v - min_v))};
i <- i + 1;
}
geoms << line(pts) ;
}
return geoms;
}
permanent {
display all_simulation {
graphics "all_simulations" {
if (not empty(results_vals)) {
int max_t <- length(results_vals[0]) - 1;
loop ax over: axis() {
draw ax end_arrow: 1 color: #black;
}
draw "Mean results" rotate: -90 at: {4,50} anchor: #center font:
font("Helvetica", 18, #bold) color: #black;
draw "Time" at: {50,98} anchor: #center font: font("Helvetica", 18, #bold)
color: #black;
draw "0" at: {marge,96} anchor: #center font: font("Helvetica", 18, #bold)
color: #black;
draw "0" rotate: -90 at: {marge,93} anchor: #center font:
font("Helvetica", 18, #bold) color: #black;
float max_v <- max(results_vals accumulate each);
float min_v <- min(results_vals accumulate each);
list<geometry> geoms <- result_lines(min_v,max_v);
loop i from: 0 to: length(geoms) - 1 {
draw geoms[i] color: #gray;
}
draw median_lines(min_v,max_v,max_t) + 0.2 color: #red ;
draw ""+ round(max_t) at: {100 - marge,96} anchor: #center font:
font("Helvetica", 18, #bold) color: #black;
draw "" + max_v with_precision 1 rotate: -90 at: {marge, marge} anchor:
#center font: font("Helvetica", 18, #bold) color: #black;
}
}
}
}
}
```
|
Beta Was this translation helpful? Give feedback.
-
Working on a video for this, just lazy to edit it :D ... |
Beta Was this translation helpful? Give feedback.
-
Thank you very much. I have one more question, please. |
Beta Was this translation helpful? Give feedback.
-
Hi,
You can use the user_input_dialog operator in the init of the batch
experiment for that.
Cheers,
Patrick
Le dim. 12 déc. 2021 à 06:58, Aya-Badawy89 ***@***.***> a
écrit :
… As a response to my above question, I figured out a possible way by which
the user dialogs only appear in the first simulation while other
simulations take the same values. Here is a dummy model for how we can do
it:
model dummyModel
global {
init {create girl;}
}
species girl {
int var;
reflex when: time=1 {
ask host {
if int(self) = 0 {
map insert <- user_input_dialog ('Parameters', [enter('Value', 4)]);
myself.var <- int(insert['Value']);
}
else {
loop while: peers[0].girl[0].var = 0 {}
myself.var <- peers[0].girl[0].var;
}
write 'Sim num= ' + (int(self)) + ' and variable = ' + myself.var;
}
}
}
experiment dummy type: batch until: time=10 repeat:2 {
}
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://github.com/gama-platform/gama/discussions/3259#discussioncomment-1792094>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALPWHIM73PDXPHAVROGQGTUQPQR3ANCNFSM5JVD4ZSA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Beta Was this translation helpful? Give feedback.
-
Just to update what I did at the end for anyone who comes across this thread and has a similar challenge: My case in brief: I have a comodel where its agents run another model to compute a value during simulation. The model also displays user-input dialogs at different points while running. The challenge was how to run several simulations for this model and take the average. I tried 3 methods:
Those are my attempts and observations in case anyone finds them useful. |
Beta Was this translation helpful? Give feedback.
-
Hello GAMA team,
Do we have a possibility in GAMA to conduct a Monte Carlo simulation?
The agents in my model do some actions randomly during the simulation; then, they reach an outcome.
I want to run several simulations all with the same parameters but explore how the outcome changes as a result of the stochasticity of variables.
To be more specific: I need multiple simulations to run sequentially and plot their results on the same chart or take their average. Is it possible?
I tried doing it by coupling the model into a macro-model which can manage the simulations and plot their results...etc. But, is there an easier solution?
Beta Was this translation helpful? Give feedback.
All reactions