File: stochastic_matrix.Rd

package info (click to toggle)
r-cran-igraph 2.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 27,044 kB
  • sloc: ansic: 204,981; cpp: 21,711; fortran: 4,090; yacc: 1,229; lex: 519; sh: 52; makefile: 8
file content (58 lines) | stat: -rw-r--r-- 1,658 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/stochastic_matrix.R
\name{stochastic_matrix}
\alias{stochastic_matrix}
\title{Stochastic matrix of a graph}
\usage{
stochastic_matrix(
  graph,
  column.wise = FALSE,
  sparse = igraph_opt("sparsematrices")
)
}
\arguments{
\item{graph}{The input graph. Must be of class \code{igraph}.}

\item{column.wise}{If \code{FALSE}, then the rows of the stochastic matrix
sum up to one; otherwise it is the columns.}

\item{sparse}{Logical scalar, whether to return a sparse matrix. The
\code{Matrix} package is needed for sparse matrices.}
}
\value{
A regular matrix or a matrix of class \code{Matrix} if a
\code{sparse} argument was \code{TRUE}.
}
\description{
Retrieves the stochastic matrix of a graph of class \code{igraph}.
}
\details{
Let \eqn{M} be an \eqn{n \times n}{n x n} adjacency matrix with real
non-negative entries. Let us define \eqn{D = \textrm{diag}(\sum_{i}M_{1i},
\dots, \sum_{i}M_{ni})}{D=diag( sum(M[1,i], i), ..., sum(M[n,i], i) )}

The (row) stochastic matrix is defined as \deqn{W = D^{-1}M,}{W = inv(D) M,}
where it is assumed that \eqn{D} is non-singular.  Column stochastic
matrices are defined in a symmetric way.
}
\examples{

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)

}
\seealso{
\code{\link[=as_adjacency_matrix]{as_adjacency_matrix()}}
}
\author{
Gabor Csardi \email{csardi.gabor@gmail.com}
}
\keyword{graphs}