Skip to main content

A lightweight tool to calculate Predictive Integrity (PI) for PyTorch models.

Project description

ΣPI: Observe the Cognitive ability of Your AI Model

PyPI version License: MIT Ask DeepWiki

ΣPI is a lightweight, universal SDK to calculate Predictive Integrity (PI), a metric from the Integrated Predictive Workspace Theory (IPWT) of consciousness. It provides a powerful, real-time proxy for your model's "cognitive state" during training.

Stop just looking at loss. Start observing how your model learns.

What is Predictive Integrity (PI)?

PI is a score (0 to 1) reflecting a model's internal world model integrity, derived from prediction error (Epsilon), model uncertainty (Tau), and global gradient norm (Surprise). High PI indicates healthy learning; a drop can signal issues like overfitting before loss metrics do.

Why Use ΣPI?

  • Early Warning for Training Instability: Detects subtle shifts in model "cognition" before loss metrics diverge.
  • Insight into OOD Impact: Quantifies the "surprise" your model experiences when encountering out-of-distribution data.
  • Understanding Model Overfitting: Reveals when your model's internal world becomes too rigid or too chaotic.
  • Quantifying Cognitive Load: Provides a novel metric for the "effort" your model expends to integrate new information.

Model Zoo & Experiments

The complete model zoo, experimental framework (PILR-S), and all associated results have been migrated to a dedicated repository: dmf-archive/PILF.

This SigmaPI repository now contains only the core SDK for calculating Predictive Integrity. Please visit the PILF repository for all implementation examples, training scripts, and pre-trained models.

Installation

pip install sigma-pi

How to Use

The sigma-pi package provides the core SigmaPI monitor. Here is a basic integration example:

import torch
from sigma_pi import SigmaPI

# 1. Initialize the SigmaPI monitor once outside your training loop
sigma_pi = SigmaPI(device='cuda' if torch.cuda.is_available() else 'cpu')

# 2. Inside your training/validation loop:
#    (Ensure you are in a `with torch.enable_grad():` block for validation)

# Calculate loss
loss_epsilon = loss_fn(logits, target)

# Compute gradients (this is crucial)
model.zero_grad()
loss_epsilon.backward(create_graph=True) # Use create_graph=True if you need to backprop through PI metrics

# Calculate PI metrics
pi_metrics = sigma_pi.calculate(
    model=model,
    loss_epsilon=loss_epsilon,
    logits=logits
)

print(f"PI: {pi_metrics['pi_score']:.4f}, Surprise: {pi_metrics['surprise']:.4f}")

# Don't forget to step your optimizer after calculating PI
optimizer.step()

The returned pi_metrics dictionary contains:

  • pi_score: The overall predictive integrity (0-1)
  • surprise: Gradient norm indicating model adaptation
  • normalized_error: Error scaled by model uncertainty
  • cognitive_cost: Combined cost of error and surprise
  • Additional component metrics for detailed analysis

Further Reading

PI is a concept derived from the Integrated Predictive Workspace Theory (IPWT), a computational theory of consciousness. To understand the deep theory behind this tool, please refer to https://github.com/dmf-archive/IPWT

Citation

If you wish to cite this work, please use the following BibTeX entry:

@misc{sigma_pi,
  author       = {Rui, L.},
  title        = {{ΣPI: Observe the Cognitive ability of Your AI Model}},
  year         = {2025},
  publisher    = {GitHub},
  url          = {https://github.com/dmf-archive/SigmaPI}
}

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sigma_pi-0.2.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sigma_pi-0.2.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file sigma_pi-0.2.1.tar.gz.

File metadata

  • Download URL: sigma_pi-0.2.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sigma_pi-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e6919e540763acceaba6ad0e9f41cd5e17e90eaf8b39923c4cc7060a0900301c
MD5 418defa8f626c4e846f3413350017218
BLAKE2b-256 d3074f18b60b0ae6cd1b4f1d4854e0a301215801876f88f3802c29c951b64b26

See more details on using hashes here.

Provenance

The following attestation bundles were made for sigma_pi-0.2.1.tar.gz:

Publisher: publish-to-pypi.yml on dmf-archive/SigmaPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sigma_pi-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: sigma_pi-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sigma_pi-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8ca5e2071fb3b154e020f50fdb7b4c761b9b5437ca92f9efc184664a18034c4b
MD5 915c0f8395c2178d87f0f1292d6e7e0f
BLAKE2b-256 1c646020bf2f3c8e64e84b6f917f0572cb6a9b8a4b9c704876786ef97deef324

See more details on using hashes here.

Provenance

The following attestation bundles were made for sigma_pi-0.2.1-py3-none-any.whl:

Publisher: publish-to-pypi.yml on dmf-archive/SigmaPI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page