Skip to main content

Revealed preference analysis at scale — rationality scores, efficiency indices, and utility recovery. Rust engine, Python interface.

Project description

PyRevealed

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

PyPI Documentation License: MIT

pip install pyrevealed

Quick Example

Score how consistently each user's choices align with rational utility maximization. Paste and run:

from pyrevealed.datasets import load_demo
from pyrevealed.engine import Engine

users = load_demo()  # 100 synthetic consumers, no download needed
engine = Engine(metrics=["garp", "ccei", "mpi", "harp", "hm"])
results = engine.analyze_arrays(users)

for r in results[:5]:
    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. Use them for fraud detection, user segmentation, A/B testing, churn prediction, or personalization.

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
Noise 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 10,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) 30+ algorithms
Input list[(prices, quantities)] BehaviorLog

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

from pyrevealed import BehaviorLog, validate_consistency, compute_integrity_score
session = BehaviorLog(cost_vectors=prices, action_vectors=quantities)
garp = validate_consistency(session)       # GARPResult with violation cycles, matrices
ccei = compute_integrity_score(session)    # AEIResult with binary search details

4 Choice Categories

                Test (bool)     Score (0-1)     Recover (vector)  Structure (bool)
Budget          GARP, WARP      CCEI, MPI, HM   Utility, CV/EV    HARP, Separability
Discrete        SARP, RUM LP    HM (menu)        Ordinal utility   Congruence
Production      Prod GARP       Prod CCEI        Tech efficiency   Cost minimization
Intertemporal   Exp discount    —                Discount delta    Quasi-hyperbolic
Category Input format Example domain
Budget (prices T×K, quantities T×K) E-commerce, grocery, food delivery
Discrete (menus, choices) or (menus, frequencies) Surveys, A/B tests, recommendations
Production (input_p, input_q, output_p, output_q) Supply chain, manufacturing
Intertemporal (amounts, dates, chosen) Subscriptions, savings, loyalty

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.

Users Metrics Time Throughput
1,000 5 0.1s 10,000/s
10,000 5 2s 5,000/s
100,000 5 20s 5,000/s

18-100x faster than pure Python. Memory stays bounded via streaming chunks.

Documentation

Full docs — tutorials, theory, API reference, application examples.

License

MIT

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

pyrevealed-0.5.3.tar.gz (322.3 kB view details)

Uploaded Source

Built Distributions

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

pyrevealed-0.5.3-cp313-cp313-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.13Windows x86-64

pyrevealed-0.5.3-cp313-cp313-manylinux_2_28_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

pyrevealed-0.5.3-cp313-cp313-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyrevealed-0.5.3-cp313-cp313-macosx_10_12_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

pyrevealed-0.5.3-cp312-cp312-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.12Windows x86-64

pyrevealed-0.5.3-cp312-cp312-manylinux_2_28_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

pyrevealed-0.5.3-cp312-cp312-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyrevealed-0.5.3-cp312-cp312-macosx_10_12_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

pyrevealed-0.5.3-cp311-cp311-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.11Windows x86-64

pyrevealed-0.5.3-cp311-cp311-manylinux_2_28_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

pyrevealed-0.5.3-cp311-cp311-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyrevealed-0.5.3-cp311-cp311-macosx_10_12_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.11macOS 10.12+ x86-64

pyrevealed-0.5.3-cp310-cp310-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.10Windows x86-64

pyrevealed-0.5.3-cp310-cp310-manylinux_2_28_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

