aequilibrae.distribution.Ipf#
- class aequilibrae.distribution.Ipf(project=None, **kwargs)[source]#
Iterative proportional fitting procedure
>>> from aequilibrae import Project >>> from aequilibrae.distribution import Ipf >>> from aequilibrae.matrix import AequilibraeMatrix, AequilibraeData >>> project = Project.from_path("/tmp/test_project_ipf") >>> matrix = AequilibraeMatrix() # Here we can create from OMX or load from an AequilibraE matrix. >>> matrix.load('/tmp/test_project/matrices/demand.omx') >>> matrix.computational_view() >>> args = {"entries": matrix.zones, "field_names": ["productions", "attractions"], ... "data_types": [np.float64, np.float64], "memory_mode": True} >>> vectors = AequilibraeData() >>> vectors.create_empty(**args) >>> vectors.productions[:] = matrix.rows()[:] >>> vectors.attractions[:] = matrix.columns()[:] # We assume that the indices would be sorted and that they would match the matrix indices >>> vectors.index[:] = matrix.index[:] >>> args = { ... "matrix": matrix, "rows": vectors, "row_field": "productions", "columns": vectors, ... "column_field": "attractions", "nan_as_zero": False} >>> fratar = Ipf(**args) >>> fratar.fit() # We can get back to our OMX matrix in the end >>> fratar.output.export("/tmp/to_omx_output.omx") >>> fratar.output.export("/tmp/to_aem_output.aem")
- __init__(project=None, **kwargs)[source]#
Instantiates the Ipf problem
- Arguments:
matrix (
AequilibraeMatrix
): Seed Matrixrows (
AequilibraeData
): Vector object with data for row totalsrow_field (
str
): Field name that contains the data for the row totalscolumns (
AequilibraeData
): Vector object with data for column totalscolumn_field (
str
): Field name that contains the data for the column totalsparameters (
str
, optional): Convergence parameters. Defaults to those in the parameter filenan_as_zero (
bool
, optional): If Nan values should be treated as zero. Defaults to True- Results:
output (
AequilibraeMatrix
): Result Matrixreport (
list
): Iteration and convergence reporterror (
str
): Error description
Methods
__init__
([project])Instantiates the Ipf problem
fit
()Runs the IPF instance problem to adjust the matrix
save_to_project
(name, file_name[, project])Saves the matrix output to the project file