Skip to content

Math

Mathematical foundations: category theory, topological observables, and differential geometry on coupling graphs.

Category Theory

sc_neurocore.math.category_theory

CategoryTheoryBridge

Functor mapping between distinct computational domains. Stochastic <-> Quantum <-> Bio

Source code in src/sc_neurocore/math/category_theory.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
class CategoryTheoryBridge:
    """
    Functor mapping between distinct computational domains.
    Stochastic <-> Quantum <-> Bio
    """

    @staticmethod
    def stochastic_to_quantum(bitstream: np.ndarray[Any, Any]) -> np.ndarray[Any, Any]:
        """
        Map bitstream probability p to quantum amplitude sqrt(p).
        """
        p = np.mean(bitstream)
        # Quantum state |psi> = sqrt(p)|1> + sqrt(1-p)|0>
        alpha = np.sqrt(1 - p)
        beta = np.sqrt(p)
        return np.array([alpha, beta])

    @staticmethod
    def quantum_to_bio(state_vector: np.ndarray[Any, Any]) -> float:
        """
        Map quantum probability |beta|^2 to concentration [0, 10] uM.
        """
        prob_1 = np.abs(state_vector[1]) ** 2
        concentration = prob_1 * 10.0
        return concentration

    @staticmethod
    def bio_to_stochastic(concentration: float, length: int = 100) -> np.ndarray[Any, Any]:
        """
        Map concentration to bitstream.
        """
        p = np.clip(concentration / 10.0, 0, 1)
        rands = np.random.random(length)
        return (rands < p).astype(np.uint8)

    def get_functor(self, source: str, target: str) -> Morphism:
        if source == "Stochastic" and target == "Quantum":
            return Morphism(self.stochastic_to_quantum, "Functor: Sto->Quant")
        if source == "Quantum" and target == "Bio":
            return Morphism(self.quantum_to_bio, "Functor: Quant->Bio")
        if source == "Bio" and target == "Stochastic":
            return Morphism(self.bio_to_stochastic, "Functor: Bio->Sto")
        raise ValueError(f"No morphism from {source} to {target}")

stochastic_to_quantum(bitstream) staticmethod

Map bitstream probability p to quantum amplitude sqrt(p).

Source code in src/sc_neurocore/math/category_theory.py
37
38
39
40
41
42
43
44
45
46
@staticmethod
def stochastic_to_quantum(bitstream: np.ndarray[Any, Any]) -> np.ndarray[Any, Any]:
    """
    Map bitstream probability p to quantum amplitude sqrt(p).
    """
    p = np.mean(bitstream)
    # Quantum state |psi> = sqrt(p)|1> + sqrt(1-p)|0>
    alpha = np.sqrt(1 - p)
    beta = np.sqrt(p)
    return np.array([alpha, beta])

quantum_to_bio(state_vector) staticmethod

Map quantum probability |beta|^2 to concentration [0, 10] uM.

Source code in src/sc_neurocore/math/category_theory.py
48
49
50
51
52
53
54
55
@staticmethod
def quantum_to_bio(state_vector: np.ndarray[Any, Any]) -> float:
    """
    Map quantum probability |beta|^2 to concentration [0, 10] uM.
    """
    prob_1 = np.abs(state_vector[1]) ** 2
    concentration = prob_1 * 10.0
    return concentration

bio_to_stochastic(concentration, length=100) staticmethod

Map concentration to bitstream.

Source code in src/sc_neurocore/math/category_theory.py
57
58
59
60
61
62
63
64
@staticmethod
def bio_to_stochastic(concentration: float, length: int = 100) -> np.ndarray[Any, Any]:
    """
    Map concentration to bitstream.
    """
    p = np.clip(concentration / 10.0, 0, 1)
    rands = np.random.random(length)
    return (rands < p).astype(np.uint8)

Topological Observables

Geometric invariants computed on SCPN coupling graphs: winding number from phase dynamics, Ollivier-Ricci curvature on edges, sheaf consistency defect, and connection curvature from parallel transport.

sc_neurocore.math.topology.winding_number(phases)

Compute the winding number of a phase trajectory around S^1.

The winding number counts how many times the phase wraps around the circle [0, 2*pi). It is a topological invariant — continuous deformations of the trajectory cannot change it.

Parameters

phases : np.ndarray, shape (T,) Time series of phase values (radians).

Returns

int Number of complete windings (positive = counterclockwise).

Source code in src/sc_neurocore/math/topology.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def winding_number(phases: np.ndarray) -> int:
    """Compute the winding number of a phase trajectory around S^1.

    The winding number counts how many times the phase wraps around
    the circle [0, 2*pi). It is a topological invariant — continuous
    deformations of the trajectory cannot change it.

    Parameters
    ----------
    phases : np.ndarray, shape (T,)
        Time series of phase values (radians).

    Returns
    -------
    int
        Number of complete windings (positive = counterclockwise).
    """
    diffs = np.diff(phases)
    # Unwrap: large jumps indicate wrapping
    diffs = np.where(diffs > np.pi, diffs - 2 * np.pi, diffs)
    diffs = np.where(diffs < -np.pi, diffs + 2 * np.pi, diffs)
    return int(np.round(np.sum(diffs) / (2 * np.pi)))

sc_neurocore.math.topology.ollivier_ricci_curvature(knm, i, j)

Compute Ollivier-Ricci curvature between nodes i and j on the coupling graph.

Ollivier (2009), "Ricci curvature of Markov chains on metric spaces." The curvature kappa(i,j) measures how much the neighborhoods of i and j overlap. Positive curvature = neighborhoods converge (community structure). Negative curvature = neighborhoods diverge (bottleneck).

