Skip to main content

PrefGraph

Rationality scores for every user. Rust engine, Python interface.

PyPI Documentation License: MIT

pip install prefgraph

Quick Example

Score how consistently each user's choices align with rational utility maximization:

from prefgraph.datasets import load_demo
from prefgraph.engine import Engine

# 100 synthetic shoppers (prices x quantities), no download needed
users = load_demo()

# Engine scores every user in parallel via Rust/Rayon
engine = Engine(metrics=["garp", "ccei", "mpi", "harp", "hm"])
results = engine.analyze_arrays(users)

for r in results[:3]:
    print(r)
EngineResult: [+] GARP-consistent  ccei=1.0000  hm=15/15  (42us)
EngineResult: [-] 3 violations  ccei=0.8472  mpi=0.0231  hm=12/15  (38us)
EngineResult: [+] GARP-consistent  ccei=1.0000  hm=15/15  (35us)

Every score is a feature you can plug into downstream models. In our benchmarks across 11 e-commerce datasets, revealed preference features rank among the top ten by model importance but add near-zero marginal lift over well-constructed baselines. See the case studies for details.

Your Data

Have a DataFrame? One line:

import prefgraph as rp

# Transaction logs (one row per user x time x item)
results = rp.analyze(df, user_col="user_id", item_col="product",
                     cost_col="price", action_col="quantity", time_col="week")

# Wide format (one row per observation, goods as columns)
results = rp.analyze(df, user_col="user_id",
                     cost_cols=["price_A", "price_B"],
                     action_cols=["qty_A", "qty_B"])

# Menu/click data (which items were shown, which was picked)
results = rp.analyze(df, user_col="user_id",
                     menu_col="shown_items", choice_col="clicked")

Returns a DataFrame with one row per user. Customize with metrics=["garp", "ccei", "mpi", "hm"].

Scores

Score Field What it measures Range
Consistency is_garp Are choices rationalizable? (GARP) bool
Efficiency ccei How close to perfectly rational? (Afriat) 0-1
Exploitability mpi Value left on the table per choice (Karp cycle) 0-1
Homotheticity is_harp Do preferences scale with budget? bool
Rationalizable fraction hm_consistent/hm_total Fraction of rationalizable choices (Houtman-Maks) 0-1
Utility recovery utility_success Can latent utility be reconstructed? (Afriat LP) bool
Per-obs efficiency vei_mean Average efficiency across observations (Varian) 0-1

Which API?

Engine Function API
Use case Score thousands of users Deep-dive one user
Speed 2,000-49,000 users/sec (Rust) Single-user
Returns EngineResult (flat scores) GARPResult, AEIResult, etc. (matrices, cycles, graphs)
Metrics 7 (garp, ccei, mpi, harp, hm, utility, vei) + network 30+ algorithms
Input list[(prices, quantities)] BehaviorLog

Engine for batch scoring. Function API when you need violation details, observation/item graphs, or advanced tests:

from prefgraph import BehaviorLog, validate_consistency, compute_integrity_score

# 3 shopping trips, 2 goods
session = BehaviorLog(cost_vectors=prices, action_vectors=quantities)

# GARP: does a consistent utility function exist?
garp = validate_consistency(session)       # GARPResult with violation cycles, matrices

# CCEI: how much must budgets shrink to remove contradictions?
ccei = compute_integrity_score(session)    # AEIResult with binary search details

Budget and Menu Choices

PrefGraph supports two primary choice domains:

Category Input format Example domain Key tests
Budget (prices T x K, quantities T x K) E-commerce, grocery, food delivery GARP, CCEI, MPI, HM, HARP, VEI
Discrete (menus, choices) or (menus, frequencies) Surveys, A/B tests, recommendations, LLM eval SARP, WARP, HM, RUM LP, IIA

Performance

The Rust engine (rpt-core) handles graph algorithms and LP solving via Rayon thread pool. Python handles I/O and the user-facing API.

Configuration Throughput 10K users 100K users
GARP only ~49,000/s 0.1s 2.0s
GARP + CCEI ~2,400/s 4.2s 39.5s
Comprehensive (GARP, CCEI, MPI, HARP) ~2,000/s 6.8s 67.1s
Menu (SARP + WARP + HM) ~1,900/s 0.3s 5.2s

Memory stays flat via streaming chunks.

Documentation

Full docs at prefgraph.readthedocs.io:

License

MIT

Metadata

Release files for prefgraph 0.6.2

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

Source distribution (sdist)

Source distribution for prefgraph 0.6.2
File Size Uploaded
prefgraph-0.6.2.tar.gz 429.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for prefgraph 0.6.2
File
prefgraph-0.6.2-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
prefgraph-0.6.2-cp313-cp313-manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64 Details
prefgraph-0.6.2-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details
prefgraph-0.6.2-cp313-cp313-macosx_10_12_x86_64.whl CPython 3.13 CPython 3.13 macOS 10.12+ x86-64 Details
prefgraph-0.6.2-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
prefgraph-0.6.2-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details
prefgraph-0.6.2-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details
prefgraph-0.6.2-cp312-cp312-macosx_10_12_x86_64.whl CPython 3.12 CPython 3.12 macOS 10.12+ x86-64 Details
prefgraph-0.6.2-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
prefgraph-0.6.2-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details
prefgraph-0.6.2-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
prefgraph-0.6.2-cp311-cp311-macosx_10_12_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.12+ x86-64 Details
prefgraph-0.6.2-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
prefgraph-0.6.2-cp310-cp310-manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64 Details
prefgraph-0.6.2-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
prefgraph-0.6.2-cp310-cp310-macosx_10_12_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.12+ x86-64 Details

Total release size: 77.8 MB

Release files / prefgraph-0.6.2.tar.gz

Download URL prefgraph-0.6.2.tar.gz
Size 429.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6f34d3d027d8b7a8df102c3d9af081c7b993d02d08f9fd630fc897d4264836e3
BLAKE2b-256 checksum
How to use checksums
7ee2c8b141f859abc70f0bcb473d496bf44e4971674a6a859be2b54a50b5fe22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release files / prefgraph-0.6.2-cp313-cp313-win_amd64.whl

Download URL prefgraph-0.6.2-cp313-cp313-win_amd64.whl
Size 4.4 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
f78cba1e52d19852f4f423d976cf240bdda99cf9d93703824912547619995dc0
BLAKE2b-256 checksum
How to use checksums
3e6f50cbc7c4d7c8a901af2b2c6cdd3f2104d399e410b853de9b4d3ab1cf4679
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release files / prefgraph-0.6.2-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL prefgraph-0.6.2-cp313-cp313-manylinux_2_28_x86_64.whl
Size 5.5 MB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
cf5fd924b7f92fe3cde5f023acadc1a032f82ad8769a4086645310e9693279c7
BLAKE2b-256 checksum
How to use checksums
5ecbfa9b4fc669ec2fb50aaab7a21cdb8dea9c6da3b353c185c43944f4a63f60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release files / prefgraph-0.6.2-cp313-cp313-macosx_11_0_arm64.whl

Download URL prefgraph-0.6.2-cp313-cp313-macosx_11_0_arm64.whl
Size 4.5 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e0490a7f2293933d9a11421036409595420e750fddf2f3af68167a8e8c653827
BLAKE2b-256 checksum
How to use checksums
e8c44963970196b2aa80ef1e14de935b420eb929cf84c982e11565df57db7867
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release files / prefgraph-0.6.2-cp313-cp313-macosx_10_12_x86_64.whl

Download URL prefgraph-0.6.2-cp313-cp313-macosx_10_12_x86_64.whl
Size 4.9 MB
Tags CPython 3.13 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
2d8ef1e17d56b8ed51960370e9f92b3586673aed919a1ccbbaee6d8dd5c8f827
BLAKE2b-256 checksum
How to use checksums
b09c03eeb20cb75876c0c86af5da4f7ba374bacf5f575994c626e283a9f6003d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release files / prefgraph-0.6.2-cp312-cp312-win_amd64.whl

Download URL prefgraph-0.6.2-cp312-cp312-win_amd64.whl
Size 4.4 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
efab43cf944bbc03e448262c76ea09f42df58a96916aab23486c7de13a89b7a8
BLAKE2b-256 checksum
How to use checksums
97e7e959479107f15a83834d66da2488a0501a8242b0cd5e5a292160cfe0704d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release files / prefgraph-0.6.2-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL prefgraph-0.6.2-cp312-cp312-manylinux_2_28_x86_64.whl
Size 5.5 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
2f8748cd24b066cc662c7a4b801739d9154480c0a6ca74d1daed6cb5a5346d57
BLAKE2b-256 checksum
How to use checksums
7fca14584090b5d7570c87038626a203432f55574e8077ecca4627ac0b301822
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release files / prefgraph-0.6.2-cp312-cp312-macosx_11_0_arm64.whl

Download URL prefgraph-0.6.2-cp312-cp312-macosx_11_0_arm64.whl
Size 4.5 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
81c1aa163ff3cd4c349885f1ccddeb917c01f76cd75c29b29928f6668b3fb235
BLAKE2b-256 checksum
How to use checksums
2b4a4461d1cfef5f5f8ecc8f6c5ae87003a36f2df6495cf1fb26aef83b0e96a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release files / prefgraph-0.6.2-cp312-cp312-macosx_10_12_x86_64.whl

