SANDAG / ipfn

Iterative Proportional Fitting for Python with N dimensions
MIT License
0 stars 0 forks source link

[FEATURE] Handle allowable 0s in marginal controls #4

Closed GregorSchroeder closed 5 hours ago

GregorSchroeder commented 6 hours ago

Is your feature request related to a problem? Please describe. When the user passes aggregates to the ipfn class that contain any 0-valued elements the algorithm performs as expected but prints a warning to the console. This can become excessive when running many IPFs.

ipfn\ipfn.py:146: RuntimeWarning: invalid value encountered in scalar divide if abs(m_ijk / ori_ijk - 1) > max_conv:

Describe the solution you'd like

import numpy as np
from ipfn import ipfn

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

aggregates = [xip, xpj]
dimensions = [[0], [1]]

IPF = ipfn.ipfn(m, aggregates, dimensions, convergence_rate=1e-6, verbose=0)
m = IPF.iteration()

If verbose=0 the RuntimeWarning should not be printed to the console. This will require edits to lines 146 and 246 in ipfn/ipfn.py.

Describe alternatives you've considered Could potentially implement a messages flag separately from the verbose input but many other libraries use verbose to suppress messages printed to the console and/or a log file.

Additional context These messages when printed to the console or a log file can become excessive when running many IPFs.

GregorSchroeder commented 5 hours ago

First commit requires Python > 3.11 which is not necessarily a reasonable requirement. Change to solution that allows for older version of Python.