Skip to content

Wiring Receptive Field & Coverage

Defined in: griffith_logic.analysis.wiring_stats.ImageLayout (class)

class ImageLayout(
channels: int = 3,
rows: int = 32,
cols: int = 32,
thresholds: int = 3,
)

The ordering of the input bits (threshold minor).

The flattening order is idx = ((channel * rows + row) * cols + col) * thresholds + threshold (the same order as datasets.vision.ThresholdTransform(interleave=True)). Inside this module it is only used as the denominator of pixel occupancy — the number of threshold bits per pixel.

Defined in: griffith_logic.analysis.wiring_stats.layer_stats (function)

def layer_stats(indices: Sequence, in_dim0: int) -> list[dict]

Applies core.connections.connection_stats to a per-layer index table.

For layer i > 0 the input dimension is taken to be the number of gates in the previous layer (indices[i-1].shape[1]). When n_inputs = 2 the number of distinct (b - a) mod in_dim values is also returned. For rot / stretched_rot the difference within a pair is constant, so exactly one value appears (s_b - s_a), which makes this a cheap check that the intended shift amounts really made it into the wiring.

Arguments

  • indices — the sequence of per-layer (n_inputs, out_dim) index tables
  • in_dim0 — the input dimension of layer 0

Returns

A list of dictionaries, one per layer. In addition to the connection_stats keys (coverage / usage_hist / same_input / n_gates) each entry carries layer / in_dim / unreferenced / unreferenced_ratio / raw_diff_unique / raw_diff_value.

Raises

ValueError: the index table is not 2-dimensional, or is out of range (raised by connection_stats)

Defined in: griffith_logic.analysis.wiring_stats.class_receptive_field (function)

def class_receptive_field(
indices: Sequence,
in_dim0: int,
classes: int = 10,
thresholds: int = CIFAR10_3T.thresholds,
) -> dict

Class receptive field: the fraction of input bits a single class can read.

Starting from the group gates of the final layer that are summed into class c (the contiguous block assignment of GroupSum, i.e. the final width divided by classes), the wiring is traced backwards and the fraction of reachable input bits is counted. Each layer only inverts a boolean mask, so even a 6-layer network of width 8,000 finishes in well under a second.

The layer-0 coverage (coverage from layer_stats) counts the inputs read by all classes together, so it can be 100% while an individual class still reads only part of the image. The design rule is stated in terms of this function’s class_cov_mean / class_cov_min instead.

Arguments

  • indices — the sequence of per-layer (n_inputs, out_dim) index tables
  • in_dim0 — the input dimension of layer 0
  • classes — the number of classes (the final layer width must be divisible by it)
  • thresholds — threshold bits per pixel (the denominator of pixel occupancy)

Returns

{'classes', 'group', 'class_cov_mean', 'class_cov_min', 'class_cov_max', 'class_cov' (the per-class fractions), 'pixel_occ_min'}

Raises

ValueError: the final layer width is not divisible by the number of classes, or the index table is not 2-dimensional

Defined in: griffith_logic.analysis.wiring_stats.receptive_field_upper_bound (function)

def receptive_field_upper_bound(width: int, in_dim: int, n_inputs: int = 2) -> float

Upper bound on the fraction of inputs a layer of width width can read (2W / in_dim for 2-input gates).

Each layer-0 gate reads only n_inputs inputs, so a layer 0 of width W touches at most n_inputs · W distinct inputs. Later layers cannot grow that set, so neither the class receptive field nor the layer-0 coverage can exceed this value — a structural bound that holds for any kind of wiring.

How to use it when designing: for a target class receptive field of 1.0 you need width >= in_dim / n_inputs (width 4,608 or more for CIFAR-10’s 9,216 inputs with 2-input gates). On a narrower budget this bound caps you no matter how the shift amounts are designed.

Arguments

  • width — the number of output gates of the layer (the width of layer 0)
  • in_dim — the input dimension of layer 0
  • n_inputs — the number of inputs per gate

Returns

min(1.0, n_inputs · width / in_dim)

Raises

ValueError: width / in_dim / n_inputs is not positive

Defined in: griffith_logic.analysis.wiring_stats.wiring_summary (function)

def wiring_summary(
indices: Sequence,
in_dim0: int,
classes: int = 10,
layout: ImageLayout = CIFAR10_3T,
) -> dict

Wiring statistics for one network: per-layer stats, the class receptive field and the structural upper bound on the receptive field.

Arguments

  • indices — the sequence of per-layer (n_inputs, out_dim) index tables
  • in_dim0 — the input dimension of layer 0
  • classes — the number of classes
  • layout — the ordering of the input bits (used for the threshold count in pixel occupancy)

Returns

{'layers': layer_stats(...), 'class_rf': class_receptive_field(...), 'rf_upper_bound': receptive_field_upper_bound(...)}