Skip to content

README algorithm examples #25

@edyhsgr

Description

@edyhsgr

I think the 3D algorithm examples aren't set to fit on all dimensions. I checked the numpy version and found it wasn't fitting to 'xipk'. Proposed code with commented (##) revisions below. I also compared to results from https://github.com/AppliedDemogToolbox/IPF_R (Excel example and application of the R code).

from ipfn import ipfn
import numpy as np
import pandas as pd

m = np.zeros((2,4,3))
m[0,0,0] = 1
m[0,0,1] = 2
m[0,0,2] = 1
m[0,1,0] = 3
m[0,1,1] = 5
m[0,1,2] = 5
m[0,2,0] = 6
m[0,2,1] = 2
m[0,2,2] = 2
m[0,3,0] = 1
m[0,3,1] = 7
m[0,3,2] = 2
m[1,0,0] = 5
m[1,0,1] = 4
m[1,0,2] = 2
m[1,1,0] = 5
m[1,1,1] = 5
m[1,1,2] = 5
m[1,2,0] = 3
m[1,2,1] = 8
m[1,2,2] = 7
m[1,3,0] = 2
m[1,3,1] = 7
m[1,3,2] = 6

xipp = np.array([52, 48])
xpjp = np.array([20, 30, 35, 15])
xppk = np.array([35, 40, 25])
xijp = np.array([[9, 17, 19, 7], [11, 13, 16, 8]])
xpjk = np.array([[7, 9, 4], [8, 12, 10], [15, 12, 8], [5, 7, 3]])
xipk = np.array([[22, 20, 10], [13, 20, 15]]) ##Added line

m[0,:,:].sum() == xipp[0]
m[1,:,:].sum() == xipp[1]

aggregates = [xipp, xpjp, xppk, xijp, xpjk, xipk]
dimensions = [[0], [1], [2], [0, 1], [1, 2], [0, 2]] ##Revised line

IPF = ipfn.ipfn(m, aggregates, dimensions)
m = IPF.iteration()
print(xijp[0,0])
print(m[0, 0, :].sum())

print(m)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions