Skip to content

3.2 Topology Generators

Raul Cardenas Montoya edited this page Sep 19, 2026 · 1 revision

Topology Generators

Relevant source files

The following files were used as context for generating this wiki page:

Purpose and Scope

The topology generation subsystem provides deterministic, index-based pseudo-random network constructors for synaptic-wiring. By avoiding external random number generators (RNGs) and relying instead on golden-ratio fractional hashing of neuron coordinate pairs, the generators ensure complete reproducibility across platforms and runs.

This page covers the core hashing infrastructure, random graph generation (generate_random), small-world network generation (generate_small_world), and parameter bounds enforced by the validation layer.

Sources: src/topology/generators.rs:3-16, README.md:39-42


Deterministic Hashing Infrastructure

To achieve cross-platform determinism without stateful RNG seeds, the subsystem uses fractional hashing based on the golden ratio ($\phi \approx 1.618$) and silver ratio ($\delta \approx 2.414$).

Key hashing functions defined in src/topology/generators.rs:

  • hash_pair(a: usize, b: usize) -> f32: Combines two integer indices using golden and silver ratios, extracting the fractional part to produce a value in $[0, 1)$ src/topology/generators.rs:23-30.
  • hash_weight(src: usize, tgt: usize, base: f32, spread: f32) -> f32: Derives a deterministic synaptic weight from source and target indices src/topology/generators.rs:33-35.
  • hash_delay(src: usize, tgt: usize, max_delay: u16) -> u16: Computes a deterministic axonal delay bound by max_delay src/topology/generators.rs:37-47.
graph TD
    subgraph "Natural Language Space"
        A["NeuronIndices"]
        B["GoldenRatioHashing"]
    end
    subgraph "Code Entity Space"
        C["hash_pair(a:usize,b:usize)"] --> D["hash_weight(src,tgt,base,spread)"]
        C --> E["hash_delay(src,tgt,max_delay)"]
    end
    A --> C
    B --> C

    classDef default fill:none,stroke:#000,stroke-width:1px;
Loading

Figure 1: Deterministic hashing architecture bridging index inputs to graph attributes.

Sources: src/topology/generators.rs:21-48


Erdős–Rényi Random Graph Generator

The generate_random function builds a directed Erdős–Rényi random graph where every directed edge $(i, j)$ with $i \neq j$ exists independently with probability $p$ src/topology/generators.rs:51-56.

Algorithm and Parameter Bounds

  1. Validation: Checks that $p \in [0, 1]$, inhibitory_fraction $\in [0, 1]$, and $n \ge 1$. Returns MeshError::InvalidConfig otherwise src/topology/generators.rs:63-75.
  2. Polarity Assignment: Splits the neuron population at inhibitory_cutoff = (n as f32 * inhibitory_fraction) as usize. Neurons below the cutoff are assigned Polarity::Inhibitory; the rest are Polarity::Excitatory src/topology/generators.rs:77-85.
  3. Edge Generation: Iterates over all directed pairs $(src, tgt)$, skipping self-loops. If hash_pair(src, tgt) < p, a SynapseDescriptor is emitted src/topology/generators.rs:87-101.
  4. Graph Construction: Finalizes the graph via SynapticGraph::from_descriptors src/topology/generators.rs:103-103.
graph TD
    A["generate_random(n,p,max_delay,inh_frac)"] --> B["ValidateParameters"]
    B --> C["ComputeInhibitoryCutoff"]
    C --> D["IterateSourceAndTargetPairs"]
    D --> E{"hash_pair < p?"}
    E -- Yes --> F["EmitSynapseDescriptor"]
    E -- No --> D
    F --> G["SynapticGraph::from_descriptors"]

    classDef default fill:none,stroke:#000,stroke-width:1px;
Loading

Figure 2: Erdős–Rényi generation data flow.

Sources: src/topology/generators.rs:51-104


Watts–Strogatz Small-World Generator

The generate_small_world constructor implements a directed ring lattice augmented with probabilistic rewiring src/topology/generators.rs:106-127.

Construction Pipeline

  1. Validation: Requires $n \ge 3$, even $k \in [2, n-1]$, $\beta \in [0, 1]$, and valid inhibitory fraction src/topology/generators.rs:135-154.
  2. Lattice Initialization: Each neuron connects to $k$ nearest neighbors ($k/2$ clockwise, $k/2$ counterclockwise) src/topology/generators.rs:157-171.
  3. Rewiring: Each outgoing synapse is evaluated against probability $\beta$ using hash_pair with salt. If rewired, rewire_small_world_target selects a valid non-self, non-duplicate target src/topology/generators.rs:173-178.
  4. Descriptor Collection: Generates SynapseDescriptor instances with deterministic weights and delays src/topology/generators.rs:180-190.
Parameter Type Valid Range Description
n usize $\ge 3$ Total neuron count
k usize Even, $[2, n-1]$ Initial mean degree
beta f32 $[0, 1]$ Rewiring probability
max_delay u16 $\ge 0$ Maximum axonal delay ticks
inhibitory_fraction f32 $[0, 1]$ Proportion of inhibitory neurons

Sources: src/topology/generators.rs:106-195

Clone this wiki locally