def test_fit(self): # The IPF per se args = { "matrix": matrix, "rows": row_vector, "row_field": "rows", "columns": column_vector, "column_field": "columns", "nan_as_zero": False, } fratar = Ipf(**args) fratar.fit() result = fratar.output if (np.nansum(result.matrix_view) - np.nansum(row_vector.data["rows"])) > 0.001: print(fratar.gap) for f in fratar.report: print(f) self.fail("Ipf did not converge") if fratar.gap > fratar.parameters["convergence level"]: print(fratar.gap) for f in fratar.report: print(f) self.fail("Ipf did not converge")
def test_fit(self): # The IPF per se args = { 'matrix': matrix, 'rows': row_vector, 'row_field': 'rows', 'columns': column_vector, 'column_field': 'columns', 'nan_as_zero': False } fratar = Ipf(**args) fratar.fit() result = fratar.output if (np.nansum(result.matrix_view) - np.nansum(row_vector.data['rows'])) > 0.001: print fratar.gap for f in fratar.report: print f self.fail('Ipf did not converge') if fratar.gap > fratar.parameters['convergence level']: print fratar.gap for f in fratar.report: print f self.fail('Ipf did not converge')
class IpfProcedure(WorkerThread): def __init__(self, parentThread, seed, rows, columns): WorkerThread.__init__(self, parentThread) self.ipf = Ipf(seed, rows, columns) self.error = None def doWork(self): self.ipf.fit() self.emit(SIGNAL("finished_threaded_procedure( PyQt_PyObject )"),0)
class IpfProcedure(WorkerThread): def __init__(self, parentThread, **kwargs): WorkerThread.__init__(self, parentThread) self.ipf = Ipf(**kwargs) self.report = None def doWork(self): self.ipf.fit() self.report = self.ipf.report self.emit(SIGNAL("finished_threaded_procedure( PyQt_PyObject )"),0) self.emit(SIGNAL("finished_threaded_procedure( PyQt_PyObject )"),0)
class IpfProcedure(WorkerThread): def __init__(self, parentThread, **kwargs): WorkerThread.__init__(self, parentThread) self.ipf = Ipf(**kwargs) self.error = None self.report = [] def doWork(self): try: self.ipf.fit() self.report = self.ipf.report except ValueError as e: self.error = e self.finished_threaded_procedure.emit(0)
def test_fit(self): # The IPF per se args = {'matrix': matrix, 'rows': row_vector, 'row_field': 'rows', 'columns': column_vector, 'column_field': 'columns', 'nan_as_zero': False} fratar = Ipf(**args) fratar.fit() result = fratar.output if (np.nansum(result.matrix_view) - np.nansum(row_vector.data['rows'])) > 0.001: print (fratar.gap) for f in fratar.report: print (f) self.fail('Ipf did not converge') if fratar.gap > fratar.parameters['convergence level']: print (fratar.gap) for f in fratar.report: print (f) self.fail('Ipf did not converge')
def __init__(self, parentThread, **kwargs): WorkerThread.__init__(self, parentThread) self.ipf = Ipf(**kwargs) self.error = None self.report = []
def __init__(self, parentThread, seed, rows, columns): WorkerThread.__init__(self, parentThread) self.ipf = Ipf(seed, rows, columns) self.error = None
# %% md ### We now run IPF for the future vectors # %% args = { "matrix": demand, "rows": vectors, "columns": vectors, "column_field": "destinations", "row_field": "origins", "nan_as_zero": True, } ipf = Ipf(**args) ipf.fit() ipf.save_to_project(name="demand_ipfd", file_name="demand_ipfd.aem") ipf.save_to_project(name="demand_ipfd_omx", file_name="demand_ipfd.omx") # %% proj_matrices.list() # %% md ## Future traffic assignment # %%
def test_fit(self): proj = Project() proj.open(self.proj_dir) mats = proj.matrices mats.update_database() seed = mats.get_matrix('SiouxFalls_omx') seed.computational_view('matrix') # row vector args = { "entries": seed.zones, "field_names": ["rows"], "data_types": [np.float64], "memory_mode": True } row_vector = AequilibraeData() row_vector.create_empty(**args) row_vector.rows[:] = np.random.rand(seed.zones)[:] * 1000 row_vector.index[:] = seed.index[:] # column vector args["field_names"] = ["columns"] column_vector = AequilibraeData() column_vector.create_empty(**args) column_vector.columns[:] = np.random.rand(seed.zones)[:] * 1000 column_vector.index[:] = seed.index[:] # balance vectors column_vector.columns[:] = column_vector.columns[:] * ( row_vector.rows.sum() / column_vector.columns.sum()) # The IPF per se args = { "matrix": seed, "rows": row_vector, "row_field": "rows", "columns": column_vector, "column_field": "columns", "nan_as_zero": False, } with self.assertRaises(TypeError): fratar = Ipf(data='test', test='data') fratar.fit() with self.assertRaises(ValueError): fratar = Ipf(**args) fratar.parameters = ['test'] fratar.fit() fratar = Ipf(**args) fratar.fit() result = fratar.output self.assertAlmostEqual(np.nansum(result.matrix_view), np.nansum(row_vector.data["rows"]), 4, "Ipf did not converge") self.assertGreater(fratar.parameters["convergence level"], fratar.gap, "Ipf did not converge") mr = fratar.save_to_project('my_matrix_ipf', 'my_matrix_ipf.aem') self.assertTrue( os.path.isfile(os.path.join(mats.fldr, 'my_matrix_ipf.aem')), 'Did not save file to the appropriate place') self.assertEqual(mr.procedure_id, fratar.procedure_id, 'procedure ID saved wrong') proj.close()