Visualization¶
Every figure of a run. hetero.sim imports nine of these lazily; the
remaining ones are still part of the module’s public surface.
- hetero.viz.get_cax(ax, width=3., dist=.05)[source]¶
Returns a human-friendly colorbar axis from a given ax, to be used with matplotlib’s colorbar method.
- hetero.viz.plot_input_char(corrs, psds, deltas, freqs, dts, res_path, mark_peaks=True, name='input_character')[source]¶
The point of this plot is to compare the first peak of autocorrelation and the first frequency in the power density. So either all the frequency and time quantities must be integers or in physical units.
Here I assume they are in physical units (that’s how I set the labels).
- hetero.viz.plot_score_score(res_path, rlz_id=None)[source]¶
Plots, for each mean-timescale level
n(first digit of the net_id), the trial-averaged score of every task of a heterogeneous network (net_idwith a non-zero second digith) against the score of the exact same task for the homogeneous network of the same group (thenet_idwithh=0). Eachhlevel is colored byhetero_colors.The score of the homogeneous network is on the x-axis and the score of the heterogeneous network on the y-axis, so points above the identity line indicate that heterogeneity improves performance.
The trn_/tst_ score files of every network are read, and the per-task score is obtained by averaging across all trials. When
rlz_idis given, only the score files of that realization (e.g.LI-rlz000) are read. One figure per score file (stateLI-rlz000and readout such aspossig1) is saved intores_path, namedscore_score_{trn|tst}{scr_name}.pngto keep therlzXXXnaming convention alive.
- hetero.viz.plot_angle_vs_score(res_path, rlz_id=None)[source]¶
Plots, for every task, the minimal angle between the network state and the task against the task’s benchmark score, for all networks.
Networks are split into groups by their mean-timescale level
n(the first digit of thenet_id, i.e. the mean tau, perTAU_MAP); each group gets one panel. Within each panel the different heterogeneity levelsh(the second digit of thenet_id) are plotted with different colors, using the same color scheme as the other plots of this module (hetero_colors, labeled byHETERO_LABEL_MAP). The top and bottom rows use the train and test splits respectively, so every task appears once per split.The task angle is read from the
angle_{state}.csvfiles produced byhetero.sim.Simulation.compute_minimal_angles()and the score from the pairedtrn_/tst_{state}-{readout}.csvfiles, averaged across trials. Whenrlz_idis given, only that realization (e.g.0->LI-rlz000) is plotted.One figure per score file is saved into
res_path, each coloring the scatter with a different scheme: by the heterogeneity/color levelh(the default,angle_vs_score{scr_name}.png), and by the task propertiesdim,deltaanddeg(angle_vs_score{scr_name}- {dim,delta,deg}.png). The task-property figures reuse the colormaps ofplot_udf_vs_complexity():dimanddegare categorical (Set2andAccent),deltais continuous (coolwarm).
- hetero.viz.plot_overlap_cdf(res_path, rlz_id=None)[source]¶
Plots the cumulative distribution of the minimal angles of every task, grouped into panels by the mean-timescale level
n(the first digit of thenet_id, i.e. the mean tau, perTAU_MAP). Within each panel the different heterogeneity levelsh(the second digit of thenet_id) are drawn in the module’shetero_colors, labeled byHETERO_LABEL_MAP.The angles are read from the
angle_{state}.csvfiles produced byhetero.sim.Simulation.compute_minimal_angles(). Each panel pools the train and test angles of every subtask of every network sharing thatn, held separately for eachh, and draws the fraction of tasks whose angle lies below each value (an empirical CDF): a curve shifting toward zero means the tasks are, on average, better aligned with the network state. One figure per angle file (state token) is saved intores_pathasoverlap_cdf{state}.png. Whenrlz_idis given, only that realization (e.g.0->-rlz000) is plotted.- Parameters:
res_path (str) – The path to a simulation directory, containing one subdirectory per network ({n}{h}) with the angle files of each benchmarked realization.
rlz_id (int, optional) – The realization to plot. By default all realizations found are plotted.
- hetero.viz.plot_svals_erank(res_path, rlz_id=None)[source]¶
Plots the singular-value spectrum of every network’s activity and the cumulative distribution of its effective rank, grouped into panels by the mean-timescale level
n(the first digit of thenet_id, i.e. the mean tau, perTAU_MAP), with the heterogeneity levelsh(the second digit of thenet_id) drawn in the module’shetero_colorsand labeled byHETERO_LABEL_MAP– the exact grouping ofplot_overlap_cdf().The spectra and effective ranks are read from the
svals_{state}.csvanderank_{state}.csvfiles produced byhetero.sim.Simulation.compute_minimal_angles(). Two figures per state token are saved intores_path:svals{tok}.png– the mean (solid line) +/- one standard deviation (shaded band) of the singular-value spectra pooled over the train and test slices and over every network sharing thatnandh. Each spectrum is normalized by its own largest singular value so the curves isolate the shape of the spectrum (how many comparable modes the activity has) rather than the overall activity scale;xruns over the modes in descending order, rescaled to the unit fraction[0, 1]. A curve hugging 1 over a long stretch means the activity is effectively low-dimensional (few dominant modes); a fast decay to 0 means the variance is spread over many modes.erank{tok}.png– the empirical CDF of the effective rank (the Roy & Vetterli spectral-entropy rank, seehetero.sim.Simulation._effective_rank()) pooled over the train and test slices and over every network of each (n,h) pair, i.e. the fraction of states whose effective rank lies below each value.
When
rlz_idis given, only that realization (e.g.0->-rlz000) is plotted.- Parameters:
res_path (str) – The path to a simulation directory, containing one subdirectory per network ({n}{h}) with the svals/erank files of each benchmarked realization.
rlz_id (int, optional) – The realization to plot. By default all realizations found are plotted.
- hetero.viz.plot_svds(net_ids, res_path, N, activation='possig', conv_params=None, suffix='')[source]¶
- hetero.viz.plot_tau_dist(data_path, bins=50, rlz_id=None)[source]¶
Plots the distribution of the neuronal time constants of every network ID of the realization into the result path. Histograms are
steptype with raw counts (density=False) on a logtauaxis, colored by the heterogeneity (h) level – the second digit of thenet_id– followinghetero_colorsand labeled byHETERO_LABEL_MAP. For the homogeneous (h=0) networks, whose time constants are all equal, a vertical line at the constant value is drawn instead of a histogram. Thenlevels (first digit, i.e. the meanE[tau]level perTAU_MAP) are differentiated by line width. A seaborn-style legend built from dummy handles reports thehcolors and thenwidths. The x/y ranges are fixed across realizations: x in [5e-3, 50] and y in [N/1000, N/2] withNthe number of neurons per network.
- hetero.viz.plot_complexity_map(data_path)[source]¶
Creates and saves a complexity map per input dimension without recomputing the tasks.
Rather than re-synthesizing the target timeseries and recomputing information-theoretic measures for every subtask, this function simply loads the previously calculated complexities from
{data_path}/complexities.csv, the file thathetero.sim.Simulation.compute_complexity()(viautils.compute_complexity) has already saved during initialization.- Parameters:
task (hetero.tasks.TemporalTask) – The task object (its
nameis used in the output file name).data_path (str) – Path to the simulation directory containing
complexities.csv.
Notes
complexities.csvcontains one row per flattened subtask with columnsdim, delta, deg, complexity.A single figure is written to
{task.name}_complexity.svgwith one row per input dimension: each row is a pcolormesh of the complexity withdeltaon the x-axis anddegreeon the y-axis.Tasks that do not vary along both a degree axis and a delta axis (e.g.
TaylororNostradamusalone) have no 2D map to draw and are skipped with a warning.
- hetero.viz.plot_udf_vs_complexity(data_path)[source]¶
Plots the input-based baseline scores against the precomputed complexities, per subtask.
Loads
{data_path}/complexities.csvand{data_path}/udf.csv, merges them on(dim, delta, deg)and draws, for each subtask, the R2 scores of the linear input-to-target decoder (udf) against the associated complexity (1 - |cos(u, y)|). A single figure is saved as{task.name}_udf_vs_complexity.svg.The layout is a grid of subtask properties (rows) vs. data splits (columns): each row colors the points by a different property of the subtask (input dimension, delta shift
\Delta, degree), the two columns are the train and test scores, and a colorbar at the right of every row identifies the coloring.The udf scores (higher = easier) quantify how much of each target subtask is linearly reachable from the input alone; the complexity (higher = harder) is the static cosine-based difficulty. The dashed
complexity = 1 - scoreline is drawn on every panel as the reference of perfect agreement.For a linear (OLS) input-to-target decoder and a zero-mean, univariate input, the two measures are translatable:
score = |cos|^2 = (1 - complexity)^2. This mapping is drawn as a dash-dotted curve on every panel.- Parameters:
task (hetero.tasks.TemporalTask) – The task object (its
nameis used in the output file name).data_path (str) – Path to the simulation directory containing
complexities.csvandudf.csv.
- hetero.viz.plot_difficulty_map_mi(task, u, data_path)[source]¶
Information-theoretic difficulty map, kept alongside
plot_complexity_map()for comparison.This version recomputes the target timeseries of every subtask and measures the difficulty of the input-to-target mapping with mutual information (
utils.compute_complexity_mi): for each subtask and input dimension the possibility, realizability and feasibility of the mapping are evaluated, and a single figure is saved as{task.name}_feasibility.svgwith one row per input dimension and three columns (Possibility, Realizability, Feasibility).- Parameters:
task (hetero.tasks.TemporalTask) – The task object. Works with both un-flattened subtasks (
[delta, deg]or[deg]) and flattened ones ([dim, delta, deg]).u (ndarray of shape (n_dims, n_timesteps)) – The (compound) input timeseries.
data_path (str) – Path to the simulation directory in which the figures are saved.
note:: (..) – Contrary to
plot_complexity_map(), this function does not reuse the precomputedcomplexities.csvand is therefore the expensive reference against which the cheap (loaded) map is compared.
- hetero.viz.plot_uvx(u, v, x, res_path, final_chunk=1000, state_name=None, rlz_id=None)[source]¶
Plots the input
u, voltagev, and activationxarrays in a 3x2 grid: the lastfinal_chunktimesteps in the first column (heatmap when the array has more than one feature, a line otherwise) and the flattened distribution of each array as a histogram in the second column. Arrays must be shaped (n_features, timesteps).