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

Add function to calculate accessibility #169

Closed
rafapereirabr opened this issue May 13, 2021 · 15 comments · Fixed by #175
Closed

Add function to calculate accessibility #169

rafapereirabr opened this issue May 13, 2021 · 15 comments · Fixed by #175
Assignees
Labels

Comments

@rafapereirabr
Copy link
Member

No description provided.

@mvpsaraiva
Copy link
Collaborator

Although accessibility can be calculated from the travel time matrices produced by r5r, a dedicated accessibility function has many advantages:

  • It's more convenient to the user;
  • R5 has native capabilities for calculating accessibility baked into the travel times calculation process, so it's probably faster than doing it on the R side;
  • It's more memory efficient, since the full travel time matrix is never stored in memory;
  • It has native capabilities for calculating accessibility considering a departure time window and different travel time percentiles;
  • It has native support for many decay functions (step, exponential, logistic, and so on)

Additionally, the new accessibility() function signature is very similar to that of the travel_time_matrix() function, with just a few differences:

  • the destinations data.frame needs a new opportunities column
  • new cutoffs parameter
  • new decay_function parameter

@mvpsaraiva
Copy link
Collaborator

First estimates, using a step decay function:

Screenshot 2021-05-14 at 09 48 06

@mvpsaraiva
Copy link
Collaborator

Conveyal documentation on decay functions is here. Those functions, beyond the step / cumulative opportunities function, are:

  • Half-life Exponential, that does not require any extra parameter because the half-life decay is inferred from the cutoff value.
  • Fixed Exponential, which requires a decay constant parameter.
  • Logistic, which requires an additional standard_deviation parameter;
  • Linear, which requires a width parameter;

I think we have two options:

  • Expose all decay functions, and include a decay_parameter parameter that is passed to each function accordingly;
  • Expose only the Step and Half-life Exponential functions, which require no extra parameters, for simplicity.

@dhersz
Copy link
Member

dhersz commented May 14, 2021

I prefer exposing all decay functions and documenting what the parameter means in each case.

Regarding the figure you posted above, are all of these "no accessibility islands" snap-related? The image seems a bit weird to me. Had we calculated the travel time matrices manually and calculated accessibility within R, the resulting plot would be similar?

@rafapereirabr
Copy link
Member Author

I would also prefer we expose all decay functions and create and decay argument.

I agree the maps has quite a few unexpected blind spots. Perhaps we should calculate accessibility step-by-step in R and compare agains the R5 estimates.

@mvpsaraiva
Copy link
Collaborator

Good points! The "inaccessible islands" of the previous maps happened because max_walk_dist was set to just 300m. I've increased it to 1km and calculated accessibility again, using the two methods. Now the areas with "no accessibility" (dark grey on the maps below) are concentrated towards the southern edge of the city, which makes more sense.

Screenshot 2021-05-14 at 14 33 52

The resulting maps look the same. I've also compared both data.frames, and the accessibility values are exactly the same as well. I believe that using a frequency-based GTFS and larger number of Monte Carlo draws, there will be some variation in travel times and accessibility values, but in this simple tests all values are equal.

@rafapereirabr
Copy link
Member Author

rafapereirabr commented May 14, 2021 via email

@mvpsaraiva
Copy link
Collaborator

Simple demonstration of the effects of all decay functions on accessibility.
The title of each facet states the decay function used and the corresponding parameter value. In the case of step and exp, it's simply the travel time cutoff; the other functions were calculated with a cutoff of 30 min and the decay parameter stated in the facet.

Screenshot 2021-05-14 at 17 27 51

@mvpsaraiva
Copy link
Collaborator

Plots of the decay functions, for the record:

Screenshot 2021-05-21 at 08 15 33

Travel times on the x axis, step and exponential functions using cutoff = 30, fixed_exponential with decay = 0.001, and logistic and linear using decay = 10.

@mvpsaraiva
Copy link
Collaborator

mvpsaraiva commented May 21, 2021

To-do:

  • Check opportunities column in destinations data.frame
  • Validate decay_value parameter: for fixed_exponential function, decay_value must be between 0 and 1, for logistic and linear functions, decay_value must be greater or equal to 1
  • Update documentation
  • Write tests

@rafapereirabr
Copy link
Member Author

I've added some more documentation to the function but I think we still have to provide (1) intuitive explanations to the behavior of each decay function, (2) the equations of each decay function

@rafapereirabr
Copy link
Member Author

@mvpsaraiva , I get the following error when I try to reproduce the example in the function:

library(r5r)

 # build transport network
 data_path <- system.file("extdata/poa", package = "r5r")
 r5r_core <- setup_r5(data_path = data_path)

 # load origin/destination points
 points <- read.csv(file.path(data_path, "poa_hexgrid.csv"))

   access <- accessibility(r5r_core,
                           origins = points,
                           destinations = points,
                           opportunities_colname = "schools",
                           mode = "WALK",
                           cutoffs = c(25, 30),
                           max_trip_duration = 30,
                           verbose = FALSE)

Error in get(opportunities_colname) : object 'schools' not found

@mvpsaraiva
Copy link
Collaborator

The issue seems to be in this line. I've removed the get from the data.table call and it seems to be working now. But sometimes it requires the get, so I'm not quite sure what's going on.

@rafapereirabr
Copy link
Member Author

Thanks! I've just added a test script for the accessibility() function, commit 09e4587

@rafapereirabr
Copy link
Member Author

Setting this issue as priority, to be incorporated in the next package release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants