R/up_low.R

Defines functions up_low

Documented in up_low

#' Bounds of grid search function
#'
#' Description of the bounds of grid search function.
#'
#' This ancillary function finds the upper and lower bounds of the grid search
#' implemented in the kernel score test.
#'
#' The function returns an m x m matrix (where m is the number of networks) to
#' be used as input for the kernel function.
#'
#' @param dist_mat a square distance matrix
#'
#' @return a square matrix of the same dimensions of the input matrix, comprised
#' of the sum square differences.
#'
up_low <- function(dist_mat) {
  stopifnot(is.matrix(dist_mat))
  stopifnot(nrow(dist_mat) == ncol(dist_mat))
  sq_diff <- diag(nrow(dist_mat))
  for (i in 1:nrow(dist_mat)) {
    for (j in 1:nrow(dist_mat)) {
      sq_diff[i, j] <- sum((dist_mat[i, ] - dist_mat[j, ])^2)
    }
  }
  sq_diff
}

Try the CommKern package in your browser

Any scripts or data that you put into this service are public.

CommKern documentation built on Sept. 23, 2022, 5:07 p.m.