-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
I'm interested in using IPFN to solve 3D problems with 2D constraints. I simplified and adapted the example given in the readme, but for three sets of 2D constraints - see below. I've added a third constraint for the zx dimension. However, the algorithm does not give the correct solution.
# Seed data
m = np.random.rand(2, 4, 3)
# Constraints
xijp = np.array([[9, 17, 19, 7], [11, 13, 16, 8]]) # xy, 2x4
xpjk = np.array([[7, 9, 4], [8, 12, 10], [15, 12, 8], [5, 7, 3]]) # yz, 4x3
xipk = np.array([[10, 20], [20, 20], [10, 20]]) # zx, 3x2
# Create arguments
aggregates = [xijp, xpjk, xipk]
dimensions = [[0, 1], [1, 2], [2, 0]]
# Run IPF algorithm and compare slice
IPF = ipfn.ipfn(m, aggregates, dimensions, verbose=2)
m = IPF.iteration()
print('Slice should be:', xijp[0,0])
print('IPF gives:', m[0][0, 0, :].sum())
print('Target sum (xy):', xijp.sum())
print('IPF gives:', m[0].sum())
print('Convergence sequence:\n', m[-1].values.tolist())
This gives the following output and a conv value of 1:
ipfn converged: convergence_rate not updating or below rate_tolerance
Slice should be: 9
IPF gives: 5.20361253053332
Target sum (xy): 100
IPF gives: 60.0
Convergence sequence:
[[1.0], [1.0]]
Happy to contribute to coding the solution, although I couldn't pinpoint the source of the issue.
EDIT: Confirmed working with same set of constraints using R package MIPFP from here.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels