Neuro-Symbolic (Predictive Coding)¶
Predictive coding primitives with hyperdimensional symbol binding. Formally verifiable inference over SC bitstreams.
Quick Start¶
from sc_neurocore.neuro_symbolic import (
NeuroSymbolicPredictiveAgent,
PredictiveAgentConfig,
)
agent = NeuroSymbolicPredictiveAgent(
PredictiveAgentConfig(
input_dim=4,
hidden_dim=2,
symbols=("left", "right", "rest"),
)
)
result = agent.observe([0.25, -0.2, 0.1, -0.1], top_k=2)
print(result.signature.popcount)
High-Level Agent¶
sc_neurocore.neuro_symbolic.agent
¶
High-level neuro-symbolic predictive-coding agent API.
PredictiveAgentConfig
dataclass
¶
Configuration for a hybrid symbolic-spiking predictive agent.
Source code in src/sc_neurocore/neuro_symbolic/agent.py
| Python | |
|---|---|
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
SCErrorSignature
dataclass
¶
SC-domain prediction-error signature.
xor_bits is the stochastic-computing error carrier. popcount
is the integer error magnitude used by hardware-friendly decision
logic.
Source code in src/sc_neurocore/neuro_symbolic/agent.py
| Python | |
|---|---|
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
to_dict()
¶
Return a JSON-compatible representation.
Source code in src/sc_neurocore/neuro_symbolic/agent.py
| Python | |
|---|---|
63 64 65 66 67 68 69 70 71 | |
HybridInferenceResult
dataclass
¶
Result of one high-level neuro-symbolic predictive pass.
Source code in src/sc_neurocore/neuro_symbolic/agent.py
| Python | |
|---|---|
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
to_dict()
¶
Return a compact JSON-compatible summary.
Source code in src/sc_neurocore/neuro_symbolic/agent.py
| Python | |
|---|---|
85 86 87 88 89 90 91 92 93 94 95 96 97 | |
NeuroSymbolicPredictiveAgent
¶
Hybrid predictive-coding agent for symbolic-spiking workflows.
Source code in src/sc_neurocore/neuro_symbolic/agent.py
| Python | |
|---|---|
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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
num_symbols
property
¶
Number of registered symbolic labels.
register_symbols(symbols)
¶
Register additional symbolic labels.
Source code in src/sc_neurocore/neuro_symbolic/agent.py
| Python | |
|---|---|
122 123 124 125 | |
observe(observation, *, top_k=1, learn=False)
¶
Run one predictive-symbolic observation pass.
Source code in src/sc_neurocore/neuro_symbolic/agent.py
| Python | |
|---|---|
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
build_sc_error_signature(observation, prediction)
¶
Build an XOR/popcount error signature from observation and prediction.
Source code in src/sc_neurocore/neuro_symbolic/agent.py
| Python | |
|---|---|
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
The high-level agent keeps the existing predictive-coding and hyperdimensional-symbol implementation as the underlying engine. Its SC-facing contract is explicit:
- prediction error is encoded as
xor_bits; - integer error magnitude is
popcount; normalised_popcountis the hardware-friendly magnitude proxy;- optional
learn=Trueapplies one predictive-coding update after inference.
Self-Verification Trace¶
The self-verification layer turns a neuro-symbolic inference result into checked obligations rather than a narrative explanation:
from sc_neurocore.neuro_symbolic import build_self_verification_trace
observation = [0.25, -0.2, 0.1, -0.1]
result = agent.observe(observation, top_k=2)
verification = build_self_verification_trace(result, observation=observation)
assert verification.passed
print(verification.result_digest)
The trace checks prediction/error consistency, SC XOR/popcount consistency, reasoning-trace bounds, confidence/similarity ranges, sorted symbolic scores, and emits a stable SHA-256 digest for audit logs.
sc_neurocore.neuro_symbolic.self_verification
¶
Checked self-verification traces for neuro-symbolic inference results.
VerificationStatus
¶
Bases: Enum
Status of one self-verification obligation.
Source code in src/sc_neurocore/neuro_symbolic/self_verification.py
| Python | |
|---|---|
28 29 30 31 32 33 | |
VerificationObligation
dataclass
¶
One checked condition in a self-verification trace.
Source code in src/sc_neurocore/neuro_symbolic/self_verification.py
| Python | |
|---|---|
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
to_dict()
¶
Return a JSON-ready obligation.
Source code in src/sc_neurocore/neuro_symbolic/self_verification.py
| Python | |
|---|---|
44 45 46 47 48 49 50 | |
NeuroSymbolicSelfVerificationTrace
dataclass
¶
Machine-checkable summary of a neuro-symbolic inference result.
Source code in src/sc_neurocore/neuro_symbolic/self_verification.py
| Python | |
|---|---|
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 | |
passed
property
¶
Whether every obligation passed.
failed_obligations
property
¶
Names of failed obligations.
to_dict()
¶
Return a JSON-ready trace.
Source code in src/sc_neurocore/neuro_symbolic/self_verification.py
| Python | |
|---|---|
77 78 79 80 81 82 83 84 85 86 87 88 89 | |
NeuroSymbolicSelfVerifier
¶
Build checked self-verification traces for inference outputs.
Source code in src/sc_neurocore/neuro_symbolic/self_verification.py
| Python | |
|---|---|
92 93 94 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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
verify_result(result, *, observation)
¶
Verify a high-level hybrid inference result against its observation.
Source code in src/sc_neurocore/neuro_symbolic/self_verification.py
| Python | |
|---|---|
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
verify_trace_only(trace, *, symbol_scores=(), signature=None)
¶
Verify a trace when only symbolic evidence is available.
Source code in src/sc_neurocore/neuro_symbolic/self_verification.py
| Python | |
|---|---|
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | |
build_self_verification_trace(result, *, observation)
¶
Convenience wrapper for high-level neuro-symbolic inference results.
Source code in src/sc_neurocore/neuro_symbolic/self_verification.py
| Python | |
|---|---|
273 274 275 276 277 278 279 | |
Low-Level Primitives¶
sc_neurocore.neuro_symbolic.predictive_coding
¶
Neuro-symbolic predictive coding primitives for SC-domain inference.
Implements a hierarchical predictive coding architecture where each layer maintains a generative model: top-down predictions are compared against bottom-up observations, and the resulting prediction errors drive learning and symbolic reasoning traces.
The HDC/VSA operations mirror the Rust neuro_symbolic crate's
Hypervector type (XOR bind, cyclic permute, majority-vote bundle,
normalised Hamming distance), enabling a pure-Python fallback when
the FFI shared library is unavailable.
References¶
- Rao & Ballard, "Predictive coding in the visual cortex", Nature Neuroscience 2(1), 1999.
- Kanerva, "Hyperdimensional Computing", Cognitive Computation 1(2), 2009.
BindOp
¶
Bases: Enum
Supported HDC binding operations.
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
43 44 45 46 47 | |
ReasoningStep
dataclass
¶
Single step in a symbolic reasoning trace.
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
50 51 52 53 54 55 56 57 58 | |
ReasoningTrace
dataclass
¶
Captures a symbolic reasoning chain for audit and formal verification.
Each step records the symbol query, the operation applied, the similarity score to the best match, and a confidence metric derived from the Hamming margin between the best and second-best candidates.
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
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 93 94 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 | |
Hypervector
¶
Packed binary hypervector (pure-Python mirror of the Rust Hypervector).
Uses np.uint64 packed bitstream layout compatible with the
neuro_symbolic crate's Vec<u64> representation.
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
bind(other)
¶
XOR binding (self-inverse, dimension-preserving).
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
153 154 155 | |
permute(shift)
¶
Cyclic right rotation by shift bits.
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
157 158 159 160 161 162 163 164 | |
hamming_distance(other)
¶
Normalised Hamming distance (0.0 = identical, 1.0 = opposite).
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
166 167 168 169 170 | |
similarity(other)
¶
Cosine-like similarity: 1 − 2·hamming.
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
172 173 174 | |
threshold_bundle(vectors)
staticmethod
¶
Majority-vote bundle across N vectors.
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | |
SymbolEncoder
¶
Deterministic symbol → hypervector mapping (mirrors Rust SymbolEncoder).
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
PredictiveCodingLayer
¶
Single layer in a hierarchical predictive coding network.
Maintains a generative model: top-down predictions are compared against bottom-up observations to produce prediction errors that drive weight updates and symbolic trace emission.
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
predict(hidden=None)
¶
Generate a top-down prediction from the hidden state.
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
280 281 282 283 | |
compute_error(observation, hidden=None)
¶
Bottom-up prediction error: weighted residual.
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
285 286 287 288 289 290 291 292 293 294 | |
update(observation, hidden=None)
¶
One-step gradient update on both weights and hidden state.
Returns the mean absolute error before the update.
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | |
VerifiableInference
¶
Wraps prediction + HDC symbol matching with an auditable trace.
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
register_symbol(name)
¶
Register a symbol into the lookup library.
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
341 342 343 | |
infer(observation, top_k=1)
¶
Run inference: prediction → error → HDC symbol match.
- Feed observation through the predictive coding layer to obtain a prediction-error vector.
- Encode the error into a hypervector via population coding.
- Match against the symbol library using Hamming distance.
- Return ranked results and an auditable reasoning trace.
Source code in src/sc_neurocore/neuro_symbolic/predictive_coding.py
| Python | |
|---|---|
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |