Skip to content

nmyinger/power-laws

Repository files navigation

Power Law Lab

A practical toolkit to detect, test, and reason about power-law environments.

This repo helps answer one question:

Are my outcomes governed by a power law, or do they just look that way?

It is designed for founders, investors, and researchers who care about asymmetric payoffs, winner-take-most dynamics, and convex bets.


What this tool does

Power Law Lab has two core parts:

1. Outcome analysis

Given a dataset of outcomes (profits, views, ROI, returns, etc.), it:

  • Measures concentration (top 1%, top 10%, Gini, Herfindahl)
  • Fits tail models:
    • Power law
    • Lognormal
    • Exponential
  • Automatically finds a tail cutoff (xmin)
  • Produces visual diagnostics (log-log CCDF)
  • Outputs a clear verdict:
    • powerlaw_tail_likely
    • heavy_tail_likely
    • heavy_tail_likely_ambiguous
    • unknown

This tells you what kind of world you are operating in.


2. Synthetic data generator

A companion script lets you create controlled datasets:

  • Pure power law
  • Lognormal
  • Normal (thin tail)
  • Exponential
  • Blended systems (e.g. 70% lognormal + 30% power law)

This is useful for:

  • Learning how tails behave
  • Testing false positives
  • Stress-testing intuition
  • Teaching others

File structure

.
├── powerlaw_lab.py          # Main analysis + bet scoring tool
├── make_synthetic_input.py  # Synthetic data generator
├── README.md
└── LICENSE

Installation

Python 3.9+

pip install -r requirements-excel.txt

Optional (for Excel support):

pip install openpyxl

Input format

Default expected format

CSV or Excel file with:

unit_id,outcome
1,3.24
2,0.91
3,145.7
...
  • unit_id can be anything (client, post, deal, strategy)
  • outcome must be numeric and positive

Column names can be overridden via CLI flags.


Analyze real or synthetic data

Basic usage

python powerlaw_lab.py analyze data.csv --auto_xmin

Outputs:

  • summary.json
  • ccdf_loglog.png
  • hist_logx.png

With explicit columns

python powerlaw_lab.py analyze data.xlsx \
  --sheet Sheet1 \
  --value_col profit \
  --unit_col deal_id \
  --auto_xmin

Interpreting results

Key signals that indicate a power-law environment:

  • Top 1% contributes 20–40%+ of total outcome
  • Gini coefficient > ~0.5
  • Power law beats exponential clearly
  • Tail size is large and stable across runs
  • CCDF looks linear on log-log axes above xmin

This is not proof. It is a decision tool.


Generate synthetic datasets

Pure power law

python make_synthetic_input.py generate \
  --dist powerlaw \
  --n 20000 \
  --params xmin=1,alpha=2.2 \
  --out synthetic_powerlaw.csv

Pure lognormal

python make_synthetic_input.py generate \
  --dist lognormal \
  --params mu=0,sigma=1.0 \
  --out synthetic_lognormal.csv

Blend systems (shift slider)

python make_synthetic_input.py blend \
  --dist_a lognormal --params_a mu=0,sigma=0.8 \
  --dist_b powerlaw  --params_b xmin=1,alpha=2.2 \
  --w 0.7 \
  --out synthetic_shift.csv

w controls the mix:

  • w = 1.0 → pure A
  • w = 0.0 → pure B

Bet scoring (optional)

There is also an interactive bet scoring tool:

python powerlaw_lab.py score_bets

You score ideas 0–2 on:

  • Upside ceiling
  • Downside cap
  • Leverage
  • Feedback speed
  • Distribution edge

Output is a ranked CSV.

This helps you allocate attention to convex bets.


What this tool is NOT

  • It does not prove universal laws.
  • It does not predict individual outcomes.
  • It does not replace judgment.

It helps you avoid the biggest mistake:

Treating a lognormal or normal world like a power-law world.


When to use this

This tool is useful if you are working on:

  • Startups
  • Content distribution
  • Investing
  • Trading strategies
  • Product usage
  • Deal sourcing
  • Any system with rare big wins

License

MIT License (recommended)

  • Free to use
  • Free to modify
  • Free for commercial use
  • Attribution required
  • No warranty

See LICENSE file.


Philosophy

Power laws change how you allocate time, capital, and risk.

This tool exists to make that visible.

Use it to take fewer bets, but bigger ones.


---

About

Here is an analysis on power laws.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages