analyzers
Define analyzers, which are used to track variables when the sim is run.
Analyzers typically include things like additional tracking states by age or another conditional.
Classes
| Name | Description |
|---|---|
| Analyzer | Base class for Analyzers. Analyzers are used to provide more detailed information |
| dynamics_by_age | Example analyzer: track dynamics of a state by age. |
| infection_log | Log infections – see ss.InfectionLog for detail |
Analyzer
analyzers.Analyzer(name=None, label=None, **kwargs)Base class for Analyzers. Analyzers are used to provide more detailed information about a simulation than is available by default – for example, pulling states out of sim.people on a particular timestep before they get updated on the next step.
The key method of the analyzer is step(), which is called with the sim on each timestep.
dynamics_by_age
analyzers.dynamics_by_age(state, age_bins=(0, 20, 40, 100))Example analyzer: track dynamics of a state by age.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| state | str | the name of the state to analyze | required |
| age_bins | list | the list of age bins to analyze by | (0, 20, 40, 100) |
Examples
by_age = ss.dynamics_by_age('sis.infected')
sim = ss.Sim(diseases='sis', networks='random', analyzers=by_age)
sim.run()
sim.analyzers[0].plot() # Note: if Sim(copy_inputs=False), we can also use by_age.plot()Methods
| Name | Description |
|---|---|
| finalize_results | Convert per-step lists to arrays |
| init_post | Validate that the requested state exists |
| plot | Plot counts by age bin over time |
| step | Record counts of agents in each age bin who have the tracked state active |
finalize_results
analyzers.dynamics_by_age.finalize_results()Convert per-step lists to arrays
init_post
analyzers.dynamics_by_age.init_post()Validate that the requested state exists
plot
analyzers.dynamics_by_age.plot(**kwargs)Plot counts by age bin over time
step
analyzers.dynamics_by_age.step()Record counts of agents in each age bin who have the tracked state active
infection_log
analyzers.infection_log()Log infections – see ss.InfectionLog for detail
This analyzer activates an infection log running in each disease. This is different than other analyzers, but is required since the information required to create an infection log isn’t kept outside of the disease’s infect() step.
Examples
import starsim as ss
sim = ss.Sim(n_agents=1000, dt=0.2, dur=15, diseases='sir', networks='random', analyzers='infection_log')
sim.run()
sim.analyzers[0].plot()Methods
| Name | Description |
|---|---|
| animate | Animate the infection log – mostly for amusement! |
| finalize_results | Collect the infection logs from each of the diseases |
| plot | Plot all of the infection logs |
| step | Handled by ss.InfectionLog() |
animate
analyzers.infection_log.animate(
key=0,
framerate=10,
clear=False,
cmap='parula',
**kwargs,
)Animate the infection log – mostly for amusement!
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| key | int / str | which disease to animate the infection log of | 0 |
| framerate | float | how many frames per second to display | 10 |
| clear | bool | whether to clear the frame on each step | False |
| cmap | str | the colormap to use | 'parula' |
finalize_results
analyzers.infection_log.finalize_results()Collect the infection logs from each of the diseases
plot
analyzers.infection_log.plot(**kwargs)Plot all of the infection logs
step
analyzers.infection_log.step()Handled by ss.InfectionLog()