Revealed preference analysis - rationality scores, efficiency indices, and utility recovery. Rust engine, Python interface.
Project description
PrefGraph
Rationality scores for every user. Rust engine, Python interface.
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:
- Loading Data - Parquet, DataFrame, synthetic generators
- Case Studies - LLM consistency, e-commerce benchmarks
- Algorithms - Implementation details
- API Reference - Full method reference
License
MIT
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 Distributions
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 prefgraph-0.5.17.tar.gz.
File metadata
- Download URL: prefgraph-0.5.17.tar.gz
- Upload date:
- Size: 396.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ee3ad2701a99fbee0b74ea9abd69d4352df768a7842f2b8e320ca04349ff84d
|
|
| MD5 |
f571ce207292599919311d0196f5b142
|
|
| BLAKE2b-256 |
ecaef328b7e14ba7036eec15f3d9f3251e6a86cffbc213b213a8dca74ca6b102
|
File details
Details for the file prefgraph-0.5.17-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: prefgraph-0.5.17-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15cf39a8c5a7ce6716ec786287ed69b22b229bfb9ecc4961d23d282d0a9fe443
|
|
| MD5 |
dce01f5e91ec2699a014d8634ae79de4
|
|
| BLAKE2b-256 |
a3d5dcfd3d062ee34b2799ba439f34068194ab8cd73167a1182630c8f3734629
|
File details
Details for the file prefgraph-0.5.17-cp313-cp313-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: prefgraph-0.5.17-cp313-cp313-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 5.5 MB
- Tags: CPython 3.13, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5fa0aa8dc5638bb1ef51bf8b7f57d690a47106c47d304b8f4c81a6232d94964
|
|
| MD5 |
fde2c1dc879e98bd72ffa5310dd3a276
|
|
| BLAKE2b-256 |
e830a5e3b6b37853a8e54cea159a0841cc5b9ae26128a31a9589cbbac94ba228
|
File details
Details for the file prefgraph-0.5.17-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: prefgraph-0.5.17-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db16f8425eff4f4d6243d34f39571353f0dca933ac791f1fa9afdba702e18823
|
|
| MD5 |
b7f2de7aa3407cbb5e6ef2b7ae31c869
|
|
| BLAKE2b-256 |
1f455ed024afe066a74fcec8f288cca147db82c65fc34b3f5e539d3f09d24e55
|
File details
Details for the file prefgraph-0.5.17-cp313-cp313-macosx_10_12_x86_64.whl.
File metadata
- Download URL: prefgraph-0.5.17-cp313-cp313-macosx_10_12_x86_64.whl
- Upload date:
- Size: 4.9 MB
- Tags: CPython 3.13, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6291cc404abe89fcad599408310f7aa1463eb9ea7f63739c71c096d908f5e32b
|
|
| MD5 |
cbabc6c6cd35f9788a71ccdebf68ea5f
|
|
| BLAKE2b-256 |
a7fe6981b419a8de55c428a302c0f9df1d07746c524461bd79e540c5408a1c73
|
File details
Details for the file prefgraph-0.5.17-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: prefgraph-0.5.17-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f44e1094ef6cdf228677e3853bc595d6cad637a2606874b426eff194685d79b8
|
|
| MD5 |
80373d2312eb444d65fc8ef199d6c362
|
|
| BLAKE2b-256 |
124966961bc6fdc64390c5fd878ac1663e26426bc62904d94068889116766c1e
|
File details
Details for the file prefgraph-0.5.17-cp312-cp312-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: prefgraph-0.5.17-cp312-cp312-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 5.5 MB
- Tags: CPython 3.12, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3e23fb454e2a1ac57793859d1075ccc033f0344c7131e0016dd26b314db596c
|
|
| MD5 |
7988a871a648155efe896b50325841cb
|
|
| BLAKE2b-256 |
185ce5fa2c92e477fd5c0cf8dadd87f492272dbf5596f06f2ecac496bcc1066c
|
File details
Details for the file prefgraph-0.5.17-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: prefgraph-0.5.17-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
218238e2d15d4073a457ca846bf31e8c630d5c671afb3454babbc2022a716500
|
|
| MD5 |
1c246eeb8692cc4a428c740c631d1493
|
|
| BLAKE2b-256 |
1f56d3426485e6af905663623fe4f6f9892a4b25bcb19ee0c5e16cf9952002fd
|
File details
Details for the file prefgraph-0.5.17-cp312-cp312-macosx_10_12_x86_64.whl.
File metadata
- Download URL: prefgraph-0.5.17-cp312-cp312-macosx_10_12_x86_64.whl
- Upload date:
- Size: 4.9 MB
- Tags: CPython 3.12, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83dbc61e6b6831a48e8c84c6b6afb11e0c14c7fa717e30993e7eb4020ddc1865
|
|
| MD5 |
7f25fa50ea5cadee4448c724ce1fdd48
|
|
| BLAKE2b-256 |
898bfc28fbc1bcbfffa7acf13f316b3cff80a1a44a00f94704fddfb5c7b620c3
|
File details
Details for the file prefgraph-0.5.17-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: prefgraph-0.5.17-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39b67d1246c2d47e7b2df47ccdf5d78d04596d0af9009cebfe4aa9826cc493e7
|
|
| MD5 |
947b7196740dcf76f1dec61edccd9548
|
|
| BLAKE2b-256 |
a0fe9bb599cc9142f73abcf726fe0b3286753eb8a741017c22122ef36c7c66a9
|
File details
Details for the file prefgraph-0.5.17-cp311-cp311-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: prefgraph-0.5.17-cp311-cp311-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 5.5 MB
- Tags: CPython 3.11, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a2068fda324dd9bf0d8b1da3bfbf75ef6a8f8c7330edf6188bc0e4133f86cb4
|
|
| MD5 |
19426c4acd31bfa5781d0d5f33389a08
|
|
| BLAKE2b-256 |
dd247b05cf368bcc0f9946c4a3d69684b875d988e3b65b10d949afa373e81cc7
|
File details
Details for the file prefgraph-0.5.17-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: prefgraph-0.5.17-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4b65f34bc43a4b7453bc786bb548336099b9d9522173e0870e43f8aed5cda6e
|
|
| MD5 |
d8fa288fb4b0f11449fd3d83f797e769
|
|
| BLAKE2b-256 |
de78a4458c16d0ee9160b2061593e001b804c623d551a958bd2d2edb1be65992
|
File details
Details for the file prefgraph-0.5.17-cp311-cp311-macosx_10_12_x86_64.whl.
File metadata
- Download URL: prefgraph-0.5.17-cp311-cp311-macosx_10_12_x86_64.whl
- Upload date:
- Size: 4.9 MB
- Tags: CPython 3.11, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db076b776834bca6124aa93b0e980e7ac667a6fa216d538734eb02f2759136a1
|
|
| MD5 |
8774368781ba8cd78fc8875b342652c1
|
|
| BLAKE2b-256 |
1f455eb9e04d2046e71fa6d67b9a1d0f41a89a32a02e15c69a27953b94bf5ec5
|
File details
Details for the file prefgraph-0.5.17-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: prefgraph-0.5.17-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0f149c66aae73d82e68d7845d5137e7ca5d955239a052d0001aefe43cc1d421
|
|
| MD5 |
68d3eb2f0f0b3b0203c7fc81e101dfdd
|
|
| BLAKE2b-256 |
3cab9574568d15276bc45d094f7cf7d8c52544aa56ff168cc928d8a1a10a454f
|
File details
Details for the file prefgraph-0.5.17-cp310-cp310-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: prefgraph-0.5.17-cp310-cp310-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 5.5 MB
- Tags: CPython 3.10, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b166c9608fac3d8252f083c861ec75b949c3114767ec3b8a02ae19df88ec4a2b
|
|
| MD5 |
63a896aa6253f9b81952080110fabc05
|
|
| BLAKE2b-256 |
af52f098ae2c8ff00d16053c88e2dc5eba4189888c240c2ee1de6b502e8b8f6f
|
File details
Details for the file prefgraph-0.5.17-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: prefgraph-0.5.17-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 4.4 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ebe8e207b354a8fc6fac8025e76ea46f44f7dff59bd68e633b500a68f3d77bd
|
|
| MD5 |
075d0701d575a12d7b7e7b5082b1cf72
|
|
| BLAKE2b-256 |
8868aa2f5065654d34bede1429a2c00c28537a7338824d57a13003f17de5bd18
|
File details
Details for the file prefgraph-0.5.17-cp310-cp310-macosx_10_12_x86_64.whl.
File metadata
- Download URL: prefgraph-0.5.17-cp310-cp310-macosx_10_12_x86_64.whl
- Upload date:
- Size: 4.9 MB
- Tags: CPython 3.10, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b83ae9cca02d3ea7b57f2c882b25e836327102a563b485eb6faebf3bfe8821d
|
|
| MD5 |
7e3bd1173bb429cb27cd3ae7a0af3152
|
|
| BLAKE2b-256 |
6c7169a379bc3a413c1a65fbd363c254ccc9c35135ac41e3c1a24393dbc90685
|