Update to large MNL template to accommodate post-MCT interaction term operations #126
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theLargeMultinomialLogitStep
class and interpreted by theperform_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.