melmasri / traveltimeHMM

Travel time prediction from GPS observations using an HMM
9 stars 2 forks source link

Improvement opportunity regarding conversion of time stamps to time bins #17

Closed ericgermaining closed 5 years ago

ericgermaining commented 5 years ago

time_bins.R hard-codes the conversion algorithm from time stamps to time bins, but does so in a way that allows for custom function objects incorporating other such algorithms. I see two improvement opportunities that would allow better user customization of time bins:

  1. Include in predict.traveltime's interface (in predict.R) a function object that could be passed all the way down to time_bins.R. This would be rather easy to do considering the current architecture of time_bins.R.
  2. Develop a learning algorithm that would automatically perform the conversion. That would be possible if the time stamps are provided along with their corresponding time bins.
melmasri commented 5 years ago

Thanks @ericgermaining for taking a look at this. time_bins are the most complicated part of the software I think. And again I did it this way for speed.

  1. can be done, where if some one comes with their data that is already time binned, we only need to understand the boundary of the binning. I have to think about how to do that efficiently. Though I think for the time being we can let this wait, since I am not sure you have time for it, though the suggestion is great.

  2. I thought the best way to include time_bins as a functional is to pass them to traveltimeHMM. Consider the following scenarios:

    • a user loads the library and uses the default data as is, then the time_bins object is already loaded and can be integrated in traveltimeHMM by default.
    • a user creates his own time bins, by the coded method. For example,
      rules = list(
      list(start='6:30', end= '9:00', days = 1:5, tag='MR'),
      list(start='15:00', end= '18:00', days = 1:5, tag='ER')
      )
      time_bins <- rules2timebins(rules)
      ## here time_bins is a function, where you can bin the data with as
      trips$timeBins = time_bins(trips$time)

      In this case the traveltimeHMM would return this functional object as part of its return list, which can be used in predict. Or simply demand from the user to input time_bins to the predict function. This method is easier to implement then 2.. What do you think?

ericgermaining commented 5 years ago

@melmasri I like the functional approach, and I see that there already is a rules2timebins function in time_bins.R . However it doesn't seem to work with this example.