Skip to content

Commit

Permalink
add Frobenuis Norm
Browse files Browse the repository at this point in the history
  • Loading branch information
kalidouBA committed Dec 6, 2023
1 parent 067d947 commit 2d206ed
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
S3method(plot,DICEPRO)
export(DICEPRO)
export(computPerf)
export(compute_precision)
export(generateProp)
export(generate_ref_matrix)
export(heatmap_abundances)
Expand Down
34 changes: 34 additions & 0 deletions R/metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,37 @@ computPerf <- function(x, y, metric) {
return(perf)
}


#' Compute precision of sequential simulation
#'
#' This function computes the precision of sequential simulation by evaluating
#' the Frobenius norm of the difference between the covariance matrix of the model
#' (CY) and the covariance matrix of the simulated vector CY_tilde, normalized by
#' the Frobenius norm of the covariance matrix of the model (CY).
#'
#' @param CY The covariance matrix of the model.
#' @param CY_tilde The covariance matrix of the simulated vector.
#' @export
#'
#' @return The precision of sequential simulation.
#'
#' @examples
#' CY <- matrix(c(3, 5, 7, 2, 6, 4, 0, 2, 8), nrow=3, ncol=3, byrow=TRUE)
#' CY_tilde <- CY
#' precision <- compute_precision(CY, CY_tilde)
#' cat("Precision of sequential simulation:", precision, "\n")

compute_precision <- function(CY, CY_tilde) {
frobenius_norm <- function(matrix) {
sqrt(sum(matrix^2))
}


diff_matrix <- CY - CY_tilde
norm_diff <- frobenius_norm(diff_matrix)
norm_CY <- frobenius_norm(CY)

precision <- norm_diff / norm_CY

return(precision)
}
28 changes: 28 additions & 0 deletions man/compute_precision.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2d206ed

Please sign in to comment.