This repository provides a lightweight Python implementation for fitting signals with a sum of exponentials using the Variable Projection (VARPRO) approach. The target model is a multi-exponential curve with an optional constant offset, i.e., a linear combination of exponential basis functions where the decay rates (or time constants) are nonlinear parameters, while amplitudes and offset are linear parameters. VARPRO exploits this separable structure: for any fixed set of decay rates, the linear coefficients are solved by a (weighted) linear least-squares problem, and only the nonlinear parameters are optimized iteratively. In this implementation, the weighted linear subproblem is solved via SVD for numerical robustness, and SciPy’s least_squares is used for the outer nonlinear optimization. The result is a practical fitter that is often more stable than “all-parameters-at-once” nonlinear least squares, especially when amplitudes are strongly correlated or when the number of exponentials is moderate.
- Python 3.x
numpyscipy
import numpy as np
from varpro4multiexps import VarPro4MultiExponetial
# Example data (synthetic)
t = np.linspace(0.0, 0.1, 10001)
y = 0.10*np.exp(-1250*t) + 0.25*np.exp(-1000*t) + 0.45*np.exp(-400*t) + 0.03
y = y + np.random.normal(0.0, 1e-6, size=t.size)
# Fit: initial_guess is a list of time constants (must be positive)
solver = VarPro4MultiExponetial(t, y)
solver.verbose = 1 # (optional) SciPy verbosity
exps = solver.fit(initial_guess=[100, 1000, 10000])
print("Coefficients:", exps.Coefficients) # amplitudes
print("TimeConstants:", exps.TimeConstants) # tau (positive)
print("Offset:", exps.Offset) # constant term
# Evaluate fitted curve:
yhat = exps(t)You can pass weight= to emphasize/de-emphasize samples. Optimization settings (bounds, tolerances, loss, etc.) are managed via SolverOption, optionally loadable from an XML file (solver_option_path).
Consider measurements
where
VARPRO eliminates
- G. H. Golub and V. Pereyra, “The differentiation of pseudoinverses and nonlinear least squares problems whose variables separate,” SIAM Journal on Numerical Analysis, 1973.
- L. Kaufman, “A variable projection method for solving separable nonlinear least squares problems,” Computational Optimization and Applications / related early VARPRO developments, 1970s.
- D. P. O’Leary and B. W. Rust, “Variable Projection for Nonlinear Least Squares Problems,” Computational Optimization and Applications, 2013 (robust formulations, constraints, Jacobians).
- (Optional background) Reviews on separable nonlinear least squares / variable projection applications across exponential fitting and related inverse problems.