Skip to content

RunSeveralSimulations

mazarsju edited this page Jan 20, 2016 · 17 revisions

Run Several Simulations

To explore a model, the easiest and the most intuitive way to proceed is running several simulations with several parameter value, and see the differences from the output. GAMA provides you the possibility to launch several simulations from the GUI.

Index

Create a simulation

Let's remind you that in GAMA, everything is an agent. We already saw that the "world" agent is the agent of the model. The model is thus a species, called modelName_model :

model toto // <- the name of the species is "toto_model"

New highlight of the day : an Experiment is also an agent ! It's a special agent which will instanciate automatically an agent from the model species. You can then perfectly create agents (model agents) from your experiment, using the statement create :

model multi_simulations // the "world" is an instanciation of the "multi_simulations_model"

global {
}

experiment my_experiment type:gui  {
	init {
		create multi_simulations_model;
	}
}

This sort model will instanciate 2 simulations (two instance of the model) : one is created automatically by the experiment, and the second one is explicitaly created through the statement create.

To simplify the syntax, you can use the built-in attribute simulation of your experiment. When you have a model called "multi_simulations", the two following lines are strictaly equal :

create multi_simulations_model;
create simulation;

As it was the case for creating regular species, you can specify the parameters of your agent during the creation through the facet with: :

model multi_simulations

global {
	rgb bgd_color;
}

