snnlab
API referencesnnlab.viz

snnlab.viz.transforms

Complete declared API of the transforms module, with signatures, data fields, validation and source.

Back to viz reference

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.

exponential_trace

View source

def exponential_trace(events: np.ndarray, *, dt_ms: float, tau_ms: float) -> np.ndarray

Compute 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.

ParameterAnnotationDefaultMeaning
eventsnp.ndarrayrequiredDefined by the source contract and implementation below.
dt_msfloatrequiredSimulation timestep in milliseconds.
tau_msfloatrequiredDecay time constant in milliseconds.

Return annotation: np.ndarray.

Return expressions (branch-dependent; names refer to the linked implementation):

trace

Explicit 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 trace

projection_activity

View source

def projection_activity(weights: np.ndarray, source_trace: np.ndarray, *, scale: np.ndarray | float=1.0) -> np.ndarray

Source docstring:

Return per-edge activity without imposing a visual representation.
ParameterAnnotationDefaultMeaning
weightsnp.ndarrayrequiredDefined by the source contract and implementation below.
source_tracenp.ndarrayrequiredDefined by the source contract and implementation below.
scalenp.ndarray | float1.0Defined 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

View source

def representative_frame(*signals: np.ndarray, candidates: np.ndarray | None=None) -> int

Source docstring:

Select the candidate with greatest simultaneous aggregate activity.
ParameterAnnotationDefaultMeaning
*signalsnp.ndarrayvariadicDefined by the source contract and implementation below.
candidatesnp.ndarray | NoneNoneDefined 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))])

On this page