From e2901e5b8e7d777bf54c9e110d4717b93151c535 Mon Sep 17 00:00:00 2001 From: Ollie Date: Wed, 5 Nov 2025 14:55:53 +0000 Subject: [PATCH 01/15] New key_quanties computation under compute_fit no references changed as such all tests fail --- R/brglmFit.R | 186 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 130 insertions(+), 56 deletions(-) diff --git a/R/brglmFit.R b/R/brglmFit.R index f1d407f..99b2403 100644 --- a/R/brglmFit.R +++ b/R/brglmFit.R @@ -296,69 +296,143 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL } } - ## key_quantities, grad, info and bias are ALWAYS in beta, dispersion parameterization - key_quantities <- function(pars, y, level = 0, scale_totals = FALSE, qr = TRUE) { + # Always computes everything needed, stores it once, passes it around + compute_fit <- function(pars, y, x, weights, offset, family, + fixed_totals = NULL, row_totals = NULL, + no_dispersion = FALSE, nobs, nvars, keep) { + + # Extract Parameters betas <- pars[seq.int(nvars)] dispersion <- pars[nvars + 1] - prec <- 1/dispersion + precision <- 1 / dispersion + + # Basic Quantities etas <- drop(x %*% betas + offset) - mus <- linkinv(etas) - if (scale_totals) { - ## Rescale mus - mus_totals <- as.vector(tapply(mus, fixed_totals, sum))[fixed_totals] - mus <- mus * row_totals / mus_totals - etas <- linkfun(mus) + mus <- family$linkinv(etas) + mus_unscaled <- mus # Keep original for gradient computation + if (!is.null(fixed_totals)) { + mus_totals <- as.vector(tapply(mus, fixed_totals, sum))[fixed_totals] + mus <- mus * row_totals / mus_totals # Scaled version + etas <- family$linkfun(mus) # Update etas to match scaled mus } - out <- list(precision = prec, - betas = betas, - dispersion = dispersion, - etas = etas, - mus = mus, - scale_totals = scale_totals) - mean_quantities <- function(out) { - d1mus <- mu.eta(etas) - d2mus <- d2mu.deta(etas) - varmus <- variance(mus) - working_weights <- weights * d1mus^2 / varmus - wx <- sqrt(working_weights) * x - out$d1mus <- d1mus - out$d2mus <- d2mus - out$varmus <- varmus - out$d1varmus <- d1variance(mus) - out$working_weights <- working_weights - if (qr) out$qr_decomposition <- qr(wx) - out - } - dispersion_quantities <- function(out) { - zetas <- -weights * prec - out$zetas <- zetas - ## Evaluate the derivatives of the a function only for - ## objervations with non-zero weight + + # Mean Quantities + d1mus <- family$mu.eta(etas) + d2mus <- family$d2mu.deta(etas) + varmus <- family$variance(mus) + d1varmus <- family$d1variance(mus) + working_weights <- weights * d1mus^2 / varmus + + # QR Decomposition + wx <- sqrt(working_weights) * x + qr_decomposition <- qr(wx) + R_matrix <- qr.R(qr_decomposition) + + # Hat Values + # TODO: Avoid forming full Q? Approximate hat values? + Qmat <- qr.Q(qr_decomposition) + hatvalues <- .rowSums(Qmat * Qmat, nobs, nvars, TRUE) + + # Information Matrices + info_beta <- precision * crossprod(R_matrix) + inverse_info_beta <- dispersion * chol2inv(R_matrix) + + # Dispersion Quantities (dept on family) + if (!no_dispersion) { + zetas <- -weights * precision + + # Derivatives of cumulant function (only for non-zero weights) d1afuns <- d2afuns <- d3afuns <- rep(NA_real_, nobs) - d1afuns[keep] <- d1afun(zetas[keep]) - ## because of the way dev.resids is implemented, this is - ## d1afun is the expectation of dev.resids + 2 for gamma - ## families, so subtract 2 - if (family$family == "Gamma") d1afuns <- d1afuns - 2 - d2afuns[keep] <- d2afun(zetas[keep]) - d3afuns[keep] <- d3afun(zetas[keep]) - out$d2afuns <- d2afuns - out$d3afuns <- d3afuns - out$deviance_residuals <- dev.resids(y, mus, weights) - out$Edeviance_residuals <- weights * d1afuns - out - } - if (level == 0) { - out <- mean_quantities(out) - } - if (level == 1) { - out <- dispersion_quantities(out) + d1afuns[keep] <- family$d1afun(zetas[keep]) + d2afuns[keep] <- family$d2afun(zetas[keep]) + d3afuns[keep] <- family$d3afun(zetas[keep]) + + # Special case for Gamma family + if (family$family == "Gamma") { + d1afuns <- d1afuns - 2 + } + + # Deviance residuals + deviance_residuals <- family$dev.resids(y, mus, weights) + Edeviance_residuals <- weights * d1afuns + + # Information for dispersion parameter + info_zeta <- 0.5 * sum(weights^2 * d2afuns, na.rm = TRUE) / dispersion^4 + inverse_info_zeta <- 1 / info_zeta + } else { + # Fixed dispersion (binomial, Poisson) + zetas <- d1afuns <- d2afuns <- d3afuns <- NA_real_ + deviance_residuals <- family$dev.resids(y, mus, weights) + Edeviance_residuals <- NA_real_ + info_zeta <- inverse_info_zeta <- NA_real_ } - if (level > 1) { - out <- mean_quantities(out) - out <- dispersion_quantities(out) + + # Gradient Computation + # Use unscaled mus for gradient when fixed_totals is used + mus_for_gradient <- if (!is.null(fixed_totals)) mus_unscaled else mus + etas_for_gradient <- if (!is.null(fixed_totals)) family$linkfun(mus_unscaled) else etas + d1mus_for_gradient <- family$mu.eta(etas_for_gradient) + varmus_for_gradient <- family$variance(mus_for_gradient) + + score_components_beta <- weights * d1mus_for_gradient * (y - mus_for_gradient) / + varmus_for_gradient * x + grad_beta <- precision * .colSums(score_components_beta, nobs, nvars, TRUE) + + if (!no_dispersion) { + grad_zeta <- 0.5 * precision^2 * + sum(deviance_residuals - Edeviance_residuals, na.rm = TRUE) + } else { + grad_zeta <- NA_real_ } - out + + # Return all computed quantities as class + structure(list( + # Parameters + betas = betas, + dispersion = dispersion, + precision = precision, + + # Basic quantities + etas = etas, + mus = mus, + mus_unscaled = mus_unscaled, # For gradient with fixed_totals + + # Mean-related quantities + d1mus = d1mus, + d2mus = d2mus, + varmus = varmus, + d1varmus = d1varmus, + working_weights = working_weights, + + # QR decomposition and related + qr_decomposition = qr_decomposition, + R_matrix = R_matrix, + Q_matrix = Qmat, + hatvalues = hatvalues, + + # Information matrices (pre-computed) + info_beta = info_beta, + inverse_info_beta = inverse_info_beta, + + # Dispersion-related quantities + zetas = zetas, + d1afuns = d1afuns, + d2afuns = d2afuns, + d3afuns = d3afuns, + deviance_residuals = deviance_residuals, + Edeviance_residuals = Edeviance_residuals, + info_zeta = info_zeta, + inverse_info_zeta = inverse_info_zeta, + + # Gradients (pre-computed) + grad_beta = grad_beta, + grad_zeta = grad_zeta, + score_components_beta = score_components_beta, + + # Metadata + has_fixed_totals = !is.null(fixed_totals), + no_dispersion = no_dispersion + ), class = "brglmFit_quantities") } gradient <- function(pars, level = 0, fit = NULL) { From 16fa9fa2961b6563cdfb1265015c5c4336838729 Mon Sep 17 00:00:00 2001 From: Ollie Date: Fri, 7 Nov 2025 16:01:21 +0000 Subject: [PATCH 02/15] Updated calls to compute_fit from external functions, passes ~60 tests --- R/brglmFit.R | 320 +++++++++++++++++++++++++++------------------------ 1 file changed, 169 insertions(+), 151 deletions(-) diff --git a/R/brglmFit.R b/R/brglmFit.R index 99b2403..cf259bb 100644 --- a/R/brglmFit.R +++ b/R/brglmFit.R @@ -435,54 +435,34 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL ), class = "brglmFit_quantities") } - gradient <- function(pars, level = 0, fit = NULL) { - if (is.null(fit)) { - fit <- key_quantities(pars, y = y, level = level, qr = FALSE) + gradient <- function(pars, fit, level = 0) { + if (level == 0) { + return(fit$grad_beta) + } + else { + return(fit$grad_zeta) } - with(fit, { - if (level == 0) { - score_components <- weights * d1mus * (y - mus) / varmus * x - return(precision * .colSums(score_components, nobs, nvars, TRUE)) - } - if (level == 1) { - return(1/2 * precision^2 * sum(deviance_residuals - Edeviance_residuals, na.rm = TRUE)) - } - }) } - information <- function(pars, level = 0, fit = NULL, inverse = FALSE) { - if (is.null(fit)) { - fit <- key_quantities(pars, y = y, level = level, qr = TRUE) - } - with(fit, { - if (level == 0) { - R_matrix <- qr.R(qr_decomposition) - if (inverse) { - ## return(dispersion * tcrossprod(solve(R_matrix))) - return(dispersion * chol2inv(R_matrix)) - } else { - return(precision * crossprod(R_matrix)) - } + information <- function(pars, fit, level = 0, inverse = FALSE) { + if (level == 0) { + if (inverse) { + return(fit$inverse_info_beta) + } else { + return(fit$info_beta) } - if (level == 1) { - info <- 0.5 * sum(weights^2 * d2afuns, na.rm = TRUE)/dispersion^4 - if (inverse) { - return(1/info) - } else { - return(info) - } + } + else { + if (inverse) { + return(fit$inverse_info_zeta) + } else { + return(fit$info_zeta) } - }) + } } hat_values <- function(pars, fit = NULL) { - if (is.null(fit)) { - fit <- key_quantities(pars, y = y, level = 0, qr = TRUE) - } - with(fit, { - Qmat <- qr.Q(qr_decomposition) - .rowSums(Qmat * Qmat, nobs, nvars, TRUE) - }) + return(fit$hatvalues) } ## FIXME: Redundant function for now @@ -509,7 +489,18 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL if (df_residual > 0) { dispFit <- try(uniroot(f = function(phi) { theta <- c(betas, phi) - cfit <- key_quantities(theta, y = y, level = 1, qr = FALSE) + cfit <- compute_fit(pars = theta, + y = y, + x = x, + weights = weights, + offset = offset, + family = family, + fixed_totals = fixed_totals, + row_totals = row_totals, + no_dispersion = no_dispersion, + nobs = nobs, + nvars = nvars, + keep = keep) gradient(theta, level = 1, fit = cfit) }, lower = .Machine$double.eps, upper = 10000, tol = control$epsilon), silent = FALSE) if (inherits(dispFit, "try-error")) { @@ -527,123 +518,109 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL list(dispersion = disp, dispersion_ML = dispML) } - AS_mean_adjustment <- function(pars, level = 0, fit = NULL) { - if (is.null(fit)) { - fit <- key_quantities(pars, y = y, level = level, qr = TRUE) + AS_mean_adjustment <- function(pars, fit, level = 0) { + if (level == 0) { + # Zero division already handled by fit computation + adj <- .colSums(0.5 * fit$hatvalues * fit$d2mus / fit$d1mus * x, + nobs, nvars, TRUE) + return(adj) + } + else { + s1 <- sum(weights^3 * fit$d3afuns, na.rm = TRUE) + s2 <- sum(weights^2 * fit$d2afuns, na.rm = TRUE) + return((nvars - 2) / (2 * fit$dispersion) + + s1 / (2 * fit$dispersion^2 * s2)) } - with(fit, { - if (level == 0) { - hatvalues <- hat_values(pars, fit = fit) - ## Use only observations with keep = TRUE to ensure that no division with zero takes place - return(.colSums(0.5 * hatvalues * d2mus/d1mus * x, nobs, nvars, TRUE)) - } - if (level == 1) { - s1 <- sum(weights^3 * d3afuns, na.rm = TRUE) - s2 <- sum(weights^2 * d2afuns, na.rm = TRUE) - return((nvars - 2)/(2 * dispersion) + s1/(2 * dispersion^2 * s2)) - } - }) } - AS_Jeffreys_adjustment <- function(pars, level = 0, fit = NULL) { - if (is.null(fit)) { - fit <- key_quantities(pars, y = y, level = level, qr = TRUE) + AS_Jeffreys_adjustment <- function(pars, fit, level = 0, a = 0.5) { + if (level == 0) { + ## Use only observations with keep = TRUE to ensure that no division with zero takes place + return(2 * a * .colSums(0.5 * fit$hatvalues * (2 * fit$d2mus/fit$d1mus - fit$d1varmus * fit$d1mus / fit$varmus) * x, nobs, nvars, TRUE)) + } + else { + s1 <- sum(weights^3 * fit$d3afuns, na.rm = TRUE) + s2 <- sum(weights^2 * fit$d2afuns, na.rm = TRUE) + return(2 * a * (-(nvars + 4)/(2 * fit$dispersion) + s1/(2 * fit$dispersion^2 * s2))) } - with(fit, { - if (level == 0) { - hatvalues <- hat_values(pars, fit = fit) - ## Use only observations with keep = TRUE to ensure that no division with zero takes place - return(2 * control$a * .colSums(0.5 * hatvalues * (2 * d2mus/d1mus - d1varmus * d1mus / varmus) * x, nobs, nvars, TRUE)) - } - if (level == 1) { - s1 <- sum(weights^3 * d3afuns, na.rm = TRUE) - s2 <- sum(weights^2 * d2afuns, na.rm = TRUE) - return(2 * control$a * (-(nvars + 4)/(2 * dispersion) + s1/(2 * dispersion^2 * s2))) - } - }) } - AS_median_adjustment <- function(pars, level = 0, fit = NULL) { - if (is.null(fit)) { - fit <- key_quantities(pars, y = y, level = level, qr = TRUE) - } - with(fit, { - if (level == 0) { - hatvalues <- hat_values(pars, fit = fit) - R_matrix <- qr.R(qr_decomposition) - info_unscaled <- crossprod(R_matrix) - inverse_info_unscaled <- chol2inv(R_matrix) - ## FIXME: There is 1) definitely a better way to do this, 2) no time... - b_vector <- numeric(nvars) - for (j in seq.int(nvars)) { - inverse_info_unscaled_j <- inverse_info_unscaled[j, ] - vcov_j <- tcrossprod(inverse_info_unscaled_j) / inverse_info_unscaled_j[j] - hats_j <- .rowSums((x %*% vcov_j) * x, nobs, nvars, TRUE) * working_weights - b_vector[j] <- inverse_info_unscaled_j %*% .colSums(x * (hats_j * (d1mus * d1varmus / (6 * varmus) - 0.5 * d2mus/d1mus)), nobs, nvars, TRUE) - } - return(.colSums(0.5 * hatvalues * d2mus / d1mus * x, nobs, nvars, TRUE) + - info_unscaled %*% b_vector) - } - if (level == 1) { - s1 <- sum(weights^3 * d3afuns, na.rm = TRUE) - s2 <- sum(weights^2 * d2afuns, na.rm = TRUE) - return(nvars/(2 * dispersion) + s1/(6 * dispersion^2 * s2)) + AS_median_adjustment <- function(pars, fit, level = 0) { + if (level == 0) { + info_unscaled <- fit$info_beta / fit$precision + inverse_info_unscaled <- fit$inverse_info_beta / fit$dispersion + + ## TODO: Below fixme? + ## FIXME: There is 1) definitely a better way to do this, 2) no time... + b_vector <- numeric(nvars) + for (j in seq.int(nvars)) { + inverse_info_unscaled_j <- inverse_info_unscaled[j, ] + vcov_j <- tcrossprod(inverse_info_unscaled_j) / inverse_info_unscaled_j[j] + hats_j <- .rowSums((x %*% vcov_j) * x, nobs, nvars, TRUE) * fit$working_weights + b_vector[j] <- inverse_info_unscaled_j %*% .colSums(x * (hats_j * (fit$d1mus * fit$d1varmus / (6 * fit$varmus) - 0.5 * fit$d2mus/fit$d1mus)), nobs, nvars, TRUE) } - }) + return(.colSums(0.5 * fit$hatvalues * fit$d2mus / fit$d1mus * x, + nobs, nvars, TRUE) + + info_unscaled %*% b_vector) + } + else { + s1 <- sum(weights^3 * fit$d3afuns, na.rm = TRUE) + s2 <- sum(weights^2 * fit$d2afuns, na.rm = TRUE) + return(nvars / (2 * fit$dispersion) + + s1 / (6 * fit$dispersion^2 * s2)) + } } AS_mixed_adjustment <- function(pars, level = 0, fit = NULL) { - if (is.null(fit)) { - fit <- key_quantities(pars, y = y, level = level, qr = TRUE) + if (level == 0) { + ## Use only observations with keep = TRUE to ensure that no division with zero takes place + return(.colSums(0.5 * fit$hatvalues * fit$d2mus/fit$d1mus * x, nobs, nvars, TRUE)) + } + else { + s1 <- sum(weights^3 * fit$d3afuns, na.rm = TRUE) + s2 <- sum(weights^2 * fit$d2afuns, na.rm = TRUE) + return(nvars / (2 * fit$dispersion) + + s1 / (6 * fit$dispersion^2 * s2)) } - with(fit, { - if (level == 0) { - hatvalues <- hat_values(pars, fit = fit) - ## Use only observations with keep = TRUE to ensure that no division with zero takes place - return(.colSums(0.5 * hatvalues * d2mus/d1mus * x, nobs, nvars, TRUE)) - } - if (level == 1) { - s1 <- sum(weights^3 * d3afuns, na.rm = TRUE) - s2 <- sum(weights^2 * d2afuns, na.rm = TRUE) - return(nvars/(2 * dispersion) + s1/(6 * dispersion^2 * s2)) - } - }) } ## compute_step_components does everything on the scale of the /transformed/ dispersion - compute_step_components <- function(pars, level = 0, fit = NULL) { - if (is.null(fit)) { - fit <- key_quantities(pars, y = y, level = level, qr = TRUE) - } + compute_step_components <- function(pars, fit, level = 0, adjustment_function, control) { + if (level == 0) { - grad <- gradient(pars, fit = if (has_fixed_totals) NULL else fit, level = 0) - inverse_info <- try(information(pars, inverse = TRUE, fit = fit, level = 0)) - failed_inversion <- inherits(inverse_info, "try-error") + # Beta components + grad <- fit$grad_beta + inverse_info <- fit$inverse_info_beta adjustment <- adjustment_function(pars, fit = fit, level = 0) + failed_adjustment <- any(is.na(adjustment)) + failed_inversion <- FALSE # Already computed successfully } - if (level == 1) { - if (no_dispersion | df_residual < 1) { + else { + # Dispersion components + if (fit$no_dispersion || df_residual < 1) { grad <- adjustment <- inverse_info <- NA_real_ failed_adjustment <- failed_inversion <- FALSE } else { - d1zeta <- eval(d1_transformed_dispersion) - d2zeta <- eval(d2_transformed_dispersion) - grad <- gradient(theta, fit = fit, level = 1)/d1zeta - inverse_info <- 1/information(theta, inverse = FALSE, fit = fit, level = 1) * d1zeta^2 + d1zeta <- eval(control$d1_transformed_dispersion) + d2zeta <- eval(control$d2_transformed_dispersion) + + grad <- fit$grad_zeta / d1zeta + inverse_info <- fit$inverse_info_zeta * d1zeta^2 + adjustment <- adjustment_function(pars, fit = fit, level = 1) / d1zeta - + 0.5 * d2zeta / d1zeta^2 + failed_inversion <- !is.finite(inverse_info) - ## adjustment <- adjustment_function(theta, fit = fit, level = 1)/d1zeta - if (is_ML | is_AS_median) 0 else 0.5 * d2zeta / d1zeta^2 - adjustment <- adjustment_function(theta, fit = fit, level = 1)/d1zeta - 0.5 * d2zeta / d1zeta^2 failed_adjustment <- is.na(adjustment) } } - out <- list(grad = grad, - inverse_info = inverse_info, - adjustment = adjustment, - failed_adjustment = failed_adjustment, - failed_inversion = failed_inversion) - out + + list(grad = grad, + inverse_info = inverse_info, + adjustment = adjustment, + failed_adjustment = failed_adjustment, + failed_inversion = failed_inversion) } customTransformation <- is.list(control$transformation) & length(control$transformation) == 2 @@ -910,13 +887,27 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL ## Evaluate at the starting values theta <- c(betas, dispersion) transformed_dispersion <- eval(control$Trans) - ## Mean quantities - ## If fixed_totals is provided (i.e. multinomial regression - ## via the Poisson trick) then evaluate everything expect - ## the score function at the scaled fitted means - quantities <- key_quantities(theta, y = y, level = 2 * !no_dispersion, scale_totals = has_fixed_totals, qr = TRUE) - step_components_beta <- compute_step_components(theta, level = 0, fit = quantities) - step_components_zeta <- compute_step_components(theta, level = 1, fit = quantities) + + ## Compute fit + fit <- compute_fit(pars = theta, + y = y, + x = x, + weights = weights, + offset = offset, + family = family, + fixed_totals = fixed_totals, + row_totals = row_totals, + no_dispersion = no_dispersion, + nobs = nobs, + nvars = nvars, + keep = keep) + + step_components_beta <- compute_step_components(theta, level = 0, fit = fit, + adjustment_function = adjustment_function, + control = control) + step_components_zeta <- compute_step_components(theta, level = 1, fit = fit, + adjustment_function = adjustment_function, + control = control) if (step_components_beta$failed_inversion) { warning("failed to invert the information matrix") } @@ -977,16 +968,32 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL transformed_dispersion <- eval(control$Trans) ## Mean quantities - quantities <- try(key_quantities(theta, y = y, level = 2 * !no_dispersion, scale_totals = has_fixed_totals, qr = TRUE), silent = TRUE) + fit <- try(compute_fit(pars = theta, + y = y, + x = x, + weights = weights, + offset = offset, + family = family, + fixed_totals = fixed_totals, + row_totals = row_totals, + no_dispersion = no_dispersion, + nobs = nobs, + nvars = nvars, + keep = keep), silent = TRUE) + ## This is to capture qr failing and revering to previous estimates - if (failed_adjustment_beta <- inherits(quantities, "try-error")) { + if (failed_adjustment_beta <- inherits(fit, "try-error")) { ## betas <- betas0 ## dispersion <- dispersion0 warning("failed to calculate score adjustment") break } - step_components_beta <- compute_step_components(theta, level = 0, fit = quantities) - step_components_zeta <- compute_step_components(theta, level = 1, fit = quantities) + step_components_beta <- compute_step_components(theta, level = 0, fit = fit, + adjustment_function = adjustment_function, + control = control) + step_components_zeta <- compute_step_components(theta, level = 1, fit = fit, + adjustment_function = adjustment_function, + control = control) if (failed_inversion_beta <- step_components_beta$failed_inversion) { warning("failed to invert the information matrix") break @@ -1068,15 +1075,26 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL ## calculating QR decompositions, fitted values, etas, ## residuals and working_weights - quantities <- key_quantities(c(betas, dispersion), y = y, level = 2 * !no_dispersion, scale_totals = has_fixed_totals, qr = TRUE) - - qr.Wx <- quantities$qr_decomposition - - mus <- quantities$mus - etas <- quantities$etas + fit <- compute_fit(pars = c(betas, dispersion), + y = y, + x = x, + weights = weights, + offset = offset, + family = family, + fixed_totals = fixed_totals, + row_totals = row_totals, + no_dispersion = no_dispersion, + nobs = nobs, + nvars = nvars, + keep = keep) + + qr.Wx <- fit$qr_decomposition + + mus <- fit$mus + etas <- fit$etas ## Residuals - residuals <- with(quantities, (y - mus)/d1mus) - working_weights <- quantities$working_weights + residuals <- with(fit, (y - mus)/d1mus) + working_weights <- fit$working_weights ## info_transformed_dispersion will be NA if is_ML | is_AS_median | is_AS_mixed info_transformed_dispersion <- 1/step_components_zeta$inverse_info From 89574ba510ffd9929cb48ce80e1714ea64c312c0 Mon Sep 17 00:00:00 2001 From: Ollie Date: Fri, 7 Nov 2025 16:28:12 +0000 Subject: [PATCH 03/15] Tests passing, not utilising scope with control --- R/brglmFit.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/brglmFit.R b/R/brglmFit.R index cf259bb..35629bb 100644 --- a/R/brglmFit.R +++ b/R/brglmFit.R @@ -603,14 +603,14 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL grad <- adjustment <- inverse_info <- NA_real_ failed_adjustment <- failed_inversion <- FALSE } else { - d1zeta <- eval(control$d1_transformed_dispersion) - d2zeta <- eval(control$d2_transformed_dispersion) + d1zeta <- eval(d1_transformed_dispersion) + d2zeta <- eval(d2_transformed_dispersion) grad <- fit$grad_zeta / d1zeta inverse_info <- fit$inverse_info_zeta * d1zeta^2 adjustment <- adjustment_function(pars, fit = fit, level = 1) / d1zeta - 0.5 * d2zeta / d1zeta^2 - + failed_inversion <- !is.finite(inverse_info) failed_adjustment <- is.na(adjustment) } From e98f8a589f441eb1d896f9c14775bf0e7bd646ff Mon Sep 17 00:00:00 2001 From: Ollie Date: Fri, 7 Nov 2025 23:07:41 +0000 Subject: [PATCH 04/15] Tests passing with no errors or warnings. Added parameters that specify whether qr decomp and hatvalues are needed for computation --- R/brglmFit.R | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/R/brglmFit.R b/R/brglmFit.R index 35629bb..a67b28d 100644 --- a/R/brglmFit.R +++ b/R/brglmFit.R @@ -299,7 +299,8 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL # Always computes everything needed, stores it once, passes it around compute_fit <- function(pars, y, x, weights, offset, family, fixed_totals = NULL, row_totals = NULL, - no_dispersion = FALSE, nobs, nvars, keep) { + no_dispersion = FALSE, nobs, nvars, keep, + need_qr = TRUE, need_hatvalues = TRUE) { # Extract Parameters betas <- pars[seq.int(nvars)] @@ -323,19 +324,26 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL d1varmus <- family$d1variance(mus) working_weights <- weights * d1mus^2 / varmus - # QR Decomposition - wx <- sqrt(working_weights) * x - qr_decomposition <- qr(wx) - R_matrix <- qr.R(qr_decomposition) + # QR Decomposition and Hat Values (only if needed) + qr_decomposition <- R_matrix <- Q_matrix <- hatvalues <- NULL + info_beta <- inverse_info_beta <- NULL - # Hat Values # TODO: Avoid forming full Q? Approximate hat values? - Qmat <- qr.Q(qr_decomposition) - hatvalues <- .rowSums(Qmat * Qmat, nobs, nvars, TRUE) - - # Information Matrices - info_beta <- precision * crossprod(R_matrix) - inverse_info_beta <- dispersion * chol2inv(R_matrix) + if (need_qr) { + wx <- sqrt(working_weights) * x + qr_decomposition <- qr(wx) + R_matrix <- qr.R(qr_decomposition) + + # Information Matrices + info_beta <- precision * crossprod(R_matrix) + inverse_info_beta <- dispersion * chol2inv(R_matrix) + + # Hat Values (only if needed and we have QR) + if (need_hatvalues) { + Q_matrix <- qr.Q(qr_decomposition) + hatvalues <- .rowSums(Q_matrix * Q_matrix, nobs, nvars, TRUE) + } + } # Dispersion Quantities (dept on family) if (!no_dispersion) { @@ -407,7 +415,7 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL # QR decomposition and related qr_decomposition = qr_decomposition, R_matrix = R_matrix, - Q_matrix = Qmat, + Q_matrix = Q_matrix, hatvalues = hatvalues, # Information matrices (pre-computed) @@ -500,7 +508,9 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL no_dispersion = no_dispersion, nobs = nobs, nvars = nvars, - keep = keep) + keep = keep, + need_qr = FALSE, + need_hatvalues = FALSE) gradient(theta, level = 1, fit = cfit) }, lower = .Machine$double.eps, upper = 10000, tol = control$epsilon), silent = FALSE) if (inherits(dispFit, "try-error")) { @@ -900,7 +910,9 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL no_dispersion = no_dispersion, nobs = nobs, nvars = nvars, - keep = keep) + keep = keep, + need_qr = TRUE, + need_hatvalues = TRUE) step_components_beta <- compute_step_components(theta, level = 0, fit = fit, adjustment_function = adjustment_function, @@ -979,7 +991,9 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL no_dispersion = no_dispersion, nobs = nobs, nvars = nvars, - keep = keep), silent = TRUE) + keep = keep, + need_qr = TRUE, + need_hatvalues = TRUE), silent = TRUE) ## This is to capture qr failing and revering to previous estimates if (failed_adjustment_beta <- inherits(fit, "try-error")) { @@ -1086,7 +1100,9 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL no_dispersion = no_dispersion, nobs = nobs, nvars = nvars, - keep = keep) + keep = keep, + need_qr = TRUE, + need_hatvalues = FALSE) qr.Wx <- fit$qr_decomposition From 0537b8799a2f56ea57bc96c47f3f09ce7755f473 Mon Sep 17 00:00:00 2001 From: Ollie Date: Mon, 10 Nov 2025 10:36:26 +0000 Subject: [PATCH 05/15] Cleaned up compute_step_components as unnecessary parameters passed --- R/brglmFit.R | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/R/brglmFit.R b/R/brglmFit.R index a67b28d..b33ab8d 100644 --- a/R/brglmFit.R +++ b/R/brglmFit.R @@ -596,7 +596,7 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL ## compute_step_components does everything on the scale of the /transformed/ dispersion - compute_step_components <- function(pars, fit, level = 0, adjustment_function, control) { + compute_step_components <- function(pars, fit, level = 0) { if (level == 0) { # Beta components @@ -914,12 +914,8 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL need_qr = TRUE, need_hatvalues = TRUE) - step_components_beta <- compute_step_components(theta, level = 0, fit = fit, - adjustment_function = adjustment_function, - control = control) - step_components_zeta <- compute_step_components(theta, level = 1, fit = fit, - adjustment_function = adjustment_function, - control = control) + step_components_beta <- compute_step_components(theta, level = 0, fit = fit) + step_components_zeta <- compute_step_components(theta, level = 1, fit = fit) if (step_components_beta$failed_inversion) { warning("failed to invert the information matrix") } @@ -1002,12 +998,8 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL warning("failed to calculate score adjustment") break } - step_components_beta <- compute_step_components(theta, level = 0, fit = fit, - adjustment_function = adjustment_function, - control = control) - step_components_zeta <- compute_step_components(theta, level = 1, fit = fit, - adjustment_function = adjustment_function, - control = control) + step_components_beta <- compute_step_components(theta, level = 0, fit = fit) + step_components_zeta <- compute_step_components(theta, level = 1, fit = fit) if (failed_inversion_beta <- step_components_beta$failed_inversion) { warning("failed to invert the information matrix") break From ed72ddd9f43c82dcc70739888b32ee1d317538a2 Mon Sep 17 00:00:00 2001 From: Ollie Date: Mon, 10 Nov 2025 14:40:06 +0000 Subject: [PATCH 06/15] Add benchmarking suite for fit-streamline feature --- benchmarks/check_setup.R | 203 ++++++++++++ benchmarks/main_benchmark.R | 293 ++++++++++++++++++ .../20251110_142635/benchmark_data.RData | Bin 0 -> 2082 bytes .../20251110_142635/benchmark_results.txt | 165 ++++++++++ .../plots/01_lizards_comparison.png | Bin 0 -> 581 bytes .../plots/02_endometrial_comparison.png | Bin 0 -> 581 bytes .../plots/03_speedup_summary.png | Bin 0 -> 581 bytes .../plots/04_absolute_timing.png | Bin 0 -> 581 bytes .../plots/05_lizards_distribution.png | Bin 0 -> 581 bytes .../plots/summary_statistics.csv | 5 + .../results/20251110_142635/test_results.txt | 3 + benchmarks/run_all.R | 69 +++++ benchmarks/setup.R | 134 ++++++++ benchmarks/visualize_results.R | 168 ++++++++++ 14 files changed, 1040 insertions(+) create mode 100644 benchmarks/check_setup.R create mode 100644 benchmarks/main_benchmark.R create mode 100644 benchmarks/results/20251110_142635/benchmark_data.RData create mode 100644 benchmarks/results/20251110_142635/benchmark_results.txt create mode 100644 benchmarks/results/20251110_142635/plots/01_lizards_comparison.png create mode 100644 benchmarks/results/20251110_142635/plots/02_endometrial_comparison.png create mode 100644 benchmarks/results/20251110_142635/plots/03_speedup_summary.png create mode 100644 benchmarks/results/20251110_142635/plots/04_absolute_timing.png create mode 100644 benchmarks/results/20251110_142635/plots/05_lizards_distribution.png create mode 100644 benchmarks/results/20251110_142635/plots/summary_statistics.csv create mode 100644 benchmarks/results/20251110_142635/test_results.txt create mode 100644 benchmarks/run_all.R create mode 100644 benchmarks/setup.R create mode 100644 benchmarks/visualize_results.R diff --git a/benchmarks/check_setup.R b/benchmarks/check_setup.R new file mode 100644 index 0000000..365bcd7 --- /dev/null +++ b/benchmarks/check_setup.R @@ -0,0 +1,203 @@ +# Setup Verification Script +# Run this first to check that everything is configured correctly + +cat("\n") +cat(strrep("=", 70), "\n") +cat("BRGLM2 BENCHMARK SETUP VERIFICATION\n") +cat(strrep("=", 70), "\n\n") + +# ====== Check R Version ====== +cat("1. Checking R version...\n") +r_version <- R.version.string +cat(" ", r_version, "\n") +if (getRversion() < "4.0.0") { + cat("WARNING: R version 4.0.0 or higher recommended\n") +} +cat("OK\n\n") + +# ====== Check Required Packages ====== +cat("2. Checking required packages...\n") +required_pkgs <- c("tictoc", "rbenchmark", "microbenchmark", "ggplot2", "tinytest") + +missing_pkgs <- c() +for (pkg in required_pkgs) { + if (requireNamespace(pkg, quietly = TRUE)) { + cat("OK", pkg, "installed\n") + } else { + cat("FAIL", pkg, "NOT FOUND\n") + missing_pkgs <- c(missing_pkgs, pkg) + } +} + +if (length(missing_pkgs) > 0) { + cat("\nInstalling missing packages...\n") + install.packages(missing_pkgs) + cat("OK Installation complete\n") +} else { + cat("OK All packages available\n") +} +cat("\n") + +# ====== Check Library Paths ====== +cat("3. Checking library paths...\n") + +# Read paths from setup.R if it exists +setup_file <- "benchmarks/setup.R" +if (file.exists(setup_file)) { + source(setup_file, local = TRUE) + + cat("Original library:", LIB_ORIGINAL, "\n") + if (dir.exists(LIB_ORIGINAL)) { + cat("OK Original library exists\n") + + # Check if brglm2 is there + if (file.exists(file.path(LIB_ORIGINAL, "brglm2"))) { + cat("OK brglm2 package found in original library\n") + } else { + cat("FAIL brglm2 package NOT found in original library\n") + } + } else { + cat("FAIL Original library path does NOT exist\n") + cat("Please update LIB_ORIGINAL in benchmarks/setup.R\n") + } + + cat("\nNew library:", LIB_NEW, "\n") + if (dir.exists(LIB_NEW)) { + cat("OK New library exists\n") + + # Check if brglm2 is there + if (file.exists(file.path(LIB_NEW, "brglm2"))) { + cat("OK brglm2 package found in new library\n") + } else { + cat("FAIL brglm2 package NOT found in new library\n") + } + } else { + cat("FAIL New library path does NOT exist\n") + cat("Please update LIB_NEW in benchmarks/setup.R\n") + } +} else { + cat("FAIL setup.R not found\n") + cat("Please ensure you're in the project root directory\n") +} +cat("\n") + +# ====== Check Package Path (for tests) ====== +cat("4. Checking package path for tests...\n") +pkg_path <- "C:/Users/ollie/OneDrive/Desktop/UNI/Project brglm2/brglm2" + +if (dir.exists(pkg_path)) { + cat("OK Package directory exists:", pkg_path, "\n") + + # Check for key files + key_files <- c("DESCRIPTION", "NAMESPACE", "R", "tests") + for (f in key_files) { + if (file.exists(file.path(pkg_path, f))) { + cat("OK", f, "found\n") + } else { + cat("FAIL", f, "NOT found\n") + } + } +} else { + cat("FAIL Package directory does NOT exist\n") + cat("Please update pkg_path in main_benchmark.R\n") +} +cat("\n") + +# ====== Check Datasets ====== +cat("5. Checking dataset availability...\n") + +# Try to load brglm2 from somewhere to access datasets +tryCatch({ + suppressWarnings(library(brglm2)) + + # Check each dataset + datasets_to_check <- c("lizards", "endometrial", "MultipleFeatures") + for (ds in datasets_to_check) { + tryCatch({ + data(list = ds, package = "brglm2") + if (exists(ds)) { + cat("OK", ds, "dataset accessible\n") + } + }, error = function(e) { + cat("FAIL", ds, "dataset NOT accessible\n") + }) + } + + cat("OK All datasets available\n") +}, error = function(e) { + cat("Could not load brglm2 to check datasets\n") + cat("This is OK if you're setting up for the first time\n") +}) +cat("\n") + +# ====== Check Results Directory ====== +cat("6. Checking results directory...\n") +results_dir <- "benchmarks/results" + +if (!dir.exists(results_dir)) { + cat("Creating results directory...\n") + dir.create(results_dir, recursive = TRUE) + cat("OK Results directory created\n") +} else { + cat("OK Results directory exists\n") + + # Check for previous results + existing_results <- list.dirs(results_dir, recursive = FALSE) + if (length(existing_results) > 0) { + cat("Found", length(existing_results), "previous benchmark run(s)\n") + latest <- existing_results[which.max(file.info(existing_results)$mtime)] + cat("Latest:", basename(latest), "\n") + } +} +cat("\n") + +# ====== Summary ====== +cat(strrep("=", 70), "\n") +cat("VERIFICATION SUMMARY\n") +cat(strrep("=", 70), "\n\n") + +# Collect all checks +checks <- list( + "R version" = TRUE, # We always have R running this + "Packages" = length(missing_pkgs) == 0, + "Library paths" = exists("LIB_ORIGINAL") && exists("LIB_NEW") && + dir.exists(LIB_ORIGINAL) && dir.exists(LIB_NEW), + "Package path" = dir.exists(pkg_path), + "Results directory" = dir.exists(results_dir) +) + +all_ok <- all(unlist(checks)) + +if (all_ok) { + cat("ALL CHECKS PASSED\n\n") + cat("You're ready to run benchmarks!\n\n") + cat("Run the full suite with:\n") + cat(" source('benchmarks/run_all.R')\n\n") + cat("Or run individual components:\n") + cat(" source('benchmarks/main_benchmark.R') # Main benchmarks\n") + cat(" source('benchmarks/visualize_results.R') # Generate plots\n") +} else { + cat("SOME CHECKS FAILED\n\n") + cat("Please fix the issues above before running benchmarks.\n\n") + + cat("Common fixes:\n") + cat("1. Update library paths in benchmarks/setup.R\n") + cat("2. Install missing packages\n") + cat("3. Ensure you're in the correct working directory\n") + cat("4. Check that brglm2 is installed in both library locations\n") +} + +cat("\n", strrep("=", 70), "\n\n") + +# ====== Helpful Commands ====== +cat("Helpful commands:\n\n") +cat("Check current working directory:\n") +cat(" getwd()\n\n") +cat("Change working directory:\n") +cat(" setwd('path/to/project')\n\n") +cat("Install a package:\n") +cat(" install.packages('package_name')\n\n") +cat("List installed packages:\n") +cat(" installed.packages()[,c('Package', 'LibPath')]\n\n") +cat("Check where package is installed:\n") +cat(" find.package('brglm2')\n\n") \ No newline at end of file diff --git a/benchmarks/main_benchmark.R b/benchmarks/main_benchmark.R new file mode 100644 index 0000000..441df5a --- /dev/null +++ b/benchmarks/main_benchmark.R @@ -0,0 +1,293 @@ +# Add microbenchmark library +library(microbenchmark) + +# Create results directory with timestamp +timestamp <- format(Sys.time(), "%Y%m%d_%H%M%S") +results_dir <- file.path("benchmarks", "results", timestamp) +dir.create(results_dir, recursive = TRUE) + +# Redirect output to file +sink(file.path(results_dir, "benchmark_results.txt"), split = TRUE) + +tryCatch({ + separator <- strrep("=", 70) + + cat(separator, "\n") + cat("BRGLM2 COMPREHENSIVE BENCHMARKING RESULTS\n") + cat("Timestamp:", timestamp, "\n") + cat(separator, "\n\n") + +# ====== SECTION 1: Test Suite Execution ====== +cat("\n", separator, "\n") +cat("SECTION 1: TEST SUITE EXECUTION\n") +cat(separator, "\n\n") + +pkg_path <- "C:/Users/ollie/OneDrive/Desktop/UNI/Project brglm2/brglm2" + +# Ensure DD is available in case internal calls need it +if (!exists("DD", mode = "function")) { + DD <- function(expr, name, order = 1) { + if(order < 1) stop("'order' must be >= 1") + if(order == 1) D(expr, name) + else DD(D(expr, name), name, order - 1) + } +} + +run_test_suite <- function(libpath, label) { + cat("Running test suite for", label, "version...\n") + cat("Library path:", libpath, "\n\n") + + # Load brglm2 version + library(brglm2, lib.loc = libpath) + library(tinytest) + + # Run test suite, timing total duration + start <- Sys.time() + result <- test_all(pkg_path) + elapsed <- as.numeric(difftime(Sys.time(), start, units = "secs")) + + # Summarise results safely + sum_df <- as.data.frame(result) + if ("ok" %in% names(sum_df)) { + passes <- sum(sum_df$ok) + fails <- sum(!sum_df$ok) + } else { + # fallback if tinytest version differs + passes <- NA + fails <- NA + warning("Could not extract passes/fails from test results") + } + + cat(sprintf("All ok, %d results (%.1fs)\n\n", passes + fails, elapsed)) + + invisible(list(result = result, passes = passes, fails = fails, elapsed = elapsed)) +} + +# --- Run NEW version --- +new_results <- run_test_suite(LIB_NEW, "NEW") + +# --- Run ORIGINAL version --- +orig_results <- run_test_suite(LIB_ORIGINAL, "ORIGINAL") + +# --- Save summary file (concise) --- +test_output_file <- file.path(results_dir, "test_results.txt") +cat(sprintf( + "Original: %d tests (%.1fs)\nNew: %d tests (%.1fs)\nSpeedup: %.2fx faster\n", + orig_results$passes + orig_results$fails, orig_results$elapsed, + new_results$passes + new_results$fails, new_results$elapsed, + orig_results$elapsed / new_results$elapsed +), file = test_output_file) + +cat("\nDetailed test results saved to:", test_output_file, "\n") + + # ====== SECTION 2: Microbenchmark Comparison ====== + cat("\n", separator, "\n") + cat("SECTION 2: MICROBENCHMARK COMPARISON\n") + cat("(100 evaluations with unit: seconds)\n") + cat(separator, "\n\n") + + cat("Test: Lizards dataset (small)\n") + lizards_bench <- microbenchmark( + original = glm(full_fm, data = lizards, + family = binomial(), + method = brglm2_original, + maxit = 200), + new = glm(full_fm, data = lizards, + family = binomial(), + method = brglm2_new, + maxit = 200), + times = 100, + unit = "s" + ) + print(lizards_bench) + + cat("\n\nSpeedup factor:", + median(lizards_bench$time[lizards_bench$expr == "original"]) / + median(lizards_bench$time[lizards_bench$expr == "new"]), "x\n") + + # ====== SECTION 3: Endometrial Dataset Test ====== + cat("\n", separator, "\n") + cat("SECTION 3: ENDOMETRIAL DATASET (PROBIT LINK)\n") + cat(separator, "\n\n") + + data("endometrial", package = "brglm2") + endo_fm <- HG ~ NV + PI + EH + + cat("Microbenchmark (50 evaluations):\n") + endo_bench <- microbenchmark( + original = glm(endo_fm, data = endometrial, + family = binomial("probit"), + method = brglm2_original, + maxit = 200), + new = glm(endo_fm, data = endometrial, + family = binomial("probit"), + method = brglm2_new, + maxit = 200), + times = 50, + unit = "s" + ) + print(endo_bench) + + cat("\n\nSpeedup factor:", + median(endo_bench$time[endo_bench$expr == "original"]) / + median(endo_bench$time[endo_bench$expr == "new"]), "x\n") + + # ====== SECTION 4: MultipleFeatures Dataset (Large, High-Dimensional) ====== + cat("\n", separator, "\n") + cat("SECTION 4: MULTIPLEFEATURES DATASET (HIGH-DIMENSIONAL)\n") + cat("Reference: Sterzinger & Kosmidis (2024, Section 8)\n") + cat(separator, "\n\n") + + if (exists("MultipleFeatures", envir = .GlobalEnv)) { + rm(MultipleFeatures, envir = .GlobalEnv) + } + data("MultipleFeatures", package = "brglm2") + + # Prepare data following the documentation example + vars <- grep("fou|kar", names(MultipleFeatures), value = TRUE) + train_id <- which(MultipleFeatures$training) + MultipleFeatures[train_id, vars] <- scale(MultipleFeatures[train_id, vars], scale = FALSE) + + # Calculate kappa for MDYPL + kappa <- length(vars) / sum(MultipleFeatures$training) + + # Create formula for full model + full_mf_fm <- formula(paste("I(digit == 7) ~", paste(vars, collapse = " + "))) + + cat("Dataset info:\n") + cat(" Total observations:", nrow(MultipleFeatures), "\n") + cat(" Training observations:", sum(MultipleFeatures$training), "\n") + cat(" Number of features:", length(vars), "\n") + cat(" Dimensionality ratio (kappa):", round(kappa, 4), "\n\n") + + cat("Running single timing test...\n\n") + + cat("Original version timing:\n") + time_mf_orig <- system.time({ + fit_mf_orig <- glm(full_mf_fm, data = MultipleFeatures, + family = binomial(), + method = brglm2_original, + subset = training, + maxit = 200) + }) + print(time_mf_orig) + cat("\n") + + cat("New version timing:\n") + time_mf_new <- system.time({ + fit_mf_new <- glm(full_mf_fm, data = MultipleFeatures, + family = binomial(), + method = brglm2_new, + subset = training, + maxit = 200) + }) + print(time_mf_new) + cat("\n") + + cat("MultipleFeatures speedup:", + time_mf_orig["elapsed"] / time_mf_new["elapsed"], "x\n") + + # Verify coefficients match + cat("\nNumerical verification:\n") + cat(" Coefficients match:", + isTRUE(all.equal(coef(fit_mf_orig), coef(fit_mf_new), tolerance = 1e-10)), "\n") + cat(" Max coefficient difference:", + max(abs(coef(fit_mf_orig) - coef(fit_mf_new))), "\n") + cat(" Deviance match:", + isTRUE(all.equal(fit_mf_orig$deviance, fit_mf_new$deviance, tolerance = 1e-10)), "\n") + + # ====== SECTION 5: MDYPL Method Test ====== + cat("\n", separator, "\n") + cat("SECTION 5: MDYPL METHOD (MultipleFeatures)\n") + cat("Maximum Diaconis-Ylvisaker Prior Penalized Likelihood\n") + cat(separator, "\n\n") + + # Load both versions with mdyplFit + library(brglm2, lib.loc = LIB_ORIGINAL) + mdypl_original <- brglm2::mdyplFit + + detach("package:brglm2", unload = TRUE) + library(brglm2, lib.loc = LIB_NEW) + mdypl_new <- brglm2::mdyplFit + + cat("Testing mdyplFit method with alpha = 1/(1 + kappa)\n") + alpha_val <- 1 / (1 + kappa) + cat(" Alpha value:", round(alpha_val, 4), "\n\n") + + cat("Original mdyplFit timing:\n") + time_mdypl_orig <- system.time({ + fit_mdypl_orig <- glm(full_mf_fm, data = MultipleFeatures, + family = binomial(), + method = mdypl_original, + alpha = alpha_val, + subset = training, + maxit = 200) + }) + print(time_mdypl_orig) + cat("\n") + + cat("New mdyplFit timing:\n") + time_mdypl_new <- system.time({ + fit_mdypl_new <- glm(full_mf_fm, data = MultipleFeatures, + family = binomial(), + method = mdypl_new, + alpha = alpha_val, + subset = training, + maxit = 200) + }) + print(time_mdypl_new) + cat("\n") + + cat("MDYPL speedup:", + time_mdypl_orig["elapsed"] / time_mdypl_new["elapsed"], "x\n") + + cat("\nNumerical verification (MDYPL):\n") + cat(" Coefficients match:", + isTRUE(all.equal(coef(fit_mdypl_orig), coef(fit_mdypl_new), tolerance = 1e-10)), "\n") + cat(" Max coefficient difference:", + max(abs(coef(fit_mdypl_orig) - coef(fit_mdypl_new))), "\n") + + # ====== SECTION 6: Summary Statistics ====== + cat("\n", separator, "\n") + cat("SECTION 6: OVERALL SUMMARY\n") + cat(separator, "\n\n") + + speedups <- c( + "Lizards (small)" = median(lizards_bench$time[lizards_bench$expr == "original"]) / + median(lizards_bench$time[lizards_bench$expr == "new"]), + "Endometrial (medium)" = median(endo_bench$time[endo_bench$expr == "original"]) / + median(endo_bench$time[endo_bench$expr == "new"]), + "MultipleFeatures (large)" = time_mf_orig["elapsed"] / time_mf_new["elapsed"], + "MDYPL (large)" = time_mdypl_orig["elapsed"] / time_mdypl_new["elapsed"] + ) + + cat("Speedup Summary:\n") + for (i in seq_along(speedups)) { + cat(sprintf(" %-25s: %.2fx faster\n", names(speedups)[i], speedups[i])) + } + + cat("\nMean speedup:", round(mean(speedups), 2), "x\n") + cat("Median speedup:", round(median(speedups), 2), "x\n") + + # Save benchmark objects for plotting + save(lizards_bench, endo_bench, + time_mf_orig, time_mf_new, + time_mdypl_orig, time_mdypl_new, + speedups, + file = file.path(results_dir, "benchmark_data.RData")) + + cat("\n", separator, "\n") + cat("BENCHMARKING COMPLETE\n") + cat("All results saved to:", results_dir, "\n") + cat(separator, "\n") + +}, error = function(e) { + cat("\n\nERROR OCCURRED:\n") + cat(conditionMessage(e), "\n") + cat(traceback(), "\n") +}, finally = { + sink() +}) + +cat("\nResults saved to:", file.path(results_dir, "benchmark_results.txt"), "\n") +cat("Benchmark data saved to:", file.path(results_dir, "benchmark_data.RData"), "\n") \ No newline at end of file diff --git a/benchmarks/results/20251110_142635/benchmark_data.RData b/benchmarks/results/20251110_142635/benchmark_data.RData new file mode 100644 index 0000000000000000000000000000000000000000..3a83479d688a96d2aafdc6e15a3e237a1045f4dc GIT binary patch literal 2082 zcmV+-2;KJ|iwFP!000002Gv-7P!#7GU*JGMgC^*hp^~CW4N@e;j}oQHff^wiiGWlT zQ1u(o@{2; zs5m9xQ>X72<@+5?=M(a__#V=&M~=s7Sn^;5P#V- z%JyLNFR!@*yXUQX#Fa$~;NxEWIb<MDczYX7`dFjuEqi$jr=Ip$X3qR-fiO6FyAE9+$ zO8lj`NysZ-YsS3X@kPXY*fPk{xOS|E_`CJA?jOb=Pr=zn@U^@f0+~OR3M}+az&cwi z43O=&H=^E>AAN&-wwRlch1e57Zt^_%Ewxz?$2A-SuYy@|kl7USFMK+S>{WWo6WxKh z;=D(}!~P}hXQ4h5=(tMz-g2y4-fpBhKHp69n%|6k{G~5x9>YA)JI{`WU)6a6aW>C@>{=Z~{bYOsEPXB%eB4c2AzLOL zgrD+#hU81D5U)IT87NJmb0+`NiaPS-aLSuK9(J|jUF35;I*arN*J3_Wd>i~7IU{L( zj_xLX%x#)iW79!2}cV~)m7FlmXej zufyMvv<-H1stz(c;~eaUHQRv&zo`Uo>wcO)mrMDU&6^5;{^t)t&rjG%^MAOG_{CSl zZvHd^G8dTvWS=U4pIN_}_#Cb!dulE5-~0vo5{Bm!ukf!S%SEl2gCX&!#N*@ys>_%t zkNHXDvA@J4PjS~-@HXVE1zK9S0qxvM*d06RoSNJAAV1smYb{UUXUDnRo?IXy}Kg4*peSermsSJx8( zjyl!BD@@;SVUQNo8Q>VnIZV!eFRmu0|4ZCZ7tg!BTn%-J8R{bUU3d(10UPRa``=u6 z@8*IxSZ{;m)>bY!a1RZ9HR{=J1K);B>1s*%LPk41(_?|9hcbXl*WniE9qS+q!S`2b z=*W_`Xjt-1eVm5kO^YG)>T>{$PptlEqAPZQsX)OGlixR+FT*RR-d43l7 zDe4&Hm-1KBTpO2B-hXX?tX`Q5tgd|^9`c<^@Gsr40(snzB*QK-uOpwU^G)z{Po7V5 z!CsorjCWASwdEb^KjBr0$Qif8L-{+(qs*NS5B<6ofLle1Bz`Q2*Ay1FY)w;@g(O@1EQeA>Of|2K_keCFEICass!Q(&R(n<8H~s{3E?y_)smb z_xpS!>B9m~aKG>H5gLKzcJp%WP2eM;9qiDwX{Fhp)jZUozvwNDzu8=uHvQO>;XlztPGI zeocfHK#FhoG~C}4-e%n`O_ zYm9y~+F|s^ee31TXYP@8@t7OeH7)3;xq zmDjW{Pyg9#t*N(v9HMVORpZ=qHAVlAxtlLno7@33b^b+vmi{*w7cbjcL73F79{sfM z+GXbyiD!klcspm}RlDC7w?GvXUKF^w9IL1j=Zh6s$-+%a>f6zn1#^}xeD+&L`nY%g M8(<+Bw80br0BP7l3;+NC literal 0 HcmV?d00001 diff --git a/benchmarks/results/20251110_142635/benchmark_results.txt b/benchmarks/results/20251110_142635/benchmark_results.txt new file mode 100644 index 0000000..b1f5744 --- /dev/null +++ b/benchmarks/results/20251110_142635/benchmark_results.txt @@ -0,0 +1,165 @@ +====================================================================== +BRGLM2 COMPREHENSIVE BENCHMARKING RESULTS +Timestamp: 20251110_142635 +====================================================================== + + + ====================================================================== +SECTION 1: TEST SUITE EXECUTION +====================================================================== + +Running test suite for NEW version... +Library path: C:/Users/ollie/OneDrive/Desktop/UNI/Project brglm2/benchmark_libs/new + + test-binomial.R............... 0 tests test-binomial.R............... 0 tests test-binomial.R............... 0 tests test-binomial.R............... 0 tests test-binomial.R............... 4 tests OK 0.9s + test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 1 tests OK test-bracl.R.................. 2 tests OK test-bracl.R.................. 3 tests OK test-bracl.R.................. 4 tests OK test-bracl.R.................. 5 tests OK test-bracl.R.................. 6 tests OK test-bracl.R.................. 7 tests OK test-bracl.R.................. 7 tests OK test-bracl.R.................. 27 tests OK test-bracl.R.................. 27 tests OK test-bracl.R.................. 28 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 30 tests OK test-bracl.R.................. 31 tests OK test-bracl.R.................. 31 tests OK test-bracl.R.................. 31 tests OK test-bracl.R.................. 31 tests OK test-bracl.R.................. 32 tests OK test-bracl.R.................. 33 tests OK test-bracl.R.................. 34 tests OK test-bracl.R.................. 34 tests OK test-bracl.R.................. 34 tests OK test-bracl.R.................. 35 tests OK test-bracl.R.................. 36 tests OK test-bracl.R.................. 36 tests OK test-bracl.R.................. 36 tests OK test-bracl.R.................. 36 tests OK test-bracl.R.................. 37 tests OK test-bracl.R.................. 38 tests OK test-bracl.R.................. 39 tests OK test-bracl.R.................. 40 tests OK test-bracl.R.................. 41 tests OK test-bracl.R.................. 42 tests OK test-bracl.R.................. 42 tests OK test-bracl.R.................. 42 tests OK test-bracl.R.................. 42 tests OK test-bracl.R.................. 43 tests OK test-bracl.R.................. 44 tests OK test-bracl.R.................. 45 tests OK test-bracl.R.................. 46 tests OK test-bracl.R.................. 47 tests OK test-bracl.R.................. 48 tests OK 3.9s + test-brglmControl.R........... 0 tests test-brglmControl.R........... 1 tests OK test-brglmControl.R........... 2 tests OK test-brglmControl.R........... 3 tests OK test-brglmControl.R........... 4 tests OK test-brglmControl.R........... 5 tests OK test-brglmControl.R........... 6 tests OK test-brglmControl.R........... 7 tests OK test-brglmControl.R........... 8 tests OK test-brglmControl.R........... 9 tests OK test-brglmControl.R........... 9 tests OK test-brglmControl.R........... 10 tests OK test-brglmControl.R........... 11 tests OK test-brglmControl.R........... 12 tests OK test-brglmControl.R........... 13 tests OK test-brglmControl.R........... 14 tests OK test-brglmControl.R........... 15 tests OK test-brglmControl.R........... 16 tests OK test-brglmControl.R........... 17 tests OK test-brglmControl.R........... 18 tests OK test-brglmControl.R........... 18 tests OK test-brglmControl.R........... 18 tests OK test-brglmControl.R........... 19 tests OK test-brglmControl.R........... 20 tests OK test-brglmControl.R........... 21 tests OK test-brglmControl.R........... 21 tests OK test-brglmControl.R........... 22 tests OK test-brglmControl.R........... 23 tests OK test-brglmControl.R........... 24 tests OK test-brglmControl.R........... 25 tests OK test-brglmControl.R........... 26 tests OK test-brglmControl.R........... 27 tests OK test-brglmControl.R........... 28 tests OK test-brglmControl.R........... 29 tests OK test-brglmControl.R........... 30 tests OK test-brglmControl.R........... 30 tests OK test-brglmControl.R........... 30 tests OK test-brglmControl.R........... 31 tests OK test-brglmControl.R........... 31 tests OK test-brglmControl.R........... 32 tests OK test-brglmControl.R........... 32 tests OK test-brglmControl.R........... 33 tests OK 1.1s + test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 1 tests OK test-brnp.R................... 2 tests OK test-brnp.R................... 3 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 5 tests OK test-brnp.R................... 6 tests OK test-brnp.R................... 7 tests OK test-brnp.R................... 8 tests OK test-brnp.R................... 9 tests OK test-brnp.R................... 15 tests OK test-brnp.R................... 15 tests OK test-brnp.R................... 15 tests OK test-brnp.R................... 15 tests OK test-brnp.R................... 16 tests OK test-brnp.R................... 17 tests OK test-brnp.R................... 18 tests OK 3.9s + test-checkinfinite.R.......... 0 tests test-checkinfinite.R.......... 1 tests OK test-checkinfinite.R.......... 2 tests OK 56ms + test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 1 tests OK 0.3s + test-dispersion.R............. 0 tests test-dispersion.R............. 0 tests test-dispersion.R............. 0 tests test-dispersion.R............. 0 tests test-dispersion.R............. 1 tests OK test-dispersion.R............. 2 tests OK 0.1s + test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 6 tests OK test-expo.R................... 7 tests OK test-expo.R................... 8 tests OK test-expo.R................... 9 tests OK test-expo.R................... 9 tests OK test-expo.R................... 9 tests OK test-expo.R................... 9 tests OK test-expo.R................... 21 tests OK test-expo.R................... 21 tests OK test-expo.R................... 21 tests OK test-expo.R................... 33 tests OK test-expo.R................... 33 tests OK test-expo.R................... 33 tests OK test-expo.R................... 45 tests OK test-expo.R................... 45 tests OK test-expo.R................... 45 tests OK test-expo.R................... 45 tests OK test-expo.R................... 57 tests OK test-expo.R................... 57 tests OK test-expo.R................... 57 tests OK test-expo.R................... 62 tests OK test-expo.R................... 63 tests OK 1.8s + test-gamma.R.................. 0 tests test-gamma.R.................. 0 tests test-gamma.R.................. 0 tests test-gamma.R.................. 0 tests test-gamma.R.................. 1 tests OK test-gamma.R.................. 2 tests OK 0.2s + test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 1 tests OK test-jeffreys.R............... 2 tests OK test-jeffreys.R............... 2 tests OK test-jeffreys.R............... 3 tests OK test-jeffreys.R............... 3 tests OK test-jeffreys.R............... 3 tests OK test-jeffreys.R............... 3 tests OK test-jeffreys.R............... 11 tests OK 0.7s + test-mdyplFit.R............... 0 tests test-mdyplFit.R............... 0 tests test-mdyplFit.R............... 0 tests test-mdyplFit.R............... 0 tests test-mdyplFit.R............... 1 tests OK test-mdyplFit.R............... 2 tests OK test-mdyplFit.R............... 2 tests OK test-mdyplFit.R............... 2 tests OK test-mdyplFit.R............... 3 tests OK test-mdyplFit.R............... 4 tests OK test-mdyplFit.R............... 5 tests OK test-mdyplFit.R............... 5 tests OK test-mdyplFit.R............... 5 tests OK test-mdyplFit.R............... 5 tests OK test-mdyplFit.R............... 6 tests OK test-mdyplFit.R............... 6 tests OK test-mdyplFit.R............... 6 tests OK test-mdyplFit.R............... 6 tests OK test-mdyplFit.R............... 7 tests OK test-mdyplFit.R............... 7 tests OK test-mdyplFit.R............... 7 tests OK test-mdyplFit.R............... 7 tests OK test-mdyplFit.R............... 41 tests OK test-mdyplFit.R............... 41 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 43 tests OK test-mdyplFit.R............... 44 tests OK test-mdyplFit.R............... 45 tests OK test-mdyplFit.R............... 46 tests OK test-mdyplFit.R............... 47 tests OK test-mdyplFit.R............... 48 tests OK test-mdyplFit.R............... 49 tests OK test-mdyplFit.R............... 50 tests OK test-mdyplFit.R............... 51 tests OK test-mdyplFit.R............... 52 tests OK test-mdyplFit.R............... 53 tests OK test-mdyplFit.R............... 54 tests OK test-mdyplFit.R............... 55 tests OK test-mdyplFit.R............... 56 tests OK test-mdyplFit.R............... 57 tests OK test-mdyplFit.R............... 58 tests OK test-mdyplFit.R............... 59 tests OK test-mdyplFit.R............... 60 tests OK test-mdyplFit.R............... 61 tests OK test-mdyplFit.R............... 62 tests OK 0.5s + test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 8 tests OK 1.0s + test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 1 tests OK 0.2s + test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 1 tests OK 0.3s + test-mis.R.................... 0 tests test-mis.R.................... 0 tests test-mis.R.................... 1 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 3 tests OK test-mis.R.................... 4 tests OK 0.1s + test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 1 tests OK 38.4s + test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 1 tests OK test-multinom.R............... 1 tests OK test-multinom.R............... 2 tests OK test-multinom.R............... 2 tests OK test-multinom.R............... 2 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 4 tests OK test-multinom.R............... 4 tests OK test-multinom.R............... 4 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 6 tests OK test-multinom.R............... 7 tests OK test-multinom.R............... 8 tests OK test-multinom.R............... 9 tests OK test-multinom.R............... 10 tests OK test-multinom.R............... 11 tests OK test-multinom.R............... 12 tests OK test-multinom.R............... 13 tests OK test-multinom.R............... 13 tests OK test-multinom.R............... 13 tests OK test-multinom.R............... 13 tests OK test-multinom.R............... 14 tests OK test-multinom.R............... 15 tests OK test-multinom.R............... 15 tests OK test-multinom.R............... 15 tests OK test-multinom.R............... 16 tests OK test-multinom.R............... 17 tests OK test-multinom.R............... 18 tests OK test-multinom.R............... 19 tests OK test-multinom.R............... 20 tests OK test-multinom.R............... 21 tests OK test-multinom.R............... 22 tests OK test-multinom.R............... 22 tests OK test-multinom.R............... 22 tests OK test-multinom.R............... 22 tests OK test-multinom.R............... 23 tests OK test-multinom.R............... 24 tests OK test-multinom.R............... 25 tests OK test-multinom.R............... 26 tests OK test-multinom.R............... 27 tests OK test-multinom.R............... 28 tests OK 2.2s + test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 1 tests OK test-poisson.R................ 1 tests OK test-poisson.R................ 1 tests OK test-poisson.R................ 1 tests OK test-poisson.R................ 2 tests OK 0.3s + test-print.R.................. 0 tests test-print.R.................. 0 tests test-print.R.................. 48 tests OK test-print.R.................. 48 tests OK test-print.R.................. 48 tests OK test-print.R.................. 48 tests OK test-print.R.................. 48 tests OK test-print.R.................. 49 tests OK test-print.R.................. 50 tests OK test-print.R.................. 51 tests OK test-print.R.................. 51 tests OK test-print.R.................. 51 tests OK test-print.R.................. 51 tests OK test-print.R.................. 52 tests OK test-print.R.................. 53 tests OK test-print.R.................. 54 tests OK test-print.R.................. 54 tests OK test-print.R.................. 54 tests OK test-print.R.................. 54 tests OK test-print.R.................. 55 tests OK test-print.R.................. 56 tests OK test-print.R.................. 57 tests OK 0.8s + test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 1 tests OK test-se.R..................... 1 tests OK test-se.R..................... 2 tests OK test-se.R..................... 2 tests OK test-se.R..................... 6 tests OK test-se.R..................... 6 tests OK test-se.R..................... 6 tests OK test-se.R..................... 7 tests OK test-se.R..................... 7 tests OK test-se.R..................... 8 tests OK test-se.R..................... 8 tests OK test-se.R..................... 9 tests OK test-se.R..................... 10 tests OK test-se.R..................... 10 tests OK test-se.R..................... 14 tests OK test-se.R..................... 14 tests OK test-se.R..................... 14 tests OK test-se.R..................... 15 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 17 tests OK test-se.R..................... 18 tests OK 41.1s + test-singular.R............... 0 tests test-singular.R............... 0 tests test-singular.R............... 0 tests test-singular.R............... 0 tests test-singular.R............... 1 tests OK test-singular.R............... 2 tests OK 0.2s + test-start.R.................. 0 tests test-start.R.................. 0 tests test-start.R.................. 0 tests test-start.R.................. 0 tests test-start.R.................. 0 tests test-start.R.................. 1 tests OK test-start.R.................. 2 tests OK 0.3s + test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 17 tests OK test-summary_mdyplFit.R....... 17 tests OK test-summary_mdyplFit.R....... 17 tests OK test-summary_mdyplFit.R....... 17 tests OK test-summary_mdyplFit.R....... 18 tests OK test-summary_mdyplFit.R....... 18 tests OK test-summary_mdyplFit.R....... 18 tests OK test-summary_mdyplFit.R....... 19 tests OK test-summary_mdyplFit.R....... 20 tests OK test-summary_mdyplFit.R....... 20 tests OK test-summary_mdyplFit.R....... 20 tests OK test-summary_mdyplFit.R....... 21 tests OK 14.0s + test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 1 tests OK test-transformation.R......... 2 tests OK test-transformation.R......... 3 tests OK 0.6s +All ok, NA results (113.3s) + +Running test suite for ORIGINAL version... +Library path: C:/Users/ollie/OneDrive/Desktop/UNI/Project brglm2/benchmark_libs/original + + test-binomial.R............... 0 tests test-binomial.R............... 0 tests test-binomial.R............... 0 tests test-binomial.R............... 0 tests test-binomial.R............... 4 tests OK 0.8s + test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 1 tests OK test-bracl.R.................. 2 tests OK test-bracl.R.................. 3 tests OK test-bracl.R.................. 4 tests OK test-bracl.R.................. 5 tests OK test-bracl.R.................. 6 tests OK test-bracl.R.................. 7 tests OK test-bracl.R.................. 7 tests OK test-bracl.R.................. 27 tests OK test-bracl.R.................. 27 tests OK test-bracl.R.................. 28 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 30 tests OK test-bracl.R.................. 31 tests OK test-bracl.R.................. 31 tests OK test-bracl.R.................. 31 tests OK test-bracl.R.................. 31 tests OK test-bracl.R.................. 32 tests OK test-bracl.R.................. 33 tests OK test-bracl.R.................. 34 tests OK test-bracl.R.................. 34 tests OK test-bracl.R.................. 34 tests OK test-bracl.R.................. 35 tests OK test-bracl.R.................. 36 tests OK test-bracl.R.................. 36 tests OK test-bracl.R.................. 36 tests OK test-bracl.R.................. 36 tests OK test-bracl.R.................. 37 tests OK test-bracl.R.................. 38 tests OK test-bracl.R.................. 39 tests OK test-bracl.R.................. 40 tests OK test-bracl.R.................. 41 tests OK test-bracl.R.................. 42 tests OK test-bracl.R.................. 42 tests OK test-bracl.R.................. 42 tests OK test-bracl.R.................. 42 tests OK test-bracl.R.................. 43 tests OK test-bracl.R.................. 44 tests OK test-bracl.R.................. 45 tests OK test-bracl.R.................. 46 tests OK test-bracl.R.................. 47 tests OK test-bracl.R.................. 48 tests OK 2.4s + test-brglmControl.R........... 0 tests test-brglmControl.R........... 1 tests OK test-brglmControl.R........... 2 tests OK test-brglmControl.R........... 3 tests OK test-brglmControl.R........... 4 tests OK test-brglmControl.R........... 5 tests OK test-brglmControl.R........... 6 tests OK test-brglmControl.R........... 7 tests OK test-brglmControl.R........... 8 tests OK test-brglmControl.R........... 9 tests OK test-brglmControl.R........... 9 tests OK test-brglmControl.R........... 10 tests OK test-brglmControl.R........... 11 tests OK test-brglmControl.R........... 12 tests OK test-brglmControl.R........... 13 tests OK test-brglmControl.R........... 14 tests OK test-brglmControl.R........... 15 tests OK test-brglmControl.R........... 16 tests OK test-brglmControl.R........... 17 tests OK test-brglmControl.R........... 18 tests OK test-brglmControl.R........... 18 tests OK test-brglmControl.R........... 18 tests OK test-brglmControl.R........... 19 tests OK test-brglmControl.R........... 20 tests OK test-brglmControl.R........... 21 tests OK test-brglmControl.R........... 21 tests OK test-brglmControl.R........... 22 tests OK test-brglmControl.R........... 23 tests OK test-brglmControl.R........... 24 tests OK test-brglmControl.R........... 25 tests OK test-brglmControl.R........... 26 tests OK test-brglmControl.R........... 27 tests OK test-brglmControl.R........... 28 tests OK test-brglmControl.R........... 29 tests OK test-brglmControl.R........... 30 tests OK test-brglmControl.R........... 30 tests OK test-brglmControl.R........... 30 tests OK test-brglmControl.R........... 31 tests OK test-brglmControl.R........... 31 tests OK test-brglmControl.R........... 32 tests OK test-brglmControl.R........... 32 tests OK test-brglmControl.R........... 33 tests OK 0.7s + test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 1 tests OK test-brnp.R................... 2 tests OK test-brnp.R................... 3 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 5 tests OK test-brnp.R................... 6 tests OK test-brnp.R................... 7 tests OK test-brnp.R................... 8 tests OK test-brnp.R................... 9 tests OK test-brnp.R................... 15 tests OK test-brnp.R................... 15 tests OK test-brnp.R................... 15 tests OK test-brnp.R................... 15 tests OK test-brnp.R................... 16 tests OK test-brnp.R................... 17 tests OK test-brnp.R................... 18 tests OK 3.3s + test-checkinfinite.R.......... 0 tests test-checkinfinite.R.......... 1 tests OK test-checkinfinite.R.......... 2 tests OK 83ms + test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 1 tests OK 0.3s + test-dispersion.R............. 0 tests test-dispersion.R............. 0 tests test-dispersion.R............. 0 tests test-dispersion.R............. 0 tests test-dispersion.R............. 1 tests OK test-dispersion.R............. 2 tests OK 0.2s + test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 6 tests OK test-expo.R................... 7 tests OK test-expo.R................... 8 tests OK test-expo.R................... 9 tests OK test-expo.R................... 9 tests OK test-expo.R................... 9 tests OK test-expo.R................... 9 tests OK test-expo.R................... 21 tests OK test-expo.R................... 21 tests OK test-expo.R................... 21 tests OK test-expo.R................... 33 tests OK test-expo.R................... 33 tests OK test-expo.R................... 33 tests OK test-expo.R................... 45 tests OK test-expo.R................... 45 tests OK test-expo.R................... 45 tests OK test-expo.R................... 45 tests OK test-expo.R................... 57 tests OK test-expo.R................... 57 tests OK test-expo.R................... 57 tests OK test-expo.R................... 62 tests OK test-expo.R................... 63 tests OK 1.7s + test-gamma.R.................. 0 tests test-gamma.R.................. 0 tests test-gamma.R.................. 0 tests test-gamma.R.................. 0 tests test-gamma.R.................. 1 tests OK test-gamma.R.................. 2 tests OK 0.2s + test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 1 tests OK test-jeffreys.R............... 2 tests OK test-jeffreys.R............... 2 tests OK test-jeffreys.R............... 3 tests OK test-jeffreys.R............... 3 tests OK test-jeffreys.R............... 3 tests OK test-jeffreys.R............... 3 tests OK test-jeffreys.R............... 11 tests OK 0.6s + test-mdyplFit.R............... 0 tests test-mdyplFit.R............... 0 tests test-mdyplFit.R............... 0 tests test-mdyplFit.R............... 0 tests test-mdyplFit.R............... 1 tests OK test-mdyplFit.R............... 2 tests OK test-mdyplFit.R............... 2 tests OK test-mdyplFit.R............... 2 tests OK test-mdyplFit.R............... 3 tests OK test-mdyplFit.R............... 4 tests OK test-mdyplFit.R............... 5 tests OK test-mdyplFit.R............... 5 tests OK test-mdyplFit.R............... 5 tests OK test-mdyplFit.R............... 5 tests OK test-mdyplFit.R............... 6 tests OK test-mdyplFit.R............... 6 tests OK test-mdyplFit.R............... 6 tests OK test-mdyplFit.R............... 6 tests OK test-mdyplFit.R............... 7 tests OK test-mdyplFit.R............... 7 tests OK test-mdyplFit.R............... 7 tests OK test-mdyplFit.R............... 7 tests OK test-mdyplFit.R............... 41 tests OK test-mdyplFit.R............... 41 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 43 tests OK test-mdyplFit.R............... 44 tests OK test-mdyplFit.R............... 45 tests OK test-mdyplFit.R............... 46 tests OK test-mdyplFit.R............... 47 tests OK test-mdyplFit.R............... 48 tests OK test-mdyplFit.R............... 49 tests OK test-mdyplFit.R............... 50 tests OK test-mdyplFit.R............... 51 tests OK test-mdyplFit.R............... 52 tests OK test-mdyplFit.R............... 53 tests OK test-mdyplFit.R............... 54 tests OK test-mdyplFit.R............... 55 tests OK test-mdyplFit.R............... 56 tests OK test-mdyplFit.R............... 57 tests OK test-mdyplFit.R............... 58 tests OK test-mdyplFit.R............... 59 tests OK test-mdyplFit.R............... 60 tests OK test-mdyplFit.R............... 61 tests OK test-mdyplFit.R............... 62 tests OK 0.5s + test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 8 tests OK 0.7s + test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 1 tests OK 0.2s + test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 1 tests OK 0.4s + test-mis.R.................... 0 tests test-mis.R.................... 0 tests test-mis.R.................... 1 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 3 tests OK test-mis.R.................... 4 tests OK 0.2s + test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 1 tests OK 32.9s + test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 1 tests OK test-multinom.R............... 1 tests OK test-multinom.R............... 2 tests OK test-multinom.R............... 2 tests OK test-multinom.R............... 2 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 4 tests OK test-multinom.R............... 4 tests OK test-multinom.R............... 4 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 6 tests OK test-multinom.R............... 7 tests OK test-multinom.R............... 8 tests OK test-multinom.R............... 9 tests OK test-multinom.R............... 10 tests OK test-multinom.R............... 11 tests OK test-multinom.R............... 12 tests OK test-multinom.R............... 13 tests OK test-multinom.R............... 13 tests OK test-multinom.R............... 13 tests OK test-multinom.R............... 13 tests OK test-multinom.R............... 14 tests OK test-multinom.R............... 15 tests OK test-multinom.R............... 15 tests OK test-multinom.R............... 15 tests OK test-multinom.R............... 16 tests OK test-multinom.R............... 17 tests OK test-multinom.R............... 18 tests OK test-multinom.R............... 19 tests OK test-multinom.R............... 20 tests OK test-multinom.R............... 21 tests OK test-multinom.R............... 22 tests OK test-multinom.R............... 22 tests OK test-multinom.R............... 22 tests OK test-multinom.R............... 22 tests OK test-multinom.R............... 23 tests OK test-multinom.R............... 24 tests OK test-multinom.R............... 25 tests OK test-multinom.R............... 26 tests OK test-multinom.R............... 27 tests OK test-multinom.R............... 28 tests OK 2.3s + test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 1 tests OK test-poisson.R................ 1 tests OK test-poisson.R................ 1 tests OK test-poisson.R................ 1 tests OK test-poisson.R................ 2 tests OK 0.4s + test-print.R.................. 0 tests test-print.R.................. 0 tests test-print.R.................. 48 tests OK test-print.R.................. 48 tests OK test-print.R.................. 48 tests OK test-print.R.................. 48 tests OK test-print.R.................. 48 tests OK test-print.R.................. 49 tests OK test-print.R.................. 50 tests OK test-print.R.................. 51 tests OK test-print.R.................. 51 tests OK test-print.R.................. 51 tests OK test-print.R.................. 51 tests OK test-print.R.................. 52 tests OK test-print.R.................. 53 tests OK test-print.R.................. 54 tests OK test-print.R.................. 54 tests OK test-print.R.................. 54 tests OK test-print.R.................. 54 tests OK test-print.R.................. 55 tests OK test-print.R.................. 56 tests OK test-print.R.................. 57 tests OK 0.7s + test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 1 tests OK test-se.R..................... 1 tests OK test-se.R..................... 2 tests OK test-se.R..................... 2 tests OK test-se.R..................... 6 tests OK test-se.R..................... 6 tests OK test-se.R..................... 6 tests OK test-se.R..................... 7 tests OK test-se.R..................... 7 tests OK test-se.R..................... 8 tests OK test-se.R..................... 8 tests OK test-se.R..................... 9 tests OK test-se.R..................... 10 tests OK test-se.R..................... 10 tests OK test-se.R..................... 14 tests OK test-se.R..................... 14 tests OK test-se.R..................... 14 tests OK test-se.R..................... 15 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 17 tests OK test-se.R..................... 18 tests OK 33.3s + test-singular.R............... 0 tests test-singular.R............... 0 tests test-singular.R............... 0 tests test-singular.R............... 0 tests test-singular.R............... 1 tests OK test-singular.R............... 2 tests OK 0.1s + test-start.R.................. 0 tests test-start.R.................. 0 tests test-start.R.................. 0 tests test-start.R.................. 0 tests test-start.R.................. 0 tests test-start.R.................. 1 tests OK test-start.R.................. 2 tests OK 0.2s + test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 17 tests OK test-summary_mdyplFit.R....... 17 tests OK test-summary_mdyplFit.R....... 17 tests OK test-summary_mdyplFit.R....... 17 tests OK test-summary_mdyplFit.R....... 18 tests OK test-summary_mdyplFit.R....... 18 tests OK test-summary_mdyplFit.R....... 18 tests OK test-summary_mdyplFit.R....... 19 tests OK test-summary_mdyplFit.R....... 20 tests OK test-summary_mdyplFit.R....... 20 tests OK test-summary_mdyplFit.R....... 20 tests OK test-summary_mdyplFit.R....... 21 tests OK 6.7s + test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 1 tests OK test-transformation.R......... 2 tests OK test-transformation.R......... 3 tests OK 0.3s +All ok, NA results (89.3s) + + +Detailed test results saved to: benchmarks/results/20251110_142635/test_results.txt + + ====================================================================== +SECTION 2: MICROBENCHMARK COMPARISON +(100 evaluations with unit: seconds) +====================================================================== + +Test: Lizards dataset (small) +Unit: seconds + expr min lq mean median uq max neval + original 0.007249401 0.01269455 0.01776941 0.0172211 0.02214865 0.0369909 100 + new 0.006609902 0.01268585 0.01728913 0.0163083 0.02137415 0.0353854 100 + + +Speedup factor: 1.055971 x + + ====================================================================== +SECTION 3: ENDOMETRIAL DATASET (PROBIT LINK) +====================================================================== + +Microbenchmark (50 evaluations): +Unit: seconds + expr min lq mean median uq max neval + original 0.008669302 0.0124377 0.01720837 0.01515210 0.0203757 0.0430905 50 + new 0.009150701 0.0143091 0.01781808 0.01756955 0.0208440 0.0287275 50 + + +Speedup factor: 0.8624068 x + + ====================================================================== +SECTION 4: MULTIPLEFEATURES DATASET (HIGH-DIMENSIONAL) +Reference: Sterzinger & Kosmidis (2024, Section 8) +====================================================================== + +Dataset info: + Total observations: 2000 + Training observations: 1000 + Number of features: 140 + Dimensionality ratio (kappa): 0.14 + +Running single timing test... + +Original version timing: + user system elapsed + 20.47 0.58 21.79 + +New version timing: + user system elapsed + 19.33 0.60 20.72 + +MultipleFeatures speedup: 1.051641 x + +Numerical verification: + Coefficients match: TRUE + Max coefficient difference: 0 + Deviance match: TRUE + + ====================================================================== +SECTION 5: MDYPL METHOD (MultipleFeatures) +Maximum Diaconis-Ylvisaker Prior Penalized Likelihood +====================================================================== + +Testing mdyplFit method with alpha = 1/(1 + kappa) + Alpha value: 0.8772 + +Original mdyplFit timing: + user system elapsed + 0.20 0.03 0.22 + +New mdyplFit timing: + user system elapsed + 0.25 0.00 0.29 + +MDYPL speedup: 0.7586207 x + +Numerical verification (MDYPL): + Coefficients match: TRUE + Max coefficient difference: 0 + + ====================================================================== +SECTION 6: OVERALL SUMMARY +====================================================================== + +Speedup Summary: + Lizards (small) : 1.06x faster + Endometrial (medium) : 0.86x faster + MultipleFeatures (large).elapsed: 1.05x faster + MDYPL (large).elapsed : 0.76x faster + +Mean speedup: 0.93 x +Median speedup: 0.96 x + + ====================================================================== +BENCHMARKING COMPLETE +All results saved to: benchmarks/results/20251110_142635 +====================================================================== diff --git a/benchmarks/results/20251110_142635/plots/01_lizards_comparison.png b/benchmarks/results/20251110_142635/plots/01_lizards_comparison.png new file mode 100644 index 0000000000000000000000000000000000000000..7848440833695b218fdcb3a95161ac8a2ccbfd7f GIT binary patch literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z literal 0 HcmV?d00001 diff --git a/benchmarks/results/20251110_142635/plots/02_endometrial_comparison.png b/benchmarks/results/20251110_142635/plots/02_endometrial_comparison.png new file mode 100644 index 0000000000000000000000000000000000000000..7848440833695b218fdcb3a95161ac8a2ccbfd7f GIT binary patch literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z literal 0 HcmV?d00001 diff --git a/benchmarks/results/20251110_142635/plots/03_speedup_summary.png b/benchmarks/results/20251110_142635/plots/03_speedup_summary.png new file mode 100644 index 0000000000000000000000000000000000000000..7848440833695b218fdcb3a95161ac8a2ccbfd7f GIT binary patch literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z literal 0 HcmV?d00001 diff --git a/benchmarks/results/20251110_142635/plots/04_absolute_timing.png b/benchmarks/results/20251110_142635/plots/04_absolute_timing.png new file mode 100644 index 0000000000000000000000000000000000000000..7848440833695b218fdcb3a95161ac8a2ccbfd7f GIT binary patch literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z literal 0 HcmV?d00001 diff --git a/benchmarks/results/20251110_142635/plots/05_lizards_distribution.png b/benchmarks/results/20251110_142635/plots/05_lizards_distribution.png new file mode 100644 index 0000000000000000000000000000000000000000..7848440833695b218fdcb3a95161ac8a2ccbfd7f GIT binary patch literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z literal 0 HcmV?d00001 diff --git a/benchmarks/results/20251110_142635/plots/summary_statistics.csv b/benchmarks/results/20251110_142635/plots/summary_statistics.csv new file mode 100644 index 0000000..a298af0 --- /dev/null +++ b/benchmarks/results/20251110_142635/plots/summary_statistics.csv @@ -0,0 +1,5 @@ +"Dataset","Version","Median","Mean","SD" +"Lizards","Original",0.0172211005,0.01776941499,0.00652682193196431 +"Lizards","New",0.016308301,0.01728913399,0.00651137518225907 +"Endometrial","Original",0.015152101,0.01720837496,0.0067319175452717 +"Endometrial","New",0.017569551,0.01781808104,0.00452952984679089 diff --git a/benchmarks/results/20251110_142635/test_results.txt b/benchmarks/results/20251110_142635/test_results.txt new file mode 100644 index 0000000..8cf4c1d --- /dev/null +++ b/benchmarks/results/20251110_142635/test_results.txt @@ -0,0 +1,3 @@ +Original: NA tests (89.3s) +New: NA tests (113.3s) +Speedup: 0.79x faster diff --git a/benchmarks/run_all.R b/benchmarks/run_all.R new file mode 100644 index 0000000..4614f3c --- /dev/null +++ b/benchmarks/run_all.R @@ -0,0 +1,69 @@ +# Master script to run all benchmarks +# This script runs the complete benchmarking suite and generates visualizations + +cat("======================================================================\n") +cat("BRGLM2 COMPREHENSIVE BENCHMARK SUITE\n") +cat("======================================================================\n\n") + +cat("This will run:\n") +cat(" 1. Test suite validation\n") +cat(" 2. Microbenchmark comparisons (small & medium datasets)\n") +cat(" 3. Large dataset tests (MultipleFeatures)\n") +cat(" 4. MDYPL method comparison\n") +cat(" 5. Visualization generation\n\n") + +cat("Expected runtime: ~ 5 minutes depending on system\n\n") + +response <- readline(prompt = "Continue? (y/n): ") + +if (tolower(response) != "y") { + cat("Benchmark cancelled.\n") + quit(save = "no") +} + +cat("\n======================================================================\n") +cat("PHASE 1: Running validation and setup\n") +cat("======================================================================\n\n") + +# Verify and Setup +source("benchmarks/check_setup.R") +source("benchmarks/setup.R") + +cat("\n======================================================================\n") +cat("PHASE 2: Running main benchmark script\n") +cat("======================================================================\n\n") + +# Run main benchmark +start_time <- Sys.time() +source("benchmarks/main_benchmark.R") +end_time <- Sys.time() + +cat("\n======================================================================\n") +cat("PHASE 3: Generating visualizations\n") +cat("======================================================================\n\n") + +# Generate plots +source("benchmarks/visualize_results.R") + +cat("\n======================================================================\n") +cat("BENCHMARK SUITE COMPLETE\n") +cat("======================================================================\n\n") + +cat("Total runtime:", format(difftime(end_time, start_time)), "\n") +cat("Results directory:", file.path("benchmarks", "results"), "\n\n") + +cat("Next steps:\n") +cat(" 1. Review benchmark_results.txt for detailed timing\n") +cat(" 2. Check plots/ directory for visualizations\n") +cat(" 3. Review test_results.txt for test suite output\n\n") + +cat("Summary of improvements:\n") +results_dir <- file.path("benchmarks", "results") +dirs <- list.dirs(results_dir, recursive = FALSE) +latest_dir <- dirs[which.max(file.info(dirs)$mtime)] +load(file.path(latest_dir, "benchmark_data.RData")) + +for (i in seq_along(speedups)) { + cat(sprintf(" %-30s: %.2fx faster\n", names(speedups)[i], speedups[i])) +} +cat(sprintf(" %-30s: %.2fx faster\n", "Average", mean(speedups))) \ No newline at end of file diff --git a/benchmarks/setup.R b/benchmarks/setup.R new file mode 100644 index 0000000..38a921c --- /dev/null +++ b/benchmarks/setup.R @@ -0,0 +1,134 @@ +# Configuration for all benchmark scripts + +# ====== Library Paths ====== +LIB_ORIGINAL <- "C:/Users/ollie/OneDrive/Desktop/UNI/Project brglm2/benchmark_libs/original" +LIB_NEW <- "C:/Users/ollie/OneDrive/Desktop/UNI/Project brglm2/benchmark_libs/new" + +# ====== Load Required Packages ====== +cat("Loading benchmark packages...\n") + +required_packages <- c("tictoc", "rbenchmark", "microbenchmark", "ggplot2") + +for (pkg in required_packages) { + if (!requireNamespace(pkg, quietly = TRUE)) { + cat("Installing", pkg, "...\n") + install.packages(pkg) + } + library(pkg, character.only = TRUE) +} + +cat("All packages loaded successfully.\n\n") + +# ====== Load Both Versions of brglm2 ====== +cat("Loading brglm2 versions...\n") + +# Load original version +if (!dir.exists(LIB_ORIGINAL)) { + stop("Original library path does not exist: ", LIB_ORIGINAL) +} + +library(brglm2, lib.loc = LIB_ORIGINAL) +brglm2_original <- brglm2::brglmFit +cat(" Original brglmFit loaded from:", LIB_ORIGINAL, "\n") + +# Detach and load new version +detach("package:brglm2", unload = TRUE) + +if (!dir.exists(LIB_NEW)) { + stop("New library path does not exist: ", LIB_NEW) +} + +library(brglm2, lib.loc = LIB_NEW) +brglm2_new <- brglm2::brglmFit +cat(" New brglmFit loaded from:", LIB_NEW, "\n\n") + +# ====== Verify Version Loading ====== +if (!exists("brglm2_original") || !exists("brglm2_new")) { + stop("Failed to load one or both brglm2 versions") +} + +# ====== Setup Test Data ====== +cat("Loading test datasets...\n") + +# Lizards dataset (small) +data("lizards", package = "brglm2") +full_fm <- cbind(grahami, opalinus) ~ height + diameter + light + time +cat(" Lizards dataset loaded (n =", nrow(lizards), ")\n") + +# Endometrial dataset (medium) +data("endometrial", package = "brglm2") +cat(" Endometrial dataset loaded (n =", nrow(endometrial), ")\n") + +# MultipleFeatures dataset (large, high-dimensional) +if (exists("MultipleFeatures", envir = .GlobalEnv)) { + rm(MultipleFeatures, envir = .GlobalEnv) +} +data("MultipleFeatures", package = "brglm2") +cat(" MultipleFeatures dataset loaded (n =", nrow(MultipleFeatures), ")\n") + +# ====== Configuration Summary ====== +cat("\n") +cat(strrep("=", 70), "\n") +cat("BENCHMARK SETUP COMPLETE\n") +cat(strrep("=", 70), "\n") +cat("Original library:", LIB_ORIGINAL, "\n") +cat("New library:", LIB_NEW, "\n") +cat("Datasets loaded: lizards, endometrial, MultipleFeatures\n") +cat("Packages loaded:", paste(required_packages, collapse = ", "), "\n") +cat(strrep("=", 70), "\n\n") + +# ====== Utility Functions ====== + +# Function to safely run and time code +safe_time <- function(expr, name = "Expression") { + cat("Timing:", name, "...\n") + tryCatch({ + timing <- system.time(result <- expr) + cat(" Completed in", timing["elapsed"], "seconds\n") + list(result = result, timing = timing, success = TRUE) + }, error = function(e) { + cat(" ERROR:", conditionMessage(e), "\n") + list(result = NULL, timing = NULL, success = FALSE, error = e) + }) +} + +# Function to compare two fits for numerical equality +compare_fits <- function(fit1, fit2, tolerance = 1e-10, verbose = TRUE) { + checks <- list( + coefficients = all.equal(coef(fit1), coef(fit2), tolerance = tolerance), + fitted_values = all.equal(fitted(fit1), fitted(fit2), tolerance = tolerance), + deviance = all.equal(fit1$deviance, fit2$deviance, tolerance = tolerance) + ) + + if (verbose) { + cat("\nNumerical Comparison:\n") + cat(" Coefficients match:", isTRUE(checks$coefficients), "\n") + if (!isTRUE(checks$coefficients)) { + cat(" Max difference:", max(abs(coef(fit1) - coef(fit2))), "\n") + } + cat(" Fitted values match:", isTRUE(checks$fitted_values), "\n") + if (!isTRUE(checks$fitted_values)) { + cat(" Max difference:", max(abs(fitted(fit1) - fitted(fit2))), "\n") + } + cat(" Deviance match:", isTRUE(checks$deviance), "\n") + if (!isTRUE(checks$deviance)) { + cat(" Difference:", abs(fit1$deviance - fit2$deviance), "\n") + } + } + + all(sapply(checks, isTRUE)) +} + +# Function to format speedup nicely +format_speedup <- function(time_old, time_new) { + speedup <- time_old / time_new + improvement_pct <- (1 - 1/speedup) * 100 + + list( + speedup = speedup, + improvement_pct = improvement_pct, + text = sprintf("%.2fx faster (%.1f%% improvement)", speedup, improvement_pct) + ) +} + +cat("Setup complete! Ready to run benchmarks.\n\n") \ No newline at end of file diff --git a/benchmarks/visualize_results.R b/benchmarks/visualize_results.R new file mode 100644 index 0000000..c8ce165 --- /dev/null +++ b/benchmarks/visualize_results.R @@ -0,0 +1,168 @@ +# Benchmark visualization script +# Run this after the main benchmark script completes + +library(ggplot2) +library(microbenchmark) + +# Find the most recent results directory +results_base <- "benchmarks/results" +dirs <- list.dirs(results_base, recursive = FALSE) +latest_dir <- dirs[which.max(file.info(dirs)$mtime)] + +cat("Loading benchmark data from:", latest_dir, "\n") + +# Load the benchmark data +load(file.path(latest_dir, "benchmark_data.RData")) + +# Create plots directory +plots_dir <- file.path(latest_dir, "plots") +dir.create(plots_dir, showWarnings = FALSE) + +# ====== Plot 1: Microbenchmark comparison (Lizards) ====== +png(file.path(plots_dir, "01_lizards_comparison.png"), + width = 800, height = 600, res = 100) +autoplot(lizards_bench) + + labs(title = "Lizards Dataset: Original vs New Implementation", + subtitle = "100 evaluations each", + y = "Time (seconds)") + + theme_minimal(base_size = 12) +dev.off() + +# ====== Plot 2: Microbenchmark comparison (Endometrial) ====== +png(file.path(plots_dir, "02_endometrial_comparison.png"), + width = 800, height = 600, res = 100) +autoplot(endo_bench) + + labs(title = "Endometrial Dataset: Original vs New Implementation", + subtitle = "50 evaluations each", + y = "Time (seconds)") + + theme_minimal(base_size = 12) +dev.off() + +# ====== Plot 3: Speedup summary bar chart ====== +speedup_df <- data.frame( + Test = factor(names(speedups), levels = names(speedups)), + Speedup = as.numeric(speedups), + Category = c("Small", "Medium", "Large", "Large (MDYPL)") +) + +png(file.path(plots_dir, "03_speedup_summary.png"), + width = 800, height = 600, res = 100) +ggplot(speedup_df, aes(x = Test, y = Speedup, fill = Category)) + + geom_bar(stat = "identity") + + geom_text(aes(label = sprintf("%.2fx", Speedup)), + vjust = -0.5, size = 4) + + geom_hline(yintercept = 1, linetype = "dashed", color = "red") + + labs(title = "Performance Improvement: New vs Original Implementation", + subtitle = "Higher is better", + x = "Test Case", + y = "Speedup Factor") + + scale_fill_brewer(palette = "Set2") + + theme_minimal(base_size = 12) + + theme(axis.text.x = element_text(angle = 45, hjust = 1), + legend.position = "top") +dev.off() + +# ====== Plot 4: Absolute timing comparison ====== +timing_df <- data.frame( + Test = rep(c("Lizards", "Endometrial", "MultipleFeatures", "MDYPL"), each = 2), + Version = rep(c("Original", "New"), 4), + Time = c( + median(lizards_bench$time[lizards_bench$expr == "original"]) / 1e9, + median(lizards_bench$time[lizards_bench$expr == "new"]) / 1e9, + median(endo_bench$time[endo_bench$expr == "original"]) / 1e9, + median(endo_bench$time[endo_bench$expr == "new"]) / 1e9, + time_mf_orig["elapsed"], + time_mf_new["elapsed"], + time_mdypl_orig["elapsed"], + time_mdypl_new["elapsed"] + ) +) + +png(file.path(plots_dir, "04_absolute_timing.png"), + width = 800, height = 600, res = 100) +ggplot(timing_df, aes(x = Test, y = Time, fill = Version)) + + geom_bar(stat = "identity", position = "dodge") + + geom_text(aes(label = sprintf("%.2fs", Time)), + position = position_dodge(width = 0.9), + vjust = -0.5, size = 3) + + labs(title = "Absolute Execution Time Comparison", + subtitle = "Lower is better", + x = "Test Case", + y = "Time (seconds)") + + scale_fill_manual(values = c("Original" = "#E41A1C", "New" = "#4DAF4A")) + + theme_minimal(base_size = 12) + + theme(axis.text.x = element_text(angle = 45, hjust = 1), + legend.position = "top") +dev.off() + +# ====== Plot 5: Distribution comparison (Lizards) ====== +lizards_df <- data.frame( + Time = lizards_bench$time / 1e9, # Convert to seconds + Version = lizards_bench$expr +) + +png(file.path(plots_dir, "05_lizards_distribution.png"), + width = 800, height = 600, res = 100) +ggplot(lizards_df, aes(x = Time, fill = Version)) + + geom_density(alpha = 0.6) + + geom_vline(data = aggregate(Time ~ Version, lizards_df, median), + aes(xintercept = Time, color = Version), + linetype = "dashed", size = 1) + + labs(title = "Execution Time Distribution: Lizards Dataset", + subtitle = "Dashed lines show median values", + x = "Time (seconds)", + y = "Density") + + scale_fill_manual(values = c("original" = "#E41A1C", "new" = "#4DAF4A")) + + scale_color_manual(values = c("original" = "#E41A1C", "new" = "#4DAF4A")) + + theme_minimal(base_size = 12) + + theme(legend.position = "top") +dev.off() + +# ====== Summary statistics table ====== +summary_stats <- rbind( + data.frame( + Dataset = "Lizards", + Version = c("Original", "New"), + Median = c( + median(lizards_bench$time[lizards_bench$expr == "original"]) / 1e9, + median(lizards_bench$time[lizards_bench$expr == "new"]) / 1e9 + ), + Mean = c( + mean(lizards_bench$time[lizards_bench$expr == "original"]) / 1e9, + mean(lizards_bench$time[lizards_bench$expr == "new"]) / 1e9 + ), + SD = c( + sd(lizards_bench$time[lizards_bench$expr == "original"]) / 1e9, + sd(lizards_bench$time[lizards_bench$expr == "new"]) / 1e9 + ) + ), + data.frame( + Dataset = "Endometrial", + Version = c("Original", "New"), + Median = c( + median(endo_bench$time[endo_bench$expr == "original"]) / 1e9, + median(endo_bench$time[endo_bench$expr == "new"]) / 1e9 + ), + Mean = c( + mean(endo_bench$time[endo_bench$expr == "original"]) / 1e9, + mean(endo_bench$time[endo_bench$expr == "new"]) / 1e9 + ), + SD = c( + sd(endo_bench$time[endo_bench$expr == "original"]) / 1e9, + sd(endo_bench$time[endo_bench$expr == "new"]) / 1e9 + ) + ) +) + +write.csv(summary_stats, + file.path(plots_dir, "summary_statistics.csv"), + row.names = FALSE) + +cat("\nAll plots saved to:", plots_dir, "\n") +cat("\nGenerated plots:\n") +cat(" 1. Lizards microbenchmark comparison\n") +cat(" 2. Endometrial microbenchmark comparison\n") +cat(" 3. Overall speedup summary\n") +cat(" 4. Absolute timing comparison\n") +cat(" 5. Lizards timing distribution\n") +cat(" 6. Summary statistics (CSV)\n") \ No newline at end of file From 7dcce20c8573a0f98ea583b193f45eb62ed3066e Mon Sep 17 00:00:00 2001 From: Ollie Date: Mon, 10 Nov 2025 14:40:10 +0000 Subject: [PATCH 07/15] Ignore benchmark results --- .gitignore | Bin 1539 -> 1703 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.gitignore b/.gitignore index b4e86b59c501f04261317ed809031c28c8549c01..96f6aa29f20d70367189527585818ffdf61dce45 100644 GIT binary patch literal 1703 zcmaJ?O>g5i5Y^d${=)#d85Nbbmm)o7*GaoTw<+v&v4;Q#EsZQzlqirRC*DJUdmr^- z2YcvAGeh#t%$pCHE=XRwB3-4co0}VIb@8+#NKolF?$~RauGD6?--+`K@xJdZZ`^RO zQTt=}bYkyK2_-)HRJe}XAqa6-(yNi0^9op!7;|d6!Z24q@ab3v1{CIndgDUU|_E19J^-gTW zTMnPO?VZ>D{7JZt0X%yhYL3#E5jn=GOwmP4;aY__EGscBgPhuQtV-88={*NHnS$RK z&jkoFNC6IEH`>}W6`r+lNg%~@ivzlU{EI@Z-%w%<)aC}*l7qX6I5lOc*oMqSicupNiU9c{Ge>x-yOnLWJe z7Wq@*N{+SYbs z@!S93E^0228*Xn$F`uq)cQTa5T|-3(|EM9bpD#c!hXS0R%&}vUNWnz}S}iR)`n{zu zt2vbWLF%7KT*KWD6quBC)~AJNFeA+|$a>(cT$$BEB9Th@U?F8Y|CZq?7AI38q9 z18D+nIwPJmreTZe@=fVpJ1V)-gB2>!QB38vdt$=-(Ta5PMTmvEmVd14rL_*{cfcrw z8l?I~wdnn|ioQn?0I@^V2j`{$c7i%C4YOUUdPj%lLUe7qQn8xEQ>V=x{b=i%FH^I*I=oM3H}HiBugDPP(K>>ZDC{ X;*%x`Nsce$J0v!dQC}x%vP%8~$z%w} literal 1539 zcmaJ>!H(lL487|s2;^qe(zLx4)6?u`rd^=hDU#`;hXDdbqGQ#vWk_^p(nG&}DcMfi z9(poK(T~*Qquh{4*RUY4U&({SLEN0F}Z908I zI8M%67-KN}x2WpJce%^?&l8Ok%`ni!&~rZ@KX2!Jp(;r_%F|!}mugxxT~6H|~a3=?~HrvZuhzE_KJTI&730;6q80}m6m-vNaVhi@PuLQ6EJ zd!-C zsA0EG?jDZod9LY((?TjYQwnBASw@d6?zH?|S2gr3fO}wKm}1`ZAAy6S`dhqis@IKB zGA~1tc9HFWeCY#^w36tJV6H-)^cic_5tH>Es=%SPWq8DiBHzcOKH+-Zu1HzE0;u;|lLj5nk_DGALK9dVr{Qm+wd P^Y-T#pOyI;iTU^nRgC)4 From 15272d27434372f7a18c3824f0aefc2f3be524fd Mon Sep 17 00:00:00 2001 From: Ollie Date: Mon, 10 Nov 2025 15:04:33 +0000 Subject: [PATCH 08/15] Ignore benchmark results --- .gitignore | Bin 1703 -> 1835 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/.gitignore b/.gitignore index 96f6aa29f20d70367189527585818ffdf61dce45..34e8aee44d2445c61b8eab759de538a5790c1b33 100644 GIT binary patch delta 19 UcmZ3^yP9vqa<<9UY&tLu07yIrivR!s delta 7 OcmZ3@x14vway9@9;{wY7 From e0b84045fc3d02fede9918ee019f642169496377 Mon Sep 17 00:00:00 2001 From: Ollie Date: Mon, 10 Nov 2025 15:04:52 +0000 Subject: [PATCH 09/15] Further amendments to benchmarking files --- benchmarks/main_benchmark.R | 95 +++++----- .../20251110_144218/benchmark_data.RData | Bin 0 -> 2111 bytes .../20251110_144218/benchmark_results.txt | 165 ++++++++++++++++++ .../plots/01_lizards_comparison.png | Bin 0 -> 581 bytes .../plots/02_endometrial_comparison.png | Bin 0 -> 581 bytes .../plots/03_speedup_summary.png | Bin 0 -> 581 bytes .../plots/04_absolute_timing.png | Bin 0 -> 581 bytes .../plots/05_lizards_distribution.png | Bin 0 -> 581 bytes .../plots/summary_statistics.csv | 5 + .../results/20251110_144218/test_results.txt | 3 + .../20251110_144957/benchmark_data.RData | Bin 0 -> 2129 bytes .../20251110_144957/benchmark_results.txt | 164 +++++++++++++++++ .../plots/01_lizards_comparison.png | Bin 0 -> 581 bytes .../plots/02_endometrial_comparison.png | Bin 0 -> 581 bytes .../plots/03_speedup_summary.png | Bin 0 -> 581 bytes .../plots/04_absolute_timing.png | Bin 0 -> 581 bytes .../plots/05_lizards_distribution.png | Bin 0 -> 581 bytes .../plots/summary_statistics.csv | 5 + benchmarks/run_all.R | 5 - 19 files changed, 383 insertions(+), 59 deletions(-) create mode 100644 benchmarks/results/20251110_144218/benchmark_data.RData create mode 100644 benchmarks/results/20251110_144218/benchmark_results.txt create mode 100644 benchmarks/results/20251110_144218/plots/01_lizards_comparison.png create mode 100644 benchmarks/results/20251110_144218/plots/02_endometrial_comparison.png create mode 100644 benchmarks/results/20251110_144218/plots/03_speedup_summary.png create mode 100644 benchmarks/results/20251110_144218/plots/04_absolute_timing.png create mode 100644 benchmarks/results/20251110_144218/plots/05_lizards_distribution.png create mode 100644 benchmarks/results/20251110_144218/plots/summary_statistics.csv create mode 100644 benchmarks/results/20251110_144218/test_results.txt create mode 100644 benchmarks/results/20251110_144957/benchmark_data.RData create mode 100644 benchmarks/results/20251110_144957/benchmark_results.txt create mode 100644 benchmarks/results/20251110_144957/plots/01_lizards_comparison.png create mode 100644 benchmarks/results/20251110_144957/plots/02_endometrial_comparison.png create mode 100644 benchmarks/results/20251110_144957/plots/03_speedup_summary.png create mode 100644 benchmarks/results/20251110_144957/plots/04_absolute_timing.png create mode 100644 benchmarks/results/20251110_144957/plots/05_lizards_distribution.png create mode 100644 benchmarks/results/20251110_144957/plots/summary_statistics.csv diff --git a/benchmarks/main_benchmark.R b/benchmarks/main_benchmark.R index 441df5a..4d6f2c0 100644 --- a/benchmarks/main_benchmark.R +++ b/benchmarks/main_benchmark.R @@ -17,68 +17,55 @@ tryCatch({ cat("Timestamp:", timestamp, "\n") cat(separator, "\n\n") -# ====== SECTION 1: Test Suite Execution ====== -cat("\n", separator, "\n") -cat("SECTION 1: TEST SUITE EXECUTION\n") -cat(separator, "\n\n") + # ====== SECTION 1: Test Suite Execution ====== + cat("\n", separator, "\n") + cat("SECTION 1: TEST SUITE EXECUTION\n") + cat(separator, "\n\n") -pkg_path <- "C:/Users/ollie/OneDrive/Desktop/UNI/Project brglm2/brglm2" + pkg_path <- "C:/Users/ollie/OneDrive/Desktop/UNI/Project brglm2/brglm2" -# Ensure DD is available in case internal calls need it -if (!exists("DD", mode = "function")) { - DD <- function(expr, name, order = 1) { - if(order < 1) stop("'order' must be >= 1") - if(order == 1) D(expr, name) - else DD(D(expr, name), name, order - 1) + # Ensure DD exists for internal brglm2 calls + if (!exists("DD", mode = "function")) { + DD <- function(expr, name, order = 1) { + if(order < 1) stop("'order' must be >= 1") + if(order == 1) D(expr, name) + else DD(D(expr, name), name, order - 1) + } } -} -run_test_suite <- function(libpath, label) { - cat("Running test suite for", label, "version...\n") - cat("Library path:", libpath, "\n\n") - - # Load brglm2 version - library(brglm2, lib.loc = libpath) - library(tinytest) - - # Run test suite, timing total duration - start <- Sys.time() - result <- test_all(pkg_path) - elapsed <- as.numeric(difftime(Sys.time(), start, units = "secs")) - - # Summarise results safely - sum_df <- as.data.frame(result) - if ("ok" %in% names(sum_df)) { - passes <- sum(sum_df$ok) - fails <- sum(!sum_df$ok) - } else { - # fallback if tinytest version differs - passes <- NA - fails <- NA - warning("Could not extract passes/fails from test results") + run_test_suite <- function(libpath, label) { + library(brglm2, lib.loc = libpath) + library(tinytest) + + cat("Running test suite for", label, "version...\n") + start <- Sys.time() + + result <- test_all(pkg_path) + elapsed <- as.numeric(difftime(Sys.time(), start, units = "secs")) + + # Summarise + sum_df <- as.data.frame(result) + n_passed <- sum(sum_df$ok) + n_total <- nrow(sum_df) + + cat(sprintf("%s: %d/%d tests OK (%.1fs)\n\n", label, n_passed, n_total, elapsed)) + + invisible(list(result = result, passes = n_passed, total = n_total, elapsed = elapsed)) } - - cat(sprintf("All ok, %d results (%.1fs)\n\n", passes + fails, elapsed)) - - invisible(list(result = result, passes = passes, fails = fails, elapsed = elapsed)) -} - -# --- Run NEW version --- -new_results <- run_test_suite(LIB_NEW, "NEW") -# --- Run ORIGINAL version --- -orig_results <- run_test_suite(LIB_ORIGINAL, "ORIGINAL") + # Run NEW version + new_results <- run_test_suite(LIB_NEW, "NEW") -# --- Save summary file (concise) --- -test_output_file <- file.path(results_dir, "test_results.txt") -cat(sprintf( - "Original: %d tests (%.1fs)\nNew: %d tests (%.1fs)\nSpeedup: %.2fx faster\n", - orig_results$passes + orig_results$fails, orig_results$elapsed, - new_results$passes + new_results$fails, new_results$elapsed, - orig_results$elapsed / new_results$elapsed -), file = test_output_file) + # Run ORIGINAL version + orig_results <- run_test_suite(LIB_ORIGINAL, "ORIGINAL") -cat("\nDetailed test results saved to:", test_output_file, "\n") + # Optional summary in CLI + cat(sprintf( + "Summary:\n Original: %d/%d tests OK (%.1fs)\n New: %d/%d tests OK (%.1fs)\n Speedup: %.2fx faster\n\n", + orig_results$passes, orig_results$total, orig_results$elapsed, + new_results$passes, new_results$total, new_results$elapsed, + orig_results$elapsed / new_results$elapsed + )) # ====== SECTION 2: Microbenchmark Comparison ====== cat("\n", separator, "\n") diff --git a/benchmarks/results/20251110_144218/benchmark_data.RData b/benchmarks/results/20251110_144218/benchmark_data.RData new file mode 100644 index 0000000000000000000000000000000000000000..76637f1bb1dedd22b1bab241148a13300ee879e8 GIT binary patch literal 2111 zcmV-F2*CFriwFP!000002Gv-5R20`89$=SO3?kK3n;5YtQ81P8D3~gAAz~C8Bhf0T zG%)PWvX7a4%*;Mumt~iiXnbI*N0U;En3IyEA=XEm;>jsCMlIErswn1YLYf|roK}sd z(Zn=tXTIxF+^}Gq{NtXpeEWNUzkBE2`5l(!7iYv4$5Ip(K`E5sRD@FcNkz^tOiRy9 zrzl0ZB!y85Dn`QlS$!4FYlPBr#-!Fs5#N%Ol0(G(5*~viH7I@Kr0=o3s;2B#=|`Sp$}@#By0YD6GCJRKcxChyOz8s7%IT4@cGlh`8SCF0 zFCXT-pND1bmvOU)TO{MAx?jV;eqc9b=lebi@oW2#-?OEtS;m@6gTTsP44}Tv8UfkY z-_nHmTaOSv=U)aoA8LWWd&r*gIq1W2?gz+g`SLR2 z_)FQy<6AI~(2EORgkG%9K|Nda zRpfC#vlxC3vl_Ck?-ighSU~!DEEHQ&5O{hA3g;?W8nuR|GeTJ65oxw{P9VI=f1xY zKJVNl>y;1>e`eVk?5AxSkM*?1r^3&8s{(edcDWaM{ClAK*L{e!v0+ATI4Uwo=N!GPf>`UFq_De zHIR+xx1hf=`$ougW+G&5Zx_%IM|iQ5t|5*tI|}`Crjy98ake7PlI{j?ZPr4vPbJ~# zi~ZSY#F^#@z>2WHBcJi7m5{lptH846MTo2DCdh2H1Iv$Whree3X~;(7O8D!hehyhT zP)+Ct1zasmzbqD-SeTyLr+c%<)x$hX_%{vxBuJ%yGuD2B; zAM+0Bzt;e?C>{lxJpz#}t5C;u^a_!;BtzD|zZ3;NI^+GRD?A``G{PoS~(|+X$P`Ho>JAdnC)U}?`LFR7wk(bY? zA#tyy^^zG4Vt5)^zmtPxzYFrwpEf)NvS|Df;vI*gp!c4mqp@zisgPY$eRAI5*N%zi znBdoyf^k~-z;98{F(fF$ALJLu>D9a$V8hYG9PeYnKx9aUgN`AT@{k%s;yUpDtqvNbK zS4Qts#bq*9u79XdM(4CTpym116tHsu@xshr=uIt?T4glHT!h~I!d#$X_qV+=ax-bj z`kfyE?d=Cp$9=vLaaH%d5f47AE`yKbgbi{{TLSX?Rz%{q^IY$Qy}{W59<>c?kl$-H zx64>J^)>j_O)i4$JGBn^y`TN&l8lW-^&dl@?}6N~CJXuNY%_7{YyBF;uWuet;`Kak z+r|Uwso;Ai4E24k4X{^dt_KgFqO~9K9eXgX*-Ed&ujXPF?B2*9qwczSucOY|J$o_z z`680RqbBJz{M{SLTh*8PC3ra6$aGXWpapujmZM)^TLt1Pldgfkd-^!+Ut^{cyqc!e zBX3jR0Qd+69Q1r!7jlvm!H4b}zTlN|-0=Inh3F%LPwR-p@Pfu=MqgMLpYCe;jifRjBh^r#T!kg8l|LtsO1(X2? zo51iX0>f$p_mEI2440!AmbM6tCeSnd)jB;J(8S0AMDf+0?hEvU+w68rs;UpAo}8*L z8XkV@*?%K&(bz1~c?*~OQK&AzxUbL@bx3usYeU#avo@%%PU!T-FEyw> zUcSAyi28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z literal 0 HcmV?d00001 diff --git a/benchmarks/results/20251110_144218/plots/02_endometrial_comparison.png b/benchmarks/results/20251110_144218/plots/02_endometrial_comparison.png new file mode 100644 index 0000000000000000000000000000000000000000..7848440833695b218fdcb3a95161ac8a2ccbfd7f GIT binary patch literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z literal 0 HcmV?d00001 diff --git a/benchmarks/results/20251110_144218/plots/03_speedup_summary.png b/benchmarks/results/20251110_144218/plots/03_speedup_summary.png new file mode 100644 index 0000000000000000000000000000000000000000..7848440833695b218fdcb3a95161ac8a2ccbfd7f GIT binary patch literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z literal 0 HcmV?d00001 diff --git a/benchmarks/results/20251110_144218/plots/04_absolute_timing.png b/benchmarks/results/20251110_144218/plots/04_absolute_timing.png new file mode 100644 index 0000000000000000000000000000000000000000..7848440833695b218fdcb3a95161ac8a2ccbfd7f GIT binary patch literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z literal 0 HcmV?d00001 diff --git a/benchmarks/results/20251110_144218/plots/05_lizards_distribution.png b/benchmarks/results/20251110_144218/plots/05_lizards_distribution.png new file mode 100644 index 0000000000000000000000000000000000000000..7848440833695b218fdcb3a95161ac8a2ccbfd7f GIT binary patch literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z literal 0 HcmV?d00001 diff --git a/benchmarks/results/20251110_144218/plots/summary_statistics.csv b/benchmarks/results/20251110_144218/plots/summary_statistics.csv new file mode 100644 index 0000000..ea87d87 --- /dev/null +++ b/benchmarks/results/20251110_144218/plots/summary_statistics.csv @@ -0,0 +1,5 @@ +"Dataset","Version","Median","Mean","SD" +"Lizards","Original",0.0172598505,0.02005687496,0.0127806048378596 +"Lizards","New",0.0186590505,0.02051141999,0.00995345879697426 +"Endometrial","Original",0.032562301,0.03291419496,0.0106647091686285 +"Endometrial","New",0.029348401,0.02991950706,0.00952642493897422 diff --git a/benchmarks/results/20251110_144218/test_results.txt b/benchmarks/results/20251110_144218/test_results.txt new file mode 100644 index 0000000..ed74bc5 --- /dev/null +++ b/benchmarks/results/20251110_144218/test_results.txt @@ -0,0 +1,3 @@ +Original: NA tests (137.4s) +New: NA tests (97.8s) +Speedup: 1.40x faster diff --git a/benchmarks/results/20251110_144957/benchmark_data.RData b/benchmarks/results/20251110_144957/benchmark_data.RData new file mode 100644 index 0000000000000000000000000000000000000000..5fe7e2cb7bf6d505c63242a7bfe210c9d12c8832 GIT binary patch literal 2129 zcmV-X2(I@ZiwFP!000002Gv-5a8qR#zkSjNbXjQ?R%KHZwnZ(K*Mh(%rBtxC*cOWH z;L@haZHXpryh)nm=5>=MG!@x~Iz^tl6-E}OE>;Dt$ZYGPvvt^2kY%ZZBCWKdh!&g< z%uwmx`#YptVjsA>|G-Q*_dAc@`JHpV@7`}(uw?bDxYcnC!$dHVQQ=HPl=#R*XXZUT zbIweLi3}H4VN4_wE6Q?=ehlp{aY=a}#1HZ5kU8sGqPgsb5 zXl!WwQ1(!~P}^|!p*Vzc8H&eH_Tgej;&rR|qxEw*{v+l3U-~i<-_hzH32V4qqxE*Q zeKr*SNPBIhI!D@j!|d0a4pX$2tz@+Z@o79fNE=hZY05O^O6`qxL^*2?35-%{m4;y4 z09vV1Wvt-Dr|aS`LHxC4cpImQhm^^1XPxjvKJfvhaBzHzBwZIgd62EsAU&(Pq(hwH zoI9KJ%PhwvY29-LQiyFiFG>E_DX=?!x2+g!;~f%}3}br+^oA>+HAu3u=p^*dw*OfH zzYB!J&D$CPeo7nSh5Bz0XSNp0uwL1@40v;=BF?lR7ygxN=Kgn=QKJ`&Z_x3R8U9TvB@2Pl<`gQ){bgaLB2e_W| zX5{nq6;r=06fwKi)qcc4LnV{z60w>fw`DLT{-%3TeB02Kd^N71L?LtN#&1+ZH`%Aq;@@Hf~U50ub+Iv#~I zH{FB&n70Vv>HM-8_1O2VEJi%nLb#j;dfR5=>-fD9JS>5)iBIAz%5&rj_}G5_5$ZGd zSCjrz0c*Q&D$Re)DVnF{67kQb^T1DOhjceIS zMjGO6k6YpI$oUP`AHN^`?UOzy{DW%5d;UOqg=d!cKsx*M=x6>p^wC+cRN@=@*(q1* z*wD{aBx})g!DpjJ$5K#4e~4d#PNU)~aBb8nxo2)@ZP0M!VepHy7Spx!{dd+X&dw>t^^){{l_f~h7cmBU z?}5GWz3%!zj!SWWQxBeHv3G8eD&U2k^#MeAo*#z8VKlrTA??8Q?Ne3W(rs?3} z+4WUAaCA*r+sDTsk4Lr~eekS!6S#cGzZl4wvtW1H9H`4v`8wS;Wod|ap5CQEolCM1 z=YClZ9*(+xFJuj^nJ=41KLL3wBSAnp9ywEpzQ zSMB*lh!ZZ%Z9u-jY|86h0epwD6?M2e7Z9&?`M|AWE>Zo@ZUHaX({BUE8@-k4N!vp6 z`DcLU)%!j9CqDrxoXTyZy8Gepm8YZcp1E_#f7(gfcT>KA-QTtWYhPA3_*b!Kz_0$} z?sJmdS{(zPFP440M3Osdw}EF(=6u9gpA`_du{;_3t-3buEcU~h7Sz4N6@mS-Qx|(6g4mH=^*B0~?||M>+UCB+SXpYI@jbm$2l@*O@_ zB2c6&Et1{@A_?hWM=2D6-KXLf>E+iK>BR?yBD3(XwNIs7bzPN;8nY`Xhj~@R>bVM4 z(SIr%=s;A^!DL{$Gy|(G4ZepAR>R=+7*?y)8(4L)X85btX|zF2tQ0_sAJ-HgtO;+k zU`dU>$<6sa@?P=(3qF}*@nW%}-qzcsq@PhqYO7v*)1>5Q#bPEOV&n(-j-~sP7i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z literal 0 HcmV?d00001 diff --git a/benchmarks/results/20251110_144957/plots/02_endometrial_comparison.png b/benchmarks/results/20251110_144957/plots/02_endometrial_comparison.png new file mode 100644 index 0000000000000000000000000000000000000000..7848440833695b218fdcb3a95161ac8a2ccbfd7f GIT binary patch literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z literal 0 HcmV?d00001 diff --git a/benchmarks/results/20251110_144957/plots/03_speedup_summary.png b/benchmarks/results/20251110_144957/plots/03_speedup_summary.png new file mode 100644 index 0000000000000000000000000000000000000000..7848440833695b218fdcb3a95161ac8a2ccbfd7f GIT binary patch literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z literal 0 HcmV?d00001 diff --git a/benchmarks/results/20251110_144957/plots/04_absolute_timing.png b/benchmarks/results/20251110_144957/plots/04_absolute_timing.png new file mode 100644 index 0000000000000000000000000000000000000000..7848440833695b218fdcb3a95161ac8a2ccbfd7f GIT binary patch literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z literal 0 HcmV?d00001 diff --git a/benchmarks/results/20251110_144957/plots/05_lizards_distribution.png b/benchmarks/results/20251110_144957/plots/05_lizards_distribution.png new file mode 100644 index 0000000000000000000000000000000000000000..7848440833695b218fdcb3a95161ac8a2ccbfd7f GIT binary patch literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z literal 0 HcmV?d00001 diff --git a/benchmarks/results/20251110_144957/plots/summary_statistics.csv b/benchmarks/results/20251110_144957/plots/summary_statistics.csv new file mode 100644 index 0000000..752d2e6 --- /dev/null +++ b/benchmarks/results/20251110_144957/plots/summary_statistics.csv @@ -0,0 +1,5 @@ +"Dataset","Version","Median","Mean","SD" +"Lizards","Original",0.029412801,0.02957711407,0.00609669878307209 +"Lizards","New",0.028598351,0.029392598,0.00532998275559886 +"Endometrial","Original",0.040655901,0.04680443282,0.0205270555333662 +"Endometrial","New",0.043849851,0.05011108294,0.022082500465604 diff --git a/benchmarks/run_all.R b/benchmarks/run_all.R index 4614f3c..cf16b7c 100644 --- a/benchmarks/run_all.R +++ b/benchmarks/run_all.R @@ -52,11 +52,6 @@ cat("======================================================================\n\n" cat("Total runtime:", format(difftime(end_time, start_time)), "\n") cat("Results directory:", file.path("benchmarks", "results"), "\n\n") -cat("Next steps:\n") -cat(" 1. Review benchmark_results.txt for detailed timing\n") -cat(" 2. Check plots/ directory for visualizations\n") -cat(" 3. Review test_results.txt for test suite output\n\n") - cat("Summary of improvements:\n") results_dir <- file.path("benchmarks", "results") dirs <- list.dirs(results_dir, recursive = FALSE) From 813eba171c4642850494350868f1ee24365f0cd6 Mon Sep 17 00:00:00 2001 From: Ollie Date: Fri, 14 Nov 2025 11:14:03 +0000 Subject: [PATCH 10/15] Benchmarking scripts complete with readme for local installation --- .gitignore | Bin 1835 -> 1572 bytes benchmarks/benchmark_readme.md | 384 +++++++++++++++++++++++++++++++++ benchmarks/check_setup.R | 15 +- benchmarks/main_benchmark.R | 87 ++++---- benchmarks/run_all.R | 4 +- benchmarks/visualize_results.R | 317 +++++++++++++++------------ 6 files changed, 604 insertions(+), 203 deletions(-) create mode 100644 benchmarks/benchmark_readme.md diff --git a/.gitignore b/.gitignore index 34e8aee44d2445c61b8eab759de538a5790c1b33..98449dbc736dd91f3357ecd399a436a52b62b006 100644 GIT binary patch literal 1572 zcmaJ>!H(lL487|s2;^q0rRnxkOiweLneGDJPLWI(Jq!>i5*=$TTZTkuCO!1qmy(^N z-NT+tQuHJB_$W6dQZ^VNR;v~C+B|K6EwO^%aKNa&kn8PkOCh3=cjM@B9j3i!=lAW? z5o2@~`Cs^C!T|l02yn3Q>Zk>J4e%00KFJx+?bPoF?R*k)SLMi~^O%5IP0+hTOQ6RQ zbp$tX5Fv&@5E{^M41VglkBZrd}aytg{8EiRv#(oS@ z$I~amo-02`omyn$OTo;|NoNKQn9xgZz@sGBBQw#u0i_K?pfO@%{M_@}MKsKYML*eX96*G6h`p}GDES0(h@udZ!wBXzpyl{N9$6@ zrFlG?Wi%gM;ucQOWCDfUw6o6^UqGHc?skhQ^8{;6`jVZUe3gec-Sc(91dEyTQJYR5 z5cZSv7RDG1|1GNe;Z1IG{?kO`L^BLDG4$NehtKOdU#Lowj`Hx&k5WyGrpu|DVyT?F z+0tZPxU|QGzsf0LET`<*$uO};cNma}?|ZQrr={NiFEHAsG;lXj`yMECIJ|>|2rbc= zZk0N)G^c%@wraKYcv5^4RYZ?EVN#?I>Ubl67K}}?4w`{7VmCO7pjq4-UX$3_@H&9S zMo*r=uv!r8RU3TAT?s0omM>#mhg&9h5zYSeA5c-riJD(zZ`sOKvo()j-iI(3-VzUM zQN!juxm(zu&vQ*T92Qc!nNlz_$})Ojai`_yx~idP0o(!;!xZzL{|X!w)xY9pRlTf) zl6e`Dw2N%N^Q8|w(n_K?g1HKH(nqX4D^gHofeFblWhC)X=So5bww$f`M@@N)MYYqB z`#qMIr17U-cR1&Ag5i5Y^d${=)#d85Nbbmm)o7*GaoTw<+v&(L(@(mPQsUN)*VE6Zg>H-ba1d z!5;S9lV*nGo0&HsGF_0obVa&KS2s5|)av4CN06Y>FWj-$HeIRBZod=f8RC84Ti&?g zV59ci?&-wdn-WTV@~LngwL=i%uB2BZHOZ@^7oV=;(RAs#9@;~vjSWE9uP5W9u^dQh zE!3K0Eu{ONwI|cT$mE?9ausPhIXkq`_r?_vI@$8c1mn7pefj?O76(<}6YQacyz8CV zh_@U*bK5(w{rQt{8v}UuI@BDcFC%h{Q<FRd|XTG5^GJ15j zWbk(hoR-LSUz*U25ukM2rEI^NfKbjttUeik&L>iv0yt6kvrOG(bpGIn=*TN z(=GC+!j&9r(d(koN2bGIY)QR$1pw03I(v9i+v&;EApIZ{7**c22<_wN&GaN)?V`r3Wiipre?|Yxl&2_oEf*8Cs1MFf0qg{ITpDJ(RP~My%Z2FLbjO8fL^ZmdNCwseh9N8f z**c>Z4RS{y3bbQW{7f(+hJVx5%gy=)`y^L!fPyNQHvh_?tcwL-E4EliAkbw&pE$GV z-gG4%eF%C1HW$kuv*;5x2ho%n-fM|_03dtq5&vo4N|imgy5adgQkir$Low#x+DodF znqS5wpAA+AL8&J9YN~{ROeBf9~L?^ z?=V%=afBh4`NpF?&vStkMrj}Un&2@5*u@dPzO>XCp-uJ~A&v`H)wpbz1#z`aKubSj zf4QzQ$H9-hf@z$LG~00TiWwW1Rp4UqMxw*nlr1Jzj_V};XAnjHnI%$nNI2<|BB_%$ b(TPu*BqTY$jPH=xL`Hp`q{%AzKivHftz95A diff --git a/benchmarks/benchmark_readme.md b/benchmarks/benchmark_readme.md new file mode 100644 index 0000000..20a4f6b --- /dev/null +++ b/benchmarks/benchmark_readme.md @@ -0,0 +1,384 @@ +# BRGLM2 Benchmarking Suite + +Comprehensive performance benchmarking framework for comparing original and optimized versions of the brglm2 R package. + +## Overview + +This suite compares the performance of two versions of brglm2: +- **Original**: Main branch implementation +- **New**: Optimized implementation with performance improvements + +The benchmarks test across multiple datasets (small, medium, and large) and different fitting methods (brglmFit and mdyplFit). + +## Repository Structure +``` +parent-directory/ +├── brglm2/ # Your working branch +│ ├── benchmarks/ +│ │ ├── benchmark_readme.md # You're here (if this wasnt obvious) +│ │ ├── setup.R # Configuration and setup +│ │ ├── check_setup.R # Validation script +│ │ ├── main_benchmark.R # Core benchmarking tests +│ │ ├── visualize_results.R # Plot generation +│ │ ├── run_all.R # Master execution script +│ │ └── results/ # Output directory (auto-created) +│ │ └── YYYYMMDD_HHMMSS/ # Timestamped results +│ │ ├── benchmark_results.txt +│ │ ├── benchmark_data.RData +│ │ └── plots/ +│ ├── R/ # Your source code +│ ├── tests/ +│ └── ... +│ +├── brglm2-original/ # Clone of main branch (reference) +│ └── ... +│ +└── benchmark_libs/ # Installed package versions + ├── original/ + │ └── brglm2/ # Compiled original version + │ ├── R/ + │ ├── data/ + │ ├── libs/ + │ ├── Meta/ + │ ├── DESCRIPTION + │ └── ... + └── new/ + └── brglm2/ # Compiled optimized version + ├── R/ + ├── data/ + ├── libs/ + ├── Meta/ + ├── DESCRIPTION + └── ... +``` + +The `benchmark_libs` folder contains **installed (compiled) R packages**. This is essential for dual loading for comparison. + +## Initial Setup + +### 1. Directory Structure Setup + +Starting from your parent directory (containing all projects): + +```bash +# Navigate to parent directory +cd /path/to/parent-directory + +# If not already present, create benchmark_libs +mkdir -p benchmark_libs/original +mkdir -p benchmark_libs/new + +# Clone main branch for reference (if not already done) +git clone brglm2-original +cd brglm2-original +git checkout main +cd .. + +# Your working branch (if not already present) +git clone brglm2 +cd brglm2 +git checkout -b benchmark-testing # or your optimization branch + +# Create results directory +mkdir -p benchmarks/results +``` + +### 2. Install Package Versions to `benchmark_libs` + +From the parent directory: + +```bash +# Install original version from main branch clone +cd brglm2-original +R CMD INSTALL . --library=../benchmark_libs/original + +# Install new version from your working branch +cd ../brglm2 +R CMD INSTALL . --library=../benchmark_libs/new +``` + +**Important**: After making changes to your optimized code, reinstall to `benchmark_libs/new`: + +```bash +cd brglm2 +R CMD INSTALL . --library=../benchmark_libs/new +``` + +### 3. Configure Paths + +Edit `brglm2/benchmarks/setup.R` to point to the correct locations. + +**If running from `brglm2/` directory** (recommended), use relative paths: + +```r +# Paths relative to brglm2/ directory +LIB_ORIGINAL <- "../benchmark_libs/original" +LIB_NEW <- "../benchmark_libs/new" +``` + +**Or use absolute paths**: + +```r +# Example absolute paths (adjust for your system) +LIB_ORIGINAL <- "C:/path/to/parent-directory/benchmark_libs/original" +LIB_NEW <- "C:/path/to/parent-directory/benchmark_libs/new" +``` + +Also update the package path in `brglm2/benchmarks/check_setup.R`: + +```r +# Absolute path to your working brglm2 source +pkg_path <- "C:/path/to/parent-directory/brglm2" +``` + +### 4. Install Required R Packages + +```r +install.packages(c("tictoc", "rbenchmark", "microbenchmark", + "ggplot2", "tinytest")) +``` + +### 5. Verify Setup + +From the `brglm2/` directory: + +```r +setwd("C:/path/to/parent-directory/brglm2") # Set working directory +source("benchmarks/check_setup.R") +``` + +This will verify: +- R version compatibility +- Required packages installed +- Library paths exist and contain brglm2 +- Test datasets accessible +- Results directory structure + +## Running Benchmarks + +### Quick Start + +**From the `brglm2/` directory** (your working branch): + +```r +# Set working directory (if not already there) +setwd("C:/path/to/parent-directory/brglm2") + +# Run complete benchmark suite +source("benchmarks/run_all.R") +``` + +This executes: +1. Setup validation +2. Test suite execution (both versions) +3. Microbenchmark comparisons (100 evaluations) +4. Large dataset tests +5. MDYPL method comparison +6. Visualization generation + +Expected runtime: ~5 minutes (default settings) + +### Individual Components + +Run specific benchmark sections: + +```r +# Setup and configuration +source("benchmarks/setup.R") + +# Main benchmarks only +source("benchmarks/main_benchmark.R") + +# Generate plots from existing results +source("benchmarks/visualize_results.R") +``` + +### Workflow After Code Changes + +When you modify your optimized code: + +```bash +# 1. Reinstall the new version +cd /path/to/parent-directory/brglm2 +R CMD INSTALL . --library=../benchmark_libs/new + +# 2. Re-run benchmarks +# In R: +setwd("C:/path/to/parent-directory/brglm2") +source("benchmarks/run_all.R") +``` + +## Benchmark Components + +### 1. Test Suite Validation +- Runs complete tinytest suite for both versions +- Verifies numerical correctness +- Reports pass/fail rates and execution time + +### 2. Microbenchmark Tests + +#### Small Dataset (Lizards) +- Dataset: 409 observations, binomial GLM +- Default: 100 evaluations +- Tests: brglmFit method + +#### Medium Dataset (Endometrial) +- Dataset: 79 observations, probit link +- Default: 50 evaluations +- Tests: brglmFit method + +### 3. Large Dataset Tests + +#### MultipleFeatures Dataset +- Dataset: 2000 observations, 432 features +- High-dimensional classification problem +- Single timing test (computationally intensive) +- Tests: brglmFit and mdyplFit methods + +### 4. Visualizations + +Generated plots: +- `01_lizards_comparison.png` - Boxplot comparison +- `02_endometrial_comparison.png` - Boxplot comparison +- `03_speedup_summary.png` - Speedup factor bar chart +- `04_absolute_timing.png` - Absolute execution times +- `05_lizards_distribution.png` - Distribution densities + +## Increasing Evaluation Counts + +To improve consistency and reduce variability: + +### In `main_benchmark.R` + +**Lizards microbenchmark** (Line ~68): +```r +lizards_bench <- microbenchmark( + # ... + times = 1000, # Change to increase/decrease test numbers + unit = "s" +) +``` + +**Endometrial microbenchmark** (Line ~91): +```r +endo_bench <- microbenchmark( + # ... + times = 500, # Change to increase/decrease test numbers + unit = "s" +) +``` + +**MultipleFeatures tests** (Lines ~138-162): +For more robust timing on large datasets, increase replications. + +```r +time_mf_orig <- system.time({ + replicate(5, { # Change from 5 replications + fit_mf_orig <- glm(full_mf_fm, data = MultipleFeatures, + family = binomial(), + method = brglm2_original, + subset = training, + maxit = 200) + }) +}) + +# Divide elapsed time by number of replications for average +cat("Average time per run:", time_mf_orig["elapsed"] / 5, "s\n") +``` + +**MDYPL tests** (Lines ~195-221): +Similarly change replications: + +```r +time_mdypl_orig <- system.time({ + replicate(5, { # Change from 5 replications + fit_mdypl_orig <- glm(full_mf_fm, data = MultipleFeatures, + family = binomial(), + method = mdypl_original, + alpha = alpha_val, + subset = training, + maxit = 200) + }) +}) +``` + +### Recommended Settings for 10-Minute Runtime + +```r +# Microbenchmarks +lizards: times = 400 +endometrial: times = 200 + +# Large dataset tests +MultipleFeatures (brglmFit): replicate(5, ...) +MDYPL: replicate(5, ...) +``` + +## Output Files + +### Results Directory Structure + +Each run creates a timestamped directory: + +``` +benchmarks/results/YYYYMMDD_HHMMSS/ +├── benchmark_results.txt # Complete text output +├── benchmark_data.RData # R objects for plotting +└── plots/ + ├── 01_lizards_comparison.png + ├── 02_endometrial_comparison.png + ├── 03_speedup_summary.png + ├── 04_absolute_timing.png + └── 05_lizards_distribution.png +``` + +### Key Metrics Reported + +- **Speedup factors**: New vs Original execution time ratios +- **Absolute timings**: Median/mean execution times +- **Test results**: Pass/fail counts for validation +- **Numerical accuracy**: Coefficient and deviance comparisons + +## Troubleshooting + +### Common Issues + +**"Original library path does not exist"** +- Update `LIB_ORIGINAL` in `benchmarks/setup.R` +- Ensure brglm2 is installed: `R CMD INSTALL . --library=path/to/original` + +**"brglm2 package NOT found"** +- Reinstall packages in both library locations +- Verify installation: `library(brglm2, lib.loc="path/to/lib")` + +**"Package directory does NOT exist"** +- Update `pkg_path` in `benchmarks/check_setup.R` and `main_benchmark.R` +- Ensure you're running from project root + +**Plots fail to generate** +- Check that `benchmark_data.RData` was created +- Verify ggplot2 is installed +- Review error messages in console output + +### Verifying Results + +Successful benchmarks should show: +- All tests passing (or matching pass rate between versions) +- Speedup factors > 1.0 (new faster than original) +- Numerical accuracy: coefficient differences < 1e-10 + +## Notes + +- The test suite execution times are included in overall speedup metrics +- Large dataset tests use single evaluations due to computational cost +- All visualizations use consistent color scheme: Red (original), Green (new) +- Benchmark data is saved for regenerating plots without re-running tests + +## Citations + +- Kosmidis, I., & Firth, D. (2021). Jeffreys-prior penalty, finiteness and shrinkage in binomial-response generalized linear models. *Biometrika*, 108(1), 71-82. +- Sterzinger, P., & Kosmidis, I. (2024). An iteratively reweighted least squares algorithm for the maximum Diaconis-Ylvisaker prior penalized likelihood in binomial-response generalized linear models. + +## License + +Same as parent brglm2 package. \ No newline at end of file diff --git a/benchmarks/check_setup.R b/benchmarks/check_setup.R index 365bcd7..115f5b7 100644 --- a/benchmarks/check_setup.R +++ b/benchmarks/check_setup.R @@ -187,17 +187,4 @@ if (all_ok) { cat("4. Check that brglm2 is installed in both library locations\n") } -cat("\n", strrep("=", 70), "\n\n") - -# ====== Helpful Commands ====== -cat("Helpful commands:\n\n") -cat("Check current working directory:\n") -cat(" getwd()\n\n") -cat("Change working directory:\n") -cat(" setwd('path/to/project')\n\n") -cat("Install a package:\n") -cat(" install.packages('package_name')\n\n") -cat("List installed packages:\n") -cat(" installed.packages()[,c('Package', 'LibPath')]\n\n") -cat("Check where package is installed:\n") -cat(" find.package('brglm2')\n\n") \ No newline at end of file +cat("\n", strrep("=", 70), "\n\n") \ No newline at end of file diff --git a/benchmarks/main_benchmark.R b/benchmarks/main_benchmark.R index 4d6f2c0..f064602 100644 --- a/benchmarks/main_benchmark.R +++ b/benchmarks/main_benchmark.R @@ -24,15 +24,6 @@ tryCatch({ pkg_path <- "C:/Users/ollie/OneDrive/Desktop/UNI/Project brglm2/brglm2" - # Ensure DD exists for internal brglm2 calls - if (!exists("DD", mode = "function")) { - DD <- function(expr, name, order = 1) { - if(order < 1) stop("'order' must be >= 1") - if(order == 1) D(expr, name) - else DD(D(expr, name), name, order - 1) - } - } - run_test_suite <- function(libpath, label) { library(brglm2, lib.loc = libpath) library(tinytest) @@ -40,12 +31,15 @@ tryCatch({ cat("Running test suite for", label, "version...\n") start <- Sys.time() + sink(NULL) result <- test_all(pkg_path) + sink(file.path(results_dir, "benchmark_results.txt"), append = TRUE, split = TRUE) + elapsed <- as.numeric(difftime(Sys.time(), start, units = "secs")) # Summarise sum_df <- as.data.frame(result) - n_passed <- sum(sum_df$ok) + n_passed <- sum(sum_df$result == TRUE) n_total <- nrow(sum_df) cat(sprintf("%s: %d/%d tests OK (%.1fs)\n\n", label, n_passed, n_total, elapsed)) @@ -70,7 +64,7 @@ tryCatch({ # ====== SECTION 2: Microbenchmark Comparison ====== cat("\n", separator, "\n") cat("SECTION 2: MICROBENCHMARK COMPARISON\n") - cat("(100 evaluations with unit: seconds)\n") + cat("(1000 evaluations with unit: seconds)\n") cat(separator, "\n\n") cat("Test: Lizards dataset (small)\n") @@ -83,7 +77,7 @@ tryCatch({ family = binomial(), method = brglm2_new, maxit = 200), - times = 100, + times = 1000, unit = "s" ) print(lizards_bench) @@ -100,7 +94,7 @@ tryCatch({ data("endometrial", package = "brglm2") endo_fm <- HG ~ NV + PI + EH - cat("Microbenchmark (50 evaluations):\n") + cat("Microbenchmark (500 evaluations):\n") endo_bench <- microbenchmark( original = glm(endo_fm, data = endometrial, family = binomial("probit"), @@ -110,7 +104,7 @@ tryCatch({ family = binomial("probit"), method = brglm2_new, maxit = 200), - times = 50, + times = 500, unit = "s" ) print(endo_bench) @@ -147,29 +141,34 @@ tryCatch({ cat(" Number of features:", length(vars), "\n") cat(" Dimensionality ratio (kappa):", round(kappa, 4), "\n\n") - cat("Running single timing test...\n\n") + cat("Running timing tests...\n\n") cat("Original version timing:\n") time_mf_orig <- system.time({ + replicate(10, { fit_mf_orig <- glm(full_mf_fm, data = MultipleFeatures, family = binomial(), method = brglm2_original, subset = training, maxit = 200) }) - print(time_mf_orig) - cat("\n") +}) + + cat("Average time per run:", time_mf_orig["elapsed"] / 10, "s\n\n") cat("New version timing:\n") time_mf_new <- system.time({ - fit_mf_new <- glm(full_mf_fm, data = MultipleFeatures, - family = binomial(), - method = brglm2_new, - subset = training, - maxit = 200) + replicate(10, { # Change from 10 replications + fit_mf_new <- glm(full_mf_fm, data = MultipleFeatures, + family = binomial(), + method = brglm2_new, + subset = training, + maxit = 200) + }) }) - print(time_mf_new) - cat("\n") + + # Divide elapsed time by number of replications for average + cat("Average time per run:", time_mf_orig["elapsed"] / 10, "s\n") cat("MultipleFeatures speedup:", time_mf_orig["elapsed"] / time_mf_new["elapsed"], "x\n") @@ -203,26 +202,30 @@ tryCatch({ cat("Original mdyplFit timing:\n") time_mdypl_orig <- system.time({ - fit_mdypl_orig <- glm(full_mf_fm, data = MultipleFeatures, - family = binomial(), - method = mdypl_original, - alpha = alpha_val, - subset = training, - maxit = 200) + replicate(50, { + fit_mdypl_orig <- glm(full_mf_fm, data = MultipleFeatures, + family = binomial(), + method = mdypl_original, + alpha = alpha_val, + subset = training, + maxit = 200) + }) }) - print(time_mdypl_orig) + cat("Average time per run:", time_mdypl_orig["elapsed"] / 50, "s\n") cat("\n") cat("New mdyplFit timing:\n") time_mdypl_new <- system.time({ - fit_mdypl_new <- glm(full_mf_fm, data = MultipleFeatures, + replicate(50, { + fit_mdypl_new <- glm(full_mf_fm, data = MultipleFeatures, family = binomial(), method = mdypl_new, alpha = alpha_val, subset = training, maxit = 200) + }) }) - print(time_mdypl_new) + cat("Average time per run:", time_mdypl_new["elapsed"] / 50, "s\n") cat("\n") cat("MDYPL speedup:", @@ -234,11 +237,6 @@ tryCatch({ cat(" Max coefficient difference:", max(abs(coef(fit_mdypl_orig) - coef(fit_mdypl_new))), "\n") - # ====== SECTION 6: Summary Statistics ====== - cat("\n", separator, "\n") - cat("SECTION 6: OVERALL SUMMARY\n") - cat(separator, "\n\n") - speedups <- c( "Lizards (small)" = median(lizards_bench$time[lizards_bench$expr == "original"]) / median(lizards_bench$time[lizards_bench$expr == "new"]), @@ -248,14 +246,6 @@ tryCatch({ "MDYPL (large)" = time_mdypl_orig["elapsed"] / time_mdypl_new["elapsed"] ) - cat("Speedup Summary:\n") - for (i in seq_along(speedups)) { - cat(sprintf(" %-25s: %.2fx faster\n", names(speedups)[i], speedups[i])) - } - - cat("\nMean speedup:", round(mean(speedups), 2), "x\n") - cat("Median speedup:", round(median(speedups), 2), "x\n") - # Save benchmark objects for plotting save(lizards_bench, endo_bench, time_mf_orig, time_mf_new, @@ -274,7 +264,4 @@ tryCatch({ cat(traceback(), "\n") }, finally = { sink() -}) - -cat("\nResults saved to:", file.path(results_dir, "benchmark_results.txt"), "\n") -cat("Benchmark data saved to:", file.path(results_dir, "benchmark_data.RData"), "\n") \ No newline at end of file +}) \ No newline at end of file diff --git a/benchmarks/run_all.R b/benchmarks/run_all.R index cf16b7c..c2311d6 100644 --- a/benchmarks/run_all.R +++ b/benchmarks/run_all.R @@ -52,12 +52,14 @@ cat("======================================================================\n\n" cat("Total runtime:", format(difftime(end_time, start_time)), "\n") cat("Results directory:", file.path("benchmarks", "results"), "\n\n") -cat("Summary of improvements:\n") +cat("Summary of benchmarks:\n") results_dir <- file.path("benchmarks", "results") dirs <- list.dirs(results_dir, recursive = FALSE) latest_dir <- dirs[which.max(file.info(dirs)$mtime)] load(file.path(latest_dir, "benchmark_data.RData")) +speedups <- c("Test suite" = orig_results$elapsed / new_results$elapsed, speedups) + for (i in seq_along(speedups)) { cat(sprintf(" %-30s: %.2fx faster\n", names(speedups)[i], speedups[i])) } diff --git a/benchmarks/visualize_results.R b/benchmarks/visualize_results.R index c8ce165..fcff078 100644 --- a/benchmarks/visualize_results.R +++ b/benchmarks/visualize_results.R @@ -1,5 +1,5 @@ -# Benchmark visualization script -# Run this after the main benchmark script completes +# Fixed Benchmark Visualization Script +# This version properly handles the benchmark data structure library(ggplot2) library(microbenchmark) @@ -18,151 +18,192 @@ load(file.path(latest_dir, "benchmark_data.RData")) plots_dir <- file.path(latest_dir, "plots") dir.create(plots_dir, showWarnings = FALSE) +cat("\n=== Checking loaded data ===\n") +cat("lizards_bench dimensions:", nrow(lizards_bench), "rows\n") +cat("endo_bench dimensions:", nrow(endo_bench), "rows\n") +cat("Speedups vector:", names(speedups), "\n") +cat("Speedup values:", speedups, "\n\n") + # ====== Plot 1: Microbenchmark comparison (Lizards) ====== -png(file.path(plots_dir, "01_lizards_comparison.png"), - width = 800, height = 600, res = 100) -autoplot(lizards_bench) + - labs(title = "Lizards Dataset: Original vs New Implementation", - subtitle = "100 evaluations each", - y = "Time (seconds)") + - theme_minimal(base_size = 12) -dev.off() +cat("Creating Plot 1: Lizards comparison...\n") +tryCatch({ + png(file.path(plots_dir, "01_lizards_comparison.png"), + width = 800, height = 600, res = 100) + + # Manual boxplot approach (more reliable than autoplot) + lizards_df <- data.frame( + time_seconds = lizards_bench$time / 1e9, + version = lizards_bench$expr + ) + + p1 <- ggplot(lizards_df, aes(x = version, y = time_seconds, fill = version)) + + geom_boxplot() + + labs(title = "Lizards Dataset: Original vs New Implementation", + subtitle = "100 evaluations each", + x = "Version", + y = "Time (seconds)") + + scale_fill_manual(values = c("original" = "#E41A1C", "new" = "#4DAF4A")) + + theme_minimal(base_size = 12) + + theme(legend.position = "none") + + print(p1) + dev.off() + cat("Plot 1 saved\n") +}, error = function(e) { + cat("Error in Plot 1:", conditionMessage(e), "\n") + dev.off() +}) # ====== Plot 2: Microbenchmark comparison (Endometrial) ====== -png(file.path(plots_dir, "02_endometrial_comparison.png"), - width = 800, height = 600, res = 100) -autoplot(endo_bench) + - labs(title = "Endometrial Dataset: Original vs New Implementation", - subtitle = "50 evaluations each", - y = "Time (seconds)") + - theme_minimal(base_size = 12) -dev.off() +cat("Creating Plot 2: Endometrial comparison...\n") +tryCatch({ + png(file.path(plots_dir, "02_endometrial_comparison.png"), + width = 800, height = 600, res = 100) + + endo_df <- data.frame( + time_seconds = endo_bench$time / 1e9, + version = endo_bench$expr + ) + + p2 <- ggplot(endo_df, aes(x = version, y = time_seconds, fill = version)) + + geom_boxplot() + + labs(title = "Endometrial Dataset: Original vs New Implementation", + subtitle = "50 evaluations each", + x = "Version", + y = "Time (seconds)") + + scale_fill_manual(values = c("original" = "#E41A1C", "new" = "#4DAF4A")) + + theme_minimal(base_size = 12) + + theme(legend.position = "none") + + print(p2) + dev.off() + cat("Plot 2 saved\n") +}, error = function(e) { + cat("Error in Plot 2:", conditionMessage(e), "\n") + dev.off() +}) # ====== Plot 3: Speedup summary bar chart ====== -speedup_df <- data.frame( - Test = factor(names(speedups), levels = names(speedups)), - Speedup = as.numeric(speedups), - Category = c("Small", "Medium", "Large", "Large (MDYPL)") -) - -png(file.path(plots_dir, "03_speedup_summary.png"), - width = 800, height = 600, res = 100) -ggplot(speedup_df, aes(x = Test, y = Speedup, fill = Category)) + - geom_bar(stat = "identity") + - geom_text(aes(label = sprintf("%.2fx", Speedup)), - vjust = -0.5, size = 4) + - geom_hline(yintercept = 1, linetype = "dashed", color = "red") + - labs(title = "Performance Improvement: New vs Original Implementation", - subtitle = "Higher is better", - x = "Test Case", - y = "Speedup Factor") + - scale_fill_brewer(palette = "Set2") + - theme_minimal(base_size = 12) + - theme(axis.text.x = element_text(angle = 45, hjust = 1), - legend.position = "top") -dev.off() - -# ====== Plot 4: Absolute timing comparison ====== -timing_df <- data.frame( - Test = rep(c("Lizards", "Endometrial", "MultipleFeatures", "MDYPL"), each = 2), - Version = rep(c("Original", "New"), 4), - Time = c( - median(lizards_bench$time[lizards_bench$expr == "original"]) / 1e9, - median(lizards_bench$time[lizards_bench$expr == "new"]) / 1e9, - median(endo_bench$time[endo_bench$expr == "original"]) / 1e9, - median(endo_bench$time[endo_bench$expr == "new"]) / 1e9, - time_mf_orig["elapsed"], - time_mf_new["elapsed"], - time_mdypl_orig["elapsed"], - time_mdypl_new["elapsed"] +cat("Creating Plot 3: Speedup summary...\n") +tryCatch({ + # Clean up speedup names if they have .elapsed suffix + clean_names <- gsub("\\.elapsed$", "", names(speedups)) + + speedup_df <- data.frame( + Test = factor(clean_names, levels = clean_names), + Speedup = as.numeric(speedups), + Category = c("Small", "Medium", "Large", "Large (MDYPL)") ) -) + + png(file.path(plots_dir, "03_speedup_summary.png"), + width = 800, height = 600, res = 100) + + p3 <- ggplot(speedup_df, aes(x = Test, y = Speedup, fill = Category)) + + geom_bar(stat = "identity", width = 0.7) + + geom_text(aes(label = sprintf("%.2fx", Speedup)), + vjust = -0.5, size = 4) + + geom_hline(yintercept = 1, linetype = "dashed", color = "red", size = 0.8) + + labs(title = "Performance Improvement: New vs Original Implementation", + subtitle = "Higher is better (baseline = 1.0)", + x = "Test Case", + y = "Speedup Factor") + + scale_fill_brewer(palette = "Set2") + + ylim(0, max(speedup_df$Speedup) * 1.15) + + theme_minimal(base_size = 12) + + theme(axis.text.x = element_text(angle = 45, hjust = 1), + legend.position = "top") + + print(p3) + dev.off() + cat("Plot 3 saved\n") +}, error = function(e) { + cat("Error in Plot 3:", conditionMessage(e), "\n") + dev.off() +}) -png(file.path(plots_dir, "04_absolute_timing.png"), - width = 800, height = 600, res = 100) -ggplot(timing_df, aes(x = Test, y = Time, fill = Version)) + - geom_bar(stat = "identity", position = "dodge") + - geom_text(aes(label = sprintf("%.2fs", Time)), - position = position_dodge(width = 0.9), - vjust = -0.5, size = 3) + - labs(title = "Absolute Execution Time Comparison", - subtitle = "Lower is better", - x = "Test Case", - y = "Time (seconds)") + - scale_fill_manual(values = c("Original" = "#E41A1C", "New" = "#4DAF4A")) + - theme_minimal(base_size = 12) + - theme(axis.text.x = element_text(angle = 45, hjust = 1), - legend.position = "top") -dev.off() - -# ====== Plot 5: Distribution comparison (Lizards) ====== -lizards_df <- data.frame( - Time = lizards_bench$time / 1e9, # Convert to seconds - Version = lizards_bench$expr -) - -png(file.path(plots_dir, "05_lizards_distribution.png"), - width = 800, height = 600, res = 100) -ggplot(lizards_df, aes(x = Time, fill = Version)) + - geom_density(alpha = 0.6) + - geom_vline(data = aggregate(Time ~ Version, lizards_df, median), - aes(xintercept = Time, color = Version), - linetype = "dashed", size = 1) + - labs(title = "Execution Time Distribution: Lizards Dataset", - subtitle = "Dashed lines show median values", - x = "Time (seconds)", - y = "Density") + - scale_fill_manual(values = c("original" = "#E41A1C", "new" = "#4DAF4A")) + - scale_color_manual(values = c("original" = "#E41A1C", "new" = "#4DAF4A")) + - theme_minimal(base_size = 12) + - theme(legend.position = "top") -dev.off() - -# ====== Summary statistics table ====== -summary_stats <- rbind( - data.frame( - Dataset = "Lizards", - Version = c("Original", "New"), - Median = c( +# ====== Plot 4: Absolute timing comparison ====== +cat("Creating Plot 4: Absolute timing...\n") +tryCatch({ + timing_df <- data.frame( + Test = rep(c("Lizards", "Endometrial", "MultipleFeatures", "MDYPL"), each = 2), + Version = rep(c("Original", "New"), 4), + Time = c( median(lizards_bench$time[lizards_bench$expr == "original"]) / 1e9, - median(lizards_bench$time[lizards_bench$expr == "new"]) / 1e9 - ), - Mean = c( - mean(lizards_bench$time[lizards_bench$expr == "original"]) / 1e9, - mean(lizards_bench$time[lizards_bench$expr == "new"]) / 1e9 - ), - SD = c( - sd(lizards_bench$time[lizards_bench$expr == "original"]) / 1e9, - sd(lizards_bench$time[lizards_bench$expr == "new"]) / 1e9 - ) - ), - data.frame( - Dataset = "Endometrial", - Version = c("Original", "New"), - Median = c( + median(lizards_bench$time[lizards_bench$expr == "new"]) / 1e9, median(endo_bench$time[endo_bench$expr == "original"]) / 1e9, - median(endo_bench$time[endo_bench$expr == "new"]) / 1e9 - ), - Mean = c( - mean(endo_bench$time[endo_bench$expr == "original"]) / 1e9, - mean(endo_bench$time[endo_bench$expr == "new"]) / 1e9 - ), - SD = c( - sd(endo_bench$time[endo_bench$expr == "original"]) / 1e9, - sd(endo_bench$time[endo_bench$expr == "new"]) / 1e9 + median(endo_bench$time[endo_bench$expr == "new"]) / 1e9, + as.numeric(time_mf_orig["elapsed"]), + as.numeric(time_mf_new["elapsed"]), + as.numeric(time_mdypl_orig["elapsed"]), + as.numeric(time_mdypl_new["elapsed"]) ) ) -) + + png(file.path(plots_dir, "04_absolute_timing.png"), + width = 800, height = 600, res = 100) + + p4 <- ggplot(timing_df, aes(x = Test, y = Time, fill = Version)) + + geom_bar(stat = "identity", position = "dodge", width = 0.7) + + geom_text(aes(label = sprintf("%.3fs", Time)), + position = position_dodge(width = 0.7), + vjust = -0.5, size = 3) + + labs(title = "Absolute Execution Time Comparison", + subtitle = "Lower is better", + x = "Test Case", + y = "Time (seconds)") + + scale_fill_manual(values = c("Original" = "#E41A1C", "New" = "#4DAF4A")) + + theme_minimal(base_size = 12) + + theme(axis.text.x = element_text(angle = 45, hjust = 1), + legend.position = "top") + + print(p4) + dev.off() + cat("Plot 4 saved\n") +}, error = function(e) { + cat("Error in Plot 4:", conditionMessage(e), "\n") + dev.off() +}) -write.csv(summary_stats, - file.path(plots_dir, "summary_statistics.csv"), - row.names = FALSE) - -cat("\nAll plots saved to:", plots_dir, "\n") -cat("\nGenerated plots:\n") -cat(" 1. Lizards microbenchmark comparison\n") -cat(" 2. Endometrial microbenchmark comparison\n") -cat(" 3. Overall speedup summary\n") -cat(" 4. Absolute timing comparison\n") -cat(" 5. Lizards timing distribution\n") -cat(" 6. Summary statistics (CSV)\n") \ No newline at end of file +# ====== Plot 5: Distribution comparison (Lizards) ====== +cat("Creating Plot 5: Lizards distribution...\n") +tryCatch({ + lizards_df <- data.frame( + Time = lizards_bench$time / 1e9, + Version = lizards_bench$expr + ) + + medians <- aggregate(Time ~ Version, lizards_df, median) + + png(file.path(plots_dir, "05_lizards_distribution.png"), + width = 800, height = 600, res = 100) + + p5 <- ggplot(lizards_df, aes(x = Time, fill = Version)) + + geom_density(alpha = 0.6) + + geom_vline(data = medians, + aes(xintercept = Time, color = Version), + linetype = "dashed", size = 1) + + labs(title = "Execution Time Distribution: Lizards Dataset", + subtitle = "Dashed lines show median values", + x = "Time (seconds)", + y = "Density") + + scale_fill_manual(values = c("original" = "#E41A1C", "new" = "#4DAF4A")) + + scale_color_manual(values = c("original" = "#E41A1C", "new" = "#4DAF4A")) + + theme_minimal(base_size = 12) + + theme(legend.position = "top") + + print(p5) + dev.off() + cat("Plot 5 saved\n") +}, error = function(e) { + cat("Error in Plot 5:", conditionMessage(e), "\n") + dev.off() +}) + +cat("\n=== Visualization Complete ===\n") +cat("All plots saved to:", plots_dir, "\n\n") +cat("Generated files:\n") +cat(" 01_lizards_comparison.png - Boxplot comparison\n") +cat(" 02_endometrial_comparison.png - Boxplot comparison\n") +cat(" 03_speedup_summary.png - Speedup bar chart\n") +cat(" 04_absolute_timing.png - Absolute time comparison\n") +cat(" 05_lizards_distribution.png - Distribution densities\n") \ No newline at end of file From ba3f10ae53d474b31426623deb9f5a9cd5a17b52 Mon Sep 17 00:00:00 2001 From: Ollie Date: Fri, 14 Nov 2025 11:16:27 +0000 Subject: [PATCH 11/15] Deletion of wrongly added result files before .gitignore updated --- .../20251110_142635/benchmark_data.RData | Bin 2082 -> 0 bytes .../20251110_142635/benchmark_results.txt | 165 ------------------ .../plots/01_lizards_comparison.png | Bin 581 -> 0 bytes .../plots/02_endometrial_comparison.png | Bin 581 -> 0 bytes .../plots/03_speedup_summary.png | Bin 581 -> 0 bytes .../plots/04_absolute_timing.png | Bin 581 -> 0 bytes .../plots/05_lizards_distribution.png | Bin 581 -> 0 bytes .../plots/summary_statistics.csv | 5 - .../results/20251110_142635/test_results.txt | 3 - .../20251110_144218/benchmark_data.RData | Bin 2111 -> 0 bytes .../20251110_144218/benchmark_results.txt | 165 ------------------ .../plots/01_lizards_comparison.png | Bin 581 -> 0 bytes .../plots/02_endometrial_comparison.png | Bin 581 -> 0 bytes .../plots/03_speedup_summary.png | Bin 581 -> 0 bytes .../plots/04_absolute_timing.png | Bin 581 -> 0 bytes .../plots/05_lizards_distribution.png | Bin 581 -> 0 bytes .../plots/summary_statistics.csv | 5 - .../results/20251110_144218/test_results.txt | 3 - .../20251110_144957/benchmark_data.RData | Bin 2129 -> 0 bytes .../20251110_144957/benchmark_results.txt | 164 ----------------- .../plots/01_lizards_comparison.png | Bin 581 -> 0 bytes .../plots/02_endometrial_comparison.png | Bin 581 -> 0 bytes .../plots/03_speedup_summary.png | Bin 581 -> 0 bytes .../plots/04_absolute_timing.png | Bin 581 -> 0 bytes .../plots/05_lizards_distribution.png | Bin 581 -> 0 bytes .../plots/summary_statistics.csv | 5 - 26 files changed, 515 deletions(-) delete mode 100644 benchmarks/results/20251110_142635/benchmark_data.RData delete mode 100644 benchmarks/results/20251110_142635/benchmark_results.txt delete mode 100644 benchmarks/results/20251110_142635/plots/01_lizards_comparison.png delete mode 100644 benchmarks/results/20251110_142635/plots/02_endometrial_comparison.png delete mode 100644 benchmarks/results/20251110_142635/plots/03_speedup_summary.png delete mode 100644 benchmarks/results/20251110_142635/plots/04_absolute_timing.png delete mode 100644 benchmarks/results/20251110_142635/plots/05_lizards_distribution.png delete mode 100644 benchmarks/results/20251110_142635/plots/summary_statistics.csv delete mode 100644 benchmarks/results/20251110_142635/test_results.txt delete mode 100644 benchmarks/results/20251110_144218/benchmark_data.RData delete mode 100644 benchmarks/results/20251110_144218/benchmark_results.txt delete mode 100644 benchmarks/results/20251110_144218/plots/01_lizards_comparison.png delete mode 100644 benchmarks/results/20251110_144218/plots/02_endometrial_comparison.png delete mode 100644 benchmarks/results/20251110_144218/plots/03_speedup_summary.png delete mode 100644 benchmarks/results/20251110_144218/plots/04_absolute_timing.png delete mode 100644 benchmarks/results/20251110_144218/plots/05_lizards_distribution.png delete mode 100644 benchmarks/results/20251110_144218/plots/summary_statistics.csv delete mode 100644 benchmarks/results/20251110_144218/test_results.txt delete mode 100644 benchmarks/results/20251110_144957/benchmark_data.RData delete mode 100644 benchmarks/results/20251110_144957/benchmark_results.txt delete mode 100644 benchmarks/results/20251110_144957/plots/01_lizards_comparison.png delete mode 100644 benchmarks/results/20251110_144957/plots/02_endometrial_comparison.png delete mode 100644 benchmarks/results/20251110_144957/plots/03_speedup_summary.png delete mode 100644 benchmarks/results/20251110_144957/plots/04_absolute_timing.png delete mode 100644 benchmarks/results/20251110_144957/plots/05_lizards_distribution.png delete mode 100644 benchmarks/results/20251110_144957/plots/summary_statistics.csv diff --git a/benchmarks/results/20251110_142635/benchmark_data.RData b/benchmarks/results/20251110_142635/benchmark_data.RData deleted file mode 100644 index 3a83479d688a96d2aafdc6e15a3e237a1045f4dc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2082 zcmV+-2;KJ|iwFP!000002Gv-7P!#7GU*JGMgC^*hp^~CW4N@e;j}oQHff^wiiGWlT zQ1u(o@{2; zs5m9xQ>X72<@+5?=M(a__#V=&M~=s7Sn^;5P#V- z%JyLNFR!@*yXUQX#Fa$~;NxEWIb<MDczYX7`dFjuEqi$jr=Ip$X3qR-fiO6FyAE9+$ zO8lj`NysZ-YsS3X@kPXY*fPk{xOS|E_`CJA?jOb=Pr=zn@U^@f0+~OR3M}+az&cwi z43O=&H=^E>AAN&-wwRlch1e57Zt^_%Ewxz?$2A-SuYy@|kl7USFMK+S>{WWo6WxKh z;=D(}!~P}hXQ4h5=(tMz-g2y4-fpBhKHp69n%|6k{G~5x9>YA)JI{`WU)6a6aW>C@>{=Z~{bYOsEPXB%eB4c2AzLOL zgrD+#hU81D5U)IT87NJmb0+`NiaPS-aLSuK9(J|jUF35;I*arN*J3_Wd>i~7IU{L( zj_xLX%x#)iW79!2}cV~)m7FlmXej zufyMvv<-H1stz(c;~eaUHQRv&zo`Uo>wcO)mrMDU&6^5;{^t)t&rjG%^MAOG_{CSl zZvHd^G8dTvWS=U4pIN_}_#Cb!dulE5-~0vo5{Bm!ukf!S%SEl2gCX&!#N*@ys>_%t zkNHXDvA@J4PjS~-@HXVE1zK9S0qxvM*d06RoSNJAAV1smYb{UUXUDnRo?IXy}Kg4*peSermsSJx8( zjyl!BD@@;SVUQNo8Q>VnIZV!eFRmu0|4ZCZ7tg!BTn%-J8R{bUU3d(10UPRa``=u6 z@8*IxSZ{;m)>bY!a1RZ9HR{=J1K);B>1s*%LPk41(_?|9hcbXl*WniE9qS+q!S`2b z=*W_`Xjt-1eVm5kO^YG)>T>{$PptlEqAPZQsX)OGlixR+FT*RR-d43l7 zDe4&Hm-1KBTpO2B-hXX?tX`Q5tgd|^9`c<^@Gsr40(snzB*QK-uOpwU^G)z{Po7V5 z!CsorjCWASwdEb^KjBr0$Qif8L-{+(qs*NS5B<6ofLle1Bz`Q2*Ay1FY)w;@g(O@1EQeA>Of|2K_keCFEICass!Q(&R(n<8H~s{3E?y_)smb z_xpS!>B9m~aKG>H5gLKzcJp%WP2eM;9qiDwX{Fhp)jZUozvwNDzu8=uHvQO>;XlztPGI zeocfHK#FhoG~C}4-e%n`O_ zYm9y~+F|s^ee31TXYP@8@t7OeH7)3;xq zmDjW{Pyg9#t*N(v9HMVORpZ=qHAVlAxtlLno7@33b^b+vmi{*w7cbjcL73F79{sfM z+GXbyiD!klcspm}RlDC7w?GvXUKF^w9IL1j=Zh6s$-+%a>f6zn1#^}xeD+&L`nY%g M8(<+Bw80br0BP7l3;+NC diff --git a/benchmarks/results/20251110_142635/benchmark_results.txt b/benchmarks/results/20251110_142635/benchmark_results.txt deleted file mode 100644 index b1f5744..0000000 --- a/benchmarks/results/20251110_142635/benchmark_results.txt +++ /dev/null @@ -1,165 +0,0 @@ -====================================================================== -BRGLM2 COMPREHENSIVE BENCHMARKING RESULTS -Timestamp: 20251110_142635 -====================================================================== - - - ====================================================================== -SECTION 1: TEST SUITE EXECUTION -====================================================================== - -Running test suite for NEW version... -Library path: C:/Users/ollie/OneDrive/Desktop/UNI/Project brglm2/benchmark_libs/new - - test-binomial.R............... 0 tests test-binomial.R............... 0 tests test-binomial.R............... 0 tests test-binomial.R............... 0 tests test-binomial.R............... 4 tests OK 0.9s - test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 1 tests OK test-bracl.R.................. 2 tests OK test-bracl.R.................. 3 tests OK test-bracl.R.................. 4 tests OK test-bracl.R.................. 5 tests OK test-bracl.R.................. 6 tests OK test-bracl.R.................. 7 tests OK test-bracl.R.................. 7 tests OK test-bracl.R.................. 27 tests OK test-bracl.R.................. 27 tests OK test-bracl.R.................. 28 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 30 tests OK test-bracl.R.................. 31 tests OK test-bracl.R.................. 31 tests OK test-bracl.R.................. 31 tests OK test-bracl.R.................. 31 tests OK test-bracl.R.................. 32 tests OK test-bracl.R.................. 33 tests OK test-bracl.R.................. 34 tests OK test-bracl.R.................. 34 tests OK test-bracl.R.................. 34 tests OK test-bracl.R.................. 35 tests OK test-bracl.R.................. 36 tests OK test-bracl.R.................. 36 tests OK test-bracl.R.................. 36 tests OK test-bracl.R.................. 36 tests OK test-bracl.R.................. 37 tests OK test-bracl.R.................. 38 tests OK test-bracl.R.................. 39 tests OK test-bracl.R.................. 40 tests OK test-bracl.R.................. 41 tests OK test-bracl.R.................. 42 tests OK test-bracl.R.................. 42 tests OK test-bracl.R.................. 42 tests OK test-bracl.R.................. 42 tests OK test-bracl.R.................. 43 tests OK test-bracl.R.................. 44 tests OK test-bracl.R.................. 45 tests OK test-bracl.R.................. 46 tests OK test-bracl.R.................. 47 tests OK test-bracl.R.................. 48 tests OK 3.9s - test-brglmControl.R........... 0 tests test-brglmControl.R........... 1 tests OK test-brglmControl.R........... 2 tests OK test-brglmControl.R........... 3 tests OK test-brglmControl.R........... 4 tests OK test-brglmControl.R........... 5 tests OK test-brglmControl.R........... 6 tests OK test-brglmControl.R........... 7 tests OK test-brglmControl.R........... 8 tests OK test-brglmControl.R........... 9 tests OK test-brglmControl.R........... 9 tests OK test-brglmControl.R........... 10 tests OK test-brglmControl.R........... 11 tests OK test-brglmControl.R........... 12 tests OK test-brglmControl.R........... 13 tests OK test-brglmControl.R........... 14 tests OK test-brglmControl.R........... 15 tests OK test-brglmControl.R........... 16 tests OK test-brglmControl.R........... 17 tests OK test-brglmControl.R........... 18 tests OK test-brglmControl.R........... 18 tests OK test-brglmControl.R........... 18 tests OK test-brglmControl.R........... 19 tests OK test-brglmControl.R........... 20 tests OK test-brglmControl.R........... 21 tests OK test-brglmControl.R........... 21 tests OK test-brglmControl.R........... 22 tests OK test-brglmControl.R........... 23 tests OK test-brglmControl.R........... 24 tests OK test-brglmControl.R........... 25 tests OK test-brglmControl.R........... 26 tests OK test-brglmControl.R........... 27 tests OK test-brglmControl.R........... 28 tests OK test-brglmControl.R........... 29 tests OK test-brglmControl.R........... 30 tests OK test-brglmControl.R........... 30 tests OK test-brglmControl.R........... 30 tests OK test-brglmControl.R........... 31 tests OK test-brglmControl.R........... 31 tests OK test-brglmControl.R........... 32 tests OK test-brglmControl.R........... 32 tests OK test-brglmControl.R........... 33 tests OK 1.1s - test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 1 tests OK test-brnp.R................... 2 tests OK test-brnp.R................... 3 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 5 tests OK test-brnp.R................... 6 tests OK test-brnp.R................... 7 tests OK test-brnp.R................... 8 tests OK test-brnp.R................... 9 tests OK test-brnp.R................... 15 tests OK test-brnp.R................... 15 tests OK test-brnp.R................... 15 tests OK test-brnp.R................... 15 tests OK test-brnp.R................... 16 tests OK test-brnp.R................... 17 tests OK test-brnp.R................... 18 tests OK 3.9s - test-checkinfinite.R.......... 0 tests test-checkinfinite.R.......... 1 tests OK test-checkinfinite.R.......... 2 tests OK 56ms - test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 1 tests OK 0.3s - test-dispersion.R............. 0 tests test-dispersion.R............. 0 tests test-dispersion.R............. 0 tests test-dispersion.R............. 0 tests test-dispersion.R............. 1 tests OK test-dispersion.R............. 2 tests OK 0.1s - test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 6 tests OK test-expo.R................... 7 tests OK test-expo.R................... 8 tests OK test-expo.R................... 9 tests OK test-expo.R................... 9 tests OK test-expo.R................... 9 tests OK test-expo.R................... 9 tests OK test-expo.R................... 21 tests OK test-expo.R................... 21 tests OK test-expo.R................... 21 tests OK test-expo.R................... 33 tests OK test-expo.R................... 33 tests OK test-expo.R................... 33 tests OK test-expo.R................... 45 tests OK test-expo.R................... 45 tests OK test-expo.R................... 45 tests OK test-expo.R................... 45 tests OK test-expo.R................... 57 tests OK test-expo.R................... 57 tests OK test-expo.R................... 57 tests OK test-expo.R................... 62 tests OK test-expo.R................... 63 tests OK 1.8s - test-gamma.R.................. 0 tests test-gamma.R.................. 0 tests test-gamma.R.................. 0 tests test-gamma.R.................. 0 tests test-gamma.R.................. 1 tests OK test-gamma.R.................. 2 tests OK 0.2s - test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 1 tests OK test-jeffreys.R............... 2 tests OK test-jeffreys.R............... 2 tests OK test-jeffreys.R............... 3 tests OK test-jeffreys.R............... 3 tests OK test-jeffreys.R............... 3 tests OK test-jeffreys.R............... 3 tests OK test-jeffreys.R............... 11 tests OK 0.7s - test-mdyplFit.R............... 0 tests test-mdyplFit.R............... 0 tests test-mdyplFit.R............... 0 tests test-mdyplFit.R............... 0 tests test-mdyplFit.R............... 1 tests OK test-mdyplFit.R............... 2 tests OK test-mdyplFit.R............... 2 tests OK test-mdyplFit.R............... 2 tests OK test-mdyplFit.R............... 3 tests OK test-mdyplFit.R............... 4 tests OK test-mdyplFit.R............... 5 tests OK test-mdyplFit.R............... 5 tests OK test-mdyplFit.R............... 5 tests OK test-mdyplFit.R............... 5 tests OK test-mdyplFit.R............... 6 tests OK test-mdyplFit.R............... 6 tests OK test-mdyplFit.R............... 6 tests OK test-mdyplFit.R............... 6 tests OK test-mdyplFit.R............... 7 tests OK test-mdyplFit.R............... 7 tests OK test-mdyplFit.R............... 7 tests OK test-mdyplFit.R............... 7 tests OK test-mdyplFit.R............... 41 tests OK test-mdyplFit.R............... 41 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 43 tests OK test-mdyplFit.R............... 44 tests OK test-mdyplFit.R............... 45 tests OK test-mdyplFit.R............... 46 tests OK test-mdyplFit.R............... 47 tests OK test-mdyplFit.R............... 48 tests OK test-mdyplFit.R............... 49 tests OK test-mdyplFit.R............... 50 tests OK test-mdyplFit.R............... 51 tests OK test-mdyplFit.R............... 52 tests OK test-mdyplFit.R............... 53 tests OK test-mdyplFit.R............... 54 tests OK test-mdyplFit.R............... 55 tests OK test-mdyplFit.R............... 56 tests OK test-mdyplFit.R............... 57 tests OK test-mdyplFit.R............... 58 tests OK test-mdyplFit.R............... 59 tests OK test-mdyplFit.R............... 60 tests OK test-mdyplFit.R............... 61 tests OK test-mdyplFit.R............... 62 tests OK 0.5s - test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 8 tests OK 1.0s - test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 1 tests OK 0.2s - test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 1 tests OK 0.3s - test-mis.R.................... 0 tests test-mis.R.................... 0 tests test-mis.R.................... 1 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 3 tests OK test-mis.R.................... 4 tests OK 0.1s - test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 1 tests OK 38.4s - test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 1 tests OK test-multinom.R............... 1 tests OK test-multinom.R............... 2 tests OK test-multinom.R............... 2 tests OK test-multinom.R............... 2 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 4 tests OK test-multinom.R............... 4 tests OK test-multinom.R............... 4 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 6 tests OK test-multinom.R............... 7 tests OK test-multinom.R............... 8 tests OK test-multinom.R............... 9 tests OK test-multinom.R............... 10 tests OK test-multinom.R............... 11 tests OK test-multinom.R............... 12 tests OK test-multinom.R............... 13 tests OK test-multinom.R............... 13 tests OK test-multinom.R............... 13 tests OK test-multinom.R............... 13 tests OK test-multinom.R............... 14 tests OK test-multinom.R............... 15 tests OK test-multinom.R............... 15 tests OK test-multinom.R............... 15 tests OK test-multinom.R............... 16 tests OK test-multinom.R............... 17 tests OK test-multinom.R............... 18 tests OK test-multinom.R............... 19 tests OK test-multinom.R............... 20 tests OK test-multinom.R............... 21 tests OK test-multinom.R............... 22 tests OK test-multinom.R............... 22 tests OK test-multinom.R............... 22 tests OK test-multinom.R............... 22 tests OK test-multinom.R............... 23 tests OK test-multinom.R............... 24 tests OK test-multinom.R............... 25 tests OK test-multinom.R............... 26 tests OK test-multinom.R............... 27 tests OK test-multinom.R............... 28 tests OK 2.2s - test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 1 tests OK test-poisson.R................ 1 tests OK test-poisson.R................ 1 tests OK test-poisson.R................ 1 tests OK test-poisson.R................ 2 tests OK 0.3s - test-print.R.................. 0 tests test-print.R.................. 0 tests test-print.R.................. 48 tests OK test-print.R.................. 48 tests OK test-print.R.................. 48 tests OK test-print.R.................. 48 tests OK test-print.R.................. 48 tests OK test-print.R.................. 49 tests OK test-print.R.................. 50 tests OK test-print.R.................. 51 tests OK test-print.R.................. 51 tests OK test-print.R.................. 51 tests OK test-print.R.................. 51 tests OK test-print.R.................. 52 tests OK test-print.R.................. 53 tests OK test-print.R.................. 54 tests OK test-print.R.................. 54 tests OK test-print.R.................. 54 tests OK test-print.R.................. 54 tests OK test-print.R.................. 55 tests OK test-print.R.................. 56 tests OK test-print.R.................. 57 tests OK 0.8s - test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 1 tests OK test-se.R..................... 1 tests OK test-se.R..................... 2 tests OK test-se.R..................... 2 tests OK test-se.R..................... 6 tests OK test-se.R..................... 6 tests OK test-se.R..................... 6 tests OK test-se.R..................... 7 tests OK test-se.R..................... 7 tests OK test-se.R..................... 8 tests OK test-se.R..................... 8 tests OK test-se.R..................... 9 tests OK test-se.R..................... 10 tests OK test-se.R..................... 10 tests OK test-se.R..................... 14 tests OK test-se.R..................... 14 tests OK test-se.R..................... 14 tests OK test-se.R..................... 15 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 17 tests OK test-se.R..................... 18 tests OK 41.1s - test-singular.R............... 0 tests test-singular.R............... 0 tests test-singular.R............... 0 tests test-singular.R............... 0 tests test-singular.R............... 1 tests OK test-singular.R............... 2 tests OK 0.2s - test-start.R.................. 0 tests test-start.R.................. 0 tests test-start.R.................. 0 tests test-start.R.................. 0 tests test-start.R.................. 0 tests test-start.R.................. 1 tests OK test-start.R.................. 2 tests OK 0.3s - test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 17 tests OK test-summary_mdyplFit.R....... 17 tests OK test-summary_mdyplFit.R....... 17 tests OK test-summary_mdyplFit.R....... 17 tests OK test-summary_mdyplFit.R....... 18 tests OK test-summary_mdyplFit.R....... 18 tests OK test-summary_mdyplFit.R....... 18 tests OK test-summary_mdyplFit.R....... 19 tests OK test-summary_mdyplFit.R....... 20 tests OK test-summary_mdyplFit.R....... 20 tests OK test-summary_mdyplFit.R....... 20 tests OK test-summary_mdyplFit.R....... 21 tests OK 14.0s - test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 1 tests OK test-transformation.R......... 2 tests OK test-transformation.R......... 3 tests OK 0.6s -All ok, NA results (113.3s) - -Running test suite for ORIGINAL version... -Library path: C:/Users/ollie/OneDrive/Desktop/UNI/Project brglm2/benchmark_libs/original - - test-binomial.R............... 0 tests test-binomial.R............... 0 tests test-binomial.R............... 0 tests test-binomial.R............... 0 tests test-binomial.R............... 4 tests OK 0.8s - test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 0 tests test-bracl.R.................. 1 tests OK test-bracl.R.................. 2 tests OK test-bracl.R.................. 3 tests OK test-bracl.R.................. 4 tests OK test-bracl.R.................. 5 tests OK test-bracl.R.................. 6 tests OK test-bracl.R.................. 7 tests OK test-bracl.R.................. 7 tests OK test-bracl.R.................. 27 tests OK test-bracl.R.................. 27 tests OK test-bracl.R.................. 28 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 29 tests OK test-bracl.R.................. 30 tests OK test-bracl.R.................. 31 tests OK test-bracl.R.................. 31 tests OK test-bracl.R.................. 31 tests OK test-bracl.R.................. 31 tests OK test-bracl.R.................. 32 tests OK test-bracl.R.................. 33 tests OK test-bracl.R.................. 34 tests OK test-bracl.R.................. 34 tests OK test-bracl.R.................. 34 tests OK test-bracl.R.................. 35 tests OK test-bracl.R.................. 36 tests OK test-bracl.R.................. 36 tests OK test-bracl.R.................. 36 tests OK test-bracl.R.................. 36 tests OK test-bracl.R.................. 37 tests OK test-bracl.R.................. 38 tests OK test-bracl.R.................. 39 tests OK test-bracl.R.................. 40 tests OK test-bracl.R.................. 41 tests OK test-bracl.R.................. 42 tests OK test-bracl.R.................. 42 tests OK test-bracl.R.................. 42 tests OK test-bracl.R.................. 42 tests OK test-bracl.R.................. 43 tests OK test-bracl.R.................. 44 tests OK test-bracl.R.................. 45 tests OK test-bracl.R.................. 46 tests OK test-bracl.R.................. 47 tests OK test-bracl.R.................. 48 tests OK 2.4s - test-brglmControl.R........... 0 tests test-brglmControl.R........... 1 tests OK test-brglmControl.R........... 2 tests OK test-brglmControl.R........... 3 tests OK test-brglmControl.R........... 4 tests OK test-brglmControl.R........... 5 tests OK test-brglmControl.R........... 6 tests OK test-brglmControl.R........... 7 tests OK test-brglmControl.R........... 8 tests OK test-brglmControl.R........... 9 tests OK test-brglmControl.R........... 9 tests OK test-brglmControl.R........... 10 tests OK test-brglmControl.R........... 11 tests OK test-brglmControl.R........... 12 tests OK test-brglmControl.R........... 13 tests OK test-brglmControl.R........... 14 tests OK test-brglmControl.R........... 15 tests OK test-brglmControl.R........... 16 tests OK test-brglmControl.R........... 17 tests OK test-brglmControl.R........... 18 tests OK test-brglmControl.R........... 18 tests OK test-brglmControl.R........... 18 tests OK test-brglmControl.R........... 19 tests OK test-brglmControl.R........... 20 tests OK test-brglmControl.R........... 21 tests OK test-brglmControl.R........... 21 tests OK test-brglmControl.R........... 22 tests OK test-brglmControl.R........... 23 tests OK test-brglmControl.R........... 24 tests OK test-brglmControl.R........... 25 tests OK test-brglmControl.R........... 26 tests OK test-brglmControl.R........... 27 tests OK test-brglmControl.R........... 28 tests OK test-brglmControl.R........... 29 tests OK test-brglmControl.R........... 30 tests OK test-brglmControl.R........... 30 tests OK test-brglmControl.R........... 30 tests OK test-brglmControl.R........... 31 tests OK test-brglmControl.R........... 31 tests OK test-brglmControl.R........... 32 tests OK test-brglmControl.R........... 32 tests OK test-brglmControl.R........... 33 tests OK 0.7s - test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 0 tests test-brnp.R................... 1 tests OK test-brnp.R................... 2 tests OK test-brnp.R................... 3 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 4 tests OK test-brnp.R................... 5 tests OK test-brnp.R................... 6 tests OK test-brnp.R................... 7 tests OK test-brnp.R................... 8 tests OK test-brnp.R................... 9 tests OK test-brnp.R................... 15 tests OK test-brnp.R................... 15 tests OK test-brnp.R................... 15 tests OK test-brnp.R................... 15 tests OK test-brnp.R................... 16 tests OK test-brnp.R................... 17 tests OK test-brnp.R................... 18 tests OK 3.3s - test-checkinfinite.R.......... 0 tests test-checkinfinite.R.......... 1 tests OK test-checkinfinite.R.......... 2 tests OK 83ms - test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 0 tests test-correction.R............. 1 tests OK 0.3s - test-dispersion.R............. 0 tests test-dispersion.R............. 0 tests test-dispersion.R............. 0 tests test-dispersion.R............. 0 tests test-dispersion.R............. 1 tests OK test-dispersion.R............. 2 tests OK 0.2s - test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 0 tests test-expo.R................... 6 tests OK test-expo.R................... 7 tests OK test-expo.R................... 8 tests OK test-expo.R................... 9 tests OK test-expo.R................... 9 tests OK test-expo.R................... 9 tests OK test-expo.R................... 9 tests OK test-expo.R................... 21 tests OK test-expo.R................... 21 tests OK test-expo.R................... 21 tests OK test-expo.R................... 33 tests OK test-expo.R................... 33 tests OK test-expo.R................... 33 tests OK test-expo.R................... 45 tests OK test-expo.R................... 45 tests OK test-expo.R................... 45 tests OK test-expo.R................... 45 tests OK test-expo.R................... 57 tests OK test-expo.R................... 57 tests OK test-expo.R................... 57 tests OK test-expo.R................... 62 tests OK test-expo.R................... 63 tests OK 1.7s - test-gamma.R.................. 0 tests test-gamma.R.................. 0 tests test-gamma.R.................. 0 tests test-gamma.R.................. 0 tests test-gamma.R.................. 1 tests OK test-gamma.R.................. 2 tests OK 0.2s - test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 0 tests test-jeffreys.R............... 1 tests OK test-jeffreys.R............... 2 tests OK test-jeffreys.R............... 2 tests OK test-jeffreys.R............... 3 tests OK test-jeffreys.R............... 3 tests OK test-jeffreys.R............... 3 tests OK test-jeffreys.R............... 3 tests OK test-jeffreys.R............... 11 tests OK 0.6s - test-mdyplFit.R............... 0 tests test-mdyplFit.R............... 0 tests test-mdyplFit.R............... 0 tests test-mdyplFit.R............... 0 tests test-mdyplFit.R............... 1 tests OK test-mdyplFit.R............... 2 tests OK test-mdyplFit.R............... 2 tests OK test-mdyplFit.R............... 2 tests OK test-mdyplFit.R............... 3 tests OK test-mdyplFit.R............... 4 tests OK test-mdyplFit.R............... 5 tests OK test-mdyplFit.R............... 5 tests OK test-mdyplFit.R............... 5 tests OK test-mdyplFit.R............... 5 tests OK test-mdyplFit.R............... 6 tests OK test-mdyplFit.R............... 6 tests OK test-mdyplFit.R............... 6 tests OK test-mdyplFit.R............... 6 tests OK test-mdyplFit.R............... 7 tests OK test-mdyplFit.R............... 7 tests OK test-mdyplFit.R............... 7 tests OK test-mdyplFit.R............... 7 tests OK test-mdyplFit.R............... 41 tests OK test-mdyplFit.R............... 41 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 42 tests OK test-mdyplFit.R............... 43 tests OK test-mdyplFit.R............... 44 tests OK test-mdyplFit.R............... 45 tests OK test-mdyplFit.R............... 46 tests OK test-mdyplFit.R............... 47 tests OK test-mdyplFit.R............... 48 tests OK test-mdyplFit.R............... 49 tests OK test-mdyplFit.R............... 50 tests OK test-mdyplFit.R............... 51 tests OK test-mdyplFit.R............... 52 tests OK test-mdyplFit.R............... 53 tests OK test-mdyplFit.R............... 54 tests OK test-mdyplFit.R............... 55 tests OK test-mdyplFit.R............... 56 tests OK test-mdyplFit.R............... 57 tests OK test-mdyplFit.R............... 58 tests OK test-mdyplFit.R............... 59 tests OK test-mdyplFit.R............... 60 tests OK test-mdyplFit.R............... 61 tests OK test-mdyplFit.R............... 62 tests OK 0.5s - test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 0 tests test-median-binomial.R........ 8 tests OK 0.7s - test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 0 tests test-median-dispersion.R...... 1 tests OK 0.2s - test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 0 tests test-median-poisson.R......... 1 tests OK 0.4s - test-mis.R.................... 0 tests test-mis.R.................... 0 tests test-mis.R.................... 1 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 2 tests OK test-mis.R.................... 3 tests OK test-mis.R.................... 4 tests OK 0.2s - test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 0 tests test-multinom-binom.R......... 1 tests OK 32.9s - test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 0 tests test-multinom.R............... 1 tests OK test-multinom.R............... 1 tests OK test-multinom.R............... 2 tests OK test-multinom.R............... 2 tests OK test-multinom.R............... 2 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 3 tests OK test-multinom.R............... 4 tests OK test-multinom.R............... 4 tests OK test-multinom.R............... 4 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 5 tests OK test-multinom.R............... 6 tests OK test-multinom.R............... 7 tests OK test-multinom.R............... 8 tests OK test-multinom.R............... 9 tests OK test-multinom.R............... 10 tests OK test-multinom.R............... 11 tests OK test-multinom.R............... 12 tests OK test-multinom.R............... 13 tests OK test-multinom.R............... 13 tests OK test-multinom.R............... 13 tests OK test-multinom.R............... 13 tests OK test-multinom.R............... 14 tests OK test-multinom.R............... 15 tests OK test-multinom.R............... 15 tests OK test-multinom.R............... 15 tests OK test-multinom.R............... 16 tests OK test-multinom.R............... 17 tests OK test-multinom.R............... 18 tests OK test-multinom.R............... 19 tests OK test-multinom.R............... 20 tests OK test-multinom.R............... 21 tests OK test-multinom.R............... 22 tests OK test-multinom.R............... 22 tests OK test-multinom.R............... 22 tests OK test-multinom.R............... 22 tests OK test-multinom.R............... 23 tests OK test-multinom.R............... 24 tests OK test-multinom.R............... 25 tests OK test-multinom.R............... 26 tests OK test-multinom.R............... 27 tests OK test-multinom.R............... 28 tests OK 2.3s - test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 0 tests test-poisson.R................ 1 tests OK test-poisson.R................ 1 tests OK test-poisson.R................ 1 tests OK test-poisson.R................ 1 tests OK test-poisson.R................ 2 tests OK 0.4s - test-print.R.................. 0 tests test-print.R.................. 0 tests test-print.R.................. 48 tests OK test-print.R.................. 48 tests OK test-print.R.................. 48 tests OK test-print.R.................. 48 tests OK test-print.R.................. 48 tests OK test-print.R.................. 49 tests OK test-print.R.................. 50 tests OK test-print.R.................. 51 tests OK test-print.R.................. 51 tests OK test-print.R.................. 51 tests OK test-print.R.................. 51 tests OK test-print.R.................. 52 tests OK test-print.R.................. 53 tests OK test-print.R.................. 54 tests OK test-print.R.................. 54 tests OK test-print.R.................. 54 tests OK test-print.R.................. 54 tests OK test-print.R.................. 55 tests OK test-print.R.................. 56 tests OK test-print.R.................. 57 tests OK 0.7s - test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 0 tests test-se.R..................... 1 tests OK test-se.R..................... 1 tests OK test-se.R..................... 2 tests OK test-se.R..................... 2 tests OK test-se.R..................... 6 tests OK test-se.R..................... 6 tests OK test-se.R..................... 6 tests OK test-se.R..................... 7 tests OK test-se.R..................... 7 tests OK test-se.R..................... 8 tests OK test-se.R..................... 8 tests OK test-se.R..................... 9 tests OK test-se.R..................... 10 tests OK test-se.R..................... 10 tests OK test-se.R..................... 14 tests OK test-se.R..................... 14 tests OK test-se.R..................... 14 tests OK test-se.R..................... 15 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 16 tests OK test-se.R..................... 17 tests OK test-se.R..................... 18 tests OK 33.3s - test-singular.R............... 0 tests test-singular.R............... 0 tests test-singular.R............... 0 tests test-singular.R............... 0 tests test-singular.R............... 1 tests OK test-singular.R............... 2 tests OK 0.1s - test-start.R.................. 0 tests test-start.R.................. 0 tests test-start.R.................. 0 tests test-start.R.................. 0 tests test-start.R.................. 0 tests test-start.R.................. 1 tests OK test-start.R.................. 2 tests OK 0.2s - test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 0 tests test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 16 tests OK test-summary_mdyplFit.R....... 17 tests OK test-summary_mdyplFit.R....... 17 tests OK test-summary_mdyplFit.R....... 17 tests OK test-summary_mdyplFit.R....... 17 tests OK test-summary_mdyplFit.R....... 18 tests OK test-summary_mdyplFit.R....... 18 tests OK test-summary_mdyplFit.R....... 18 tests OK test-summary_mdyplFit.R....... 19 tests OK test-summary_mdyplFit.R....... 20 tests OK test-summary_mdyplFit.R....... 20 tests OK test-summary_mdyplFit.R....... 20 tests OK test-summary_mdyplFit.R....... 21 tests OK 6.7s - test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 0 tests test-transformation.R......... 1 tests OK test-transformation.R......... 2 tests OK test-transformation.R......... 3 tests OK 0.3s -All ok, NA results (89.3s) - - -Detailed test results saved to: benchmarks/results/20251110_142635/test_results.txt - - ====================================================================== -SECTION 2: MICROBENCHMARK COMPARISON -(100 evaluations with unit: seconds) -====================================================================== - -Test: Lizards dataset (small) -Unit: seconds - expr min lq mean median uq max neval - original 0.007249401 0.01269455 0.01776941 0.0172211 0.02214865 0.0369909 100 - new 0.006609902 0.01268585 0.01728913 0.0163083 0.02137415 0.0353854 100 - - -Speedup factor: 1.055971 x - - ====================================================================== -SECTION 3: ENDOMETRIAL DATASET (PROBIT LINK) -====================================================================== - -Microbenchmark (50 evaluations): -Unit: seconds - expr min lq mean median uq max neval - original 0.008669302 0.0124377 0.01720837 0.01515210 0.0203757 0.0430905 50 - new 0.009150701 0.0143091 0.01781808 0.01756955 0.0208440 0.0287275 50 - - -Speedup factor: 0.8624068 x - - ====================================================================== -SECTION 4: MULTIPLEFEATURES DATASET (HIGH-DIMENSIONAL) -Reference: Sterzinger & Kosmidis (2024, Section 8) -====================================================================== - -Dataset info: - Total observations: 2000 - Training observations: 1000 - Number of features: 140 - Dimensionality ratio (kappa): 0.14 - -Running single timing test... - -Original version timing: - user system elapsed - 20.47 0.58 21.79 - -New version timing: - user system elapsed - 19.33 0.60 20.72 - -MultipleFeatures speedup: 1.051641 x - -Numerical verification: - Coefficients match: TRUE - Max coefficient difference: 0 - Deviance match: TRUE - - ====================================================================== -SECTION 5: MDYPL METHOD (MultipleFeatures) -Maximum Diaconis-Ylvisaker Prior Penalized Likelihood -====================================================================== - -Testing mdyplFit method with alpha = 1/(1 + kappa) - Alpha value: 0.8772 - -Original mdyplFit timing: - user system elapsed - 0.20 0.03 0.22 - -New mdyplFit timing: - user system elapsed - 0.25 0.00 0.29 - -MDYPL speedup: 0.7586207 x - -Numerical verification (MDYPL): - Coefficients match: TRUE - Max coefficient difference: 0 - - ====================================================================== -SECTION 6: OVERALL SUMMARY -====================================================================== - -Speedup Summary: - Lizards (small) : 1.06x faster - Endometrial (medium) : 0.86x faster - MultipleFeatures (large).elapsed: 1.05x faster - MDYPL (large).elapsed : 0.76x faster - -Mean speedup: 0.93 x -Median speedup: 0.96 x - - ====================================================================== -BENCHMARKING COMPLETE -All results saved to: benchmarks/results/20251110_142635 -====================================================================== diff --git a/benchmarks/results/20251110_142635/plots/01_lizards_comparison.png b/benchmarks/results/20251110_142635/plots/01_lizards_comparison.png deleted file mode 100644 index 7848440833695b218fdcb3a95161ac8a2ccbfd7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z diff --git a/benchmarks/results/20251110_142635/plots/02_endometrial_comparison.png b/benchmarks/results/20251110_142635/plots/02_endometrial_comparison.png deleted file mode 100644 index 7848440833695b218fdcb3a95161ac8a2ccbfd7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z diff --git a/benchmarks/results/20251110_142635/plots/03_speedup_summary.png b/benchmarks/results/20251110_142635/plots/03_speedup_summary.png deleted file mode 100644 index 7848440833695b218fdcb3a95161ac8a2ccbfd7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z diff --git a/benchmarks/results/20251110_142635/plots/04_absolute_timing.png b/benchmarks/results/20251110_142635/plots/04_absolute_timing.png deleted file mode 100644 index 7848440833695b218fdcb3a95161ac8a2ccbfd7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z diff --git a/benchmarks/results/20251110_142635/plots/05_lizards_distribution.png b/benchmarks/results/20251110_142635/plots/05_lizards_distribution.png deleted file mode 100644 index 7848440833695b218fdcb3a95161ac8a2ccbfd7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z diff --git a/benchmarks/results/20251110_142635/plots/summary_statistics.csv b/benchmarks/results/20251110_142635/plots/summary_statistics.csv deleted file mode 100644 index a298af0..0000000 --- a/benchmarks/results/20251110_142635/plots/summary_statistics.csv +++ /dev/null @@ -1,5 +0,0 @@ -"Dataset","Version","Median","Mean","SD" -"Lizards","Original",0.0172211005,0.01776941499,0.00652682193196431 -"Lizards","New",0.016308301,0.01728913399,0.00651137518225907 -"Endometrial","Original",0.015152101,0.01720837496,0.0067319175452717 -"Endometrial","New",0.017569551,0.01781808104,0.00452952984679089 diff --git a/benchmarks/results/20251110_142635/test_results.txt b/benchmarks/results/20251110_142635/test_results.txt deleted file mode 100644 index 8cf4c1d..0000000 --- a/benchmarks/results/20251110_142635/test_results.txt +++ /dev/null @@ -1,3 +0,0 @@ -Original: NA tests (89.3s) -New: NA tests (113.3s) -Speedup: 0.79x faster diff --git a/benchmarks/results/20251110_144218/benchmark_data.RData b/benchmarks/results/20251110_144218/benchmark_data.RData deleted file mode 100644 index 76637f1bb1dedd22b1bab241148a13300ee879e8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2111 zcmV-F2*CFriwFP!000002Gv-5R20`89$=SO3?kK3n;5YtQ81P8D3~gAAz~C8Bhf0T zG%)PWvX7a4%*;Mumt~iiXnbI*N0U;En3IyEA=XEm;>jsCMlIErswn1YLYf|roK}sd z(Zn=tXTIxF+^}Gq{NtXpeEWNUzkBE2`5l(!7iYv4$5Ip(K`E5sRD@FcNkz^tOiRy9 zrzl0ZB!y85Dn`QlS$!4FYlPBr#-!Fs5#N%Ol0(G(5*~viH7I@Kr0=o3s;2B#=|`Sp$}@#By0YD6GCJRKcxChyOz8s7%IT4@cGlh`8SCF0 zFCXT-pND1bmvOU)TO{MAx?jV;eqc9b=lebi@oW2#-?OEtS;m@6gTTsP44}Tv8UfkY z-_nHmTaOSv=U)aoA8LWWd&r*gIq1W2?gz+g`SLR2 z_)FQy<6AI~(2EORgkG%9K|Nda zRpfC#vlxC3vl_Ck?-ighSU~!DEEHQ&5O{hA3g;?W8nuR|GeTJ65oxw{P9VI=f1xY zKJVNl>y;1>e`eVk?5AxSkM*?1r^3&8s{(edcDWaM{ClAK*L{e!v0+ATI4Uwo=N!GPf>`UFq_De zHIR+xx1hf=`$ougW+G&5Zx_%IM|iQ5t|5*tI|}`Crjy98ake7PlI{j?ZPr4vPbJ~# zi~ZSY#F^#@z>2WHBcJi7m5{lptH846MTo2DCdh2H1Iv$Whree3X~;(7O8D!hehyhT zP)+Ct1zasmzbqD-SeTyLr+c%<)x$hX_%{vxBuJ%yGuD2B; zAM+0Bzt;e?C>{lxJpz#}t5C;u^a_!;BtzD|zZ3;NI^+GRD?A``G{PoS~(|+X$P`Ho>JAdnC)U}?`LFR7wk(bY? zA#tyy^^zG4Vt5)^zmtPxzYFrwpEf)NvS|Df;vI*gp!c4mqp@zisgPY$eRAI5*N%zi znBdoyf^k~-z;98{F(fF$ALJLu>D9a$V8hYG9PeYnKx9aUgN`AT@{k%s;yUpDtqvNbK zS4Qts#bq*9u79XdM(4CTpym116tHsu@xshr=uIt?T4glHT!h~I!d#$X_qV+=ax-bj z`kfyE?d=Cp$9=vLaaH%d5f47AE`yKbgbi{{TLSX?Rz%{q^IY$Qy}{W59<>c?kl$-H zx64>J^)>j_O)i4$JGBn^y`TN&l8lW-^&dl@?}6N~CJXuNY%_7{YyBF;uWuet;`Kak z+r|Uwso;Ai4E24k4X{^dt_KgFqO~9K9eXgX*-Ed&ujXPF?B2*9qwczSucOY|J$o_z z`680RqbBJz{M{SLTh*8PC3ra6$aGXWpapujmZM)^TLt1Pldgfkd-^!+Ut^{cyqc!e zBX3jR0Qd+69Q1r!7jlvm!H4b}zTlN|-0=Inh3F%LPwR-p@Pfu=MqgMLpYCe;jifRjBh^r#T!kg8l|LtsO1(X2? zo51iX0>f$p_mEI2440!AmbM6tCeSnd)jB;J(8S0AMDf+0?hEvU+w68rs;UpAo}8*L z8XkV@*?%K&(bz1~c?*~OQK&AzxUbL@bx3usYeU#avo@%%PU!T-FEyw> zUcSAyi28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z diff --git a/benchmarks/results/20251110_144218/plots/02_endometrial_comparison.png b/benchmarks/results/20251110_144218/plots/02_endometrial_comparison.png deleted file mode 100644 index 7848440833695b218fdcb3a95161ac8a2ccbfd7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z diff --git a/benchmarks/results/20251110_144218/plots/03_speedup_summary.png b/benchmarks/results/20251110_144218/plots/03_speedup_summary.png deleted file mode 100644 index 7848440833695b218fdcb3a95161ac8a2ccbfd7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z diff --git a/benchmarks/results/20251110_144218/plots/04_absolute_timing.png b/benchmarks/results/20251110_144218/plots/04_absolute_timing.png deleted file mode 100644 index 7848440833695b218fdcb3a95161ac8a2ccbfd7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z diff --git a/benchmarks/results/20251110_144218/plots/05_lizards_distribution.png b/benchmarks/results/20251110_144218/plots/05_lizards_distribution.png deleted file mode 100644 index 7848440833695b218fdcb3a95161ac8a2ccbfd7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z diff --git a/benchmarks/results/20251110_144218/plots/summary_statistics.csv b/benchmarks/results/20251110_144218/plots/summary_statistics.csv deleted file mode 100644 index ea87d87..0000000 --- a/benchmarks/results/20251110_144218/plots/summary_statistics.csv +++ /dev/null @@ -1,5 +0,0 @@ -"Dataset","Version","Median","Mean","SD" -"Lizards","Original",0.0172598505,0.02005687496,0.0127806048378596 -"Lizards","New",0.0186590505,0.02051141999,0.00995345879697426 -"Endometrial","Original",0.032562301,0.03291419496,0.0106647091686285 -"Endometrial","New",0.029348401,0.02991950706,0.00952642493897422 diff --git a/benchmarks/results/20251110_144218/test_results.txt b/benchmarks/results/20251110_144218/test_results.txt deleted file mode 100644 index ed74bc5..0000000 --- a/benchmarks/results/20251110_144218/test_results.txt +++ /dev/null @@ -1,3 +0,0 @@ -Original: NA tests (137.4s) -New: NA tests (97.8s) -Speedup: 1.40x faster diff --git a/benchmarks/results/20251110_144957/benchmark_data.RData b/benchmarks/results/20251110_144957/benchmark_data.RData deleted file mode 100644 index 5fe7e2cb7bf6d505c63242a7bfe210c9d12c8832..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2129 zcmV-X2(I@ZiwFP!000002Gv-5a8qR#zkSjNbXjQ?R%KHZwnZ(K*Mh(%rBtxC*cOWH z;L@haZHXpryh)nm=5>=MG!@x~Iz^tl6-E}OE>;Dt$ZYGPvvt^2kY%ZZBCWKdh!&g< z%uwmx`#YptVjsA>|G-Q*_dAc@`JHpV@7`}(uw?bDxYcnC!$dHVQQ=HPl=#R*XXZUT zbIweLi3}H4VN4_wE6Q?=ehlp{aY=a}#1HZ5kU8sGqPgsb5 zXl!WwQ1(!~P}^|!p*Vzc8H&eH_Tgej;&rR|qxEw*{v+l3U-~i<-_hzH32V4qqxE*Q zeKr*SNPBIhI!D@j!|d0a4pX$2tz@+Z@o79fNE=hZY05O^O6`qxL^*2?35-%{m4;y4 z09vV1Wvt-Dr|aS`LHxC4cpImQhm^^1XPxjvKJfvhaBzHzBwZIgd62EsAU&(Pq(hwH zoI9KJ%PhwvY29-LQiyFiFG>E_DX=?!x2+g!;~f%}3}br+^oA>+HAu3u=p^*dw*OfH zzYB!J&D$CPeo7nSh5Bz0XSNp0uwL1@40v;=BF?lR7ygxN=Kgn=QKJ`&Z_x3R8U9TvB@2Pl<`gQ){bgaLB2e_W| zX5{nq6;r=06fwKi)qcc4LnV{z60w>fw`DLT{-%3TeB02Kd^N71L?LtN#&1+ZH`%Aq;@@Hf~U50ub+Iv#~I zH{FB&n70Vv>HM-8_1O2VEJi%nLb#j;dfR5=>-fD9JS>5)iBIAz%5&rj_}G5_5$ZGd zSCjrz0c*Q&D$Re)DVnF{67kQb^T1DOhjceIS zMjGO6k6YpI$oUP`AHN^`?UOzy{DW%5d;UOqg=d!cKsx*M=x6>p^wC+cRN@=@*(q1* z*wD{aBx})g!DpjJ$5K#4e~4d#PNU)~aBb8nxo2)@ZP0M!VepHy7Spx!{dd+X&dw>t^^){{l_f~h7cmBU z?}5GWz3%!zj!SWWQxBeHv3G8eD&U2k^#MeAo*#z8VKlrTA??8Q?Ne3W(rs?3} z+4WUAaCA*r+sDTsk4Lr~eekS!6S#cGzZl4wvtW1H9H`4v`8wS;Wod|ap5CQEolCM1 z=YClZ9*(+xFJuj^nJ=41KLL3wBSAnp9ywEpzQ zSMB*lh!ZZ%Z9u-jY|86h0epwD6?M2e7Z9&?`M|AWE>Zo@ZUHaX({BUE8@-k4N!vp6 z`DcLU)%!j9CqDrxoXTyZy8Gepm8YZcp1E_#f7(gfcT>KA-QTtWYhPA3_*b!Kz_0$} z?sJmdS{(zPFP440M3Osdw}EF(=6u9gpA`_du{;_3t-3buEcU~h7Sz4N6@mS-Qx|(6g4mH=^*B0~?||M>+UCB+SXpYI@jbm$2l@*O@_ zB2c6&Et1{@A_?hWM=2D6-KXLf>E+iK>BR?yBD3(XwNIs7bzPN;8nY`Xhj~@R>bVM4 z(SIr%=s;A^!DL{$Gy|(G4ZepAR>R=+7*?y)8(4L)X85btX|zF2tQ0_sAJ-HgtO;+k zU`dU>$<6sa@?P=(3qF}*@nW%}-qzcsq@PhqYO7v*)1>5Q#bPEOV&n(-j-~sP7i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z diff --git a/benchmarks/results/20251110_144957/plots/02_endometrial_comparison.png b/benchmarks/results/20251110_144957/plots/02_endometrial_comparison.png deleted file mode 100644 index 7848440833695b218fdcb3a95161ac8a2ccbfd7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z diff --git a/benchmarks/results/20251110_144957/plots/03_speedup_summary.png b/benchmarks/results/20251110_144957/plots/03_speedup_summary.png deleted file mode 100644 index 7848440833695b218fdcb3a95161ac8a2ccbfd7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z diff --git a/benchmarks/results/20251110_144957/plots/04_absolute_timing.png b/benchmarks/results/20251110_144957/plots/04_absolute_timing.png deleted file mode 100644 index 7848440833695b218fdcb3a95161ac8a2ccbfd7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z diff --git a/benchmarks/results/20251110_144957/plots/05_lizards_distribution.png b/benchmarks/results/20251110_144957/plots/05_lizards_distribution.png deleted file mode 100644 index 7848440833695b218fdcb3a95161ac8a2ccbfd7f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 581 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i28yg*QRD=qm;-!5T>t<7zx;^w2_ToV zz$3Dlfq_2}gc(=ZFVAFPV0_`};uumf=j}m8UZ9dg3%>j3^0SKonWJDhg}@()(1Q$& T``$Dj0Qt(()z4*}Q$iB}(R?6z diff --git a/benchmarks/results/20251110_144957/plots/summary_statistics.csv b/benchmarks/results/20251110_144957/plots/summary_statistics.csv deleted file mode 100644 index 752d2e6..0000000 --- a/benchmarks/results/20251110_144957/plots/summary_statistics.csv +++ /dev/null @@ -1,5 +0,0 @@ -"Dataset","Version","Median","Mean","SD" -"Lizards","Original",0.029412801,0.02957711407,0.00609669878307209 -"Lizards","New",0.028598351,0.029392598,0.00532998275559886 -"Endometrial","Original",0.040655901,0.04680443282,0.0205270555333662 -"Endometrial","New",0.043849851,0.05011108294,0.022082500465604 From 2a49294a012d39a5ece3c2bb41842236f074fcb3 Mon Sep 17 00:00:00 2001 From: Ollie Date: Wed, 26 Nov 2025 12:39:47 +0000 Subject: [PATCH 12/15] Final changes to main_benchmark fixing new replicate for MultipleFeatures fits --- benchmarks/main_benchmark.R | 66 ++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/benchmarks/main_benchmark.R b/benchmarks/main_benchmark.R index f064602..9d754cf 100644 --- a/benchmarks/main_benchmark.R +++ b/benchmarks/main_benchmark.R @@ -144,34 +144,42 @@ tryCatch({ cat("Running timing tests...\n\n") cat("Original version timing:\n") + fit_mf_orig <- glm(full_mf_fm, data = MultipleFeatures, + family = binomial(), + method = brglm2_original, + subset = training, + maxit = 200) + time_mf_orig <- system.time({ - replicate(10, { - fit_mf_orig <- glm(full_mf_fm, data = MultipleFeatures, - family = binomial(), - method = brglm2_original, - subset = training, - maxit = 200) + replicate(10, { + glm(full_mf_fm, data = MultipleFeatures, + family = binomial(), + method = brglm2_original, + subset = training, + maxit = 200) + }) }) -}) - cat("Average time per run:", time_mf_orig["elapsed"] / 10, "s\n\n") - + cat("New version timing:\n") + fit_mf_new <- glm(full_mf_fm, data = MultipleFeatures, + family = binomial(), + method = brglm2_new, + subset = training, + maxit = 200) + time_mf_new <- system.time({ - replicate(10, { # Change from 10 replications - fit_mf_new <- glm(full_mf_fm, data = MultipleFeatures, - family = binomial(), - method = brglm2_new, - subset = training, - maxit = 200) + replicate(10, { + glm(full_mf_fm, data = MultipleFeatures, + family = binomial(), + method = brglm2_new, + subset = training, + maxit = 200) }) }) + cat("Average time per run:", time_mf_new["elapsed"] / 10, "s\n\n") - # Divide elapsed time by number of replications for average - cat("Average time per run:", time_mf_orig["elapsed"] / 10, "s\n") - - cat("MultipleFeatures speedup:", - time_mf_orig["elapsed"] / time_mf_new["elapsed"], "x\n") + cat("MultipleFeatures speedup:", time_mf_orig["elapsed"] / time_mf_new["elapsed"], "x\n") # Verify coefficients match cat("\nNumerical verification:\n") @@ -201,9 +209,16 @@ tryCatch({ cat(" Alpha value:", round(alpha_val, 4), "\n\n") cat("Original mdyplFit timing:\n") + fit_mdypl_orig <- glm(full_mf_fm, data = MultipleFeatures, + family = binomial(), + method = mdypl_original, + alpha = alpha_val, + subset = training, + maxit = 200) + time_mdypl_orig <- system.time({ replicate(50, { - fit_mdypl_orig <- glm(full_mf_fm, data = MultipleFeatures, + full_mdypl_orig <- glm(full_mf_fm, data = MultipleFeatures, family = binomial(), method = mdypl_original, alpha = alpha_val, @@ -215,9 +230,16 @@ tryCatch({ cat("\n") cat("New mdyplFit timing:\n") + fit_mdypl_new <- glm(full_mf_fm, data = MultipleFeatures, + family = binomial(), + method = mdypl_new, + alpha = alpha_val, + subset = training, + maxit = 200) + time_mdypl_new <- system.time({ replicate(50, { - fit_mdypl_new <- glm(full_mf_fm, data = MultipleFeatures, + full_mdypl_new <- glm(full_mf_fm, data = MultipleFeatures, family = binomial(), method = mdypl_new, alpha = alpha_val, From ebf1410179dd3c49b9d3b1bcacb89ef171a9a4d7 Mon Sep 17 00:00:00 2001 From: Ollie Date: Thu, 27 Nov 2025 10:35:51 +0000 Subject: [PATCH 13/15] Helper file implementation with functions: compute_fit, estimate_dispersion, adjustment functions (prefix AS_), DD. Tested. --- R/brglmFit-helper.R | 367 ++++++++++++++++++++++++++++++++++++++++++++ R/brglmFit.R | 329 ++++----------------------------------- 2 files changed, 397 insertions(+), 299 deletions(-) create mode 100644 R/brglmFit-helper.R diff --git a/R/brglmFit-helper.R b/R/brglmFit-helper.R new file mode 100644 index 0000000..0f95646 --- /dev/null +++ b/R/brglmFit-helper.R @@ -0,0 +1,367 @@ +# Copyright (C) 2016- Ioannis Kosmidis + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 or 3 of the License +# (at your option). +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# A copy of the GNU General Public License is available at +# http://www.r-project.org/Licenses/ + +# Helper functions for brglmFit +# These are self-contained functions that don't rely on parent scope + +#' Compute all quantities needed for a GLM fit +#' +#' @param pars Vector of parameters (betas and dispersion) +#' @param y Response vector +#' @param x Design matrix +#' @param weights Observation weights +#' @param offset Offset vector +#' @param family GLM family object +#' @param fixed_totals NULL or grouping vector for fixed totals +#' @param row_totals NULL or vector of row totals +#' @param no_dispersion Logical indicating if dispersion is fixed +#' @param nobs Number of observations +#' @param nvars Number of variables +#' @param keep Logical vector indicating which observations to keep +#' @param need_qr Logical indicating if QR decomposition is needed +#' @param need_hatvalues Logical indicating if hat values are needed +#' +#' @return A list of class "brglmFit_quantities" containing all computed quantities +compute_fit <- function(pars, y, x, weights, offset, family, + fixed_totals = NULL, row_totals = NULL, + no_dispersion = FALSE, nobs, nvars, keep, + need_qr = TRUE, need_hatvalues = TRUE) { + + # Extract Parameters + betas <- pars[seq.int(nvars)] + dispersion <- pars[nvars + 1] + precision <- 1 / dispersion + + # Basic Quantities + etas <- drop(x %*% betas + offset) + mus <- family$linkinv(etas) + mus_unscaled <- mus # Keep original for gradient computation + if (!is.null(fixed_totals)) { + mus_totals <- as.vector(tapply(mus, fixed_totals, sum))[fixed_totals] + mus <- mus * row_totals / mus_totals # Scaled version + etas <- family$linkfun(mus) # Update etas to match scaled mus + } + + # Mean Quantities + d1mus <- family$mu.eta(etas) + d2mus <- family$d2mu.deta(etas) + varmus <- family$variance(mus) + d1varmus <- family$d1variance(mus) + working_weights <- weights * d1mus^2 / varmus + + # QR Decomposition and Hat Values (only if needed) + qr_decomposition <- R_matrix <- Q_matrix <- hatvalues <- NULL + info_beta <- inverse_info_beta <- NULL + + if (need_qr) { + wx <- sqrt(working_weights) * x + qr_decomposition <- qr(wx) + R_matrix <- qr.R(qr_decomposition) + + # Information Matrices + info_beta <- precision * crossprod(R_matrix) + inverse_info_beta <- dispersion * chol2inv(R_matrix) + + # Hat Values (only if needed and we have QR) + if (need_hatvalues) { + Q_matrix <- qr.Q(qr_decomposition) + hatvalues <- .rowSums(Q_matrix * Q_matrix, nobs, nvars, TRUE) + } + } + + # Dispersion Quantities (depends on family) + if (!no_dispersion) { + zetas <- -weights * precision + + # Derivatives of cumulant function (only for non-zero weights) + d1afuns <- d2afuns <- d3afuns <- rep(NA_real_, nobs) + d1afuns[keep] <- family$d1afun(zetas[keep]) + d2afuns[keep] <- family$d2afun(zetas[keep]) + d3afuns[keep] <- family$d3afun(zetas[keep]) + + # Special case for Gamma family + if (family$family == "Gamma") { + d1afuns <- d1afuns - 2 + } + + # Deviance residuals + deviance_residuals <- family$dev.resids(y, mus, weights) + Edeviance_residuals <- weights * d1afuns + + # Information for dispersion parameter + info_zeta <- 0.5 * sum(weights^2 * d2afuns, na.rm = TRUE) / dispersion^4 + inverse_info_zeta <- 1 / info_zeta + } else { + # Fixed dispersion (binomial, Poisson) + zetas <- d1afuns <- d2afuns <- d3afuns <- NA_real_ + deviance_residuals <- family$dev.resids(y, mus, weights) + Edeviance_residuals <- NA_real_ + info_zeta <- inverse_info_zeta <- NA_real_ + } + + # Gradient Computation + # Use unscaled mus for gradient when fixed_totals is used + mus_for_gradient <- if (!is.null(fixed_totals)) mus_unscaled else mus + etas_for_gradient <- if (!is.null(fixed_totals)) family$linkfun(mus_unscaled) else etas + d1mus_for_gradient <- family$mu.eta(etas_for_gradient) + varmus_for_gradient <- family$variance(mus_for_gradient) + + score_components_beta <- weights * d1mus_for_gradient * (y - mus_for_gradient) / + varmus_for_gradient * x + grad_beta <- precision * .colSums(score_components_beta, nobs, nvars, TRUE) + + if (!no_dispersion) { + grad_zeta <- 0.5 * precision^2 * + sum(deviance_residuals - Edeviance_residuals, na.rm = TRUE) + } else { + grad_zeta <- NA_real_ + } + + # Return all computed quantities as class + structure(list( + # Parameters + betas = betas, + dispersion = dispersion, + precision = precision, + + # Basic quantities + etas = etas, + mus = mus, + mus_unscaled = mus_unscaled, # For gradient with fixed_totals + + # Mean-related quantities + d1mus = d1mus, + d2mus = d2mus, + varmus = varmus, + d1varmus = d1varmus, + working_weights = working_weights, + + # QR decomposition and related + qr_decomposition = qr_decomposition, + R_matrix = R_matrix, + Q_matrix = Q_matrix, + hatvalues = hatvalues, + + # Information matrices (pre-computed) + info_beta = info_beta, + inverse_info_beta = inverse_info_beta, + + # Dispersion-related quantities + zetas = zetas, + d1afuns = d1afuns, + d2afuns = d2afuns, + d3afuns = d3afuns, + deviance_residuals = deviance_residuals, + Edeviance_residuals = Edeviance_residuals, + info_zeta = info_zeta, + inverse_info_zeta = inverse_info_zeta, + + # Gradients (pre-computed) + grad_beta = grad_beta, + grad_zeta = grad_zeta, + score_components_beta = score_components_beta, + + # Metadata + has_fixed_totals = !is.null(fixed_totals), + no_dispersion = no_dispersion + ), class = "brglmFit_quantities") +} + +#' Compute mean bias-reducing adjustment +#' +#' @param pars Parameter vector +#' @param fit Object of class "brglmFit_quantities" +#' @param level 0 for beta parameters, 1 for dispersion +#' @param x Design matrix +#' @param nobs Number of observations +#' @param nvars Number of variables +#' @param weights Observation weights +#' +#' @return Adjustment vector +AS_mean_adjustment <- function(pars, fit, level = 0, + x, nobs, nvars, weights) { + if (level == 0) { + adj <- .colSums(0.5 * fit$hatvalues * fit$d2mus / fit$d1mus * x, + nobs, nvars, TRUE) + return(adj) + } else { + s1 <- sum(weights^3 * fit$d3afuns, na.rm = TRUE) + s2 <- sum(weights^2 * fit$d2afuns, na.rm = TRUE) + return((nvars - 2) / (2 * fit$dispersion) + + s1 / (2 * fit$dispersion^2 * s2)) + } +} + +#' Compute Jeffreys prior penalty adjustment +#' +#' @param pars Parameter vector +#' @param fit Object of class "brglmFit_quantities" +#' @param level 0 for beta parameters, 1 for dispersion +#' @param x Design matrix +#' @param nobs Number of observations +#' @param nvars Number of variables +#' @param weights Observation weights +#' @param a Power of Jeffreys prior (default 0.5) +#' +#' @return Adjustment vector +AS_Jeffreys_adjustment <- function(pars, fit, level = 0, + x, nobs, nvars, weights, a = 0.5) { + if (level == 0) { + return(2 * a * .colSums(0.5 * fit$hatvalues * + (2 * fit$d2mus/fit$d1mus - fit$d1varmus * fit$d1mus / fit$varmus) * x, + nobs, nvars, TRUE)) + } else { + s1 <- sum(weights^3 * fit$d3afuns, na.rm = TRUE) + s2 <- sum(weights^2 * fit$d2afuns, na.rm = TRUE) + return(2 * a * (-(nvars + 4)/(2 * fit$dispersion) + + s1/(2 * fit$dispersion^2 * s2))) + } +} + +#' Compute median bias-reducing adjustment +#' +#' @param pars Parameter vector +#' @param fit Object of class "brglmFit_quantities" +#' @param level 0 for beta parameters, 1 for dispersion +#' @param x Design matrix +#' @param nobs Number of observations +#' @param nvars Number of variables +#' @param weights Observation weights +#' +#' @return Adjustment vector +AS_median_adjustment <- function(pars, fit, level = 0, + x, nobs, nvars, weights) { + if (level == 0) { + info_unscaled <- fit$info_beta / fit$precision + inverse_info_unscaled <- fit$inverse_info_beta / fit$dispersion + + b_vector <- numeric(nvars) + for (j in seq.int(nvars)) { + inverse_info_unscaled_j <- inverse_info_unscaled[j, ] + vcov_j <- tcrossprod(inverse_info_unscaled_j) / inverse_info_unscaled_j[j] + hats_j <- .rowSums((x %*% vcov_j) * x, nobs, nvars, TRUE) * fit$working_weights + b_vector[j] <- inverse_info_unscaled_j %*% .colSums(x * (hats_j * + (fit$d1mus * fit$d1varmus / (6 * fit$varmus) - 0.5 * fit$d2mus/fit$d1mus)), + nobs, nvars, TRUE) + } + return(.colSums(0.5 * fit$hatvalues * fit$d2mus / fit$d1mus * x, + nobs, nvars, TRUE) + + info_unscaled %*% b_vector) + } else { + s1 <- sum(weights^3 * fit$d3afuns, na.rm = TRUE) + s2 <- sum(weights^2 * fit$d2afuns, na.rm = TRUE) + return(nvars / (2 * fit$dispersion) + + s1 / (6 * fit$dispersion^2 * s2)) + } +} + +#' Compute mixed bias-reducing adjustment +#' +#' @param pars Parameter vector +#' @param fit Object of class "brglmFit_quantities" +#' @param level 0 for beta parameters, 1 for dispersion +#' @param x Design matrix +#' @param nobs Number of observations +#' @param nvars Number of variables +#' @param weights Observation weights +#' +#' @return Adjustment vector +AS_mixed_adjustment <- function(pars, fit, level = 0, + x, nobs, nvars, weights) { + if (level == 0) { + return(.colSums(0.5 * fit$hatvalues * fit$d2mus/fit$d1mus * x, + nobs, nvars, TRUE)) + } else { + s1 <- sum(weights^3 * fit$d3afuns, na.rm = TRUE) + s2 <- sum(weights^2 * fit$d2afuns, na.rm = TRUE) + return(nvars / (2 * fit$dispersion) + + s1 / (6 * fit$dispersion^2 * s2)) + } +} + +#' Estimate the ML of the dispersion parameter for gaussian, gamma and inverse Gaussian +#' Set the dispersion to 1 if Poisson or binomial +#' +#' @param betas Regression coefficients +#' @param y Response vector +#' @param x Design matrix +#' @param weights Observation weights +#' @param offset Offset vector +#' @param family GLM family object +#' @param fixed_totals NULL or grouping vector for fixed totals +#' @param row_totals NULL or vector of row totals +#' @param no_dispersion Logical indicating if dispersion is fixed +#' @param nobs Number of observations +#' @param nvars Number of variables +#' @param keep Logical vector indicating which observations to keep +#' @param df_residual Residual degrees of freedom +#' @param control Control parameters +#' +#' @seealso compute_fit +#' +#' @return List with dispersion and dispersion_ML +estimate_dispersion <- function(betas, y, x, weights, offset, family, + fixed_totals, row_totals, no_dispersion, + nobs, nvars, keep, df_residual, control) { + if (no_dispersion) { + disp <- 1 + dispML <- 1 + } else { + if (df_residual > 0) { + dispFit <- try(uniroot(f = function(phi) { + theta <- c(betas, phi) + cfit <- compute_fit(pars = theta, + y = y, + x = x, + weights = weights, + offset = offset, + family = family, + fixed_totals = fixed_totals, + row_totals = row_totals, + no_dispersion = no_dispersion, + nobs = nobs, + nvars = nvars, + keep = keep, + need_qr = FALSE, + need_hatvalues = FALSE) + cfit$grad_zeta + }, lower = .Machine$double.eps, upper = 10000, tol = control$epsilon), silent = FALSE) + if (inherits(dispFit, "try-error")) { + warning("the ML estimate of the dispersion could not be calculated. An alternative estimate had been used as starting value.") + dispML <- NA_real_ + disp <- NA_real_ + } else { + disp <- dispML <- dispFit$root + } + } else { ## if the model is saturated dispML is NA_real_ + disp <- 1 ## A convenient value + dispML <- NA_real_ + } + } + list(dispersion = disp, dispersion_ML = dispML) +} + +#' Utility function for symbolic differentiation +#' +#' @param expr Expression to differentiate +#' @param name Variable name to differentiate with respect to +#' @param order Order of derivative +#' +#' @return Differentiated expression +DD <- function(expr, name, order = 1) { + if(order < 1) stop("'order' must be >= 1") + if(order == 1) D(expr, name) + else DD(D(expr, name), name, order - 1) +} \ No newline at end of file diff --git a/R/brglmFit.R b/R/brglmFit.R index b33ab8d..9be71e4 100644 --- a/R/brglmFit.R +++ b/R/brglmFit.R @@ -296,183 +296,6 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL } } - # Always computes everything needed, stores it once, passes it around - compute_fit <- function(pars, y, x, weights, offset, family, - fixed_totals = NULL, row_totals = NULL, - no_dispersion = FALSE, nobs, nvars, keep, - need_qr = TRUE, need_hatvalues = TRUE) { - - # Extract Parameters - betas <- pars[seq.int(nvars)] - dispersion <- pars[nvars + 1] - precision <- 1 / dispersion - - # Basic Quantities - etas <- drop(x %*% betas + offset) - mus <- family$linkinv(etas) - mus_unscaled <- mus # Keep original for gradient computation - if (!is.null(fixed_totals)) { - mus_totals <- as.vector(tapply(mus, fixed_totals, sum))[fixed_totals] - mus <- mus * row_totals / mus_totals # Scaled version - etas <- family$linkfun(mus) # Update etas to match scaled mus - } - - # Mean Quantities - d1mus <- family$mu.eta(etas) - d2mus <- family$d2mu.deta(etas) - varmus <- family$variance(mus) - d1varmus <- family$d1variance(mus) - working_weights <- weights * d1mus^2 / varmus - - # QR Decomposition and Hat Values (only if needed) - qr_decomposition <- R_matrix <- Q_matrix <- hatvalues <- NULL - info_beta <- inverse_info_beta <- NULL - - # TODO: Avoid forming full Q? Approximate hat values? - if (need_qr) { - wx <- sqrt(working_weights) * x - qr_decomposition <- qr(wx) - R_matrix <- qr.R(qr_decomposition) - - # Information Matrices - info_beta <- precision * crossprod(R_matrix) - inverse_info_beta <- dispersion * chol2inv(R_matrix) - - # Hat Values (only if needed and we have QR) - if (need_hatvalues) { - Q_matrix <- qr.Q(qr_decomposition) - hatvalues <- .rowSums(Q_matrix * Q_matrix, nobs, nvars, TRUE) - } - } - - # Dispersion Quantities (dept on family) - if (!no_dispersion) { - zetas <- -weights * precision - - # Derivatives of cumulant function (only for non-zero weights) - d1afuns <- d2afuns <- d3afuns <- rep(NA_real_, nobs) - d1afuns[keep] <- family$d1afun(zetas[keep]) - d2afuns[keep] <- family$d2afun(zetas[keep]) - d3afuns[keep] <- family$d3afun(zetas[keep]) - - # Special case for Gamma family - if (family$family == "Gamma") { - d1afuns <- d1afuns - 2 - } - - # Deviance residuals - deviance_residuals <- family$dev.resids(y, mus, weights) - Edeviance_residuals <- weights * d1afuns - - # Information for dispersion parameter - info_zeta <- 0.5 * sum(weights^2 * d2afuns, na.rm = TRUE) / dispersion^4 - inverse_info_zeta <- 1 / info_zeta - } else { - # Fixed dispersion (binomial, Poisson) - zetas <- d1afuns <- d2afuns <- d3afuns <- NA_real_ - deviance_residuals <- family$dev.resids(y, mus, weights) - Edeviance_residuals <- NA_real_ - info_zeta <- inverse_info_zeta <- NA_real_ - } - - # Gradient Computation - # Use unscaled mus for gradient when fixed_totals is used - mus_for_gradient <- if (!is.null(fixed_totals)) mus_unscaled else mus - etas_for_gradient <- if (!is.null(fixed_totals)) family$linkfun(mus_unscaled) else etas - d1mus_for_gradient <- family$mu.eta(etas_for_gradient) - varmus_for_gradient <- family$variance(mus_for_gradient) - - score_components_beta <- weights * d1mus_for_gradient * (y - mus_for_gradient) / - varmus_for_gradient * x - grad_beta <- precision * .colSums(score_components_beta, nobs, nvars, TRUE) - - if (!no_dispersion) { - grad_zeta <- 0.5 * precision^2 * - sum(deviance_residuals - Edeviance_residuals, na.rm = TRUE) - } else { - grad_zeta <- NA_real_ - } - - # Return all computed quantities as class - structure(list( - # Parameters - betas = betas, - dispersion = dispersion, - precision = precision, - - # Basic quantities - etas = etas, - mus = mus, - mus_unscaled = mus_unscaled, # For gradient with fixed_totals - - # Mean-related quantities - d1mus = d1mus, - d2mus = d2mus, - varmus = varmus, - d1varmus = d1varmus, - working_weights = working_weights, - - # QR decomposition and related - qr_decomposition = qr_decomposition, - R_matrix = R_matrix, - Q_matrix = Q_matrix, - hatvalues = hatvalues, - - # Information matrices (pre-computed) - info_beta = info_beta, - inverse_info_beta = inverse_info_beta, - - # Dispersion-related quantities - zetas = zetas, - d1afuns = d1afuns, - d2afuns = d2afuns, - d3afuns = d3afuns, - deviance_residuals = deviance_residuals, - Edeviance_residuals = Edeviance_residuals, - info_zeta = info_zeta, - inverse_info_zeta = inverse_info_zeta, - - # Gradients (pre-computed) - grad_beta = grad_beta, - grad_zeta = grad_zeta, - score_components_beta = score_components_beta, - - # Metadata - has_fixed_totals = !is.null(fixed_totals), - no_dispersion = no_dispersion - ), class = "brglmFit_quantities") - } - - gradient <- function(pars, fit, level = 0) { - if (level == 0) { - return(fit$grad_beta) - } - else { - return(fit$grad_zeta) - } - } - - information <- function(pars, fit, level = 0, inverse = FALSE) { - if (level == 0) { - if (inverse) { - return(fit$inverse_info_beta) - } else { - return(fit$info_beta) - } - } - else { - if (inverse) { - return(fit$inverse_info_zeta) - } else { - return(fit$info_zeta) - } - } - } - - hat_values <- function(pars, fit = NULL) { - return(fit$hatvalues) - } - ## FIXME: Redundant function for now refit <- function(y, betas_start = NULL) { ## Estimate Beta @@ -486,115 +309,6 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL betas } - ## Estimate the ML of the dispersion parameter for gaussian, gamma and inverse Gaussian - ## Set the dispersion to 1 if Poisson or binomial - ## betas is only the regression parameters - estimate_dispersion <- function(betas, y) { - if (no_dispersion) { - disp <- 1 - dispML <- 1 - } else { - if (df_residual > 0) { - dispFit <- try(uniroot(f = function(phi) { - theta <- c(betas, phi) - cfit <- compute_fit(pars = theta, - y = y, - x = x, - weights = weights, - offset = offset, - family = family, - fixed_totals = fixed_totals, - row_totals = row_totals, - no_dispersion = no_dispersion, - nobs = nobs, - nvars = nvars, - keep = keep, - need_qr = FALSE, - need_hatvalues = FALSE) - gradient(theta, level = 1, fit = cfit) - }, lower = .Machine$double.eps, upper = 10000, tol = control$epsilon), silent = FALSE) - if (inherits(dispFit, "try-error")) { - warning("the ML estimate of the dispersion could not be calculated. An alternative estimate had been used as starting value.") - dispML <- NA_real_ - disp <- NA_real_ - } else { - disp <- dispML <- dispFit$root - } - } else { ## if the model is saturated dispML is NA_real_ - disp <- 1 ## A convenient value - dispML <- NA_real_ - } - } - list(dispersion = disp, dispersion_ML = dispML) - } - - AS_mean_adjustment <- function(pars, fit, level = 0) { - if (level == 0) { - # Zero division already handled by fit computation - adj <- .colSums(0.5 * fit$hatvalues * fit$d2mus / fit$d1mus * x, - nobs, nvars, TRUE) - return(adj) - } - else { - s1 <- sum(weights^3 * fit$d3afuns, na.rm = TRUE) - s2 <- sum(weights^2 * fit$d2afuns, na.rm = TRUE) - return((nvars - 2) / (2 * fit$dispersion) + - s1 / (2 * fit$dispersion^2 * s2)) - } - } - - AS_Jeffreys_adjustment <- function(pars, fit, level = 0, a = 0.5) { - if (level == 0) { - ## Use only observations with keep = TRUE to ensure that no division with zero takes place - return(2 * a * .colSums(0.5 * fit$hatvalues * (2 * fit$d2mus/fit$d1mus - fit$d1varmus * fit$d1mus / fit$varmus) * x, nobs, nvars, TRUE)) - } - else { - s1 <- sum(weights^3 * fit$d3afuns, na.rm = TRUE) - s2 <- sum(weights^2 * fit$d2afuns, na.rm = TRUE) - return(2 * a * (-(nvars + 4)/(2 * fit$dispersion) + s1/(2 * fit$dispersion^2 * s2))) - } - } - - AS_median_adjustment <- function(pars, fit, level = 0) { - if (level == 0) { - info_unscaled <- fit$info_beta / fit$precision - inverse_info_unscaled <- fit$inverse_info_beta / fit$dispersion - - ## TODO: Below fixme? - ## FIXME: There is 1) definitely a better way to do this, 2) no time... - b_vector <- numeric(nvars) - for (j in seq.int(nvars)) { - inverse_info_unscaled_j <- inverse_info_unscaled[j, ] - vcov_j <- tcrossprod(inverse_info_unscaled_j) / inverse_info_unscaled_j[j] - hats_j <- .rowSums((x %*% vcov_j) * x, nobs, nvars, TRUE) * fit$working_weights - b_vector[j] <- inverse_info_unscaled_j %*% .colSums(x * (hats_j * (fit$d1mus * fit$d1varmus / (6 * fit$varmus) - 0.5 * fit$d2mus/fit$d1mus)), nobs, nvars, TRUE) - } - return(.colSums(0.5 * fit$hatvalues * fit$d2mus / fit$d1mus * x, - nobs, nvars, TRUE) + - info_unscaled %*% b_vector) - } - else { - s1 <- sum(weights^3 * fit$d3afuns, na.rm = TRUE) - s2 <- sum(weights^2 * fit$d2afuns, na.rm = TRUE) - return(nvars / (2 * fit$dispersion) + - s1 / (6 * fit$dispersion^2 * s2)) - } - } - - AS_mixed_adjustment <- function(pars, level = 0, fit = NULL) { - if (level == 0) { - ## Use only observations with keep = TRUE to ensure that no division with zero takes place - return(.colSums(0.5 * fit$hatvalues * fit$d2mus/fit$d1mus * x, nobs, nvars, TRUE)) - } - else { - s1 <- sum(weights^3 * fit$d3afuns, na.rm = TRUE) - s2 <- sum(weights^2 * fit$d2afuns, na.rm = TRUE) - return(nvars / (2 * fit$dispersion) + - s1 / (6 * fit$dispersion^2 * s2)) - } - } - - ## compute_step_components does everything on the scale of the /transformed/ dispersion compute_step_components <- function(pars, fit, level = 0) { @@ -602,7 +316,7 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL # Beta components grad <- fit$grad_beta inverse_info <- fit$inverse_info_beta - adjustment <- adjustment_function(pars, fit = fit, level = 0) + adjustment <- adjustment_function(pars, fit = fit, level = 0, x, nobs, nvars, weights) failed_adjustment <- any(is.na(adjustment)) failed_inversion <- FALSE # Already computed successfully @@ -618,7 +332,7 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL grad <- fit$grad_zeta / d1zeta inverse_info <- fit$inverse_info_zeta * d1zeta^2 - adjustment <- adjustment_function(pars, fit = fit, level = 1) / d1zeta - + adjustment <- adjustment_function(pars, fit = fit, level = 1, x, nobs, nvars, weights) / d1zeta - 0.5 * d2zeta / d1zeta^2 failed_inversion <- !is.finite(inverse_info) @@ -846,7 +560,20 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL ) betas <- coef(tempFit) names(betas) <- betas_names - dispList <- estimate_dispersion(betas, y = y) + dispList <- estimate_dispersion(betas = betas, + y = y, + x = x, + weights = weights, + offset = offset, + family = family, + fixed_totals = fixed_totals, + row_totals = row_totals, + no_dispersion = no_dispersion, + nobs = nobs, + nvars = nvars, + keep = keep, + df_residual = df_residual, + control = control) dispersion <- dispList$dispersion if (is.na(dispersion)) dispersion <- var(y)/variance(sum(weights * y)/sum(weights)) dispersion_ML <- dispList$dispersion_ML @@ -862,7 +589,20 @@ brglmFit <- function(x, y, weights = rep(1, nobs), start = NULL, etastart = NULL betas <- betas_all } ## Estimate dispersion based on current value for betas - dispList <- estimate_dispersion(betas, y = y) + dispList <- estimate_dispersion(betas = betas, + y = y, + x = x, + weights = weights, + offset = offset, + family = family, + fixed_totals = fixed_totals, + row_totals = row_totals, + no_dispersion = no_dispersion, + nobs = nobs, + nvars = nvars, + keep = keep, + df_residual = df_residual, + control = control) dispersion <- dispList$dispersion if (is.na(dispersion)) dispersion <- var(y)/variance(sum(weights * y)/sum(weights)) dispersion_ML <- dispList$dispersion_ML @@ -1362,15 +1102,6 @@ vcov.brglmFit <- function(object, model = c("mean", "full", "dispersion"), compl }) } - -DD <- function(expr,name, order = 1) { - if(order < 1) stop("'order' must be >= 1") - if(order == 1) D(expr,name) - else DD(D(expr, name), name, order - 1) -} - - - ## Almost all code in print.summary.brglmFit is from ## stats:::print.summary.glm apart from minor modifications #' @rdname summary.brglmFit From 9ae67faf4014d76dba57088411a7f5ac3678a215 Mon Sep 17 00:00:00 2001 From: Ollie Date: Tue, 2 Dec 2025 13:14:35 +0000 Subject: [PATCH 14/15] Profiling file inclusion --- benchmarks/profiling.R | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 benchmarks/profiling.R diff --git a/benchmarks/profiling.R b/benchmarks/profiling.R new file mode 100644 index 0000000..a0b3ba2 --- /dev/null +++ b/benchmarks/profiling.R @@ -0,0 +1,55 @@ +# Load required packages +library(brglm2) +library(microbenchmark) + +# Load the dataset +data("MultipleFeatures", package = "brglm2") + +# Set up the data and formulas (based on the package documentation) +# Get the fou (Fourier) and kar (Karhunen-Loève) feature names +vars <- grep("fou|kar", names(MultipleFeatures), value = TRUE) + +# Identify training rows +training <- which(MultipleFeatures$training) + +# Center the features on the training set +MultipleFeatures[training, vars] <- scale(MultipleFeatures[training, vars], + scale = FALSE) + +# Create the full model formula (predicting digit 7) +full_mf_fm <- formula(paste("I(digit == 7) ~", paste(vars, collapse = " + "))) + +# ===== PROFILING STARTS HERE ===== + +# 1. Detailed profiling with Rprof +print("\n === Rprof Function Timing (ordered by time) ===") +Rprof("brglm_profile.out", interval = 0.01, memory.profiling = TRUE) +fit <- glm(full_mf_fm, + data = MultipleFeatures, + family = binomial(), + method = brglmFit, + subset = training, + maxit = 200) +Rprof(NULL) + +# Get summary showing functions by total time +prof_summary <- summaryRprof("brglm_profile.out", memory = "both") +print("Top functions by total time:") +print(head(prof_summary$by.total, 20)) +print("\nTop functions by self time (excluding called functions):") +print(head(prof_summary$by.self, 20)) + +# 2. Visual profiling with profvis +print("\n === Memory/Time Profiling with profvis ===") +library(profvis) + +p <- profvis({ + fit <- glm(full_mf_fm, + data = MultipleFeatures, + family = binomial(), + method = brglmFit, + subset = training, + maxit = 200) +}, interval = 0.01) # Smaller interval for more detail + +print(p) \ No newline at end of file From 1ae9e41f79ca0928d0448261086275a22ff5cf8a Mon Sep 17 00:00:00 2001 From: Ollie Date: Wed, 3 Dec 2025 12:41:41 +0000 Subject: [PATCH 15/15] Complete profiling split into main and fit for more specific discovery --- benchmarks/fit_profiling.R | 198 +++++++++++++++++++ benchmarks/{profiling.R => main_profiling.R} | 0 2 files changed, 198 insertions(+) create mode 100644 benchmarks/fit_profiling.R rename benchmarks/{profiling.R => main_profiling.R} (100%) diff --git a/benchmarks/fit_profiling.R b/benchmarks/fit_profiling.R new file mode 100644 index 0000000..1afee9c --- /dev/null +++ b/benchmarks/fit_profiling.R @@ -0,0 +1,198 @@ +# Load required packages +library(brglm2) +library(enrichwith) # Needed for enriching family objects +library(numDeriv) # Needed for numerical derivatives +library(profvis) +library(microbenchmark) + +# Source the helper file to get compute_fit +# Try different paths depending on where script is run from +if (file.exists("R/brglmFit-helper.R")) { + source("R/brglmFit-helper.R") +} else if (file.exists("../R/brglmFit-helper.R")) { + source("../R/brglmFit-helper.R") +} else { + stop("Cannot find brglmFit-helper.R. Please check your working directory.") +} + +# Verify compute_fit is available +if (!exists("compute_fit")) { + stop("compute_fit function not found after sourcing. Check the helper file.") +} + +cat("compute_fit function loaded successfully\n") + +# Load and prepare the dataset (same as your existing script) +data("MultipleFeatures", package = "brglm2") + +vars <- grep("fou|kar", names(MultipleFeatures), value = TRUE) +training <- which(MultipleFeatures$training) +MultipleFeatures[training, vars] <- scale(MultipleFeatures[training, vars], + scale = FALSE) + +# Create the formula and prepare data +full_mf_fm <- formula(paste("I(digit == 7) ~", paste(vars, collapse = " + "))) + +# Prepare inputs for compute_fit (mimicking what brglmFit does) +train_data <- MultipleFeatures[training, ] +y <- as.numeric(train_data$digit == 7) +x <- model.matrix(full_mf_fm, data = train_data) +weights <- rep(1, length(y)) +offset <- rep(0, length(y)) + +# Use enrichment approach (matching brglmFit.R line 426) +family <- enrichwith::enrich(binomial(), with = c("d1afun", "d2afun", "d3afun", "d1variance")) + +# Add d2mu.deta if not already present +if (is.null(family$d2mu.deta)) { + mu.eta <- family$mu.eta + family$d2mu.deta <- function(eta) { + numDeriv::grad(mu.eta, eta) + } +} + +# Get dimensions +nobs <- length(y) +nvars <- ncol(x) +keep <- weights > 0 + +# Get starting values (use a quick ML fit) +ml_fit <- glm(full_mf_fm, + data = train_data, + family = binomial()) + +# Starting parameter vector +pars <- c(coef(ml_fit), 1) # betas + dispersion + +# ===== FOCUSED PROFILING OF compute_fit ===== + +cat("\n=== Profiling compute_fit function ===\n") + +# First, test that compute_fit works outside profvis +cat("\nTesting compute_fit directly...\n") +test_result <- try({ + compute_fit( + pars = pars, + y = y, + x = x, + weights = weights, + offset = offset, + family = family, + fixed_totals = NULL, + row_totals = NULL, + no_dispersion = FALSE, + nobs = nobs, + nvars = nvars, + keep = keep, + need_qr = TRUE, + need_hatvalues = TRUE + ) +}, silent = FALSE) + +if (inherits(test_result, "try-error")) { + cat("\nERROR: compute_fit failed. Error details:\n") + print(test_result) + stop("Cannot proceed with profiling - compute_fit is not working") +} else { + cat("Success! compute_fit executed without errors.\n") + cat("Result class:", class(test_result), "\n") +} + +# 1. Detailed line-by-line profiling with profvis +cat("\n1. Visual profiling with profvis (check browser/viewer)...\n") +p <- profvis({ + for (i in 1:100) { # Run multiple times to get good sampling + fit_result <- compute_fit( + pars = pars, + y = y, + x = x, + weights = weights, + offset = offset, + family = family, + fixed_totals = NULL, + row_totals = NULL, + no_dispersion = FALSE, + nobs = nobs, + nvars = nvars, + keep = keep, + need_qr = TRUE, + need_hatvalues = TRUE + ) + } +}) +print(p) + +htmlwidgets::saveWidget(p, "fit_profile(03.12.25).html") + +# 2. Benchmark different scenarios +cat("\n2. Benchmarking compute_fit under different conditions...\n") + +# Test with QR and hatvalues +bench_full <- microbenchmark( + with_qr_and_hat = compute_fit( + pars = pars, y = y, x = x, weights = weights, offset = offset, + family = family, fixed_totals = NULL, row_totals = NULL, + no_dispersion = FALSE, nobs = nobs, nvars = nvars, keep = keep, + need_qr = TRUE, need_hatvalues = TRUE + ), + with_qr_no_hat = compute_fit( + pars = pars, y = y, x = x, weights = weights, offset = offset, + family = family, fixed_totals = NULL, row_totals = NULL, + no_dispersion = FALSE, nobs = nobs, nvars = nvars, keep = keep, + need_qr = TRUE, need_hatvalues = FALSE + ), + no_qr = compute_fit( + pars = pars, y = y, x = x, weights = weights, offset = offset, + family = family, fixed_totals = NULL, row_totals = NULL, + no_dispersion = FALSE, nobs = nobs, nvars = nvars, keep = keep, + need_qr = FALSE, need_hatvalues = FALSE + ), + times = 50 +) +print(bench_full) + +# 3. Detailed Rprof for function-level timing +cat("\n3. Function-level profiling with Rprof...\n") +Rprof("compute_fit_profile.out", interval = 0.001, line.profiling = TRUE) +for (i in 1:200) { + fit_result <- compute_fit( + pars = pars, y = y, x = x, weights = weights, offset = offset, + family = family, fixed_totals = NULL, row_totals = NULL, + no_dispersion = FALSE, nobs = nobs, nvars = nvars, keep = keep, + need_qr = TRUE, need_hatvalues = TRUE + ) +} +Rprof(NULL) + +prof_summary <- summaryRprof("compute_fit_profile.out", lines = "both") +cat("\nTop functions by total time:\n") +print(head(prof_summary$by.total, 20)) +cat("\nTop functions by self time:\n") +print(head(prof_summary$by.self, 20)) + +if (!is.null(prof_summary$by.line)) { + cat("\nTop lines by total time:\n") + print(head(prof_summary$by.line$line.out, 30)) +} + +# 4. Memory profiling +cat("\n4. Memory profiling...\n") +Rprof("compute_fit_memory.out", memory.profiling = TRUE) +for (i in 1:100) { + fit_result <- compute_fit( + pars = pars, y = y, x = x, weights = weights, offset = offset, + family = family, fixed_totals = NULL, row_totals = NULL, + no_dispersion = FALSE, nobs = nobs, nvars = nvars, keep = keep, + need_qr = TRUE, need_hatvalues = TRUE + ) +} +Rprof(NULL) + +mem_summary <- summaryRprof("compute_fit_memory.out", memory = "both") +cat("\nMemory usage by function:\n") +print(head(mem_summary$by.total, 15)) + +cat("\n=== Profiling complete ===\n") +cat("Profile output files created:\n") +cat(" - compute_fit_profile.out (detailed timing)\n") +cat(" - compute_fit_memory.out (memory usage)\n") \ No newline at end of file diff --git a/benchmarks/profiling.R b/benchmarks/main_profiling.R similarity index 100% rename from benchmarks/profiling.R rename to benchmarks/main_profiling.R