| cgraph | R Documentation |
Callback examples for matpow.
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)
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. |
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
matrix m in the call to matpow 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.
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
component connected. If the mindist option had been
chosen, the dists component will show the minimum intervertex
distances.
eig: The x component will be the principal
eigenvector.
mc: The pivec component will be the long-run
distribution vector.
mexp: The esum component will be the matrix
exponential.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.