aequilibrae.distribution.Ipf#

class aequilibrae.distribution.Ipf(project=None, **kwargs)[source]#

Iterative proportional fitting procedure

>>> from aequilibrae.distribution import Ipf

>>> project = create_example(project_path)

>>> matrix = project.matrices.get_matrix("demand_omx")
>>> matrix.computational_view()

>>> vectors = pd.DataFrame({"productions":np.zeros(matrix.zones), "attractions":np.zeros(matrix.zones)}, index=matrix.index)

>>> vectors["productions"] = matrix.rows()
>>> vectors["attractions"] = matrix.columns()

>>> ipf_args = {"matrix": matrix,
...             "vectors": vectors,
...             "row_field": "productions",
...             "column_field": "attractions",
...             "nan_as_zero": False}

>>> fratar = Ipf(**ipf_args)
>>> fratar.fit()

# We can get back to our OMX matrix in the end
>>> fratar.output.export(os.path.join(my_folder_path, "to_omx_output.omx"))
__init__(project=None, **kwargs)[source]#

Instantiates the IPF problem

Arguments:

matrix (AequilibraeMatrix): Seed Matrix

vectors (pd.DataFrame): Dataframe with the vectors to be used for the IPF

row_field (str): Field name that contains the data for the row 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