larray-project / larray

N-dimensional labelled arrays in Python
https://larray.readthedocs.io/
GNU General Public License v3.0
8 stars 6 forks source link

implement argument to allow "some" difference between axes totals in ipfp #1004

Open gdementen opened 2 years ago

gdementen commented 2 years ago

Some users are complaining the following test in ipfp is too strict and annoying:

if str(axis_total) != str(axis0_total):
    raise ValueError(f"target sum along {axis} (axis {a.axes.index(axis)}) is different than target sum along "
                     f"{axes[0]} (axis {a.axes.index(axes[0])}): {axis_total} vs {axis0_total}")

The problem is that removing this test or allowing some threshold would make the total value alternate between each axis total during each iteration, systematically ending with the last axis sum, making it harder and possibly impossible to reach threshold.

In any case, it should be an immediate error if abs(axis_total - axis0_total) >= the_global_convergence_threshold, because that would make the algorithm always end at maxiter with a "bad" (unconverged) result.

One option would be to distribute the error (axis_total - axis0_total) on all labels of that axis. That should be an option though.