ATFutures / who

Active Transport Futures planning tools for the World Health Organisation
8 stars 2 forks source link

Error when trying to run optimise code #19

Closed Robinlovelace closed 6 years ago

Robinlovelace commented 6 years ago

https://github.com/ATFutures/who/blob/4db174b453175d4abe8f94f457c1ee5d17ba8992/code/od-calibrate.R#L66

All works until I get to this line. I get this error:

Error in dodgr_spatial_interaction(net, nodes, dens, k = k) : 
  nodes and dens must have same length 
mpadge commented 6 years ago

i think that's the non-latest version of dodgr. Can you install latest and check again?

Robinlovelace commented 6 years ago

It is the latest version from ATFutures:

devtools::install_github("ATFutures/dodgr")
Skipping install of 'dodgr' from a github remote, the SHA1 (dc6d87a8) has not changed since last install.
  Use `force = TRUE` to force installation
Robinlovelace commented 6 years ago

This is what is going into the spatial interaction model:

mpadge commented 6 years ago

okay, i'll check it out now. I've seen that error before, so i know that i know how to solve it.

Robinlovelace commented 6 years ago

Maybe it's a difference between our datasets? Try pushing the contents of who-data if it is

mpadge commented 6 years ago

it's not that because i've reset / deleted my local who-data. Am currently waiting while it re-clones

Robinlovelace commented 6 years ago

OK thanks. Great use of optimise() in any case.

Robinlovelace commented 6 years ago

I'm reading the documentation for it now.

mpadge commented 6 years ago

I've got a test case somewhere for 4 "modern" implementations of that versus base optimise that clearly show the superiority of base R in loads of standard conditions. optimise seems truly optimised. It's so bloody fast and accurate!

mpadge commented 6 years ago

Oh, it is a problem with outdated dodgr, but i haven't changed the version number, so you'll have to uninstall then reinstall coz devtools only checks version number. I just ran it from scratch with re-cloned who and who-data and all works perfectly.

Robinlovelace commented 6 years ago

Aha - I suggest updating the version number if that's the case. In my experience though devtools updates packages even when you don't change the version number as far as I know (AFAIK)

Robinlovelace commented 6 years ago

Or IIRC...

Robinlovelace commented 6 years ago

I'm just re-installing it. FYI it seemed to have updated it 1st time round though... could you print out a summary of what you have for dens? I'm surprised it's only 64 elements.

Robinlovelace commented 6 years ago

Seems to be doing something...

Robinlovelace commented 6 years ago

Getting this error now:

Error in rcpp_spatial_interaction(graph2, vert_map, node_index, k, dens,  : 
object 'k' not found
Robinlovelace commented 6 years ago

But this works (result!):

dodgr_spatial_interaction (net, nodes, dens, k = k)
Robinlovelace commented 6 years ago

I think k just needs to be initiated...

Robinlovelace commented 6 years ago

Now getting a strange result (may be because tol was v high):

res <- optimise (f (k) , lower = 0.1, upper = 20, maximum = TRUE, tol = 0.1)
> res
$maximum
[1] 6.821563
Robinlovelace commented 6 years ago

OK - resolved. But I'm getting another error message:

f <- dodgr_flows(net, od_id, od_id, flows = s, contract = T)
Error in get_pts_index(graph, gr_cols, vert_map, pts) : 
  from/to are not numeric yet can not be matched onto graph vertices
Robinlovelace commented 6 years ago

From the same script... No biggy, does not stop me finishing the report.