I'd like to define an interaction variable for the household location choice model that measures the distance to work for each household from each sampled location. Since work locations differ across households AND alternatives, it cannot be defined using the standard patsy way, e.g. "h:b".
Thanks to a tip from Scott Bridwell, I implemented a function that creates the right interaction matrix, say distance(h,b) where 'h' is a household's attribute and 'b' is a buildings attribute:
def distance(h,b):
# create distance matrix from h and b
return dist
from urbansim.models import dcm
dcm.distance = distance
If I attach my function to the dcm class as above, I can then include it in a patsy formula using simply distance(h,b)
. However, the estimation breaks in one of the patsy modules, because the dist object in my function has a different index than the interaction object coming from the mnl_interaction_dataset
function in urbanchoice.
Is there any way I can access the interaction index in a user-defined function like the one above? Or, is there another way to do this? Thanks a lot.