Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to large MNL template to accommodate post-MCT interaction term operations #126

Merged
merged 6 commits into from
Sep 27, 2021

Conversation

mxndrwgrdnr
Copy link
Member

@mxndrwgrdnr mxndrwgrdnr commented Sep 13, 2021

Sometimes interaction terms can only be computed after sampling of alternatives has been performed. For example, in the household location choice context, it is common to include a commute distance parameter where that commute distance is the average distance between each potential residential location and the workplace of each worker in that household. In this case, because the actual decision-making unit is the household, we can only compute this aggregate distance term after the alternatives have been sampled and merged with the choosers to form a "merged choice table". When using urbansim_templates for simulation, however, the formation of the merged choice table happens on-the-fly via the choicemodels library, for example here. This makes it difficult to perform any ad-hoc manipulations of the table such as would be needed for the use case described here.

To achieve this functionality, I have instead devised a way to pass an additional set of instructions to the underlying large mnl model, containing information about a set of operations to perform on the merged choice table after it gets created. In short, the changes here allow the user to specify these operations as a new dict-like model attribute called mct_intx_ops, which can then be read by the LargeMultinomialLogitStep class and interpreted by the perform_mct_intx_ops() method here. Other parts of the large MNL template have been altered to accommodate the reading and writing of the new model attribute.

An example model spec with the new attribute can be found here. And here is an example notebook showing how model estimation works with the new functionality.

The corresponding changes to choicemodels can be found in this PR.

Copy link
Member

@smmaurer smmaurer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this!

@smmaurer
Copy link
Member

This PR adds to the LargeMultinomialLogitStep class an attribute called mct_intx_ops and a method called perform_mct_intx_ops(). No breaking changes.

To do before releasing:

@smmaurer smmaurer merged commit 723b83b into dev Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants