topsort {Peanut} | R Documentation |
The structural part of the Ω-matrix is an incidence matrix where the entry is 1 if the node represented by the column is a parent of the node represented by the child. This sorts the rows and columns of the matrix (which should have the same names) so that the ancestors of a node always appear prior to it in the sequence. As a consequence, the values in the upper triangle of the Ω-matrix are always zero after sorting.
topsort(Omega, noisy = FALSE)
Omega |
A square matrix of 1's and zeros which corresponds to an acyclic directed graph. |
noisy |
A logical value. If true, details of progress through the algorithm are printed. |
An ordering of the rows and columns which will sort the matrix.
This will generate an error if the graph represented by the matrix is cyclic.
Russell Almond
Pnet2Omega
uses this function to sort the columns in the
Omega matrix.
## Sample Omega matrix. omegamat <- read.csv(paste(library(help="Peanut")$path, "auxdata", "miniPP-omega.csv", sep=.Platform$file.sep), row.names=1,stringsAsFactors=FALSE) omega <- as.matrix(omegamat[,2:6]) ## omega is already sorted so scramble it. shuffle <- sample.int(5) omegas <- omega[shuffle,shuffle] ord <- topsort(omegas) omegas[ord,ord]