Approximation: kappa(i,j) = 1 - W1(mu_i, mu_j) / d(i,j) where mu_i is the lazy random walk distribution from node i, and W1 is the Wasserstein-1 distance on the graph.

Simplified version: uses the coupling strength ratio as a proxy.

Parameters

knm : np.ndarray, shape (N, N) Coupling matrix (non-negative, not necessarily symmetric). i, j : int Node indices.

Returns

float Estimated Ollivier-Ricci curvature in [-1, 1].

Source code in src/sc_neurocore/math/topology.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def ollivier_ricci_curvature(knm: np.ndarray, i: int, j: int) -> float:
    """Compute Ollivier-Ricci curvature between nodes i and j on the coupling graph.

    Ollivier (2009), "Ricci curvature of Markov chains on metric spaces."
    The curvature kappa(i,j) measures how much the neighborhoods of i and j
    overlap. Positive curvature = neighborhoods converge (community structure).
    Negative curvature = neighborhoods diverge (bottleneck).

    Approximation: kappa(i,j) = 1 - W1(mu_i, mu_j) / d(i,j)
    where mu_i is the lazy random walk distribution from node i,
    and W1 is the Wasserstein-1 distance on the graph.

    Simplified version: uses the coupling strength ratio as a proxy.

    Parameters
    ----------
    knm : np.ndarray, shape (N, N)
        Coupling matrix (non-negative, not necessarily symmetric).
    i, j : int
        Node indices.

    Returns
    -------
    float
        Estimated Ollivier-Ricci curvature in [-1, 1].
    """
    N = knm.shape[0]
    # Lazy random walk distribution from node i
    row_i = np.abs(knm[i, :]).copy()
    row_j = np.abs(knm[j, :]).copy()

    sum_i = row_i.sum()
    sum_j = row_j.sum()
    if sum_i == 0 or sum_j == 0:
        return 0.0

    mu_i = row_i / sum_i
    mu_j = row_j / sum_j

    # L1 distance as Wasserstein proxy on the discrete metric
    w1 = 0.5 * np.sum(np.abs(mu_i - mu_j))

    # Curvature: 1 - W1 (since graph distance d(i,j) = 1 for neighbors)
    return float(1.0 - w1)

sc_neurocore.math.topology.sheaf_consistency_defect(phases, knm)

Compute the sheaf consistency defect for the SCPN phase state.

In sheaf theory, a global section exists iff the gluing conditions are satisfied on all overlaps. For the SCPN, the coupling matrix defines the overlaps, and the phase differences weighted by coupling measure the failure to glue.

defect = (1/N^2) * sum_{i,j} |K_ij| * |1 - cos(theta_i - theta_j)|

When phases are synchronized (all equal), defect = 0. When phases are maximally incoherent, defect approaches max(|K|).

This is equivalent to (1 - Kuramoto_R) weighted by coupling.

Parameters

phases : np.ndarray, shape (N,) Phase values (radians) for each layer/oscillator. knm : np.ndarray, shape (N, N) Coupling matrix.

Returns

float Sheaf consistency defect >= 0. Zero means globally coherent.

Source code in src/sc_neurocore/math/topology.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
def sheaf_consistency_defect(phases: np.ndarray, knm: np.ndarray) -> float:
    """Compute the sheaf consistency defect for the SCPN phase state.

    In sheaf theory, a global section exists iff the gluing conditions
    are satisfied on all overlaps. For the SCPN, the coupling matrix
    defines the overlaps, and the phase differences weighted by coupling
    measure the failure to glue.

    defect = (1/N^2) * sum_{i,j} |K_ij| * |1 - cos(theta_i - theta_j)|

    When phases are synchronized (all equal), defect = 0.
    When phases are maximally incoherent, defect approaches max(|K|).

    This is equivalent to (1 - Kuramoto_R) weighted by coupling.

    Parameters
    ----------
    phases : np.ndarray, shape (N,)
        Phase values (radians) for each layer/oscillator.
    knm : np.ndarray, shape (N, N)
        Coupling matrix.

    Returns
    -------
    float
        Sheaf consistency defect >= 0. Zero means globally coherent.
    """
    N = len(phases)
    diffs = phases[np.newaxis, :] - phases[:, np.newaxis]
    cost = np.abs(knm) * (1.0 - np.cos(diffs))
    return float(cost.sum() / (N * N))

sc_neurocore.math.topology.connection_curvature(phases, knm)

Compute the connection curvature from PGBO phase dynamics.

The PGBO covariant derivative u_mu = dphi_mu - alpha * A_mu defines a U(1) connection. The curvature F_{ij} = K_{ij} * cos(theta_i - theta_j) measures the obstruction to parallel transport between layers i and j.

Parameters

phases : np.ndarray, shape (N,) Phase values. knm : np.ndarray, shape (N, N) Coupling matrix.

Returns

np.ndarray, shape (N, N) Connection curvature matrix. Diagonal is zero.

Source code in src/sc_neurocore/math/topology.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
def connection_curvature(phases: np.ndarray, knm: np.ndarray) -> np.ndarray:
    """Compute the connection curvature from PGBO phase dynamics.

    The PGBO covariant derivative u_mu = dphi_mu - alpha * A_mu
    defines a U(1) connection. The curvature F_{ij} = K_{ij} * cos(theta_i - theta_j)
    measures the obstruction to parallel transport between layers i and j.

    Parameters
    ----------
    phases : np.ndarray, shape (N,)
        Phase values.
    knm : np.ndarray, shape (N, N)
        Coupling matrix.

    Returns
    -------
    np.ndarray, shape (N, N)
        Connection curvature matrix. Diagonal is zero.
    """
    diffs = phases[np.newaxis, :] - phases[:, np.newaxis]
    return knm * np.cos(diffs)