experiment my_experiment type:gui  {
	parameter name:"background color:" var:bgd_color init:#blue;
	init {
		create simulation with:[bgd_color::#red];
	}
	output {
		display "my_display" background:bgd_color{}
	}
}

Manipulate simulations

When you think the simulations as agents, it gives you a lot of new possibilities. You can for example create a reflex from your experiment, asking to create simulations during the experiment execution !

The following short model for example will create a new simulation at each 10 cycles :

model multi_simulations

global {
	init {
		write "new simulation created ! Its name is "+name;
	}
}

experiment my_experiment type:gui  {
	init {
	}
	reflex when:(mod(cycle,10)=0 and cycle!=0) {
		create simulation;
	}
	output {
	}
}

You may ask, what is the purpose of such a thing ? Well, with such a short model, it is not very interestring, for sure. But you can imagine running a simulation, and if the simulation reaches a certain state, it can be closed, and another simulation can be run instead with different parameters.

Random seed

Seed from your model

If you run several simulations, you may want to use the same seed for each one of those simulations (to compare the influence of a certain parameter, in exactly the same conditions).

Let's remind you that seed is a built-in attribute of the model. You than just need to speficy the value of your seed during the creation of the simulation if you want to fix the seed :

create simulation with:[seed::10.0];

You can also specify the seed if you are inside the init scope of your global agent.

global {
	init {
		seed<-10.0;
	}
}

Notice that if you affect the value of your seed built-in directly in the global scope, the affectation of the parameters (for instance specified with the facet with of the statement create), and the "init" will be done after will be done at the end.

Seed from your experiment

The experiment agent also have a built-in attribute seed. The value of this seed is defined in your simulation preferences. The first simulation created is created with the seed value of the experiment.

The following sequence diagram can explain you better how the affectation of the seed attribute works :

resources/images/exploringModel/sequence_diagram_seed_affectation.png

The affectation of an attribute is always done in this order : (1) the attribute is affected with a specific value in the species scope. If no attribute value is specified, the value is a default value. (2) if a value is specified for this attribute in the create statement, then the attribute value is affected again. (3) the attribute value can be changed again in the init scope.

Run several simulations with the same random numbers

The following code shows how to run several simulations with a specific seed, determined from the experiment agent :

model multi_simulations

global {
	init {
		create my_species;
	}
}

species my_species skills:[moving] {
	reflex update {
		do wander;
	}
	aspect base {
		draw circle(2) color:#green;
	}
}

experiment my_experiment type:gui  {
	float seedValue <- 10.0;
	float seed <- seedValue; // force the value of the seed.
	init {
		// create a second simulation with the same seed as the main simulation
		create simulation with:[seed::seedValue];
	}
	output {
		display my_display {
			species my_species aspect:base;
		}
	}
}

When you run this simulation, their execution is exactly similar.

resources/images/exploringModel/same_simulation_one_agent.png

Let's try now to add a new species in this model, and to add a parameter to the simulation for the number of agents created for this species.

model multi_simulations

global {
	int number_of_speciesB <- 1;
	init {
		create my_speciesA;
		create my_speciesB number:number_of_speciesB;
	}
}

species my_speciesA skills:[moving] {
	reflex update {
		do wander;
	}
	aspect base {
		draw circle(2) color:#green;
	}
}

species my_speciesB skills:[moving] {
	reflex update {
		do wander;
	}
	aspect base {
		draw circle(2) color:#red;
	}
}

experiment my_experiment type:gui  {
	float seedValue <- 10.0;
	float seed <- seedValue; // force the value of the seed.
	init {
		create simulation with:[seed::seedValue,number_of_speciesB::2];
	}
	output {
		display my_display {
			species my_speciesA aspect:base;
			species my_speciesB aspect:base;
		}
	}
}

Then you run the experiment, you may find something strange...

resources/images/exploringModel/same_simulation_2_species.png

Even if the first step seems ok (the greed agent and one of the two red agent is initialized with the same location), the simulation differs completly. You should have expected to have the same behavior for the greed agent in both of the simulation, but it is not the case. The explaination of this behavior is that a random number generator has generated more random numbers in the second simulation than in the first one.

If you don't understand, here is a short example that may help you to understand better :

model multi_simulations

global {
	int iteration_number <- 1;
	reflex update {
		float value;
		loop times:iteration_number {
			value<-rnd(10.0);
			write value;
		}
		write "cycle "+cycle+" in experiment "+name+" : "+value;
	}
}

experiment my_experiment type:gui  {
	float seedValue <- 10.0;
	float seed <- seedValue; // force the value of the seed.
	init {
		create simulation with:[seed::seedValue,iteration_number::2];
	}
	output {
	}
}

The output will be something like that :

7.67003069780383
cycle 0 in experiment multi_simulations_model0 : 7.67003069780383
7.67003069780383
0.22889843360303863
cycle 0 in experiment multi_simulations_model1 : 0.22889843360303863
0.22889843360303863
cycle 1 in experiment multi_simulations_model0 : 0.22889843360303863
4.5220913306263855
0.8363180333035425
cycle 1 in experiment multi_simulations_model1 : 0.8363180333035425
4.5220913306263855
cycle 2 in experiment multi_simulations_model0 : 4.5220913306263855
5.460148568140819
4.158355846617511
cycle 2 in experiment multi_simulations_model1 : 4.158355846617511
0.8363180333035425
cycle 3 in experiment multi_simulations_model0 : 0.8363180333035425
1.886091659169562
4.371253083874633
cycle 3 in experiment multi_simulations_model1 : 4.371253083874633

Which means :

Cycle Value generated in simulation 0 Value generated in simulation 1
1 7.67003069780383 7.67003069780383
0.22889843360303863
2 0.22889843360303863 4.5220913306263855
0.8363180333035425
3 4.5220913306263855 5.460148568140819
4.158355846617511

When writing your models, you have to be aware of this behavior. Remember that each simulation has it's own random number generator.

  1. What's new (Changelog)
  1. Installation and Launching
    1. Installation
    2. Launching GAMA
    3. Updating GAMA
    4. Installing Plugins
  2. Workspace, Projects and Models
    1. Navigating in the Workspace
    2. Changing Workspace
    3. Importing Models
  3. Editing Models
    1. GAML Editor (Generalities)
    2. GAML Editor Tools
    3. Validation of Models
  4. Running Experiments
    1. Launching Experiments
    2. Experiments User interface
    3. Controls of experiments
    4. Parameters view
    5. Inspectors and monitors
    6. Displays
    7. Batch Specific UI
    8. Errors View
  5. Running Headless
    1. Headless Batch
    2. Headless Server
    3. Headless Legacy
  6. Preferences
  7. Troubleshooting
  1. Introduction
    1. Start with GAML
    2. Organization of a Model
    3. Basic programming concepts in GAML
  2. Manipulate basic Species
  3. Global Species
    1. Regular Species
    2. Defining Actions and Behaviors
    3. Interaction between Agents
    4. Attaching Skills
    5. Inheritance
  4. Defining Advanced Species
    1. Grid Species
    2. Graph Species
    3. Mirror Species
    4. Multi-Level Architecture
  5. Defining GUI Experiment
    1. Defining Parameters
    2. Defining Displays Generalities
    3. Defining 3D Displays
    4. Defining Charts
    5. Defining Monitors and Inspectors
    6. Defining Export files
    7. Defining User Interaction
  6. Exploring Models
    1. Run Several Simulations
    2. Batch Experiments
    3. Exploration Methods
  7. Optimizing Model Section
    1. Runtime Concepts
    2. Optimizing Models
  8. Multi-Paradigm Modeling
    1. Control Architecture
    2. Defining Differential Equations
  1. Manipulate OSM Data
  2. Diffusion
  3. Using Database
  4. Using FIPA ACL
  5. Using BDI with BEN
  6. Using Driving Skill
  7. Manipulate dates
  8. Manipulate lights
  9. Using comodel
  10. Save and restore Simulations
  11. Using network
  12. Headless mode
  13. Using Headless
  14. Writing Unit Tests
  15. Ensure model's reproducibility
  16. Going further with extensions
    1. Calling R
    2. Using Graphical Editor
    3. Using Git from GAMA
  1. Built-in Species
  2. Built-in Skills
  3. Built-in Architecture
  4. Statements
  5. Data Type
  6. File Type
  7. Expressions
    1. Literals
    2. Units and Constants
    3. Pseudo Variables
    4. Variables And Attributes
    5. Operators [A-A]
    6. Operators [B-C]
    7. Operators [D-H]
    8. Operators [I-M]
    9. Operators [N-R]
    10. Operators [S-Z]
  8. Exhaustive list of GAMA Keywords
  1. Installing the GIT version
  2. Developing Extensions
    1. Developing Plugins
    2. Developing Skills
    3. Developing Statements
    4. Developing Operators
    5. Developing Types
    6. Developing Species
    7. Developing Control Architectures
    8. Index of annotations
  3. Introduction to GAMA Java API
    1. Architecture of GAMA
    2. IScope
  4. Using GAMA flags
  5. Creating a release of GAMA
  6. Documentation generation

  1. Predator Prey
  2. Road Traffic
  3. 3D Tutorial
  4. Incremental Model
  5. Luneray's flu
  6. BDI Agents

  1. Team
  2. Projects using GAMA
  3. Scientific References
  4. Training Sessions

Resources

  1. Videos
  2. Conferences
  3. Code Examples
  4. Pedagogical materials
Clone this wiki locally