-
Notifications
You must be signed in to change notification settings - Fork 16
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
dodgr_flows_aggregate aggregates integer flows into non-integers #137
Comments
@unbrother you will be intrested in this |
Thanks @mem48, and you are indeed correct, but that is an intentional design decision as explained in #89. Everything is hard-coded as In the meantime, it would help if you could opine on #117 - have you ever resorted to anything but the default |
Ok, but if these are floating point errors then shouldn't they be very small. I could understand getting a flow of 5.000001 but a flow of 5.5 seems like a large error. I did a few more tests
Changing the heap made no difference except for Also, notice the flow values I get. My input was a matrix of ones, so I would expect the minimum non-zero flow to be 1 and all other values to be a multiple of 1. Instead, I get some very small numbers. As the hampi example is quite complex I tried something even simpler.
I would have expected the |
Aha, i see. It's the
library (dodgr)
graph <- weight_streetnet (hampi)
from <- sample (graph$from_id, size = 10)
to <- sample (graph$to_id, size = 5)
to <- to [!to %in% from]
flows <- matrix(rep(1, length(from) * length(to)),
nrow = length(from))
graph <- dodgr_flows_aggregate(graph, from = from, to = to, flows = flows)
summary(graph$flow[graph$flow > 0])
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 0.003401 0.011322 0.013446 0.023629 0.031730 0.079733
graph <- dodgr_flows_aggregate(graph, from = from, to = to, flows = flows,
norm_sums = FALSE)
#> Warning in prepare_graph(graph, from, to): graph already has a 'flow' column;
#> this will be overwritten
summary(graph$flow[graph$flow > 0])
#> Min. 1st Qu. Median Mean 3rd Qu. Max.
#> 1.000 3.000 4.000 4.114 5.000 10.000
# Make a simple Tree in igraph
library(igraph)
graph_i <- make_tree(19,2,"undirected")
#plot(graph_i)
# Convert to dodgr and make undirected
graph <- as_data_frame(graph_i)
graph2 <- graph[,2:1]
names(graph2) <- c("from","to")
graph <- rbind(graph, graph2)
graph$d <- 1
# Flow of 1 from all to all (same as edge betweenness)
flows <- matrix(rep(1, 19 * 19), ncol = 19)
graph <- dodgr_flows_aggregate(graph, from = 1:19, to = 1:19, flows = flows)
graph$flow
#> [1] 19.452381 18.452381 19.619048 12.866667 12.076190 12.076190 12.492857
#> [8] 12.492857 5.283333 5.283333 5.054762 5.054762 5.054762 5.054762
#> [15] 5.171429 5.171429 5.171429 5.171429 19.452381 18.452381 19.619048
#> [22] 12.866667 12.076190 12.076190 12.492857 12.492857 5.283333 5.283333
#> [29] 5.054762 5.054762 5.054762 5.054762 5.171429 5.171429 5.171429
#> [36] 5.171429
graph <- dodgr_flows_aggregate(graph, from = 1:19, to = 1:19, flows = flows,
norm_sums = FALSE)
#> Warning in prepare_graph(graph, from, to): graph already has a 'flow' column;
#> this will be overwritten
graph$flow
#> [1] 88 84 84 48 48 48 48 48 18 18 18 18 18 18 18 18 18 18 88 84 84 48 48 48 48
#> [26] 48 18 18 18 18 18 18 18 18 18 18
# Do edge betweeness in igraph
E(graph_i)$between <- edge.betweenness(graph_i)
E(graph_i)$between
#> [1] 88 84 84 48 48 48 48 48 18 18 18 18 18 18 18 18 18 18 Created on 2020-06-23 by the reprex package (v0.3.0) ... and actually, that was an additional explicit reason why i did not implement strict |
Ok, But I don't understand when |
Say you've got the following network: With a flow of 10 from A -> C and a flow of 10 from D -> C. Direct aggregation of flows will then give the following:
And the total flow aggregated throughout the entire network is 40, even though only 10 units are flowing from each of A and D. It might rightly be asserted that this total flow should be constrained to the total amounts emanating from each source/origin point, and so be constrained to 10 + 10 = 20. This is what
So you can see what it effectively does is to "spread" the flow from, say A -> C, equally along each of the intervening edges. If there are N edges between any two origin -> destination points with a flow between them of f, then the flow on each of those intervening edges will be f / N if One context for considering the appropriateness of this whole functionality is OSM. A single way might be represented by a bunch of nodes along it simply because it is highly curved. Aggregating flows along with way using |
I suppose it depends on what you then do with the results. I'm plotting them on a map, so a highly curved road is clear. But if you did some statiticaly analysis of the network I can see the normalisation being useful. |
If all the flow values input to dodgr_flows_aggregate are whole numbers I would expect all the resulting flows to also be whole numbers, as they are simple sums.
Reprex
The text was updated successfully, but these errors were encountered: