topsort: Topologically sorts the rows and columns of an Omega matrix

topsortR Documentation

Topologically sorts the rows and columns of an Omega matrix

Description

The structural part of the \Omega-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 \Omega-matrix are always zero after sorting.

Usage

topsort(Omega, noisy = FALSE)

Arguments

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.

Value

An ordering of the rows and columns which will sort the matrix.

Note

This will generate an error if the graph represented by the matrix is cyclic.

Author(s)

Russell Almond

See Also

Pnet2Omega uses this function to sort the columns in the Omega matrix.

Examples


## Sample Omega matrix.
omegamat <- read.csv(system.file("auxdata", "miniPP-omega.csv",
                     package="Peanut"),
                     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]


ralmond/Peanut documentation built on Sept. 19, 2023, 8:27 a.m.