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 Matrix

rows (AequilibraeData): Vector object with data for row totals

row_field (str): Field name that contains the data for the row totals

columns (AequilibraeData): Vector object with data for column totals

column_field (str): Field name that contains the data for the column totals

parameters (str, Optional): Convergence parameters. Defaults to those in the parameter file

nan_as_zero (bool, Optional): If Nan values should be treated as zero. Defaults to True

Results:

output (AequilibraeMatrix): Result Matrix

report (list): Iteration and convergence report

error (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

fit()[source]#

Runs the IPF instance problem to adjust the matrix

Resulting matrix is the output class member

save_to_project(name: str, file_name: str, project=None) MatrixRecord[source]#

Saves the matrix output to the project file

Arguments:

name (str): Name of the desired matrix record

file_name (str): Name for the matrix file name. AEM and OMX supported

project (Project, Optional): Project we want to save the results to. Defaults to the active project