@@ -58,20 +58,22 @@ graph_most_likely <- function(graph, quiet = FALSE) {
5858 # number of nodes in the 3d grid
5959 n <- prod(graph $ sz )
6060
61- # Compute the matrix TO
61+ # Compute the matrix TO (transition * observation)
6262 if (! quiet ) {
6363 cli :: cli_progress_step(" Compute movement model" )
6464 }
6565 trans_obs <- graph_transition(graph ) * graph $ obs [graph $ t ]
6666
67- # Initiate the matrix providing for each node of the graph, the source id (index of the node)
68- # with the most likely path to get there.
67+ # Initiate the sparse 1D matrix providing for each node of the graph, the source id (index of the
68+ # node in the 3D grid) with the cumulative max probability to get there.
69+ # Start with prob=1 at the equipment site (log = 0)
6970 path_s <- Matrix :: sparseMatrix(
7071 rep(1 , length(graph $ equipment )),
7172 graph $ equipment ,
7273 x = 0 , dims = c(1 , n )
7374 )
74- # Initiate the same matrix providing the total probability of the current path so far
75+ # Initiate the same matrix providing the cumulative total probability of the current path so far
76+ # Not sure why x is differently specify, should be the same value for both path_s and path_max
7577 path_max <- Matrix :: sparseMatrix(
7678 rep(1 , length(graph $ equipment )),
7779 graph $ equipment ,
@@ -89,9 +91,10 @@ graph_most_likely <- function(graph, quiet = FALSE) {
8991 stap = arrayInd(graph $ s , graph $ sz )[, 3 ]
9092 )
9193
92- # Split this data.fram by stationary period (of the source)
94+ # Split this data.frame by stationary period (of the source)
9395 node_stap <- split(node , node $ stap )
9496
97+ # Compute number of nodes per stap
9598 n_edge <- sapply(node_stap , nrow )
9699
97100 if (! quiet ) {
@@ -109,12 +112,14 @@ graph_most_likely <- function(graph, quiet = FALSE) {
109112 }
110113
111114 for (i_s in seq_len(length(node_stap ))) {
115+ # Select all nodes of the current stap
112116 node_i_s <- node_stap [[i_s ]]
113117
114- # compute the probability of all possible transition
118+ # Compute the (cum) log probability of all possible transitions
115119 node_i_s $ p <- path_max [node_i_s $ s ] + node_i_s $ to
116120
117- # Find the value of the maximum possible transition for each target node
121+ # Find the value of the maximum possible transition for each target node and store it into
122+ # path_max
118123 max_v <- sapply(split(node_i_s $ p , node_i_s $ t ), max )
119124 max_t <- as.numeric(names(max_v ))
120125 path_max [max_t ] <- max_v
0 commit comments