Skip to main content

credencegraph

Python CI pre-commit.ci status Documentation Status codecov PyPI Version Python Versions License Ruff SPEC 0 — Minimum Supported Dependencies

credencegraph is a neutral engine for graphs of propositions with credences.

Scientific statements are rarely certain. Instead of proving a statement, credencegraph records how strongly each proposition is believed given the propositions it rests on, and computes what follows:

  • the credence of any proposition, conjunction, or conditional query;
  • how that credence changes when a premise is assumed true, false, or wrong;
  • which premises and links a conclusion depends on most — its weak points.

Each node keeps the original text it came from alongside the proposition it states. Relations are either inferential (requires, supports, refutes, equivalent, exclusive), with a fixed probabilistic meaning, or annotations (any other type), which are stored and queried but ignored by inference. The engine has no built-in notion of authors, projects, or workflow; those are expressible as ordinary nodes and annotation relations.

Status: experimental. The package is under active development and stays on 0.x. Any minor release may change the API.

Installation

pip install credencegraph

Requires Python 3.13+.

Example

from credencegraph.core import Beta, Graph, Node, Relation
from credencegraph.inference import conditional, intervene, marginal
from credencegraph.semantics import compile_graph

graph = Graph()
graph.add_node(Node("calibrated", statement="The instrument is calibrated.", base=0.9))
graph.add_node(Node("signal", statement="The signal is real.", base=0.05))
graph.add_node(Node("claim", statement="The effect exists.", base=0.1))
graph.add_relation(Relation("r1", "requires", "calibrated", "signal", strength=1.0))
graph.add_relation(Relation("r2", "supports", "signal", "claim", strength=Beta(8, 2)))
network = compile_graph(graph)

marginal(network, "claim").point  # 0.1324
conditional(network, "calibrated", {"claim": True}).point  # 0.9245
intervene(network, "claim", set={"calibrated": False}).point  # 0.1

answer = marginal(network, "claim", rng=0)
answer.band  # Band(q05=0.1235, q50=0.1335, q95=0.1387), over draws of Beta(8, 2)
answer.mean_over_draws  # 0.1326, the average of the per-draw answers

Conditioning on the claim raises the credence that the instrument is calibrated; intervening on calibration asks what the claim rests on without that premise. The point answer uses the credence means; the band shows how far the answer moves when the uncertain parameters are drawn from their credences, and is omitted when every parameter is a plain number.

Diagnostics

from credencegraph.diagnostics import diagnose

for finding in diagnose(graph, "claim"):
    print(finding.id, finding.message)

Each finding is a record with an id, the nodes and relations involved, a value and a one-line explanation (finding.to_dict() is its JSON form). For the graph above it reports, among others, that calibrated is an assumption with no source, ranks r2 as the crux — the only uncertain input the claim depends on — and ranks signal as the premise most worth resolving. A node's stated credence, the confidence its source asserts, is compared with the credence its premises deliver in log-odds, and a gap above 2 ln(11/9) ≈ 0.40 is reported as an overclaim or underclaim. That value is the infimum of the log-odds gaps between probabilities more than 0.1 apart, approached arbitrarily closely but never reached, so every pair that an absolute gap of 0.1 would report is reported too, up to a rounding allowance of 1e-12.

Command line

The same graph can be built and queried from the shell. Every command takes --json and then prints a single JSON object, including on failure, where it carries a stable error code, a message and a hint.

credencegraph init g.json
credencegraph add-node g.json --id calibrated --base 0.9
credencegraph add-node g.json --id signal --base 0.05
credencegraph add-node g.json --id claim --base 0.1
credencegraph relate g.json calibrated signal --type requires --strength 1
credencegraph relate g.json signal claim --type supports --strength beta:8,2
credencegraph check g.json
credencegraph query g.json marginal claim --json
credencegraph query g.json intervene claim --set calibrated=false
credencegraph diagnose g.json --target claim --json

License

BSD 3-Clause. See LICENSE.

Metadata

Release files for credencegraph 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for credencegraph 0.1.0
File Size Uploaded Provenance
credencegraph-0.1.0.tar.gz 249.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for credencegraph 0.1.0
File Interpreter ABI Platform
credencegraph-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 325.4 kB

Release files / credencegraph-0.1.0.tar.gz

Download URL credencegraph-0.1.0.tar.gz
Size 249.8 kB
Tags Source
SHA-256 checksum
How to use checksums
508522a90a5807f86119842dacfa1bb910c128869eb29c97b4cab517dd0bb59e
BLAKE2b-256 checksum
How to use checksums
8cf7d45388caf85af801adc8d1f14067860bd0b2e68397bf3fa196d28e0f8bf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / credencegraph-0.1.0-py3-none-any.whl

Download URL credencegraph-0.1.0-py3-none-any.whl
Size 75.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eed82683e1792b9e7b88aab23e7ca76d35a8f7a063f5926d91750896ed660c8f
BLAKE2b-256 checksum
How to use checksums
0bef62886f19efc816be67f2051209c2ff3cd2a4783d45143e38979a2d802153
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for credencegraph 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page