pyrevealed-0.5.3-cp310-cp310-macosx_11_0_arm64.whl (2.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyrevealed-0.5.3-cp310-cp310-macosx_10_12_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.10macOS 10.12+ x86-64

File details

Details for the file pyrevealed-0.5.3.tar.gz.

File metadata

  • Download URL: pyrevealed-0.5.3.tar.gz
  • Upload date:
  • Size: 322.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for pyrevealed-0.5.3.tar.gz
Algorithm Hash digest
SHA256 ce77a3bc570e8c9027faf91d92372a8bcaf8d26d74f3abf5e6c9ea6723c05e11
MD5 f383b7f2c5cb1a20ae11a2d988018627
BLAKE2b-256 290614c36c7fe7755f9325da878554b7c52dc9d8818c36c388d29031077117d9

See more details on using hashes here.

File details

Details for the file pyrevealed-0.5.3-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for pyrevealed-0.5.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 015688fdb4305e78a3e3b45fc0c17d79535d3b31bbdd37193966805dc8794a73
MD5 f5a3a2cacb1be96dfc9fadf7c55bdbaa
BLAKE2b-256 5922ad2c53608902c3ffd05ab113d5bfb82143de83b977ca2710e468d20e9851

See more details on using hashes here.

File details

Details for the file pyrevealed-0.5.3-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyrevealed-0.5.3-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 97fbbf00084c8e47a581e58bf2667b959bcfd334ed2433c5142f2f236f7a0e46
MD5 1a54873acb47ed75bf63bbfa007ecfcb
BLAKE2b-256 6c787a5f4a0e64ec75e5e1083a1a8f01429e9cc7cbddc5fb939921ac8b98e029

See more details on using hashes here.

File details

Details for the file pyrevealed-0.5.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyrevealed-0.5.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d49856b7d16c6aeafe0fd22dc6f140786937802c2240d84478a9070f2cc4e22d
MD5 c7d60da16d5599b9b0d5a1e511c1b0ea
BLAKE2b-256 1b13e78973b9c7b67d1b72095d49a17bf3044086f46c6810fb9b91d30ae5fec9

See more details on using hashes here.

File details

Details for the file pyrevealed-0.5.3-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyrevealed-0.5.3-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8f4fd64ea1cf627a41b3ba96a55f684ee5170b6d9fb8b87a7e91e735ee8d6565
MD5 325123801a77e700318c0f8d87e52265
BLAKE2b-256 9d3270cf2bd1f3560cffaffa988d77176b7ef7296a1de6073f20afa948232ae7

See more details on using hashes here.

File details

Details for the file pyrevealed-0.5.3-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for pyrevealed-0.5.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 715bba77ab889a2ac16389766ed8f899a34cd6d89feac8cef146a520b8d2ad54
MD5 b80680e64fd6ed79202885780bc69446
BLAKE2b-256 23b7236a14f16b4478fd565ebd31d7a9004ba8bd797d93e217dba235ba61953c

See more details on using hashes here.

File details

Details for the file pyrevealed-0.5.3-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyrevealed-0.5.3-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8afcb521ebcd7a4e0d81b4eeec2b3392308a816004ea287d4e4f360647da2d45
MD5 b5bcf2a74811c40fc2a0a5b5f46eba8f
BLAKE2b-256 5fe80ace4d27e36520a00cfd7bd1c06e81e72fc820285fa8e3936a49ae08a878

See more details on using hashes here.

File details

Details for the file pyrevealed-0.5.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyrevealed-0.5.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 faa67000d3f8930a772fe34b76f8bfaa250f97b9eefb3fbf199b322fb44ef47e
MD5 cf51273a3a176c0c1a066886c41e05e7
BLAKE2b-256 2c9a4c7c409f0b43429f8f85e6887deac70abd3bb77bc066a497fa861e20b164

See more details on using hashes here.

File details

Details for the file pyrevealed-0.5.3-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyrevealed-0.5.3-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 aad78cf5164fd80fcd65da0a4a23676fcf418314e8840f35850fc2bacb4c5330
MD5 7ac90fd8e281f864b962f598ee28319a
BLAKE2b-256 c5bd7694d4839d7447e6bffbda4408bf2ac3b9271497c14d2705950cdc0d43d5

See more details on using hashes here.

File details

Details for the file pyrevealed-0.5.3-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for pyrevealed-0.5.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 66af874ec683ffb964b757e81ad0b8cb452b38a378175215f27b132ccdd79321
MD5 b7b03d324feaef8efc54cd01b300126f
BLAKE2b-256 8096e8170ff6b69612bc48223f8c56e6d1d1799678c7b2917dbda2af453f5cbe

See more details on using hashes here.

File details

Details for the file pyrevealed-0.5.3-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyrevealed-0.5.3-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2aa48dfa7a85f93525b908b1c15805614a672108cab7ee204677c8726ca81ff0
MD5 6f783f3ddc6a7b08231ffeca34407ca1
BLAKE2b-256 c05f035b66845ad19ef91b7510d9497b83c5fdc1ef23e10c971815cc934a8f71

See more details on using hashes here.

File details

Details for the file pyrevealed-0.5.3-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyrevealed-0.5.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c49773a53fb73c3c602f43023764aeb066e75e16c8428b856a493506985e79fd
MD5 adb196d2e91dfa4dc86750f66d459d94
BLAKE2b-256 419bffa4c195ddb7f846b5cf1fb002094e03615e8738ef1c8884e5acce582b31

See more details on using hashes here.

File details

Details for the file pyrevealed-0.5.3-cp311-cp311-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyrevealed-0.5.3-cp311-cp311-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d6a67f9a1e643782dc15f2da36664231a48503279cd7a581d543bb10d36651a8
MD5 8b1b7c20630608095dd04b259e3f9f10
BLAKE2b-256 4fd9eab741a20b1f39a9d688973c88044201a7211c1f6d26367f004d72ea8e3d

See more details on using hashes here.

File details

Details for the file pyrevealed-0.5.3-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for pyrevealed-0.5.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 acf332a94d790c608dd813c003495e6a5a24f36b74be3eab8e2ed76b56f44f9d
MD5 0ae99529dd475fcd0744ca55f212c512
BLAKE2b-256 9f985c4fa42eed662bc8edcf915d2315d3b3e3719e1bc0175ef1d54fee5dfb5c

See more details on using hashes here.

File details

Details for the file pyrevealed-0.5.3-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyrevealed-0.5.3-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ecdac3752ae2210b92cef79ea72a190e9712a6af393ef4a14fa45c0ce4ebd2bd
MD5 acfeeddbfff9e8da79baab4b933caff2
BLAKE2b-256 b2a7b13853dfd0b8ca38ca6ec8852677986534457940109600d531b846a7aa97

See more details on using hashes here.

File details

Details for the file pyrevealed-0.5.3-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyrevealed-0.5.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4e30a57edf6fc530e1844addfc53262dc6ccf3ee51cc471b32339b828c93ca3f
MD5 25c639d2715eab93cff248fd91d296f5
BLAKE2b-256 e3923a61bb74e5a190c793edb936ba1879c5e1f73e21fcfa429f14a9af06cbeb

See more details on using hashes here.

File details

Details for the file pyrevealed-0.5.3-cp310-cp310-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyrevealed-0.5.3-cp310-cp310-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 701d5af6190bdd16c6bd48c265a663e084838a76402fc127df7538dcb54501e0
MD5 06a826911da57d5445841669c142eb8f
BLAKE2b-256 6b9f030847de1141b9461e7e5b19d9c16353da1b93abe3f8d4bece968bd6433a

See more details on using hashes here.

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