Explainability¶
Bitstream-level explainability and causal attribution for SC decisions. Anchored to formal verification properties.
Quick Start¶
from sc_neurocore.explainability.explainability import (
ExplainabilityEngine, CausalAttributor, FormalPropertyLink,
)
sc_neurocore.explainability.explainability
¶
Bitstream-level explainability with deterministic replay and provenance.
Leverages bit-true deterministic SC streams and LFSR replay to generate
full provenance traces: "why this spike fired" as a verifiable bitstream
decision tree. Integrates with the predictive_coding.ReasoningTrace
for neuro-symbolic explanations and produces hash-verified audit trails.
LFSRReplay
¶
Deterministic LFSR-16 replay engine.
Mirrors core_engine::Lfsr16 polynomial: x^16 + x^14 + x^13 + x^11 + 1.
Given the same seed, reproduces the exact same bitstream for formal
verification and replay-based auditing.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
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 | |
step()
¶
Advance one step, return new register value.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
46 47 48 49 50 | |
encode(threshold, length)
¶
Generate a bitstream by comparing LFSR output against threshold.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
52 53 54 55 56 57 58 | |
reset()
¶
Reset to initial seed for replay.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
60 61 62 | |
DecisionMargin
dataclass
¶
How close a decision was to flipping.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
74 75 76 77 78 79 80 81 | |
DecisionNode
dataclass
¶
One node in a spike decision tree.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
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 | |
SpikeDecisionTree
¶
Captures "why this spike fired" as a verifiable decision tree.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
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 | |
add_decision(neuron_id, bitstream, threshold, scc=0.0, parent=None, timestep=0, layer_id='', contributing_neurons=None, threshold_q16=0)
¶
Record a spike decision from bitstream observation.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
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 | |
nodes_at_layer(layer_id)
¶
Return all nodes at a given layer.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
185 186 187 | |
nodes_at_timestep(timestep)
¶
Return all nodes at a given timestep.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
189 190 191 | |
get_node(neuron_id)
¶
Look up a node by neuron ID.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
193 194 195 196 197 198 | |
spike_path()
¶
Return the chain of spiking nodes from root down.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
200 201 202 203 204 205 206 | |
ProvenanceStep
dataclass
¶
One step in a full provenance chain.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
240 241 242 243 244 245 246 247 248 | |
ProvenanceTrace
¶
Full chain from input → encoding → computation → spike decision.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
251 252 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 | |
chain_hash
property
¶
Hash of the entire provenance chain for tamper detection.
add_step(stage, description, data=None, metadata=None)
¶
Record one provenance step.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
RegulatoryMetadata
dataclass
¶
IEC 62304 / FDA SaMD traceability fields.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
317 318 319 320 321 322 323 324 325 326 327 328 | |
FormalPropertyLink
dataclass
¶
Cross-reference to SymbiYosys formal verification.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
331 332 333 334 335 336 337 338 339 | |
VerifiabilityReport
dataclass
¶
Formal audit report with hash verification.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
342 343 344 345 346 347 348 349 350 351 352 353 354 | |
SensitivityResult
dataclass
¶
Result of a 'what-if' threshold perturbation.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
360 361 362 363 364 365 366 367 368 369 | |
SensitivityAnalyzer
¶
Counterfactual analysis: 'would the decision flip if threshold ±N?'
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 | |
critical_delta(node)
staticmethod
¶
Smallest threshold change that flips the decision.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
398 399 400 401 402 403 404 | |
CausalAttribution
dataclass
¶
Attribution of a spike to upstream neurons.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
410 411 412 413 414 415 416 417 418 419 420 421 | |
top_contributors
property
¶
Sorted (descending) list of contributing neurons.
CausalAttributor
¶
Computes causal attribution from input neurons to output spike.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | |
attribute(target, input_bitstreams, weights=None)
staticmethod
¶
Compute per-input-neuron contribution to the target popcount.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 | |
DiffEntry
dataclass
¶
One field that differs between two explanations.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
450 451 452 453 454 455 456 | |
ExplanationDiff
¶
Compares two decision nodes to find divergence points.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
TemporalWindow
¶
Records decisions across timesteps for temporal attribution.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | |
peak_timestep()
¶
Timestep with the highest spike rate.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
503 504 505 506 507 508 509 510 511 512 | |
NaturalLanguageExplainer
¶
Generates human-readable explanation strings.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | |
enhance_with_local_llm(text, *, bridge, question='Rewrite this deterministic spike explanation for a human operator. Preserve all numeric facts and keep the wording concise.')
staticmethod
¶
Enhance a deterministic explanation through the local LLM bridge.
The caller must supply a configured LocalLLMBridge instance so this
module keeps no hard runtime dependency on any local model server.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 | |
explain_node_with_local_llm(node, *, bridge, question='Explain this spike decision for a human operator in two short paragraphs. Do not change or invent numeric values.')
staticmethod
¶
Generate a local-LLM-enhanced explanation for one decision node.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 | |
MultiLayerTrace
¶
Traces decisions across network layers.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 | |
propagation_path()
¶
Per-layer spike rate for visualising propagation.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
631 632 633 634 635 636 | |
SymbolicPathStep
dataclass
¶
One step in a symbolic decision path.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
642 643 644 645 646 647 648 | |
SymbolicPath
¶
Human-readable symbolic path: input → encoding → decision.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 | |
ExplainabilityEngine
¶
End-to-end explainability: replay + decision tree + provenance.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 | |
explain_spike(neuron_id, threshold_q16, bitstream_length, spike_threshold_count, scc=0.0, timestep=0, layer_id='', contributing_neurons=None)
¶
Explain one spike decision via deterministic replay.
Replays the LFSR from the current seed state, generates the exact bitstream, and records the decision in the tree and trace.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 | |
verify(regulatory=None, formal_properties=None)
¶
Generate a verifiability report with full replay check.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 | |
replay_bitstream(threshold_q16, length)
¶
Replay a bitstream from the engine's seed (for external comparison).
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
787 788 789 790 791 792 793 794 | |
sensitivity(node, perturbations=None)
¶
Run sensitivity analysis on a decision node.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
796 797 798 799 800 801 802 | |
attribute(target, input_bitstreams, weights=None)
¶
Compute causal attribution for a decision.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
804 805 806 807 808 809 810 811 | |
explain_spike_with_local_llm(neuron_id, threshold_q16, bitstream_length, spike_threshold_count, *, bridge, scc=0.0, timestep=0, layer_id='', contributing_neurons=None, question='Explain this spike decision for a human operator in two short paragraphs. Do not change or invent numeric values.')
¶
Run the deterministic explainability path, then enhance it locally.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 | |