Download URL prefgraph-0.6.2-cp312-cp312-macosx_10_12_x86_64.whl
Size 4.9 MB
Tags CPython 3.12 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
6357c54b5597cba1f04e89090ec37e3393dba25f6cb199cb9ff519ec1259aec2
BLAKE2b-256 checksum
How to use checksums
a24a13b10869209a2b430884ddb8208a5a2c154954a64130547d7120fb89f5c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release files / prefgraph-0.6.2-cp311-cp311-win_amd64.whl

Download URL prefgraph-0.6.2-cp311-cp311-win_amd64.whl
Size 4.4 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
dedfb3e2da80e2a2e625fdf3147d07db945e97646183629b3f616b4ee9992194
BLAKE2b-256 checksum
How to use checksums
3065879b860effb478891b76ed0fe7f7fb02b7c5447b5bcbbfc9a19544593d03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release files / prefgraph-0.6.2-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL prefgraph-0.6.2-cp311-cp311-manylinux_2_28_x86_64.whl
Size 5.5 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
5724c65abe44f78bb9beb3b860dafc211867a77ce6b360cd16c0edd37958243c
BLAKE2b-256 checksum
How to use checksums
ee370d99d4423d42ae1063663632d8223981d2bad8252f4ca91d01e0e4bf16b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release files / prefgraph-0.6.2-cp311-cp311-macosx_11_0_arm64.whl

Download URL prefgraph-0.6.2-cp311-cp311-macosx_11_0_arm64.whl
Size 4.5 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b6322426fc70ba6e2ed95bdf3ce2a70fc0be9ba95108c27ddf705850a217dec1
BLAKE2b-256 checksum
How to use checksums
d7ced97e09cee9063efc33e84b794edca6e09611ad37697d750e19fb4c480538
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release files / prefgraph-0.6.2-cp311-cp311-macosx_10_12_x86_64.whl

Download URL prefgraph-0.6.2-cp311-cp311-macosx_10_12_x86_64.whl
Size 4.9 MB
Tags CPython 3.11 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
5f1284b750cafc8f9ce8173e48579a602147656e8f53fb561cafb9e1e5821ed8
BLAKE2b-256 checksum
How to use checksums
8164c0176956495718c17456c5d7d33be14116f2ff8a24aa42aaf4ae2c7df8a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release files / prefgraph-0.6.2-cp310-cp310-win_amd64.whl

Download URL prefgraph-0.6.2-cp310-cp310-win_amd64.whl
Size 4.4 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
a77285c3c904fa72467426b1cdb0c67413cb25d1f8f84c4a2e8657f618ad921e
BLAKE2b-256 checksum
How to use checksums
387099b92c5cbf33fb8db86cddde45902fabb270ccc502989094650a0b002613
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release files / prefgraph-0.6.2-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL prefgraph-0.6.2-cp310-cp310-manylinux_2_28_x86_64.whl
Size 5.5 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
f037c6d3ac3f8e049c8c53a7d01fe4277b420c55ce81962d794ba329451ed101
BLAKE2b-256 checksum
How to use checksums
653cf030813c026f45150f1a493d761d0211be3472cc0998646b51aa48d78a7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release files / prefgraph-0.6.2-cp310-cp310-macosx_11_0_arm64.whl

Download URL prefgraph-0.6.2-cp310-cp310-macosx_11_0_arm64.whl
Size 4.5 MB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
9dd33c02c8afc2c9fb1f987ccc439f3f134bf7f896365d8148491f31ccd0ab05
BLAKE2b-256 checksum
How to use checksums
06287f5978f2b264ab6209526abc7edc2b1aa25c3856978679fb0a81c552e88c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release files / prefgraph-0.6.2-cp310-cp310-macosx_10_12_x86_64.whl

Download URL prefgraph-0.6.2-cp310-cp310-macosx_10_12_x86_64.whl
Size 4.9 MB
Tags CPython 3.10 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
e2f2b4ec4aa5e8292d3ac450e431ba65a7d51115d4174bd66da37f36227e4052
BLAKE2b-256 checksum
How to use checksums
6eb5329276083446111b75ea1773a676c14dcac9d1ad1fcf1ee1719f8cc81cce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via maturin/1.13.3

Release history Release notifications | RSS feed

This release

0.6.2 This release

17 release files

0.6.1

17 release files

0.6.0

17 release files

0.5.9

18 release files

0.5.8

18 release files

0.5.7

17 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

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