Performing experiments#

See the simulator guide to see how to use the functions described in this section.

Functions for composing and executing an experiment.

class Simulator(model: BaseModel, network: MultilayerNetwork | TemporalNetwork)#

Bases: object

Perform experiment defined by BaseModel on MultiLayerNetwork.

__init__(model: BaseModel, network: MultilayerNetwork | TemporalNetwork) None#

Construct an object.

Parameters:
  • model – model of propagation which determines how experiment looks like

  • network – a network which is being examined during experiment

perform_propagation(n_epochs: int, patience: int | None = None) Logger#

Perform experiment on a given network and model.

It saves logs in Logger object which can be used for further analysis.

Parameters:
  • n_epochs – number of simulation steps to perform experiment for; note, that for temporal networks simulation steps are executed on consecutive snapshots, therefore if one needs to simulate spreading for a longer “time” than number of snapshots, he/she needs to upsample the temporal network first.

  • patience – if provided experiment will be stopped when in “patience” (e.g. 4) consecutive epoch there was no propagation

Returns:

logs of experiment stored in special object

Functions for logging experiment results.

class Logger(model_description: str, network_description: str)#

Bases: object

Store and processes logs acquired during performing Simulator.

__init__(model_description: str, network_description: str) None#

Construct object.

Parameters:
  • model_description – description of the model (i.e. BaseModel.__str__()) which is used for saving in logs

  • network_description – description of the network (i.e. MultilayerNetwork.__str__()) which is used for saving in logs

add_global_stat(log: dict[str, Any]) None#

Add raw log from single epoch to the object.

Parameters:

log – raw log (i.e. a single call of MultilayerNetwork.get_states_num())

add_local_stat(epoch: int, stats: list[dict[str, str]]) None#

Add local log from single epoch to the object.

convert_logs(model_parameters: dict[str, tuple[str, ...]]) None#

Convert raw logs into pandas dataframe.

Used after finishing aggregation of logs. It fulfills self._stats.

Parameters:

model_parameters – parameters of the propagation model to store

get_aggragated_logs() list[dict[str, Any]]#

Get aggregated logs from the experiment as a list of dicts.

get_detailed_logs() dict[int, list[dict[str, str]]]#

Get detailed logs from the experiment as a dict of list of dicts.

plot(to_file: bool = False, path: None | str = None) None#

Plot out visualisation of performed experiment.

Parameters:
  • to_file – flag, if true save figure to file, otherwise it is plotted on screen

  • path – path to save figure

report(visualisation: bool = False, path: None | str = None) None#

Create report of experiment.

It consists of report of the network, report of the model, record of propagation progress and optionally visualisation of the progress.

Parameters:
  • visualisation – (bool) a flag, if true visualisation is being plotted

  • path – (str) path to folder where report will be saved if not provided logs are printed out on the screen