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

Use od_disaggregate() in od_jitter() #39

Open
Robinlovelace opened this issue Dec 5, 2021 · 1 comment
Open

Use od_disaggregate() in od_jitter() #39

Robinlovelace opened this issue Dec 5, 2021 · 1 comment

Comments

@Robinlovelace
Copy link
Member

With #38 od_disaggregate() is more efficient, and deserves to be used in od_jitter().

@Robinlovelace
Copy link
Member Author

They seem to have similar performance on a small dataset:

library(od)
od = od_data_df
z = od_data_zones_min
dlr = od_jitter(od, z) # desire_lines_random
#> 0 origins with no match in zone ids
#> 0 destinations with no match in zone ids
#>  points not in od data removed.
#> Linking to GEOS 3.9.1, GDAL 3.3.2, PROJ 7.2.1
dlr2 = od_disaggregate(od, z, max_per_od = 10000, keep_ids = FALSE)
#> Creating origin and destination points at random locations

desire_lines = od_to_sf(od, z)
#> 0 origins with no match in zone ids
#> 0 destinations with no match in zone ids
#>  points not in od data removed.
plot(z$geometry)
plot(dlr, add = TRUE, lwd = 3)
#> Warning in plot.sf(dlr, add = TRUE, lwd = 3): ignoring all but the first
#> attribute
plot(dlr2, add = TRUE, lwd = 3)
#> Warning in plot.sf(dlr2, add = TRUE, lwd = 3): ignoring all but the first
#> attribute
plot(desire_lines, add = TRUE, lwd = 5)
#> Warning in plot.sf(desire_lines, add = TRUE, lwd = 5): ignoring all but the
#> first attribute

dim(dlr)
#> [1]  7 11
dim(dlr2)
#> [1]  7 11
waldo::compare(sf::st_drop_geometry(dlr), sf::st_drop_geometry(dlr2)) # minor diffs
#> `names(old)[1:5]`: "geo_code1" "geo_code2" "all" "train" "bus"
#> `names(new)[1:5]`: "o"         "d"         "all" "train" "bus"
#> 
#> `old$geo_code1` is a character vector ('E02002384', 'E02002404', 'E02006875', 'E02006876', 'E02006861', ...)
#> `new$geo_code1` is absent
#> 
#> `old$geo_code2` is a character vector ('E02006875', 'E02006875', 'E02006875', 'E02006875', 'E02002392', ...)
#> `new$geo_code2` is absent
#> 
#> `old$o` is absent
#> `new$o` is a character vector ('1', '5', '13', '14', '6', ...)
#> 
#> `old$d` is absent
#> `new$d` is a character vector ('10', '7', '9', '8', '3', ...)
dlr$all == dlr$all
#> [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE

bench::mark(check = FALSE, 
            od_jitter = od_jitter(od, z),
            od_disaggregate = od_disaggregate(od, z, max_per_od = 10000, keep_ids = FALSE)
            )
#> 0 origins with no match in zone ids
#> 0 destinations with no match in zone ids
#>  points not in od data removed.
#> Creating origin and destination points at random locations
#> 0 origins with no match in zone ids
#> 0 destinations with no match in zone ids
#>  points not in od data removed.
#> 0 origins with no match in zone ids
#> 0 destinations with no match in zone ids
#>  points not in od data removed.
#> 0 origins with no match in zone ids
#> 0 destinations with no match in zone ids
#>  points not in od data removed.
#> Creating origin and destination points at random locations
#> Creating origin and destination points at random locations
#> Creating origin and destination points at random locations
#> Warning: Some expressions had a GC in every iteration; so filtering is disabled.
#> # A tibble: 2 × 6
#>   expression           min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>      <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 od_jitter          190ms    190ms      5.13    6.26MB     5.13
#> 2 od_disaggregate    155ms    161ms      5.87    4.69MB     5.87

Created on 2021-12-05 by the reprex package (v2.0.1)

Robinlovelace added a commit that referenced this issue Dec 5, 2021
Robinlovelace added a commit that referenced this issue Dec 5, 2021
* Add od_disag args to od_jitter for #39

* Use od_dissaggrate backend for #39
Robinlovelace added a commit that referenced this issue Dec 5, 2021
* od_nrows()

* Refactor with od$nrows column

* Refactor, remove subzones arg

* Tidy up, remove lines!

* Add od_disag args to od_jitter for #39 (#40)

* Add od_disag args to od_jitter for #39

* Use od_dissaggrate backend for #39

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

No branches or pull requests

1 participant