Rank-Preserving Calibration Documentation

Python application PyPI version Python versions

Welcome to the documentation for rank_preserving_calibration, a Python package for rank-preserving calibration of multiclass probabilities. This package implements algorithms to project probability matrices onto the intersection of row-simplex constraints and isotonic column marginals.

Key Features

  • Two main algorithms: Dykstra’s alternating projections (recommended) and ADMM optimization

  • Rank preservation: Maintains the original ordering of predictions while satisfying calibration constraints

  • Nearly isotonic calibration: Support for relaxed isotonic constraints with epsilon-slack or lambda-penalty approaches

  • Robust implementation: Numerically stable algorithms with comprehensive error handling

  • Comprehensive testing: Extensive test suite ensuring mathematical correctness

Quick Start

Install the package:

pip install rank_preserving_calibration

Basic usage:

import numpy as np
from rank_preserving_calibration import calibrate_dykstra

# Your probability matrix (N samples × J classes)
P = np.random.dirichlet([1, 1, 1], size=100)

# Target column sums
M = np.array([30.0, 40.0, 30.0])

# Calibrate probabilities
result = calibrate_dykstra(P, M)
calibrated_probs = result.Q

Contents

Development

Indices and tables