R/matrix_shuffle.R

Defines functions sim_matrix_shuffle row_shuffle_matrix_

Documented in sim_matrix_shuffle

#' @importFrom Matrix sparseMatrix
#' @keywords internal
row_shuffle_matrix_ <- function(rows) {
  return(
    sparseMatrix(i = 1:length(rows), j = rows, x = 1)
  )
}
  
#' @title Re-order a similarity matrix
#' @description Re-order columns / rows of a similarity matrix based on a given permutation.
#' @param X Matrix
#' @param row_order Integer vector, a permutation of \code{1:nrow(m)}.
#' @return A re-arranged similarity matrix (sparse & symmetric)
sim_matrix_shuffle <- function(X, row_order) {
  sh <- row_shuffle_matrix_(row_order)
  return (sh %*% X %*% sh)
}
ytoren/simscaleR documentation built on April 17, 2021, 12:32 p.m.