From 4e7f24c98a44e82a3ff1c9c8e156cf6d7ad1aca0 Mon Sep 17 00:00:00 2001 From: Sam Maurer Date: Mon, 15 Jul 2019 18:55:33 -0700 Subject: [PATCH 1/3] Applying changes from 0.2.dev7 --- tests/test_regression.py | 20 ++++++++++++++++++++ urbansim_templates/models/regression.py | 17 ++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/tests/test_regression.py b/tests/test_regression.py index 1220395..bc8e03d 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -64,3 +64,23 @@ def test_simulation(orca_session): assert orca.get_table('obs').to_frame()['a_predicted'].equals(m.predicted_values) + +def test_out_transform(orca_session): + """ + Test transformation of the predicted values. + + """ + modelmanager.initialize() + + m = OLSRegressionStep() + m.tables = 'obs' + m.model_expression = 'a ~ b' + m.fit() + + m.out_column = 'a_predicted' + m.out_transform = 'np.exp' + m.run() + + predictions = m.predicted_values.apply(np.exp) + + assert orca.get_table('obs').to_frame()['a_predicted'].equals(predictions) diff --git a/urbansim_templates/models/regression.py b/urbansim_templates/models/regression.py index ce2ed49..8367f23 100644 --- a/urbansim_templates/models/regression.py +++ b/urbansim_templates/models/regression.py @@ -1,5 +1,6 @@ from __future__ import print_function +import math import numpy as np import pandas as pd from datetime import datetime as dt @@ -69,11 +70,13 @@ class OLSRegressionStep(TemplateStep): side variable from the model expression will be used. Replaces the `out_fname` argument in UrbanSim. - out_transform : callable, optional - Transformation to apply to the predicted values, for example to reverse a - transformation of the left-hand-side variable in the model expression. Replaces - the `ytransform` argument in UrbanSim. - + out_transform : str, optional + Element-wise transformation to apply to the predicted values, for example to + reverse a transformation of the left-hand-side variable in the model expression. + This should be provided as a string containing a function name. Supports anything + from NumPy or Python's built-in math library, for example 'np.exp' or + 'math.floor'. Replaces the `ytransform` argument in UrbanSim. + out_filters : str or list of str, optional Filters to apply to the data before simulation. If not provided, no filters will be applied. Replaces the `predict_filters` argument in UrbanSim. @@ -168,7 +171,7 @@ def fit(self): """ self.model = RegressionModel(model_expression=self.model_expression, fit_filters=self.filters, predict_filters=self.out_filters, - ytransform=self.out_transform, name=self.name) + ytransform=None, name=self.name) results = self.model.fit(self._get_data()) @@ -198,7 +201,7 @@ def run(self): self.predicted_values = values if self.out_transform is not None: - values = self.out_transform(values) + values = values.apply(eval(self.out_transform)) colname = self._get_out_column() tabname = self._get_out_table() From 979b0a226b6430d7c00ad038b39c6660d7089f5a Mon Sep 17 00:00:00 2001 From: Sam Maurer Date: Mon, 15 Jul 2019 18:58:54 -0700 Subject: [PATCH 2/3] Versioning --- CHANGELOG.md | 4 ++++ docs/source/index.rst | 2 +- setup.py | 2 +- urbansim_templates/__init__.py | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8b63b9..4f0b62a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # UrbanSim Templates change log +### 0.1.3 (2019-07-15) + +- fixes a bug with `out_transform` parameter for OLS simulation + ### 0.1.2 (2019-02-28) - fixes a crash in small MNL simulation diff --git a/docs/source/index.rst b/docs/source/index.rst index dbf7bdb..697565c 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -10,7 +10,7 @@ UrbanSim Templates provides building blocks for Orca-based simulation models. It The library contains templates for common types of model steps, plus a tool called ModelManager that runs as an extension to the `Orca `__ task orchestrator. ModelManager can register template-based model steps with the orchestrator, save them to disk, and automatically reload them for future sessions. -v0.1.2, released February 28, 2019 +v0.1.3, released July 15, 2019 Contents diff --git a/setup.py b/setup.py index 2aa2b68..943f905 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='urbansim_templates', - version='0.1.2', + version='0.1.3', description='UrbanSim extension for managing model steps', author='UrbanSim Inc.', author_email='info@urbansim.com', diff --git a/urbansim_templates/__init__.py b/urbansim_templates/__init__.py index 6f5532e..adb9e1a 100644 --- a/urbansim_templates/__init__.py +++ b/urbansim_templates/__init__.py @@ -1 +1 @@ -version = __version__ = '0.1.2' +version = __version__ = '0.1.3' From 2da27ba242e6053c880f598eeed6f920332316bd Mon Sep 17 00:00:00 2001 From: Sam Maurer Date: Mon, 22 Jul 2019 09:26:32 -0700 Subject: [PATCH 3/3] Updating release date --- docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 697565c..19f9c24 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -10,7 +10,7 @@ UrbanSim Templates provides building blocks for Orca-based simulation models. It The library contains templates for common types of model steps, plus a tool called ModelManager that runs as an extension to the `Orca `__ task orchestrator. ModelManager can register template-based model steps with the orchestrator, save them to disk, and automatically reload them for future sessions. -v0.1.3, released July 15, 2019 +v0.1.3, released July 22, 2019 Contents