ResperByrow {resper} | R Documentation |
Sample from a set of permutations restricted by a Boolean or 0-1 matrix A, where the rows correspond to the original elements and the columns to the positions in the permutation. A_{i,j}=1 means that the ith element may occur at the jth position in the permuted sequence.
ResperByrow(mat)
mat |
A Boolean or 0-1 matrix. A permutation can only be gemerated if at least one element in each row and each column is equal to 1. |
This function uses an accept-reject algorithm. It selects the first row, samples an appropriate cell from the 1s in the row (denoting the position to which the element corresponding to the row will be shifted), eliminates the cell row and column from the matrix and reiterates the algorithm on the minor. The sampling weights are constructed by an envelope probability discovered by huber2003, which guarantees that the sum of weights over all minors is less than or equal to the weight of the matrix itself. If the algorithm samples the ``less than'' part, it will reject and restart the current attempt.
A sequence of values corresponding to the row indices of verb+t+.
The function does not check if the input is a proper 0-1 matrix.
Johannes Hüsing
link{WithinDeltaMat}
, link{ResperClot}
## No element may be shifted by more than two ## positions mat <- toeplitz(c(rep(1,3), rep(0,3))) perm <- ResperByrow(mat) perm