Skip to content

Commit

Permalink
Merge 825611d into 3324905
Browse files Browse the repository at this point in the history
  • Loading branch information
smmaurer committed Jul 22, 2019
2 parents 3324905 + 825611d commit b921d51
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 9 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 0.2 (not yet released)

#### 0.2.dev7 (2019-07-15)

- fixes a bug with the `out_transform` parameter for `OLSRegressionStep`

#### 0.2.dev6 (2019-04-04)

- introduces classes for storing common settings: `shared.CoreTemplateSettings`, `shared.OutputColumnSettings`
Expand Down Expand Up @@ -39,6 +43,11 @@
- adds support for `autorun` template property


## 0.1.3 (2019-07-15)

- patch to incorporate the `out_transform` bug fix for `OLSRegressionStep`, from 0.2.dev7


## 0.1.2 (2019-02-28)

- patch to incorporate the small MNL bug fix from 0.2.dev1
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://udst.github.io/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.2.dev6, released April 4, 2019
v0.2.dev7, released July 22, 2019


Contents
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='urbansim_templates',
version='0.2.dev6',
version='0.2.dev7',
description='UrbanSim extension for managing model steps',
author='UrbanSim Inc.',
author_email='info@urbansim.com',
Expand Down
21 changes: 21 additions & 0 deletions tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,24 @@ 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)

2 changes: 1 addition & 1 deletion urbansim_templates/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = __version__ = '0.2.dev6'
version = __version__ = '0.2.dev7'
15 changes: 9 additions & 6 deletions urbansim_templates/models/regression.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -69,10 +70,12 @@ 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
Expand Down Expand Up @@ -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)

df = get_data(tables = self.tables,
filters = self.filters,
Expand Down Expand Up @@ -207,7 +210,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()
Expand Down

0 comments on commit b921d51

Please sign in to comment.