Programmable cognition for systems.
Project description
Cognize
Programmable cognition for Python systems
Overview
Cognize is a lightweight cognition engine that tracks a system’s belief (V) against reality (R), accumulates misalignment memory (E), and triggers rupture when drift exceeds a threshold (Θ).
It’s programmable at runtime—inject your own threshold, realignment, and collapse logic, or use the included safe presets.
Built for agents, simulations, filters, anomaly detection, and drift‑aware pipelines.
Features
- Epistemic kernel:
EpistemicStatewith scalar & vector support - Programmable policies: inject custom
threshold,realign,collapsefunctions - Perception adapter: normalize text/image/sensor inputs into a fused vector
- Meta‑policy selection:
PolicyManagerwith shadow evaluation & safe promotion - Explainability: rolling logs,
explain_last(), JSON/CSV export - Tiny core: hard dependency only on NumPy; visualization is optional
Install
pip install cognize
Core Concepts
| Symbol | Meaning |
|---|---|
V |
Belief / Projection |
R |
Reality signal |
∆ |
Distortion (` |
Θ |
Rupture threshold |
E |
Misalignment memory |
⊙ |
Realignment operator |
Quick start (scalar)
from cognize import EpistemicState, threshold_adaptive, realign_tanh, collapse_soft_decay
state = EpistemicState(V0=0.5, threshold=0.35, realign_strength=0.3)
state.inject_policy(
threshold=threshold_adaptive,
realign=realign_tanh,
collapse=collapse_soft_decay,
)
for r in [0.1, 0.3, 0.7, 0.9]:
state.receive(r)
print(state.explain_last()) # human-readable step summary
print(state.summary()) # compact state snapshot
# Export full trace
state.export_json("run.json")
state.export_csv("run.csv")
Multi‑modal with Perception
Bring your own encoders and fuse modalities into a single evidence vector.
import numpy as np
from cognize import EpistemicState, Perception
# Toy 4‑D text embedding
def toy_text_encoder(s: str) -> np.ndarray:
return np.array([len(s), s.count(" "), s.count("a"), 1.0], dtype=float)
P = Perception(text_encoder=toy_text_encoder) # defaults handle fusion & normalization
state = EpistemicState(V0=np.zeros(4), perception=P)
state.receive({"text": "hello world"}) # dict -> Perception -> vector
print(state.last())
You can pass multiple modalities in one dict, e.g. {"text": "...", "image": img, "sensor": {...}}.
See cognize/perception.py for fusion, normalization, modality weights, and explain hooks.
Meta‑policy selection (safe presets)
Use the built‑in PolicyManager to evaluate policy candidates in a shadow run and promote them when they outperform the current behavior.
from cognize import EpistemicState, PolicyManager, PolicyMemory, ShadowRunner, SAFE_SPECS
state = EpistemicState(V0=0.0, threshold=0.35, realign_strength=0.3, rng_seed=42)
state.policy_manager = PolicyManager(
base_specs=SAFE_SPECS, # conservative / cautious / adoptive
memory=PolicyMemory(),
shadow=ShadowRunner(),
epsilon=0.15, # exploration rate
promote_margin=1.03, # must beat baseline by 3%
cooldown_steps=30
)
for r in [0.2, 0.4, 0.45, 0.5, 0.6, 0.65, 0.62, 0.58, 0.7, 0.72, 0.69, 0.75, 0.8]:
state.receive(r)
print(state.event_log_summary()[-3:]) # see policy promotions/evolution events
Want bounded on‑policy evolution?
state.enable_auto_evolution(
param_space={
"conservative": {"k": (0.1, 0.3), "Θ": (0.2, 0.6)},
"cautious": {"k": (0.1, 0.25), "Θ": (0.2, 0.6)},
"adoptive": {"k": (0.2, 0.35), "Θ": (0.2, 0.6)},
},
every=30, rate=1.0, margin=1.02
)
API surface
from cognize import (
EpistemicState, EpistemicGraph, Perception,
PolicyManager, PolicySpec, PolicyMemory, ShadowRunner, SAFE_SPECS,
POLICY_REGISTRY, # prebuilt policy registry (threshold/realign/collapse)
make_simple_state, # convenience factory
)
EpistemicState: kernel (receive evidence, log steps, export traces)Perception: vector-fused adapter for dict inputsPolicyManager: ε‑greedy + shadow evaluation + safe promotionSAFE_SPECS: conservative / cautious / adoptive presetsEpistemicGraph: multi‑state graphs (networks of interacting states)
User Guide: https://github.com/heraclitus0/cognize/blob/main/docs/USER_GUIDE.md
License
Licensed under the Apache License 2.0.
© 2025 Pulikanti Sashi Bharadwaj
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cognize-0.1.6.tar.gz.
File metadata
- Download URL: cognize-0.1.6.tar.gz
- Upload date:
- Size: 40.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
464724662367340b83ccd44231fa21c3eac0e4ad142d5a1d2b44b5d0b4ec168e
|
|
| MD5 |
1969ff5f086dd9ccf27878ea1bdeb619
|
|
| BLAKE2b-256 |
1126c07607f589bb086a36e803f0aa947523b9e8ce4fd41d64ea79edfd92e533
|
File details
Details for the file cognize-0.1.6-py3-none-any.whl.
File metadata
- Download URL: cognize-0.1.6-py3-none-any.whl
- Upload date:
- Size: 39.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f2dde8f818f993f76cdefa1e4d4ba60c337c6eb54ac2d44c57070810f680e72
|
|
| MD5 |
d1a69b7a739b0d77d80dd9ceb2ccf817
|
|
| BLAKE2b-256 |
dbbfd8b1d251031d7484691d10ceceeeabd5ee1d86db25a76c13f68a1ddc8ef5
|