Implementations

A small Python library, mirrored by parity-tested JavaScript ports.

Every mechanism has a Python reference implementation in the mechanisms package, dependency-light (numpy only) and written to be read. The core deterministic mechanisms additionally have JavaScript ports that power the browser demos and are checked for numerical parity against Python in the test suite.

Python package

pip install -e ".[test]"
ModuleMechanism
scoring_rulesLog, Brier, spherical; pinball & interval; CRPS; energy score
local_scoringHyvärinen / m-local scoring; score matching, Fisher divergence
parimutuelPool betting; dynamic parimutuel market
nearest_the_pinContinuous / Monte-Carlo parimutuel; density pot-split, sliced scoring
lmsrLogarithmic market scoring rule
cmmGeneric convex cost-function market maker
ammConstant-product / constant-mean CFMMs; impermanent loss
pm_ammParadigm's pm-AMM (Gaussian score dynamics)
combinatorialLMSR over joint states; coherent marginals & conditionals
cdaContinuous double auction / limit order book
fbaFrequent batch auction (uniform-price clearing)
hybrid_marketHybrid CLOB + AMM matcher (complementary fills, AMM backstop)
perpPerpetual futures funding & liquidation
pdlpPerpetual demand lending pools; collateral, funding, liquidation
peer_predictionBayesian Truth Serum; output & correlated agreement
aggregationLinear / logarithmic / depth-trimmed opinion pools
calibrationReliability diagram, ECE, Brier decomposition
kellyKelly (log-optimal) sizing; wealth-weighted ensemble update
decision_marketConditional markets per action; ensembling-and-selection rules

JavaScript ports, tested against Python

The browser demos must not quietly drift from the library, so the JavaScript in docs/js/mechanisms.js is a faithful port of the Python reference and is verified against it: tests/test_js_parity.py runs each JS function in a Node subprocess (via tests/js_parity_runner.js) and asserts the result equals the Python implementation to floating-point tolerance. The parity tests skip cleanly if node is not installed, so Python-only CI is unaffected. (Pattern borrowed from microprediction/humpday, where JS optimizers are validated against their Python counterparts.)

# Python reference, JS port, and the parity check
pytest -q                          # full suite (Python + JS parity)
node tests/js_parity_runner.js lmsrPrices '[[10,-5,3],50]'

Run the tour

python examples/quickstart.py

Example simulations

Each demo in examples/ drives one mechanism through a short Monte-Carlo story and prints the result as a terminal chart (numpy-only, no plotting dependencies), so they run anywhere.

python examples/sim_lmsr.py

New implementation, port, or integration? Open an issue on microprediction/mechanisms.