File: random_walk.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 (48 lines) | stat: -rw-r--r-- 1,525 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
% Generated by roxygen2 (4.1.1): do not edit by hand
% Please edit documentation in R/random_walk.R
\name{random_walk}
\alias{random_walk}
\title{Random walk on a graph}
\usage{
random_walk(graph, start, steps, mode = c("out", "in", "all"),
  stuck = c("return", "error"))
}
\arguments{
\item{graph}{The input graph, might be undirected or directed.}

\item{start}{The start vertex.}

\item{steps}{The number of steps to make.}

\item{mode}{How to follow directed edges. \code{"out"} steps along the
edge direction, \code{"in"} is opposite to that. \code{"all"} ignores
edge directions. This argument is ignored for directed graphs.}

\item{stuck}{What to do if the random walk gets stuck. \code{"return"}
returns the partial walk, \code{"error"} raises an error.}
}
\value{
A vertex sequence containing the vertices along the walk.
}
\description{
Do a random walk. From the given start vertex, take the given number of
steps, choosing an edge from the actual vertex uniformly randomly. Edge
directions are observed in directed graphs (see the \code{mode} argument
as well). Multiple and loop edges are also observed.
}
\examples{
## Stationary distribution of a Markov chain
g <- make_ring(10, directed = TRUE) \%u\%
  make_star(11, center = 11) + edge(11, 1)

ec <- eigen_centrality(g, directed = TRUE)$vector
pg <- page_rank(g, damping = 0.999)$vector
w <- random_walk(g, start = 1, steps = 10000)

## These are similar, but not exactly the same
cor(table(w), ec)

## But these are (almost) the same
cor(table(w), pg)
}