stochastic_visualizations
RL4CRN.utils.stochastic_visualizations
Plotting utilities for SSA / simulation diagnostics.
This module contains small helper functions to visualize simulation results, with an emphasis on stochastic simulations where multiple trajectories per input setting are summarized via mean ± standard deviation.
The main entry point, plot_simulation_summary, accepts either:
- Raw SSA output with per-trajectory samples (identified by a
timecolumn and species columns), in which case it aggregates on-the-fly; or - Pre-summarized output (e.g., from
quick_measurement_SSA) where columns are a pandas MultiIndex with statistics like('X_1', 'mean'),('X_1', 'std').
The function groups traces by unique input combinations (e.g., u_1, u_2, u_3)
and draws a grid of subplots, one panel per distinct input setting.
plot_simulation_summary(df, species_cols=['X_1', 'X_2', 'X_3', 'OUT'], input_cols=['u_1', 'u_2', 'u_3'], mean_only=False)
Plot mean ± standard deviation trajectories for each distinct input setting.
This helper is designed to work with two common dataframe layouts:
(A) Raw data (per-trajectory samples)
- Must contain a
timecolumn and one column per species inspecies_cols. - May contain input columns in
input_cols(e.g.,u_1,u_2,u_3). - The function will aggregate with:
subset.groupby('time')[species_cols].agg(['mean','std']).
(B) Summarized data (already aggregated)
- Uses a pandas
MultiIndexon columns where the second level contains statistics such as'mean'and'std'. - Expected column pattern:
(species_name, 'mean')and(species_name, 'std'). - Still requires a
timecolumn (possibly as('time','')in MultiIndex).
For each unique combination of the available input columns, a subplot is created
and the mean trajectory for each species is plotted; shaded bands show ±1 std
unless mean_only=True.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
Dataframe containing either raw or summarized simulation data.
TYPE:
|
species_cols
|
Species columns to plot (default: ('X_1','X_2','X_3','OUT')).
TYPE:
|
input_cols
|
Input columns used to partition the dataframe into subplots.
Columns may be plain strings or appear as
TYPE:
|
mean_only
|
If True, plot only means (no ±std shading).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
None. The function creates a matplotlib figure and subplots.
(It does not call |
Notes
- If no valid
input_colsare present, the entire dataframe is plotted in a single panel. - If a species is not present in the dataframe, it is skipped silently.
- The function prints whether it detected summarized vs raw mode.