Retrieves the stochastic matrix of a graph of class igraph
.
stochastic_matrix(
graph,
column.wise = FALSE,
sparse = igraph_opt("sparsematrices")
)
The input graph. Must be of class igraph
.
If FALSE
, then the rows of the stochastic matrix
sum up to one; otherwise it is the columns.
Logical scalar, whether to return a sparse matrix. The
Matrix
package is needed for sparse matrices.
A regular matrix or a matrix of class Matrix
if a
sparse
argument was TRUE
.
Let
The (row) stochastic matrix is defined as
# NOT RUN {
library(Matrix)
## g is a large sparse graph
g <- sample_pa(n = 10^5, power = 2, directed = FALSE)
W <- stochastic_matrix(g, sparse=TRUE)
## a dense matrix here would probably not fit in the memory
class(W)
## may not be exactly 1, due to numerical errors
max(abs(rowSums(W))-1)
# }
Run the code above in your browser using DataLab