snnlab.viz.transforms
Complete declared API of the transforms module, with signatures, data fields, validation and source.
Reusable numerical transforms, independent of Matplotlib.
The signatures, defaults, fields, docstrings and implementation excerpts below are generated from the Python source. Annotations are shown as declared; unannotated means the source supplies no type annotation. These pages document callable surfaces, including legacy support utilities, without promising backend support for every declaration.
| Symbol | Kind |
|---|---|
| exponential_trace | function |
| projection_activity | function |
| representative_frame | function |
exponential_trace
def exponential_trace(events: np.ndarray, *, dt_ms: float, tau_ms: float) -> np.ndarrayCompute a causal exponential trace from a (time, units) event array. The initial trace is zero; each later step decays the previous trace and adds the previous timestep's events. Return a float32 array with the same shape.
| Parameter | Annotation | Default | Meaning |
|---|---|---|---|
events | np.ndarray | required | Defined by the source contract and implementation below. |
dt_ms | float | required | Simulation timestep in milliseconds. |
tau_ms | float | required | Decay time constant in milliseconds. |
Return annotation: np.ndarray.
Return expressions (branch-dependent; names refer to the linked implementation):
traceExplicit exceptions in this implementation; called helpers may raise additional errors:
| Explicit exception expression |
|---|
ValueError('events must have shape (time, units)') |
ValueError('dt_ms and tau_ms must be positive') |
Implementation
def exponential_trace(
events: np.ndarray, *, dt_ms: float, tau_ms: float
) -> np.ndarray:
events = np.asarray(events)
if events.ndim != 2:
raise ValueError("events must have shape (time, units)")
if dt_ms <= 0 or tau_ms <= 0:
raise ValueError("dt_ms and tau_ms must be positive")
trace = np.zeros(events.shape, dtype=np.float32)
decay = np.exp(-dt_ms / tau_ms)
for step in range(1, len(events)):
trace[step] = trace[step - 1] * decay + events[step - 1]
return traceprojection_activity
def projection_activity(weights: np.ndarray, source_trace: np.ndarray, *, scale: np.ndarray | float=1.0) -> np.ndarraySource docstring:
Return per-edge activity without imposing a visual representation.| Parameter | Annotation | Default | Meaning |
|---|---|---|---|
weights | np.ndarray | required | Defined by the source contract and implementation below. |
source_trace | np.ndarray | required | Defined by the source contract and implementation below. |
scale | np.ndarray | float | 1.0 | Defined by the source contract and implementation below. |
Return annotation: np.ndarray.
Return expressions (branch-dependent; names refer to the linked implementation):
values * (scale_array[:, None] if scale_array.ndim else float(scale_array))Implementation
def projection_activity(
weights: np.ndarray,
source_trace: np.ndarray,
*,
scale: np.ndarray | float = 1.0,
) -> np.ndarray:
"""Return per-edge activity without imposing a visual representation."""
weight = np.asarray(weights)
trace = np.asarray(source_trace)
source, target = np.nonzero(weight)
values = trace[:, source] * weight[source, target]
scale_array = np.asarray(scale)
return values * (
scale_array[:, None] if scale_array.ndim else float(scale_array)
)representative_frame
def representative_frame(*signals: np.ndarray, candidates: np.ndarray | None=None) -> intSource docstring:
Select the candidate with greatest simultaneous aggregate activity.| Parameter | Annotation | Default | Meaning |
|---|---|---|---|
*signals | np.ndarray | variadic | Defined by the source contract and implementation below. |
candidates | np.ndarray | None | None | Defined by the source contract and implementation below. |
Return annotation: int.
Return expressions (branch-dependent; names refer to the linked implementation):
int(indices[int(np.argmax(score))])Explicit exceptions in this implementation; called helpers may raise additional errors:
| Explicit exception expression |
|---|
ValueError('at least one signal is required') |
ValueError('signals must share a time dimension') |
Implementation
def representative_frame(
*signals: np.ndarray, candidates: np.ndarray | None = None
) -> int:
"""Select the candidate with greatest simultaneous aggregate activity."""
if not signals:
raise ValueError("at least one signal is required")
length = len(np.asarray(signals[0]))
if any(len(np.asarray(signal)) != length for signal in signals):
raise ValueError("signals must share a time dimension")
indices = (
np.arange(length)
if candidates is None
else np.asarray(candidates, dtype=int)
)
score = np.zeros(len(indices), dtype=float)
for signal in signals:
values = np.asarray(signal)[indices]
score += values.reshape(len(indices), -1).sum(axis=1)
return int(indices[int(np.argmax(score))])