cgraph {matpow} | R Documentation |
Callback Examples
Description
Callback examples for matpow
.
Usage
cgraph(ev,cbinit=FALSE,mindist=FALSE)
eig(ev,cbinit=FALSE,x=NULL,eps=1e-08)
mc(ev,cbinit=FALSE,eps=1e-08)
mexp(ev,cbinit=FALSE,eps=1e-08)
Arguments
ev |
R environment as in the return value of matpow. |
cbinit |
|
mindist |
if TRUE, the matrix of minimum intervertex distances will be calculated. |
x |
initial guess for the principal eigenvector. |
eps |
convergence criterion. |
Details
Note that these functions are not called directly. The user
specifies the callback function (whether one of the examples here or one
written by the user) in his/her call to matpow
, which
calls the callback after each iteration.
-
cgraph
: Determines the connectivity of a graph, and optionally the minimum intervertex distance matrix. The matrixm
in the call tomatpow
should be an adjacency matrix, 1s and 0s. -
eig
: Calculates the principal eigenvector of the input matrix. -
mc
: Calculates the long-run distribution vector for an aperiodic, discrete-time Markov chain; the input matrix is the transition matrix for the chain. -
mexp
: Calculates the exponential of the input matrix, as in e.g.expm
of the Matrix package.
In cgraph
, it is recommended that squaring
be set to TRUE
in calling matpow
, though this cannot be done if the
mindist
option is used. Use of squaring is unconditionally
recommended for eig
and mc
. Do not use squaring
with mexp
.
Restrictions: These functions are currently set up only for
ordinary R matrix multiplication or use with gputools
.
Value
Callback functions don't normally return values, but they usually do
maintain data in the R environment ev
that is eventually
returned by matpow
, including the following components as
well as the application-independent ones:
-
cgraph
: Graph connectedness is returned in a boolean componentconnected
. If themindist
option had been chosen, thedists
component will show the minimum intervertex distances. -
eig
: Thex
component will be the principal eigenvector. -
mc
: Thepivec
component will be the long-run distribution vector. -
mexp
: Theesum
component will be the matrix exponential.
Examples
## Not run:
m <- rbind(c(1,0,0,1),c(1,0,1,1),c(0,1,0,0),c(0,0,1,1))
ev <- matpow(m,callback=cgraph,mindist=T)
ev$connected # prints TRUE
ev$dists # prints, e.g. that min dist from 1 to 2 is 3
m <- rbind(1:2,3:4)
# allow for 1000 iterations max
ev <- matpow(m,1000,callback=eig,squaring=TRUE)
# how many iterations did we actually need?
ev$i # only 8
ev$x # prints eigenvec; check by calling R's eigen()
## End(Not run)