snnlab
API referencesnnlab.lang

snnlab.lang.readouts

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

Back to lang reference

Readout factories expand into ordinary network populations, projections and operations. They mutate the source network and return a Readout handle rather than computing scores immediately. The Readout forwards attribute lookup to its Signal.

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.

SymbolKind
Readoutclass
MeanVoltagefunction
FinalVoltagefunction
SpikeCountfunction
SpikeRatefunction
CumulativePotentialfunction

Readout

View source

Class decorators: dataclass(frozen=True).

Dataclass constructor parameters. Factory defaults are shown as field declarations; omit these arguments to create fresh values per instance:

Readout(signal: Signal, parameters: tuple = ())

Declared fields, including fields inherited from local data classes:

FieldAnnotationDefaultMeaning
signalSignalrequiredStored member of this data contract; see the class docstring and serialization methods.
parameterstuple()Stored member of this data contract; see the class docstring and serialization methods.

Readout.getattr

View source

def Readout.__getattr__(self, item)
ParameterAnnotationDefaultMeaning
itemunannotatedrequiredDefined by the source contract and implementation below.

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

getattr(self.signal, item)
Implementation
def __getattr__(self, item):
        return getattr(self.signal, item)

Readout.id

View source

Decorators: property.

def Readout.id(self) -> str

Return annotation: str.

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

self.signal.id
Implementation
def id(self) -> str:
        return self.signal.id
Complete class implementation
class Readout:
    signal: Signal
    parameters: tuple = ()

    def __getattr__(self, item):
        return getattr(self.signal, item)

    @property
    def id(self) -> str:
        return self.signal.id

MeanVoltage

View source

def MeanVoltage(*, source: Signal, classes: int, name: str, tau=2 * ms, weight: Spec=Normal(1.0, 0.1)) -> Readout

Connect spikes through a non-negative weighted projection into a non-spiking leaky integrator with one unit per class, then reduce its voltage by a mean over time. The returned Readout records the projection parameter ids.

ParameterAnnotationDefaultMeaning
sourceSignalrequiredDefined by the source contract and implementation below.
classesintrequiredNumber of output/readout classes.
namestrrequiredName used to identify the authored or rendered object.
tauunannotated2 * msDefined by the source contract and implementation below.
weightSpecNormal(1.0, 0.1)Defined by the source contract and implementation below.

Return annotation: Readout.

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

Readout(mean, projection.parameter_ids)
Implementation
def MeanVoltage(
    *,
    source: Signal,
    classes: int,
    name: str,
    tau=2 * ms,
    weight: Spec = Normal(1.0, 0.1),
) -> Readout:
    net = source.network
    with net.group(name):
        layer = net.population(
            f"{name}_integrator",
            size=classes,
            neuron=LeakyIntegrator(
                tau=tau,
                soft_reset_threshold=1.0,
                surrogate_slope=5.0,
                initial_voltage=0.0,
            ),
            spiking=False,
        )
        projection = net.connect(
            source,
            layer.excitatory,
            name=f"{name}_projection",
            synapse=LeakyIntegrator(tau=tau),
            weight=weight,
            constraint=NonNegative(),
            connection="feedforward",
        )
        mean = ops.reduce(
            layer.voltage, operation="mean", over="time", name=f"{name}_mean"
        )
    return Readout(mean, projection.parameter_ids)

FinalVoltage

View source

def FinalVoltage(*, source: Signal, classes: int, name: str) -> Readout

Apply a linear projection to classes, then select its final timestep. Leading non-time dimensions remain.

ParameterAnnotationDefaultMeaning
sourceSignalrequiredDefined by the source contract and implementation below.
classesintrequiredNumber of output/readout classes.
namestrrequiredName used to identify the authored or rendered object.

Return annotation: Readout.

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

Readout(signal)
Implementation
def FinalVoltage(*, source: Signal, classes: int, name: str) -> Readout:
    with source.network.group(name):
        projected = ops.linear(source, size=classes, name=f"{name}_projection")
        signal = source.network.operation(
            "select_final",
            projected,
            name=f"{name}_final",
            shape=tuple(
                dimension for dimension in projected.shape if dimension != "time"
            ),
            unit=projected.unit,
        )
    return Readout(signal)

SpikeCount

View source

def SpikeCount(*, source: Signal, classes: int, name: str) -> Readout

Linearly project the source to classes and sum over time. The linear parameter starts at zero; this is an authored weighted readout, not a raw unweighted population count.

ParameterAnnotationDefaultMeaning
sourceSignalrequiredDefined by the source contract and implementation below.
classesintrequiredNumber of output/readout classes.
namestrrequiredName used to identify the authored or rendered object.

Return annotation: Readout.

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

Readout(result)
Implementation
def SpikeCount(*, source: Signal, classes: int, name: str) -> Readout:
    with source.network.group(name):
        projected = ops.linear(source, size=classes, name=f"{name}_projection")
        result = ops.reduce(
            projected, operation="sum", over="time", name=f"{name}_count"
        )
    return Readout(result)

SpikeRate

View source

def SpikeRate(*, source: Signal, classes: int, name: str, duration: float | None=None, mask: Signal | None=None, window: str='full') -> Readout

Sum the projected source over time and normalize by a physical duration in seconds or a valid-time mask whose duration is inferred from graph dt. Output unit is Hz. Compilation rejects conflicting duration/mask declarations.

ParameterAnnotationDefaultMeaning
sourceSignalrequiredDefined by the source contract and implementation below.
classesintrequiredNumber of output/readout classes.
namestrrequiredName used to identify the authored or rendered object.
durationfloat | NoneNoneDefined by the source contract and implementation below.
maskSignal | NoneNoneDefined by the source contract and implementation below.
windowstr'full'Defined by the source contract and implementation below.

Return annotation: Readout.

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

Readout(signal)

Explicit exceptions in this implementation; called helpers may raise additional errors:

Explicit exception expression
ValueError('SpikeRate requires a duration or valid-time mask')
Implementation
def SpikeRate(
    *,
    source: Signal,
    classes: int,
    name: str,
    duration: float | None = None,
    mask: Signal | None = None,
    window: str = "full",
) -> Readout:
    if duration is None and mask is None:
        raise ValueError("SpikeRate requires a duration or valid-time mask")
    with source.network.group(name):
        projected = ops.linear(source, size=classes, name=f"{name}_projection")
        count = ops.reduce(
            projected,
            operation="sum",
            over="time",
            name=f"{name}_count",
            window=window,
            mask=mask,
        )
        signal = source.network.operation(
            "duration_normalise",
            [count] + ([mask] if mask else []),
            name=f"{name}_rate",
            shape=count.shape,
            unit="Hz",
            duration=duration,
            mask=mask.id if mask else None,
            window=window,
        )
    return Readout(signal)

CumulativePotential

View source

def CumulativePotential(*, source: Signal, classes: int, name: str) -> Readout

Linearly project the source and produce a cumulative sum that retains the time axis.

ParameterAnnotationDefaultMeaning
sourceSignalrequiredDefined by the source contract and implementation below.
classesintrequiredNumber of output/readout classes.
namestrrequiredName used to identify the authored or rendered object.

Return annotation: Readout.

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

Readout(signal)
Implementation
def CumulativePotential(*, source: Signal, classes: int, name: str) -> Readout:
    with source.network.group(name):
        projected = ops.linear(source, size=classes, name=f"{name}_projection")
        signal = source.network.operation(
            "cumulative_sum",
            projected,
            name=f"{name}_cumulative",
            shape=projected.shape,
            unit=projected.unit,
        )
    return Readout(signal)

On this page