m-richards / RecursiveRouteChoice

Implementation of the Recursive Logit model for prediction and estimation
https://m-richards.github.io/RecursiveRouteChoice/
17 stars 4 forks source link

Confusion on Incidence Matrix Format #23

Open haruharu9 opened 1 year ago

haruharu9 commented 1 year ago

Hi, I am a graduate student in civil engineering. I am trying to apply recursive logit model for a route choice analysis. I have come across your repo and Tien Mai’s. I am confused about the formulation for incidence matrix.

The incidence matrix should be (start_node, end_node, 1) or (start_link, succeeding_link, 1)?

Based on the observation matrix format ([Dest, Orig, Link1, Link2, ..., LinkN, Dest]), seems like the incidence matrix should be link based. But according to your comments in your network_visualiser.py, the incidence matrix format should be node based (Tien Mai's code is node based?). If the incidence matrix is node based, the link ID information is not stored in the incidence matrix, how can we get a link based observation matrix?

Thank you very much.

m-richards commented 1 year ago

Hi @haruharu9, thanks for the question!

It's been a little while since I've worked with this code, so I'll have to double check and get back to you. If you're looking into the recursive logit in detail, if you want to send me an email, I'm happy to pass on the thesis accompanying the code ( but that probably won't help answer this specific question)

haruharu9 commented 1 year ago

Hi @haruharu9, thanks for the question!

It's been a little while since I've worked with this code, so I'll have to double check and get back to you. If you're looking into the recursive logit in detail, if you want to send me an email, I'm happy to pass on the thesis accompanying the code ( but that probably won't help answer this specific question)

Hi Matt,

Thank you so much for your reply. I do want to learn more details about the recursive logit model, I may add additional network attributes, your thesis will be very helpful. I don't use github very often, not sure how to send you an email or send you an email address in a privateer way. For the incidence matrix format, if you ever have time to take a look, I am really appreciate. Thank you again.

m-richards commented 1 year ago

It's been interesting going back through the code to see what I remember. My code was originally based on tien mai's code and so developed in link based fashion, but I switched to use a node based formulation when trying to run with real data - I didn't have turn angle information available. So I believe it can suport both - and the model can be formulated in a link and node based way. The main difference is to do with the network attributes you have / want to encode. A link based formulation supports attributes such as turn direction indicators (there is some code of mine that deals with extracting turn angles, however I didn't have good data to test this on).

The node based formulation is most straightforward as the short term utility term transitioning from one node to the next directly corresponds to attirbutes of a link (whilst for a link based formulation, the short term utiltiy term should include some of the current link and the next link). This is what I wrote in my thesis on this (it's nice to have a well written up record):

image

image

however the point about not being able to measure physical characteristics across link pairs is potentially able to be avoided by considering the current state to be "just before the very end of the link", rather than the midpoint of the link.

You might also be interested in https://github.com/m-richards/TAM-RecursiveLogit which is where I annotated (and I think bugfixed but I don't entirely remember) some of tien mai's code.

haruharu9 commented 1 year ago

It's been interesting going back through the code to see what I remember. My code was originally based on tien mai's code and so developed in link based fashion, but I switched to use a node based formulation when trying to run with real data - I didn't have turn angle information available. So I believe it can suport both - and the model can be formulated in a link and node based way. The main difference is to do with the network attributes you have / want to encode. A link based formulation supports attributes such as turn direction indicators (there is some code of mine that deals with extracting turn angles, however I didn't have good data to test this on).

The node based formulation is most straightforward as the short term utility term transitioning from one node to the next directly corresponds to attirbutes of a link (whilst for a link based formulation, the short term utiltiy term should include some of the current link and the next link). This is what I wrote in my thesis on this (it's nice to have a well written up record):

image

image

however the point about not being able to measure physical characteristics across link pairs is potentially able to be avoided by considering the current state to be "just before the very end of the link", rather than the midpoint of the link.

You might also be interested in https://github.com/m-richards/TAM-RecursiveLogit which is where I annotated (and I think bugfixed but I don't entirely remember) some of tien mai's code.

You can get in touch with me by email at mrichards7 at outlook dot com dot au

Hi Matt,

Hope everything is going well for you. I tried to reach you via email, but probably the email did get delivered. Just want to say thank you, the materials you provided are very helpful. Given my situation, I think the node-based formulation is more suitable, we are not considering turn angles and u turns at this point. However, in some special cases, for example, there are two different links between the same pair of nodes, I am wondering if the node-based formulation cannot deal with this kind of situation very well? Since the node-based formulation the incidence matrix can only have one value between a pair of nodes. Not sure if I am understanding this correctly or not. Thank you again for your help.

m-richards commented 1 year ago

I've just replied by email - sorry I've had a busy week so have only just gotten back to it.