added floating point guard
This commit is contained in:
@@ -44,6 +44,10 @@ source("R/graphon_distribution.R")
|
|||||||
#' @param Fv Cumulative distribution function of the latent variable
|
#' @param Fv Cumulative distribution function of the latent variable
|
||||||
#' \eqn{v}. Also has to be vectorised. Typical examples are
|
#' \eqn{v}. Also has to be vectorised. Typical examples are
|
||||||
#' `pnorm`, `pexp`, ….
|
#' `pnorm`, `pexp`, ….
|
||||||
|
#' @param guard Positive numeric guard value. Default is `sqrt(.Machine$double.eps)`,
|
||||||
|
#' which is about `1.5e‑8` on most platforms – small enough to be negligible
|
||||||
|
#' for most computations. If it is null, then it is not used.
|
||||||
|
#' The guard is used for the value k = 0, which can cause arithmetic errors.
|
||||||
#'
|
#'
|
||||||
#' @return A numeric matrix **Q** of dimension `K × n`. The \eqn{j}-th row
|
#' @return A numeric matrix **Q** of dimension `K × n`. The \eqn{j}-th row
|
||||||
#' (for `j = 1,…,K`) contains the increments of the CDF evaluated at
|
#' (for `j = 1,…,K`) contains the increments of the CDF evaluated at
|
||||||
@@ -100,7 +104,8 @@ compute_matrix <- function(
|
|||||||
K,
|
K,
|
||||||
sample_X_fn,
|
sample_X_fn,
|
||||||
fv,
|
fv,
|
||||||
Fv
|
Fv,
|
||||||
|
guard = sqrt(.Machine$double.eps)
|
||||||
) {
|
) {
|
||||||
## 1.1 Check inputs ==========================================================
|
## 1.1 Check inputs ==========================================================
|
||||||
if (!is.numeric(seed) || length(seed) != 1) stop("'seed' must be a single number")
|
if (!is.numeric(seed) || length(seed) != 1) stop("'seed' must be a single number")
|
||||||
@@ -127,6 +132,9 @@ compute_matrix <- function(
|
|||||||
|
|
||||||
## 1.4 Compute the graphon quantiles =========================================
|
## 1.4 Compute the graphon quantiles =========================================
|
||||||
k <- seq(0, K) / K
|
k <- seq(0, K) / K
|
||||||
|
if (!is.null(guard)) {
|
||||||
|
k[1] <- guard
|
||||||
|
}
|
||||||
graphon_quantiles <- qgraphon(k, a = a, Fv = Fv, X_matrix = X)
|
graphon_quantiles <- qgraphon(k, a = a, Fv = Fv, X_matrix = X)
|
||||||
|
|
||||||
## 1.5 Build the matrix Q ====================================================
|
## 1.5 Build the matrix Q ====================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user