The getEdgeWeightNStepsAway
function finds the weight of an edge that is a certain number of steps away from a specified node in a graph. This function is used within the context of the computeTransitionProbability
function to calculate transition probabilities along paths.
Usage
getEdgeWeightNStepsAway(g, start_col, start_row)
Arguments
- g
A numeric matrix representing the adjacency matrix of the graph. The matrix should contain edge weights as its values.
- start_col
An integer specifying the column index of the starting node.
- start_row
An integer specifying the row index of the starting node.
Value
If the edge is not reachable due to no incoming edges, the function returns NULL. If the edge is reachable, the function returns the weight of the edge that is a certain number of steps away.
Note
The function assumes that the input graph is represented as an adjacency matrix with non-negative edge weights.
Examples
# Create a sample adjacency matrix
g <- matrix(c(0, 1, 2, 0, 0, 0, 1, 0, 0), nrow = 3, byrow = TRUE)
# Get the weight of an edge n steps away
weight <- getEdgeWeightNStepsAway(g, 2, 3)