skillfed

ipfn

Iterative Proportional Fitting with N dimensions, for python

ipfn v1.4.4 102.2K downloads/30d#12,881 on PyPI106
Permissive license MIT DORMANT released

What it is and what it does

ipfn implements the iterative proportional fitting algorithm, a mathematical technique used in economics, demography, and social sciences to adjust a multidimensional contingency table so that its marginal sums (aggregates along one or more dimensions) match known target values. The package automatically selects between a fast numpy implementation and a slower but more user-friendly pandas implementation based on input type.

You provide an original array or dataframe, a list of target marginals, and the dimensions along which each marginal should apply. The algorithm iteratively rescales the table until convergence. It exposes control over iteration limits, convergence tolerance, and verbosity, returning either the fitted result, a success flag, or detailed iteration diagnostics depending on the verbosity level.

Use it for:

  • Adjust population survey data to match known demographic totals across multiple geographic and age categories.
  • Rescale economic input-output tables to match independently estimated row and column sums.
  • Balance contingency tables in social science research when marginal distributions are known but cell values are uncertain.
  • Calibrate multidimensional traffic or flow models to match observed aggregate counts on subsets of dimensions.
  • Prepare synthetic microdata by adjusting initial samples to match target distributions on multiple cross-tabulated variables.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Iterative proportional fitting algorithm that adjusts multidimensional arrays or dataframes so their aggregates along specified dimensions match target marginals, with both fast numpy and slower pandas implementations.

Yes, if you need iterative proportional fitting and can tolerate dormancy. The package is stable and low-friction to install, with no known vulnerabilities and a permissive MIT license. However, expect no active maintenance—last release was 2021-12-30. Use it for well-understood IPF problems; do not expect bug fixes or updates if you encounter edge cases.

Install

ipfn on PyPI

pip

pip install ipfn

uv

uv add ipfn

poetry

poetry add ipfn

Installing ipfn

Before you install

Low friction install with only pandas and numpy as runtime dependencies. Package is dormant—last release was 2021-12-30 and last commit 2024-05-10, so expect no active maintenance or bug fixes.

License in practice

MIT license is permissive, allowing commercial and private use with minimal restrictions; you may use and modify freely provided you retain the license notice.

Quickstart

import numpy as np
from ipfn import ipfn

m = np.array([[40, 30, 20, 10], [35, 50, 100, 75], [30, 80, 70, 120], [20, 30, 40, 50]])
xip = np.array([150, 300, 400, 150])
xpj = np.array([200, 300, 400, 100])

IPF = ipfn.ipfn(m, [xip, xpj], [[0], [1]], convergence_rate=1e-6)
m_fitted = IPF.iteration()
print(m_fitted)

Verify before relying

  • Whether the algorithm converges reliably on all input types and dimensions, or if certain edge cases are known to fail.
  • Performance characteristics on large multidimensional arrays relative to the R ipfp package it claims equivalence with.
  • Whether dormancy means the package is stable-complete or abandoned and no longer maintained.

Package facts

License MIT (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies 2 — pandas, numpy
Maintenance dormant — 1,688 days since the last release
Last repo commit
First released
Downloads 102,246/month — #12,881 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: ipfn-1.4.4-py2.py3-none-any.whl

Keywords: iterative, proportional, fitting, ipfp, biproportional, ras, raking, scaling

Development Status :: 4 - BetaIntended Audience :: Science/ResearchLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Topic :: Software Development :: Build Tools

Tags

iterative proportional fittingipf algorithm pythonadjust marginals multidimensionalraking scaling algorithmbiproportional fittingcontingency table adjustmentnumpy pandas fitting
contingency-tablesstatistical-adjustment

More Build Tools packages