File: stochastic_matrix.Rd

package info (click to toggle)
r-cran-igraph 1.0.1-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 18,232 kB
  • sloc: ansic: 173,538; cpp: 19,365; fortran: 4,550; yacc: 1,164; tcl: 931; lex: 484; makefile: 149; sh: 9
file content (55 lines) | stat: -rw-r--r-- 1,631 bytes parent folder | download | duplicates (2)
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
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/scg.R
\name{stochastic_matrix}
\alias{get.stochastic}
\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 <- barabasi.game(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)
}
\author{
Gabor Csardi \email{csardi.gabor@gmail.com}
}
\seealso{
\code{\link{as_adj}}
}
\keyword{graphs}