implement factory pattern
This commit is contained in:
+3
-11
@@ -33,10 +33,6 @@ source(here::here("R", "graphon_distribution.R"))
|
||||
#' generated.
|
||||
#' @param K Positive integer. Number of divisions of the unit interval;
|
||||
#' the resulting grid has length `K+1`.
|
||||
#' @param fv Density function of the latent variable \eqn{v}. Must be
|
||||
#' vectorised (i.e. accept a numeric vector and return a numeric
|
||||
#' vector of the same length). Typical examples are
|
||||
#' `dnorm`, `dexp`, ….
|
||||
#' @param Fv Cumulative distribution function of the latent variable
|
||||
#' \eqn{v}. Also has to be vectorised. Typical examples are
|
||||
#' `pnorm`, `pexp`, ….
|
||||
@@ -112,7 +108,6 @@ compute_matrix <- function(
|
||||
a,
|
||||
n,
|
||||
K,
|
||||
fv,
|
||||
Fv,
|
||||
fX=NULL,
|
||||
sample_X_fn=NULL,
|
||||
@@ -132,6 +127,7 @@ compute_matrix <- function(
|
||||
if (is.null(matrix_X) && is.null(sample_X_fn)) stop("Either 'matrix_X' or 'sample_X_fn' must be supplied!")
|
||||
if (!is.null(matrix_X) && !is.null(sample_X_fn)) warning("Both arguments 'matrix_X' and `sample_X_fn` is given. Priority is given by to the first!")
|
||||
if (!is.null(fX) && !is.function(fX)) stop("'fX' must be a density function")
|
||||
if (!is.logical(scaled)) stop("`scaled` must be a logical!")
|
||||
|
||||
## 1.2 Generate the Matrix X of covariates ===================================
|
||||
# If the argument matrix_X is present, use this matrix, otherwise generate one
|
||||
@@ -150,11 +146,7 @@ compute_matrix <- function(
|
||||
stop("Number of columns of X (", ncol(X), ") must equal length(a) (", length(a), ")")
|
||||
}
|
||||
|
||||
## 1.3 Create conditional density ============================================
|
||||
# this is not used in the computation
|
||||
# empir_cond_density <- create_cond_density(a, fv, Fv, X)
|
||||
|
||||
## 1.4 Compute the graphon quantiles =========================================
|
||||
## 1.3 Compute the graphon quantiles =========================================
|
||||
k <- seq(0, K) / K
|
||||
if (!is.null(guard)) {
|
||||
k[1] <- guard
|
||||
@@ -164,7 +156,7 @@ compute_matrix <- function(
|
||||
# expression. The intended use is for small values of n
|
||||
graphon_quantiles <- qgraphon(k, a = a, Fv = Fv, X_matrix = X, fX= fX)
|
||||
|
||||
## 1.5 Build the matrix Q ====================================================
|
||||
## 1.4 Build the matrix Q ====================================================
|
||||
inner_products = as.vector(X %*% a)
|
||||
|
||||
# outer(y, x, "-") gives a matrix with entry (j,i) = y[j] - x[i]
|
||||
|
||||
Reference in New Issue
Block a user