From 61f0ec9bf268541abcd1f8a62aa12dd9222a5a4b Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Tue, 28 Apr 2026 17:13:49 +0800 Subject: [PATCH 01/25] add everything --- NAMESPACE | 1 + R/objectives.R | 301 ++++++++++++++++++++++++++++ man/calc_concurrence_matrix.Rd | 15 ++ man/calc_incidence_matrix.Rd | 11 + man/calc_info_matrix.Rd | 16 ++ man/calculate_efficiency_factors.Rd | 16 ++ man/compute_L_projection.Rd | 11 + man/dot-build_L_from_df.Rd | 16 ++ man/dot-build_treatment_matrix.Rd | 11 + man/objective_function_info.Rd | 39 ++++ 10 files changed, 437 insertions(+) create mode 100644 R/objectives.R create mode 100644 man/calc_concurrence_matrix.Rd create mode 100644 man/calc_incidence_matrix.Rd create mode 100644 man/calc_info_matrix.Rd create mode 100644 man/calculate_efficiency_factors.Rd create mode 100644 man/compute_L_projection.Rd create mode 100644 man/dot-build_L_from_df.Rd create mode 100644 man/dot-build_treatment_matrix.Rd create mode 100644 man/objective_function_info.Rd diff --git a/NAMESPACE b/NAMESPACE index 889d8fa5..c4c819e2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,6 +16,7 @@ export(initialise_design_df) export(initialize_design_df) export(objective_function) export(objective_function_factorial) +export(objective_function_info) export(objective_function_piepho) export(objective_function_signature) export(optim_params) diff --git a/R/objectives.R b/R/objectives.R new file mode 100644 index 00000000..1e3701f3 --- /dev/null +++ b/R/objectives.R @@ -0,0 +1,301 @@ +#' Objective function using the treatment information matrix +#' +#' Creates an objective function that optimises experimental designs using the +#' Fisher information for treatment contrasts after adjusting for nuisance +#' effects, and takes an optional spatial covariance structure for spatial +#' optimisation. +#' +#' @param design Data frame representing the spatial layout of the experiment. +#' @param swap Column name to swap, usually the treatment. +#' @param spatial_cols Column name of the spatial factors. +#' @param row_col Column name of the design's rows +#' @param range_col Column name of the design's range +#' @param criterion Either \code{"A"} or \code{"D"}, representing A or D +#' optimality. +#' - A-optimality: Minimises \eqn{\mathrm{tr} \left( A^- \right)}{Sigma^(-1)}. +#' - D-optimality: Minimises \eqn{-\log \left| I \right|} +#' @param L_matrix Precomputed projection matrix. Use +#' \code{precompute_projection} to generate it. If \code{NULL}, then the +#' identity covariance structure will be assumed, and the projection will be +#' computed using the structure of the design's blocks. +#' @param block_col Column name of the design's block factor. Used when +#' \code{L_matrix} isn't supplied. +#' +#' @details +#' This function computes the treatment information matrix: +#' +#' +#' @export +objective_function_info <- function( + design, + swap, + spatial_cols, + row_col = "row", + range_col = "range", + criterion = c("A", "D"), + L_matrix = NULL, + block_col = "block", + ... +) { + criterion <- match.arg(criterion) + + ## a lot of the args come from the design now + treatments <- design[[swap]] + trt_levels <- levels(factor(treatments)) + v <- length(trt_levels) + n <- nrow(design) + + ## L + ### projection matrix + if (is.null(L_matrix)) { + L_matrix <- .build_L_from_df(design, block_col, n) + } + + ## X1 + ### treatment design matrix. + X1 <- .build_treatment_matrix(treatments, trt_levels, n, v) + + ## information matrix I = X1t L X1 + info <- t(X1) %*% L_matrix %*% X1 + + ## get positive eigenvals from info matrix + eig <- eigen(info, symmetric = TRUE, only.values = TRUE)$values + pos_eig <- eig[eig > 1e-10] + + ## if design is disconnected, penalise greatly + ## otherwise A or D + if (length(pos_eig) < v - 1) { + score <- Inf + } else { + score <- switch(criterion, + A = sum(1 / pos_eig), + D = -sum(log(pos_eig)) + ) + } + + return(list( + score = score, + info_matrix = info, + eigenvalues = sort(pos_eig, decreasing = TRUE), + criterion = criterion + )) +} + +#' Build the treatment indicator matrix X1 +.build_treatment_matrix <- function(treatments, trt_levels, n, v) { + X1 <- matrix(0, n, v) + trt_idx <- match(treatments, trt_levels) + for (i in seq_len(n)) { + X1[i, trt_idx[i]] <- 1 + } + return(X1) +} + +#' Function to precompute \eqn{L} +#' +#' \eqn{L} is the projection matrix that removes nuisance effects under a +#' spatial correlation structure, given an \eqn{n \times n}{n * n} covariance +#' \eqn{\Sigma}{Sigma} and nuisance effects design \eqn{X_2}. +#' +#' This only depends on lambda and the block structure, so precompute this. +.build_L_from_df <- function(design, block_col, n) { + if (!block_col %in% names(design)) { + ## L = I - (1/n) ones_matrix + return(diag(n) - matrix(1 / n, n, n)) + } + + blocks <- factor(design[[block_col]]) + b <- nlevels(blocks) + + X2 <- matrix(0, n, b) + for (j in seq_len(b)) { + X2[blocks == levels(blocks)[j], j] <- 1 + } + + ## L = I - X2 (X2t X2)^{-1} X2t + X2tX2_inv <- diag(1 / colSums(X2), nrow = b) + diag(n) - X2 %*% X2tX2_inv %*% t(X2) +} + + +# Helper functions + +#' Compute L projection +compute_L_projection <- function(design, Sigma, block_col = "block") { + n <- nrow(design) + + ## arg checks + if (!is.matrix(Sigma)) stop("Sigma must be a matrix") + if (nrow(Sigma) != n) stop("Sigma matrix must have dimension equal to dimension of design dataframe") + if (ncol(Sigma) != n) stop("Sigma matrix must have dimension equal to dimension of design dataframe") + if (!isSymmetric(Sigma, tol = 1e-8)) stop("Sigma must be symmetric") + if (!(block_col %in% names(design))) stop("Block column name not in design dataframe") + + blocks <- factor(design[[block_col]]) + b <- nlevels(blocks) + + ## X2 + ### block indicator matrix with the intercept removed + X2 <- matrix(0, n, b) + for (j in seq_len(b)) { + X2[blocks == levels(blocks)[j], j] <- 1 + } + + Sigma_inv <- solve(Sigma) + SiX2 <- Sigma_inv %*% X2 + return(Sigma_inv - SiX2 %*% solve(t(X2) %*% SiX2) %*% t(SiX2)) +} + +#' Calculate info matrix +calc_info_matrix <- function( + design, + treatment_col = "treatment", + L_matrix = NULL, + block_col = "block" +) { + treatments <- design[[treatment_col]] + trt_levels <- levels(factor(treatments)) + v <- length(trt_levels) + n <- nrow(design) + + # TODO: Duplicated from above. Probably try and simplify later + ## L + ### projection matrix + if (is.null(L_matrix)) { + L_matrix <- .build_L_from_df(design, block_col, n) + } + + ## X1 + ### treatment design matrix. + X1 <- .build_treatment_matrix(treatments, trt_levels, n, v) + + ## information matrix I = X1t L X1 + info <- t(X1) %*% L_matrix %*% X1 + + rownames(info) <- trt_levels + colnames(info) <- trt_levels + + ## get positive eigenvals from info matrix + eig <- eigen(info, symmetric = TRUE, only.values = TRUE)$values + pos_eig <- eig[eig > 1e-10] + + ## if design is disconnected, penalise greatly + ## otherwise A or D + if (length(pos_eig) < v - 1) { + A_val <- Inf + D_val <- Inf + } else { + A_val = sum(1 / pos_eig) + D_val = -sum(log(pos_eig)) + } + + return(list( + info_matrix = info, + eigenvalues = sort(pos_eig, decreasing = TRUE), + rank = length(pos_eig), + A_value = A_val, + D_value = D_val + )) +} + +#' Calculate incidence matrix +calc_incidence_matrix <- function( + design, + treatment_col = "treatment", + block_col = "block" +) { + treatments <- factor(design[[treatment_col]]) + blocks <- factor(design[[block_col]]) + + ## make a matrix of integers + N <- table(treatments, blocks) + class(N) <- "matrix" + storage.mode(N) <- "integer" + + return(N) +} + +#' Calculate concurrence matrix +calc_concurrence_matrix <- function( + design, + treatment_col = "treatment", + block_col = "block" +) { + N <- calc_incidence_matrix(design, treatment_col, block_col) + C <- N %*% t(N) + storage.mode(C) <- "integer" + return(C) +} + +#' Calculate canonical efficiency factors +calculate_efficiency_factors <- function( + design, + treatment_col = "treatment", + L_matrix = NULL, + block_col = "block" +) { + info <- calc_info_matrix( + design, + treatment_col, + L_matrix, + block_col + ) + + treatments <- factor(design[[treatment_col]]) + reps <- table(treatments) + r_bar <- mean(reps) + + eff_factors <- info$eigenvalues / r_bar + + v <- nlevels(treatments) + E <- if (info$rank >= v - 1) { + (v - 1) / sum(1 / eff_factors) + } else { + NA_real_ + } + + list( + efficiency_factors = eff_factors, + E = E, + replication = setNames(as.integer(reps), levels(treatments)) + ) +} + + +## Convenience correlation structure constructors +cor_ar1 <- function(n, rho) { + rho^abs(outer(seq_len(n), seq_len(n), "-")) +} + +cor_ar1_ar1 <- function(n_rows, n_cols, rho_row, rho_col) { + kronecker( + cor_ar1(n_rows, rho_row), + cor_ar1(n_cols, rho_col) + ) +} + + +## Testing +set.seed(1) +n_treatments <- 4 +n_blocks <- 3 + +df <- data.frame( + row = rep(1:n_blocks, each = n_treatments), + col = rep(1:n_treatments, times = n_blocks), + block = rep(1:n_blocks, each = n_treatments), + treatment = NA_character_ +) + +scores <- numeric(20) +for (i in seq_len(20)) { + for (b in 1:n_blocks) { + idx <- df$block == b + df$treatment[idx] <- paste0("T", sample(n_treatments)) + } + result <- objective_function_info( + df, swap = "treatment", spatial_cols = c("row", "col"), + criterion = "A" + ) + scores[i] <- result$score +} diff --git a/man/calc_concurrence_matrix.Rd b/man/calc_concurrence_matrix.Rd new file mode 100644 index 00000000..308cae3d --- /dev/null +++ b/man/calc_concurrence_matrix.Rd @@ -0,0 +1,15 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/objectives.R +\name{calc_concurrence_matrix} +\alias{calc_concurrence_matrix} +\title{Calculate concurrence matrix} +\usage{ +calc_concurrence_matrix( + design, + treatment_col = "treatment", + block_col = "block" +) +} +\description{ +Calculate concurrence matrix +} diff --git a/man/calc_incidence_matrix.Rd b/man/calc_incidence_matrix.Rd new file mode 100644 index 00000000..6bf2ddb7 --- /dev/null +++ b/man/calc_incidence_matrix.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/objectives.R +\name{calc_incidence_matrix} +\alias{calc_incidence_matrix} +\title{Calculate incidence matrix} +\usage{ +calc_incidence_matrix(design, treatment_col = "treatment", block_col = "block") +} +\description{ +Calculate incidence matrix +} diff --git a/man/calc_info_matrix.Rd b/man/calc_info_matrix.Rd new file mode 100644 index 00000000..120ee048 --- /dev/null +++ b/man/calc_info_matrix.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/objectives.R +\name{calc_info_matrix} +\alias{calc_info_matrix} +\title{Calculate info matrix} +\usage{ +calc_info_matrix( + design, + treatment_col = "treatment", + L_matrix = NULL, + block_col = "block" +) +} +\description{ +Calculate info matrix +} diff --git a/man/calculate_efficiency_factors.Rd b/man/calculate_efficiency_factors.Rd new file mode 100644 index 00000000..fc3a1b93 --- /dev/null +++ b/man/calculate_efficiency_factors.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/objectives.R +\name{calculate_efficiency_factors} +\alias{calculate_efficiency_factors} +\title{Calculate canonical efficiency factors} +\usage{ +calculate_efficiency_factors( + design, + treatment_col = "treatment", + L_matrix = NULL, + block_col = "block" +) +} +\description{ +Calculate canonical efficiency factors +} diff --git a/man/compute_L_projection.Rd b/man/compute_L_projection.Rd new file mode 100644 index 00000000..6dc43531 --- /dev/null +++ b/man/compute_L_projection.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/objectives.R +\name{compute_L_projection} +\alias{compute_L_projection} +\title{Compute L projection} +\usage{ +compute_L_projection(design, Sigma, block_col = "block") +} +\description{ +Compute L projection +} diff --git a/man/dot-build_L_from_df.Rd b/man/dot-build_L_from_df.Rd new file mode 100644 index 00000000..7b0b3794 --- /dev/null +++ b/man/dot-build_L_from_df.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/objectives.R +\name{.build_L_from_df} +\alias{.build_L_from_df} +\title{Function to precompute \eqn{L}} +\usage{ +.build_L_from_df(design, block_col, n) +} +\description{ +\eqn{L} is the projection matrix that removes nuisance effects under a +spatial correlation structure, given an \eqn{n \times n}{n * n} covariance +\eqn{\Sigma}{Sigma} and nuisance effects design \eqn{X_2}. +} +\details{ +This only depends on lambda and the block structure, so precompute this. +} diff --git a/man/dot-build_treatment_matrix.Rd b/man/dot-build_treatment_matrix.Rd new file mode 100644 index 00000000..c7853821 --- /dev/null +++ b/man/dot-build_treatment_matrix.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/objectives.R +\name{.build_treatment_matrix} +\alias{.build_treatment_matrix} +\title{Build the treatment indicator matrix X1} +\usage{ +.build_treatment_matrix(treatments, trt_levels, n, v) +} +\description{ +Build the treatment indicator matrix X1 +} diff --git a/man/objective_function_info.Rd b/man/objective_function_info.Rd new file mode 100644 index 00000000..0642a50d --- /dev/null +++ b/man/objective_function_info.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/objectives.R +\name{objective_function_info} +\alias{objective_function_info} +\title{Objective function using the treatment information matrix} +\usage{ +objective_function_info( + design, + swap, + spatial_cols, + current_score_obj = NULL, + swapped_items = NULL, + row_col = "row", + col_col = "col", + criterion = c("A", "D"), + L_matrix = NULL, + block_col = "block", + ... +) +} +\arguments{ +\item{design}{Data frame representing the spatial layout of the experiment.} + +\item{swap}{Column name to swap, usually the treatment.} + +\item{spatial_cols}{Column name of the spatial factors. + +Information matrix based objectives +\itemize{ +\item A-optimality: \eqn{\mathrm{tr} \left( A^- \right)}{Sigma^(-1)} +\item D-optimality: \eqn{-\log \left| I \right|} +}} +} +\description{ +Creates an objective function that optimises experimental designs using the +Fisher information for treatment contrasts after adjusting for nuisance +effects, and takes an optional spatial covariance structure for spatial +optimisation. +} From 7efaf560bbbc7b5302b4bbc88381d41b01fc5a6c Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Thu, 30 Apr 2026 12:01:20 +0800 Subject: [PATCH 02/25] update tests and add some comments --- tests/testthat/test-objective_function_info.R | 317 ++++++++++++++++++ 1 file changed, 317 insertions(+) create mode 100644 tests/testthat/test-objective_function_info.R diff --git a/tests/testthat/test-objective_function_info.R b/tests/testthat/test-objective_function_info.R new file mode 100644 index 00000000..6a64ed65 --- /dev/null +++ b/tests/testthat/test-objective_function_info.R @@ -0,0 +1,317 @@ +# tests/testthat/test-objective_function_info.R + +# ---- objective_function_info + +# all RCBDs are equally optimal +test_that("all valid RCBD randomisations produce the same score under identity covariance", { + set.seed(1) + n_treatments <- 4 + n_blocks <- 3 + + df <- data.frame( + row = rep(1:n_blocks, each = n_treatments), + col = rep(1:n_treatments, times = n_blocks), + block = rep(1:n_blocks, each = n_treatments), + treatment = NA_character_ + ) + + scores <- numeric(20) + for (i in seq_len(20)) { + for (b in 1:n_blocks) { + idx <- df$block == b + df$treatment[idx] <- paste0("T", sample(n_treatments)) + } + result <- objective_function_info( + df, swap = "treatment", spatial_cols = c("row", "col"), + criterion = "A" + ) + scores[i] <- result$score + } + + expect_true(max(scores) - min(scores) < 1e-10) +}) + +# when there IS spatial correlation, two different arrangements of the same +# treatments must give different scores. df1 should be worse, since treatments +# are always in the same column position, but in df2 they're "randomised". +test_that("spatial designs differentiate between arrangements", { + n_treatments <- 4 + n_blocks <- 3 + + df <- data.frame( + row = rep(1:n_blocks, each = n_treatments), + col = rep(1:n_treatments, times = n_blocks), + block = rep(1:n_blocks, each = n_treatments) + ) + + Sigma <- cor_ar1_ar1(n_blocks, n_treatments, rho_row = 0.7, rho_col = 0.5) + L <- compute_L_projection(df, Sigma, block_col = "block") + + # Same treatment ordering in every block + df1 <- df + df1$treatment <- rep(paste0("T", 1:n_treatments), n_blocks) + + # Alternated ordering + df2 <- df + df2$treatment <- c( + paste0("T", c(1, 2, 3, 4)), + paste0("T", c(3, 4, 1, 2)), + paste0("T", c(4, 3, 2, 1)) + ) + + s1 <- objective_function_info( + df1, "treatment", c("row", "col"), + criterion = "A", L_matrix = L + )$score + + s2 <- objective_function_info( + df2, "treatment", c("row", "col"), + criterion = "A", L_matrix = L + )$score + + expect_false(abs(s1 - s2) < 1e-10) +}) + +# just make sure this works lel +test_that("D-optimality criterion works", { + df <- data.frame( + row = rep(1:3, each = 4), + col = rep(1:4, times = 3), + block = rep(1:3, each = 4), + treatment = rep(paste0("T", 1:4), 3) + ) + + result <- objective_function_info( + df, "treatment", c("row", "col"), + criterion = "D" + ) + + expect_true(is.finite(result$score)) + expect_equal(result$criterion, "D") + expect_equal(length(result$eigenvalues), 3) # v - 1 +}) + +# if treatments never exist in the same block together, you cant compare them, +# so the design is fully broken +test_that("disconnected designs return Inf", { + df <- data.frame( + row = 1:6, + col = c(1, 2, 1, 2, 1, 2), + block = c(1, 1, 2, 2, 3, 3), + treatment = c("A", "A", "B", "B", "C", "C") + ) + + result <- objective_function_info( + df, "treatment", c("row", "col"), + criterion = "A" + ) + + expect_equal(result$score, Inf) +}) + + +# ---- compute_L_projection + +# input validation test +test_that("compute_L_projection validates inputs", { + df <- data.frame( + row = 1:4, col = 1:4, block = c(1, 1, 2, 2), + treatment = c("A", "B", "A", "B") + ) + + # Wrong dimensions + expect_error(compute_L_projection(df, diag(3))) + + # Not symmetric + expect_error(compute_L_projection(df, matrix(1:16, 4, 4))) + + # Missing block column + expect_error(compute_L_projection(df, diag(4), block_col = "nonexistent")) +}) + +# identity sigma should be the default L projection. i.e. spatial optimisation +# with identity correlation is the same as non-spatial +test_that("L with identity Sigma matches .build_L_from_df", { + df <- data.frame( + row = rep(1:3, each = 4), + col = rep(1:4, times = 3), + block = rep(1:3, each = 4), + treatment = rep(paste0("T", 1:4), 3) + ) + + L_spatial <- compute_L_projection(df, diag(12), block_col = "block") + L_direct <- .build_L_from_df(df, "block", 12) + + expect_true(max(abs(L_spatial - L_direct)) < 1e-10) +}) + + +# ---- calc_info_matrix + +# balanced RCBD should have rank = v - 1 +test_that("info matrix for RCBD has correct properties", { + df <- data.frame( + row = rep(1:3, each = 5), + col = rep(1:5, times = 3), + block = rep(1:3, each = 5), + treatment = rep(paste0("T", 1:5), 3) + ) + + info <- calc_info_matrix(df) + + # v = 5, so rank = v - 1 = 4 + expect_equal(info$rank, 4) + + # For balanced RCBD all non-zero eigenvalues = b = 3 + expect_true(all(abs(info$eigenvalues - 3) < 1e-10)) + + # 5x5 matrix + expect_equal(dim(info$info_matrix), c(5, 5)) + + # Named + expect_equal(rownames(info$info_matrix), paste0("T", 1:5)) + expect_equal(colnames(info$info_matrix), paste0("T", 1:5)) +}) + + +# spatial should always be different to non-spatial +test_that("spatial info matrix differs from non-spatial", { + df <- data.frame( + row = rep(1:3, each = 4), + col = rep(1:4, times = 3), + block = rep(1:3, each = 4), + treatment = rep(paste0("T", 1:4), 3) + ) + + Sigma <- cor_ar1_ar1(3, 4, 0.5, 0.3) + L <- compute_L_projection(df, Sigma) + + info_plain <- calc_info_matrix(df) + info_spatial <- calc_info_matrix(df, L_matrix = L) + + expect_false( + all(abs(info_plain$eigenvalues - info_spatial$eigenvalues) < 1e-10) + ) +}) + +# disconnected design should give invalid criteria +test_that("disconnected design gives Inf for A and D values", { + df <- data.frame( + row = 1:6, + col = c(1, 2, 1, 2, 1, 2), + block = c(1, 1, 2, 2, 3, 3), + treatment = c("A", "A", "B", "B", "C", "C") + ) + + info <- calc_info_matrix(df) + + expect_equal(info$A_value, Inf) + expect_equal(info$D_value, Inf) +}) + + +# ---- calc_incidence_matrix + +# complete design should have all incidence matrix entries = 1 +# should also encode replication (rows) and block size (cols) +test_that("incidence matrix has correct dimensions and values for RCBD", { + df <- data.frame( + row = rep(1:3, each = 4), + col = rep(1:4, times = 3), + block = rep(1:3, each = 4), + treatment = rep(paste0("T", 1:4), 3) + ) + + N <- calc_incidence_matrix(df) + + expect_equal(dim(N), c(4, 3)) # v x b + expect_true(all(N == 1)) # complete blocks + expect_true(all(rowSums(N) == 3)) # replication = b + expect_true(all(colSums(N) == 4)) # block size = v +}) + +# ensure incidence works fine for imbalanced designs +test_that("incidence matrix handles unequal replication", { + df <- data.frame( + row = 1:5, + col = c(1, 2, 1, 2, 1), + block = c(1, 1, 2, 2, 2), + treatment = c("A", "B", "A", "B", "A") + ) + + N <- calc_incidence_matrix(df) + + expect_equal(dim(N), c(2, 2)) + expect_equal(sum(N["A", ]), 3) # A appears 3 times + expect_equal(sum(N["B", ]), 2) # B appears 2 times +}) + +# ---- calc_concurrence_matrix + +# balanced RCBD with N all = 1, N Nt should have entries equal to block number +test_that("concurrence matrix is correct for RCBD", { + df <- data.frame( + row = rep(1:3, each = 4), + col = rep(1:4, times = 3), + block = rep(1:3, each = 4), + treatment = rep(paste0("T", 1:4), 3) + ) + + C <- calc_concurrence_matrix(df) + + expect_equal(dim(C), c(4, 4)) + expect_true(all(C == 3)) +}) + + +# ---- calculate_efficiency_factors + +# balanced RCBD has all efficiency factors = 1 +test_that("efficiency factors are 1 for complete blocks", { + df <- data.frame( + row = rep(1:4, each = 5), + col = rep(1:5, times = 4), + block = rep(1:4, each = 5), + treatment = rep(paste0("T", 1:5), 4) + ) + + info <- calc_info_matrix(df) + treatments <- factor(df$treatment) + r_bar <- mean(table(treatments)) + eff <- info$eigenvalues / r_bar + + expect_true(all(abs(eff - 1) < 1e-10)) +}) + + +# ---- correlation constructors + +# make sure ar1 builder works fine +test_that("cor_ar1 produces valid correlation matrix", { + R <- cor_ar1(5, 0.7) + + expect_equal(dim(R), c(5, 5)) + expect_true(isSymmetric(R)) + expect_true(all(diag(R) == 1)) + expect_true(all(eigen(R, only.values = TRUE)$values > 0)) + + # Check specific entries + expect_equal(R[1, 2], 0.7) + expect_equal(R[1, 3], 0.7^2) + expect_equal(R[1, 5], 0.7^4) +}) + +# yes +test_that("cor_ar1 with rho = 0 gives identity", { + expect_equal(cor_ar1(4, 0), diag(4)) +}) + +# make sure ar1 x ar1 builder works fine +test_that("cor_ar1_ar1 has correct dimensions and is valid", { + Sigma <- cor_ar1_ar1(3, 5, 0.6, 0.4) + + expect_equal(dim(Sigma), c(15, 15)) + expect_true(isSymmetric(Sigma)) + expect_true(all(diag(Sigma) == 1)) + expect_true(all(eigen(Sigma, only.values = TRUE)$values > 0)) +}) From d827d90a29163ad834fe9d1eb4a7be079e44e748 Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Thu, 30 Apr 2026 12:03:22 +0800 Subject: [PATCH 03/25] add Kai and Curtin Uni to the description --- DESCRIPTION | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index df08a3a2..fc034de1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,7 +2,7 @@ Type: Package Package: speed Title: Generate Spatially Efficient Experimental Designs Version: 0.0.6 -Authors@R: +Authors@R: c(person(given = "Sam", family = "Rogers", role = c("aut", "cre"), @@ -19,31 +19,39 @@ Authors@R: family = "Pipattungsakul", role = "aut", email = "wasin.pipattungsakul@adelaide.edu.au"), + person(given = "Kai", + family = "Bagley", + email = "kai.bagley@curtin.edu.au", + role = "aut", + comment = c(ORCID = "0009-0004-6579-6959")), person(given = "University of Adelaide", role = c("cph", "fnd"), comment = "https://adelaide.edu.au/"), person(given = "Grains Research and Development Corporation", role = c("cph", "fnd"), - comment = "https://grdc.com.au/")) -Description: The Speed package optimises spatial experimental designs by rearranging - treatments to improve statistical efficiency while maintaining statistical validity. - It employs customisable optimisation metrics, with a default approach that balances - minimising treatment adjacency and maintaining spatial balance. Users can supply their - own optimisation metrics to tailor designs to specific experimental requirements. - The package also includes visualisation tools that allow users to inspect + comment = "https://grdc.com.au/") + person(given = "Curtin University", + role = c("cph"), + comment = c("http://www.curtin.edu.au/", ROR = "02n415q13"))) +Description: The Speed package optimises spatial experimental designs by rearranging + treatments to improve statistical efficiency while maintaining statistical validity. + It employs customisable optimisation metrics, with a default approach that balances + minimising treatment adjacency and maintaining spatial balance. Users can supply their + own optimisation metrics to tailor designs to specific experimental requirements. + The package also includes visualisation tools that allow users to inspect optimised designs. License: MIT + file LICENSE URL: https://biometryhub.github.io/speed/ BugReports: https://github.com/biometryhub/speed/issues Depends: R (>= 4.1) -Imports: +Imports: farver, ggplot2, matrixStats, rlang, scales, stringi -Suggests: +Suggests: igraph, patchwork, quarto, From d678f00239525bf2ecbb435934c34a6c25715e69 Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Thu, 30 Apr 2026 12:45:40 +0800 Subject: [PATCH 04/25] update roxygen2 stuff for exported functions --- DESCRIPTION | 2 +- R/objectives.R | 76 +++++++++++++++++++++++++++++++--- man/objective_function_info.Rd | 31 ++++++++++---- man/speed-package.Rd | 2 + 4 files changed, 95 insertions(+), 16 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fc034de1..40387602 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,7 +29,7 @@ Authors@R: comment = "https://adelaide.edu.au/"), person(given = "Grains Research and Development Corporation", role = c("cph", "fnd"), - comment = "https://grdc.com.au/") + comment = "https://grdc.com.au/"), person(given = "Curtin University", role = c("cph"), comment = c("http://www.curtin.edu.au/", ROR = "02n415q13"))) diff --git a/R/objectives.R b/R/objectives.R index 1e3701f3..2e06dc17 100644 --- a/R/objectives.R +++ b/R/objectives.R @@ -8,12 +8,10 @@ #' @param design Data frame representing the spatial layout of the experiment. #' @param swap Column name to swap, usually the treatment. #' @param spatial_cols Column name of the spatial factors. -#' @param row_col Column name of the design's rows -#' @param range_col Column name of the design's range #' @param criterion Either \code{"A"} or \code{"D"}, representing A or D #' optimality. -#' - A-optimality: Minimises \eqn{\mathrm{tr} \left( A^- \right)}{Sigma^(-1)}. -#' - D-optimality: Minimises \eqn{-\log \left| I \right|} +#' - A-optimality: Minimises \eqn{\mathrm{tr} \left( \mathcal{I}^- \right)}{tr(I⁻)}. +#' - D-optimality: Minimises \eqn{-\log \left| \mathcal{I} \right|}{-log(|I|)} #' @param L_matrix Precomputed projection matrix. Use #' \code{precompute_projection} to generate it. If \code{NULL}, then the #' identity covariance structure will be assumed, and the projection will be @@ -23,7 +21,14 @@ #' #' @details #' This function computes the treatment information matrix: -#' +#' \deqn{I = X_1^\intercal L X_1}{I = X₁ᵀ L X₁} +#' Where \eqn{X_1}{X₁} is the treatment design matrix, and \eqn{L} is the +#' projection that removes nuisance fixed effects from the GLS's inverse +#' covariance: +#' \deqn{L = \Sigma^{-1} - \Sigma^{-1} X_2 \left( X_2^\intercal \Sigma^{-1} X_2 \right)^{-1}}{L = Σ⁻¹ - Σ⁻¹ X₂ (X₂ᵀ Σ⁻¹ X₂)⁻¹} +#' The user specifies the spatial covariance \eqn{\Sigma}{Σ} they intend to use +#' at the time of analysis, e.g. autoregressive-lag-1 \eqn{\text{AR}_1 \otimes \text{AR}_1}{AR₁ ⊗ AR₁}, +#' and this objective will optimise under that structure. #' #' @export objective_function_info <- function( @@ -121,6 +126,15 @@ objective_function_info <- function( # Helper functions #' Compute L projection +#' +#' This is the projection matrix that removes nuisance effects from the GLS's +#' covariance +#' +#' @param design Data frame representing the spatial layout of the experiment. +#' @param Sigma Covariance structure to use. +#' @param block_col Column name of the design's block factor in \code{design}. +#' +#' @export compute_L_projection <- function(design, Sigma, block_col = "block") { n <- nrow(design) @@ -147,6 +161,17 @@ compute_L_projection <- function(design, Sigma, block_col = "block") { } #' Calculate info matrix +#' +#' Calculate the Fisher information in the experimental design +#' +#' @param design Data frame representing the spatial layout of the experiment. +#' @param treatment_col Column name containing the design's treatments in +#' \code{design}. +#' @param L_matrix Precomputed projection matrix from +#' \code{compute_L_projection}. +#' @param block_col Column name containing the designs block in \code{design}. +#' +#' @export calc_info_matrix <- function( design, treatment_col = "treatment", @@ -199,6 +224,13 @@ calc_info_matrix <- function( } #' Calculate incidence matrix +#' +#' @param design Data frame representing the spatial layout of the experiment. +#' @param treatment_col Column name containing the design's treatments in +#' \code{design}. +#' @param block_col Column name containing the designs block in \code{design}. +#' +#' @export calc_incidence_matrix <- function( design, treatment_col = "treatment", @@ -216,6 +248,13 @@ calc_incidence_matrix <- function( } #' Calculate concurrence matrix +#' +#' @param design Data frame representing the spatial layout of the experiment. +#' @param treatment_col Column name containing the design's treatments in +#' \code{design}. +#' @param block_col Column name containing the designs block in \code{design}. +#' +#' @export calc_concurrence_matrix <- function( design, treatment_col = "treatment", @@ -228,6 +267,15 @@ calc_concurrence_matrix <- function( } #' Calculate canonical efficiency factors +#' +#' @param design Data frame representing the spatial layout of the experiment. +#' @param treatment_col Column name containing the design's treatments in +#' \code{design}. +#' @param L_matrix Precomputed projection matrix from +#' \code{compute_L_projection}. +#' @param block_col Column name containing the designs block in \code{design}. +#' +#' @export calculate_efficiency_factors <- function( design, treatment_col = "treatment", @@ -262,11 +310,27 @@ calculate_efficiency_factors <- function( } -## Convenience correlation structure constructors +# Convenience correlation structure constructors + +#' Construct a 1 dimensional lag-1 autoregressive covariance +#' +#' @param n Size of the covariance vector to generate +#' @param rho Correlation parameter +#' +#' @export cor_ar1 <- function(n, rho) { rho^abs(outer(seq_len(n), seq_len(n), "-")) } + +#' Construct a 2 dimensional lag-1 autoregressive covariance +#' +#' @param n_rows Number of rows in the design. +#' @param n_cols Number of columns in the design. +#' @param rho_row Correlation parameter along the row direction. +#' @param rho_col Correlation parameter along the column direction. +#' +#' @export cor_ar1_ar1 <- function(n_rows, n_cols, rho_row, rho_col) { kronecker( cor_ar1(n_rows, rho_row), diff --git a/man/objective_function_info.Rd b/man/objective_function_info.Rd index 0642a50d..a884b945 100644 --- a/man/objective_function_info.Rd +++ b/man/objective_function_info.Rd @@ -8,10 +8,8 @@ objective_function_info( design, swap, spatial_cols, - current_score_obj = NULL, - swapped_items = NULL, row_col = "row", - col_col = "col", + range_col = "range", criterion = c("A", "D"), L_matrix = NULL, block_col = "block", @@ -23,13 +21,24 @@ objective_function_info( \item{swap}{Column name to swap, usually the treatment.} -\item{spatial_cols}{Column name of the spatial factors. +\item{spatial_cols}{Column name of the spatial factors.} -Information matrix based objectives -\itemize{ -\item A-optimality: \eqn{\mathrm{tr} \left( A^- \right)}{Sigma^(-1)} -\item D-optimality: \eqn{-\log \left| I \right|} -}} +\item{row_col}{Column name of the design's rows} + +\item{range_col}{Column name of the design's range} + +\item{criterion}{Either \code{"A"} or \code{"D"}, representing A or D +optimality. +- A-optimality: Minimises \eqn{\mathrm{tr} \left( A^- \right)}{tr(A^-)}. +- D-optimality: Minimises \eqn{-\log \left| I \right|}{-log(det(I))}} + +\item{L_matrix}{Precomputed projection matrix. Use +\code{precompute_projection} to generate it. If \code{NULL}, then the +identity covariance structure will be assumed, and the projection will be +computed using the structure of the design's blocks.} + +\item{block_col}{Column name of the design's block factor. Used when +\code{L_matrix} isn't supplied.} } \description{ Creates an objective function that optimises experimental designs using the @@ -37,3 +46,7 @@ Fisher information for treatment contrasts after adjusting for nuisance effects, and takes an optional spatial covariance structure for spatial optimisation. } +\details{ +This function computes the treatment information matrix: +\deqn{I = X_1^\intercal L X_1}{I = X₁ᵀ L X₁} +} diff --git a/man/speed-package.Rd b/man/speed-package.Rd index 49e43baf..746f653c 100644 --- a/man/speed-package.Rd +++ b/man/speed-package.Rd @@ -23,12 +23,14 @@ Authors: \item Julian Taylor \email{julian.taylor@adelaide.edu.au} \item Russell Edson \email{russell.edson@adelaide.edu.au} \item Wasin Pipattungsakul \email{wasin.pipattungsakul@adelaide.edu.au} + \item Kai Bagley \email{kai.bagley@curtin.edu.au} (\href{https://orcid.org/0009-0004-6579-6959}{ORCID}) } Other contributors: \itemize{ \item University of Adelaide (https://adelaide.edu.au/) [copyright holder, funder] \item Grains Research and Development Corporation (https://grdc.com.au/) [copyright holder, funder] + \item Curtin University (\href{https://ror.org/02n415q13}{ROR}) (http://www.curtin.edu.au/) [copyright holder] } } From f48a670f8438f312da6e5895bd650041ab80cf29 Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Fri, 1 May 2026 11:15:18 +0800 Subject: [PATCH 05/25] add emacs dir locals --- .Rbuildignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.Rbuildignore b/.Rbuildignore index d0aba753..7e1a4c27 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -21,3 +21,4 @@ codemeta.json ^Meta$ ^CODE_OF_CONDUCT\.md$ ^doc$ +^\.dir-locals\.el$ From b31c28379810dbc18c8a6cdad79d31144fffe407 Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Fri, 1 May 2026 11:15:38 +0800 Subject: [PATCH 06/25] many fixes so examples work, and other issues lel --- R/objectives.R | 537 +++++++++++++++++++++++++++---------------------- 1 file changed, 299 insertions(+), 238 deletions(-) diff --git a/R/objectives.R b/R/objectives.R index 2e06dc17..59a01b51 100644 --- a/R/objectives.R +++ b/R/objectives.R @@ -5,7 +5,7 @@ #' effects, and takes an optional spatial covariance structure for spatial #' optimisation. #' -#' @param design Data frame representing the spatial layout of the experiment. +#' @param layout_df Data frame representing the spatial layout of the experiment. #' @param swap Column name to swap, usually the treatment. #' @param spatial_cols Column name of the spatial factors. #' @param criterion Either \code{"A"} or \code{"D"}, representing A or D @@ -16,8 +16,9 @@ #' \code{precompute_projection} to generate it. If \code{NULL}, then the #' identity covariance structure will be assumed, and the projection will be #' computed using the structure of the design's blocks. -#' @param block_col Column name of the design's block factor. Used when +#' @param block_column Column name of the design's block factor. Used when #' \code{L_matrix} isn't supplied. +#' @param ... Extra parameters passed from \code{speed}. #' #' @details #' This function computes the treatment information matrix: @@ -25,75 +26,109 @@ #' Where \eqn{X_1}{X₁} is the treatment design matrix, and \eqn{L} is the #' projection that removes nuisance fixed effects from the GLS's inverse #' covariance: -#' \deqn{L = \Sigma^{-1} - \Sigma^{-1} X_2 \left( X_2^\intercal \Sigma^{-1} X_2 \right)^{-1}}{L = Σ⁻¹ - Σ⁻¹ X₂ (X₂ᵀ Σ⁻¹ X₂)⁻¹} +#' \deqn{L = \Sigma^{-1} - \Sigma^{-1} X_2 \left( X_2^\intercal \Sigma^{-1} X_2 +#' \right)^{-1}}{L = Σ⁻¹ - Σ⁻¹ X₂ (X₂ᵀ Σ⁻¹ X₂)⁻¹} #' The user specifies the spatial covariance \eqn{\Sigma}{Σ} they intend to use -#' at the time of analysis, e.g. autoregressive-lag-1 \eqn{\text{AR}_1 \otimes \text{AR}_1}{AR₁ ⊗ AR₁}, -#' and this objective will optimise under that structure. +#' at the time of analysis, e.g. lag-1 autoregressive \eqn{\text{AR}_1 \otimes +#' \text{AR}_1}{AR₁ ⊗ AR₁}, and this objective will optimise under that +#' structure. +#' +#' @examples +#' # Small RCBD layout: 6 treatments in 4 blocks of 6 plots +#' df <- initialise_design_df( +#' items = 6, nrows = 4, ncols = 6, +#' block_nrows = 1, block_ncols = 6 +#' ) +#' +#' # Non-spatial: identity covariance +#' result <- speed( +#' df, +#' swap = "treatment", +#' swap_within = "block", +#' obj_function = objective_function_info, +#' criterion = "A", +#' seed = 42, +#' quiet = TRUE +#' ) +#' +#' # Spatial: AR(1) x AR(1) +#' Sigma <- cor_ar1_ar1( +#' n_rows = 4, n_cols = 6, +#' rho_row = 0.6, rho_col = 0.3 +#' ) +#' L <- compute_L_projection(df, Sigma, block_column = "block") +#' result_spatial <- speed( +#' df, +#' swap = "treatment", +#' swap_within = "block", +#' obj_function = objective_function_info, +#' L_matrix = L, +#' criterion = "A", +#' optimise_params = optim_params(random_initialisation = TRUE), +#' seed = 42, +#' quiet = TRUE +#' ) +#' +#' # Inspect the optimised design +#' calc_info_matrix(result_spatial$design_df, L_matrix = L) +#' +#' @return A named list with \code{score}, \code{info_matrix}, +#' \code{eigenvalues}, \code{criterion}. #' #' @export objective_function_info <- function( - design, - swap, - spatial_cols, - row_col = "row", - range_col = "range", - criterion = c("A", "D"), - L_matrix = NULL, - block_col = "block", - ... + layout_df, + swap, + spatial_cols, + criterion = c("A", "D"), + L_matrix = NULL, + block_column = "block", + ... ) { - criterion <- match.arg(criterion) - - ## a lot of the args come from the design now - treatments <- design[[swap]] - trt_levels <- levels(factor(treatments)) - v <- length(trt_levels) - n <- nrow(design) - - ## L - ### projection matrix - if (is.null(L_matrix)) { - L_matrix <- .build_L_from_df(design, block_col, n) - } - - ## X1 - ### treatment design matrix. - X1 <- .build_treatment_matrix(treatments, trt_levels, n, v) - - ## information matrix I = X1t L X1 - info <- t(X1) %*% L_matrix %*% X1 - - ## get positive eigenvals from info matrix - eig <- eigen(info, symmetric = TRUE, only.values = TRUE)$values - pos_eig <- eig[eig > 1e-10] - + criterion <- match.arg(criterion) + + ci <- .compute_info(layout_df, swap, L_matrix, block_column) + info <- ci$info + v <- ci$v + + ## get positive eigenvals from info matrix + eig <- eigen(info, symmetric = TRUE, only.values = TRUE)$values + max_eig <- max(eig) + if (max_eig <= 0) { + score <- 1e10 + pos_eig <- numeric(0) + } else { + pos_eig <- eig[eig > max_eig * 1e-10] ## if design is disconnected, penalise greatly ## otherwise A or D if (length(pos_eig) < v - 1) { - score <- Inf + score <- 1e10 } else { - score <- switch(criterion, - A = sum(1 / pos_eig), - D = -sum(log(pos_eig)) - ) + score <- switch(criterion, + A = sum(1 / pos_eig), + D = -sum(log(pos_eig)) + ) + if (!is.finite(score)) score <- 1e10 } - - return(list( - score = score, - info_matrix = info, - eigenvalues = sort(pos_eig, decreasing = TRUE), - criterion = criterion - )) + } + + return(list( + score = score, + info_matrix = info, + eigenvalues = sort(pos_eig, decreasing = TRUE), + criterion = criterion + )) } #' Build the treatment indicator matrix X1 +#' @noRd .build_treatment_matrix <- function(treatments, trt_levels, n, v) { - X1 <- matrix(0, n, v) - trt_idx <- match(treatments, trt_levels) - for (i in seq_len(n)) { - X1[i, trt_idx[i]] <- 1 - } - return(X1) + X1 <- matrix(0, n, v) + trt_idx <- match(treatments, trt_levels) + for (i in seq_len(n)) { + X1[i, trt_idx[i]] <- 1 + } + return(X1) } #' Function to precompute \eqn{L} @@ -103,25 +138,54 @@ objective_function_info <- function( #' \eqn{\Sigma}{Sigma} and nuisance effects design \eqn{X_2}. #' #' This only depends on lambda and the block structure, so precompute this. -.build_L_from_df <- function(design, block_col, n) { - if (!block_col %in% names(design)) { - ## L = I - (1/n) ones_matrix - return(diag(n) - matrix(1 / n, n, n)) - } - - blocks <- factor(design[[block_col]]) - b <- nlevels(blocks) - - X2 <- matrix(0, n, b) - for (j in seq_len(b)) { - X2[blocks == levels(blocks)[j], j] <- 1 - } - - ## L = I - X2 (X2t X2)^{-1} X2t - X2tX2_inv <- diag(1 / colSums(X2), nrow = b) - diag(n) - X2 %*% X2tX2_inv %*% t(X2) +#' @noRd +.build_L_from_df <- function(layout_df, block_column, n) { + if (!block_column %in% names(layout_df)) { + ## L = I - (1/n) ones_matrix + return(diag(n) - matrix(1 / n, n, n)) + } + + blocks <- factor(layout_df[[block_column]]) + b <- nlevels(blocks) + + X2 <- matrix(0, n, b) + for (j in seq_len(b)) { + X2[blocks == levels(blocks)[j], j] <- 1 + } + + ## L = I - X2 (X2t X2)^{-1} X2t + X2tX2_inv <- diag(1 / colSums(X2), nrow = b) + diag(n) - X2 %*% X2tX2_inv %*% t(X2) } +#' Function for computing the information matrix +#' @noRd +.compute_info <- function( + layout_df, + swap, + L_matrix, + block_column +) { + ## a lot of the args come from the design now + treatments <- layout_df[[swap]] + trt_levels <- levels(factor(treatments)) + v <- length(trt_levels) + n <- nrow(layout_df) + + ## L + ### projection matrix + if (is.null(L_matrix)) { + L_matrix <- .build_L_from_df(layout_df, block_column, n) + } + + ## X1 + ### treatment design matrix. + X1 <- .build_treatment_matrix(treatments, trt_levels, n, v) + ## information matrix I = X1t L X1 + info <- t(X1) %*% L_matrix %*% X1 + + list(info = info, v = v, trt_levels = trt_levels) +} # Helper functions @@ -130,183 +194,201 @@ objective_function_info <- function( #' This is the projection matrix that removes nuisance effects from the GLS's #' covariance #' -#' @param design Data frame representing the spatial layout of the experiment. +#' @param layout_df Data frame representing the spatial layout of the experiment. #' @param Sigma Covariance structure to use. -#' @param block_col Column name of the design's block factor in \code{design}. +#' @param block_column Column name of the design's block factor in \code{layout_df}. +#' +#' @return \eqn{(n \times n)} numeric matrix. #' #' @export -compute_L_projection <- function(design, Sigma, block_col = "block") { - n <- nrow(design) - - ## arg checks - if (!is.matrix(Sigma)) stop("Sigma must be a matrix") - if (nrow(Sigma) != n) stop("Sigma matrix must have dimension equal to dimension of design dataframe") - if (ncol(Sigma) != n) stop("Sigma matrix must have dimension equal to dimension of design dataframe") - if (!isSymmetric(Sigma, tol = 1e-8)) stop("Sigma must be symmetric") - if (!(block_col %in% names(design))) stop("Block column name not in design dataframe") - - blocks <- factor(design[[block_col]]) - b <- nlevels(blocks) - - ## X2 - ### block indicator matrix with the intercept removed - X2 <- matrix(0, n, b) - for (j in seq_len(b)) { - X2[blocks == levels(blocks)[j], j] <- 1 - } - - Sigma_inv <- solve(Sigma) - SiX2 <- Sigma_inv %*% X2 - return(Sigma_inv - SiX2 %*% solve(t(X2) %*% SiX2) %*% t(SiX2)) +compute_L_projection <- function( + layout_df, + Sigma, + block_column = "block" +) { + n <- nrow(layout_df) + + ## arg checks + if (!is.matrix(Sigma)) stop("Sigma must be a matrix") + if (nrow(Sigma) != n) { + stop( + "Sigma matrix must have dimension equal ", + "to dimension of layout_df dataframe") + } + if (ncol(Sigma) != n) { + stop( + "Sigma matrix must have dimension equal ", + "to dimension of layout_df dataframe" + ) + } + if (!isSymmetric(Sigma, tol = 1e-8)) stop("Sigma must be symmetric") + if (!(block_column %in% names(layout_df))) { + stop("Block column name not in layout_df dataframe") + } + + blocks <- factor(layout_df[[block_column]]) + b <- nlevels(blocks) + + ## X2 + ### block indicator matrix with the intercept removed + X2 <- matrix(0, n, b) + for (j in seq_len(b)) { + X2[blocks == levels(blocks)[j], j] <- 1 + } + + Sigma_inv <- solve(Sigma) + SiX2 <- Sigma_inv %*% X2 + return(Sigma_inv - SiX2 %*% solve(t(X2) %*% SiX2) %*% t(SiX2)) } #' Calculate info matrix #' #' Calculate the Fisher information in the experimental design #' -#' @param design Data frame representing the spatial layout of the experiment. -#' @param treatment_col Column name containing the design's treatments in -#' \code{design}. +#' @param layout_df Data frame representing the spatial layout of the experiment. +#' @param treatment_column Column name containing the design's treatments in +#' \code{layout_df}. #' @param L_matrix Precomputed projection matrix from #' \code{compute_L_projection}. -#' @param block_col Column name containing the designs block in \code{design}. +#' @param block_column Column name containing the designs block in +#' \code{layout_df}. #' #' @export calc_info_matrix <- function( - design, - treatment_col = "treatment", - L_matrix = NULL, - block_col = "block" + layout_df, + treatment_column = "treatment", + L_matrix = NULL, + block_column = "block" ) { - treatments <- design[[treatment_col]] - trt_levels <- levels(factor(treatments)) - v <- length(trt_levels) - n <- nrow(design) - - # TODO: Duplicated from above. Probably try and simplify later - ## L - ### projection matrix - if (is.null(L_matrix)) { - L_matrix <- .build_L_from_df(design, block_col, n) - } - - ## X1 - ### treatment design matrix. - X1 <- .build_treatment_matrix(treatments, trt_levels, n, v) - - ## information matrix I = X1t L X1 - info <- t(X1) %*% L_matrix %*% X1 - - rownames(info) <- trt_levels - colnames(info) <- trt_levels - - ## get positive eigenvals from info matrix - eig <- eigen(info, symmetric = TRUE, only.values = TRUE)$values - pos_eig <- eig[eig > 1e-10] - - ## if design is disconnected, penalise greatly - ## otherwise A or D - if (length(pos_eig) < v - 1) { - A_val <- Inf - D_val <- Inf - } else { - A_val = sum(1 / pos_eig) - D_val = -sum(log(pos_eig)) - } - - return(list( - info_matrix = info, - eigenvalues = sort(pos_eig, decreasing = TRUE), - rank = length(pos_eig), - A_value = A_val, - D_value = D_val - )) + ci <- .compute_info(layout_df, treatment_column, L_matrix, block_column) + info <- ci$info + v <- ci$v + rownames(info) <- ci$trt_levels + colnames(info) <- ci$trt_levels + + ## get positive eigenvals from info matrix + eig <- eigen(info, symmetric = TRUE, only.values = TRUE)$values + max_eig <- max(eig) + if (max_eig <= 0) { + pos_eig <- numeric(0) + } else { + pos_eig <- eig[eig > max_eig * 1e-10] + } + + if (length(pos_eig) < v - 1) { + A_val <- Inf + D_val <- Inf + } else { + A_val = sum(1 / pos_eig) + D_val = -sum(log(pos_eig)) + if (!is.finite(A_val)) A_val <- Inf + if (!is.finite(D_val)) D_val <- Inf + } + + return(list( + info_matrix = info, + eigenvalues = sort(pos_eig, decreasing = TRUE), + rank = length(pos_eig), + A_value = A_val, + D_value = D_val + )) } #' Calculate incidence matrix #' -#' @param design Data frame representing the spatial layout of the experiment. -#' @param treatment_col Column name containing the design's treatments in -#' \code{design}. -#' @param block_col Column name containing the designs block in \code{design}. +#' @param layout_df Data frame representing the spatial layout of the experiment. +#' @param treatment_column Column name containing the design's treatments in +#' \code{layout_df}. +#' @param block_column Column name containing the designs block in +#' \code{layout_df}. +#' +#' @return \eqn{v \times b} matrix of integers, with treatment levels as row +#' names, and block levels as column names. #' #' @export calc_incidence_matrix <- function( - design, - treatment_col = "treatment", - block_col = "block" + layout_df, + treatment_column = "treatment", + block_column = "block" ) { - treatments <- factor(design[[treatment_col]]) - blocks <- factor(design[[block_col]]) + treatments <- factor(layout_df[[treatment_column]]) + blocks <- factor(layout_df[[block_column]]) - ## make a matrix of integers - N <- table(treatments, blocks) - class(N) <- "matrix" - storage.mode(N) <- "integer" + ## make a matrix of integers + N <- table(treatments, blocks) + class(N) <- "matrix" + storage.mode(N) <- "integer" - return(N) + return(N) } #' Calculate concurrence matrix #' -#' @param design Data frame representing the spatial layout of the experiment. -#' @param treatment_col Column name containing the design's treatments in -#' \code{design}. -#' @param block_col Column name containing the designs block in \code{design}. +#' @param layout_df Data frame representing the spatial layout of the +#' experiment. +#' @param treatment_column Column name containing the design's treatments in +#' \code{layout_df}. +#' @param block_column Column name containing the designs block in +#' \code{layout_df}. +#' +#' @return Symmetric \eqn{N N^\intercal}{N Nᵀ} matrix. #' #' @export calc_concurrence_matrix <- function( - design, - treatment_col = "treatment", - block_col = "block" + layout_df, + treatment_column = "treatment", + block_column = "block" ) { - N <- calc_incidence_matrix(design, treatment_col, block_col) - C <- N %*% t(N) - storage.mode(C) <- "integer" - return(C) + N <- calc_incidence_matrix(layout_df, treatment_column, block_column) + C <- N %*% t(N) + storage.mode(C) <- "integer" + return(C) } #' Calculate canonical efficiency factors #' -#' @param design Data frame representing the spatial layout of the experiment. -#' @param treatment_col Column name containing the design's treatments in -#' \code{design}. +#' @param layout_df Data frame representing the spatial layout of the experiment. +#' @param treatment_column Column name containing the design's treatments in +#' \code{layout_df}. #' @param L_matrix Precomputed projection matrix from #' \code{compute_L_projection}. -#' @param block_col Column name containing the designs block in \code{design}. +#' @param block_column Column name containing the designs block in +#' \code{layout_df}. +#' +#' @return A list with \code{efficiency_factors}, \code{E}, \code{replication}. #' #' @export calculate_efficiency_factors <- function( - design, - treatment_col = "treatment", - L_matrix = NULL, - block_col = "block" + layout_df, + treatment_column = "treatment", + L_matrix = NULL, + block_column = "block" ) { - info <- calc_info_matrix( - design, - treatment_col, - L_matrix, - block_col - ) - - treatments <- factor(design[[treatment_col]]) - reps <- table(treatments) - r_bar <- mean(reps) - - eff_factors <- info$eigenvalues / r_bar - - v <- nlevels(treatments) - E <- if (info$rank >= v - 1) { - (v - 1) / sum(1 / eff_factors) - } else { - NA_real_ - } - - list( - efficiency_factors = eff_factors, - E = E, - replication = setNames(as.integer(reps), levels(treatments)) - ) + info <- calc_info_matrix( + layout_df, + treatment_column, + L_matrix, + block_column + ) + + treatments <- factor(layout_df[[treatment_column]]) + reps <- table(treatments) + r_bar <- mean(reps) + + eff_factors <- info$eigenvalues / r_bar + + v <- nlevels(treatments) + E <- if (info$rank >= v - 1) { + (v - 1) / sum(1 / eff_factors) + } else { + NA_real_ + } + + list( + efficiency_factors = eff_factors, + E = E, + replication = setNames(as.integer(reps), levels(treatments)) + ) } @@ -317,6 +399,8 @@ calculate_efficiency_factors <- function( #' @param n Size of the covariance vector to generate #' @param rho Correlation parameter #' +#' @return A symmetric \eqn{(n \times n)} correlation matrix. +#' #' @export cor_ar1 <- function(n, rho) { rho^abs(outer(seq_len(n), seq_len(n), "-")) @@ -330,36 +414,13 @@ cor_ar1 <- function(n, rho) { #' @param rho_row Correlation parameter along the row direction. #' @param rho_col Correlation parameter along the column direction. #' +#' @return A symmetric \eqn{(\text{n_rows} \cdot \text{n_cols}) \times +#' (\text{n_rows} \cdot \text{n_cols})} correlation matrix. +#' #' @export cor_ar1_ar1 <- function(n_rows, n_cols, rho_row, rho_col) { - kronecker( - cor_ar1(n_rows, rho_row), - cor_ar1(n_cols, rho_col) - ) -} - - -## Testing -set.seed(1) -n_treatments <- 4 -n_blocks <- 3 - -df <- data.frame( - row = rep(1:n_blocks, each = n_treatments), - col = rep(1:n_treatments, times = n_blocks), - block = rep(1:n_blocks, each = n_treatments), - treatment = NA_character_ -) - -scores <- numeric(20) -for (i in seq_len(20)) { - for (b in 1:n_blocks) { - idx <- df$block == b - df$treatment[idx] <- paste0("T", sample(n_treatments)) - } - result <- objective_function_info( - df, swap = "treatment", spatial_cols = c("row", "col"), - criterion = "A" - ) - scores[i] <- result$score + kronecker( + cor_ar1(n_rows, rho_row), + cor_ar1(n_cols, rho_col) + ) } From 35a6d3ff0ac9df158aad4a94f1a4f365c1f86a70 Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Fri, 1 May 2026 11:15:58 +0800 Subject: [PATCH 07/25] fix test with new penalty --- tests/testthat/test-objective_function_info.R | 479 ++++++++++-------- 1 file changed, 270 insertions(+), 209 deletions(-) diff --git a/tests/testthat/test-objective_function_info.R b/tests/testthat/test-objective_function_info.R index 6a64ed65..9c893797 100644 --- a/tests/testthat/test-objective_function_info.R +++ b/tests/testthat/test-objective_function_info.R @@ -4,109 +4,110 @@ # all RCBDs are equally optimal test_that("all valid RCBD randomisations produce the same score under identity covariance", { - set.seed(1) - n_treatments <- 4 - n_blocks <- 3 - - df <- data.frame( - row = rep(1:n_blocks, each = n_treatments), - col = rep(1:n_treatments, times = n_blocks), - block = rep(1:n_blocks, each = n_treatments), - treatment = NA_character_ - ) - - scores <- numeric(20) - for (i in seq_len(20)) { - for (b in 1:n_blocks) { - idx <- df$block == b - df$treatment[idx] <- paste0("T", sample(n_treatments)) - } - result <- objective_function_info( - df, swap = "treatment", spatial_cols = c("row", "col"), - criterion = "A" - ) - scores[i] <- result$score + set.seed(1) + n_treatments <- 4 + n_blocks <- 3 + + df <- data.frame( + row = rep(1:n_blocks, each = n_treatments), + col = rep(1:n_treatments, times = n_blocks), + block = rep(1:n_blocks, each = n_treatments), + treatment = NA_character_ + ) + + scores <- numeric(20) + for (i in seq_len(20)) { + for (b in 1:n_blocks) { + idx <- df$block == b + df$treatment[idx] <- paste0("T", sample(n_treatments)) } + result <- objective_function_info( + df, swap = "treatment", spatial_cols = c("row", "col"), + criterion = "A" + ) + scores[i] <- result$score + } - expect_true(max(scores) - min(scores) < 1e-10) + expect_true(max(scores) - min(scores) < 1e-10) }) # when there IS spatial correlation, two different arrangements of the same # treatments must give different scores. df1 should be worse, since treatments # are always in the same column position, but in df2 they're "randomised". test_that("spatial designs differentiate between arrangements", { - n_treatments <- 4 - n_blocks <- 3 - - df <- data.frame( - row = rep(1:n_blocks, each = n_treatments), - col = rep(1:n_treatments, times = n_blocks), - block = rep(1:n_blocks, each = n_treatments) - ) - - Sigma <- cor_ar1_ar1(n_blocks, n_treatments, rho_row = 0.7, rho_col = 0.5) - L <- compute_L_projection(df, Sigma, block_col = "block") - - # Same treatment ordering in every block - df1 <- df - df1$treatment <- rep(paste0("T", 1:n_treatments), n_blocks) - - # Alternated ordering - df2 <- df - df2$treatment <- c( - paste0("T", c(1, 2, 3, 4)), - paste0("T", c(3, 4, 1, 2)), - paste0("T", c(4, 3, 2, 1)) - ) - - s1 <- objective_function_info( - df1, "treatment", c("row", "col"), - criterion = "A", L_matrix = L - )$score - - s2 <- objective_function_info( - df2, "treatment", c("row", "col"), - criterion = "A", L_matrix = L - )$score - - expect_false(abs(s1 - s2) < 1e-10) + n_treatments <- 4 + n_blocks <- 3 + + df <- data.frame( + row = rep(1:n_blocks, each = n_treatments), + col = rep(1:n_treatments, times = n_blocks), + block = rep(1:n_blocks, each = n_treatments) + ) + + Sigma <- cor_ar1_ar1(n_blocks, n_treatments, rho_row = 0.7, rho_col = 0.5) + L <- compute_L_projection(df, Sigma, block_col = "block") + + # Same treatment ordering in every block + df1 <- df + df1$treatment <- rep(paste0("T", 1:n_treatments), n_blocks) + + # Alternated ordering + df2 <- df + df2$treatment <- c( + paste0("T", c(1, 2, 3, 4)), + paste0("T", c(3, 4, 1, 2)), + paste0("T", c(4, 3, 2, 1)) + ) + + s1 <- objective_function_info( + df1, "treatment", c("row", "col"), + criterion = "A", L_matrix = L + )$score + + s2 <- objective_function_info( + df2, "treatment", c("row", "col"), + criterion = "A", L_matrix = L + )$score + + expect_false(abs(s1 - s2) < 1e-10) }) # just make sure this works lel test_that("D-optimality criterion works", { - df <- data.frame( - row = rep(1:3, each = 4), - col = rep(1:4, times = 3), - block = rep(1:3, each = 4), - treatment = rep(paste0("T", 1:4), 3) - ) - - result <- objective_function_info( - df, "treatment", c("row", "col"), - criterion = "D" - ) - - expect_true(is.finite(result$score)) - expect_equal(result$criterion, "D") - expect_equal(length(result$eigenvalues), 3) # v - 1 + df <- data.frame( + row = rep(1:3, each = 4), + col = rep(1:4, times = 3), + block = rep(1:3, each = 4), + treatment = rep(paste0("T", 1:4), 3) + ) + + result <- objective_function_info( + df, "treatment", c("row", "col"), + criterion = "D" + ) + + expect_true(is.finite(result$score)) + expect_equal(result$criterion, "D") + expect_equal(length(result$eigenvalues), 3) # v - 1 }) # if treatments never exist in the same block together, you cant compare them, # so the design is fully broken -test_that("disconnected designs return Inf", { - df <- data.frame( - row = 1:6, - col = c(1, 2, 1, 2, 1, 2), - block = c(1, 1, 2, 2, 3, 3), - treatment = c("A", "A", "B", "B", "C", "C") - ) - - result <- objective_function_info( - df, "treatment", c("row", "col"), - criterion = "A" - ) - - expect_equal(result$score, Inf) +test_that("disconnected designs have massive penalty", { + df <- data.frame( + row = 1:6, + col = c(1, 2, 1, 2, 1, 2), + block = c(1, 1, 2, 2, 3, 3), + treatment = c("A", "A", "B", "B", "C", "C") + ) + + result <- objective_function_info( + df, "treatment", c("row", "col"), + criterion = "A" + ) + + expect_gte(result$score, 1e9) + expect_true(is.finite(result$score)) }) @@ -114,35 +115,35 @@ test_that("disconnected designs return Inf", { # input validation test test_that("compute_L_projection validates inputs", { - df <- data.frame( - row = 1:4, col = 1:4, block = c(1, 1, 2, 2), - treatment = c("A", "B", "A", "B") - ) + df <- data.frame( + row = 1:4, col = 1:4, block = c(1, 1, 2, 2), + treatment = c("A", "B", "A", "B") + ) - # Wrong dimensions - expect_error(compute_L_projection(df, diag(3))) + # Wrong dimensions + expect_error(compute_L_projection(df, diag(3))) - # Not symmetric - expect_error(compute_L_projection(df, matrix(1:16, 4, 4))) + # Not symmetric + expect_error(compute_L_projection(df, matrix(1:16, 4, 4))) - # Missing block column - expect_error(compute_L_projection(df, diag(4), block_col = "nonexistent")) + # Missing block column + expect_error(compute_L_projection(df, diag(4), block_col = "nonexistent")) }) # identity sigma should be the default L projection. i.e. spatial optimisation # with identity correlation is the same as non-spatial test_that("L with identity Sigma matches .build_L_from_df", { - df <- data.frame( - row = rep(1:3, each = 4), - col = rep(1:4, times = 3), - block = rep(1:3, each = 4), - treatment = rep(paste0("T", 1:4), 3) - ) + df <- data.frame( + row = rep(1:3, each = 4), + col = rep(1:4, times = 3), + block = rep(1:3, each = 4), + treatment = rep(paste0("T", 1:4), 3) + ) - L_spatial <- compute_L_projection(df, diag(12), block_col = "block") - L_direct <- .build_L_from_df(df, "block", 12) + L_spatial <- compute_L_projection(df, diag(12), block_col = "block") + L_direct <- .build_L_from_df(df, "block", 12) - expect_true(max(abs(L_spatial - L_direct)) < 1e-10) + expect_true(max(abs(L_spatial - L_direct)) < 1e-10) }) @@ -150,63 +151,63 @@ test_that("L with identity Sigma matches .build_L_from_df", { # balanced RCBD should have rank = v - 1 test_that("info matrix for RCBD has correct properties", { - df <- data.frame( - row = rep(1:3, each = 5), - col = rep(1:5, times = 3), - block = rep(1:3, each = 5), - treatment = rep(paste0("T", 1:5), 3) - ) + df <- data.frame( + row = rep(1:3, each = 5), + col = rep(1:5, times = 3), + block = rep(1:3, each = 5), + treatment = rep(paste0("T", 1:5), 3) + ) - info <- calc_info_matrix(df) + info <- calc_info_matrix(df) - # v = 5, so rank = v - 1 = 4 - expect_equal(info$rank, 4) + # v = 5, so rank = v - 1 = 4 + expect_equal(info$rank, 4) - # For balanced RCBD all non-zero eigenvalues = b = 3 - expect_true(all(abs(info$eigenvalues - 3) < 1e-10)) + # For balanced RCBD all non-zero eigenvalues = b = 3 + expect_true(all(abs(info$eigenvalues - 3) < 1e-10)) - # 5x5 matrix - expect_equal(dim(info$info_matrix), c(5, 5)) + # 5x5 matrix + expect_equal(dim(info$info_matrix), c(5, 5)) - # Named - expect_equal(rownames(info$info_matrix), paste0("T", 1:5)) - expect_equal(colnames(info$info_matrix), paste0("T", 1:5)) + # Named + expect_equal(rownames(info$info_matrix), paste0("T", 1:5)) + expect_equal(colnames(info$info_matrix), paste0("T", 1:5)) }) # spatial should always be different to non-spatial test_that("spatial info matrix differs from non-spatial", { - df <- data.frame( - row = rep(1:3, each = 4), - col = rep(1:4, times = 3), - block = rep(1:3, each = 4), - treatment = rep(paste0("T", 1:4), 3) - ) - - Sigma <- cor_ar1_ar1(3, 4, 0.5, 0.3) - L <- compute_L_projection(df, Sigma) - - info_plain <- calc_info_matrix(df) - info_spatial <- calc_info_matrix(df, L_matrix = L) - - expect_false( - all(abs(info_plain$eigenvalues - info_spatial$eigenvalues) < 1e-10) - ) + df <- data.frame( + row = rep(1:3, each = 4), + col = rep(1:4, times = 3), + block = rep(1:3, each = 4), + treatment = rep(paste0("T", 1:4), 3) + ) + + Sigma <- cor_ar1_ar1(3, 4, 0.5, 0.3) + L <- compute_L_projection(df, Sigma) + + info_plain <- calc_info_matrix(df) + info_spatial <- calc_info_matrix(df, L_matrix = L) + + expect_false( + all(abs(info_plain$eigenvalues - info_spatial$eigenvalues) < 1e-10) + ) }) # disconnected design should give invalid criteria test_that("disconnected design gives Inf for A and D values", { - df <- data.frame( - row = 1:6, - col = c(1, 2, 1, 2, 1, 2), - block = c(1, 1, 2, 2, 3, 3), - treatment = c("A", "A", "B", "B", "C", "C") - ) + df <- data.frame( + row = 1:6, + col = c(1, 2, 1, 2, 1, 2), + block = c(1, 1, 2, 2, 3, 3), + treatment = c("A", "A", "B", "B", "C", "C") + ) - info <- calc_info_matrix(df) + info <- calc_info_matrix(df) - expect_equal(info$A_value, Inf) - expect_equal(info$D_value, Inf) + expect_equal(info$A_value, Inf) + expect_equal(info$D_value, Inf) }) @@ -215,52 +216,52 @@ test_that("disconnected design gives Inf for A and D values", { # complete design should have all incidence matrix entries = 1 # should also encode replication (rows) and block size (cols) test_that("incidence matrix has correct dimensions and values for RCBD", { - df <- data.frame( - row = rep(1:3, each = 4), - col = rep(1:4, times = 3), - block = rep(1:3, each = 4), - treatment = rep(paste0("T", 1:4), 3) - ) - - N <- calc_incidence_matrix(df) - - expect_equal(dim(N), c(4, 3)) # v x b - expect_true(all(N == 1)) # complete blocks - expect_true(all(rowSums(N) == 3)) # replication = b - expect_true(all(colSums(N) == 4)) # block size = v + df <- data.frame( + row = rep(1:3, each = 4), + col = rep(1:4, times = 3), + block = rep(1:3, each = 4), + treatment = rep(paste0("T", 1:4), 3) + ) + + N <- calc_incidence_matrix(df) + + expect_equal(dim(N), c(4, 3)) # v x b + expect_true(all(N == 1)) # complete blocks + expect_true(all(rowSums(N) == 3)) # replication = b + expect_true(all(colSums(N) == 4)) # block size = v }) # ensure incidence works fine for imbalanced designs test_that("incidence matrix handles unequal replication", { - df <- data.frame( - row = 1:5, - col = c(1, 2, 1, 2, 1), - block = c(1, 1, 2, 2, 2), - treatment = c("A", "B", "A", "B", "A") - ) - - N <- calc_incidence_matrix(df) - - expect_equal(dim(N), c(2, 2)) - expect_equal(sum(N["A", ]), 3) # A appears 3 times - expect_equal(sum(N["B", ]), 2) # B appears 2 times + df <- data.frame( + row = 1:5, + col = c(1, 2, 1, 2, 1), + block = c(1, 1, 2, 2, 2), + treatment = c("A", "B", "A", "B", "A") + ) + + N <- calc_incidence_matrix(df) + + expect_equal(dim(N), c(2, 2)) + expect_equal(sum(N["A", ]), 3) # A appears 3 times + expect_equal(sum(N["B", ]), 2) # B appears 2 times }) # ---- calc_concurrence_matrix # balanced RCBD with N all = 1, N Nt should have entries equal to block number test_that("concurrence matrix is correct for RCBD", { - df <- data.frame( - row = rep(1:3, each = 4), - col = rep(1:4, times = 3), - block = rep(1:3, each = 4), - treatment = rep(paste0("T", 1:4), 3) - ) + df <- data.frame( + row = rep(1:3, each = 4), + col = rep(1:4, times = 3), + block = rep(1:3, each = 4), + treatment = rep(paste0("T", 1:4), 3) + ) - C <- calc_concurrence_matrix(df) + C <- calc_concurrence_matrix(df) - expect_equal(dim(C), c(4, 4)) - expect_true(all(C == 3)) + expect_equal(dim(C), c(4, 4)) + expect_true(all(C == 3)) }) @@ -268,19 +269,19 @@ test_that("concurrence matrix is correct for RCBD", { # balanced RCBD has all efficiency factors = 1 test_that("efficiency factors are 1 for complete blocks", { - df <- data.frame( - row = rep(1:4, each = 5), - col = rep(1:5, times = 4), - block = rep(1:4, each = 5), - treatment = rep(paste0("T", 1:5), 4) - ) - - info <- calc_info_matrix(df) - treatments <- factor(df$treatment) - r_bar <- mean(table(treatments)) - eff <- info$eigenvalues / r_bar - - expect_true(all(abs(eff - 1) < 1e-10)) + df <- data.frame( + row = rep(1:4, each = 5), + col = rep(1:5, times = 4), + block = rep(1:4, each = 5), + treatment = rep(paste0("T", 1:5), 4) + ) + + info <- calc_info_matrix(df) + treatments <- factor(df$treatment) + r_bar <- mean(table(treatments)) + eff <- info$eigenvalues / r_bar + + expect_true(all(abs(eff - 1) < 1e-10)) }) @@ -288,30 +289,90 @@ test_that("efficiency factors are 1 for complete blocks", { # make sure ar1 builder works fine test_that("cor_ar1 produces valid correlation matrix", { - R <- cor_ar1(5, 0.7) + R <- cor_ar1(5, 0.7) - expect_equal(dim(R), c(5, 5)) - expect_true(isSymmetric(R)) - expect_true(all(diag(R) == 1)) - expect_true(all(eigen(R, only.values = TRUE)$values > 0)) + expect_equal(dim(R), c(5, 5)) + expect_true(isSymmetric(R)) + expect_true(all(diag(R) == 1)) + expect_true(all(eigen(R, only.values = TRUE)$values > 0)) - # Check specific entries - expect_equal(R[1, 2], 0.7) - expect_equal(R[1, 3], 0.7^2) - expect_equal(R[1, 5], 0.7^4) + # Check specific entries + expect_equal(R[1, 2], 0.7) + expect_equal(R[1, 3], 0.7^2) + expect_equal(R[1, 5], 0.7^4) }) # yes test_that("cor_ar1 with rho = 0 gives identity", { - expect_equal(cor_ar1(4, 0), diag(4)) + expect_equal(cor_ar1(4, 0), diag(4)) }) # make sure ar1 x ar1 builder works fine test_that("cor_ar1_ar1 has correct dimensions and is valid", { - Sigma <- cor_ar1_ar1(3, 5, 0.6, 0.4) + Sigma <- cor_ar1_ar1(3, 5, 0.6, 0.4) + + expect_equal(dim(Sigma), c(15, 15)) + expect_true(isSymmetric(Sigma)) + expect_true(all(diag(Sigma) == 1)) + expect_true(all(eigen(Sigma, only.values = TRUE)$values > 0)) +}) + + +# ---- Test with speed function + +# Actually test by passing to speed +test_that("speed() optimises an RCBD with the info objective under AR1xAR1", { + skip_if_not_installed("speed") + + df <- initialise_design_df( + items = 6, nrows = 4, ncols = 6, + block_nrows = 1, block_ncols = 6 + ) + + Sigma <- cor_ar1_ar1(4, 6, rho_row = 0.6, rho_col = 0.3) + L <- compute_L_projection(df, Sigma, block_column = "block") + + result <- speed( + df, + swap = "treatment", + swap_within = "block", + spatial_factors = ~ block + row + col, + obj_function = objective_function_info, + L_matrix = L, + criterion = "A", + optimise_params = optim_params(random_initialisation = TRUE), + seed = 42, + quiet = TRUE + ) + + expect_s3_class(result, "design") + expect_lt(result$score, Inf) + + info <- calc_info_matrix(result$design_df, L_matrix = L) + expect_equal(info$rank, 5) + expect_true(is.finite(info$A_value)) +}) - expect_equal(dim(Sigma), c(15, 15)) - expect_true(isSymmetric(Sigma)) - expect_true(all(diag(Sigma) == 1)) - expect_true(all(eigen(Sigma, only.values = TRUE)$values > 0)) +test_that("speed() optimises a BIBD with the info objective", { + skip_if_not_installed("speed") + + df <- initialise_design_df( + items = 5, nrows = 3, ncols = 10, + block_nrows = 3, block_ncols = 1 + ) + + result <- speed( + df, + swap = "treatment", + spatial_factors = ~ block + row + col, + obj_function = objective_function_info, + criterion = "A", + optimise_params = optim_params(random_initialisation = TRUE), + seed = 42, + quiet = TRUE + ) + + info <- calc_info_matrix(result$design_df) + expect_equal(info$rank, 4) + expect_true(is.finite(info$A_value)) }) From 9275f8d4b745b2ae986010e8533586907df981bb Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Fri, 1 May 2026 11:16:09 +0800 Subject: [PATCH 08/25] run devtools::check() --- NAMESPACE | 7 +++ man/calc_concurrence_matrix.Rd | 19 ++++++-- man/calc_incidence_matrix.Rd | 19 +++++++- man/calc_info_matrix.Rd | 20 ++++++-- man/calculate_efficiency_factors.Rd | 21 +++++++-- man/compute_L_projection.Rd | 15 +++++- man/dot-build_L_from_df.Rd | 16 ------- man/dot-build_treatment_matrix.Rd | 11 ----- man/objective_function_info.Rd | 73 ++++++++++++++++++++++++----- 9 files changed, 149 insertions(+), 52 deletions(-) delete mode 100644 man/dot-build_L_from_df.Rd delete mode 100644 man/dot-build_treatment_matrix.Rd diff --git a/NAMESPACE b/NAMESPACE index c4c819e2..b1c97323 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,11 +4,18 @@ S3method(autoplot,design) S3method(print,design) export(add_buffers) export(autoplot) +export(calc_concurrence_matrix) +export(calc_incidence_matrix) +export(calc_info_matrix) export(calculate_adjacency_score) export(calculate_balance_score) export(calculate_ed) export(calculate_efficiency_factor) +export(calculate_efficiency_factors) export(calculate_nb) +export(compute_L_projection) +export(cor_ar1) +export(cor_ar1_ar1) export(create_pair_mapping) export(get_edges) export(get_vertices) diff --git a/man/calc_concurrence_matrix.Rd b/man/calc_concurrence_matrix.Rd index 308cae3d..463ee5c7 100644 --- a/man/calc_concurrence_matrix.Rd +++ b/man/calc_concurrence_matrix.Rd @@ -5,11 +5,24 @@ \title{Calculate concurrence matrix} \usage{ calc_concurrence_matrix( - design, - treatment_col = "treatment", - block_col = "block" + layout_df, + treatment_column = "treatment", + block_column = "block" ) } +\arguments{ +\item{layout_df}{Data frame representing the spatial layout of the +experiment.} + +\item{treatment_column}{Column name containing the design's treatments in +\code{layout_df}.} + +\item{block_column}{Column name containing the designs block in +\code{layout_df}.} +} +\value{ +Symmetric \eqn{N N^\intercal}{N Nᵀ} matrix. +} \description{ Calculate concurrence matrix } diff --git a/man/calc_incidence_matrix.Rd b/man/calc_incidence_matrix.Rd index 6bf2ddb7..8f113bbf 100644 --- a/man/calc_incidence_matrix.Rd +++ b/man/calc_incidence_matrix.Rd @@ -4,7 +4,24 @@ \alias{calc_incidence_matrix} \title{Calculate incidence matrix} \usage{ -calc_incidence_matrix(design, treatment_col = "treatment", block_col = "block") +calc_incidence_matrix( + layout_df, + treatment_column = "treatment", + block_column = "block" +) +} +\arguments{ +\item{layout_df}{Data frame representing the spatial layout of the experiment.} + +\item{treatment_column}{Column name containing the design's treatments in +\code{layout_df}.} + +\item{block_column}{Column name containing the designs block in +\code{layout_df}.} +} +\value{ +\eqn{v \times b} matrix of integers, with treatment levels as row +names, and block levels as column names. } \description{ Calculate incidence matrix diff --git a/man/calc_info_matrix.Rd b/man/calc_info_matrix.Rd index 120ee048..5887f425 100644 --- a/man/calc_info_matrix.Rd +++ b/man/calc_info_matrix.Rd @@ -5,12 +5,24 @@ \title{Calculate info matrix} \usage{ calc_info_matrix( - design, - treatment_col = "treatment", + layout_df, + treatment_column = "treatment", L_matrix = NULL, - block_col = "block" + block_column = "block" ) } +\arguments{ +\item{layout_df}{Data frame representing the spatial layout of the experiment.} + +\item{treatment_column}{Column name containing the design's treatments in +\code{layout_df}.} + +\item{L_matrix}{Precomputed projection matrix from +\code{compute_L_projection}.} + +\item{block_column}{Column name containing the designs block in +\code{layout_df}.} +} \description{ -Calculate info matrix +Calculate the Fisher information in the experimental design } diff --git a/man/calculate_efficiency_factors.Rd b/man/calculate_efficiency_factors.Rd index fc3a1b93..cadc96f6 100644 --- a/man/calculate_efficiency_factors.Rd +++ b/man/calculate_efficiency_factors.Rd @@ -5,12 +5,27 @@ \title{Calculate canonical efficiency factors} \usage{ calculate_efficiency_factors( - design, - treatment_col = "treatment", + layout_df, + treatment_column = "treatment", L_matrix = NULL, - block_col = "block" + block_column = "block" ) } +\arguments{ +\item{layout_df}{Data frame representing the spatial layout of the experiment.} + +\item{treatment_column}{Column name containing the design's treatments in +\code{layout_df}.} + +\item{L_matrix}{Precomputed projection matrix from +\code{compute_L_projection}.} + +\item{block_column}{Column name containing the designs block in +\code{layout_df}.} +} +\value{ +A list with \code{efficiency_factors}, \code{E}, \code{replication}. +} \description{ Calculate canonical efficiency factors } diff --git a/man/compute_L_projection.Rd b/man/compute_L_projection.Rd index 6dc43531..0d401ea0 100644 --- a/man/compute_L_projection.Rd +++ b/man/compute_L_projection.Rd @@ -4,8 +4,19 @@ \alias{compute_L_projection} \title{Compute L projection} \usage{ -compute_L_projection(design, Sigma, block_col = "block") +compute_L_projection(layout_df, Sigma, block_column = "block") +} +\arguments{ +\item{layout_df}{Data frame representing the spatial layout of the experiment.} + +\item{Sigma}{Covariance structure to use.} + +\item{block_column}{Column name of the design's block factor in \code{layout_df}.} +} +\value{ +\eqn{(n \times n)} numeric matrix. } \description{ -Compute L projection +This is the projection matrix that removes nuisance effects from the GLS's +covariance } diff --git a/man/dot-build_L_from_df.Rd b/man/dot-build_L_from_df.Rd deleted file mode 100644 index 7b0b3794..00000000 --- a/man/dot-build_L_from_df.Rd +++ /dev/null @@ -1,16 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/objectives.R -\name{.build_L_from_df} -\alias{.build_L_from_df} -\title{Function to precompute \eqn{L}} -\usage{ -.build_L_from_df(design, block_col, n) -} -\description{ -\eqn{L} is the projection matrix that removes nuisance effects under a -spatial correlation structure, given an \eqn{n \times n}{n * n} covariance -\eqn{\Sigma}{Sigma} and nuisance effects design \eqn{X_2}. -} -\details{ -This only depends on lambda and the block structure, so precompute this. -} diff --git a/man/dot-build_treatment_matrix.Rd b/man/dot-build_treatment_matrix.Rd deleted file mode 100644 index c7853821..00000000 --- a/man/dot-build_treatment_matrix.Rd +++ /dev/null @@ -1,11 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/objectives.R -\name{.build_treatment_matrix} -\alias{.build_treatment_matrix} -\title{Build the treatment indicator matrix X1} -\usage{ -.build_treatment_matrix(treatments, trt_levels, n, v) -} -\description{ -Build the treatment indicator matrix X1 -} diff --git a/man/objective_function_info.Rd b/man/objective_function_info.Rd index a884b945..0f0993d3 100644 --- a/man/objective_function_info.Rd +++ b/man/objective_function_info.Rd @@ -5,40 +5,40 @@ \title{Objective function using the treatment information matrix} \usage{ objective_function_info( - design, + layout_df, swap, spatial_cols, - row_col = "row", - range_col = "range", criterion = c("A", "D"), L_matrix = NULL, - block_col = "block", + block_column = "block", ... ) } \arguments{ -\item{design}{Data frame representing the spatial layout of the experiment.} +\item{layout_df}{Data frame representing the spatial layout of the experiment.} \item{swap}{Column name to swap, usually the treatment.} \item{spatial_cols}{Column name of the spatial factors.} -\item{row_col}{Column name of the design's rows} - -\item{range_col}{Column name of the design's range} - \item{criterion}{Either \code{"A"} or \code{"D"}, representing A or D optimality. -- A-optimality: Minimises \eqn{\mathrm{tr} \left( A^- \right)}{tr(A^-)}. -- D-optimality: Minimises \eqn{-\log \left| I \right|}{-log(det(I))}} +- A-optimality: Minimises \eqn{\mathrm{tr} \left( \mathcal{I}^- \right)}{tr(I⁻)}. + - D-optimality: Minimises \eqn{-\log \left| \mathcal{I} \right|}{-log(|I|)}} \item{L_matrix}{Precomputed projection matrix. Use \code{precompute_projection} to generate it. If \code{NULL}, then the identity covariance structure will be assumed, and the projection will be computed using the structure of the design's blocks.} -\item{block_col}{Column name of the design's block factor. Used when +\item{block_column}{Column name of the design's block factor. Used when \code{L_matrix} isn't supplied.} + +\item{...}{Extra parameters passed from \code{speed}.} +} +\value{ +A named list with \code{score}, \code{info_matrix}, +\code{eigenvalues}, \code{criterion}. } \description{ Creates an objective function that optimises experimental designs using the @@ -49,4 +49,53 @@ optimisation. \details{ This function computes the treatment information matrix: \deqn{I = X_1^\intercal L X_1}{I = X₁ᵀ L X₁} +Where \eqn{X_1}{X₁} is the treatment design matrix, and \eqn{L} is the +projection that removes nuisance fixed effects from the GLS's inverse +covariance: +\deqn{L = \Sigma^{-1} - \Sigma^{-1} X_2 \left( X_2^\intercal \Sigma^{-1} X_2 +\right)^{-1}}{L = Σ⁻¹ - Σ⁻¹ X₂ (X₂ᵀ Σ⁻¹ X₂)⁻¹} +The user specifies the spatial covariance \eqn{\Sigma}{Σ} they intend to use +at the time of analysis, e.g. lag-1 autoregressive \eqn{\text{AR}_1 \otimes +\text{AR}_1}{AR₁ ⊗ AR₁}, and this objective will optimise under that +structure. +} +\examples{ +# Small RCBD layout: 6 treatments in 4 blocks of 6 plots +df <- initialise_design_df( + items = 6, nrows = 4, ncols = 6, + block_nrows = 1, block_ncols = 6 +) + +# Non-spatial: identity covariance +result <- speed( + df, + swap = "treatment", + swap_within = "block", + obj_function = objective_function_info, + criterion = "A", + seed = 42, + quiet = TRUE +) + +# Spatial: AR(1) x AR(1) +Sigma <- cor_ar1_ar1( + n_rows = 4, n_cols = 6, + rho_row = 0.6, rho_col = 0.3 +) +L <- compute_L_projection(df, Sigma, block_column = "block") +result_spatial <- speed( + df, + swap = "treatment", + swap_within = "block", + obj_function = objective_function_info, + L_matrix = L, + criterion = "A", + optimise_params = optim_params(random_initialisation = TRUE), + seed = 42, + quiet = TRUE +) + +# Inspect the optimised design +calc_info_matrix(result_spatial$design_df, L_matrix = L) + } From c292872895f9392a7a6fb439d323dd1fc540753a Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Fri, 1 May 2026 11:16:38 +0800 Subject: [PATCH 09/25] fix indenting --- R/objectives.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/objectives.R b/R/objectives.R index 59a01b51..f4bbc3db 100644 --- a/R/objectives.R +++ b/R/objectives.R @@ -403,7 +403,7 @@ calculate_efficiency_factors <- function( #' #' @export cor_ar1 <- function(n, rho) { - rho^abs(outer(seq_len(n), seq_len(n), "-")) + rho^abs(outer(seq_len(n), seq_len(n), "-")) } From 179b4847e08f83d5c2b85e9c1625cbfbf6e695c6 Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Fri, 1 May 2026 11:18:16 +0800 Subject: [PATCH 10/25] fix some lintr stuff --- R/objectives.R | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/R/objectives.R b/R/objectives.R index f4bbc3db..9fd72cb7 100644 --- a/R/objectives.R +++ b/R/objectives.R @@ -5,13 +5,16 @@ #' effects, and takes an optional spatial covariance structure for spatial #' optimisation. #' -#' @param layout_df Data frame representing the spatial layout of the experiment. +#' @param layout_df Data frame representing the spatial layout of the +#' experiment. #' @param swap Column name to swap, usually the treatment. #' @param spatial_cols Column name of the spatial factors. #' @param criterion Either \code{"A"} or \code{"D"}, representing A or D #' optimality. -#' - A-optimality: Minimises \eqn{\mathrm{tr} \left( \mathcal{I}^- \right)}{tr(I⁻)}. -#' - D-optimality: Minimises \eqn{-\log \left| \mathcal{I} \right|}{-log(|I|)} +#' - A-optimality: Minimises \eqn{\mathrm{tr} \left( \mathcal{I}^- +#' \right)}{tr(I⁻)}. +#' - D-optimality: Minimises \eqn{-\log \left| \mathcal{I} \right|}{- +#' log(|I|)} #' @param L_matrix Precomputed projection matrix. Use #' \code{precompute_projection} to generate it. If \code{NULL}, then the #' identity covariance structure will be assumed, and the projection will be @@ -194,9 +197,11 @@ objective_function_info <- function( #' This is the projection matrix that removes nuisance effects from the GLS's #' covariance #' -#' @param layout_df Data frame representing the spatial layout of the experiment. +#' @param layout_df Data frame representing the spatial layout of the +#' experiment. #' @param Sigma Covariance structure to use. -#' @param block_column Column name of the design's block factor in \code{layout_df}. +#' @param block_column Column name of the design's block factor in +#' \code{layout_df}. #' #' @return \eqn{(n \times n)} numeric matrix. #' @@ -245,7 +250,8 @@ compute_L_projection <- function( #' #' Calculate the Fisher information in the experimental design #' -#' @param layout_df Data frame representing the spatial layout of the experiment. +#' @param layout_df Data frame representing the spatial layout of the +#' experiment. #' @param treatment_column Column name containing the design's treatments in #' \code{layout_df}. #' @param L_matrix Precomputed projection matrix from @@ -296,7 +302,8 @@ calc_info_matrix <- function( #' Calculate incidence matrix #' -#' @param layout_df Data frame representing the spatial layout of the experiment. +#' @param layout_df Data frame representing the spatial layout of the +#' experiment. #' @param treatment_column Column name containing the design's treatments in #' \code{layout_df}. #' @param block_column Column name containing the designs block in @@ -347,7 +354,8 @@ calc_concurrence_matrix <- function( #' Calculate canonical efficiency factors #' -#' @param layout_df Data frame representing the spatial layout of the experiment. +#' @param layout_df Data frame representing the spatial layout of the +#' experiment. #' @param treatment_column Column name containing the design's treatments in #' \code{layout_df}. #' @param L_matrix Precomputed projection matrix from From c89070a19147e22f3e6bc4d7f4e1736b4f26728e Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Tue, 30 Jun 2026 11:46:57 +0800 Subject: [PATCH 11/25] fix some documentation, update _pkgdown.yml --- R/objectives.R | 4 ++-- _pkgdown.yml | 7 +++++++ man/calc_incidence_matrix.Rd | 3 ++- man/calc_info_matrix.Rd | 3 ++- man/calculate_efficiency_factors.Rd | 3 ++- man/compute_L_projection.Rd | 6 ++++-- man/objective_function_info.Rd | 11 +++++++---- 7 files changed, 26 insertions(+), 11 deletions(-) diff --git a/R/objectives.R b/R/objectives.R index 9fd72cb7..a89a7b5d 100644 --- a/R/objectives.R +++ b/R/objectives.R @@ -16,7 +16,7 @@ #' - D-optimality: Minimises \eqn{-\log \left| \mathcal{I} \right|}{- #' log(|I|)} #' @param L_matrix Precomputed projection matrix. Use -#' \code{precompute_projection} to generate it. If \code{NULL}, then the +#' \code{compute_L_projection} to generate it. If \code{NULL}, then the #' identity covariance structure will be assumed, and the projection will be #' computed using the structure of the design's blocks. #' @param block_column Column name of the design's block factor. Used when @@ -190,7 +190,7 @@ objective_function_info <- function( list(info = info, v = v, trt_levels = trt_levels) } -# Helper functions +# Information matrix diagnostics and covariance utilities #' Compute L projection #' diff --git a/_pkgdown.yml b/_pkgdown.yml index f2a3ae6a..d1e7d359 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -15,9 +15,16 @@ reference: - subtitle: Calculation functions desc: Functions that calculate values for the objective functions - contents: + - starts_with("calc_") - starts_with("calculate") - get_edges - get_vertices + - subtitle: Spatial covariance utilities + desc: Functions for constructing spatial covariance inputs for Fisher information objectives + - contents: + - compute_L_projection + - cor_ar1 + - cor_ar1_ar1 - title: Plotting desc: Functions for checking designs. - contents: diff --git a/man/calc_incidence_matrix.Rd b/man/calc_incidence_matrix.Rd index 8f113bbf..1e88f293 100644 --- a/man/calc_incidence_matrix.Rd +++ b/man/calc_incidence_matrix.Rd @@ -11,7 +11,8 @@ calc_incidence_matrix( ) } \arguments{ -\item{layout_df}{Data frame representing the spatial layout of the experiment.} +\item{layout_df}{Data frame representing the spatial layout of the +experiment.} \item{treatment_column}{Column name containing the design's treatments in \code{layout_df}.} diff --git a/man/calc_info_matrix.Rd b/man/calc_info_matrix.Rd index 5887f425..223f2557 100644 --- a/man/calc_info_matrix.Rd +++ b/man/calc_info_matrix.Rd @@ -12,7 +12,8 @@ calc_info_matrix( ) } \arguments{ -\item{layout_df}{Data frame representing the spatial layout of the experiment.} +\item{layout_df}{Data frame representing the spatial layout of the +experiment.} \item{treatment_column}{Column name containing the design's treatments in \code{layout_df}.} diff --git a/man/calculate_efficiency_factors.Rd b/man/calculate_efficiency_factors.Rd index cadc96f6..4cc9f849 100644 --- a/man/calculate_efficiency_factors.Rd +++ b/man/calculate_efficiency_factors.Rd @@ -12,7 +12,8 @@ calculate_efficiency_factors( ) } \arguments{ -\item{layout_df}{Data frame representing the spatial layout of the experiment.} +\item{layout_df}{Data frame representing the spatial layout of the +experiment.} \item{treatment_column}{Column name containing the design's treatments in \code{layout_df}.} diff --git a/man/compute_L_projection.Rd b/man/compute_L_projection.Rd index 0d401ea0..f8210b77 100644 --- a/man/compute_L_projection.Rd +++ b/man/compute_L_projection.Rd @@ -7,11 +7,13 @@ compute_L_projection(layout_df, Sigma, block_column = "block") } \arguments{ -\item{layout_df}{Data frame representing the spatial layout of the experiment.} +\item{layout_df}{Data frame representing the spatial layout of the +experiment.} \item{Sigma}{Covariance structure to use.} -\item{block_column}{Column name of the design's block factor in \code{layout_df}.} +\item{block_column}{Column name of the design's block factor in +\code{layout_df}.} } \value{ \eqn{(n \times n)} numeric matrix. diff --git a/man/objective_function_info.Rd b/man/objective_function_info.Rd index 0f0993d3..0af34d25 100644 --- a/man/objective_function_info.Rd +++ b/man/objective_function_info.Rd @@ -15,7 +15,8 @@ objective_function_info( ) } \arguments{ -\item{layout_df}{Data frame representing the spatial layout of the experiment.} +\item{layout_df}{Data frame representing the spatial layout of the +experiment.} \item{swap}{Column name to swap, usually the treatment.} @@ -23,11 +24,13 @@ objective_function_info( \item{criterion}{Either \code{"A"} or \code{"D"}, representing A or D optimality. -- A-optimality: Minimises \eqn{\mathrm{tr} \left( \mathcal{I}^- \right)}{tr(I⁻)}. - - D-optimality: Minimises \eqn{-\log \left| \mathcal{I} \right|}{-log(|I|)}} +- A-optimality: Minimises \eqn{\mathrm{tr} \left( \mathcal{I}^- + \right)}{tr(I⁻)}. + - D-optimality: Minimises \eqn{-\log \left| \mathcal{I} \right|}{- + log(|I|)}} \item{L_matrix}{Precomputed projection matrix. Use -\code{precompute_projection} to generate it. If \code{NULL}, then the +\code{compute_L_projection} to generate it. If \code{NULL}, then the identity covariance structure will be assumed, and the projection will be computed using the structure of the design's blocks.} From d51d185507175b2c22686aaf226b5d92bb9942f5 Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Tue, 30 Jun 2026 11:58:48 +0800 Subject: [PATCH 12/25] fixup! fix some documentation, update _pkgdown.yml --- NAMESPACE | 4 ---- R/objectives.R | 11 ++++------- _pkgdown.yml | 1 - man/calc_concurrence_matrix.Rd | 1 + man/calc_incidence_matrix.Rd | 1 + man/calc_info_matrix.Rd | 1 + man/calculate_efficiency_factors.Rd | 1 + man/cor_ar1.Rd | 19 +++++++++++++++++++ man/cor_ar1_ar1.Rd | 24 ++++++++++++++++++++++++ man/objective_function_info.Rd | 3 --- 10 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 man/cor_ar1.Rd create mode 100644 man/cor_ar1_ar1.Rd diff --git a/NAMESPACE b/NAMESPACE index 28c7a6a6..d5b9e18c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,14 +4,10 @@ S3method(autoplot,design) S3method(print,design) export(add_buffers) export(autoplot) -export(calc_concurrence_matrix) -export(calc_incidence_matrix) -export(calc_info_matrix) export(calculate_adjacency_score) export(calculate_balance_score) export(calculate_ed) export(calculate_efficiency_factor) -export(calculate_efficiency_factors) export(calculate_nb) export(compute_L_projection) export(cor_ar1) diff --git a/R/objectives.R b/R/objectives.R index a89a7b5d..ab90f0cc 100644 --- a/R/objectives.R +++ b/R/objectives.R @@ -72,9 +72,6 @@ #' quiet = TRUE #' ) #' -#' # Inspect the optimised design -#' calc_info_matrix(result_spatial$design_df, L_matrix = L) -#' #' @return A named list with \code{score}, \code{info_matrix}, #' \code{eigenvalues}, \code{criterion}. #' @@ -259,7 +256,7 @@ compute_L_projection <- function( #' @param block_column Column name containing the designs block in #' \code{layout_df}. #' -#' @export +#' @keywords internal calc_info_matrix <- function( layout_df, treatment_column = "treatment", @@ -312,7 +309,7 @@ calc_info_matrix <- function( #' @return \eqn{v \times b} matrix of integers, with treatment levels as row #' names, and block levels as column names. #' -#' @export +#' @keywords internal calc_incidence_matrix <- function( layout_df, treatment_column = "treatment", @@ -340,7 +337,7 @@ calc_incidence_matrix <- function( #' #' @return Symmetric \eqn{N N^\intercal}{N Nᵀ} matrix. #' -#' @export +#' @keywords internal calc_concurrence_matrix <- function( layout_df, treatment_column = "treatment", @@ -365,7 +362,7 @@ calc_concurrence_matrix <- function( #' #' @return A list with \code{efficiency_factors}, \code{E}, \code{replication}. #' -#' @export +#' @keywords internal calculate_efficiency_factors <- function( layout_df, treatment_column = "treatment", diff --git a/_pkgdown.yml b/_pkgdown.yml index 1221ccfc..8291bb65 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -15,7 +15,6 @@ reference: - subtitle: Calculation functions desc: Functions that calculate values for the objective functions - contents: - - starts_with("calc_") - starts_with("calculate") - get_edges - get_vertices diff --git a/man/calc_concurrence_matrix.Rd b/man/calc_concurrence_matrix.Rd index 463ee5c7..a4b6ff20 100644 --- a/man/calc_concurrence_matrix.Rd +++ b/man/calc_concurrence_matrix.Rd @@ -26,3 +26,4 @@ Symmetric \eqn{N N^\intercal}{N Nᵀ} matrix. \description{ Calculate concurrence matrix } +\keyword{internal} diff --git a/man/calc_incidence_matrix.Rd b/man/calc_incidence_matrix.Rd index 1e88f293..37683300 100644 --- a/man/calc_incidence_matrix.Rd +++ b/man/calc_incidence_matrix.Rd @@ -27,3 +27,4 @@ names, and block levels as column names. \description{ Calculate incidence matrix } +\keyword{internal} diff --git a/man/calc_info_matrix.Rd b/man/calc_info_matrix.Rd index 223f2557..7c2b3e04 100644 --- a/man/calc_info_matrix.Rd +++ b/man/calc_info_matrix.Rd @@ -27,3 +27,4 @@ experiment.} \description{ Calculate the Fisher information in the experimental design } +\keyword{internal} diff --git a/man/calculate_efficiency_factors.Rd b/man/calculate_efficiency_factors.Rd index 4cc9f849..901894ba 100644 --- a/man/calculate_efficiency_factors.Rd +++ b/man/calculate_efficiency_factors.Rd @@ -30,3 +30,4 @@ A list with \code{efficiency_factors}, \code{E}, \code{replication}. \description{ Calculate canonical efficiency factors } +\keyword{internal} diff --git a/man/cor_ar1.Rd b/man/cor_ar1.Rd new file mode 100644 index 00000000..e010bb4d --- /dev/null +++ b/man/cor_ar1.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/objectives.R +\name{cor_ar1} +\alias{cor_ar1} +\title{Construct a 1 dimensional lag-1 autoregressive covariance} +\usage{ +cor_ar1(n, rho) +} +\arguments{ +\item{n}{Size of the covariance vector to generate} + +\item{rho}{Correlation parameter} +} +\value{ +A symmetric \eqn{(n \times n)} correlation matrix. +} +\description{ +Construct a 1 dimensional lag-1 autoregressive covariance +} diff --git a/man/cor_ar1_ar1.Rd b/man/cor_ar1_ar1.Rd new file mode 100644 index 00000000..cb0332c5 --- /dev/null +++ b/man/cor_ar1_ar1.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/objectives.R +\name{cor_ar1_ar1} +\alias{cor_ar1_ar1} +\title{Construct a 2 dimensional lag-1 autoregressive covariance} +\usage{ +cor_ar1_ar1(n_rows, n_cols, rho_row, rho_col) +} +\arguments{ +\item{n_rows}{Number of rows in the design.} + +\item{n_cols}{Number of columns in the design.} + +\item{rho_row}{Correlation parameter along the row direction.} + +\item{rho_col}{Correlation parameter along the column direction.} +} +\value{ +A symmetric \eqn{(\text{n_rows} \cdot \text{n_cols}) \times + (\text{n_rows} \cdot \text{n_cols})} correlation matrix. +} +\description{ +Construct a 2 dimensional lag-1 autoregressive covariance +} diff --git a/man/objective_function_info.Rd b/man/objective_function_info.Rd index 0af34d25..9979fad8 100644 --- a/man/objective_function_info.Rd +++ b/man/objective_function_info.Rd @@ -98,7 +98,4 @@ result_spatial <- speed( quiet = TRUE ) -# Inspect the optimised design -calc_info_matrix(result_spatial$design_df, L_matrix = L) - } From 04f093c5c3f434e6979b5425058cbf52fb3abf0c Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Tue, 18 Aug 2026 15:50:58 +0800 Subject: [PATCH 13/25] Rename objective, cache some calcs, remove old helpers, address other wasin things --- R/objective_fisher.R | 511 ++++++++++++++++++ R/objectives.R | 431 --------------- man/calc_concurrence_matrix.Rd | 29 - man/calc_incidence_matrix.Rd | 30 - man/calc_info_matrix.Rd | 30 - man/calculate_efficiency_factors.Rd | 33 -- man/compute_L_projection.Rd | 18 +- man/cor_ar1.Rd | 2 +- man/cor_ar1_ar1.Rd | 2 +- man/objective_function_info.Rd | 47 +- tests/testthat/test-compute_L_projection.R | 48 ++ tests/testthat/test-cor_ar1.R | 15 + tests/testthat/test-cor_ar1_ar1.R | 14 + tests/testthat/test-objective_fisher.R | 327 +++++++++++ tests/testthat/test-objective_function_info.R | 378 ------------- 15 files changed, 970 insertions(+), 945 deletions(-) create mode 100644 R/objective_fisher.R delete mode 100644 R/objectives.R delete mode 100644 man/calc_concurrence_matrix.Rd delete mode 100644 man/calc_incidence_matrix.Rd delete mode 100644 man/calc_info_matrix.Rd delete mode 100644 man/calculate_efficiency_factors.Rd create mode 100644 tests/testthat/test-compute_L_projection.R create mode 100644 tests/testthat/test-cor_ar1.R create mode 100644 tests/testthat/test-cor_ar1_ar1.R create mode 100644 tests/testthat/test-objective_fisher.R delete mode 100644 tests/testthat/test-objective_function_info.R diff --git a/R/objective_fisher.R b/R/objective_fisher.R new file mode 100644 index 00000000..21c6da88 --- /dev/null +++ b/R/objective_fisher.R @@ -0,0 +1,511 @@ +#' Objective function using the treatment information matrix +#' +#' Creates an objective function that optimises experimental designs using the +#' Fisher information for treatment contrasts after adjusting for nuisance +#' effects, and takes an optional spatial covariance structure for spatial +#' optimisation. +#' +#' @param layout_df Data frame representing the spatial layout of the +#' experiment. +#' @param swap Column name to swap, usually the treatment. +#' @param spatial_cols Column name of the spatial factors. +#' @param criterion Either \code{"A"} or \code{"D"}, representing A or D +#' optimality. +#' - A-optimality: Minimises \eqn{\mathrm{tr} \left( \mathcal{I}^- +#' \right)}{tr(I⁻)}. +#' - D-optimality: Minimises \eqn{-\log \left| \mathcal{I} \right|}{- +#' log(|I|)} +#' @param L_matrix Optional precomputed projection matrix. This is an advanced +#' alternative to `Sigma`; the two cannot be supplied together. +#' @param Sigma Optional covariance matrix whose rows and columns follow the row +#' order of `layout_df`. The projection is computed on the first objective +#' call and reused during optimisation. If both `Sigma` and `L_matrix` are +#' `NULL`, identity covariance is assumed. +#' @param contrast_matrix Numeric contrast matrix with one column per treatment +#' level. Column names, when supplied, must match the treatment levels. Only +#' these contrasts are required to be estimable and contribute to the +#' optimality criterion. The default targets the complete treatment-contrast +#' space. +#' @param block_column Column name of the design's block factor. Used when +#' \code{L_matrix} isn't supplied. +#' @param nuisance_formula Optional one-sided formula describing nuisance +#' effects. Used when \code{L_matrix} is not supplied. If omitted, +#' \code{block_column} is treated as a factor. +#' @param tolerance Relative numerical tolerance for rank and estimability +#' checks. +#' @param current_score_obj The current objective result supplied by [speed()] +#' after the initial call. Used to reuse invariant matrix calculations. +#' @param swapped_items The treatments swapped by [speed()]. Changed plot rows +#' are identified from the cached and proposed allocations so repeated +#' treatments and multi-swaps are handled exactly. +#' @param ... Extra parameters passed from \code{speed}. +#' +#' @details +#' This function computes the treatment information matrix: +#' \deqn{I = X_1^\intercal L X_1}{I = X₁ᵀ L X₁} +#' Where \eqn{X_1}{X₁} is the treatment design matrix, and \eqn{L} is the +#' projection that removes nuisance fixed effects from the GLS's inverse +#' covariance: +#' \deqn{L = \Sigma^{-1} - \Sigma^{-1} X_2 \left( X_2^\intercal \Sigma^{-1} X_2 +#' \right)^{-1} X_2^\intercal \Sigma^{-1}}{L = Σ⁻¹ - Σ⁻¹ X₂ +#' (X₂ᵀ Σ⁻¹ X₂)⁻¹ X₂ᵀ Σ⁻¹} +#' The user specifies the spatial covariance \eqn{\Sigma}{Σ} they intend to use +#' at the time of analysis, e.g. lag-1 autoregressive \eqn{\text{AR}_1 \otimes +#' \text{AR}_1}{AR₁ ⊗ AR₁}, and this objective will optimise under that +#' structure. +#' +#' @examples +#' # Small RCBD layout: 6 treatments in 4 blocks of 6 plots +#' df <- initialise_design_df( +#' items = 6, nrows = 4, ncols = 6, +#' block_nrows = 1, block_ncols = 6 +#' ) +#' +#' # Non-spatial: identity covariance +#' result <- speed( +#' df, +#' swap = "treatment", +#' swap_within = "block", +#' obj_function = objective_function_info, +#' criterion = "A", +#' seed = 42, +#' quiet = TRUE +#' ) +#' +#' # Spatial: AR(1) x AR(1) +#' Sigma <- cor_ar1_ar1( +#' n_rows = 4, n_cols = 6, +#' rho_row = 0.6, rho_col = 0.3 +#' ) +#' result_spatial <- speed( +#' df, +#' swap = "treatment", +#' swap_within = "block", +#' obj_function = objective_function_info, +#' Sigma = Sigma, +#' criterion = "A", +#' optimise_params = optim_params(random_initialisation = TRUE), +#' seed = 42, +#' quiet = TRUE +#' ) +#' +#' @return A named list with \code{score}, \code{info_matrix}, +#' \code{eigenvalues}, contrast diagnostics, and \code{criterion}. +#' +#' @export +objective_function_info <- function( + layout_df, + swap, + spatial_cols, + criterion = c("A", "D"), + L_matrix = NULL, + Sigma = NULL, + contrast_matrix = NULL, + block_column = "block", + nuisance_formula = NULL, + tolerance = 1e-9, + current_score_obj = NULL, + swapped_items = NULL, + ... +) { + criterion <- match.arg(criterion) + + fisher_cache <- NULL + if (!is.null(swapped_items)) { + fisher_cache <- attr(current_score_obj, "fisher_cache", exact = TRUE) + } + ci <- .compute_info( + layout_df, + swap, + Sigma, + L_matrix, + block_column, + nuisance_formula, + tolerance, + fisher_cache + ) + diagnostics <- .information_criteria( + ci$info, ci$trt_levels, contrast_matrix, tolerance + ) + score <- diagnostics[[paste0(criterion, "_value")]] + if (!is.finite(score)) score <- 1e10 + + result <- list( + score = score, + info_matrix = ci$info, + eigenvalues = diagnostics$eigenvalues, + contrast_matrix = diagnostics$contrast_matrix, + contrast_covariance = diagnostics$contrast_covariance, + estimable = diagnostics$estimable, + rank = diagnostics$rank, + criterion = criterion, + A_value = diagnostics$A_value, + D_value = diagnostics$D_value + ) + attr(result, "fisher_cache") <- ci$cache + return(result) +} + +#' Build the treatment indicator matrix X1 +#' @noRd +.build_treatment_matrix <- function(treatments, trt_levels, n, v) { + X1 <- matrix(0, n, v) + trt_idx <- match(treatments, trt_levels) + if (anyNA(trt_idx)) stop("Treatment allocations cannot contain missing values.", call. = FALSE) + X1[cbind(seq_len(n), trt_idx)] <- 1 + return(X1) +} + +#' Prepare a requested contrast space +#' @noRd +.prepare_contrast_matrix <- function(contrast_matrix, trt_levels, tolerance) { + v <- length(trt_levels) + if (is.null(contrast_matrix)) { + if (v < 2L) { + return(matrix(numeric(0), nrow = 0L, ncol = v)) + } + basis <- qr.Q(qr(stats::contr.helmert(v)), complete = FALSE) + contrast_matrix <- t(basis) + colnames(contrast_matrix) <- trt_levels + } else { + if (!is.matrix(contrast_matrix) || !is.numeric(contrast_matrix)) { + stop("`contrast_matrix` must be a numeric matrix.", call. = FALSE) + } + if (any(!is.finite(contrast_matrix))) { + stop("`contrast_matrix` must contain only finite values.", call. = FALSE) + } + if (is.null(colnames(contrast_matrix))) { + if (ncol(contrast_matrix) != v) { + stop("`contrast_matrix` must have one column per treatment.", call. = FALSE) + } + colnames(contrast_matrix) <- trt_levels + } else { + missing <- setdiff(trt_levels, colnames(contrast_matrix)) + extra <- setdiff(colnames(contrast_matrix), trt_levels) + if (length(missing) > 0L || length(extra) > 0L) { + stop("Contrast columns must match the treatment levels.", call. = FALSE) + } + contrast_matrix <- contrast_matrix[, trt_levels, drop = FALSE] + } + } + + if (nrow(contrast_matrix) > 0L && qr(t(contrast_matrix), tol = tolerance)$rank < nrow(contrast_matrix)) { + stop("Rows of `contrast_matrix` must be linearly independent.", call. = FALSE) + } + return(contrast_matrix) +} + +#' Calculate information criteria for a requested contrast space +#' @noRd +.information_criteria <- function(info, trt_levels, contrast_matrix, tolerance) { + info <- (info + t(info)) / 2 + eig <- eigen(info, symmetric = TRUE) + scale <- max(abs(eig$values)) + keep <- if (scale == 0) rep(FALSE, length(eig$values)) else eig$values > scale * tolerance + rank <- sum(keep) + pos_eig <- sort(eig$values[keep], decreasing = TRUE) + + info_inverse <- matrix(0, nrow(info), ncol(info)) + if (rank > 0L) { + vectors <- eig$vectors[, keep, drop = FALSE] + info_inverse <- vectors %*% diag(1 / eig$values[keep], nrow = rank) %*% t(vectors) + } + + contrasts <- .prepare_contrast_matrix(contrast_matrix, trt_levels, tolerance) + projection <- info_inverse %*% info + residual <- contrasts - contrasts %*% projection + estimable <- nrow(contrasts) == 0L || + max(abs(residual)) <= tolerance * (1 + max(abs(contrasts))) + + contrast_covariance <- matrix(numeric(0), nrow = 0L, ncol = 0L) + A_value <- Inf + D_value <- Inf + if (estimable) { + contrast_covariance <- contrasts %*% info_inverse %*% t(contrasts) + contrast_covariance <- (contrast_covariance + t(contrast_covariance)) / 2 + if (nrow(contrasts) == 0L) { + A_value <- 0 + D_value <- 0 + } else { + contrast_eig <- eigen(contrast_covariance, symmetric = TRUE, only.values = TRUE)$values + contrast_scale <- max(abs(contrast_eig)) + if (all(contrast_eig > contrast_scale * tolerance)) { + A_value <- sum(diag(contrast_covariance)) + D_value <- sum(log(contrast_eig)) + } + } + } + + return(list( + eigenvalues = pos_eig, + rank = rank, + contrast_matrix = contrasts, + contrast_covariance = contrast_covariance, + estimable = estimable, + A_value = A_value, + D_value = D_value + )) +} + +#' Function to precompute \eqn{L} +#' +#' \eqn{L} is the projection matrix that removes nuisance effects under a +#' spatial correlation structure, given an \eqn{n \times n}{n * n} covariance +#' \eqn{\Sigma}{Sigma} and nuisance effects design \eqn{X_2}. +#' +#' This only depends on lambda and the block structure, so precompute this. +#' @noRd +.build_nuisance_matrix <- function(layout_df, block_column, nuisance_formula) { + if (is.null(nuisance_formula)) { + if (!block_column %in% names(layout_df)) { + return(matrix(1, nrow(layout_df), 1L)) + } + return(stats::model.matrix(~ 0 + block, data.frame(block = factor(layout_df[[block_column]])))) + } + if (!inherits(nuisance_formula, "formula") || length(nuisance_formula) != 2L) { + stop("`nuisance_formula` must be a one-sided formula.", call. = FALSE) + } + return(stats::model.matrix(nuisance_formula, layout_df)) +} + +#' Build a projection under identity covariance +#' @noRd +.build_L_from_df <- function(layout_df, block_column, n, nuisance_formula = NULL, tolerance = 1e-10) { + X2 <- .build_nuisance_matrix(layout_df, block_column, nuisance_formula) + crossprod_inverse <- pseudo_inverse(crossprod(X2), tolerance) + return(diag(n) - X2 %*% crossprod_inverse %*% t(X2)) +} + +#' Check whether a cached projection matches the requested projection +#' @noRd +.fisher_projection_matches <- function( + cache, + source, + input, + block_column, + nuisance_formula, + tolerance, + n +) { + matches <- is.list(cache) && + identical(cache$projection_source, source) && + identical(cache$projection_input, input) && + identical(cache$block_column, block_column) && + identical(cache$nuisance_formula, nuisance_formula) && + identical(cache$tolerance, tolerance) && + is.matrix(cache$L_matrix) && + identical(dim(cache$L_matrix), c(n, n)) + return(isTRUE(matches)) +} + +#' Check whether an information-matrix cache can be updated +#' @noRd +.fisher_cache_is_valid <- function(cache, swap, trt_levels, L_matrix, n, v) { + valid <- is.list(cache) && + identical(cache$swap, swap) && + identical(cache$trt_levels, trt_levels) && + length(cache$treatments) == n && + all(cache$treatments %in% trt_levels) && + is.matrix(cache$LX_matrix) && + identical(dim(cache$LX_matrix), c(n, v)) && + identical(cache$L_matrix, L_matrix) + return(isTRUE(valid)) +} + +#' Function for computing and caching the information matrix +#' @noRd +.compute_info <- function( + layout_df, + swap, + Sigma, + L_matrix, + block_column, + nuisance_formula = NULL, + tolerance = 1e-10, + cache = NULL +) { + treatments <- layout_df[[swap]] + trt_levels <- levels(factor(treatments)) + v <- length(trt_levels) + n <- nrow(layout_df) + treatment_labels <- as.character(treatments) + + if (!is.null(Sigma) && !is.null(L_matrix)) { + stop("Only one of `Sigma` and `L_matrix` can be supplied.", call. = FALSE) + } + + if (!is.null(L_matrix)) { + projection_source <- "L_matrix" + projection_input <- L_matrix + } else if (!is.null(Sigma)) { + projection_source <- "Sigma" + projection_input <- Sigma + if (.fisher_projection_matches( + cache, + projection_source, + projection_input, + block_column, + nuisance_formula, + tolerance, + n + )) { + L_matrix <- cache$L_matrix + } else { + L_matrix <- compute_L_projection( + layout_df, + Sigma, + block_column, + nuisance_formula, + tolerance + ) + } + } else { + projection_source <- "identity" + projection_input <- NULL + if (.fisher_projection_matches( + cache, + projection_source, + projection_input, + block_column, + nuisance_formula, + tolerance, + n + )) { + L_matrix <- cache$L_matrix + } else { + L_matrix <- .build_L_from_df( + layout_df, + block_column, + n, + nuisance_formula, + tolerance + ) + } + } + + if (!is.matrix(L_matrix) || !identical(dim(L_matrix), c(n, n))) { + stop("`L_matrix` must be an n by n matrix for `layout_df`.", call. = FALSE) + } + + X1 <- .build_treatment_matrix(treatment_labels, trt_levels, n, v) + if (.fisher_cache_is_valid(cache, swap, trt_levels, L_matrix, n, v)) { + changed <- which(cache$treatments != treatment_labels) + LX <- cache$LX_matrix + if (length(changed) > 0L) { + old_index <- match(cache$treatments[changed], trt_levels) + new_index <- match(treatment_labels[changed], trt_levels) + delta <- matrix(0, nrow = length(changed), ncol = v) + delta[cbind(seq_along(changed), old_index)] <- -1 + delta[cbind(seq_along(changed), new_index)] <- 1 + LX <- LX + L_matrix[, changed, drop = FALSE] %*% delta + } + } else { + LX <- L_matrix %*% X1 + } + + info <- crossprod(X1, LX) + info <- (info + t(info)) / 2 + dimnames(info) <- list(trt_levels, trt_levels) + + cache <- list( + swap = swap, + treatments = treatment_labels, + trt_levels = trt_levels, + L_matrix = L_matrix, + LX_matrix = LX, + projection_source = projection_source, + projection_input = projection_input, + block_column = block_column, + nuisance_formula = nuisance_formula, + tolerance = tolerance + ) + + return(list( + info = info, + v = v, + trt_levels = trt_levels, + cache = cache + )) +} + +# Covariance utilities + +#' Compute L projection +#' +#' This is the projection matrix that removes nuisance effects from the GLS's +#' covariance +#' +#' @param layout_df Data frame representing the spatial layout of the +#' experiment. +#' @param Sigma Covariance structure to use. Its rows and columns must follow +#' the row order of `layout_df`. +#' @param block_column Column name of the design's block factor in +#' \code{layout_df}. +#' @param nuisance_formula Optional one-sided formula describing nuisance +#' effects. If omitted, \code{block_column} is treated as a factor. +#' @param tolerance Numerical tolerance used for generalized inverses. +#' +#' @return \eqn{(n \times n)} numeric matrix. +#' +#' @export +compute_L_projection <- function( + layout_df, + Sigma, + block_column = "block", + nuisance_formula = NULL, + tolerance = 1e-10 +) { + n <- nrow(layout_df) + + if (!is.matrix(Sigma)) { + stop("Sigma must be a matrix") + } + if (!identical(dim(Sigma), c(n, n))) { + stop( + "Sigma matrix must have dimension equal ", + "to dimension of layout_df dataframe" + ) + } + if (!isSymmetric(Sigma, tol = 1e-8)) stop("Sigma must be symmetric") + X2 <- .build_nuisance_matrix(layout_df, block_column, nuisance_formula) + + Sigma_inv <- solve(Sigma) + SiX2 <- Sigma_inv %*% X2 + nuisance_inverse <- pseudo_inverse(crossprod(X2, SiX2), tolerance) + L <- Sigma_inv - SiX2 %*% nuisance_inverse %*% t(SiX2) + return((L + t(L)) / 2) +} + + +# Convenience correlation structure constructors + +#' Construct a 1 dimensional lag-1 autoregressive covariance +#' +#' @param n Size of the covariance vector to generate +#' @param rho Correlation parameter +#' +#' @return A symmetric \eqn{(n \times n)} correlation matrix. +#' +#' @export +cor_ar1 <- function(n, rho) { + return(rho^abs(outer(seq_len(n), seq_len(n), "-"))) +} + + +#' Construct a 2 dimensional lag-1 autoregressive covariance +#' +#' @param n_rows Number of rows in the design. +#' @param n_cols Number of columns in the design. +#' @param rho_row Correlation parameter along the row direction. +#' @param rho_col Correlation parameter along the column direction. +#' +#' @return A symmetric \eqn{(\text{n_rows} \cdot \text{n_cols}) \times +#' (\text{n_rows} \cdot \text{n_cols})} correlation matrix. +#' +#' @export +cor_ar1_ar1 <- function(n_rows, n_cols, rho_row, rho_col) { + return(kronecker( + cor_ar1(n_rows, rho_row), + cor_ar1(n_cols, rho_col) + )) +} diff --git a/R/objectives.R b/R/objectives.R deleted file mode 100644 index ab90f0cc..00000000 --- a/R/objectives.R +++ /dev/null @@ -1,431 +0,0 @@ -#' Objective function using the treatment information matrix -#' -#' Creates an objective function that optimises experimental designs using the -#' Fisher information for treatment contrasts after adjusting for nuisance -#' effects, and takes an optional spatial covariance structure for spatial -#' optimisation. -#' -#' @param layout_df Data frame representing the spatial layout of the -#' experiment. -#' @param swap Column name to swap, usually the treatment. -#' @param spatial_cols Column name of the spatial factors. -#' @param criterion Either \code{"A"} or \code{"D"}, representing A or D -#' optimality. -#' - A-optimality: Minimises \eqn{\mathrm{tr} \left( \mathcal{I}^- -#' \right)}{tr(I⁻)}. -#' - D-optimality: Minimises \eqn{-\log \left| \mathcal{I} \right|}{- -#' log(|I|)} -#' @param L_matrix Precomputed projection matrix. Use -#' \code{compute_L_projection} to generate it. If \code{NULL}, then the -#' identity covariance structure will be assumed, and the projection will be -#' computed using the structure of the design's blocks. -#' @param block_column Column name of the design's block factor. Used when -#' \code{L_matrix} isn't supplied. -#' @param ... Extra parameters passed from \code{speed}. -#' -#' @details -#' This function computes the treatment information matrix: -#' \deqn{I = X_1^\intercal L X_1}{I = X₁ᵀ L X₁} -#' Where \eqn{X_1}{X₁} is the treatment design matrix, and \eqn{L} is the -#' projection that removes nuisance fixed effects from the GLS's inverse -#' covariance: -#' \deqn{L = \Sigma^{-1} - \Sigma^{-1} X_2 \left( X_2^\intercal \Sigma^{-1} X_2 -#' \right)^{-1}}{L = Σ⁻¹ - Σ⁻¹ X₂ (X₂ᵀ Σ⁻¹ X₂)⁻¹} -#' The user specifies the spatial covariance \eqn{\Sigma}{Σ} they intend to use -#' at the time of analysis, e.g. lag-1 autoregressive \eqn{\text{AR}_1 \otimes -#' \text{AR}_1}{AR₁ ⊗ AR₁}, and this objective will optimise under that -#' structure. -#' -#' @examples -#' # Small RCBD layout: 6 treatments in 4 blocks of 6 plots -#' df <- initialise_design_df( -#' items = 6, nrows = 4, ncols = 6, -#' block_nrows = 1, block_ncols = 6 -#' ) -#' -#' # Non-spatial: identity covariance -#' result <- speed( -#' df, -#' swap = "treatment", -#' swap_within = "block", -#' obj_function = objective_function_info, -#' criterion = "A", -#' seed = 42, -#' quiet = TRUE -#' ) -#' -#' # Spatial: AR(1) x AR(1) -#' Sigma <- cor_ar1_ar1( -#' n_rows = 4, n_cols = 6, -#' rho_row = 0.6, rho_col = 0.3 -#' ) -#' L <- compute_L_projection(df, Sigma, block_column = "block") -#' result_spatial <- speed( -#' df, -#' swap = "treatment", -#' swap_within = "block", -#' obj_function = objective_function_info, -#' L_matrix = L, -#' criterion = "A", -#' optimise_params = optim_params(random_initialisation = TRUE), -#' seed = 42, -#' quiet = TRUE -#' ) -#' -#' @return A named list with \code{score}, \code{info_matrix}, -#' \code{eigenvalues}, \code{criterion}. -#' -#' @export -objective_function_info <- function( - layout_df, - swap, - spatial_cols, - criterion = c("A", "D"), - L_matrix = NULL, - block_column = "block", - ... -) { - criterion <- match.arg(criterion) - - ci <- .compute_info(layout_df, swap, L_matrix, block_column) - info <- ci$info - v <- ci$v - - ## get positive eigenvals from info matrix - eig <- eigen(info, symmetric = TRUE, only.values = TRUE)$values - max_eig <- max(eig) - if (max_eig <= 0) { - score <- 1e10 - pos_eig <- numeric(0) - } else { - pos_eig <- eig[eig > max_eig * 1e-10] - ## if design is disconnected, penalise greatly - ## otherwise A or D - if (length(pos_eig) < v - 1) { - score <- 1e10 - } else { - score <- switch(criterion, - A = sum(1 / pos_eig), - D = -sum(log(pos_eig)) - ) - if (!is.finite(score)) score <- 1e10 - } - } - - return(list( - score = score, - info_matrix = info, - eigenvalues = sort(pos_eig, decreasing = TRUE), - criterion = criterion - )) -} - -#' Build the treatment indicator matrix X1 -#' @noRd -.build_treatment_matrix <- function(treatments, trt_levels, n, v) { - X1 <- matrix(0, n, v) - trt_idx <- match(treatments, trt_levels) - for (i in seq_len(n)) { - X1[i, trt_idx[i]] <- 1 - } - return(X1) -} - -#' Function to precompute \eqn{L} -#' -#' \eqn{L} is the projection matrix that removes nuisance effects under a -#' spatial correlation structure, given an \eqn{n \times n}{n * n} covariance -#' \eqn{\Sigma}{Sigma} and nuisance effects design \eqn{X_2}. -#' -#' This only depends on lambda and the block structure, so precompute this. -#' @noRd -.build_L_from_df <- function(layout_df, block_column, n) { - if (!block_column %in% names(layout_df)) { - ## L = I - (1/n) ones_matrix - return(diag(n) - matrix(1 / n, n, n)) - } - - blocks <- factor(layout_df[[block_column]]) - b <- nlevels(blocks) - - X2 <- matrix(0, n, b) - for (j in seq_len(b)) { - X2[blocks == levels(blocks)[j], j] <- 1 - } - - ## L = I - X2 (X2t X2)^{-1} X2t - X2tX2_inv <- diag(1 / colSums(X2), nrow = b) - diag(n) - X2 %*% X2tX2_inv %*% t(X2) -} - -#' Function for computing the information matrix -#' @noRd -.compute_info <- function( - layout_df, - swap, - L_matrix, - block_column -) { - ## a lot of the args come from the design now - treatments <- layout_df[[swap]] - trt_levels <- levels(factor(treatments)) - v <- length(trt_levels) - n <- nrow(layout_df) - - ## L - ### projection matrix - if (is.null(L_matrix)) { - L_matrix <- .build_L_from_df(layout_df, block_column, n) - } - - ## X1 - ### treatment design matrix. - X1 <- .build_treatment_matrix(treatments, trt_levels, n, v) - ## information matrix I = X1t L X1 - info <- t(X1) %*% L_matrix %*% X1 - - list(info = info, v = v, trt_levels = trt_levels) -} - -# Information matrix diagnostics and covariance utilities - -#' Compute L projection -#' -#' This is the projection matrix that removes nuisance effects from the GLS's -#' covariance -#' -#' @param layout_df Data frame representing the spatial layout of the -#' experiment. -#' @param Sigma Covariance structure to use. -#' @param block_column Column name of the design's block factor in -#' \code{layout_df}. -#' -#' @return \eqn{(n \times n)} numeric matrix. -#' -#' @export -compute_L_projection <- function( - layout_df, - Sigma, - block_column = "block" -) { - n <- nrow(layout_df) - - ## arg checks - if (!is.matrix(Sigma)) stop("Sigma must be a matrix") - if (nrow(Sigma) != n) { - stop( - "Sigma matrix must have dimension equal ", - "to dimension of layout_df dataframe") - } - if (ncol(Sigma) != n) { - stop( - "Sigma matrix must have dimension equal ", - "to dimension of layout_df dataframe" - ) - } - if (!isSymmetric(Sigma, tol = 1e-8)) stop("Sigma must be symmetric") - if (!(block_column %in% names(layout_df))) { - stop("Block column name not in layout_df dataframe") - } - - blocks <- factor(layout_df[[block_column]]) - b <- nlevels(blocks) - - ## X2 - ### block indicator matrix with the intercept removed - X2 <- matrix(0, n, b) - for (j in seq_len(b)) { - X2[blocks == levels(blocks)[j], j] <- 1 - } - - Sigma_inv <- solve(Sigma) - SiX2 <- Sigma_inv %*% X2 - return(Sigma_inv - SiX2 %*% solve(t(X2) %*% SiX2) %*% t(SiX2)) -} - -#' Calculate info matrix -#' -#' Calculate the Fisher information in the experimental design -#' -#' @param layout_df Data frame representing the spatial layout of the -#' experiment. -#' @param treatment_column Column name containing the design's treatments in -#' \code{layout_df}. -#' @param L_matrix Precomputed projection matrix from -#' \code{compute_L_projection}. -#' @param block_column Column name containing the designs block in -#' \code{layout_df}. -#' -#' @keywords internal -calc_info_matrix <- function( - layout_df, - treatment_column = "treatment", - L_matrix = NULL, - block_column = "block" -) { - ci <- .compute_info(layout_df, treatment_column, L_matrix, block_column) - info <- ci$info - v <- ci$v - rownames(info) <- ci$trt_levels - colnames(info) <- ci$trt_levels - - ## get positive eigenvals from info matrix - eig <- eigen(info, symmetric = TRUE, only.values = TRUE)$values - max_eig <- max(eig) - if (max_eig <= 0) { - pos_eig <- numeric(0) - } else { - pos_eig <- eig[eig > max_eig * 1e-10] - } - - if (length(pos_eig) < v - 1) { - A_val <- Inf - D_val <- Inf - } else { - A_val = sum(1 / pos_eig) - D_val = -sum(log(pos_eig)) - if (!is.finite(A_val)) A_val <- Inf - if (!is.finite(D_val)) D_val <- Inf - } - - return(list( - info_matrix = info, - eigenvalues = sort(pos_eig, decreasing = TRUE), - rank = length(pos_eig), - A_value = A_val, - D_value = D_val - )) -} - -#' Calculate incidence matrix -#' -#' @param layout_df Data frame representing the spatial layout of the -#' experiment. -#' @param treatment_column Column name containing the design's treatments in -#' \code{layout_df}. -#' @param block_column Column name containing the designs block in -#' \code{layout_df}. -#' -#' @return \eqn{v \times b} matrix of integers, with treatment levels as row -#' names, and block levels as column names. -#' -#' @keywords internal -calc_incidence_matrix <- function( - layout_df, - treatment_column = "treatment", - block_column = "block" -) { - treatments <- factor(layout_df[[treatment_column]]) - blocks <- factor(layout_df[[block_column]]) - - ## make a matrix of integers - N <- table(treatments, blocks) - class(N) <- "matrix" - storage.mode(N) <- "integer" - - return(N) -} - -#' Calculate concurrence matrix -#' -#' @param layout_df Data frame representing the spatial layout of the -#' experiment. -#' @param treatment_column Column name containing the design's treatments in -#' \code{layout_df}. -#' @param block_column Column name containing the designs block in -#' \code{layout_df}. -#' -#' @return Symmetric \eqn{N N^\intercal}{N Nᵀ} matrix. -#' -#' @keywords internal -calc_concurrence_matrix <- function( - layout_df, - treatment_column = "treatment", - block_column = "block" -) { - N <- calc_incidence_matrix(layout_df, treatment_column, block_column) - C <- N %*% t(N) - storage.mode(C) <- "integer" - return(C) -} - -#' Calculate canonical efficiency factors -#' -#' @param layout_df Data frame representing the spatial layout of the -#' experiment. -#' @param treatment_column Column name containing the design's treatments in -#' \code{layout_df}. -#' @param L_matrix Precomputed projection matrix from -#' \code{compute_L_projection}. -#' @param block_column Column name containing the designs block in -#' \code{layout_df}. -#' -#' @return A list with \code{efficiency_factors}, \code{E}, \code{replication}. -#' -#' @keywords internal -calculate_efficiency_factors <- function( - layout_df, - treatment_column = "treatment", - L_matrix = NULL, - block_column = "block" -) { - info <- calc_info_matrix( - layout_df, - treatment_column, - L_matrix, - block_column - ) - - treatments <- factor(layout_df[[treatment_column]]) - reps <- table(treatments) - r_bar <- mean(reps) - - eff_factors <- info$eigenvalues / r_bar - - v <- nlevels(treatments) - E <- if (info$rank >= v - 1) { - (v - 1) / sum(1 / eff_factors) - } else { - NA_real_ - } - - list( - efficiency_factors = eff_factors, - E = E, - replication = setNames(as.integer(reps), levels(treatments)) - ) -} - - -# Convenience correlation structure constructors - -#' Construct a 1 dimensional lag-1 autoregressive covariance -#' -#' @param n Size of the covariance vector to generate -#' @param rho Correlation parameter -#' -#' @return A symmetric \eqn{(n \times n)} correlation matrix. -#' -#' @export -cor_ar1 <- function(n, rho) { - rho^abs(outer(seq_len(n), seq_len(n), "-")) -} - - -#' Construct a 2 dimensional lag-1 autoregressive covariance -#' -#' @param n_rows Number of rows in the design. -#' @param n_cols Number of columns in the design. -#' @param rho_row Correlation parameter along the row direction. -#' @param rho_col Correlation parameter along the column direction. -#' -#' @return A symmetric \eqn{(\text{n_rows} \cdot \text{n_cols}) \times -#' (\text{n_rows} \cdot \text{n_cols})} correlation matrix. -#' -#' @export -cor_ar1_ar1 <- function(n_rows, n_cols, rho_row, rho_col) { - kronecker( - cor_ar1(n_rows, rho_row), - cor_ar1(n_cols, rho_col) - ) -} diff --git a/man/calc_concurrence_matrix.Rd b/man/calc_concurrence_matrix.Rd deleted file mode 100644 index a4b6ff20..00000000 --- a/man/calc_concurrence_matrix.Rd +++ /dev/null @@ -1,29 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/objectives.R -\name{calc_concurrence_matrix} -\alias{calc_concurrence_matrix} -\title{Calculate concurrence matrix} -\usage{ -calc_concurrence_matrix( - layout_df, - treatment_column = "treatment", - block_column = "block" -) -} -\arguments{ -\item{layout_df}{Data frame representing the spatial layout of the -experiment.} - -\item{treatment_column}{Column name containing the design's treatments in -\code{layout_df}.} - -\item{block_column}{Column name containing the designs block in -\code{layout_df}.} -} -\value{ -Symmetric \eqn{N N^\intercal}{N Nᵀ} matrix. -} -\description{ -Calculate concurrence matrix -} -\keyword{internal} diff --git a/man/calc_incidence_matrix.Rd b/man/calc_incidence_matrix.Rd deleted file mode 100644 index 37683300..00000000 --- a/man/calc_incidence_matrix.Rd +++ /dev/null @@ -1,30 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/objectives.R -\name{calc_incidence_matrix} -\alias{calc_incidence_matrix} -\title{Calculate incidence matrix} -\usage{ -calc_incidence_matrix( - layout_df, - treatment_column = "treatment", - block_column = "block" -) -} -\arguments{ -\item{layout_df}{Data frame representing the spatial layout of the -experiment.} - -\item{treatment_column}{Column name containing the design's treatments in -\code{layout_df}.} - -\item{block_column}{Column name containing the designs block in -\code{layout_df}.} -} -\value{ -\eqn{v \times b} matrix of integers, with treatment levels as row -names, and block levels as column names. -} -\description{ -Calculate incidence matrix -} -\keyword{internal} diff --git a/man/calc_info_matrix.Rd b/man/calc_info_matrix.Rd deleted file mode 100644 index 7c2b3e04..00000000 --- a/man/calc_info_matrix.Rd +++ /dev/null @@ -1,30 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/objectives.R -\name{calc_info_matrix} -\alias{calc_info_matrix} -\title{Calculate info matrix} -\usage{ -calc_info_matrix( - layout_df, - treatment_column = "treatment", - L_matrix = NULL, - block_column = "block" -) -} -\arguments{ -\item{layout_df}{Data frame representing the spatial layout of the -experiment.} - -\item{treatment_column}{Column name containing the design's treatments in -\code{layout_df}.} - -\item{L_matrix}{Precomputed projection matrix from -\code{compute_L_projection}.} - -\item{block_column}{Column name containing the designs block in -\code{layout_df}.} -} -\description{ -Calculate the Fisher information in the experimental design -} -\keyword{internal} diff --git a/man/calculate_efficiency_factors.Rd b/man/calculate_efficiency_factors.Rd deleted file mode 100644 index 901894ba..00000000 --- a/man/calculate_efficiency_factors.Rd +++ /dev/null @@ -1,33 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/objectives.R -\name{calculate_efficiency_factors} -\alias{calculate_efficiency_factors} -\title{Calculate canonical efficiency factors} -\usage{ -calculate_efficiency_factors( - layout_df, - treatment_column = "treatment", - L_matrix = NULL, - block_column = "block" -) -} -\arguments{ -\item{layout_df}{Data frame representing the spatial layout of the -experiment.} - -\item{treatment_column}{Column name containing the design's treatments in -\code{layout_df}.} - -\item{L_matrix}{Precomputed projection matrix from -\code{compute_L_projection}.} - -\item{block_column}{Column name containing the designs block in -\code{layout_df}.} -} -\value{ -A list with \code{efficiency_factors}, \code{E}, \code{replication}. -} -\description{ -Calculate canonical efficiency factors -} -\keyword{internal} diff --git a/man/compute_L_projection.Rd b/man/compute_L_projection.Rd index f8210b77..9923f9c2 100644 --- a/man/compute_L_projection.Rd +++ b/man/compute_L_projection.Rd @@ -1,19 +1,31 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/objectives.R +% Please edit documentation in R/objective_fisher.R \name{compute_L_projection} \alias{compute_L_projection} \title{Compute L projection} \usage{ -compute_L_projection(layout_df, Sigma, block_column = "block") +compute_L_projection( + layout_df, + Sigma, + block_column = "block", + nuisance_formula = NULL, + tolerance = 1e-10 +) } \arguments{ \item{layout_df}{Data frame representing the spatial layout of the experiment.} -\item{Sigma}{Covariance structure to use.} +\item{Sigma}{Covariance structure to use. Its rows and columns must follow +the row order of \code{layout_df}.} \item{block_column}{Column name of the design's block factor in \code{layout_df}.} + +\item{nuisance_formula}{Optional one-sided formula describing nuisance +effects. If omitted, \code{block_column} is treated as a factor.} + +\item{tolerance}{Numerical tolerance used for generalized inverses.} } \value{ \eqn{(n \times n)} numeric matrix. diff --git a/man/cor_ar1.Rd b/man/cor_ar1.Rd index e010bb4d..4dd478b7 100644 --- a/man/cor_ar1.Rd +++ b/man/cor_ar1.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/objectives.R +% Please edit documentation in R/objective_fisher.R \name{cor_ar1} \alias{cor_ar1} \title{Construct a 1 dimensional lag-1 autoregressive covariance} diff --git a/man/cor_ar1_ar1.Rd b/man/cor_ar1_ar1.Rd index cb0332c5..bbb4b2be 100644 --- a/man/cor_ar1_ar1.Rd +++ b/man/cor_ar1_ar1.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/objectives.R +% Please edit documentation in R/objective_fisher.R \name{cor_ar1_ar1} \alias{cor_ar1_ar1} \title{Construct a 2 dimensional lag-1 autoregressive covariance} diff --git a/man/objective_function_info.Rd b/man/objective_function_info.Rd index 9979fad8..db4acc04 100644 --- a/man/objective_function_info.Rd +++ b/man/objective_function_info.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/objectives.R +% Please edit documentation in R/objective_fisher.R \name{objective_function_info} \alias{objective_function_info} \title{Objective function using the treatment information matrix} @@ -10,7 +10,13 @@ objective_function_info( spatial_cols, criterion = c("A", "D"), L_matrix = NULL, + Sigma = NULL, + contrast_matrix = NULL, block_column = "block", + nuisance_formula = NULL, + tolerance = 1e-09, + current_score_obj = NULL, + swapped_items = NULL, ... ) } @@ -29,19 +35,42 @@ optimality. - D-optimality: Minimises \eqn{-\log \left| \mathcal{I} \right|}{- log(|I|)}} -\item{L_matrix}{Precomputed projection matrix. Use -\code{compute_L_projection} to generate it. If \code{NULL}, then the -identity covariance structure will be assumed, and the projection will be -computed using the structure of the design's blocks.} +\item{L_matrix}{Optional precomputed projection matrix. This is an advanced +alternative to \code{Sigma}; the two cannot be supplied together.} + +\item{Sigma}{Optional covariance matrix whose rows and columns follow the row +order of \code{layout_df}. The projection is computed on the first objective +call and reused during optimisation. If both \code{Sigma} and \code{L_matrix} are +\code{NULL}, identity covariance is assumed.} + +\item{contrast_matrix}{Numeric contrast matrix with one column per treatment +level. Column names, when supplied, must match the treatment levels. Only +these contrasts are required to be estimable and contribute to the +optimality criterion. The default targets the complete treatment-contrast +space.} \item{block_column}{Column name of the design's block factor. Used when \code{L_matrix} isn't supplied.} +\item{nuisance_formula}{Optional one-sided formula describing nuisance +effects. Used when \code{L_matrix} is not supplied. If omitted, +\code{block_column} is treated as a factor.} + +\item{tolerance}{Relative numerical tolerance for rank and estimability +checks.} + +\item{current_score_obj}{The current objective result supplied by \code{\link[=speed]{speed()}} +after the initial call. Used to reuse invariant matrix calculations.} + +\item{swapped_items}{The treatments swapped by \code{\link[=speed]{speed()}}. Changed plot rows +are identified from the cached and proposed allocations so repeated +treatments and multi-swaps are handled exactly.} + \item{...}{Extra parameters passed from \code{speed}.} } \value{ A named list with \code{score}, \code{info_matrix}, -\code{eigenvalues}, \code{criterion}. +\code{eigenvalues}, contrast diagnostics, and \code{criterion}. } \description{ Creates an objective function that optimises experimental designs using the @@ -56,7 +85,8 @@ Where \eqn{X_1}{X₁} is the treatment design matrix, and \eqn{L} is the projection that removes nuisance fixed effects from the GLS's inverse covariance: \deqn{L = \Sigma^{-1} - \Sigma^{-1} X_2 \left( X_2^\intercal \Sigma^{-1} X_2 -\right)^{-1}}{L = Σ⁻¹ - Σ⁻¹ X₂ (X₂ᵀ Σ⁻¹ X₂)⁻¹} +\right)^{-1} X_2^\intercal \Sigma^{-1}}{L = Σ⁻¹ - Σ⁻¹ X₂ +(X₂ᵀ Σ⁻¹ X₂)⁻¹ X₂ᵀ Σ⁻¹} The user specifies the spatial covariance \eqn{\Sigma}{Σ} they intend to use at the time of analysis, e.g. lag-1 autoregressive \eqn{\text{AR}_1 \otimes \text{AR}_1}{AR₁ ⊗ AR₁}, and this objective will optimise under that @@ -85,13 +115,12 @@ Sigma <- cor_ar1_ar1( n_rows = 4, n_cols = 6, rho_row = 0.6, rho_col = 0.3 ) -L <- compute_L_projection(df, Sigma, block_column = "block") result_spatial <- speed( df, swap = "treatment", swap_within = "block", obj_function = objective_function_info, - L_matrix = L, + Sigma = Sigma, criterion = "A", optimise_params = optim_params(random_initialisation = TRUE), seed = 42, diff --git a/tests/testthat/test-compute_L_projection.R b/tests/testthat/test-compute_L_projection.R new file mode 100644 index 00000000..ff3e58a3 --- /dev/null +++ b/tests/testthat/test-compute_L_projection.R @@ -0,0 +1,48 @@ +test_that("compute_L_projection validates covariance inputs", { + df <- data.frame( + row = 1:4, + col = 1:4, + block = c(1, 1, 2, 2), + treatment = c("A", "B", "A", "B") + ) + + expect_error(compute_L_projection(df, 1:4), "matrix") + expect_error(compute_L_projection(df, diag(3)), "dimension") + expect_error(compute_L_projection(df, matrix(1:16, 4, 4)), "symmetric") +}) + +test_that("identity covariance matches the direct projection", { + df <- data.frame( + row = rep(1:3, each = 4), + col = rep(1:4, times = 3), + block = rep(1:3, each = 4), + treatment = rep(paste0("T", 1:4), 3) + ) + + spatial <- compute_L_projection(df, diag(12), block_column = "block") + direct <- .build_L_from_df(df, "block", 12) + + expect_equal(unname(spatial), unname(direct), tolerance = 1e-10) +}) + +test_that("compute_L_projection supports nuisance formulas", { + df <- data.frame( + row = rep(1:3, each = 4), + col = rep(1:4, times = 3), + treatment = rep(paste0("T", 1:4), 3) + ) + + spatial <- compute_L_projection( + df, + diag(12), + nuisance_formula = ~ row + col + ) + direct <- .build_L_from_df( + df, + "block", + 12, + nuisance_formula = ~ row + col + ) + + expect_equal(unname(spatial), unname(direct), tolerance = 1e-10) +}) diff --git a/tests/testthat/test-cor_ar1.R b/tests/testthat/test-cor_ar1.R new file mode 100644 index 00000000..96a8e0c5 --- /dev/null +++ b/tests/testthat/test-cor_ar1.R @@ -0,0 +1,15 @@ +test_that("cor_ar1 produces a valid correlation matrix", { + correlation <- cor_ar1(5, 0.7) + + expect_equal(dim(correlation), c(5, 5)) + expect_true(isSymmetric(correlation)) + expect_true(all(diag(correlation) == 1)) + expect_true(all(eigen(correlation, only.values = TRUE)$values > 0)) + expect_equal(correlation[1, 2], 0.7) + expect_equal(correlation[1, 3], 0.7^2) + expect_equal(correlation[1, 5], 0.7^4) +}) + +test_that("cor_ar1 with zero correlation gives identity", { + expect_equal(cor_ar1(4, 0), diag(4)) +}) diff --git a/tests/testthat/test-cor_ar1_ar1.R b/tests/testthat/test-cor_ar1_ar1.R new file mode 100644 index 00000000..60799260 --- /dev/null +++ b/tests/testthat/test-cor_ar1_ar1.R @@ -0,0 +1,14 @@ +test_that("cor_ar1_ar1 produces a valid separable correlation matrix", { + correlation <- cor_ar1_ar1(3, 5, 0.6, 0.4) + + expect_equal(dim(correlation), c(15, 15)) + expect_true(isSymmetric(correlation)) + expect_true(all(diag(correlation) == 1)) + expect_true(all(eigen(correlation, only.values = TRUE)$values > 0)) +}) + +test_that("cor_ar1_ar1 is the Kronecker product of marginal correlations", { + expected <- kronecker(cor_ar1(3, 0.6), cor_ar1(5, 0.4)) + + expect_equal(cor_ar1_ar1(3, 5, 0.6, 0.4), expected) +}) diff --git a/tests/testthat/test-objective_fisher.R b/tests/testthat/test-objective_fisher.R new file mode 100644 index 00000000..6cbb22e3 --- /dev/null +++ b/tests/testthat/test-objective_fisher.R @@ -0,0 +1,327 @@ +# tests/testthat/test-objective_fisher.R + +# ---- objective_function_info + +# all RCBDs are equally optimal +test_that("all valid RCBD randomisations produce the same score under identity covariance", { + set.seed(1) + n_treatments <- 4 + n_blocks <- 3 + + df <- data.frame( + row = rep(1:n_blocks, each = n_treatments), + col = rep(1:n_treatments, times = n_blocks), + block = rep(1:n_blocks, each = n_treatments), + treatment = NA_character_ + ) + + scores <- numeric(20) + for (i in seq_len(20)) { + for (b in 1:n_blocks) { + idx <- df$block == b + df$treatment[idx] <- paste0("T", sample(n_treatments)) + } + result <- objective_function_info( + df, + swap = "treatment", spatial_cols = c("row", "col"), + criterion = "A" + ) + scores[i] <- result$score + } + + expect_true(max(scores) - min(scores) < 1e-10) +}) + +# when there IS spatial correlation, two different arrangements of the same +# treatments must give different scores. df1 should be worse, since treatments +# are always in the same column position, but in df2 they're "randomised". +test_that("spatial designs differentiate between arrangements", { + n_treatments <- 4 + n_blocks <- 3 + + df <- data.frame( + row = rep(1:n_blocks, each = n_treatments), + col = rep(1:n_treatments, times = n_blocks), + block = rep(1:n_blocks, each = n_treatments) + ) + + Sigma <- cor_ar1_ar1(n_blocks, n_treatments, rho_row = 0.7, rho_col = 0.5) + + # Same treatment ordering in every block + df1 <- df + df1$treatment <- rep(paste0("T", 1:n_treatments), n_blocks) + + # Alternated ordering + df2 <- df + df2$treatment <- c( + paste0("T", c(1, 2, 3, 4)), + paste0("T", c(3, 4, 1, 2)), + paste0("T", c(4, 3, 2, 1)) + ) + + s1 <- objective_function_info( + df1, "treatment", c("row", "col"), + criterion = "A", Sigma = Sigma + )$score + + s2 <- objective_function_info( + df2, "treatment", c("row", "col"), + criterion = "A", Sigma = Sigma + )$score + + expect_false(abs(s1 - s2) < 1e-10) +}) + +# just make sure this works lel +test_that("D-optimality criterion works", { + df <- data.frame( + row = rep(1:3, each = 4), + col = rep(1:4, times = 3), + block = rep(1:3, each = 4), + treatment = rep(paste0("T", 1:4), 3) + ) + + result <- objective_function_info( + df, "treatment", c("row", "col"), + criterion = "D" + ) + + expect_true(is.finite(result$score)) + expect_equal(result$criterion, "D") + expect_equal(length(result$eigenvalues), 3) # v - 1 +}) + +# if treatments never exist in the same block together, you cant compare them, +# so the design is fully broken +test_that("disconnected designs have massive penalty", { + df <- data.frame( + row = 1:6, + col = c(1, 2, 1, 2, 1, 2), + block = c(1, 1, 2, 2, 3, 3), + treatment = c("A", "A", "B", "B", "C", "C") + ) + + result <- objective_function_info( + df, "treatment", c("row", "col"), + criterion = "A" + ) + + expect_gte(result$score, 1e9) + expect_true(is.finite(result$score)) + expect_equal(result$A_value, Inf) + expect_equal(result$D_value, Inf) +}) + +test_that("information matrix for an RCBD has the expected rank", { + df <- data.frame( + row = rep(1:3, each = 5), + col = rep(1:5, times = 3), + block = rep(1:3, each = 5), + treatment = rep(paste0("T", 1:5), 3) + ) + + result <- objective_function_info(df, "treatment", c("row", "col")) + + expect_equal(result$rank, 4) + expect_equal(result$eigenvalues, rep(3, 4), tolerance = 1e-10) + expect_equal(dim(result$info_matrix), c(5, 5)) + expect_equal(rownames(result$info_matrix), paste0("T", 1:5)) + expect_equal(colnames(result$info_matrix), paste0("T", 1:5)) +}) + +test_that("a requested estimable contrast does not require full connectedness", { + df <- data.frame( + row = 1:6, + col = rep(1:2, 3), + block = rep(1:3, each = 2), + treatment = c("A", "B", "A", "B", "C", "C") + ) + contrast <- matrix(c(1, -1, 0), nrow = 1) + colnames(contrast) <- c("A", "B", "C") + + full <- objective_function_info(df, "treatment", c("row", "col")) + targeted <- objective_function_info( + df, + "treatment", + c("row", "col"), + contrast_matrix = contrast + ) + + expect_false(full$estimable) + expect_true(targeted$estimable) + expect_true(is.finite(targeted$score)) +}) + +test_that("incremental calculation matches full recalculation", { + df <- data.frame( + row = rep(1:3, each = 4), + col = rep(1:4, times = 3), + block = rep(1:3, each = 4), + treatment = rep(LETTERS[1:4], 3) + ) + Sigma <- cor_ar1_ar1(3, 4, rho_row = 0.6, rho_col = 0.3) + current <- objective_function_info( + df, + "treatment", + c("row", "col"), + Sigma = Sigma + ) + + proposal <- df + proposal$treatment[c(1, 2, 7, 8)] <- proposal$treatment[c(2, 1, 8, 7)] + incremental <- objective_function_info( + proposal, + "treatment", + c("row", "col"), + Sigma = Sigma, + current_score_obj = current, + swapped_items = c("A", "B", "C", "D") + ) + full <- objective_function_info( + proposal, + "treatment", + c("row", "col"), + Sigma = Sigma + ) + + expect_equal(incremental$info_matrix, full$info_matrix, tolerance = 1e-12) + expect_equal(incremental$score, full$score, tolerance = 1e-12) + + # Reuse the original score object as if the first proposal was rejected. + second_proposal <- df + second_proposal$treatment[c(3, 4)] <- second_proposal$treatment[c(4, 3)] + second_incremental <- objective_function_info( + second_proposal, + "treatment", + c("row", "col"), + Sigma = Sigma, + current_score_obj = current, + swapped_items = c("C", "D") + ) + second_full <- objective_function_info( + second_proposal, + "treatment", + c("row", "col"), + Sigma = Sigma + ) + + expect_equal( + second_incremental$info_matrix, + second_full$info_matrix, + tolerance = 1e-12 + ) +}) + +test_that("covariance matrices remain aligned when layout rows are reordered", { + df <- data.frame( + row = rep(1:3, each = 4), + col = rep(1:4, times = 3), + block = rep(1:3, each = 4), + treatment = rep(LETTERS[1:4], 3) + ) + Sigma <- cor_ar1_ar1(3, 4, rho_row = 0.6, rho_col = 0.3) + original <- objective_function_info( + df, + "treatment", + c("row", "col"), + Sigma = Sigma + ) + + row_order <- c(5:12, 1:4) + reordered <- objective_function_info( + df[row_order, ], + "treatment", + c("row", "col"), + Sigma = Sigma[row_order, row_order] + ) + + expect_equal(reordered$info_matrix, original$info_matrix, tolerance = 1e-12) + expect_equal(reordered$score, original$score, tolerance = 1e-12) +}) + +test_that("Sigma and L_matrix are mutually exclusive", { + df <- data.frame( + row = 1:4, + col = 1:4, + treatment = rep(c("A", "B"), 2) + ) + + expect_error( + objective_function_info( + df, + "treatment", + c("row", "col"), + Sigma = diag(4), + L_matrix = diag(4) + ), + "Only one" + ) +}) + + +# ---- Test with speed function + +# Actually test by passing to speed +test_that("speed() optimises an RCBD with the info objective under AR1xAR1", { + skip_if_not_installed("speed") + + df <- initialise_design_df( + items = 6, nrows = 4, ncols = 6, + block_nrows = 1, block_ncols = 6 + ) + + Sigma <- cor_ar1_ar1(4, 6, rho_row = 0.6, rho_col = 0.3) + + result <- speed( + df, + swap = "treatment", + swap_within = "block", + spatial_factors = ~ block + row + col, + obj_function = objective_function_info, + Sigma = Sigma, + criterion = "A", + optimise_params = optim_params(random_initialisation = TRUE), + seed = 42, + quiet = TRUE + ) + + expect_s3_class(result, "design") + expect_lt(result$score, Inf) + + info <- objective_function_info( + result$design_df, + "treatment", + c("row", "col"), + Sigma = Sigma + ) + expect_equal(info$rank, 5) + expect_true(is.finite(info$A_value)) +}) + +test_that("speed() optimises a BIBD with the info objective", { + skip_if_not_installed("speed") + + df <- initialise_design_df( + items = 5, nrows = 3, ncols = 10, + block_nrows = 3, block_ncols = 1 + ) + + result <- speed( + df, + swap = "treatment", + spatial_factors = ~ block + row + col, + obj_function = objective_function_info, + criterion = "A", + optimise_params = optim_params(random_initialisation = TRUE), + seed = 42, + quiet = TRUE + ) + + info <- objective_function_info( + result$design_df, + "treatment", + c("row", "col") + ) + expect_equal(info$rank, 4) + expect_true(is.finite(info$A_value)) +}) diff --git a/tests/testthat/test-objective_function_info.R b/tests/testthat/test-objective_function_info.R deleted file mode 100644 index 9c893797..00000000 --- a/tests/testthat/test-objective_function_info.R +++ /dev/null @@ -1,378 +0,0 @@ -# tests/testthat/test-objective_function_info.R - -# ---- objective_function_info - -# all RCBDs are equally optimal -test_that("all valid RCBD randomisations produce the same score under identity covariance", { - set.seed(1) - n_treatments <- 4 - n_blocks <- 3 - - df <- data.frame( - row = rep(1:n_blocks, each = n_treatments), - col = rep(1:n_treatments, times = n_blocks), - block = rep(1:n_blocks, each = n_treatments), - treatment = NA_character_ - ) - - scores <- numeric(20) - for (i in seq_len(20)) { - for (b in 1:n_blocks) { - idx <- df$block == b - df$treatment[idx] <- paste0("T", sample(n_treatments)) - } - result <- objective_function_info( - df, swap = "treatment", spatial_cols = c("row", "col"), - criterion = "A" - ) - scores[i] <- result$score - } - - expect_true(max(scores) - min(scores) < 1e-10) -}) - -# when there IS spatial correlation, two different arrangements of the same -# treatments must give different scores. df1 should be worse, since treatments -# are always in the same column position, but in df2 they're "randomised". -test_that("spatial designs differentiate between arrangements", { - n_treatments <- 4 - n_blocks <- 3 - - df <- data.frame( - row = rep(1:n_blocks, each = n_treatments), - col = rep(1:n_treatments, times = n_blocks), - block = rep(1:n_blocks, each = n_treatments) - ) - - Sigma <- cor_ar1_ar1(n_blocks, n_treatments, rho_row = 0.7, rho_col = 0.5) - L <- compute_L_projection(df, Sigma, block_col = "block") - - # Same treatment ordering in every block - df1 <- df - df1$treatment <- rep(paste0("T", 1:n_treatments), n_blocks) - - # Alternated ordering - df2 <- df - df2$treatment <- c( - paste0("T", c(1, 2, 3, 4)), - paste0("T", c(3, 4, 1, 2)), - paste0("T", c(4, 3, 2, 1)) - ) - - s1 <- objective_function_info( - df1, "treatment", c("row", "col"), - criterion = "A", L_matrix = L - )$score - - s2 <- objective_function_info( - df2, "treatment", c("row", "col"), - criterion = "A", L_matrix = L - )$score - - expect_false(abs(s1 - s2) < 1e-10) -}) - -# just make sure this works lel -test_that("D-optimality criterion works", { - df <- data.frame( - row = rep(1:3, each = 4), - col = rep(1:4, times = 3), - block = rep(1:3, each = 4), - treatment = rep(paste0("T", 1:4), 3) - ) - - result <- objective_function_info( - df, "treatment", c("row", "col"), - criterion = "D" - ) - - expect_true(is.finite(result$score)) - expect_equal(result$criterion, "D") - expect_equal(length(result$eigenvalues), 3) # v - 1 -}) - -# if treatments never exist in the same block together, you cant compare them, -# so the design is fully broken -test_that("disconnected designs have massive penalty", { - df <- data.frame( - row = 1:6, - col = c(1, 2, 1, 2, 1, 2), - block = c(1, 1, 2, 2, 3, 3), - treatment = c("A", "A", "B", "B", "C", "C") - ) - - result <- objective_function_info( - df, "treatment", c("row", "col"), - criterion = "A" - ) - - expect_gte(result$score, 1e9) - expect_true(is.finite(result$score)) -}) - - -# ---- compute_L_projection - -# input validation test -test_that("compute_L_projection validates inputs", { - df <- data.frame( - row = 1:4, col = 1:4, block = c(1, 1, 2, 2), - treatment = c("A", "B", "A", "B") - ) - - # Wrong dimensions - expect_error(compute_L_projection(df, diag(3))) - - # Not symmetric - expect_error(compute_L_projection(df, matrix(1:16, 4, 4))) - - # Missing block column - expect_error(compute_L_projection(df, diag(4), block_col = "nonexistent")) -}) - -# identity sigma should be the default L projection. i.e. spatial optimisation -# with identity correlation is the same as non-spatial -test_that("L with identity Sigma matches .build_L_from_df", { - df <- data.frame( - row = rep(1:3, each = 4), - col = rep(1:4, times = 3), - block = rep(1:3, each = 4), - treatment = rep(paste0("T", 1:4), 3) - ) - - L_spatial <- compute_L_projection(df, diag(12), block_col = "block") - L_direct <- .build_L_from_df(df, "block", 12) - - expect_true(max(abs(L_spatial - L_direct)) < 1e-10) -}) - - -# ---- calc_info_matrix - -# balanced RCBD should have rank = v - 1 -test_that("info matrix for RCBD has correct properties", { - df <- data.frame( - row = rep(1:3, each = 5), - col = rep(1:5, times = 3), - block = rep(1:3, each = 5), - treatment = rep(paste0("T", 1:5), 3) - ) - - info <- calc_info_matrix(df) - - # v = 5, so rank = v - 1 = 4 - expect_equal(info$rank, 4) - - # For balanced RCBD all non-zero eigenvalues = b = 3 - expect_true(all(abs(info$eigenvalues - 3) < 1e-10)) - - # 5x5 matrix - expect_equal(dim(info$info_matrix), c(5, 5)) - - # Named - expect_equal(rownames(info$info_matrix), paste0("T", 1:5)) - expect_equal(colnames(info$info_matrix), paste0("T", 1:5)) -}) - - -# spatial should always be different to non-spatial -test_that("spatial info matrix differs from non-spatial", { - df <- data.frame( - row = rep(1:3, each = 4), - col = rep(1:4, times = 3), - block = rep(1:3, each = 4), - treatment = rep(paste0("T", 1:4), 3) - ) - - Sigma <- cor_ar1_ar1(3, 4, 0.5, 0.3) - L <- compute_L_projection(df, Sigma) - - info_plain <- calc_info_matrix(df) - info_spatial <- calc_info_matrix(df, L_matrix = L) - - expect_false( - all(abs(info_plain$eigenvalues - info_spatial$eigenvalues) < 1e-10) - ) -}) - -# disconnected design should give invalid criteria -test_that("disconnected design gives Inf for A and D values", { - df <- data.frame( - row = 1:6, - col = c(1, 2, 1, 2, 1, 2), - block = c(1, 1, 2, 2, 3, 3), - treatment = c("A", "A", "B", "B", "C", "C") - ) - - info <- calc_info_matrix(df) - - expect_equal(info$A_value, Inf) - expect_equal(info$D_value, Inf) -}) - - -# ---- calc_incidence_matrix - -# complete design should have all incidence matrix entries = 1 -# should also encode replication (rows) and block size (cols) -test_that("incidence matrix has correct dimensions and values for RCBD", { - df <- data.frame( - row = rep(1:3, each = 4), - col = rep(1:4, times = 3), - block = rep(1:3, each = 4), - treatment = rep(paste0("T", 1:4), 3) - ) - - N <- calc_incidence_matrix(df) - - expect_equal(dim(N), c(4, 3)) # v x b - expect_true(all(N == 1)) # complete blocks - expect_true(all(rowSums(N) == 3)) # replication = b - expect_true(all(colSums(N) == 4)) # block size = v -}) - -# ensure incidence works fine for imbalanced designs -test_that("incidence matrix handles unequal replication", { - df <- data.frame( - row = 1:5, - col = c(1, 2, 1, 2, 1), - block = c(1, 1, 2, 2, 2), - treatment = c("A", "B", "A", "B", "A") - ) - - N <- calc_incidence_matrix(df) - - expect_equal(dim(N), c(2, 2)) - expect_equal(sum(N["A", ]), 3) # A appears 3 times - expect_equal(sum(N["B", ]), 2) # B appears 2 times -}) - -# ---- calc_concurrence_matrix - -# balanced RCBD with N all = 1, N Nt should have entries equal to block number -test_that("concurrence matrix is correct for RCBD", { - df <- data.frame( - row = rep(1:3, each = 4), - col = rep(1:4, times = 3), - block = rep(1:3, each = 4), - treatment = rep(paste0("T", 1:4), 3) - ) - - C <- calc_concurrence_matrix(df) - - expect_equal(dim(C), c(4, 4)) - expect_true(all(C == 3)) -}) - - -# ---- calculate_efficiency_factors - -# balanced RCBD has all efficiency factors = 1 -test_that("efficiency factors are 1 for complete blocks", { - df <- data.frame( - row = rep(1:4, each = 5), - col = rep(1:5, times = 4), - block = rep(1:4, each = 5), - treatment = rep(paste0("T", 1:5), 4) - ) - - info <- calc_info_matrix(df) - treatments <- factor(df$treatment) - r_bar <- mean(table(treatments)) - eff <- info$eigenvalues / r_bar - - expect_true(all(abs(eff - 1) < 1e-10)) -}) - - -# ---- correlation constructors - -# make sure ar1 builder works fine -test_that("cor_ar1 produces valid correlation matrix", { - R <- cor_ar1(5, 0.7) - - expect_equal(dim(R), c(5, 5)) - expect_true(isSymmetric(R)) - expect_true(all(diag(R) == 1)) - expect_true(all(eigen(R, only.values = TRUE)$values > 0)) - - # Check specific entries - expect_equal(R[1, 2], 0.7) - expect_equal(R[1, 3], 0.7^2) - expect_equal(R[1, 5], 0.7^4) -}) - -# yes -test_that("cor_ar1 with rho = 0 gives identity", { - expect_equal(cor_ar1(4, 0), diag(4)) -}) - -# make sure ar1 x ar1 builder works fine -test_that("cor_ar1_ar1 has correct dimensions and is valid", { - Sigma <- cor_ar1_ar1(3, 5, 0.6, 0.4) - - expect_equal(dim(Sigma), c(15, 15)) - expect_true(isSymmetric(Sigma)) - expect_true(all(diag(Sigma) == 1)) - expect_true(all(eigen(Sigma, only.values = TRUE)$values > 0)) -}) - - -# ---- Test with speed function - -# Actually test by passing to speed -test_that("speed() optimises an RCBD with the info objective under AR1xAR1", { - skip_if_not_installed("speed") - - df <- initialise_design_df( - items = 6, nrows = 4, ncols = 6, - block_nrows = 1, block_ncols = 6 - ) - - Sigma <- cor_ar1_ar1(4, 6, rho_row = 0.6, rho_col = 0.3) - L <- compute_L_projection(df, Sigma, block_column = "block") - - result <- speed( - df, - swap = "treatment", - swap_within = "block", - spatial_factors = ~ block + row + col, - obj_function = objective_function_info, - L_matrix = L, - criterion = "A", - optimise_params = optim_params(random_initialisation = TRUE), - seed = 42, - quiet = TRUE - ) - - expect_s3_class(result, "design") - expect_lt(result$score, Inf) - - info <- calc_info_matrix(result$design_df, L_matrix = L) - expect_equal(info$rank, 5) - expect_true(is.finite(info$A_value)) -}) - -test_that("speed() optimises a BIBD with the info objective", { - skip_if_not_installed("speed") - - df <- initialise_design_df( - items = 5, nrows = 3, ncols = 10, - block_nrows = 3, block_ncols = 1 - ) - - result <- speed( - df, - swap = "treatment", - spatial_factors = ~ block + row + col, - obj_function = objective_function_info, - criterion = "A", - optimise_params = optim_params(random_initialisation = TRUE), - seed = 42, - quiet = TRUE - ) - - info <- calc_info_matrix(result$design_df) - expect_equal(info$rank, 4) - expect_true(is.finite(info$A_value)) -}) From 61cdde6d52393b14c2304f80999d7909cd957324 Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Tue, 18 Aug 2026 15:51:53 +0800 Subject: [PATCH 14/25] Add factorial_contrast_matrix --- NAMESPACE | 1 + R/objective_fisher.R | 69 +++++++++++++++++++ man/factorial_contrast_matrix.Rd | 33 +++++++++ .../testthat/test-factorial_contrast_matrix.R | 50 ++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 man/factorial_contrast_matrix.Rd create mode 100644 tests/testthat/test-factorial_contrast_matrix.R diff --git a/NAMESPACE b/NAMESPACE index fcac9612..96d25597 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,6 +15,7 @@ export(compute_L_projection) export(cor_ar1) export(cor_ar1_ar1) export(create_pair_mapping) +export(factorial_contrast_matrix) export(get_edges) export(get_vertices) export(initialise_design_df) diff --git a/R/objective_fisher.R b/R/objective_fisher.R index 21c6da88..76dc5286 100644 --- a/R/objective_fisher.R +++ b/R/objective_fisher.R @@ -156,6 +156,75 @@ objective_function_info <- function( return(X1) } +#' Build an orthonormal factorial contrast matrix +#' +#' Constructs a contrast basis for selected factorial effects while treatments +#' remain encoded as atomic combinations during optimisation. The returned rows +#' are orthonormal, so A-optimality is invariant to the particular contrast +#' coding used by [stats::model.matrix()]. +#' +#' @param treatment_df One row per treatment combination, containing the +#' component factor columns. +#' @param formula One-sided formula selecting factorial effects, for example +#' \code{~ (stage + cultivar + inoculum)^2}. +#' @param treatment_column Column containing the atomic treatment labels. +#' @param tolerance Numerical rank tolerance. +#' +#' @return A numeric contrast matrix whose columns are named by treatment level. +#' +#' @export +factorial_contrast_matrix <- function( + treatment_df, + formula, + treatment_column = "treatment", + tolerance = 1e-10 +) { + if (!is.data.frame(treatment_df)) { + stop("`treatment_df` must be a data frame.", call. = FALSE) + } + if (!inherits(formula, "formula") || length(formula) != 2L) { + stop("`formula` must be a one-sided formula.", call. = FALSE) + } + if (!treatment_column %in% names(treatment_df)) { + stop("Treatment column `", treatment_column, "` not found.", call. = FALSE) + } + + treatment_levels <- as.character(treatment_df[[treatment_column]]) + if (anyNA(treatment_levels) || anyDuplicated(treatment_levels)) { + stop("`treatment_df` must contain one non-missing row per treatment.", call. = FALSE) + } + + formula_vars <- all.vars(formula) + missing_vars <- setdiff(formula_vars, names(treatment_df)) + if (length(missing_vars) > 0L) { + stop( + "Formula variable(s) not found: ", paste(missing_vars, collapse = ", "), + call. = FALSE + ) + } + + model_data <- treatment_df + for (column in formula_vars) { + if (is.character(model_data[[column]])) { + model_data[[column]] <- factor(model_data[[column]]) + } + } + + effect_matrix <- stats::model.matrix(formula, model_data) + effect_matrix <- sweep(effect_matrix, 2L, colMeans(effect_matrix), "-") + decomposition <- qr(effect_matrix, tol = tolerance) + effect_rank <- decomposition$rank + if (effect_rank == 0L) { + stop("`formula` does not define any treatment contrasts.", call. = FALSE) + } + + basis <- qr.Q(decomposition, complete = FALSE)[, seq_len(effect_rank), drop = FALSE] + contrasts <- t(basis) + rownames(contrasts) <- paste0("contrast_", seq_len(nrow(contrasts))) + colnames(contrasts) <- treatment_levels + return(contrasts) +} + #' Prepare a requested contrast space #' @noRd .prepare_contrast_matrix <- function(contrast_matrix, trt_levels, tolerance) { diff --git a/man/factorial_contrast_matrix.Rd b/man/factorial_contrast_matrix.Rd new file mode 100644 index 00000000..b64c792d --- /dev/null +++ b/man/factorial_contrast_matrix.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/objective_fisher.R +\name{factorial_contrast_matrix} +\alias{factorial_contrast_matrix} +\title{Build an orthonormal factorial contrast matrix} +\usage{ +factorial_contrast_matrix( + treatment_df, + formula, + treatment_column = "treatment", + tolerance = 1e-10 +) +} +\arguments{ +\item{treatment_df}{One row per treatment combination, containing the +component factor columns.} + +\item{formula}{One-sided formula selecting factorial effects, for example +\code{~ (stage + cultivar + inoculum)^2}.} + +\item{treatment_column}{Column containing the atomic treatment labels.} + +\item{tolerance}{Numerical rank tolerance.} +} +\value{ +A numeric contrast matrix whose columns are named by treatment level. +} +\description{ +Constructs a contrast basis for selected factorial effects while treatments +remain encoded as atomic combinations during optimisation. The returned rows +are orthonormal, so A-optimality is invariant to the particular contrast +coding used by \code{\link[stats:model.matrix]{stats::model.matrix()}}. +} diff --git a/tests/testthat/test-factorial_contrast_matrix.R b/tests/testthat/test-factorial_contrast_matrix.R new file mode 100644 index 00000000..8f37241f --- /dev/null +++ b/tests/testthat/test-factorial_contrast_matrix.R @@ -0,0 +1,50 @@ +test_that("factorial_contrast_matrix builds an orthonormal effect space", { + treatments <- expand.grid( + stage = c("early", "late"), + cultivar = c("A", "B", "C") + ) + treatments$treatment <- with(treatments, paste(stage, cultivar, sep = ":")) + + contrasts <- factorial_contrast_matrix( + treatments, + ~ stage + cultivar + ) + + expect_equal(dim(contrasts), c(3, 6)) + expect_equal(colnames(contrasts), treatments$treatment) + expect_equal(unname(rowSums(contrasts)), rep(0, 3), tolerance = 1e-12) + expect_equal(unname(tcrossprod(contrasts)), diag(3), tolerance = 1e-12) +}) + +test_that("factorial_contrast_matrix supports interactions", { + treatments <- expand.grid( + stage = c("early", "late"), + cultivar = c("A", "B", "C") + ) + treatments$treatment <- with(treatments, paste(stage, cultivar, sep = ":")) + + contrasts <- factorial_contrast_matrix( + treatments, + ~ stage * cultivar + ) + + expect_equal(nrow(contrasts), nrow(treatments) - 1) + expect_equal(unname(tcrossprod(contrasts)), diag(5), tolerance = 1e-12) +}) + +test_that("factorial_contrast_matrix validates its inputs", { + treatments <- data.frame( + treatment = c("A", "B"), + factor_a = c("low", "high") + ) + + expect_error(factorial_contrast_matrix(1:2, ~factor_a), "data frame") + expect_error(factorial_contrast_matrix(treatments, factor_a ~ 1), "one-sided") + expect_error(factorial_contrast_matrix(treatments, ~missing), "not found") + + duplicated <- rbind(treatments, treatments[1, ]) + expect_error( + factorial_contrast_matrix(duplicated, ~factor_a), + "one non-missing row" + ) +}) From a151f4e3f7d331a3afa5bf2db0dfb5025bc6ddee Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Thu, 20 Aug 2026 13:46:33 +0800 Subject: [PATCH 15/25] update pkgdown --- _pkgdown.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/_pkgdown.yml b/_pkgdown.yml index e11877cc..18955f14 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -20,9 +20,10 @@ reference: - get_edges - get_vertices - prep_relationship - - subtitle: Spatial covariance utilities - desc: Functions for constructing spatial covariance inputs for Fisher information objectives + - subtitle: Fisher information utilities + desc: Functions for constructing contrast and covariance inputs for Fisher information objectives - contents: + - factorial_contrast_matrix - compute_L_projection - cor_ar1 - cor_ar1_ar1 From db32f96054a88e60e7bc34e5e6f61c642bb477d6 Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Mon, 19 Oct 2026 11:48:23 +0800 Subject: [PATCH 16/25] Fix D-optimality stopping, covariance ordering, and block validation --- R/objective_fisher.R | 119 +++++++++-- R/speed.R | 10 +- man/compute_L_projection.Rd | 34 +++- man/cor_ar1_ar1.Rd | 3 +- man/objective_function_info.Rd | 46 ++++- tests/testthat/test-compute_L_projection.R | 25 +++ tests/testthat/test-design_utils.R | 7 +- tests/testthat/test-objective_fisher.R | 221 +++++++++++++++++++-- tests/testthat/test-speed-layouts.R | 4 +- tests/testthat/test-speed.R | 50 +++++ 10 files changed, 459 insertions(+), 60 deletions(-) diff --git a/R/objective_fisher.R b/R/objective_fisher.R index 76dc5286..44a786ac 100644 --- a/R/objective_fisher.R +++ b/R/objective_fisher.R @@ -15,19 +15,18 @@ #' \right)}{tr(I⁻)}. #' - D-optimality: Minimises \eqn{-\log \left| \mathcal{I} \right|}{- #' log(|I|)} -#' @param L_matrix Optional precomputed projection matrix. This is an advanced -#' alternative to `Sigma`; the two cannot be supplied together. -#' @param Sigma Optional covariance matrix whose rows and columns follow the row -#' order of `layout_df`. The projection is computed on the first objective -#' call and reused during optimisation. If both `Sigma` and `L_matrix` are -#' `NULL`, identity covariance is assumed. +#' @param L_matrix Optional precomputed projection matrix in grid order, as +#' returned by [compute_L_projection()]. Cannot be supplied with `Sigma`. +#' @param Sigma Optional covariance matrix in grid order (see Details). If both +#' `Sigma` and `L_matrix` are `NULL`, identity covariance is assumed. #' @param contrast_matrix Numeric contrast matrix with one column per treatment #' level. Column names, when supplied, must match the treatment levels. Only #' these contrasts are required to be estimable and contribute to the #' optimality criterion. The default targets the complete treatment-contrast #' space. -#' @param block_column Column name of the design's block factor. Used when -#' \code{L_matrix} isn't supplied. +#' @param block_column Column name of the design's block factor, with at least +#' two observed blocks. Used when neither `nuisance_formula` nor `L_matrix` +#' is supplied. #' @param nuisance_formula Optional one-sided formula describing nuisance #' effects. Used when \code{L_matrix} is not supplied. If omitted, #' \code{block_column} is treated as a factor. @@ -38,9 +37,30 @@ #' @param swapped_items The treatments swapped by [speed()]. Changed plot rows #' are identified from the cached and proposed allocations so repeated #' treatments and multi-swaps are handled exactly. +#' @inheritParams calculate_adjacency_score +#' @param by Optional column name grouping plots into grids (e.g. `"site"`). +#' `NULL` treats the design as one grid. +#' @param grid_index Optional pre-built list from [grid_indices()], supplied by +#' [speed()] to reuse coordinate validation. Leave `NULL` for direct calls. #' @param ... Extra parameters passed from \code{speed}. #' #' @details +#' The default nuisance model requires a blocked design with at least two +#' observed blocks and no missing block labels. An explicit `nuisance_formula` +#' or `L_matrix` can instead specify a different nuisance model. +#' +#' `Sigma` and `L_matrix` have one row and column per observed plot, ordered by +#' numeric row position and then column position (columns vary fastest), +#' regardless of the row order of `layout_df`. This matches [cor_ar1_ar1()]. +#' For multiple grids, plots are grouped by the factor levels of `by` (sorted +#' labels otherwise) before ordering within each grid. For missing plots, +#' subset the covariance to the observed positions in this order. The +#' projection is cached during optimisation while the covariance and nuisance +#' effects remain unchanged. +#' +#' D-optimality uses a log determinant, so negative scores are valid and do not +#' indicate that the optimum has been reached. +#' #' This function computes the treatment information matrix: #' \deqn{I = X_1^\intercal L X_1}{I = X₁ᵀ L X₁} #' Where \eqn{X_1}{X₁} is the treatment design matrix, and \eqn{L} is the @@ -106,10 +126,19 @@ objective_function_info <- function( tolerance = 1e-9, current_score_obj = NULL, swapped_items = NULL, + row_column = "row", + col_column = "col", + by = NULL, + grid_index = NULL, ... ) { criterion <- match.arg(criterion) + if (!is.null(Sigma) || !is.null(L_matrix)) { + plot_order <- .fisher_plot_order(layout_df, row_column, col_column, by, grid_index) + layout_df <- layout_df[plot_order, , drop = FALSE] + } + fisher_cache <- NULL if (!is.null(swapped_items)) { fisher_cache <- attr(current_score_obj, "fisher_cache", exact = TRUE) @@ -146,6 +175,19 @@ objective_function_info <- function( return(result) } +#' Order observed plots to match spatial covariance matrices +#' @noRd +.fisher_plot_order <- function(layout_df, row_column, col_column, by, grid_index) { + grid_index <- grid_index %||% grid_indices(layout_df, row_column, col_column, by) + plot_order <- unlist(lapply(grid_index, function(g) { + return(g$rows[order(g$index$idx[, 1], g$index$idx[, 2])]) + }), use.names = FALSE) + if (!identical(sort(plot_order), seq_len(nrow(layout_df)))) { + stop("`grid_index` must include every plot exactly once.", call. = FALSE) + } + return(plot_order) +} + #' Build the treatment indicator matrix X1 #' @noRd .build_treatment_matrix <- function(treatments, trt_levels, n, v) { @@ -326,10 +368,18 @@ factorial_contrast_matrix <- function( #' @noRd .build_nuisance_matrix <- function(layout_df, block_column, nuisance_formula) { if (is.null(nuisance_formula)) { - if (!block_column %in% names(layout_df)) { - return(matrix(1, nrow(layout_df), 1L)) + blocks <- layout_df[[block_column]] + if (length(unique(blocks[!is.na(blocks)])) < 2L) { + stop( + "A blocked design with at least two blocks in `", block_column, + "` is required when `nuisance_formula` is not supplied.", + call. = FALSE + ) } - return(stats::model.matrix(~ 0 + block, data.frame(block = factor(layout_df[[block_column]])))) + if (anyNA(blocks)) { + stop("Block labels in `", block_column, "` cannot contain missing values.", call. = FALSE) + } + return(stats::model.matrix(~ 0 + block, data.frame(block = factor(blocks)))) } if (!inherits(nuisance_formula, "formula") || length(nuisance_formula) != 2L) { stop("`nuisance_formula` must be a one-sided formula.", call. = FALSE) @@ -353,6 +403,7 @@ factorial_contrast_matrix <- function( input, block_column, nuisance_formula, + nuisance_data, tolerance, n ) { @@ -361,6 +412,7 @@ factorial_contrast_matrix <- function( identical(cache$projection_input, input) && identical(cache$block_column, block_column) && identical(cache$nuisance_formula, nuisance_formula) && + identical(cache$nuisance_data, nuisance_data) && identical(cache$tolerance, tolerance) && is.matrix(cache$L_matrix) && identical(dim(cache$L_matrix), c(n, n)) @@ -403,6 +455,9 @@ factorial_contrast_matrix <- function( stop("Only one of `Sigma` and `L_matrix` can be supplied.", call. = FALSE) } + nuisance_columns <- if (is.null(nuisance_formula)) block_column else all.vars(nuisance_formula) + nuisance_data <- as.list(layout_df[intersect(nuisance_columns, names(layout_df))]) + if (!is.null(L_matrix)) { projection_source <- "L_matrix" projection_input <- L_matrix @@ -415,12 +470,13 @@ factorial_contrast_matrix <- function( projection_input, block_column, nuisance_formula, + nuisance_data, tolerance, n )) { L_matrix <- cache$L_matrix } else { - L_matrix <- compute_L_projection( + L_matrix <- .build_L_from_Sigma( layout_df, Sigma, block_column, @@ -437,6 +493,7 @@ factorial_contrast_matrix <- function( projection_input, block_column, nuisance_formula, + nuisance_data, tolerance, n )) { @@ -486,6 +543,7 @@ factorial_contrast_matrix <- function( projection_input = projection_input, block_column = block_column, nuisance_formula = nuisance_formula, + nuisance_data = nuisance_data, tolerance = tolerance ) @@ -506,15 +564,23 @@ factorial_contrast_matrix <- function( #' #' @param layout_df Data frame representing the spatial layout of the #' experiment. -#' @param Sigma Covariance structure to use. Its rows and columns must follow -#' the row order of `layout_df`. -#' @param block_column Column name of the design's block factor in -#' \code{layout_df}. +#' @param Sigma Covariance matrix in numeric row-then-column grid order, +#' regardless of the row order of `layout_df`. +#' @inheritParams objective_function_info +#' @param block_column Column name of the design's block factor, with at least +#' two observed blocks. Used when `nuisance_formula` is not supplied. #' @param nuisance_formula Optional one-sided formula describing nuisance -#' effects. If omitted, \code{block_column} is treated as a factor. +#' effects. If omitted, `block_column` is treated as a factor. #' @param tolerance Numerical tolerance used for generalized inverses. #' -#' @return \eqn{(n \times n)} numeric matrix. +#' @details +#' A blocked design with at least two observed blocks and no missing block +#' labels is required unless `nuisance_formula` is supplied. See +#' [objective_function_info()] for the covariance ordering convention, +#' including multiple grids and missing plots. +#' +#' @return \eqn{(n \times n)} numeric matrix in the same grid order as `Sigma`, +#' suitable for the `L_matrix` argument to [objective_function_info()]. #' #' @export compute_L_projection <- function( @@ -522,8 +588,20 @@ compute_L_projection <- function( Sigma, block_column = "block", nuisance_formula = NULL, - tolerance = 1e-10 + tolerance = 1e-10, + row_column = "row", + col_column = "col", + by = NULL, + grid_index = NULL ) { + plot_order <- .fisher_plot_order(layout_df, row_column, col_column, by, grid_index) + layout_df <- layout_df[plot_order, , drop = FALSE] + return(.build_L_from_Sigma(layout_df, Sigma, block_column, nuisance_formula, tolerance)) +} + +#' Build a projection for data already aligned with Sigma +#' @noRd +.build_L_from_Sigma <- function(layout_df, Sigma, block_column, nuisance_formula, tolerance) { n <- nrow(layout_df) if (!is.matrix(Sigma)) { @@ -569,7 +647,8 @@ cor_ar1 <- function(n, rho) { #' @param rho_col Correlation parameter along the column direction. #' #' @return A symmetric \eqn{(\text{n_rows} \cdot \text{n_cols}) \times -#' (\text{n_rows} \cdot \text{n_cols})} correlation matrix. +#' (\text{n_rows} \cdot \text{n_cols})} correlation matrix in row-then-column +#' grid order (columns vary fastest). #' #' @export cor_ar1_ar1 <- function(n_rows, n_cols, rho_row, rho_col) { diff --git a/R/speed.R b/R/speed.R index 0535e0d2..ceda9e52 100644 --- a/R/speed.R +++ b/R/speed.R @@ -461,14 +461,14 @@ speed_hierarchical <- function(data, optimise, quiet, seed, ...) { "\n") } - # Zero is the most optimal score any design can reach. - reached_zero <- new_score < .Machine$double.eps - if (reached_zero || iter - last_improvement_iter >= opt$early_stop_iterations) { + # known lower bound for optimality rather than zero + reached_optimal <- stop_at_optimal && !is.na(optimal_score) && best_score <= optimal_score + 1e-9 + if (reached_optimal || iter - last_improvement_iter >= opt$early_stop_iterations) { if (!quiet) { - cat(if (reached_zero) "Optimal score reached at iteration" else "Early stopping at iteration", + cat(if (reached_optimal) "Optimal score reached at iteration" else "Early stopping at iteration", iter, "for level", level, "\n") } - stop_reason <- if (reached_zero) "optimal" else "no_improvement" + stop_reason <- if (reached_optimal) "optimal" else "no_improvement" # Record final score and temperature before breaking if (iter < opt$iterations) { scores[iter + 1] <- current_score diff --git a/man/compute_L_projection.Rd b/man/compute_L_projection.Rd index 9923f9c2..05341361 100644 --- a/man/compute_L_projection.Rd +++ b/man/compute_L_projection.Rd @@ -9,28 +9,50 @@ compute_L_projection( Sigma, block_column = "block", nuisance_formula = NULL, - tolerance = 1e-10 + tolerance = 1e-10, + row_column = "row", + col_column = "col", + by = NULL, + grid_index = NULL ) } \arguments{ \item{layout_df}{Data frame representing the spatial layout of the experiment.} -\item{Sigma}{Covariance structure to use. Its rows and columns must follow -the row order of \code{layout_df}.} +\item{Sigma}{Covariance matrix in numeric row-then-column grid order, +regardless of the row order of \code{layout_df}.} -\item{block_column}{Column name of the design's block factor in -\code{layout_df}.} +\item{block_column}{Column name of the design's block factor, with at least +two observed blocks. Used when \code{nuisance_formula} is not supplied.} \item{nuisance_formula}{Optional one-sided formula describing nuisance effects. If omitted, \code{block_column} is treated as a factor.} \item{tolerance}{Numerical tolerance used for generalized inverses.} + +\item{row_column}{Name of the column representing rows (default \code{"row"}).} + +\item{col_column}{Name of the column representing columns +(default \code{"col"}).} + +\item{by}{Optional column name grouping plots into grids (e.g. \code{"site"}). +\code{NULL} treats the design as one grid.} + +\item{grid_index}{Optional pre-built list from \code{\link[=grid_indices]{grid_indices()}}, supplied by +\code{\link[=speed]{speed()}} to reuse coordinate validation. Leave \code{NULL} for direct calls.} } \value{ -\eqn{(n \times n)} numeric matrix. +\eqn{(n \times n)} numeric matrix in the same grid order as \code{Sigma}, +suitable for the \code{L_matrix} argument to \code{\link[=objective_function_info]{objective_function_info()}}. } \description{ This is the projection matrix that removes nuisance effects from the GLS's covariance } +\details{ +A blocked design with at least two observed blocks and no missing block +labels is required unless \code{nuisance_formula} is supplied. See +\code{\link[=objective_function_info]{objective_function_info()}} for the covariance ordering convention, +including multiple grids and missing plots. +} diff --git a/man/cor_ar1_ar1.Rd b/man/cor_ar1_ar1.Rd index bbb4b2be..ea71f03d 100644 --- a/man/cor_ar1_ar1.Rd +++ b/man/cor_ar1_ar1.Rd @@ -17,7 +17,8 @@ cor_ar1_ar1(n_rows, n_cols, rho_row, rho_col) } \value{ A symmetric \eqn{(\text{n_rows} \cdot \text{n_cols}) \times - (\text{n_rows} \cdot \text{n_cols})} correlation matrix. + (\text{n_rows} \cdot \text{n_cols})} correlation matrix in row-then-column +grid order (columns vary fastest). } \description{ Construct a 2 dimensional lag-1 autoregressive covariance diff --git a/man/objective_function_info.Rd b/man/objective_function_info.Rd index db4acc04..f0744c95 100644 --- a/man/objective_function_info.Rd +++ b/man/objective_function_info.Rd @@ -17,6 +17,10 @@ objective_function_info( tolerance = 1e-09, current_score_obj = NULL, swapped_items = NULL, + row_column = "row", + col_column = "col", + by = NULL, + grid_index = NULL, ... ) } @@ -35,13 +39,11 @@ optimality. - D-optimality: Minimises \eqn{-\log \left| \mathcal{I} \right|}{- log(|I|)}} -\item{L_matrix}{Optional precomputed projection matrix. This is an advanced -alternative to \code{Sigma}; the two cannot be supplied together.} +\item{L_matrix}{Optional precomputed projection matrix in grid order, as +returned by \code{\link[=compute_L_projection]{compute_L_projection()}}. Cannot be supplied with \code{Sigma}.} -\item{Sigma}{Optional covariance matrix whose rows and columns follow the row -order of \code{layout_df}. The projection is computed on the first objective -call and reused during optimisation. If both \code{Sigma} and \code{L_matrix} are -\code{NULL}, identity covariance is assumed.} +\item{Sigma}{Optional covariance matrix in grid order (see Details). If both +\code{Sigma} and \code{L_matrix} are \code{NULL}, identity covariance is assumed.} \item{contrast_matrix}{Numeric contrast matrix with one column per treatment level. Column names, when supplied, must match the treatment levels. Only @@ -49,8 +51,9 @@ these contrasts are required to be estimable and contribute to the optimality criterion. The default targets the complete treatment-contrast space.} -\item{block_column}{Column name of the design's block factor. Used when -\code{L_matrix} isn't supplied.} +\item{block_column}{Column name of the design's block factor, with at least +two observed blocks. Used when neither \code{nuisance_formula} nor \code{L_matrix} +is supplied.} \item{nuisance_formula}{Optional one-sided formula describing nuisance effects. Used when \code{L_matrix} is not supplied. If omitted, @@ -66,6 +69,17 @@ after the initial call. Used to reuse invariant matrix calculations.} are identified from the cached and proposed allocations so repeated treatments and multi-swaps are handled exactly.} +\item{row_column}{Name of the column representing rows (default \code{"row"}).} + +\item{col_column}{Name of the column representing columns +(default \code{"col"}).} + +\item{by}{Optional column name grouping plots into grids (e.g. \code{"site"}). +\code{NULL} treats the design as one grid.} + +\item{grid_index}{Optional pre-built list from \code{\link[=grid_indices]{grid_indices()}}, supplied by +\code{\link[=speed]{speed()}} to reuse coordinate validation. Leave \code{NULL} for direct calls.} + \item{...}{Extra parameters passed from \code{speed}.} } \value{ @@ -79,6 +93,22 @@ effects, and takes an optional spatial covariance structure for spatial optimisation. } \details{ +The default nuisance model requires a blocked design with at least two +observed blocks and no missing block labels. An explicit \code{nuisance_formula} +or \code{L_matrix} can instead specify a different nuisance model. + +\code{Sigma} and \code{L_matrix} have one row and column per observed plot, ordered by +numeric row position and then column position (columns vary fastest), +regardless of the row order of \code{layout_df}. This matches \code{\link[=cor_ar1_ar1]{cor_ar1_ar1()}}. +For multiple grids, plots are grouped by the factor levels of \code{by} (sorted +labels otherwise) before ordering within each grid. For missing plots, +subset the covariance to the observed positions in this order. The +projection is cached during optimisation while the covariance and nuisance +effects remain unchanged. + +D-optimality uses a log determinant, so negative scores are valid and do not +indicate that the optimum has been reached. + This function computes the treatment information matrix: \deqn{I = X_1^\intercal L X_1}{I = X₁ᵀ L X₁} Where \eqn{X_1}{X₁} is the treatment design matrix, and \eqn{L} is the diff --git a/tests/testthat/test-compute_L_projection.R b/tests/testthat/test-compute_L_projection.R index ff3e58a3..31e00563 100644 --- a/tests/testthat/test-compute_L_projection.R +++ b/tests/testthat/test-compute_L_projection.R @@ -46,3 +46,28 @@ test_that("compute_L_projection supports nuisance formulas", { expect_equal(unname(spatial), unname(direct), tolerance = 1e-10) }) + +test_that("compute_L_projection returns a projection in grid order", { + df <- initialise_design_df( + items = 6, nrows = 4, ncols = 6, + block_nrows = 1, block_ncols = 6 + ) + Sigma <- cor_ar1_ar1(4, 6, rho_row = 0.6, rho_col = 0.3) + X2 <- kronecker(diag(4), rep(1, 6)) + Sigma_inv <- solve(Sigma) + expected <- Sigma_inv - Sigma_inv %*% X2 %*% + solve(crossprod(X2, Sigma_inv %*% X2)) %*% t(X2) %*% Sigma_inv + + for (layout in list(df, df[rev(seq_len(nrow(df))), ])) { + result <- compute_L_projection(layout, Sigma) + expect_equal(unname(result), unname(expected), tolerance = 1e-10) + expect_equal(unname(result %*% X2), matrix(0, 24, 4), tolerance = 1e-10) + } +}) + +test_that("compute_L_projection requires at least two blocks by default", { + df <- data.frame(row = rep(1:2, each = 2), col = rep(1:2, 2)) + expect_error(compute_L_projection(df, diag(4)), "at least two blocks") + df$block <- factor(rep(1, 4), levels = 1:2) + expect_error(compute_L_projection(df, diag(4)), "at least two blocks") +}) diff --git a/tests/testthat/test-design_utils.R b/tests/testthat/test-design_utils.R index c90055d0..4961e894 100644 --- a/tests/testthat/test-design_utils.R +++ b/tests/testthat/test-design_utils.R @@ -427,7 +427,7 @@ test_that("speed() records why each level stopped", { ) }) -test_that("speed() calls a score of zero optimal without a derived lower bound", { +test_that("speed() stops on no improvement at zero without a derived lower bound", { df <- data.frame( row = rep(1:4, times = 5), col = rep(1:5, each = 4), @@ -436,7 +436,7 @@ test_that("speed() calls a score of zero optimal without a derived lower bound", ) # A custom objective, so no lower bound can be derived and `optimal_score` is - # `NA`. Reaching zero is still optimal rather than merely out of improvements. + # `NA`. A zero score does not establish optimality. obj_runs <- function(layout_df, swap, spatial_cols, ...) { trt <- as.character(layout_df[[swap]]) return(list(score = as.numeric(sum(trt[-1] == trt[-length(trt)])))) @@ -453,7 +453,8 @@ test_that("speed() calls a score of zero optimal without a derived lower bound", expect_equal(result$score, 0) expect_true(is.na(result$metadata$per_level[[1]]$optimal_score)) - expect_equal(result$metadata$per_level[[1]]$stop_reason, "optimal") + expect_equal(result$metadata$per_level[[1]]$stop_reason, "no_improvement") + expect_gt(result$iterations_run, 2000) }) test_that("speed() does not warn when every group can swap", { diff --git a/tests/testthat/test-objective_fisher.R b/tests/testthat/test-objective_fisher.R index 6cbb22e3..9ba660a1 100644 --- a/tests/testthat/test-objective_fisher.R +++ b/tests/testthat/test-objective_fisher.R @@ -213,32 +213,188 @@ test_that("incremental calculation matches full recalculation", { }) test_that("covariance matrices remain aligned when layout rows are reordered", { - df <- data.frame( - row = rep(1:3, each = 4), - col = rep(1:4, times = 3), - block = rep(1:3, each = 4), - treatment = rep(LETTERS[1:4], 3) + df <- initialise_design_df( + items = 6, nrows = 4, ncols = 6, + block_nrows = 1, block_ncols = 6 ) - Sigma <- cor_ar1_ar1(3, 4, rho_row = 0.6, rho_col = 0.3) + Sigma <- cor_ar1_ar1(4, 6, rho_row = 0.6, rho_col = 0.3) + sorted <- df[order(df$row, df$col), ] + reordered <- df[rev(seq_len(nrow(df))), ] + L <- compute_L_projection(df, Sigma) + + for (criterion in c("A", "D")) { + original <- objective_function_info( + sorted, "treatment", c("row", "col"), + criterion = criterion, Sigma = Sigma + ) + for (layout in list(df, reordered)) { + result <- objective_function_info( + layout, "treatment", c("row", "col"), + criterion = criterion, Sigma = Sigma + ) + incremental <- objective_function_info( + layout, "treatment", c("row", "col"), + criterion = criterion, Sigma = Sigma, + current_score_obj = original, swapped_items = unique(df$treatment) + ) + precomputed <- objective_function_info( + layout, "treatment", c("row", "col"), + criterion = criterion, L_matrix = L + ) + + expect_equal(result$info_matrix, original$info_matrix, tolerance = 1e-12) + expect_equal(result$score, original$score, tolerance = 1e-12) + expect_equal(incremental$info_matrix, original$info_matrix, tolerance = 1e-12) + expect_equal(precomputed$info_matrix, original$info_matrix, tolerance = 1e-12) + } + } +}) + +test_that("spatial scoring uses numeric coordinates and custom grid columns", { + df <- initialise_design_df( + items = 6, nrows = 4, ncols = 6, + block_nrows = 1, block_ncols = 6 + ) + Sigma <- cor_ar1_ar1(4, 6, rho_row = 0.6, rho_col = 0.3) + original <- objective_function_info(df, "treatment", c("row", "col"), Sigma = Sigma) + names(df)[names(df) == "row"] <- "x" + names(df)[names(df) == "col"] <- "y" + df$x <- factor(df$x, levels = 4:1) + df$y <- factor(df$y, levels = 6:1) + + for (index in list(NULL, grid_indices(df, "x", "y"))) { + result <- objective_function_info( + df, "treatment", c("x", "y"), Sigma = Sigma, + row_column = "x", col_column = "y", grid_index = index + ) + expect_equal(result$info_matrix, original$info_matrix, tolerance = 1e-12) + } +}) + +test_that("spatial scoring orders multiple grids consistently", { + df <- initialise_design_df( + items = 4, nrows = 3, ncols = 4, + block_nrows = 1, block_ncols = 4 + ) + df <- rbind(transform(df, site = "A"), transform(df, site = "B")) + df$block <- interaction(df$site, df$block, drop = TRUE) + df$treatment[c(13, 16)] <- df$treatment[c(16, 13)] + Sigma <- kronecker(diag(c(1, 2)), cor_ar1_ar1(3, 4, rho_row = 0.6, rho_col = 0.3)) original <- objective_function_info( - df, - "treatment", - c("row", "col"), - Sigma = Sigma + df, "treatment", c("row", "col"), Sigma = Sigma, by = "site" + ) + site_a <- objective_function_info( + df[1:12, ], "treatment", c("row", "col"), Sigma = Sigma[1:12, 1:12] + ) + site_b <- objective_function_info( + df[13:24, ], "treatment", c("row", "col"), Sigma = Sigma[13:24, 13:24] + ) + expect_equal(original$info_matrix, site_a$info_matrix + site_b$info_matrix, tolerance = 1e-12) + reordered <- df[rev(seq_len(nrow(df))), ] + for (index in list(NULL, grid_indices(reordered, by = "site"))) { + result <- objective_function_info( + reordered, "treatment", c("row", "col"), Sigma = Sigma, + by = "site", grid_index = index + ) + expect_equal(result$info_matrix, original$info_matrix, tolerance = 1e-12) + } + + result <- speed( + reordered, + swap = "treatment", + swap_within = "block", + grid_factors = list(dim1 = "row", dim2 = "col", by = "site"), + obj_function = objective_function_info, + Sigma = Sigma, + iterations = 20, + early_stop_iterations = 100, + optimise_params = optim_params(random_initialisation = 2), + seed = 1, + quiet = TRUE + ) + final <- objective_function_info( + result$design_df, "treatment", c("row", "col"), Sigma = Sigma, by = "site" ) + expect_equal(result$score, final$score, tolerance = 1e-10) + expect_lte(result$score, original$score) +}) - row_order <- c(5:12, 1:4) +test_that("spatial scoring accepts covariance for observed plots only", { + df <- initialise_design_df( + items = 4, nrows = 3, ncols = 4, + block_nrows = 1, block_ncols = 4 + ) + df <- df[order(df$row, df$col), ] + observed <- setdiff(seq_len(nrow(df)), c(2, 7)) + df <- df[observed, ] + Sigma <- cor_ar1_ar1(3, 4, rho_row = 0.6, rho_col = 0.3)[observed, observed] + original <- objective_function_info(df, "treatment", c("row", "col"), Sigma = Sigma) reordered <- objective_function_info( - df[row_order, ], - "treatment", - c("row", "col"), - Sigma = Sigma[row_order, row_order] + df[rev(seq_len(nrow(df))), ], "treatment", c("row", "col"), Sigma = Sigma ) + expect_true(original$estimable) expect_equal(reordered$info_matrix, original$info_matrix, tolerance = 1e-12) expect_equal(reordered$score, original$score, tolerance = 1e-12) }) +test_that("cached projections are rebuilt when nuisance effects change", { + df <- initialise_design_df( + items = 6, nrows = 4, ncols = 6, + block_nrows = 1, block_ncols = 6 + ) + Sigma <- cor_ar1_ar1(4, 6, rho_row = 0.6, rho_col = 0.3) + + for (covariance in list(NULL, Sigma)) { + original <- objective_function_info(df, "treatment", c("row", "col"), Sigma = covariance) + proposal <- df + proposal$block[c(1, 6)] <- proposal$block[c(6, 1)] + incremental <- objective_function_info( + proposal, "treatment", c("row", "col"), Sigma = covariance, + current_score_obj = original, swapped_items = unique(df$treatment) + ) + full <- objective_function_info(proposal, "treatment", c("row", "col"), Sigma = covariance) + + expect_false(isTRUE(all.equal(full$info_matrix, original$info_matrix))) + expect_equal(incremental$info_matrix, full$info_matrix, tolerance = 1e-12) + expect_equal(incremental$score, full$score, tolerance = 1e-12) + } +}) + +test_that("the default nuisance model requires at least two blocks", { + df <- data.frame(treatment = rep(c("A", "B"), 2)) + expect_error(objective_function_info(df, "treatment", character()), "at least two blocks") + df$block <- factor(rep(1, 4), levels = 1:2) + expect_error(objective_function_info(df, "treatment", character()), "at least two blocks") + df$block <- rep(NA_integer_, 4) + expect_error(objective_function_info(df, "treatment", character()), "at least two blocks") + df$block <- c(1, 1, 2, NA) + expect_error(objective_function_info(df, "treatment", character()), "missing") +}) + +test_that("explicit nuisance models can replace the block model", { + df <- initialise_design_df( + items = 4, nrows = 3, ncols = 4, + block_nrows = 1, block_ncols = 4 + ) + Sigma <- cor_ar1_ar1(3, 4, rho_row = 0.6, rho_col = 0.3) + original <- objective_function_info(df, "treatment", c("row", "col"), Sigma = Sigma) + L <- compute_L_projection(df, Sigma) + + for (blocks in list(NULL, rep(1, nrow(df)))) { + df$block <- blocks + custom <- objective_function_info( + df, "treatment", c("row", "col"), Sigma = Sigma, + nuisance_formula = ~ factor(row) + ) + precomputed <- objective_function_info( + df, "treatment", c("row", "col"), L_matrix = L + ) + expect_equal(custom$info_matrix, original$info_matrix, tolerance = 1e-12) + expect_equal(precomputed$info_matrix, original$info_matrix, tolerance = 1e-12) + } +}) + test_that("Sigma and L_matrix are mutually exclusive", { df <- data.frame( row = 1:4, @@ -261,6 +417,41 @@ test_that("Sigma and L_matrix are mutually exclusive", { # ---- Test with speed function +test_that("speed() does not treat negative D-optimality scores as an optimum", { + df <- initialise_design_df( + items = 6, nrows = 4, ncols = 6, + block_nrows = 1, block_ncols = 6 + ) + Sigma <- cor_ar1_ar1(4, 6, rho_row = 0.6, rho_col = 0.3) + + for (covariance in list(NULL, Sigma)) { + result <- speed( + df, + swap = "treatment", + swap_within = "block", + obj_function = objective_function_info, + criterion = "D", + Sigma = covariance, + iterations = 100, + early_stop_iterations = 200, + seed = 1, + quiet = TRUE + ) + final <- objective_function_info( + result$design_df, "treatment", c("row", "col"), + criterion = "D", Sigma = covariance + ) + + expect_lt(result$score, 0) + expect_equal(result$iterations_run, 100) + expect_identical(result$metadata$per_level[[1]]$stop_reason, "iterations") + expect_equal(result$score, final$score, tolerance = 1e-10) + if (is.null(covariance)) { + expect_equal(result$scores, rep(-5 * log(4), 100), tolerance = 1e-10) + } + } +}) + # Actually test by passing to speed test_that("speed() optimises an RCBD with the info objective under AR1xAR1", { skip_if_not_installed("speed") diff --git a/tests/testthat/test-speed-layouts.R b/tests/testthat/test-speed-layouts.R index bcea3752..23cf9582 100644 --- a/tests/testthat/test-speed-layouts.R +++ b/tests/testthat/test-speed-layouts.R @@ -101,8 +101,8 @@ test_that("speed works with a custom objective function", { expect_s3_class(result, "design") expect_equal(result$score, 0) - expect_equal(result$iterations_run, 742) - expect_equal(result$stopped_early, TRUE) + expect_equal(result$iterations_run, 1000) + expect_equal(result$stopped_early, FALSE) vdiffr::expect_doppelganger("speed_custom_obj_func", autoplot(result)) }) diff --git a/tests/testthat/test-speed.R b/tests/testthat/test-speed.R index a4202395..81425990 100644 --- a/tests/testthat/test-speed.R +++ b/tests/testthat/test-speed.R @@ -270,6 +270,56 @@ test_that("speed does not stop on the optimal score for custom objectives", { expect_equal(result$iterations_run, 200) }) +test_that("zero and negative custom scores do not imply optimality", { + test_data <- expand.grid(row = 1:2, col = 1:2) + test_data$treatment <- c("A", "B", "B", "A") + + for (value in c(0, -1)) { + custom_objective <- function(layout_df, swap, spatial_cols, ...) { + return(list(score = value)) + } + result <- speed( + test_data, + swap = "treatment", + obj_function = custom_objective, + iterations = 20, + early_stop_iterations = 100, + seed = 1, + quiet = TRUE + ) + + expect_equal(result$iterations_run, 20) + expect_equal(result$scores, rep(value, 20)) + expect_identical(result$metadata$per_level[[1]]$stop_reason, "iterations") + expect_false(result$stopped_early) + } +}) + +test_that("stop_at_optimal also controls stopping at a zero bound", { + test_data <- expand.grid(row = 1:2, col = 1:2) + test_data$treatment <- c("A", "B", "B", "A") + + for (stop_at_optimal in c(TRUE, FALSE)) { + result <- speed( + test_data, + swap = "treatment", + optimise_params = optim_params( + adj_weight = 0, + bal_weight = 0, + stop_at_optimal = stop_at_optimal + ), + iterations = 20, + early_stop_iterations = 100, + seed = 1, + quiet = TRUE + ) + + expect_equal(result$metadata$per_level[[1]]$optimal_score, 0) + expect_equal(result$iterations_run, if (stop_at_optimal) 1 else 20) + expect_equal(result$stopped_early, stop_at_optimal) + } +}) + test_that("speed does not stop on the optimal score (NA) for negative weights", { test_data <- expand.grid(row = 1:5, col = 1:4) test_data$treatment <- LETTERS[1:4] From a346cfd4adc80eb8e855685230f9ab6090e4abaa Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Mon, 19 Oct 2026 15:36:39 +0800 Subject: [PATCH 17/25] fix info-obj caching, invalid scores, scalar inverse --- R/objective_fisher.R | 15 ++++- R/speed.R | 5 +- R/utils.R | 2 +- man/objective_function_info.Rd | 3 + tests/testthat/test-objective_fisher.R | 90 +++++++++++++++++++++++++- tests/testthat/test-speed.R | 83 ++++++++++++++++++++++++ tests/testthat/test-utils.R | 7 ++ 7 files changed, 197 insertions(+), 8 deletions(-) diff --git a/R/objective_fisher.R b/R/objective_fisher.R index 44a786ac..1044fd53 100644 --- a/R/objective_fisher.R +++ b/R/objective_fisher.R @@ -61,6 +61,9 @@ #' D-optimality uses a log determinant, so negative scores are valid and do not #' indicate that the optimum has been reached. #' +#' Non-estimable requested contrasts receive an infinite score, so invalid +#' designs cannot be preferred to designs with large finite scores. +#' #' This function computes the treatment information matrix: #' \deqn{I = X_1^\intercal L X_1}{I = X₁ᵀ L X₁} #' Where \eqn{X_1}{X₁} is the treatment design matrix, and \eqn{L} is the @@ -157,7 +160,6 @@ objective_function_info <- function( ci$info, ci$trt_levels, contrast_matrix, tolerance ) score <- diagnostics[[paste0(criterion, "_value")]] - if (!is.finite(score)) score <- 1e10 result <- list( score = score, @@ -455,8 +457,15 @@ factorial_contrast_matrix <- function( stop("Only one of `Sigma` and `L_matrix` can be supplied.", call. = FALSE) } - nuisance_columns <- if (is.null(nuisance_formula)) block_column else all.vars(nuisance_formula) - nuisance_data <- as.list(layout_df[intersect(nuisance_columns, names(layout_df))]) + nuisance_data <- NULL + if (is.null(L_matrix)) { + nuisance_data <- if (is.null(nuisance_formula)) { + layout_df[[block_column]] + } else { + # Evaluating the formula also captures `.` and variables in its environment. + .build_nuisance_matrix(layout_df, block_column, nuisance_formula) + } + } if (!is.null(L_matrix)) { projection_source <- "L_matrix" diff --git a/R/speed.R b/R/speed.R index ceda9e52..b23bd490 100644 --- a/R/speed.R +++ b/R/speed.R @@ -432,7 +432,10 @@ speed_hierarchical <- function(data, optimise, quiet, seed, ...) { new_score <- new_score_obj$score # Decide whether to accept the new design - if (new_score < current_score || runif(1) < exp((current_score - new_score) / temp)) { + # Allow moves between invalid designs without evaluating Inf - Inf + if (new_score < current_score || + (is.infinite(current_score) && new_score == current_score) || + runif(1) < exp((current_score - new_score) / temp)) { current_design <- new_design$design current_score <- new_score current_score_obj <- new_score_obj diff --git a/R/utils.R b/R/utils.R index f8bcc2e8..f9760d45 100644 --- a/R/utils.R +++ b/R/utils.R @@ -34,7 +34,7 @@ pseudo_inverse <- function(a_matrix, tolerance = 1e-10) { if (rank_a > 0) { diag_values <- numeric(ncol(svd_a$v)) diag_values[1:rank_a] <- 1 / svd_a$d[1:rank_a] - return(svd_a$v %*% diag(diag_values) %*% t(svd_a$u)) + return(svd_a$v %*% diag(diag_values, nrow = length(diag_values)) %*% t(svd_a$u)) } else { matrix_name <- deparse(substitute(a_matrix)) stop(paste0(matrix_name, " has rank 0 - design may be invalid")) diff --git a/man/objective_function_info.Rd b/man/objective_function_info.Rd index f0744c95..7c850bee 100644 --- a/man/objective_function_info.Rd +++ b/man/objective_function_info.Rd @@ -109,6 +109,9 @@ effects remain unchanged. D-optimality uses a log determinant, so negative scores are valid and do not indicate that the optimum has been reached. +Non-estimable requested contrasts receive an infinite score, so invalid +designs cannot be preferred to designs with large finite scores. + This function computes the treatment information matrix: \deqn{I = X_1^\intercal L X_1}{I = X₁ᵀ L X₁} Where \eqn{X_1}{X₁} is the treatment design matrix, and \eqn{L} is the diff --git a/tests/testthat/test-objective_fisher.R b/tests/testthat/test-objective_fisher.R index 9ba660a1..6e50757e 100644 --- a/tests/testthat/test-objective_fisher.R +++ b/tests/testthat/test-objective_fisher.R @@ -93,7 +93,7 @@ test_that("D-optimality criterion works", { # if treatments never exist in the same block together, you cant compare them, # so the design is fully broken -test_that("disconnected designs have massive penalty", { +test_that("disconnected designs have infinite scores", { df <- data.frame( row = 1:6, col = c(1, 2, 1, 2, 1, 2), @@ -106,12 +106,33 @@ test_that("disconnected designs have massive penalty", { criterion = "A" ) - expect_gte(result$score, 1e9) - expect_true(is.finite(result$score)) + expect_equal(result$score, Inf) + expect_false(result$estimable) expect_equal(result$A_value, Inf) expect_equal(result$D_value, Inf) }) +test_that("large finite contrast variances are preferable to non-estimable targets", { + df <- data.frame( + row = rep(1:2, each = 4), col = rep(1:4, 2), + block = rep(1:2, each = 4), treatment = rep(c("A", "B"), 4) + ) + contrast <- matrix(c(1e6, -1e6), nrow = 1, dimnames = list(NULL, c("A", "B"))) + connected <- objective_function_info( + df, "treatment", c("row", "col"), contrast_matrix = contrast + ) + df$treatment <- rep(c("A", "B"), each = 4) + disconnected <- objective_function_info( + df, "treatment", c("row", "col"), contrast_matrix = contrast + ) + + expect_equal(connected$score, 5e11, tolerance = 1e-10) + expect_true(connected$estimable) + expect_equal(disconnected$score, Inf) + expect_false(disconnected$estimable) + expect_lt(connected$score, disconnected$score) +}) + test_that("information matrix for an RCBD has the expected rank", { df <- data.frame( row = rep(1:3, each = 5), @@ -361,6 +382,57 @@ test_that("cached projections are rebuilt when nuisance effects change", { } }) +test_that("formula expansion and environment changes invalidate the projection", { + df <- initialise_design_df( + items = 4, nrows = 3, ncols = 4, + block_nrows = 1, block_ncols = 4 + ) + df <- df[order(df$row, df$col), ] + df$block <- factor(df$block) + Sigma <- cor_ar1_ar1(3, 4, 0.6, 0.3) + + for (covariance in list(NULL, Sigma)) { + nuisance <- ~ . - treatment - row - col + original <- objective_function_info( + df, "treatment", c("row", "col"), + Sigma = covariance, nuisance_formula = nuisance + ) + proposal <- df + proposal$block[c(1, 6)] <- proposal$block[c(6, 1)] + cached <- objective_function_info( + proposal, "treatment", c("row", "col"), + Sigma = covariance, nuisance_formula = nuisance, + current_score_obj = original, swapped_items = unique(df$treatment) + ) + full <- objective_function_info( + proposal, "treatment", c("row", "col"), + Sigma = covariance, nuisance_formula = nuisance + ) + expect_false(isTRUE(all.equal(original$info_matrix, full$info_matrix))) + expect_equal(cached$info_matrix, full$info_matrix, tolerance = 1e-10) + expect_equal(cached$score, full$score, tolerance = 1e-10) + + adjustment <- rep(c(0, 1, 0, 1), 3) + nuisance <- ~ block + adjustment + original <- objective_function_info( + df, "treatment", c("row", "col"), + Sigma = covariance, nuisance_formula = nuisance + ) + adjustment <- rep(c(0, 0, 1, 1), 3) + cached <- objective_function_info( + df, "treatment", c("row", "col"), + Sigma = covariance, nuisance_formula = nuisance, + current_score_obj = original, swapped_items = unique(df$treatment) + ) + full <- objective_function_info( + df, "treatment", c("row", "col"), + Sigma = covariance, nuisance_formula = nuisance + ) + expect_false(isTRUE(all.equal(original$info_matrix, full$info_matrix))) + expect_equal(cached$info_matrix, full$info_matrix, tolerance = 1e-10) + } +}) + test_that("the default nuisance model requires at least two blocks", { df <- data.frame(treatment = rep(c("A", "B"), 2)) expect_error(objective_function_info(df, "treatment", character()), "at least two blocks") @@ -395,6 +467,18 @@ test_that("explicit nuisance models can replace the block model", { } }) +test_that("intercept-only nuisance formulas produce the expected information", { + df <- data.frame(row = 1:4, col = 1L, treatment = c("A", "B", "A", "B")) + for (covariance in list(NULL, diag(4))) { + result <- objective_function_info( + df, "treatment", c("row", "col"), + Sigma = covariance, nuisance_formula = ~ 1 + ) + expect_equal(unname(result$info_matrix), matrix(c(1, -1, -1, 1), 2, 2)) + expect_equal(result$A_value, 0.5, tolerance = 1e-10) + } +}) + test_that("Sigma and L_matrix are mutually exclusive", { df <- data.frame( row = 1:4, diff --git a/tests/testthat/test-speed.R b/tests/testthat/test-speed.R index 81425990..61d55175 100644 --- a/tests/testthat/test-speed.R +++ b/tests/testthat/test-speed.R @@ -71,6 +71,89 @@ test_that("speed returns correct output structure", { vdiffr::expect_doppelganger("speed_small", autoplot(result)) }) +test_that("annealing traverses invalid designs before reaching a valid design", { + initial_treatment <- LETTERS[1:4] + objective <- function(layout_df, swap, spatial_cols, ...) { + moved <- as.character(layout_df$treatment) != initial_treatment + return(list(score = if (all(moved)) 0 else Inf)) + } + design <- data.frame( + row = rep(1:2, each = 2), + col = rep(1:2, times = 2), + treatment = initial_treatment + ) + + result <- speed( + design, + swap = "treatment", + obj_function = objective, + iterations = 30, + early_stop_iterations = 100, + optimise_params = optim_params(stop_at_optimal = FALSE), + seed = 1, + quiet = TRUE + ) + + # No single swap can move all four treatments; an invalid step is necessary. + expect_equal(result$scores[1:2], c(Inf, Inf)) + expect_equal(result$score, 0) + expect_true(all(as.character(result$design_df$treatment) != initial_treatment)) +}) + +test_that("annealing rejects an invalid proposal from a finite design", { + initial_treatment <- LETTERS[1:4] + objective <- function(layout_df, swap, spatial_cols, ...) { + score <- if (identical(as.character(layout_df$treatment), initial_treatment)) 0 else Inf + return(list(score = score)) + } + design <- data.frame( + row = rep(1:2, each = 2), + col = rep(1:2, times = 2), + treatment = initial_treatment + ) + + result <- speed( + design, + swap = "treatment", + obj_function = objective, + iterations = 1, + early_stop_iterations = 10, + optimise_params = optim_params(stop_at_optimal = FALSE), + seed = 1, + quiet = TRUE + ) + + expect_equal(result$scores, 0) + expect_equal(result$score, 0) + expect_identical(as.character(result$design_df$treatment), initial_treatment) +}) + +test_that("all-invalid annealing runs finish without NaN acceptance", { + objective <- function(layout_df, swap, spatial_cols, ...) { + return(list(score = Inf)) + } + design <- data.frame( + row = rep(1:2, each = 2), + col = rep(1:2, times = 2), + treatment = LETTERS[1:4] + ) + + result <- speed( + design, + swap = "treatment", + obj_function = objective, + iterations = 5, + early_stop_iterations = 10, + optimise_params = optim_params(random_initialisation = 2, stop_at_optimal = FALSE), + seed = 1, + quiet = TRUE + ) + + expect_equal(result$iterations_run, 5) + expect_equal(result$score, Inf) + expect_true(all(is.infinite(result$scores))) +}) + test_that("speed throws error for missing columns", { test_data <- data.frame( row = rep(1:5, times = 4), diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index b9378078..f1e2ab60 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -13,6 +13,13 @@ test_that("pseudo_inverse calculates Moore-Penrose inverse correctly", { expect_equal(A_inv, solve(A), tolerance = 1e-10) }) +test_that("pseudo_inverse handles 1x1 matrices", { + for (value in c(2, 0.5)) { + A <- matrix(value, nrow = 1, ncol = 1) + expect_equal(pseudo_inverse(A), matrix(1 / value, nrow = 1, ncol = 1)) + } +}) + test_that("pseudo_inverse handles singular matrices", { # Test with a rank-deficient matrix (singular) singular_matrix <- matrix(c(1, 2, 2, 4), nrow = 2, ncol = 2) From 57e4ac2f0ddd95bf4b98e6e4e60036891e9699cd Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Mon, 19 Oct 2026 16:57:03 +0800 Subject: [PATCH 18/25] fix formatting, tweak some docstrings --- R/objective_fisher.R | 119 +++++++++++++++++++++---------- man/compute_L_projection.Rd | 4 +- man/cor_ar1.Rd | 2 +- man/factorial_contrast_matrix.Rd | 2 +- 4 files changed, 86 insertions(+), 41 deletions(-) diff --git a/R/objective_fisher.R b/R/objective_fisher.R index 1044fd53..3a57c637 100644 --- a/R/objective_fisher.R +++ b/R/objective_fisher.R @@ -138,7 +138,9 @@ objective_function_info <- function( criterion <- match.arg(criterion) if (!is.null(Sigma) || !is.null(L_matrix)) { - plot_order <- .fisher_plot_order(layout_df, row_column, col_column, by, grid_index) + plot_order <- .fisher_plot_order( + layout_df, row_column, col_column, by, grid_index + ) layout_df <- layout_df[plot_order, , drop = FALSE] } @@ -179,8 +181,11 @@ objective_function_info <- function( #' Order observed plots to match spatial covariance matrices #' @noRd -.fisher_plot_order <- function(layout_df, row_column, col_column, by, grid_index) { - grid_index <- grid_index %||% grid_indices(layout_df, row_column, col_column, by) +.fisher_plot_order <- function( + layout_df, row_column, col_column, by, grid_index +) { + grid_index <- grid_index %||% + grid_indices(layout_df, row_column, col_column, by) plot_order <- unlist(lapply(grid_index, function(g) { return(g$rows[order(g$index$idx[, 1], g$index$idx[, 2])]) }), use.names = FALSE) @@ -195,7 +200,9 @@ objective_function_info <- function( .build_treatment_matrix <- function(treatments, trt_levels, n, v) { X1 <- matrix(0, n, v) trt_idx <- match(treatments, trt_levels) - if (anyNA(trt_idx)) stop("Treatment allocations cannot contain missing values.", call. = FALSE) + if (anyNA(trt_idx)) { + stop("Treatment allocations cannot contain missing values.", call. = FALSE) + } X1[cbind(seq_len(n), trt_idx)] <- 1 return(X1) } @@ -214,7 +221,7 @@ objective_function_info <- function( #' @param treatment_column Column containing the atomic treatment labels. #' @param tolerance Numerical rank tolerance. #' -#' @return A numeric contrast matrix whose columns are named by treatment level. +#' @return A numeric contrast matrix with columns named by treatment level. #' #' @export factorial_contrast_matrix <- function( @@ -235,7 +242,10 @@ factorial_contrast_matrix <- function( treatment_levels <- as.character(treatment_df[[treatment_column]]) if (anyNA(treatment_levels) || anyDuplicated(treatment_levels)) { - stop("`treatment_df` must contain one non-missing row per treatment.", call. = FALSE) + stop( + "`treatment_df` must contain one non-missing row per treatment.", + call. = FALSE + ) } formula_vars <- all.vars(formula) @@ -262,7 +272,10 @@ factorial_contrast_matrix <- function( stop("`formula` does not define any treatment contrasts.", call. = FALSE) } - basis <- qr.Q(decomposition, complete = FALSE)[, seq_len(effect_rank), drop = FALSE] + basis <- qr.Q( + decomposition, + complete = FALSE + )[, seq_len(effect_rank), drop = FALSE] contrasts <- t(basis) rownames(contrasts) <- paste0("contrast_", seq_len(nrow(contrasts))) colnames(contrasts) <- treatment_levels @@ -289,39 +302,58 @@ factorial_contrast_matrix <- function( } if (is.null(colnames(contrast_matrix))) { if (ncol(contrast_matrix) != v) { - stop("`contrast_matrix` must have one column per treatment.", call. = FALSE) + stop( + "`contrast_matrix` must have one column per treatment.", + call. = FALSE + ) } colnames(contrast_matrix) <- trt_levels } else { missing <- setdiff(trt_levels, colnames(contrast_matrix)) extra <- setdiff(colnames(contrast_matrix), trt_levels) if (length(missing) > 0L || length(extra) > 0L) { - stop("Contrast columns must match the treatment levels.", call. = FALSE) + stop( + "Contrast columns must match the treatment levels.", + call. = FALSE + ) } contrast_matrix <- contrast_matrix[, trt_levels, drop = FALSE] } } - if (nrow(contrast_matrix) > 0L && qr(t(contrast_matrix), tol = tolerance)$rank < nrow(contrast_matrix)) { - stop("Rows of `contrast_matrix` must be linearly independent.", call. = FALSE) + if ( + nrow(contrast_matrix) > 0L && + qr(t(contrast_matrix), tol = tolerance)$rank < nrow(contrast_matrix) + ) { + stop( + "Rows of `contrast_matrix` must be linearly independent.", + call. = FALSE + ) } return(contrast_matrix) } #' Calculate information criteria for a requested contrast space #' @noRd -.information_criteria <- function(info, trt_levels, contrast_matrix, tolerance) { +.information_criteria <- function( + info, trt_levels, contrast_matrix, tolerance +) { info <- (info + t(info)) / 2 eig <- eigen(info, symmetric = TRUE) scale <- max(abs(eig$values)) - keep <- if (scale == 0) rep(FALSE, length(eig$values)) else eig$values > scale * tolerance + keep <- if (scale == 0) { + rep(FALSE, length(eig$values)) + } else { + eig$values > scale * tolerance + } rank <- sum(keep) pos_eig <- sort(eig$values[keep], decreasing = TRUE) info_inverse <- matrix(0, nrow(info), ncol(info)) if (rank > 0L) { vectors <- eig$vectors[, keep, drop = FALSE] - info_inverse <- vectors %*% diag(1 / eig$values[keep], nrow = rank) %*% t(vectors) + info_inverse <- vectors %*% + diag(1 / eig$values[keep], nrow = rank) %*% t(vectors) } contrasts <- .prepare_contrast_matrix(contrast_matrix, trt_levels, tolerance) @@ -340,7 +372,9 @@ factorial_contrast_matrix <- function( A_value <- 0 D_value <- 0 } else { - contrast_eig <- eigen(contrast_covariance, symmetric = TRUE, only.values = TRUE)$values + contrast_eig <- eigen( + contrast_covariance, symmetric = TRUE, only.values = TRUE + )$values contrast_scale <- max(abs(contrast_eig)) if (all(contrast_eig > contrast_scale * tolerance)) { A_value <- sum(diag(contrast_covariance)) @@ -360,13 +394,7 @@ factorial_contrast_matrix <- function( )) } -#' Function to precompute \eqn{L} -#' -#' \eqn{L} is the projection matrix that removes nuisance effects under a -#' spatial correlation structure, given an \eqn{n \times n}{n * n} covariance -#' \eqn{\Sigma}{Sigma} and nuisance effects design \eqn{X_2}. -#' -#' This only depends on lambda and the block structure, so precompute this. +#' Build the nuisance design matrix X2 #' @noRd .build_nuisance_matrix <- function(layout_df, block_column, nuisance_formula) { if (is.null(nuisance_formula)) { @@ -379,11 +407,18 @@ factorial_contrast_matrix <- function( ) } if (anyNA(blocks)) { - stop("Block labels in `", block_column, "` cannot contain missing values.", call. = FALSE) + stop( + "Block labels in `", block_column, "` cannot contain missing values.", + call. = FALSE + ) } - return(stats::model.matrix(~ 0 + block, data.frame(block = factor(blocks)))) + return( + stats::model.matrix(~ 0 + block, data.frame(block = factor(blocks))) + ) } - if (!inherits(nuisance_formula, "formula") || length(nuisance_formula) != 2L) { + if ( + !inherits(nuisance_formula, "formula") || length(nuisance_formula) != 2L + ) { stop("`nuisance_formula` must be a one-sided formula.", call. = FALSE) } return(stats::model.matrix(nuisance_formula, layout_df)) @@ -391,7 +426,9 @@ factorial_contrast_matrix <- function( #' Build a projection under identity covariance #' @noRd -.build_L_from_df <- function(layout_df, block_column, n, nuisance_formula = NULL, tolerance = 1e-10) { +.build_L_from_df <- function( + layout_df, block_column, n, nuisance_formula = NULL, tolerance = 1e-10 +) { X2 <- .build_nuisance_matrix(layout_df, block_column, nuisance_formula) crossprod_inverse <- pseudo_inverse(crossprod(X2), tolerance) return(diag(n) - X2 %*% crossprod_inverse %*% t(X2)) @@ -462,7 +499,7 @@ factorial_contrast_matrix <- function( nuisance_data <- if (is.null(nuisance_formula)) { layout_df[[block_column]] } else { - # Evaluating the formula also captures `.` and variables in its environment. + # Evaluation captures `.` and variables in the formula's environment. .build_nuisance_matrix(layout_df, block_column, nuisance_formula) } } @@ -568,8 +605,8 @@ factorial_contrast_matrix <- function( #' Compute L projection #' -#' This is the projection matrix that removes nuisance effects from the GLS's -#' covariance +#' Removes nuisance fixed effects from the inverse covariance matrix used in +#' generalised least squares (GLS). #' #' @param layout_df Data frame representing the spatial layout of the #' experiment. @@ -603,26 +640,34 @@ compute_L_projection <- function( by = NULL, grid_index = NULL ) { - plot_order <- .fisher_plot_order(layout_df, row_column, col_column, by, grid_index) + plot_order <- .fisher_plot_order( + layout_df, row_column, col_column, by, grid_index + ) layout_df <- layout_df[plot_order, , drop = FALSE] - return(.build_L_from_Sigma(layout_df, Sigma, block_column, nuisance_formula, tolerance)) + return(.build_L_from_Sigma( + layout_df, Sigma, block_column, nuisance_formula, tolerance + )) } #' Build a projection for data already aligned with Sigma #' @noRd -.build_L_from_Sigma <- function(layout_df, Sigma, block_column, nuisance_formula, tolerance) { +.build_L_from_Sigma <- function( + layout_df, Sigma, block_column, nuisance_formula, tolerance +) { n <- nrow(layout_df) if (!is.matrix(Sigma)) { - stop("Sigma must be a matrix") + stop("`Sigma` must be a matrix.", call. = FALSE) } if (!identical(dim(Sigma), c(n, n))) { stop( - "Sigma matrix must have dimension equal ", - "to dimension of layout_df dataframe" + "`Sigma` dimensions must match the number of rows in `layout_df`.", + call. = FALSE ) } - if (!isSymmetric(Sigma, tol = 1e-8)) stop("Sigma must be symmetric") + if (!isSymmetric(Sigma, tol = 1e-8)) { + stop("`Sigma` must be symmetric.", call. = FALSE) + } X2 <- .build_nuisance_matrix(layout_df, block_column, nuisance_formula) Sigma_inv <- solve(Sigma) @@ -637,7 +682,7 @@ compute_L_projection <- function( #' Construct a 1 dimensional lag-1 autoregressive covariance #' -#' @param n Size of the covariance vector to generate +#' @param n Number of observations. #' @param rho Correlation parameter #' #' @return A symmetric \eqn{(n \times n)} correlation matrix. diff --git a/man/compute_L_projection.Rd b/man/compute_L_projection.Rd index 05341361..c96795de 100644 --- a/man/compute_L_projection.Rd +++ b/man/compute_L_projection.Rd @@ -47,8 +47,8 @@ effects. If omitted, \code{block_column} is treated as a factor.} suitable for the \code{L_matrix} argument to \code{\link[=objective_function_info]{objective_function_info()}}. } \description{ -This is the projection matrix that removes nuisance effects from the GLS's -covariance +Removes nuisance fixed effects from the inverse covariance matrix used in +generalised least squares (GLS). } \details{ A blocked design with at least two observed blocks and no missing block diff --git a/man/cor_ar1.Rd b/man/cor_ar1.Rd index 4dd478b7..7fed8c52 100644 --- a/man/cor_ar1.Rd +++ b/man/cor_ar1.Rd @@ -7,7 +7,7 @@ cor_ar1(n, rho) } \arguments{ -\item{n}{Size of the covariance vector to generate} +\item{n}{Number of observations.} \item{rho}{Correlation parameter} } diff --git a/man/factorial_contrast_matrix.Rd b/man/factorial_contrast_matrix.Rd index b64c792d..e1201799 100644 --- a/man/factorial_contrast_matrix.Rd +++ b/man/factorial_contrast_matrix.Rd @@ -23,7 +23,7 @@ component factor columns.} \item{tolerance}{Numerical rank tolerance.} } \value{ -A numeric contrast matrix whose columns are named by treatment level. +A numeric contrast matrix with columns named by treatment level. } \description{ Constructs a contrast basis for selected factorial effects while treatments From d7b0f43db930a17fe127cbb15f86d3a5bf3802d1 Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Wed, 4 Nov 2026 13:52:46 +0800 Subject: [PATCH 19/25] require named contrasts, simplify annealing acceptance, stopping scope changes --- R/objective_fisher.R | 36 ++++++------ R/speed.R | 20 ++++--- man/objective_function_info.Rd | 10 ++-- tests/testthat/test-design_utils.R | 7 +-- tests/testthat/test-objective_fisher.R | 80 ++++++++++++++++++++++++++ tests/testthat/test-speed-layouts.R | 4 +- tests/testthat/test-speed.R | 77 +++++++++---------------- 7 files changed, 147 insertions(+), 87 deletions(-) diff --git a/R/objective_fisher.R b/R/objective_fisher.R index 3a57c637..7ea14d92 100644 --- a/R/objective_fisher.R +++ b/R/objective_fisher.R @@ -300,25 +300,27 @@ factorial_contrast_matrix <- function( if (any(!is.finite(contrast_matrix))) { stop("`contrast_matrix` must contain only finite values.", call. = FALSE) } + if (ncol(contrast_matrix) != v) { + stop( + "`contrast_matrix` must have one column per treatment.", + call. = FALSE + ) + } if (is.null(colnames(contrast_matrix))) { - if (ncol(contrast_matrix) != v) { - stop( - "`contrast_matrix` must have one column per treatment.", - call. = FALSE - ) - } - colnames(contrast_matrix) <- trt_levels - } else { - missing <- setdiff(trt_levels, colnames(contrast_matrix)) - extra <- setdiff(colnames(contrast_matrix), trt_levels) - if (length(missing) > 0L || length(extra) > 0L) { - stop( - "Contrast columns must match the treatment levels.", - call. = FALSE - ) - } - contrast_matrix <- contrast_matrix[, trt_levels, drop = FALSE] + stop( + "`contrast_matrix` must have column names matching the treatment levels.", + call. = FALSE + ) + } + missing <- setdiff(trt_levels, colnames(contrast_matrix)) + extra <- setdiff(colnames(contrast_matrix), trt_levels) + if (length(missing) > 0L || length(extra) > 0L) { + stop( + "Contrast columns must match the treatment levels.", + call. = FALSE + ) } + contrast_matrix <- contrast_matrix[, trt_levels, drop = FALSE] } if ( diff --git a/R/speed.R b/R/speed.R index b23bd490..b5358f85 100644 --- a/R/speed.R +++ b/R/speed.R @@ -352,6 +352,7 @@ speed_hierarchical <- function(data, optimise, quiet, seed, ...) { adj_weight <- optimise_params$adj_weight bal_weight <- optimise_params$bal_weight stop_at_optimal <- optimise_params$stop_at_optimal + stop_at_zero <- !identical(opt$obj_function, objective_function_info) spatial_cols <- all.vars(opt$spatial_factors) # A level searches from the best design from the previous level @@ -432,10 +433,11 @@ speed_hierarchical <- function(data, optimise, quiet, seed, ...) { new_score <- new_score_obj$score # Decide whether to accept the new design - # Allow moves between invalid designs without evaluating Inf - Inf - if (new_score < current_score || - (is.infinite(current_score) && new_score == current_score) || - runif(1) < exp((current_score - new_score) / temp)) { + delta <- if (new_score == current_score) 0 else new_score - current_score + # Keep the random draw for finite ties at positive temperatures. + if (delta < 0 || + (delta == 0 && (is.infinite(current_score) || temp == 0)) || + runif(1) < exp(-delta / temp)) { current_design <- new_design$design current_score <- new_score current_score_obj <- new_score_obj @@ -464,14 +466,14 @@ speed_hierarchical <- function(data, optimise, quiet, seed, ...) { "\n") } - # known lower bound for optimality rather than zero - reached_optimal <- stop_at_optimal && !is.na(optimal_score) && best_score <= optimal_score + 1e-9 - if (reached_optimal || iter - last_improvement_iter >= opt$early_stop_iterations) { + # Fisher scores can be negative without reaching an optimum. + reached_zero <- stop_at_zero && new_score < .Machine$double.eps + if (reached_zero || iter - last_improvement_iter >= opt$early_stop_iterations) { if (!quiet) { - cat(if (reached_optimal) "Optimal score reached at iteration" else "Early stopping at iteration", + cat(if (reached_zero) "Optimal score reached at iteration" else "Early stopping at iteration", iter, "for level", level, "\n") } - stop_reason <- if (reached_optimal) "optimal" else "no_improvement" + stop_reason <- if (reached_zero) "optimal" else "no_improvement" # Record final score and temperature before breaking if (iter < opt$iterations) { scores[iter + 1] <- current_score diff --git a/man/objective_function_info.Rd b/man/objective_function_info.Rd index 7c850bee..e23e54be 100644 --- a/man/objective_function_info.Rd +++ b/man/objective_function_info.Rd @@ -45,11 +45,11 @@ returned by \code{\link[=compute_L_projection]{compute_L_projection()}}. Cannot \item{Sigma}{Optional covariance matrix in grid order (see Details). If both \code{Sigma} and \code{L_matrix} are \code{NULL}, identity covariance is assumed.} -\item{contrast_matrix}{Numeric contrast matrix with one column per treatment -level. Column names, when supplied, must match the treatment levels. Only -these contrasts are required to be estimable and contribute to the -optimality criterion. The default targets the complete treatment-contrast -space.} +\item{contrast_matrix}{Named numeric contrast matrix with one column per +treatment level. Column names must match the treatment levels exactly once; +columns are matched by name, not position. Only these contrasts are required +to be estimable and contribute to the optimality criterion. The default +targets the complete treatment-contrast space.} \item{block_column}{Column name of the design's block factor, with at least two observed blocks. Used when neither \code{nuisance_formula} nor \code{L_matrix} diff --git a/tests/testthat/test-design_utils.R b/tests/testthat/test-design_utils.R index 4961e894..c90055d0 100644 --- a/tests/testthat/test-design_utils.R +++ b/tests/testthat/test-design_utils.R @@ -427,7 +427,7 @@ test_that("speed() records why each level stopped", { ) }) -test_that("speed() stops on no improvement at zero without a derived lower bound", { +test_that("speed() calls a score of zero optimal without a derived lower bound", { df <- data.frame( row = rep(1:4, times = 5), col = rep(1:5, each = 4), @@ -436,7 +436,7 @@ test_that("speed() stops on no improvement at zero without a derived lower bound ) # A custom objective, so no lower bound can be derived and `optimal_score` is - # `NA`. A zero score does not establish optimality. + # `NA`. Reaching zero is still optimal rather than merely out of improvements. obj_runs <- function(layout_df, swap, spatial_cols, ...) { trt <- as.character(layout_df[[swap]]) return(list(score = as.numeric(sum(trt[-1] == trt[-length(trt)])))) @@ -453,8 +453,7 @@ test_that("speed() stops on no improvement at zero without a derived lower bound expect_equal(result$score, 0) expect_true(is.na(result$metadata$per_level[[1]]$optimal_score)) - expect_equal(result$metadata$per_level[[1]]$stop_reason, "no_improvement") - expect_gt(result$iterations_run, 2000) + expect_equal(result$metadata$per_level[[1]]$stop_reason, "optimal") }) test_that("speed() does not warn when every group can swap", { diff --git a/tests/testthat/test-objective_fisher.R b/tests/testthat/test-objective_fisher.R index 6e50757e..e709272b 100644 --- a/tests/testthat/test-objective_fisher.R +++ b/tests/testthat/test-objective_fisher.R @@ -173,6 +173,86 @@ test_that("a requested estimable contrast does not require full connectedness", expect_true(is.finite(targeted$score)) }) +test_that("custom contrasts require treatment column names", { + df <- initialise_design_df( + items = 10, nrows = 2, ncols = 10, + block_nrows = 1, block_ncols = 10 + ) + Sigma <- cor_ar1_ar1(2, 10, rho_row = 0.6, rho_col = 0.3) + contrast <- matrix(c(1, -1, rep(0, 8)), nrow = 1) + + expect_error( + objective_function_info( + df, "treatment", c("row", "col"), + Sigma = Sigma, contrast_matrix = contrast + ), + "must have column names" + ) + expect_error( + speed( + df, swap = "treatment", swap_within = "block", + obj_function = objective_function_info, + Sigma = Sigma, contrast_matrix = contrast, + iterations = 20, seed = 1, quiet = TRUE + ), + "must have column names" + ) +}) + +test_that("named contrasts match treatments rather than column positions", { + df <- initialise_design_df( + items = 10, nrows = 2, ncols = 10, + block_nrows = 1, block_ncols = 10 + ) + df <- df[order(df$row, df$col), ] + treatments <- paste0("T", 1:10) + df$treatment <- factor(df$treatment, levels = treatments) + Sigma <- cor_ar1_ar1(2, 10, rho_row = 0.6, rho_col = 0.3) + contrast <- matrix( + c(1, -1, rep(0, 8)), nrow = 1, + dimnames = list("T1 - T2", treatments) + ) + + # T2's coefficient is T2 - T1 in this full-rank reference model. + model <- model.matrix(~ factor(block) + treatment, df) + covariance <- solve(crossprod(model, solve(Sigma, model))) + variance <- covariance["treatmentT2", "treatmentT2"] + df$treatment <- as.character(df$treatment) + reordered <- df[rev(seq_len(nrow(df))), ] + reordered$treatment <- factor(reordered$treatment, levels = rev(treatments)) + + for (layout in list(df, reordered)) { + for (columns in list(seq_along(treatments), rev(seq_along(treatments)))) { + result <- objective_function_info( + layout, "treatment", c("row", "col"), + Sigma = Sigma, contrast_matrix = contrast[, columns, drop = FALSE] + ) + expect_equal(result$A_value, variance, tolerance = 1e-10) + expect_equal(result$D_value, log(variance), tolerance = 1e-10) + expect_equal(unname(result$contrast_matrix[, "T2"]), -1) + expect_equal(unname(result$contrast_matrix[, "T10"]), 0) + } + } +}) + +test_that("contrast columns identify each treatment exactly once", { + treatments <- c("T1", "T2", "T10") + contrast <- matrix(c(1, -1, 0), nrow = 1, + dimnames = list(NULL, treatments)) + + expect_error( + .prepare_contrast_matrix(cbind(contrast, T2 = 0), treatments, 1e-9), + "one column per treatment" + ) + for (last_name in c("T2", "unknown", "", NA_character_)) { + colnames(contrast) <- c("T1", "T2", last_name) + expect_error( + .prepare_contrast_matrix(contrast, treatments, 1e-9), + "must match the treatment levels" + ) + } +}) + test_that("incremental calculation matches full recalculation", { df <- data.frame( row = rep(1:3, each = 4), diff --git a/tests/testthat/test-speed-layouts.R b/tests/testthat/test-speed-layouts.R index 23cf9582..bcea3752 100644 --- a/tests/testthat/test-speed-layouts.R +++ b/tests/testthat/test-speed-layouts.R @@ -101,8 +101,8 @@ test_that("speed works with a custom objective function", { expect_s3_class(result, "design") expect_equal(result$score, 0) - expect_equal(result$iterations_run, 1000) - expect_equal(result$stopped_early, FALSE) + expect_equal(result$iterations_run, 742) + expect_equal(result$stopped_early, TRUE) vdiffr::expect_doppelganger("speed_custom_obj_func", autoplot(result)) }) diff --git a/tests/testthat/test-speed.R b/tests/testthat/test-speed.R index 61d55175..e4304f21 100644 --- a/tests/testthat/test-speed.R +++ b/tests/testthat/test-speed.R @@ -154,6 +154,33 @@ test_that("all-invalid annealing runs finish without NaN acceptance", { expect_true(all(is.infinite(result$scores))) }) +test_that("annealing accepts equal scores at zero temperature", { + design <- data.frame( + row = rep(1:2, each = 2), + col = rep(1:2, times = 2), + treatment = LETTERS[1:4] + ) + + for (value in c(0, 1, Inf)) { + objective <- function(layout_df, swap, spatial_cols, ...) { + return(list(score = value)) + } + result <- speed( + design, + swap = "treatment", + obj_function = objective, + iterations = 1, + optimise_params = optim_params(start_temp = 0, stop_at_optimal = FALSE), + seed = 1, + quiet = TRUE + ) + + expect_equal(result$score, value) + expect_setequal(as.character(result$design_df$treatment), design$treatment) + expect_false(identical(as.character(result$design_df$treatment), design$treatment)) + } +}) + test_that("speed throws error for missing columns", { test_data <- data.frame( row = rep(1:5, times = 4), @@ -353,56 +380,6 @@ test_that("speed does not stop on the optimal score for custom objectives", { expect_equal(result$iterations_run, 200) }) -test_that("zero and negative custom scores do not imply optimality", { - test_data <- expand.grid(row = 1:2, col = 1:2) - test_data$treatment <- c("A", "B", "B", "A") - - for (value in c(0, -1)) { - custom_objective <- function(layout_df, swap, spatial_cols, ...) { - return(list(score = value)) - } - result <- speed( - test_data, - swap = "treatment", - obj_function = custom_objective, - iterations = 20, - early_stop_iterations = 100, - seed = 1, - quiet = TRUE - ) - - expect_equal(result$iterations_run, 20) - expect_equal(result$scores, rep(value, 20)) - expect_identical(result$metadata$per_level[[1]]$stop_reason, "iterations") - expect_false(result$stopped_early) - } -}) - -test_that("stop_at_optimal also controls stopping at a zero bound", { - test_data <- expand.grid(row = 1:2, col = 1:2) - test_data$treatment <- c("A", "B", "B", "A") - - for (stop_at_optimal in c(TRUE, FALSE)) { - result <- speed( - test_data, - swap = "treatment", - optimise_params = optim_params( - adj_weight = 0, - bal_weight = 0, - stop_at_optimal = stop_at_optimal - ), - iterations = 20, - early_stop_iterations = 100, - seed = 1, - quiet = TRUE - ) - - expect_equal(result$metadata$per_level[[1]]$optimal_score, 0) - expect_equal(result$iterations_run, if (stop_at_optimal) 1 else 20) - expect_equal(result$stopped_early, stop_at_optimal) - } -}) - test_that("speed does not stop on the optimal score (NA) for negative weights", { test_data <- expand.grid(row = 1:5, col = 1:4) test_data$treatment <- LETTERS[1:4] From 3b36184f01f1bf97baf529ca38e0da648d84a378 Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Wed, 4 Nov 2026 14:22:02 +0800 Subject: [PATCH 20/25] simplify annealing acceptance, update tests and docs --- R/objective_fisher.R | 10 +- R/speed.R | 5 +- .../buffers/buffers-colourblind-palette.svg | 28 +- .../_snaps/buffers/buffers-no-margin.svg | 28 +- .../_snaps/buffers/buffers-plasma-palette.svg | 28 +- .../_snaps/buffers/buffers-rotated-text.svg | 28 +- .../buffers/buffers-with-legend-display.svg | 28 +- .../_snaps/buffers/buffers-with-margin.svg | 28 +- .../speed-optimised-column-buffers.svg | 32 +- .../buffers/speed-optimised-edge-buffers.svg | 32 +- .../buffers/speed-optimised-row-buffers.svg | 32 +- .../autoplot-blocked-margin-false.svg | 48 +- .../plotting/autoplot-blocked-margin-true.svg | 48 +- .../plotting/autoplot-blocks-inferno.svg | 48 +- .../plotting/autoplot-blocks-paired.svg | 48 +- .../_snaps/plotting/autoplot-custom-hex.svg | 28 +- .../_snaps/plotting/autoplot-custom-mixed.svg | 28 +- .../_snaps/plotting/autoplot-custom-rgb.svg | 28 +- .../autoplot-hierarchical-plasma-wp.svg | 64 +- .../autoplot-hierarchical-set3-sp.svg | 64 +- .../autoplot-palette-large-treatments.svg | 112 +- .../speed-split-split-ssp.svg | 492 +- .../speed-hierarchical/speed-splitplot-sp.svg | 156 +- .../speed-hierarchical/speed-splitplot-wp.svg | 192 +- .../speed-hierarchical/speed-strip-ht.svg | 216 +- .../speed-hierarchical/speed-strip-vt.svg | 240 +- tests/testthat/_snaps/speed-layouts.md | 484 +- .../speed-layouts/speed-custom-obj-func.svg | 48 +- .../speed-layouts/speed-large-blocks.svg | 980 +- .../_snaps/speed-layouts/speed-large-grid.svg | 1488 +-- .../speed-large-missing-clump.svg | 1440 +-- .../speed-layouts/speed-large-missing-l.svg | 1092 +-- .../speed-layouts/speed-large-missing.svg | 1312 +-- .../_snaps/speed-layouts/speed-large-rcbd.svg | 7974 ++++++++--------- .../speed-multi-spatial-factors.svg | 84 +- .../speed-layouts/speed-non-uniform.svg | 264 +- .../speed-layouts/speed-partial-rep.svg | 788 +- .../speed-layouts/speed-rcbd-multi-reps.svg | 1868 ++-- tests/testthat/_snaps/speed-output.md | 4 +- .../autoplot-factor-with-blocks.svg | 84 +- ...autoplot-hierarchical-mixed-factors-sp.svg | 240 +- ...autoplot-hierarchical-mixed-factors-wp.svg | 260 +- .../autoplot-hierarchical-no-legend.svg | 32 +- .../autoplot-hierarchical-with-legend.svg | 32 +- .../speed-output/autoplot-no-legend.svg | 32 +- .../speed-output/autoplot-with-legend.svg | 32 +- tests/testthat/_snaps/speed/speed-blocks.svg | 64 +- tests/testthat/_snaps/speed/speed-small.svg | 68 +- tests/testthat/test-build_design_matrix.R | 2 +- tests/testthat/test-speed-hierarchical.R | 12 +- tests/testthat/test-speed-layouts.R | 4 +- tests/testthat/test-speed.R | 32 + 52 files changed, 10420 insertions(+), 10391 deletions(-) diff --git a/R/objective_fisher.R b/R/objective_fisher.R index 7ea14d92..08f9a68e 100644 --- a/R/objective_fisher.R +++ b/R/objective_fisher.R @@ -19,11 +19,11 @@ #' returned by [compute_L_projection()]. Cannot be supplied with `Sigma`. #' @param Sigma Optional covariance matrix in grid order (see Details). If both #' `Sigma` and `L_matrix` are `NULL`, identity covariance is assumed. -#' @param contrast_matrix Numeric contrast matrix with one column per treatment -#' level. Column names, when supplied, must match the treatment levels. Only -#' these contrasts are required to be estimable and contribute to the -#' optimality criterion. The default targets the complete treatment-contrast -#' space. +#' @param contrast_matrix Named numeric contrast matrix with one column per +#' treatment level. Column names must match the treatment levels exactly once; +#' columns are matched by name, not position. Only these contrasts are required +#' to be estimable and contribute to the optimality criterion. The default +#' targets the complete treatment-contrast space. #' @param block_column Column name of the design's block factor, with at least #' two observed blocks. Used when neither `nuisance_formula` nor `L_matrix` #' is supplied. diff --git a/R/speed.R b/R/speed.R index b5358f85..3e8cdb9e 100644 --- a/R/speed.R +++ b/R/speed.R @@ -434,10 +434,7 @@ speed_hierarchical <- function(data, optimise, quiet, seed, ...) { # Decide whether to accept the new design delta <- if (new_score == current_score) 0 else new_score - current_score - # Keep the random draw for finite ties at positive temperatures. - if (delta < 0 || - (delta == 0 && (is.infinite(current_score) || temp == 0)) || - runif(1) < exp(-delta / temp)) { + if (delta <= 0 || runif(1) < exp(-delta / temp)) { current_design <- new_design$design current_score <- new_score current_score_obj <- new_score_obj diff --git a/tests/testthat/_snaps/buffers/buffers-colourblind-palette.svg b/tests/testthat/_snaps/buffers/buffers-colourblind-palette.svg index 47461111..5e76c86a 100644 --- a/tests/testthat/_snaps/buffers/buffers-colourblind-palette.svg +++ b/tests/testthat/_snaps/buffers/buffers-colourblind-palette.svg @@ -49,15 +49,15 @@ + - - - - - - + + + + + + - @@ -74,15 +74,15 @@ +A A -A -A -B -B -B -C +A +B +B +B +C +C C -C diff --git a/tests/testthat/_snaps/buffers/buffers-no-margin.svg b/tests/testthat/_snaps/buffers/buffers-no-margin.svg index 8a27cc3d..f4bdb6dd 100644 --- a/tests/testthat/_snaps/buffers/buffers-no-margin.svg +++ b/tests/testthat/_snaps/buffers/buffers-no-margin.svg @@ -49,15 +49,15 @@ + - - - - - - + + + + + + - @@ -74,15 +74,15 @@ +A A -A -A -B -B -B -C +A +B +B +B +C +C C -C diff --git a/tests/testthat/_snaps/buffers/buffers-plasma-palette.svg b/tests/testthat/_snaps/buffers/buffers-plasma-palette.svg index e36927bb..d0e3835b 100644 --- a/tests/testthat/_snaps/buffers/buffers-plasma-palette.svg +++ b/tests/testthat/_snaps/buffers/buffers-plasma-palette.svg @@ -49,15 +49,15 @@ + - - - - - - + + + + + + - @@ -74,15 +74,15 @@ +A A -A -A -B -B -B -C +A +B +B +B +C +C C -C diff --git a/tests/testthat/_snaps/buffers/buffers-rotated-text.svg b/tests/testthat/_snaps/buffers/buffers-rotated-text.svg index 0d97a333..4dc673a8 100644 --- a/tests/testthat/_snaps/buffers/buffers-rotated-text.svg +++ b/tests/testthat/_snaps/buffers/buffers-rotated-text.svg @@ -49,15 +49,15 @@ + - - - - - - + + + + + + - @@ -74,15 +74,15 @@ +A A -A -A -B -B -B -C +A +B +B +B +C +C C -C diff --git a/tests/testthat/_snaps/buffers/buffers-with-legend-display.svg b/tests/testthat/_snaps/buffers/buffers-with-legend-display.svg index 737dab89..747de30e 100644 --- a/tests/testthat/_snaps/buffers/buffers-with-legend-display.svg +++ b/tests/testthat/_snaps/buffers/buffers-with-legend-display.svg @@ -49,15 +49,15 @@ + - - - - - - + + + + + + - @@ -74,15 +74,15 @@ +A A -A -A -B -B -B -C +A +B +B +B +C +C C -C diff --git a/tests/testthat/_snaps/buffers/buffers-with-margin.svg b/tests/testthat/_snaps/buffers/buffers-with-margin.svg index 9fe7d2e0..13bc6e68 100644 --- a/tests/testthat/_snaps/buffers/buffers-with-margin.svg +++ b/tests/testthat/_snaps/buffers/buffers-with-margin.svg @@ -49,15 +49,15 @@ + - - - - - - + + + + + + - @@ -74,15 +74,15 @@ +A A -A -A -B -B -B -C +A +B +B +B +C +C C -C diff --git a/tests/testthat/_snaps/buffers/speed-optimised-column-buffers.svg b/tests/testthat/_snaps/buffers/speed-optimised-column-buffers.svg index 6638dab8..e926e59e 100644 --- a/tests/testthat/_snaps/buffers/speed-optimised-column-buffers.svg +++ b/tests/testthat/_snaps/buffers/speed-optimised-column-buffers.svg @@ -49,14 +49,14 @@ - - - - - - - - + + + + + + + + @@ -70,14 +70,14 @@ -A -A -A -B -B -B -C -C +A +A +A +B +B +B +C +C C diff --git a/tests/testthat/_snaps/buffers/speed-optimised-edge-buffers.svg b/tests/testthat/_snaps/buffers/speed-optimised-edge-buffers.svg index e00c91b8..303e37d5 100644 --- a/tests/testthat/_snaps/buffers/speed-optimised-edge-buffers.svg +++ b/tests/testthat/_snaps/buffers/speed-optimised-edge-buffers.svg @@ -49,14 +49,14 @@ - - - - - - - - + + + + + + + + @@ -74,14 +74,14 @@ -A -A -A -B -B -B -C -C +A +A +A +B +B +B +C +C C diff --git a/tests/testthat/_snaps/buffers/speed-optimised-row-buffers.svg b/tests/testthat/_snaps/buffers/speed-optimised-row-buffers.svg index 3ece4b05..88634c87 100644 --- a/tests/testthat/_snaps/buffers/speed-optimised-row-buffers.svg +++ b/tests/testthat/_snaps/buffers/speed-optimised-row-buffers.svg @@ -49,14 +49,14 @@ - - - - - - - - + + + + + + + + @@ -70,14 +70,14 @@ -A -A -A -B -B -B -C -C +A +A +A +B +B +B +C +C C diff --git a/tests/testthat/_snaps/plotting/autoplot-blocked-margin-false.svg b/tests/testthat/_snaps/plotting/autoplot-blocked-margin-false.svg index 5eac9a1c..62e87528 100644 --- a/tests/testthat/_snaps/plotting/autoplot-blocked-margin-false.svg +++ b/tests/testthat/_snaps/plotting/autoplot-blocked-margin-false.svg @@ -49,52 +49,52 @@ + - + - - - - - - + + + - - + + + + + - - - + + +A A -A +A A -A B -B -B B -C -C -C +B +B +C C -D -D +C +C D +D +D D +E E -E E E -F -F +F +F F F diff --git a/tests/testthat/_snaps/plotting/autoplot-blocked-margin-true.svg b/tests/testthat/_snaps/plotting/autoplot-blocked-margin-true.svg index f18e5679..a1b8ebab 100644 --- a/tests/testthat/_snaps/plotting/autoplot-blocked-margin-true.svg +++ b/tests/testthat/_snaps/plotting/autoplot-blocked-margin-true.svg @@ -49,52 +49,52 @@ + - + - - - - - - + + + - - + + + + + - - - + + +A A -A +A A -A B -B -B B -C -C -C +B +B +C C -D -D +C +C D +D +D D +E E -E E E -F -F +F +F F F diff --git a/tests/testthat/_snaps/plotting/autoplot-blocks-inferno.svg b/tests/testthat/_snaps/plotting/autoplot-blocks-inferno.svg index 75334ad2..d1139aae 100644 --- a/tests/testthat/_snaps/plotting/autoplot-blocks-inferno.svg +++ b/tests/testthat/_snaps/plotting/autoplot-blocks-inferno.svg @@ -49,52 +49,52 @@ + - + - - - - - - + + + - - + + + + + - - - + + +A A -A +A A -A B -B -B B -C -C -C +B +B +C C -D -D +C +C D +D +D D +E E -E E E -F -F +F +F F F diff --git a/tests/testthat/_snaps/plotting/autoplot-blocks-paired.svg b/tests/testthat/_snaps/plotting/autoplot-blocks-paired.svg index c6c37275..2ed7040a 100644 --- a/tests/testthat/_snaps/plotting/autoplot-blocks-paired.svg +++ b/tests/testthat/_snaps/plotting/autoplot-blocks-paired.svg @@ -49,52 +49,52 @@ + - + - - - - - - + + + - - + + + + + - - - + + +A A -A +A A -A B -B -B B -C -C -C +B +B +C C -D -D +C +C D +D +D D +E E -E E E -F -F +F +F F F diff --git a/tests/testthat/_snaps/plotting/autoplot-custom-hex.svg b/tests/testthat/_snaps/plotting/autoplot-custom-hex.svg index 56d92846..c6258525 100644 --- a/tests/testthat/_snaps/plotting/autoplot-custom-hex.svg +++ b/tests/testthat/_snaps/plotting/autoplot-custom-hex.svg @@ -41,24 +41,24 @@ - + + - + + - - - - - -A + + + +A +A A -A +B +B B -B -B -C -C -C +C +C +C diff --git a/tests/testthat/_snaps/plotting/autoplot-custom-mixed.svg b/tests/testthat/_snaps/plotting/autoplot-custom-mixed.svg index 87583d95..665e9693 100644 --- a/tests/testthat/_snaps/plotting/autoplot-custom-mixed.svg +++ b/tests/testthat/_snaps/plotting/autoplot-custom-mixed.svg @@ -41,24 +41,24 @@ - + + - + + - - - - - -A + + + +A +A A -A +B +B B -B -B -C -C -C +C +C +C diff --git a/tests/testthat/_snaps/plotting/autoplot-custom-rgb.svg b/tests/testthat/_snaps/plotting/autoplot-custom-rgb.svg index 25b7b6bd..faafd238 100644 --- a/tests/testthat/_snaps/plotting/autoplot-custom-rgb.svg +++ b/tests/testthat/_snaps/plotting/autoplot-custom-rgb.svg @@ -41,24 +41,24 @@ - + + - + + - - - - - -A + + + +A +A A -A +B +B B -B -B -C -C -C +C +C +C diff --git a/tests/testthat/_snaps/plotting/autoplot-hierarchical-plasma-wp.svg b/tests/testthat/_snaps/plotting/autoplot-hierarchical-plasma-wp.svg index 048ae649..95be8504 100644 --- a/tests/testthat/_snaps/plotting/autoplot-hierarchical-plasma-wp.svg +++ b/tests/testthat/_snaps/plotting/autoplot-hierarchical-plasma-wp.svg @@ -49,50 +49,50 @@ - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + -A -A -A -A -A -A -A -A +A +A +A +A +A +A +A +A B B B B -B -B -B -B -C -C -C -C +B +B +B +B +C +C +C +C C C C diff --git a/tests/testthat/_snaps/plotting/autoplot-hierarchical-set3-sp.svg b/tests/testthat/_snaps/plotting/autoplot-hierarchical-set3-sp.svg index fb86213c..b557ff3a 100644 --- a/tests/testthat/_snaps/plotting/autoplot-hierarchical-set3-sp.svg +++ b/tests/testthat/_snaps/plotting/autoplot-hierarchical-set3-sp.svg @@ -52,51 +52,51 @@ - - - - - - - + + + - + + + + + - - + + - - + + + - - - + + + - a a a -a -a -a -b -b -b -b +a +a +a b -b +b +b +b +b +b c -c -c +c +c c -c -c +c +c +d d -d -d -d +d +d +d d -d diff --git a/tests/testthat/_snaps/plotting/autoplot-palette-large-treatments.svg b/tests/testthat/_snaps/plotting/autoplot-palette-large-treatments.svg index 7a6cabfe..e52eb45e 100644 --- a/tests/testthat/_snaps/plotting/autoplot-palette-large-treatments.svg +++ b/tests/testthat/_snaps/plotting/autoplot-palette-large-treatments.svg @@ -53,70 +53,70 @@ - - - - + + + + + + + - - - - - - - - - + + + + - + + + - - - - - - - - - - + + + + + + + + + + - - - - -A -A -A -A + + + + +A +A +A +A +B +B +B B -B -B -B -C -C -C -C -D -D +C +C +C +C D -D +D +D +D E -E -E -E -F -F -F -F -G -G -G +E +E +E +F +F +F +F +G +G +G G -H -H -H -H +H +H +H +H diff --git a/tests/testthat/_snaps/speed-hierarchical/speed-split-split-ssp.svg b/tests/testthat/_snaps/speed-hierarchical/speed-split-split-ssp.svg index 595d6d1e..a1c47272 100644 --- a/tests/testthat/_snaps/speed-hierarchical/speed-split-split-ssp.svg +++ b/tests/testthat/_snaps/speed-hierarchical/speed-split-split-ssp.svg @@ -79,294 +79,294 @@ - - - - - - + + + + + + + + - - - - - - - - - - + + + + + - - + + + + + + + + + + - - - - - - - - - - - - - - - - + - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - + + + + + + + + - - + + + + + + + + + - - - - - + + + + + + + + + + + + + + + + + - - - + + + - - - - - + + + + + + + + + + + + + + + + + + - - - - - + + + - + + + + + + + + - + + - - + + + - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - + + + + + + - - -x -x -x -x -x -x + + +x +x +x +x +x +x +x +x x -x -x -x -x x -x -x -x -x -x -x x +x +x +x +x +x x -x -x +x +x +x +x +x +x +x +x +x +x x x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x +x x -x -x +x +x +x +x x -x -x -x -x -y -y -y -y -y -y -y -y -y -y -y -y -y -y -y -y -y -y -y -y -y -y -y -y -y -y -y +x +x +x +x +x +x +x +x +x +x +x +x +y y -y -y -y +y +y +y +y +y +y +y +y y -y -y +y +y +y +y +y +y +y +y +y y -y -y -y -y -y +y +y +y +y +y +y +y +y +y +y +y +y +y +y +y +y +y y -y -y -y +y +y +y y -y -y -y -z -z +y +y +y +y +y +z +z +z +z +z +z +z +z +z +z +z +z +z z -z -z -z -z -z +z +z +z z -z +z +z +z +z +z +z +z +z z -z +z +z z z -z -z +z +z +z z -z -z -z -z -z -z -z -z -z -z -z -z -z -z -z -z -z -z +z +z +z z -z -z -z -z -z -z -z -z -z +z +z +z +z +z +z z -z -z +z +z diff --git a/tests/testthat/_snaps/speed-hierarchical/speed-splitplot-sp.svg b/tests/testthat/_snaps/speed-hierarchical/speed-splitplot-sp.svg index 58a68303..336f26a5 100644 --- a/tests/testthat/_snaps/speed-hierarchical/speed-splitplot-sp.svg +++ b/tests/testthat/_snaps/speed-hierarchical/speed-splitplot-sp.svg @@ -61,102 +61,102 @@ - - + + + - - - - - - - - + + - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - + - - + + + - - - - - - - + + + + + + + + + - - + - - - -a -a + + + + +a +a +a a -a -a -a -a -a -a -a -a +a +a a -b -b -b -b -b -b -b -b -b -b +a +a +a +a +a +b b +b +b +b b +b +b +b +b +b +b +c c -c -c -c -c -c +c c -c -c +c +c +c c -c -c -d -d -d -d -d +c +c +c +c +d +d +d +d +d d -d -d +d d -d -d -d +d +d +d +d diff --git a/tests/testthat/_snaps/speed-hierarchical/speed-splitplot-wp.svg b/tests/testthat/_snaps/speed-hierarchical/speed-splitplot-wp.svg index 8587958b..b3780dc9 100644 --- a/tests/testthat/_snaps/speed-hierarchical/speed-splitplot-wp.svg +++ b/tests/testthat/_snaps/speed-hierarchical/speed-splitplot-wp.svg @@ -61,102 +61,102 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C diff --git a/tests/testthat/_snaps/speed-hierarchical/speed-strip-ht.svg b/tests/testthat/_snaps/speed-hierarchical/speed-strip-ht.svg index a029ec27..3d33b7a7 100644 --- a/tests/testthat/_snaps/speed-hierarchical/speed-strip-ht.svg +++ b/tests/testthat/_snaps/speed-hierarchical/speed-strip-ht.svg @@ -65,150 +65,150 @@ - - - - - - - - - - - - + - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + - - + + + + + + + + + + - + + + + + + - - - - - - - - - - - - - + + - + + - - - - + + + - - + + + + - - -a -a -a -a -a -a -a -a -a -a -a -a +a a -a -a -a -a -a +a +a +a +a +a +a +a +a +a +a +a +a +a +a +a +a b b b -b -b -b -b -b -b -b b -b -b -b -b -b +b +b +b +b +b +b b +b +b +b +b b -c -c +b +b +c c +c +c +c +c +c +c +c c -c +c +c +c +c +c +c c -c -c -c -c -c -c -c -c -c -c -c -c -d +c d d +d d d -d +d +d d -d d -d -d -d +d +d +d d -d -d +d +d +d +d d -d -d diff --git a/tests/testthat/_snaps/speed-hierarchical/speed-strip-vt.svg b/tests/testthat/_snaps/speed-hierarchical/speed-strip-vt.svg index 25b24893..1517967d 100644 --- a/tests/testthat/_snaps/speed-hierarchical/speed-strip-vt.svg +++ b/tests/testthat/_snaps/speed-hierarchical/speed-strip-vt.svg @@ -65,150 +65,150 @@ - - - - - - - + + + + - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + - + - + + + + + - - - - - - + - - - - - - - - - - - - - - - - + + + + + + + + + + + + - - - + + - - + + + + + + + + - - + - - - -A -A -A -A -A -A -A + + +A +A +A +A A -A -A -A -A -A -A -A -A -A -A +A +A +A +A +A A +A +A +A +A +A +A A -A -A -A -A -B -B -B -B -B +A +A +A +A +A +A +B +B +B +B +B +B +B B -B +B B -B +B +B +B +B +B B -B -B -B -B B -B -B +B B -B -B -B -B -B -B -C -C -C -C -C -C -C -C -C -C +B +B +B +B +B +C +C +C +C +C +C +C C -C -C -C +C +C C -C -C +C +C +C +C +C +C +C +C C -C -C +C C -C -C -C +C +C diff --git a/tests/testthat/_snaps/speed-layouts.md b/tests/testthat/_snaps/speed-layouts.md index d0abc94d..4df09564 100644 --- a/tests/testthat/_snaps/speed-layouts.md +++ b/tests/testthat/_snaps/speed-layouts.md @@ -4,260 +4,260 @@ result$design_df Output row col block treatment - 1 1 1 1 L - 2 1 2 1 N - 3 1 3 1 P - 4 1 4 1 B - 5 1 5 1 C + 1 1 1 1 P + 2 1 2 1 A + 3 1 3 1 B + 4 1 4 1 I + 5 1 5 1 J 6 1 6 1 G - 7 1 7 1 E - 8 1 8 1 M - 9 1 9 1 O - 10 1 10 1 I - 11 1 11 1 H - 12 1 12 1 K - 13 1 13 1 F - 14 1 14 1 D - 15 1 15 1 A - 16 1 16 1 J - 17 2 1 1 O - 18 2 2 1 C + 7 1 7 1 L + 8 1 8 1 F + 9 1 9 1 A + 10 1 10 1 H + 11 1 11 1 O + 12 1 12 1 N + 13 1 13 1 C + 14 1 14 1 K + 15 1 15 1 M + 16 1 16 1 D + 17 2 1 1 D + 18 2 2 1 N 19 2 3 1 F - 20 2 4 1 L - 21 2 5 1 B - 22 2 6 1 P - 23 2 7 1 D - 24 2 8 1 J - 25 2 9 1 K - 26 2 10 1 A - 27 2 11 1 M - 28 2 12 1 N - 29 2 13 1 H - 30 2 14 1 G - 31 2 15 1 E - 32 2 16 1 O - 33 3 1 1 E - 34 3 2 1 B - 35 3 3 1 J - 36 3 4 1 G - 37 3 5 1 D - 38 3 6 1 H - 39 3 7 1 K - 40 3 8 1 A - 41 3 9 1 I - 42 3 10 1 O - 43 3 11 1 L - 44 3 12 1 F + 20 2 4 1 K + 21 2 5 1 D + 22 2 6 1 I + 23 2 7 1 J + 24 2 8 1 L + 25 2 9 1 O + 26 2 10 1 G + 27 2 11 1 E + 28 2 12 1 C + 29 2 13 1 B + 30 2 14 1 M + 31 2 15 1 P + 32 2 16 1 H + 33 3 1 1 J + 34 3 2 1 L + 35 3 3 1 H + 36 3 4 1 O + 37 3 5 1 F + 38 3 6 1 C + 39 3 7 1 E + 40 3 8 1 B + 41 3 9 1 M + 42 3 10 1 I + 43 3 11 1 K + 44 3 12 1 A 45 3 13 1 P - 46 3 14 1 N - 47 3 15 1 C - 48 3 16 1 I - 49 4 1 1 M - 50 4 2 1 K - 51 4 3 1 M - 52 4 4 1 H - 53 4 5 1 A - 54 4 6 1 J - 55 4 7 1 I - 56 4 8 1 L - 57 4 9 1 P - 58 4 10 1 D - 59 4 11 1 B - 60 4 12 1 C - 61 4 13 1 N - 62 4 14 1 E - 63 4 15 1 F - 64 4 16 1 G - 65 5 1 2 A - 66 5 2 2 B - 67 5 3 2 H - 68 5 4 2 F - 69 5 5 2 N - 70 5 6 2 M - 71 5 7 2 C - 72 5 8 2 K - 73 5 9 2 J - 74 5 10 2 E - 75 5 11 2 I - 76 5 12 2 P - 77 5 13 2 G - 78 5 14 2 O - 79 5 15 2 L - 80 5 16 2 D - 81 6 1 2 O - 82 6 2 2 I - 83 6 3 2 G - 84 6 4 2 K - 85 6 5 2 D - 86 6 6 2 E - 87 6 7 2 F - 88 6 8 2 D - 89 6 9 2 A + 46 3 14 1 G + 47 3 15 1 E + 48 3 16 1 N + 49 4 1 1 I + 50 4 2 1 H + 51 4 3 1 E + 52 4 4 1 J + 53 4 5 1 P + 54 4 6 1 N + 55 4 7 1 C + 56 4 8 1 K + 57 4 9 1 G + 58 4 10 1 L + 59 4 11 1 D + 60 4 12 1 F + 61 4 13 1 M + 62 4 14 1 O + 63 4 15 1 B + 64 4 16 1 A + 65 5 1 2 G + 66 5 2 2 P + 67 5 3 2 I + 68 5 4 2 N + 69 5 5 2 E + 70 5 6 2 D + 71 5 7 2 O + 72 5 8 2 M + 73 5 9 2 A + 74 5 10 2 B + 75 5 11 2 C + 76 5 12 2 H + 77 5 13 2 L + 78 5 14 2 J + 79 5 15 2 F + 80 5 16 2 K + 81 6 1 2 C + 82 6 2 2 K + 83 6 3 2 J + 84 6 4 2 E + 85 6 5 2 B + 86 6 6 2 O + 87 6 7 2 I + 88 6 8 2 A + 89 6 9 2 D 90 6 10 2 M 91 6 11 2 P - 92 6 12 2 B - 93 6 13 2 H - 94 6 14 2 C - 95 6 15 2 J - 96 6 16 2 N - 97 7 1 2 D - 98 7 2 2 J - 99 7 3 2 I - 100 7 4 2 P - 101 7 5 2 G - 102 7 6 2 B - 103 7 7 2 A - 104 7 8 2 N - 105 7 9 2 E - 106 7 10 2 H - 107 7 11 2 F - 108 7 12 2 O - 109 7 13 2 L - 110 7 14 2 K - 111 7 15 2 M - 112 7 16 2 C - 113 8 1 2 H - 114 8 2 2 L + 92 6 12 2 G + 93 6 13 2 N + 94 6 14 2 H + 95 6 15 2 L + 96 6 16 2 F + 97 7 1 2 I + 98 7 2 2 H + 99 7 3 2 A + 100 7 4 2 L + 101 7 5 2 N + 102 7 6 2 K + 103 7 7 2 D + 104 7 8 2 J + 105 7 9 2 F + 106 7 10 2 N + 107 7 11 2 G + 108 7 12 2 M + 109 7 13 2 O + 110 7 14 2 E + 111 7 15 2 C + 112 7 16 2 B + 113 8 1 2 M + 114 8 2 2 J 115 8 3 2 O - 116 8 4 2 C - 117 8 5 2 E + 116 8 4 2 D + 117 8 5 2 I 118 8 6 2 A - 119 8 7 2 F - 120 8 8 2 B - 121 8 9 2 M - 122 8 10 2 L - 123 8 11 2 N - 124 8 12 2 J - 125 8 13 2 K - 126 8 14 2 I - 127 8 15 2 G - 128 8 16 2 P - 129 9 1 3 I - 130 9 2 3 D - 131 9 3 3 N - 132 9 4 3 E - 133 9 5 3 I - 134 9 6 3 K - 135 9 7 3 J - 136 9 8 3 O - 137 9 9 3 F - 138 9 10 3 G - 139 9 11 3 C - 140 9 12 3 M - 141 9 13 3 E - 142 9 14 3 P - 143 9 15 3 L - 144 9 16 3 H - 145 10 1 3 J - 146 10 2 3 F - 147 10 3 3 H - 148 10 4 3 O - 149 10 5 3 P - 150 10 6 3 F - 151 10 7 3 C - 152 10 8 3 E - 153 10 9 3 N - 154 10 10 3 L - 155 10 11 3 K - 156 10 12 3 G - 157 10 13 3 B - 158 10 14 3 M + 119 8 7 2 P + 120 8 8 2 G + 121 8 9 2 L + 122 8 10 2 P + 123 8 11 2 E + 124 8 12 2 B + 125 8 13 2 H + 126 8 14 2 F + 127 8 15 2 K + 128 8 16 2 C + 129 9 1 3 H + 130 9 2 3 F + 131 9 3 3 L + 132 9 4 3 M + 133 9 5 3 K + 134 9 6 3 E + 135 9 7 3 A + 136 9 8 3 I + 137 9 9 3 B + 138 9 10 3 D + 139 9 11 3 J + 140 9 12 3 O + 141 9 13 3 J + 142 9 14 3 C + 143 9 15 3 G + 144 9 16 3 P + 145 10 1 3 A + 146 10 2 3 B + 147 10 3 3 C + 148 10 4 3 H + 149 10 5 3 L + 150 10 6 3 N + 151 10 7 3 G + 152 10 8 3 N + 153 10 9 3 C + 154 10 10 3 O + 155 10 11 3 F + 156 10 12 3 P + 157 10 13 3 E + 158 10 14 3 I 159 10 15 3 D - 160 10 16 3 I - 161 11 1 3 K - 162 11 2 3 A - 163 11 3 3 C - 164 11 4 3 N - 165 11 5 3 J - 166 11 6 3 M - 167 11 7 3 O - 168 11 8 3 H - 169 11 9 3 B + 160 10 16 3 M + 161 11 1 3 B + 162 11 2 3 M + 163 11 3 3 K + 164 11 4 3 A + 165 11 5 3 O + 166 11 6 3 J + 167 11 7 3 H + 168 11 8 3 P + 169 11 9 3 N 170 11 10 3 F - 171 11 11 3 G - 172 11 12 3 I - 173 11 13 3 D - 174 11 14 3 L - 175 11 15 3 P - 176 11 16 3 A - 177 12 1 3 B - 178 12 2 3 E - 179 12 3 3 B - 180 12 4 3 D - 181 12 5 3 M - 182 12 6 3 K - 183 12 7 3 P - 184 12 8 3 G + 171 11 11 3 L + 172 11 12 3 K + 173 11 13 3 G + 174 11 14 3 D + 175 11 15 3 I + 176 11 16 3 E + 177 12 1 3 N + 178 12 2 3 C + 179 12 3 3 P + 180 12 4 3 O + 181 12 5 3 F + 182 12 6 3 D + 183 12 7 3 K + 184 12 8 3 H 185 12 9 3 L - 186 12 10 3 C - 187 12 11 3 A - 188 12 12 3 H - 189 12 13 3 J - 190 12 14 3 A - 191 12 15 3 O - 192 12 16 3 N - 193 13 1 4 C + 186 12 10 3 I + 187 12 11 3 M + 188 12 12 3 E + 189 12 13 3 A + 190 12 14 3 B + 191 12 15 3 J + 192 12 16 3 G + 193 13 1 4 K 194 13 2 4 G - 195 13 3 4 E - 196 13 4 4 I - 197 13 5 4 P - 198 13 6 4 N - 199 13 7 4 M - 200 13 8 4 F - 201 13 9 4 H - 202 13 10 4 J - 203 13 11 4 O - 204 13 12 4 D - 205 13 13 4 A - 206 13 14 4 B - 207 13 15 4 K - 208 13 16 4 L - 209 14 1 4 P - 210 14 2 4 M - 211 14 3 4 A + 195 13 3 4 D + 196 13 4 4 C + 197 13 5 4 M + 198 13 6 4 F + 199 13 7 4 N + 200 13 8 4 O + 201 13 9 4 E + 202 13 10 4 B + 203 13 11 4 A + 204 13 12 4 I + 205 13 13 4 P + 206 13 14 4 L + 207 13 15 4 H + 208 13 16 4 J + 209 14 1 4 L + 210 14 2 4 I + 211 14 3 4 M 212 14 4 4 G - 213 14 5 4 L - 214 14 6 4 I - 215 14 7 4 N - 216 14 8 4 C - 217 14 9 4 D - 218 14 10 4 K - 219 14 11 4 J - 220 14 12 4 B - 221 14 13 4 O - 222 14 14 4 H - 223 14 15 4 I - 224 14 16 4 F - 225 15 1 4 K - 226 15 2 4 P - 227 15 3 4 L - 228 15 4 4 M + 213 14 5 4 J + 214 14 6 4 H + 215 14 7 4 F + 216 14 8 4 E + 217 14 9 4 P + 218 14 10 4 C + 219 14 11 4 B + 220 14 12 4 K + 221 14 13 4 G + 222 14 14 4 N + 223 14 15 4 A + 224 14 16 4 O + 225 15 1 4 C + 226 15 2 4 K + 227 15 3 4 G + 228 15 4 4 F 229 15 5 4 H - 230 15 6 4 O - 231 15 7 4 A - 232 15 8 4 I - 233 15 9 4 C - 234 15 10 4 B - 235 15 11 4 D - 236 15 12 4 E - 237 15 13 4 G - 238 15 14 4 F - 239 15 15 4 N - 240 15 16 4 B + 230 15 6 4 M + 231 15 7 4 B + 232 15 8 4 D + 233 15 9 4 I + 234 15 10 4 A + 235 15 11 4 N + 236 15 12 4 J + 237 15 13 4 E + 238 15 14 4 P + 239 15 15 4 O + 240 15 16 4 L 241 16 1 4 F - 242 16 2 4 G - 243 16 3 4 D - 244 16 4 4 A - 245 16 5 4 O - 246 16 6 4 L - 247 16 7 4 M - 248 16 8 4 P - 249 16 9 4 K - 250 16 10 4 N - 251 16 11 4 E - 252 16 12 4 J - 253 16 13 4 C - 254 16 14 4 J - 255 16 15 4 H - 256 16 16 4 E + 242 16 2 4 D + 243 16 3 4 O + 244 16 4 4 J + 245 16 5 4 C + 246 16 6 4 B + 247 16 7 4 D + 248 16 8 4 M + 249 16 9 4 P + 250 16 10 4 E + 251 16 11 4 H + 252 16 12 4 L + 253 16 13 4 K + 254 16 14 4 A + 255 16 15 4 N + 256 16 16 4 I diff --git a/tests/testthat/_snaps/speed-layouts/speed-custom-obj-func.svg b/tests/testthat/_snaps/speed-layouts/speed-custom-obj-func.svg index f92b55ba..68047add 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-custom-obj-func.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-custom-obj-func.svg @@ -45,37 +45,37 @@ - - - - - - - - - - + + + + + + + + + + - - + + -A -A -A -A -B -B -B -B -C -C +A +A +A +A +B +B +B +B +C +C C C D -D -D +D +D D diff --git a/tests/testthat/_snaps/speed-layouts/speed-large-blocks.svg b/tests/testthat/_snaps/speed-layouts/speed-large-blocks.svg index e063d589..8b40b4db 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-large-blocks.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-large-blocks.svg @@ -93,518 +93,518 @@ - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + - - + + + + + + + + + + + + + + - - - - - - - - - + + - - - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - -A -A -A -A -A + + + + + + + + + + + + + +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A A -A -A -A -A -A -A -A -A -A -A -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -D -D -D -D -D -D -D -D -D -D -D -D +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +D +D +D +D +D +D +D +D +D D -D -D -D -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -F -F -F -F -F -F -F -F -F -F -F +D +D +D +D +D +D +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +F +F F -F -F +F +F +F +F +F F -F -G +F +F +F +F +F +F +F +G +G +G +G +G +G +G G -G -G -G -G -G -G -G -G -G +G +G G -G -G -G -G -H -H -H -H -H -H -H -H -H +G +G +G +G +G +H +H +H +H +H H -H -H -H -H -H -H -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -K -K -K -K -K -K -K -K -K -K -K -K -K -K -K -K -L -L -L -L -L -L -L +H +H +H +H +H +H +H +H +H +H +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +K +K +K +K +K +K +K +K +K +K +K +K +K +K +K +K +L +L +L +L L -L -L -L -L -L -L -L -L -M -M +L +L +L +L +L +L +L +L +L +L +L +M +M +M +M M -M -M -M -M -M -M -M -M -M -M -M -M -M -N -N -N -N -N -N -N -N -N -N -N -N -N -N -N -N -O -O -O -O -O -O -O -O -O -O -O -O +M +M +M +M +M +M +M +M +M +M +M +N +N +N +N +N +N +N +N +N +N +N +N +N +N +N +N +O +O +O +O O -O -O -O -P -P -P -P -P -P -P -P -P +O +O +O +O +O +O +O +O +O +O +O +P +P P -P -P -P -P -P -P +P +P +P +P +P +P +P +P +P +P +P +P +P diff --git a/tests/testthat/_snaps/speed-layouts/speed-large-grid.svg b/tests/testthat/_snaps/speed-layouts/speed-large-grid.svg index 4c1b8ed1..c4d75595 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-large-grid.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-large-grid.svg @@ -109,806 +109,806 @@ - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - + - - - + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - - - + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + -A -A -A -A -A -A -A -A -A -A + + + + + + + + + + + +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A +A +A +A +A +A +A A -A -A -A -A -A -A -A -A -A -A -A -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B +B B -B -B -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C +B +C +C +C +C +C +C +C +C +C +C C -C -C -C -C -C -C -C -C -C -C -C +C C -C -C -C +C +C +C C -C -C -C -C -C -C -D -D -D -D -D -D -D -D -D +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +D D -D -D D -D -D -D -D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D D -D -D -D -D -D -D -D +D +D +D +D +D +D +D +D +D +D +D D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -E -E -E -E -E -E +D +D +D +D +D +D +E +E +E +E +E +E +E E -E -E -E -E -E -E -E -E -E -E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E E -E -E -E -E -E -E -E -E -E -E -E E -E -E -E -E -E -E -E -E -E -E -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F +E +E +E +E +E +E F -F -F -F +F +F F -F -F -F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F F -F -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G +F +G +G +G +G +G +G +G +G G -G -G -G -G +G +G +G +G +G +G +G +G G -G -G -G -G -G -G -G -G -G -G -G -G -H -H -H -H +G +G +G +G +G +G +G +G +G +G +G +G +G +G +G +G +G +G +G +G +G +G +H +H +H +H +H H -H -H -H -H -H +H H -H -H -H -H -H -H -H H -H -H -H -H -H -H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -I +H +H +H +H +H +H +H +H +H +H +H +H +I +I +I +I +I +I +I +I +I +I +I +I I +I +I I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -J -J -J -J -J -J -J -J -J +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J +J +J +J +J +J J -J -J -J -J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J J +J +J +J +J +J +J +J +J +J +J +J diff --git a/tests/testthat/_snaps/speed-layouts/speed-large-missing-clump.svg b/tests/testthat/_snaps/speed-layouts/speed-large-missing-clump.svg index eb70f051..8440c619 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-large-missing-clump.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-large-missing-clump.svg @@ -109,774 +109,774 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - + + + + + + - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + - - - + + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + - - - - - - - - - - - - - + + + + + + + - - - - - - + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + - - - + + + + + + + + + - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +A +A +A +A +A +A +A +A A -A +A +A +A +A +A +A A -A -A -A +A +A +A +A +A +A +A +A +A A -A -A -A -A -A -A -A -A -A -A -A -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B +A +A +A +A +A +A +A +A +A +A +A +A +A +A +B +B +B +B +B +B +B +B B -B -B -B -B -B -B -B -B -B -B -B +B +B +B B -B -B -B +B +B +B +B +B +B +B +B +B +B +B +B +B +B B -C -C -C -C -C +B +B +B +B +B +B +B +B +B +B +B +B +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C +C +C +C +C +C C -C -C -C -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D +C +C +C +C +C +C +C +C +C +D +D +D +D +D +D +D +D +D +D +D +D D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +E +E E -E -E -E -E -E -E -E -E -E +E +E E -E -E -E -E -E -E -E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E E -E -E -E -E -E -E -F -F -F -F -F -F -F -F -F +E +E +E +E +E +E +E +F +F +F +F +F F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F +F +F +F F -F -F -F -F -F -F -F -F -G -G -G +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +G +G +G +G G -G -G -G +G +G +G +G +G +G +G +G +G G -G -G -G -G -G -G -G -G -G -G -G -G -G +G +G +G +G +G +G +G G -G -G -G -G -G -G +G +G +G +G G -G -G -G -G -G -G -G -H -H -H -H -H -H -H -H -H -H -H -H +G +G +G +G +G +G +G +G +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H H -H -H -H -H -H -H -H -H -H -H -H -H -H -H +H +H +H +H H -H -H -H -H -H -H -H -H -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I +H +H +H +H +H +H +H +H +H +I +I +I I -I -I -I +I +I +I +I +I +I +I +I +I I -I -I -I -I -I -I +I +I +I +I +I +I +I +I +I +I +I +I +I I -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J +I +I +I +I +I +I +I +I +J +J +J +J +J J -J -J -J -J -J -J -J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J diff --git a/tests/testthat/_snaps/speed-layouts/speed-large-missing-l.svg b/tests/testthat/_snaps/speed-layouts/speed-large-missing-l.svg index 28df3431..8517f29f 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-large-missing-l.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-large-missing-l.svg @@ -109,582 +109,582 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +A +A A -A +A +A +A +A +A +A +A +A +A +A +A +A +A +A A -A -A -A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +B +B +B +B +B +B +B +B +B +B +B +B +B +B B -B -B -B -B -B -B -B -B -B +B B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B +B +B +B +B +B +B +B +B +B +B +B +B B -B -B -B -B -B -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C +B +B +B +B +B +B +B +B +B +B +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C C -C -C -C -C -C -C -C -C -C -C -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D +C +C +C +C +C +D +D +D D -D -D -D -D -D -D -D -D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +E +E +E +E +E +E E -E -E -E +E +E +E +E +E +E +E E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F +E +E +E +E +E +E +E +E +E +E +E +F +F +F F +F +F +F +F F -F -G -G -G -G -G -G -G -G -G -G -G -G +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +G +G G -G -G -G -G +G +G +G +G +G +G +G +G +G +G +G +G +G G -G -G -G -G G -G -G -G -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H +G +G +G +G +G +G +G +G +H +H +H +H +H +H +H +H +H +H +H +H H -H -H -H -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J +H +H +H +H +H +H +H +H +H +H +H +H +H +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J diff --git a/tests/testthat/_snaps/speed-layouts/speed-large-missing.svg b/tests/testthat/_snaps/speed-layouts/speed-large-missing.svg index 641eea99..c0bfec24 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-large-missing.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-large-missing.svg @@ -109,706 +109,706 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - + - - - - - - - - - - - - - - - + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + - - - - - - - - - - -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A + + + + + + + + + + + + + + + + + + + +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -B -B -B -B -B -B -B +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A B -B -B -B -B -B -B -B -B -B -B -B +B B -B -B -B -B -B -B -B B -B -B -B -B -B -B -B -B +B +B +B +B +B +B +B +B +B +B B -C -C -C -C -C -C -C +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +C +C +C C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C C -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D +C +C +C +C +C +C +C +C +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -E -E -E -E +D +D +D +D +D +D +D +D +D +E +E +E +E +E +E +E +E +E +E E -E -E -E -E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -F -F -F -F -F -F -F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F F -F -F -F -F -F +F F -F -F -F -F -F -F -F -F -F -F -F -F -F -F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F F -F -F -F -F -F -F -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G G -G -G -G -G -G +G +G +G +G +G +G +G +G G +G +G +G +G +G +G +G +G +G G -G -G -G -G -G +G +G +G +G +G +G +G +G +G +G +G +G +G +G +G +H +H +H +H +H +H H -H -H -H -H -H -H -H -H -H -H -H -H -H -H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I +H +H +H +H +H +H +H +H +H +I +I +I +I I -I -I -I -I -I -I -I -I -I -I -I -I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I I -J -J -J -J -J -J -J -J -J +I +I +I +I +J +J +J +J +J +J +J +J +J +J +J J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J +J +J +J +J J -J -J -J -J -J -J -J -J -J -J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J diff --git a/tests/testthat/_snaps/speed-layouts/speed-large-rcbd.svg b/tests/testthat/_snaps/speed-layouts/speed-large-rcbd.svg index 9024555c..d0e97f94 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-large-rcbd.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-large-rcbd.svg @@ -209,4006 +209,4006 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -V1 -V1 -V1 -V1 -V10 -V10 -V10 -V10 -V100 -V100 -V100 -V100 -V101 -V101 -V101 -V101 -V102 -V102 -V102 -V102 -V103 -V103 -V103 -V103 -V104 -V104 -V104 -V104 -V105 -V105 -V105 -V105 -V106 -V106 -V106 -V106 -V107 -V107 -V107 -V107 -V108 -V108 -V108 -V108 -V109 -V109 -V109 -V109 -V11 -V11 -V11 -V11 -V110 -V110 -V110 -V110 -V111 -V111 -V111 -V111 -V112 -V112 -V112 -V112 -V113 -V113 -V113 -V113 -V114 -V114 -V114 -V114 -V115 -V115 -V115 -V115 -V116 -V116 -V116 -V116 -V117 -V117 -V117 -V117 -V118 -V118 -V118 -V118 -V119 -V119 -V119 -V119 -V12 -V12 -V12 -V12 -V120 -V120 -V120 -V120 -V121 -V121 -V121 -V121 -V122 -V122 -V122 -V122 -V123 -V123 -V123 -V123 -V124 -V124 -V124 -V124 -V125 -V125 -V125 -V125 -V126 -V126 -V126 -V126 -V127 -V127 -V127 -V127 -V128 -V128 -V128 -V128 -V129 -V129 -V129 -V129 -V13 -V13 -V13 -V13 -V130 -V130 -V130 -V130 -V131 -V131 -V131 -V131 -V132 -V132 -V132 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +V1 +V1 +V1 +V1 +V10 +V10 +V10 +V10 +V100 +V100 +V100 +V100 +V101 +V101 +V101 +V101 +V102 +V102 +V102 +V102 +V103 +V103 +V103 +V103 +V104 +V104 +V104 +V104 +V105 +V105 +V105 +V105 +V106 +V106 +V106 +V106 +V107 +V107 +V107 +V107 +V108 +V108 +V108 +V108 +V109 +V109 +V109 +V109 +V11 +V11 +V11 +V11 +V110 +V110 +V110 +V110 +V111 +V111 +V111 +V111 +V112 +V112 +V112 +V112 +V113 +V113 +V113 +V113 +V114 +V114 +V114 +V114 +V115 +V115 +V115 +V115 +V116 +V116 +V116 +V116 +V117 +V117 +V117 +V117 +V118 +V118 +V118 +V118 +V119 +V119 +V119 +V119 +V12 +V12 +V12 +V12 +V120 +V120 +V120 +V120 +V121 +V121 +V121 +V121 +V122 +V122 +V122 +V122 +V123 +V123 +V123 +V123 +V124 +V124 +V124 +V124 +V125 +V125 +V125 +V125 +V126 +V126 +V126 +V126 +V127 +V127 +V127 +V127 +V128 +V128 +V128 +V128 +V129 +V129 +V129 +V129 +V13 +V13 +V13 +V13 +V130 +V130 +V130 +V130 +V131 +V131 +V131 +V131 +V132 +V132 +V132 V132 -V133 -V133 -V133 -V133 -V134 -V134 -V134 -V134 -V135 -V135 -V135 -V135 -V136 -V136 -V136 -V136 -V137 -V137 -V137 -V137 -V138 -V138 -V138 -V138 -V139 -V139 -V139 -V139 -V14 -V14 -V14 -V14 -V140 -V140 -V140 -V140 -V141 -V141 -V141 -V141 -V142 -V142 -V142 -V142 -V143 -V143 -V143 -V143 -V144 -V144 -V144 -V144 -V145 -V145 -V145 -V145 -V146 -V146 -V146 -V146 -V147 -V147 -V147 -V147 -V148 -V148 -V148 -V148 -V149 -V149 -V149 -V149 -V15 -V15 -V15 -V15 -V150 -V150 -V150 -V150 -V151 -V151 -V151 -V151 -V152 -V152 +V133 +V133 +V133 +V133 +V134 +V134 +V134 +V134 +V135 +V135 +V135 +V135 +V136 +V136 +V136 +V136 +V137 +V137 +V137 +V137 +V138 +V138 +V138 +V138 +V139 +V139 +V139 +V139 +V14 +V14 +V14 +V14 +V140 +V140 +V140 +V140 +V141 +V141 +V141 +V141 +V142 +V142 +V142 +V142 +V143 +V143 +V143 +V143 +V144 +V144 +V144 +V144 +V145 +V145 +V145 +V145 +V146 +V146 +V146 +V146 +V147 +V147 +V147 +V147 +V148 +V148 +V148 +V148 +V149 +V149 +V149 +V149 +V15 +V15 +V15 +V15 +V150 +V150 +V150 +V150 +V151 +V151 +V151 +V151 +V152 +V152 V152 -V152 -V153 -V153 -V153 -V153 -V154 -V154 -V154 -V154 -V155 -V155 -V155 -V155 -V156 -V156 -V156 -V156 -V157 -V157 -V157 -V157 -V158 -V158 -V158 -V158 -V159 -V159 -V159 -V159 -V16 -V16 -V16 -V16 -V160 -V160 -V160 -V160 -V161 -V161 -V161 -V161 -V162 -V162 -V162 -V162 -V163 -V163 -V163 -V163 -V164 -V164 -V164 -V164 -V165 -V165 -V165 -V165 -V166 -V166 -V166 -V166 -V167 -V167 -V167 -V167 -V168 -V168 -V168 -V168 -V169 -V169 -V169 -V169 -V17 -V17 -V17 -V17 -V170 -V170 -V170 -V170 -V171 -V171 -V171 -V171 -V172 -V172 -V172 -V172 -V173 -V173 -V173 -V173 -V174 -V174 -V174 -V174 -V175 -V175 -V175 -V175 -V176 -V176 -V176 -V176 -V177 -V177 -V177 -V177 -V178 -V178 -V178 -V178 -V179 -V179 -V179 -V179 -V18 -V18 -V18 -V18 -V180 -V180 -V180 -V180 -V181 -V181 -V181 -V181 -V182 -V182 -V182 -V182 -V183 -V183 -V183 -V183 -V184 -V184 -V184 -V184 -V185 -V185 -V185 -V185 -V186 -V186 -V186 -V186 -V187 -V187 -V187 -V187 -V188 -V188 -V188 -V188 -V189 -V189 -V189 -V189 -V19 -V19 -V19 -V19 -V190 -V190 -V190 -V190 -V191 -V191 -V191 -V191 -V192 -V192 -V192 -V192 -V193 -V193 -V193 -V193 -V194 -V194 -V194 -V194 -V195 -V195 -V195 -V195 -V196 -V196 -V196 -V196 -V197 -V197 -V197 -V197 -V198 -V198 -V198 -V198 -V199 -V199 -V199 -V199 -V2 -V2 -V2 -V2 -V20 -V20 -V20 -V20 -V200 -V200 -V200 -V200 -V201 -V201 -V201 -V201 -V202 -V202 -V202 -V202 -V203 -V203 -V203 -V203 -V204 -V204 -V204 -V204 -V205 -V205 -V205 -V205 -V206 -V206 -V206 -V206 -V207 -V207 -V207 -V207 -V208 -V208 -V208 -V208 -V209 -V209 -V209 -V209 -V21 -V21 -V21 -V21 -V210 -V210 -V210 -V210 -V211 -V211 -V211 -V211 -V212 -V212 -V212 -V212 -V213 -V213 -V213 -V213 -V214 -V214 -V214 -V214 -V215 -V215 -V215 -V215 -V216 -V216 -V216 -V216 -V217 -V217 -V217 -V217 -V218 -V218 -V218 -V218 -V219 -V219 -V219 -V219 -V22 -V22 -V22 -V22 -V220 -V220 -V220 -V220 -V221 -V221 -V221 -V221 -V222 -V222 -V222 -V222 -V223 -V223 -V223 -V223 -V224 -V224 -V224 -V224 -V225 -V225 -V225 -V225 -V226 -V226 -V226 -V226 -V227 -V227 -V227 -V227 -V228 -V228 -V228 -V228 -V229 -V229 -V229 -V229 -V23 -V23 -V23 -V23 -V230 -V230 -V230 -V230 -V231 -V231 -V231 -V231 -V232 -V232 -V232 -V232 -V233 -V233 -V233 -V233 -V234 -V234 -V234 -V234 -V235 -V235 -V235 -V235 -V236 -V236 -V236 -V236 -V237 -V237 -V237 -V237 -V238 -V238 -V238 -V238 -V239 -V239 -V239 -V239 -V24 -V24 -V24 -V24 -V240 -V240 -V240 -V240 -V241 -V241 -V241 -V241 -V242 -V242 -V242 -V242 -V243 -V243 -V243 -V243 -V244 -V244 -V244 -V244 -V245 -V245 -V245 -V245 -V246 -V246 -V246 -V246 -V247 -V247 -V247 -V247 -V248 -V248 -V248 -V248 -V249 -V249 -V249 -V249 -V25 -V25 -V25 -V25 -V250 -V250 -V250 -V250 -V251 -V251 -V251 -V251 -V252 -V252 -V252 -V252 -V253 -V253 -V253 -V253 -V254 -V254 -V254 -V254 -V255 -V255 -V255 +V152 +V153 +V153 +V153 +V153 +V154 +V154 +V154 +V154 +V155 +V155 +V155 +V155 +V156 +V156 +V156 +V156 +V157 +V157 +V157 +V157 +V158 +V158 +V158 +V158 +V159 +V159 +V159 +V159 +V16 +V16 +V16 +V16 +V160 +V160 +V160 +V160 +V161 +V161 +V161 +V161 +V162 +V162 +V162 +V162 +V163 +V163 +V163 +V163 +V164 +V164 +V164 +V164 +V165 +V165 +V165 +V165 +V166 +V166 +V166 +V166 +V167 +V167 +V167 +V167 +V168 +V168 +V168 +V168 +V169 +V169 +V169 +V169 +V17 +V17 +V17 +V17 +V170 +V170 +V170 +V170 +V171 +V171 +V171 +V171 +V172 +V172 +V172 +V172 +V173 +V173 +V173 +V173 +V174 +V174 +V174 +V174 +V175 +V175 +V175 +V175 +V176 +V176 +V176 +V176 +V177 +V177 +V177 +V177 +V178 +V178 +V178 +V178 +V179 +V179 +V179 +V179 +V18 +V18 +V18 +V18 +V180 +V180 +V180 +V180 +V181 +V181 +V181 +V181 +V182 +V182 +V182 +V182 +V183 +V183 +V183 +V183 +V184 +V184 +V184 +V184 +V185 +V185 +V185 +V185 +V186 +V186 +V186 +V186 +V187 +V187 +V187 +V187 +V188 +V188 +V188 +V188 +V189 +V189 +V189 +V189 +V19 +V19 +V19 +V19 +V190 +V190 +V190 +V190 +V191 +V191 +V191 +V191 +V192 +V192 +V192 +V192 +V193 +V193 +V193 +V193 +V194 +V194 +V194 +V194 +V195 +V195 +V195 +V195 +V196 +V196 +V196 +V196 +V197 +V197 +V197 +V197 +V198 +V198 +V198 +V198 +V199 +V199 +V199 +V199 +V2 +V2 +V2 +V2 +V20 +V20 +V20 +V20 +V200 +V200 +V200 +V200 +V201 +V201 +V201 +V201 +V202 +V202 +V202 +V202 +V203 +V203 +V203 +V203 +V204 +V204 +V204 +V204 +V205 +V205 +V205 +V205 +V206 +V206 +V206 +V206 +V207 +V207 +V207 +V207 +V208 +V208 +V208 +V208 +V209 +V209 +V209 +V209 +V21 +V21 +V21 +V21 +V210 +V210 +V210 +V210 +V211 +V211 +V211 +V211 +V212 +V212 +V212 +V212 +V213 +V213 +V213 +V213 +V214 +V214 +V214 +V214 +V215 +V215 +V215 +V215 +V216 +V216 +V216 +V216 +V217 +V217 +V217 +V217 +V218 +V218 +V218 +V218 +V219 +V219 +V219 +V219 +V22 +V22 +V22 +V22 +V220 +V220 +V220 +V220 +V221 +V221 +V221 +V221 +V222 +V222 +V222 +V222 +V223 +V223 +V223 +V223 +V224 +V224 +V224 +V224 +V225 +V225 +V225 +V225 +V226 +V226 +V226 +V226 +V227 +V227 +V227 +V227 +V228 +V228 +V228 +V228 +V229 +V229 +V229 +V229 +V23 +V23 +V23 +V23 +V230 +V230 +V230 +V230 +V231 +V231 +V231 +V231 +V232 +V232 +V232 +V232 +V233 +V233 +V233 +V233 +V234 +V234 +V234 +V234 +V235 +V235 +V235 +V235 +V236 +V236 +V236 +V236 +V237 +V237 +V237 +V237 +V238 +V238 +V238 +V238 +V239 +V239 +V239 +V239 +V24 +V24 +V24 +V24 +V240 +V240 +V240 +V240 +V241 +V241 +V241 +V241 +V242 +V242 +V242 +V242 +V243 +V243 +V243 +V243 +V244 +V244 +V244 +V244 +V245 +V245 +V245 +V245 +V246 +V246 +V246 +V246 +V247 +V247 +V247 +V247 +V248 +V248 +V248 +V248 +V249 +V249 +V249 +V249 +V25 +V25 +V25 +V25 +V250 +V250 +V250 +V250 +V251 +V251 +V251 +V251 +V252 +V252 +V252 +V252 +V253 +V253 +V253 +V253 +V254 +V254 +V254 +V254 V255 -V256 -V256 -V256 -V256 -V257 -V257 -V257 -V257 -V258 -V258 -V258 -V258 -V259 -V259 -V259 -V259 -V26 -V26 -V26 -V26 -V260 -V260 -V260 -V260 -V261 -V261 -V261 -V261 -V262 -V262 -V262 -V262 -V263 -V263 -V263 -V263 -V264 -V264 -V264 -V264 -V265 -V265 -V265 -V265 -V266 -V266 -V266 -V266 -V267 -V267 -V267 -V267 -V268 -V268 -V268 -V268 -V269 -V269 -V269 -V269 -V27 -V27 -V27 -V27 -V270 -V270 -V270 -V270 -V271 -V271 -V271 -V271 -V272 -V272 -V272 -V272 -V273 -V273 -V273 -V273 -V274 -V274 -V274 -V274 -V275 -V275 -V275 -V275 -V276 -V276 -V276 -V276 -V277 -V277 -V277 -V277 -V278 -V278 -V278 -V278 -V279 -V279 -V279 -V279 -V28 -V28 -V28 -V28 -V280 -V280 -V280 -V280 -V281 -V281 -V281 -V281 -V282 -V282 -V282 -V282 -V283 -V283 -V283 -V283 -V284 -V284 -V284 -V284 -V285 -V285 -V285 -V285 -V286 -V286 -V286 -V286 -V287 -V287 -V287 -V287 -V288 -V288 -V288 -V288 -V289 -V289 -V289 -V289 -V29 -V29 -V29 -V29 -V290 -V290 -V290 -V290 -V291 -V291 -V291 -V291 -V292 -V292 -V292 -V292 -V293 -V293 -V293 -V293 -V294 -V294 -V294 -V294 -V295 -V295 -V295 -V295 -V296 -V296 -V296 -V296 -V297 -V297 -V297 -V297 -V298 -V298 -V298 -V298 -V299 -V299 -V299 -V299 -V3 -V3 -V3 -V3 -V30 -V30 -V30 -V30 -V300 -V300 -V300 -V300 -V301 -V301 -V301 -V301 -V302 -V302 -V302 -V302 -V303 -V303 -V303 -V303 -V304 -V304 -V304 -V304 -V305 -V305 -V305 -V305 -V306 -V306 -V306 -V306 -V307 -V307 -V307 -V307 -V308 -V308 -V308 -V308 -V309 -V309 -V309 -V309 -V31 -V31 -V31 -V31 -V310 -V310 -V310 -V310 -V311 -V311 -V311 -V311 -V312 -V312 -V312 -V312 -V313 -V313 -V313 -V313 -V314 -V314 -V314 -V314 -V315 -V315 -V315 -V315 -V316 -V316 -V316 -V316 -V317 -V317 -V317 -V317 -V318 -V318 -V318 -V318 -V319 -V319 -V319 -V319 -V32 -V32 -V32 -V32 -V320 -V320 -V320 -V320 -V321 -V321 -V321 -V321 -V322 -V322 -V322 -V322 -V323 -V323 -V323 -V323 -V324 -V324 -V324 -V324 -V325 -V325 -V325 -V325 -V326 -V326 -V326 -V326 -V327 -V327 -V327 -V327 -V328 -V328 -V328 -V328 -V329 -V329 -V329 -V329 -V33 -V33 -V33 -V33 -V330 -V330 -V330 -V330 -V331 -V331 -V331 -V331 -V332 -V332 -V332 -V332 -V333 -V333 -V333 -V333 -V334 -V334 -V334 -V334 -V335 -V335 -V335 -V335 -V336 -V336 -V336 -V336 -V337 -V337 -V337 -V337 -V338 -V338 -V338 -V338 -V339 -V339 -V339 -V339 -V34 -V34 -V34 -V34 -V340 -V340 -V340 -V340 -V341 -V341 -V341 -V341 -V342 -V342 -V342 -V342 -V343 -V343 -V343 -V343 -V344 -V344 -V344 -V344 -V345 -V345 -V345 -V345 -V346 -V346 -V346 -V346 -V347 -V347 -V347 -V347 -V348 -V348 -V348 -V348 -V349 -V349 -V349 -V349 -V35 -V35 -V35 -V35 -V350 -V350 -V350 -V350 -V351 -V351 -V351 -V351 -V352 -V352 -V352 -V352 -V353 -V353 -V353 -V353 -V354 -V354 -V354 -V354 -V355 -V355 -V355 -V355 -V356 -V356 -V356 -V356 -V357 -V357 -V357 -V357 -V358 -V358 -V358 -V358 -V359 -V359 -V359 -V359 -V36 -V36 -V36 -V36 -V360 -V360 -V360 -V360 -V361 -V361 -V361 -V361 -V362 -V362 -V362 -V362 -V363 -V363 -V363 -V363 -V364 -V364 -V364 -V364 -V365 -V365 -V365 -V365 -V366 -V366 -V366 -V366 -V367 -V367 -V367 -V367 -V368 -V368 -V368 -V368 -V369 -V369 -V369 -V369 -V37 -V37 -V37 -V37 -V370 -V370 -V370 -V370 -V371 -V371 -V371 -V371 -V372 -V372 -V372 -V372 -V373 -V373 -V373 -V373 -V374 -V374 -V374 -V374 -V375 -V375 -V375 -V375 -V376 -V376 -V376 -V376 -V377 -V377 -V377 -V377 -V378 -V378 -V378 -V378 -V379 -V379 -V379 -V379 -V38 -V38 -V38 -V38 -V380 -V380 -V380 -V380 -V381 -V381 -V381 -V381 -V382 -V382 -V382 -V382 -V383 -V383 -V383 -V383 -V384 -V384 -V384 -V384 -V385 -V385 -V385 -V385 -V386 -V386 -V386 -V386 -V387 -V387 -V387 -V387 -V388 -V388 -V388 -V388 -V389 -V389 -V389 -V389 -V39 -V39 -V39 -V39 -V390 -V390 -V390 -V390 -V391 -V391 -V391 -V391 -V392 -V392 -V392 -V392 -V393 -V393 -V393 -V393 -V394 -V394 -V394 -V394 -V395 -V395 -V395 -V395 -V396 -V396 -V396 -V396 -V397 -V397 -V397 -V397 -V398 -V398 -V398 -V398 -V399 -V399 -V399 -V399 -V4 -V4 -V4 -V4 -V40 -V40 -V40 -V40 -V400 -V400 -V400 -V400 -V401 -V401 -V401 -V401 -V402 -V402 -V402 -V402 -V403 -V403 -V403 -V403 -V404 -V404 -V404 -V404 -V405 -V405 -V405 -V405 -V406 -V406 -V406 -V406 -V407 -V407 -V407 -V407 -V408 -V408 -V408 -V408 -V409 -V409 -V409 -V409 -V41 -V41 -V41 -V41 -V410 -V410 -V410 -V410 -V411 -V411 -V411 -V411 -V412 -V412 -V412 -V412 -V413 -V413 -V413 -V413 -V414 -V414 -V414 -V414 -V415 -V415 -V415 -V415 -V416 -V416 -V416 -V416 -V417 -V417 -V417 -V417 -V418 -V418 -V418 -V418 -V419 -V419 -V419 -V419 -V42 -V42 -V42 -V42 -V420 -V420 -V420 -V420 -V421 -V421 -V421 -V421 -V422 -V422 -V422 -V422 -V423 -V423 -V423 -V423 -V424 -V424 -V424 -V424 -V425 -V425 -V425 -V425 -V426 -V426 -V426 -V426 -V427 -V427 -V427 -V427 -V428 -V428 -V428 -V428 -V429 -V429 -V429 -V429 -V43 -V43 -V43 -V43 -V430 -V430 -V430 -V430 -V431 -V431 -V431 -V431 -V432 -V432 -V432 -V432 +V255 +V255 +V255 +V256 +V256 +V256 +V256 +V257 +V257 +V257 +V257 +V258 +V258 +V258 +V258 +V259 +V259 +V259 +V259 +V26 +V26 +V26 +V26 +V260 +V260 +V260 +V260 +V261 +V261 +V261 +V261 +V262 +V262 +V262 +V262 +V263 +V263 +V263 +V263 +V264 +V264 +V264 +V264 +V265 +V265 +V265 +V265 +V266 +V266 +V266 +V266 +V267 +V267 +V267 +V267 +V268 +V268 +V268 +V268 +V269 +V269 +V269 +V269 +V27 +V27 +V27 +V27 +V270 +V270 +V270 +V270 +V271 +V271 +V271 +V271 +V272 +V272 +V272 +V272 +V273 +V273 +V273 +V273 +V274 +V274 +V274 +V274 +V275 +V275 +V275 +V275 +V276 +V276 +V276 +V276 +V277 +V277 +V277 +V277 +V278 +V278 +V278 +V278 +V279 +V279 +V279 +V279 +V28 +V28 +V28 +V28 +V280 +V280 +V280 +V280 +V281 +V281 +V281 +V281 +V282 +V282 +V282 +V282 +V283 +V283 +V283 +V283 +V284 +V284 +V284 +V284 +V285 +V285 +V285 +V285 +V286 +V286 +V286 +V286 +V287 +V287 +V287 +V287 +V288 +V288 +V288 +V288 +V289 +V289 +V289 +V289 +V29 +V29 +V29 +V29 +V290 +V290 +V290 +V290 +V291 +V291 +V291 +V291 +V292 +V292 +V292 +V292 +V293 +V293 +V293 +V293 +V294 +V294 +V294 +V294 +V295 +V295 +V295 +V295 +V296 +V296 +V296 +V296 +V297 +V297 +V297 +V297 +V298 +V298 +V298 +V298 +V299 +V299 +V299 +V299 +V3 +V3 +V3 +V3 +V30 +V30 +V30 +V30 +V300 +V300 +V300 +V300 +V301 +V301 +V301 +V301 +V302 +V302 +V302 +V302 +V303 +V303 +V303 +V303 +V304 +V304 +V304 +V304 +V305 +V305 +V305 +V305 +V306 +V306 +V306 +V306 +V307 +V307 +V307 +V307 +V308 +V308 +V308 +V308 +V309 +V309 +V309 +V309 +V31 +V31 +V31 +V31 +V310 +V310 +V310 +V310 +V311 +V311 +V311 +V311 +V312 +V312 +V312 +V312 +V313 +V313 +V313 +V313 +V314 +V314 +V314 +V314 +V315 +V315 +V315 +V315 +V316 +V316 +V316 +V316 +V317 +V317 +V317 +V317 +V318 +V318 +V318 +V318 +V319 +V319 +V319 +V319 +V32 +V32 +V32 +V32 +V320 +V320 +V320 +V320 +V321 +V321 +V321 +V321 +V322 +V322 +V322 +V322 +V323 +V323 +V323 +V323 +V324 +V324 +V324 +V324 +V325 +V325 +V325 +V325 +V326 +V326 +V326 +V326 +V327 +V327 +V327 +V327 +V328 +V328 +V328 +V328 +V329 +V329 +V329 +V329 +V33 +V33 +V33 +V33 +V330 +V330 +V330 +V330 +V331 +V331 +V331 +V331 +V332 +V332 +V332 +V332 +V333 +V333 +V333 +V333 +V334 +V334 +V334 +V334 +V335 +V335 +V335 +V335 +V336 +V336 +V336 +V336 +V337 +V337 +V337 +V337 +V338 +V338 +V338 +V338 +V339 +V339 +V339 +V339 +V34 +V34 +V34 +V34 +V340 +V340 +V340 +V340 +V341 +V341 +V341 +V341 +V342 +V342 +V342 +V342 +V343 +V343 +V343 +V343 +V344 +V344 +V344 +V344 +V345 +V345 +V345 +V345 +V346 +V346 +V346 +V346 +V347 +V347 +V347 +V347 +V348 +V348 +V348 +V348 +V349 +V349 +V349 +V349 +V35 +V35 +V35 +V35 +V350 +V350 +V350 +V350 +V351 +V351 +V351 +V351 +V352 +V352 +V352 +V352 +V353 +V353 +V353 +V353 +V354 +V354 +V354 +V354 +V355 +V355 +V355 +V355 +V356 +V356 +V356 +V356 +V357 +V357 +V357 +V357 +V358 +V358 +V358 +V358 +V359 +V359 +V359 +V359 +V36 +V36 +V36 +V36 +V360 +V360 +V360 +V360 +V361 +V361 +V361 +V361 +V362 +V362 +V362 +V362 +V363 +V363 +V363 +V363 +V364 +V364 +V364 +V364 +V365 +V365 +V365 +V365 +V366 +V366 +V366 +V366 +V367 +V367 +V367 +V367 +V368 +V368 +V368 +V368 +V369 +V369 +V369 +V369 +V37 +V37 +V37 +V37 +V370 +V370 +V370 +V370 +V371 +V371 +V371 +V371 +V372 +V372 +V372 +V372 +V373 +V373 +V373 +V373 +V374 +V374 +V374 +V374 +V375 +V375 +V375 +V375 +V376 +V376 +V376 +V376 +V377 +V377 +V377 +V377 +V378 +V378 +V378 +V378 +V379 +V379 +V379 +V379 +V38 +V38 +V38 +V38 +V380 +V380 +V380 +V380 +V381 +V381 +V381 +V381 +V382 +V382 +V382 +V382 +V383 +V383 +V383 +V383 +V384 +V384 +V384 +V384 +V385 +V385 +V385 +V385 +V386 +V386 +V386 +V386 +V387 +V387 +V387 +V387 +V388 +V388 +V388 +V388 +V389 +V389 +V389 +V389 +V39 +V39 +V39 +V39 +V390 +V390 +V390 +V390 +V391 +V391 +V391 +V391 +V392 +V392 +V392 +V392 +V393 +V393 +V393 +V393 +V394 +V394 +V394 +V394 +V395 +V395 +V395 +V395 +V396 +V396 +V396 +V396 +V397 +V397 +V397 +V397 +V398 +V398 +V398 +V398 +V399 +V399 +V399 +V399 +V4 +V4 +V4 +V4 +V40 +V40 +V40 +V40 +V400 +V400 +V400 +V400 +V401 +V401 +V401 +V401 +V402 +V402 +V402 +V402 +V403 +V403 +V403 +V403 +V404 +V404 +V404 +V404 +V405 +V405 +V405 +V405 +V406 +V406 +V406 +V406 +V407 +V407 +V407 +V407 +V408 +V408 +V408 +V408 +V409 +V409 +V409 +V409 +V41 +V41 +V41 +V41 +V410 +V410 +V410 +V410 +V411 +V411 +V411 +V411 +V412 +V412 +V412 +V412 +V413 +V413 +V413 +V413 +V414 +V414 +V414 +V414 +V415 +V415 +V415 +V415 +V416 +V416 +V416 +V416 +V417 +V417 +V417 +V417 +V418 +V418 +V418 +V418 +V419 +V419 +V419 +V419 +V42 +V42 +V42 +V42 +V420 +V420 +V420 +V420 +V421 +V421 +V421 +V421 +V422 +V422 +V422 +V422 +V423 +V423 +V423 +V423 +V424 +V424 +V424 +V424 +V425 +V425 +V425 +V425 +V426 +V426 +V426 +V426 +V427 +V427 +V427 +V427 +V428 +V428 +V428 +V428 +V429 +V429 +V429 +V429 +V43 +V43 +V43 +V43 +V430 +V430 +V430 +V430 +V431 +V431 +V431 +V431 +V432 +V432 +V432 +V432 +V433 V433 -V433 -V433 -V433 -V434 -V434 -V434 -V434 -V435 -V435 -V435 +V433 +V433 +V434 +V434 +V434 +V434 +V435 +V435 +V435 V435 -V436 -V436 -V436 -V436 -V437 -V437 -V437 -V437 -V438 -V438 -V438 -V438 -V439 -V439 -V439 -V439 -V44 -V44 -V44 -V44 -V440 -V440 -V440 -V440 -V441 -V441 -V441 -V441 -V442 -V442 -V442 -V442 -V443 -V443 -V443 -V443 -V444 -V444 -V444 -V444 -V445 -V445 -V445 -V445 -V446 -V446 -V446 -V446 -V447 -V447 -V447 -V447 -V448 -V448 -V448 -V448 -V449 -V449 -V449 -V449 -V45 -V45 -V45 -V45 -V450 -V450 -V450 -V450 -V451 -V451 -V451 -V451 -V452 -V452 -V452 -V452 -V453 -V453 -V453 -V453 -V454 -V454 -V454 -V454 -V455 -V455 -V455 -V455 -V456 -V456 -V456 -V456 -V457 -V457 -V457 -V457 -V458 -V458 -V458 -V458 -V459 -V459 -V459 -V459 -V46 -V46 -V46 -V46 -V460 -V460 -V460 -V460 -V461 -V461 -V461 -V461 -V462 -V462 -V462 -V462 -V463 -V463 -V463 -V463 -V464 -V464 -V464 -V464 -V465 -V465 -V465 -V465 -V466 -V466 -V466 -V466 -V467 -V467 -V467 -V467 -V468 -V468 -V468 -V468 -V469 -V469 -V469 -V469 -V47 -V47 -V47 -V47 -V470 -V470 -V470 -V470 -V471 -V471 -V471 -V471 -V472 -V472 -V472 -V472 -V473 -V473 -V473 -V473 -V474 -V474 -V474 -V474 -V475 -V475 -V475 -V475 -V476 -V476 -V476 -V476 -V477 -V477 -V477 -V477 -V478 -V478 -V478 -V478 -V479 -V479 -V479 -V479 -V48 -V48 -V48 -V48 -V480 -V480 -V480 -V480 -V481 -V481 -V481 -V481 -V482 -V482 -V482 -V482 -V483 -V483 -V483 -V483 -V484 -V484 -V484 -V484 -V485 -V485 -V485 -V485 -V486 -V486 -V486 -V486 -V487 -V487 -V487 -V487 -V488 -V488 -V488 -V488 -V489 -V489 -V489 -V489 -V49 -V49 -V49 -V49 -V490 -V490 -V490 -V490 -V491 -V491 -V491 -V491 -V492 -V492 -V492 -V492 -V493 -V493 -V493 -V493 -V494 -V494 -V494 -V494 -V495 -V495 -V495 -V495 -V496 -V496 -V496 -V496 -V497 -V497 -V497 -V497 -V498 -V498 -V498 -V498 -V499 -V499 -V499 -V499 -V5 -V5 -V5 -V5 -V50 -V50 -V50 -V50 -V500 -V500 -V500 -V500 -V51 -V51 -V51 -V51 -V52 -V52 -V52 -V52 -V53 -V53 -V53 -V53 -V54 -V54 -V54 -V54 -V55 -V55 -V55 -V55 -V56 -V56 -V56 -V56 -V57 -V57 -V57 -V57 -V58 -V58 -V58 -V58 -V59 -V59 -V59 -V59 -V6 -V6 -V6 -V6 -V60 -V60 -V60 -V60 -V61 -V61 -V61 -V61 -V62 -V62 -V62 -V62 -V63 -V63 -V63 -V63 -V64 -V64 -V64 -V64 -V65 -V65 -V65 -V65 -V66 -V66 -V66 -V66 -V67 -V67 -V67 -V67 -V68 -V68 -V68 -V68 -V69 -V69 -V69 -V69 -V7 -V7 -V7 -V7 -V70 -V70 -V70 -V70 -V71 -V71 -V71 -V71 -V72 -V72 -V72 -V72 -V73 -V73 -V73 -V73 -V74 -V74 -V74 -V74 -V75 -V75 -V75 -V75 -V76 -V76 -V76 -V76 -V77 -V77 -V77 -V77 -V78 -V78 -V78 -V78 -V79 -V79 -V79 -V79 -V8 -V8 -V8 -V8 -V80 -V80 -V80 -V80 -V81 -V81 -V81 -V81 -V82 -V82 -V82 -V82 -V83 -V83 -V83 -V83 -V84 -V84 -V84 -V84 -V85 -V85 -V85 -V85 -V86 -V86 -V86 -V86 -V87 -V87 -V87 -V87 -V88 -V88 -V88 -V88 -V89 -V89 -V89 -V89 -V9 -V9 -V9 -V9 -V90 -V90 -V90 -V90 -V91 -V91 -V91 -V91 -V92 -V92 -V92 -V92 -V93 -V93 -V93 -V93 -V94 -V94 -V94 -V94 -V95 -V95 -V95 -V95 -V96 -V96 -V96 -V96 -V97 -V97 -V97 -V97 -V98 -V98 -V98 -V98 -V99 -V99 -V99 -V99 +V436 +V436 +V436 +V436 +V437 +V437 +V437 +V437 +V438 +V438 +V438 +V438 +V439 +V439 +V439 +V439 +V44 +V44 +V44 +V44 +V440 +V440 +V440 +V440 +V441 +V441 +V441 +V441 +V442 +V442 +V442 +V442 +V443 +V443 +V443 +V443 +V444 +V444 +V444 +V444 +V445 +V445 +V445 +V445 +V446 +V446 +V446 +V446 +V447 +V447 +V447 +V447 +V448 +V448 +V448 +V448 +V449 +V449 +V449 +V449 +V45 +V45 +V45 +V45 +V450 +V450 +V450 +V450 +V451 +V451 +V451 +V451 +V452 +V452 +V452 +V452 +V453 +V453 +V453 +V453 +V454 +V454 +V454 +V454 +V455 +V455 +V455 +V455 +V456 +V456 +V456 +V456 +V457 +V457 +V457 +V457 +V458 +V458 +V458 +V458 +V459 +V459 +V459 +V459 +V46 +V46 +V46 +V46 +V460 +V460 +V460 +V460 +V461 +V461 +V461 +V461 +V462 +V462 +V462 +V462 +V463 +V463 +V463 +V463 +V464 +V464 +V464 +V464 +V465 +V465 +V465 +V465 +V466 +V466 +V466 +V466 +V467 +V467 +V467 +V467 +V468 +V468 +V468 +V468 +V469 +V469 +V469 +V469 +V47 +V47 +V47 +V47 +V470 +V470 +V470 +V470 +V471 +V471 +V471 +V471 +V472 +V472 +V472 +V472 +V473 +V473 +V473 +V473 +V474 +V474 +V474 +V474 +V475 +V475 +V475 +V475 +V476 +V476 +V476 +V476 +V477 +V477 +V477 +V477 +V478 +V478 +V478 +V478 +V479 +V479 +V479 +V479 +V48 +V48 +V48 +V48 +V480 +V480 +V480 +V480 +V481 +V481 +V481 +V481 +V482 +V482 +V482 +V482 +V483 +V483 +V483 +V483 +V484 +V484 +V484 +V484 +V485 +V485 +V485 +V485 +V486 +V486 +V486 +V486 +V487 +V487 +V487 +V487 +V488 +V488 +V488 +V488 +V489 +V489 +V489 +V489 +V49 +V49 +V49 +V49 +V490 +V490 +V490 +V490 +V491 +V491 +V491 +V491 +V492 +V492 +V492 +V492 +V493 +V493 +V493 +V493 +V494 +V494 +V494 +V494 +V495 +V495 +V495 +V495 +V496 +V496 +V496 +V496 +V497 +V497 +V497 +V497 +V498 +V498 +V498 +V498 +V499 +V499 +V499 +V499 +V5 +V5 +V5 +V5 +V50 +V50 +V50 +V50 +V500 +V500 +V500 +V500 +V51 +V51 +V51 +V51 +V52 +V52 +V52 +V52 +V53 +V53 +V53 +V53 +V54 +V54 +V54 +V54 +V55 +V55 +V55 +V55 +V56 +V56 +V56 +V56 +V57 +V57 +V57 +V57 +V58 +V58 +V58 +V58 +V59 +V59 +V59 +V59 +V6 +V6 +V6 +V6 +V60 +V60 +V60 +V60 +V61 +V61 +V61 +V61 +V62 +V62 +V62 +V62 +V63 +V63 +V63 +V63 +V64 +V64 +V64 +V64 +V65 +V65 +V65 +V65 +V66 +V66 +V66 +V66 +V67 +V67 +V67 +V67 +V68 +V68 +V68 +V68 +V69 +V69 +V69 +V69 +V7 +V7 +V7 +V7 +V70 +V70 +V70 +V70 +V71 +V71 +V71 +V71 +V72 +V72 +V72 +V72 +V73 +V73 +V73 +V73 +V74 +V74 +V74 +V74 +V75 +V75 +V75 +V75 +V76 +V76 +V76 +V76 +V77 +V77 +V77 +V77 +V78 +V78 +V78 +V78 +V79 +V79 +V79 +V79 +V8 +V8 +V8 +V8 +V80 +V80 +V80 +V80 +V81 +V81 +V81 +V81 +V82 +V82 +V82 +V82 +V83 +V83 +V83 +V83 +V84 +V84 +V84 +V84 +V85 +V85 +V85 +V85 +V86 +V86 +V86 +V86 +V87 +V87 +V87 +V87 +V88 +V88 +V88 +V88 +V89 +V89 +V89 +V89 +V9 +V9 +V9 +V9 +V90 +V90 +V90 +V90 +V91 +V91 +V91 +V91 +V92 +V92 +V92 +V92 +V93 +V93 +V93 +V93 +V94 +V94 +V94 +V94 +V95 +V95 +V95 +V95 +V96 +V96 +V96 +V96 +V97 +V97 +V97 +V97 +V98 +V98 +V98 +V98 +V99 +V99 +V99 +V99 diff --git a/tests/testthat/_snaps/speed-layouts/speed-multi-spatial-factors.svg b/tests/testthat/_snaps/speed-layouts/speed-multi-spatial-factors.svg index 7c51ce3d..f123eb22 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-multi-spatial-factors.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-multi-spatial-factors.svg @@ -49,56 +49,56 @@ - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - + + -A + +A A -A -A -A -B -B -B -B -B -C -C -C -C -C -D -D -D -D +A +A +A +B +B +B +B +B +C +C +C +C +C +D +D +D +D D -E -E -E +E E +E E +E diff --git a/tests/testthat/_snaps/speed-layouts/speed-non-uniform.svg b/tests/testthat/_snaps/speed-layouts/speed-non-uniform.svg index 5394d2ef..48509b60 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-non-uniform.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-non-uniform.svg @@ -63,150 +63,150 @@ - - - - - - - - - - - + + + + + + + + + + + - - - - - + + + + + + - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + -A -A -A -A -A -A -A -A -A -A -A + + + + + + +A +A +A +A +A +A +A +A +A +A +A A -A -A -A -A -A +A +A +A +A +A +A A -A +A +A +A +A +A +A +A A -A -A -A -A -A -A -A -B -B -B -B -B -B -B -B -B -C -C -C -C -C -C -C +B +B +B +B +B +B +B +B +B +C C -C -D -D -D -D -D -D -D -D +C +C +C +C +C +C +C D -E -E -E -E -E -E -E -E -E -F -F -F -F -F -F -F -F +D +D +D +D +D +D +D +D +E +E +E +E +E +E +E +E +E +F +F F +F +F +F +F +F +F diff --git a/tests/testthat/_snaps/speed-layouts/speed-partial-rep.svg b/tests/testthat/_snaps/speed-layouts/speed-partial-rep.svg index a57641b5..46784e43 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-partial-rep.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-partial-rep.svg @@ -89,406 +89,406 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -V1 -V10 -V100 -V101 -V102 -V103 -V104 -V105 -V106 -V106 -V107 -V108 -V109 -V11 -V11 -V110 -V111 -V112 -V113 -V114 -V114 -V115 -V116 -V117 -V118 -V119 -V12 -V12 -V120 -V121 -V122 -V122 -V123 -V124 -V125 -V126 -V126 -V127 -V128 -V129 -V13 -V130 -V130 -V131 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +V1 +V10 +V100 +V101 +V102 +V103 +V104 +V105 +V106 +V106 +V107 +V108 +V109 +V11 +V11 +V110 +V111 +V112 +V113 +V114 +V114 +V115 +V116 +V117 +V118 +V119 +V12 +V12 +V120 +V121 +V122 +V122 +V123 +V124 +V125 +V126 +V126 +V127 +V128 +V129 +V13 +V130 +V130 V131 -V132 -V133 -V134 -V135 -V136 -V137 -V138 -V139 -V14 -V140 -V141 -V142 -V143 -V144 -V144 -V145 -V145 -V146 -V146 -V147 -V147 -V148 -V148 -V149 -V149 -V15 -V150 -V150 -V16 -V17 -V18 -V18 -V19 -V19 -V2 -V2 -V20 -V21 -V21 -V22 -V22 -V23 -V23 -V24 -V25 -V26 -V27 -V28 -V28 -V29 -V3 -V3 -V30 -V30 -V31 -V32 -V32 -V33 -V34 -V35 -V36 -V37 -V38 -V39 -V39 -V4 -V40 -V40 -V41 -V41 -V42 -V43 -V44 -V45 -V45 -V46 +V131 +V132 +V133 +V134 +V135 +V136 +V137 +V138 +V139 +V14 +V140 +V141 +V142 +V143 +V144 +V144 +V145 +V145 +V146 +V146 +V147 +V147 +V148 +V148 +V149 +V149 +V15 +V150 +V150 +V16 +V17 +V18 +V18 +V19 +V19 +V2 +V2 +V20 +V21 +V21 +V22 +V22 +V23 +V23 +V24 +V25 +V26 +V27 +V28 +V28 +V29 +V3 +V3 +V30 +V30 +V31 +V32 +V32 +V33 +V34 +V35 +V36 +V37 +V38 +V39 +V39 +V4 +V40 +V40 +V41 +V41 +V42 +V43 +V44 +V45 +V45 +V46 V46 -V47 -V47 -V48 -V49 -V49 -V5 -V5 -V50 -V51 -V52 +V47 +V47 +V48 +V49 +V49 +V5 +V5 +V50 +V51 +V52 V53 -V54 -V54 -V55 -V56 -V57 -V57 -V58 -V59 -V59 -V6 -V6 -V60 -V60 -V61 -V62 -V63 -V63 -V64 -V65 -V66 -V67 -V67 -V68 -V69 -V7 -V7 -V70 -V71 -V72 -V72 -V73 -V74 -V75 -V76 -V77 -V78 -V79 -V79 -V8 -V8 -V80 -V80 -V81 -V82 -V83 -V84 -V85 -V86 -V87 -V88 -V88 -V89 -V89 -V9 -V90 -V91 -V92 -V93 -V93 -V94 -V95 -V96 -V97 -V97 -V98 -V98 -V99 +V54 +V54 +V55 +V56 +V57 +V57 +V58 +V59 +V59 +V6 +V6 +V60 +V60 +V61 +V62 +V63 +V63 +V64 +V65 +V66 +V67 +V67 +V68 +V69 +V7 +V7 +V70 +V71 +V72 +V72 +V73 +V74 +V75 +V76 +V77 +V78 +V79 +V79 +V8 +V8 +V80 +V80 +V81 +V82 +V83 +V84 +V85 +V86 +V87 +V88 +V88 +V89 +V89 +V9 +V90 +V91 +V92 +V93 +V93 +V94 +V95 +V96 +V97 +V97 +V98 +V98 +V99 diff --git a/tests/testthat/_snaps/speed-layouts/speed-rcbd-multi-reps.svg b/tests/testthat/_snaps/speed-layouts/speed-rcbd-multi-reps.svg index 9febdb3e..6bf3673d 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-rcbd-multi-reps.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-rcbd-multi-reps.svg @@ -119,1006 +119,1006 @@ - - - - - - + + + + + + - - - - - + + + + + + - - - + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - + + + - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - + - - + + + + + - - - - + + + + + + + + - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + - - - + - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - -V1 -V1 -V1 -V1 -V1 -V1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +V1 +V1 +V1 +V1 +V1 +V1 V1 -V1 -V1 -V1 -V1 -V1 +V1 +V1 +V1 +V1 +V1 +V1 V1 -V1 -V1 -V1 +V1 +V1 +V1 +V1 V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 V1 -V1 -V1 -V1 -V1 -V1 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V10 V10 -V10 -V10 -V10 +V10 +V10 +V10 V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 V10 -V10 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V2 +V2 +V2 +V2 V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 +V2 +V2 +V2 V2 -V2 -V2 -V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 V2 -V2 -V2 -V3 -V3 -V3 -V3 -V3 -V3 -V3 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V3 +V3 +V3 +V3 V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 +V3 V3 -V3 -V3 +V3 +V3 +V3 +V3 +V3 V3 -V3 -V3 -V3 -V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 V3 -V3 -V3 -V3 -V4 -V4 -V4 -V4 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V4 +V4 V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 +V4 +V4 +V4 V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 V4 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 V5 -V5 -V5 V5 V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 V5 -V5 -V5 -V5 -V5 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 +V5 +V5 +V5 +V6 +V6 +V6 V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 V7 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 +V7 +V7 +V7 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 V8 -V8 -V8 -V8 +V8 V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 +V8 V8 -V8 -V8 -V8 -V8 V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V9 +V9 +V9 +V9 +V9 V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 diff --git a/tests/testthat/_snaps/speed-output.md b/tests/testthat/_snaps/speed-output.md index 1eed1937..e85ab738 100644 --- a/tests/testthat/_snaps/speed-output.md +++ b/tests/testthat/_snaps/speed-output.md @@ -23,7 +23,7 @@ row and col are used as row and column, respectively. Output Optimising level: wp - Level: wp Iteration: 1000 Score: 22 Best: 22 Since Improvement: 480 + Level: wp Iteration: 1000 Score: 22 Best: 22 Since Improvement: 680 Optimising level: sp - Level: sp Iteration: 1000 Score: 1.333333 Best: 1.333333 Since Improvement: 14 + Level: sp Iteration: 1000 Score: 1.333333 Best: 1.333333 Since Improvement: 266 diff --git a/tests/testthat/_snaps/speed-output/autoplot-factor-with-blocks.svg b/tests/testthat/_snaps/speed-output/autoplot-factor-with-blocks.svg index 53f431d9..a460a8a3 100644 --- a/tests/testthat/_snaps/speed-output/autoplot-factor-with-blocks.svg +++ b/tests/testthat/_snaps/speed-output/autoplot-factor-with-blocks.svg @@ -37,54 +37,54 @@ - - - - - - - - + + + + + + - - - - - - - - + + + + + + + + + + - - - - - -A -A -A -B -B -B -C -C + + + + + +A +A +A +B +B +B C -D -D -D -E -E -E -F -F +C +C +D +D +D +E +E +E +F F +F G -G -G -H -H -H +G +G +H +H +H diff --git a/tests/testthat/_snaps/speed-output/autoplot-hierarchical-mixed-factors-sp.svg b/tests/testthat/_snaps/speed-output/autoplot-hierarchical-mixed-factors-sp.svg index 64fe082a..0f01c70d 100644 --- a/tests/testthat/_snaps/speed-output/autoplot-hierarchical-mixed-factors-sp.svg +++ b/tests/testthat/_snaps/speed-output/autoplot-hierarchical-mixed-factors-sp.svg @@ -52,150 +52,150 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - + + - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - + + + + + - - - - - - - - + + + -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPb -SPb + + + + + +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPb SPb -SPb -SPb -SPb +SPb SPb +SPb SPb -SPb -SPb -SPb +SPb SPb +SPb +SPb +SPb +SPb +SPb +SPb SPb -SPb SPb -SPb -SPb SPb -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc +SPb +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc SPd -SPd -SPd -SPd -SPd -SPd +SPd +SPd +SPd +SPd +SPd SPd SPd -SPd -SPd -SPd -SPd -SPd -SPd -SPd -SPd +SPd +SPd +SPd SPd SPd +SPd +SPd +SPd +SPd +SPd diff --git a/tests/testthat/_snaps/speed-output/autoplot-hierarchical-mixed-factors-wp.svg b/tests/testthat/_snaps/speed-output/autoplot-hierarchical-mixed-factors-wp.svg index 1be105c9..f20ea225 100644 --- a/tests/testthat/_snaps/speed-output/autoplot-hierarchical-mixed-factors-wp.svg +++ b/tests/testthat/_snaps/speed-output/autoplot-hierarchical-mixed-factors-wp.svg @@ -52,150 +52,150 @@ - + + + + - + + + + + + - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -WPA + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +WPA +WPA +WPA +WPA WPA WPA -WPA +WPA +WPA +WPA +WPA +WPA +WPA WPA -WPA -WPA -WPA -WPA -WPA WPA -WPA -WPA -WPA -WPA -WPA +WPA +WPA +WPA +WPA +WPA WPA +WPA WPA -WPA -WPA -WPA WPA -WPA -WPA -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC +WPA +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC diff --git a/tests/testthat/_snaps/speed-output/autoplot-hierarchical-no-legend.svg b/tests/testthat/_snaps/speed-output/autoplot-hierarchical-no-legend.svg index 7d3784bd..03c3e266 100644 --- a/tests/testthat/_snaps/speed-output/autoplot-hierarchical-no-legend.svg +++ b/tests/testthat/_snaps/speed-output/autoplot-hierarchical-no-legend.svg @@ -53,10 +53,10 @@ - - - - + + + + @@ -69,18 +69,18 @@ - - - - + + + + A A A A -A -A -A -A +A +A +A +A B B B @@ -93,10 +93,10 @@ C C C -C -C -C -C +C +C +C +C diff --git a/tests/testthat/_snaps/speed-output/autoplot-hierarchical-with-legend.svg b/tests/testthat/_snaps/speed-output/autoplot-hierarchical-with-legend.svg index 44b01e41..546b69f1 100644 --- a/tests/testthat/_snaps/speed-output/autoplot-hierarchical-with-legend.svg +++ b/tests/testthat/_snaps/speed-output/autoplot-hierarchical-with-legend.svg @@ -53,10 +53,10 @@ - - - - + + + + @@ -69,18 +69,18 @@ - - - - + + + + A A A A -A -A -A -A +A +A +A +A B B B @@ -93,10 +93,10 @@ C C C -C -C -C -C +C +C +C +C diff --git a/tests/testthat/_snaps/speed-output/autoplot-no-legend.svg b/tests/testthat/_snaps/speed-output/autoplot-no-legend.svg index 1b082e4b..45141454 100644 --- a/tests/testthat/_snaps/speed-output/autoplot-no-legend.svg +++ b/tests/testthat/_snaps/speed-output/autoplot-no-legend.svg @@ -41,23 +41,23 @@ - - - - - - - - + + + + + + + + -A -A -A -B -B -B -C -C +A +A +A +B +B +B +C +C C diff --git a/tests/testthat/_snaps/speed-output/autoplot-with-legend.svg b/tests/testthat/_snaps/speed-output/autoplot-with-legend.svg index fb27a4b8..d72e618d 100644 --- a/tests/testthat/_snaps/speed-output/autoplot-with-legend.svg +++ b/tests/testthat/_snaps/speed-output/autoplot-with-legend.svg @@ -41,23 +41,23 @@ - - - - - - - - + + + + + + + + -A -A -A -B -B -B -C -C +A +A +A +B +B +B +C +C C diff --git a/tests/testthat/_snaps/speed/speed-blocks.svg b/tests/testthat/_snaps/speed/speed-blocks.svg index 8f1f7003..1c4b3ac9 100644 --- a/tests/testthat/_snaps/speed/speed-blocks.svg +++ b/tests/testthat/_snaps/speed/speed-blocks.svg @@ -47,45 +47,45 @@ - - - + + + - - - + + + - - - - + + + + - - - - - - + + + + + + -A -A -B +A +A +B B -C -C -D +C +C +D D -E -E -F -F +E +E +F +F G -G -H -H -I -I -J +G +H +H +I +I +J J diff --git a/tests/testthat/_snaps/speed/speed-small.svg b/tests/testthat/_snaps/speed/speed-small.svg index c9865e49..cf4e7293 100644 --- a/tests/testthat/_snaps/speed/speed-small.svg +++ b/tests/testthat/_snaps/speed/speed-small.svg @@ -48,45 +48,45 @@ - - - - - - + + + + + + + - - - - - - - - - - - + + + + + + + + + + A -A -A -A -A -B -B +A +A +A +A +B +B +B B -B -B -C -C -C -C -C -D -D -D -D +B +C +C +C +C +C +D +D D +D +D diff --git a/tests/testthat/test-build_design_matrix.R b/tests/testthat/test-build_design_matrix.R index b73fbced..ca81389e 100644 --- a/tests/testthat/test-build_design_matrix.R +++ b/tests/testthat/test-build_design_matrix.R @@ -412,7 +412,7 @@ test_that("a design whose coordinates cannot form a grid still runs when no grid optimise_params = optim_params(adj_weight = 0) ) ) - expect_equal(r$score, 4) + expect_equal(r$score, 3) }) test_that("grid_index() names a missing coordinate column", { diff --git a/tests/testthat/test-speed-hierarchical.R b/tests/testthat/test-speed-hierarchical.R index ae7daa18..640d31d4 100644 --- a/tests/testthat/test-speed-hierarchical.R +++ b/tests/testthat/test-speed-hierarchical.R @@ -21,9 +21,9 @@ test_that("speed handles split plot designs", { ) expect_s3_class(result, "design") - expect_equal(result$score, 100) - expect_equal(result$iterations_run, 1726) - expect_equal(result$stopped_early, c(wp = TRUE, sp = TRUE)) + expect_equal(result$score, 101) + expect_equal(result$iterations_run, 11001) + expect_equal(result$stopped_early, c(wp = TRUE, sp = FALSE)) vdiffr::expect_doppelganger( "speed_splitplot_wp", @@ -97,7 +97,7 @@ test_that("speed handles split-split plot designs", { expect_equal(length(result$scores), 3) expect_equal(sapply(result$scores, length), c(wp = 229, sp = 201, ssp = 1000)) - expect_equal(result$score, 393) + expect_equal(result$score, 403) expect_equal(result$iterations_run, 1430) expect_equal(result$stopped_early, c(wp = TRUE, sp = TRUE, ssp = FALSE)) expect_equal(result$seed, 42) @@ -174,10 +174,10 @@ test_that("speed handles strip plot designs", { expect_equal(nrow(result$design_df), 72) # 16 rows × 9 cols expect_equal(ncol(result$design_df), 6) # All columns preserved expect_equal(length(result$scores), 2) - expect_equal(sapply(result$scores, length), c(ht = 232, vt = 369)) + expect_equal(sapply(result$scores, length), c(ht = 279, vt = 258)) expect_equal(result$score, 138) - expect_equal(result$iterations_run, 601) + expect_equal(result$iterations_run, 537) expect_equal(result$stopped_early, c(ht = TRUE, vt = TRUE)) expect_equal(result$seed, 42) diff --git a/tests/testthat/test-speed-layouts.R b/tests/testthat/test-speed-layouts.R index bcea3752..5ea2ebc2 100644 --- a/tests/testthat/test-speed-layouts.R +++ b/tests/testthat/test-speed-layouts.R @@ -71,7 +71,7 @@ test_that("speed handles non-uniform treatment distributions", { expect_equal(result$stopped_early, TRUE) expect_equal(result$score, 14) - expect_equal(result$iterations_run, 13264) + expect_equal(result$iterations_run, 14965) vdiffr::expect_doppelganger("speed_non_uniform", autoplot(result)) }) @@ -101,7 +101,7 @@ test_that("speed works with a custom objective function", { expect_s3_class(result, "design") expect_equal(result$score, 0) - expect_equal(result$iterations_run, 742) + expect_equal(result$iterations_run, 475) expect_equal(result$stopped_early, TRUE) vdiffr::expect_doppelganger("speed_custom_obj_func", autoplot(result)) diff --git a/tests/testthat/test-speed.R b/tests/testthat/test-speed.R index e4304f21..d3ff80c7 100644 --- a/tests/testthat/test-speed.R +++ b/tests/testthat/test-speed.R @@ -181,6 +181,38 @@ test_that("annealing accepts equal scores at zero temperature", { } }) +test_that("annealing accepts ties without drawing an acceptance probability", { + design <- data.frame( + row = rep(1:2, each = 2), + col = rep(1:2, times = 2), + treatment = LETTERS[1:4] + ) + proposal <- design + proposal$treatment[c(1, 2)] <- proposal$treatment[c(2, 1)] + objective <- function(layout_df, swap, spatial_cols, ...) { + return(list(score = 1)) + } + local_mocked_bindings( + generate_neighbour = function(...) { + return(list(design = proposal, swapped_items = c("A", "B"))) + }, + runif = function(...) { + stop("A tied score should not require an acceptance draw.") + } + ) + + result <- speed( + design, + swap = "treatment", + obj_function = objective, + iterations = 1, + seed = 1, + quiet = TRUE + ) + + expect_identical(as.character(result$design_df$treatment), proposal$treatment) +}) + test_that("speed throws error for missing columns", { test_data <- data.frame( row = rep(1:5, times = 4), From cc81c9052cc2dfe5ddd007bdd282ff56d6bbdf68 Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Fri, 13 Nov 2026 10:43:27 +0800 Subject: [PATCH 21/25] add lower bound param --- R/optim_params.R | 16 ++++++---- R/speed.R | 22 ++++++------- R/verify_utils.R | 10 +++++- man/create_speed_input.Rd | 5 ++- man/optim_params.Rd | 14 ++++++--- man/speed.Rd | 5 ++- man/verify.Rd | 19 ++++++----- tests/testthat/test-design_utils.R | 8 ++--- tests/testthat/test-optim_params.R | 22 ++++++++++--- tests/testthat/test-speed-layouts.R | 1 + tests/testthat/test-speed.R | 49 +++++++++++++++++++++++++++++ 11 files changed, 124 insertions(+), 47 deletions(-) diff --git a/R/optim_params.R b/R/optim_params.R index 2a70f432..cd2a951c 100644 --- a/R/optim_params.R +++ b/R/optim_params.R @@ -22,10 +22,12 @@ #' the best score is used as an initial design (default: 0). #' @param adj_weight Weight for adjacency score (default: 1). #' @param bal_weight Weight for balance score (default: 1). -#' @param stop_at_optimal Logical; if `TRUE`, stops the level as soon as the best score reaches the lowest score -#' its layout allows (default: `TRUE`). The bound is only derivable for the default [objective_function()] -#' with non-negative weights and no `relationship` matrix; otherwise the level runs to its usual stopping -#' rules regardless of this setting. +#' @param stop_at_optimal Logical; if `TRUE`, stops the level when the best score reaches its +#' lower bound (default: `TRUE`). +#' @param lower_bound Optional finite numeric lower bound on the score, overriding the automatically +#' derived bound. `NULL` (default) derives a bound for the default [objective_function()] with +#' non-negative weights and no `relationship` matrix. If no bound is known, only the usual +#' iteration and no-improvement stopping rules apply. #' #' @returns A named list of optimization parameters. #' @@ -41,7 +43,8 @@ optim_params <- function( random_initialisation = 0, adj_weight = 1, bal_weight = 1, - stop_at_optimal = TRUE + stop_at_optimal = TRUE, + lower_bound = NULL ) { params <- list( swap_count = swap_count, @@ -52,7 +55,8 @@ optim_params <- function( random_initialisation = random_initialisation, adj_weight = adj_weight, bal_weight = bal_weight, - stop_at_optimal = stop_at_optimal + stop_at_optimal = stop_at_optimal, + lower_bound = lower_bound ) # check legacy options diff --git a/R/speed.R b/R/speed.R index 3e8cdb9e..6322f42a 100644 --- a/R/speed.R +++ b/R/speed.R @@ -38,9 +38,8 @@ #' with names matching `swap`. #' @param early_stop_iterations Number of iterations without improvement before #' early stopping (default: 2000). For hierarchical designs, can be a named -#' list with names matching `swap`. Optimisation also stops as soon as a level -#' reaches the lowest score its layout allows, which is only applicable for the -#' default [objective_function()]; see [summary()][summary.design()]. +#' list with names matching `swap`. Optimisation can also stop at a known lower +#' bound on the score; see `stop_at_optimal` and `lower_bound` in [optim_params()]. #' @param obj_function Objective function used to calculate score (lower is #' better) (default: [objective_function()]). For hierarchical designs, can #' be a named list with names matching `swap`. @@ -352,7 +351,6 @@ speed_hierarchical <- function(data, optimise, quiet, seed, ...) { adj_weight <- optimise_params$adj_weight bal_weight <- optimise_params$bal_weight stop_at_optimal <- optimise_params$stop_at_optimal - stop_at_zero <- !identical(opt$obj_function, objective_function_info) spatial_cols <- all.vars(opt$spatial_factors) # A level searches from the best design from the previous level @@ -367,9 +365,10 @@ speed_hierarchical <- function(data, optimise, quiet, seed, ...) { stop("`score` from `objective_function` must be numeric.") } - # Lower bound on the score for this level; `NA` when none can be derived - optimal_score <- .optimal_score(current_design, opt$swap, spatial_cols, opt$obj_function, - adj_weight = adj_weight, bal_weight = bal_weight, ...) + # Lower bound on the score for this level; `NA` when none is known + optimal_score <- optimise_params$lower_bound %||% + .optimal_score(current_design, opt$swap, spatial_cols, opt$obj_function, + adj_weight = adj_weight, bal_weight = bal_weight, ...) all_optimal_scores[[level]] <- optimal_score best_score_obj <- current_score_obj @@ -463,14 +462,11 @@ speed_hierarchical <- function(data, optimise, quiet, seed, ...) { "\n") } - # Fisher scores can be negative without reaching an optimum. - reached_zero <- stop_at_zero && new_score < .Machine$double.eps - if (reached_zero || iter - last_improvement_iter >= opt$early_stop_iterations) { + if (iter - last_improvement_iter >= opt$early_stop_iterations) { if (!quiet) { - cat(if (reached_zero) "Optimal score reached at iteration" else "Early stopping at iteration", - iter, "for level", level, "\n") + cat("Early stopping at iteration", iter, "for level", level, "\n") } - stop_reason <- if (reached_zero) "optimal" else "no_improvement" + stop_reason <- "no_improvement" # Record final score and temperature before breaking if (iter < opt$iterations) { scores[iter + 1] <- current_score diff --git a/R/verify_utils.R b/R/verify_utils.R index c665efbb..331a33e6 100644 --- a/R/verify_utils.R +++ b/R/verify_utils.R @@ -373,7 +373,8 @@ random_initialisation, adj_weight, bal_weight, - stop_at_optimal + stop_at_optimal, + lower_bound ) { verify_positive_whole_number(swap_count) verify_non_negative_whole(start_temp) @@ -381,6 +382,13 @@ verify_between(cooling_rate, lower = 0, upper = 1, upper_exclude = TRUE) verify_numeric(adj_weight, bal_weight) + if (!is.null(lower_bound)) { + verify_numeric(lower_bound) + if (is.complex(lower_bound) || !is.finite(lower_bound)) { + stop("`lower_bound` must be a finite real number.", call. = FALSE) + } + } + if (!(random_initialisation %in% c(TRUE, FALSE))) { verify_non_negative_whole(random_initialisation) } diff --git a/man/create_speed_input.Rd b/man/create_speed_input.Rd index 3cb51ecc..4d7b2c9d 100644 --- a/man/create_speed_input.Rd +++ b/man/create_speed_input.Rd @@ -56,9 +56,8 @@ with names matching \code{swap}.} \item{early_stop_iterations}{Number of iterations without improvement before early stopping (default: 2000). For hierarchical designs, can be a named -list with names matching \code{swap}. Optimisation also stops as soon as a level -reaches the lowest score its layout allows, which is only applicable for the -default \code{\link[=objective_function]{objective_function()}}; see \link[=summary.design]{summary()}.} +list with names matching \code{swap}. Optimisation can also stop at a given lower +bound on the score; see \code{stop_at_optimal} and \code{lower_bound} in \code{\link[=optim_params]{optim_params()}}.} \item{obj_function}{Objective function used to calculate score (lower is better) (default: \code{\link[=objective_function]{objective_function()}}). For hierarchical designs, can diff --git a/man/optim_params.Rd b/man/optim_params.Rd index 7d1961d6..e97dd3f2 100644 --- a/man/optim_params.Rd +++ b/man/optim_params.Rd @@ -13,7 +13,8 @@ optim_params( random_initialisation = 0, adj_weight = 1, bal_weight = 1, - stop_at_optimal = TRUE + stop_at_optimal = TRUE, + lower_bound = NULL ) } \arguments{ @@ -43,10 +44,13 @@ the best score is used as an initial design (default: 0).} \item{bal_weight}{Weight for balance score (default: 1).} -\item{stop_at_optimal}{Logical; if \code{TRUE}, stops the level as soon as the best score reaches the lowest score -its layout allows (default: \code{TRUE}). The bound is only derivable for the default \code{\link[=objective_function]{objective_function()}} -with non-negative weights and no \code{relationship} matrix; otherwise the level runs to its usual stopping -rules regardless of this setting.} +\item{stop_at_optimal}{Logical; if \code{TRUE}, stops the level when the best score reaches its +lower bound (default: \code{TRUE}).} + +\item{lower_bound}{Optional finite numeric lower bound on the score, overriding the automatically +derived bound. \code{NULL} (default) derives a bound for the default \code{\link[=objective_function]{objective_function()}} with +non-negative weights and no \code{relationship} matrix. If no bound is known, only the usual +iteration and no-improvement stopping rules apply.} } \value{ A named list of optimization parameters. diff --git a/man/speed.Rd b/man/speed.Rd index 2225109a..e457834f 100644 --- a/man/speed.Rd +++ b/man/speed.Rd @@ -62,9 +62,8 @@ with names matching \code{swap}.} \item{early_stop_iterations}{Number of iterations without improvement before early stopping (default: 2000). For hierarchical designs, can be a named -list with names matching \code{swap}. Optimisation also stops as soon as a level -reaches the lowest score its layout allows, which is only applicable for the -default \code{\link[=objective_function]{objective_function()}}; see \link[=summary.design]{summary()}.} +list with names matching \code{swap}. Optimisation can also stop at a known lower +bound on the score; see \code{stop_at_optimal} and \code{lower_bound} in \code{\link[=optim_params]{optim_params()}}.} \item{obj_function}{Objective function used to calculate score (lower is better) (default: \code{\link[=objective_function]{objective_function()}}). For hierarchical designs, can diff --git a/man/verify.Rd b/man/verify.Rd index 6929fe4c..c3809b68 100644 --- a/man/verify.Rd +++ b/man/verify.Rd @@ -55,7 +55,8 @@ random_initialisation, adj_weight, bal_weight, - stop_at_optimal + stop_at_optimal, + lower_bound ) .verify_grid_factors(grid_factors) @@ -102,9 +103,8 @@ with names matching \code{swap}.} \item{early_stop_iterations}{Number of iterations without improvement before early stopping (default: 2000). For hierarchical designs, can be a named -list with names matching \code{swap}. Optimisation also stops as soon as a level -reaches the lowest score its layout allows, which is only applicable for the -default \code{\link[=objective_function]{objective_function()}}; see \link[=summary.design]{summary()}.} +list with names matching \code{swap}. Optimisation can also stop at a known lower +bound on the score; see \code{stop_at_optimal} and \code{lower_bound} in \code{\link[=optim_params]{optim_params()}}.} \item{obj_function}{Objective function used to calculate score (lower is better) (default: \code{\link[=objective_function]{objective_function()}}). For hierarchical designs, can @@ -143,10 +143,13 @@ the best score is used as an initial design (default: 0).} \item{bal_weight}{Weight for balance score (default: 1).} -\item{stop_at_optimal}{Logical; if \code{TRUE}, stops the level as soon as the best score reaches the lowest score -its layout allows (default: \code{TRUE}). The bound is only derivable for the default \code{\link[=objective_function]{objective_function()}} -with non-negative weights and no \code{relationship} matrix; otherwise the level runs to its usual stopping -rules regardless of this setting.} +\item{stop_at_optimal}{Logical; if \code{TRUE}, stops the level when the best score reaches its +lower bound (default: \code{TRUE}).} + +\item{lower_bound}{Optional finite numeric lower bound on the score, overriding the automatically +derived bound. \code{NULL} (default) derives a bound for the default \code{\link[=objective_function]{objective_function()}} with +non-negative weights and no \code{relationship} matrix. If no bound is known, only the usual +iteration and no-improvement stopping rules apply.} } \description{ Validates the arguments as the user passed them, dispatching to the checker diff --git a/tests/testthat/test-design_utils.R b/tests/testthat/test-design_utils.R index c90055d0..1a7130ca 100644 --- a/tests/testthat/test-design_utils.R +++ b/tests/testthat/test-design_utils.R @@ -427,7 +427,7 @@ test_that("speed() records why each level stopped", { ) }) -test_that("speed() calls a score of zero optimal without a derived lower bound", { +test_that("speed() calls a score of zero optimal with a supplied lower bound", { df <- data.frame( row = rep(1:4, times = 5), col = rep(1:5, each = 4), @@ -435,8 +435,7 @@ test_that("speed() calls a score of zero optimal without a derived lower bound", stringsAsFactors = FALSE ) - # A custom objective, so no lower bound can be derived and `optimal_score` is - # `NA`. Reaching zero is still optimal rather than merely out of improvements. + # A custom objective, so its known lower bound must be supplied. obj_runs <- function(layout_df, swap, spatial_cols, ...) { trt <- as.character(layout_df[[swap]]) return(list(score = as.numeric(sum(trt[-1] == trt[-length(trt)])))) @@ -446,13 +445,14 @@ test_that("speed() calls a score of zero optimal without a derived lower bound", df, swap = "treatment", obj_function = obj_runs, + optimise_params = optim_params(lower_bound = 0), iterations = 5000, seed = 3, quiet = TRUE ) expect_equal(result$score, 0) - expect_true(is.na(result$metadata$per_level[[1]]$optimal_score)) + expect_equal(result$metadata$per_level[[1]]$optimal_score, 0) expect_equal(result$metadata$per_level[[1]]$stop_reason, "optimal") }) diff --git a/tests/testthat/test-optim_params.R b/tests/testthat/test-optim_params.R index 16f4eca9..6c72a863 100644 --- a/tests/testthat/test-optim_params.R +++ b/tests/testthat/test-optim_params.R @@ -8,7 +8,8 @@ test_that("optim_params works with no arguments", { "random_initialisation", "adj_weight", "bal_weight", - "stop_at_optimal" + "stop_at_optimal", + "lower_bound" ) optimize_params <- optim_params() @@ -27,7 +28,8 @@ test_that("optim_params works with arguments", { "random_initialisation", "adj_weight", "bal_weight", - "stop_at_optimal" + "stop_at_optimal", + "lower_bound" ) optimize_params <- optim_params(swap_count = 2) @@ -57,7 +59,8 @@ test_that("optim_params works with arguments", { random_initialisation = 3, adj_weight = 2, bal_weight = 3, - stop_at_optimal = FALSE + stop_at_optimal = FALSE, + lower_bound = -10 ) optimize_params <- do.call(optim_params, optimize_params_expected) @@ -77,7 +80,8 @@ test_that("optim_params works with legacy options", { "random_initialisation", "adj_weight", "bal_weight", - "stop_at_optimal" + "stop_at_optimal", + "lower_bound" ) withr::with_options( @@ -151,3 +155,13 @@ test_that("optim_params throws error for invalid inputs", { expect_error(optim_params(stop_at_optimal = "TRUE")) expect_error(optim_params(stop_at_optimal = 1)) }) + +test_that("optim_params validates lower_bound", { + expect_null(optim_params()$lower_bound) + for (bound in c(-1, 0, 1)) { + expect_identical(optim_params(lower_bound = bound)$lower_bound, bound) + } + for (bound in list("0", TRUE, numeric(0), c(0, 1), NA_real_, NaN, Inf, -Inf, 1i)) { + expect_error(optim_params(lower_bound = bound), "`lower_bound`") + } +}) diff --git a/tests/testthat/test-speed-layouts.R b/tests/testthat/test-speed-layouts.R index 5ea2ebc2..1d4f9291 100644 --- a/tests/testthat/test-speed-layouts.R +++ b/tests/testthat/test-speed-layouts.R @@ -94,6 +94,7 @@ test_that("speed works with a custom objective function", { swap = "treatment", spatial_factors = ~ row + col, obj_function = custom_obj_function(), + optimise_params = optim_params(lower_bound = 0), iterations = 1000, seed = 42, quiet = TRUE diff --git a/tests/testthat/test-speed.R b/tests/testthat/test-speed.R index d3ff80c7..f7948571 100644 --- a/tests/testthat/test-speed.R +++ b/tests/testthat/test-speed.R @@ -356,6 +356,55 @@ test_that("speed keeps running when stop_at_optimal is FALSE", { expect_equal(result$iterations_run, 500) }) +test_that("speed uses supplied lower bounds and respects stop_at_optimal", { + test_data <- expand.grid(row = 1:2, col = 1:2) + test_data$treatment <- LETTERS[1:4] + + for (value in c(-1, 0)) { + objective <- function(layout_df, swap, spatial_cols, ...) { + return(list(score = value)) + } + for (bound in list(NULL, value - 1, value)) { + for (stop_at_optimal in c(TRUE, FALSE)) { + result <- speed( + test_data, + swap = "treatment", + obj_function = objective, + optimise_params = optim_params(lower_bound = bound, stop_at_optimal = stop_at_optimal), + iterations = 5, + early_stop_iterations = 10, + seed = 1, + quiet = TRUE + ) + + reached_bound <- stop_at_optimal && !is.null(bound) && bound == value + expect_equal(result$iterations_run, if (reached_bound) 1 else 5) + expect_equal(result$metadata$per_level[[1]]$optimal_score, bound %||% NA_real_) + expect_identical(result$metadata$per_level[[1]]$stop_reason, + if (reached_bound) "optimal" else "iterations") + } + } + } +}) + +test_that("a supplied lower bound overrides the derived bound", { + test_data <- expand.grid(row = 1:5, col = 1:4) + test_data$treatment <- LETTERS[1:4] + + result <- speed( + test_data, + swap = "treatment", + optimise_params = optim_params(lower_bound = 0), + iterations = 5, + seed = 1, + quiet = TRUE + ) + + expect_equal(result$metadata$per_level[[1]]$optimal_score, 0) + expect_equal(result$iterations_run, 5) + expect_false(result$stopped_early) +}) + test_that("speed keeps running when the optimal score is out of reach", { # having high rep for 1 treatment makes optimal score out of reach test_data <- expand.grid(row = 1:3, col = 1:4) From 08189b59a39e528e78841cfd7f0b4f8dc7b558d1 Mon Sep 17 00:00:00 2001 From: Kai Bagley Date: Fri, 13 Nov 2026 11:47:15 +0800 Subject: [PATCH 22/25] fix scaling in estimability and nuisance projections --- R/objective_fisher.R | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/R/objective_fisher.R b/R/objective_fisher.R index 08f9a68e..ed3bbf7a 100644 --- a/R/objective_fisher.R +++ b/R/objective_fisher.R @@ -360,9 +360,13 @@ factorial_contrast_matrix <- function( contrasts <- .prepare_contrast_matrix(contrast_matrix, trt_levels, tolerance) projection <- info_inverse %*% info - residual <- contrasts - contrasts %*% projection - estimable <- nrow(contrasts) == 0L || - max(abs(residual)) <= tolerance * (1 + max(abs(contrasts))) + estimable <- TRUE + if (nrow(contrasts) > 0L) { + # Contrast weights affect the score, but not estimability. + scaled_contrasts <- sweep(contrasts, 1L, apply(abs(contrasts), 1L, max), "/") + residual <- scaled_contrasts - scaled_contrasts %*% projection + estimable <- max(abs(residual)) <= tolerance + } contrast_covariance <- matrix(numeric(0), nrow = 0L, ncol = 0L) A_value <- Inf @@ -426,13 +430,22 @@ factorial_contrast_matrix <- function( return(stats::model.matrix(nuisance_formula, layout_df)) } +#' Invert nuisance information independently of covariate and covariance scale +#' @noRd +.fisher_nuisance_inverse <- function(info, tolerance) { + scales <- sqrt(diag(info)) + scales[scales == 0] <- 1 + scale_matrix <- outer(scales, scales) + return(pseudo_inverse(info / scale_matrix, tolerance) / scale_matrix) +} + #' Build a projection under identity covariance #' @noRd .build_L_from_df <- function( layout_df, block_column, n, nuisance_formula = NULL, tolerance = 1e-10 ) { X2 <- .build_nuisance_matrix(layout_df, block_column, nuisance_formula) - crossprod_inverse <- pseudo_inverse(crossprod(X2), tolerance) + crossprod_inverse <- .fisher_nuisance_inverse(crossprod(X2), tolerance) return(diag(n) - X2 %*% crossprod_inverse %*% t(X2)) } @@ -674,7 +687,7 @@ compute_L_projection <- function( Sigma_inv <- solve(Sigma) SiX2 <- Sigma_inv %*% X2 - nuisance_inverse <- pseudo_inverse(crossprod(X2, SiX2), tolerance) + nuisance_inverse <- .fisher_nuisance_inverse(crossprod(X2, SiX2), tolerance) L <- Sigma_inv - SiX2 %*% nuisance_inverse %*% t(SiX2) return((L + t(L)) / 2) } From 16233688ad6fb19f5a0fb2ff82c2a2653f633326 Mon Sep 17 00:00:00 2001 From: Wasin Pipattungsakul Date: Tue, 17 Nov 2026 11:06:24 +1030 Subject: [PATCH 23/25] fix: retain rng pull sequence --- R/speed.R | 3 +- man/create_speed_input.Rd | 2 +- man/objective_function_info.Rd | 10 +- .../buffers/buffers-colourblind-palette.svg | 28 +- .../_snaps/buffers/buffers-no-margin.svg | 28 +- .../_snaps/buffers/buffers-plasma-palette.svg | 28 +- .../_snaps/buffers/buffers-rotated-text.svg | 28 +- .../buffers/buffers-with-legend-display.svg | 28 +- .../_snaps/buffers/buffers-with-margin.svg | 28 +- .../speed-optimised-column-buffers.svg | 32 +- .../buffers/speed-optimised-edge-buffers.svg | 32 +- .../buffers/speed-optimised-row-buffers.svg | 32 +- .../autoplot-blocked-margin-false.svg | 48 +- .../plotting/autoplot-blocked-margin-true.svg | 48 +- .../plotting/autoplot-blocks-inferno.svg | 48 +- .../plotting/autoplot-blocks-paired.svg | 48 +- .../_snaps/plotting/autoplot-custom-hex.svg | 28 +- .../_snaps/plotting/autoplot-custom-mixed.svg | 28 +- .../_snaps/plotting/autoplot-custom-rgb.svg | 28 +- .../autoplot-hierarchical-plasma-wp.svg | 64 +- .../autoplot-hierarchical-set3-sp.svg | 64 +- .../autoplot-palette-large-treatments.svg | 112 +- .../speed-split-split-ssp.svg | 492 +- .../speed-hierarchical/speed-splitplot-sp.svg | 156 +- .../speed-hierarchical/speed-splitplot-wp.svg | 192 +- .../speed-hierarchical/speed-strip-ht.svg | 216 +- .../speed-hierarchical/speed-strip-vt.svg | 240 +- tests/testthat/_snaps/speed-layouts.md | 484 +- .../speed-layouts/speed-custom-obj-func.svg | 48 +- .../speed-layouts/speed-large-blocks.svg | 980 +- .../_snaps/speed-layouts/speed-large-grid.svg | 1488 +-- .../speed-large-missing-clump.svg | 1440 +-- .../speed-layouts/speed-large-missing-l.svg | 1092 +-- .../speed-layouts/speed-large-missing.svg | 1312 +-- .../_snaps/speed-layouts/speed-large-rcbd.svg | 7974 ++++++++--------- .../speed-multi-spatial-factors.svg | 84 +- .../speed-layouts/speed-non-uniform.svg | 264 +- .../speed-layouts/speed-partial-rep.svg | 788 +- .../speed-layouts/speed-rcbd-multi-reps.svg | 1868 ++-- tests/testthat/_snaps/speed-output.md | 4 +- .../autoplot-factor-with-blocks.svg | 84 +- ...autoplot-hierarchical-mixed-factors-sp.svg | 240 +- ...autoplot-hierarchical-mixed-factors-wp.svg | 260 +- .../autoplot-hierarchical-no-legend.svg | 32 +- .../autoplot-hierarchical-with-legend.svg | 32 +- .../speed-output/autoplot-no-legend.svg | 32 +- .../speed-output/autoplot-with-legend.svg | 32 +- tests/testthat/_snaps/speed/speed-blocks.svg | 64 +- tests/testthat/_snaps/speed/speed-small.svg | 68 +- tests/testthat/test-build_design_matrix.R | 2 +- tests/testthat/test-speed-hierarchical.R | 12 +- tests/testthat/test-speed-layouts.R | 4 +- tests/testthat/test-speed.R | 32 - 53 files changed, 10391 insertions(+), 10420 deletions(-) diff --git a/R/speed.R b/R/speed.R index dd212547..7f7a83f5 100644 --- a/R/speed.R +++ b/R/speed.R @@ -441,7 +441,8 @@ speed_hierarchical <- function(data, optimise, quiet, seed, ...) { # Decide whether to accept the new design delta <- if (new_score == current_score) 0 else new_score - current_score - if (delta <= 0 || runif(1) < exp(-delta / temp)) { + accept_prob <- if (delta == 0) 1 else exp(-delta / temp) + if (delta < 0 || runif(1) < accept_prob) { current_design <- new_design$design current_score <- new_score current_score_obj <- new_score_obj diff --git a/man/create_speed_input.Rd b/man/create_speed_input.Rd index 4f076908..112a3e4d 100644 --- a/man/create_speed_input.Rd +++ b/man/create_speed_input.Rd @@ -58,7 +58,7 @@ with names matching \code{swap}.} \item{early_stop_iterations}{Number of iterations without improvement before early stopping (default: 2000). For hierarchical designs, can be a named -list with names matching \code{swap}. Optimisation can also stop at a given lower +list with names matching \code{swap}. Optimisation can also stop at a known lower bound on the score; see \code{stop_at_optimal} and \code{lower_bound} in \code{\link[=optim_params]{optim_params()}}.} \item{obj_function}{Objective function used to calculate score (lower is diff --git a/man/objective_function_info.Rd b/man/objective_function_info.Rd index e23e54be..c82f46f4 100644 --- a/man/objective_function_info.Rd +++ b/man/objective_function_info.Rd @@ -34,10 +34,12 @@ experiment.} \item{criterion}{Either \code{"A"} or \code{"D"}, representing A or D optimality. -- A-optimality: Minimises \eqn{\mathrm{tr} \left( \mathcal{I}^- - \right)}{tr(I⁻)}. - - D-optimality: Minimises \eqn{-\log \left| \mathcal{I} \right|}{- - log(|I|)}} +\itemize{ +\item A-optimality: Minimises \eqn{\mathrm{tr} \left( \mathcal{I}^- + \right)}{tr(I⁻)}. +\item D-optimality: Minimises \eqn{-\log \left| \mathcal{I} \right|}{- + log(|I|)} +}} \item{L_matrix}{Optional precomputed projection matrix in grid order, as returned by \code{\link[=compute_L_projection]{compute_L_projection()}}. Cannot be supplied with \code{Sigma}.} diff --git a/tests/testthat/_snaps/buffers/buffers-colourblind-palette.svg b/tests/testthat/_snaps/buffers/buffers-colourblind-palette.svg index 5e76c86a..47461111 100644 --- a/tests/testthat/_snaps/buffers/buffers-colourblind-palette.svg +++ b/tests/testthat/_snaps/buffers/buffers-colourblind-palette.svg @@ -49,15 +49,15 @@ - - - - - - - + + + + + + + @@ -74,15 +74,15 @@ -A A -A -B -B -B -C -C +A +A +B +B +B +C C +C diff --git a/tests/testthat/_snaps/buffers/buffers-no-margin.svg b/tests/testthat/_snaps/buffers/buffers-no-margin.svg index f4bdb6dd..8a27cc3d 100644 --- a/tests/testthat/_snaps/buffers/buffers-no-margin.svg +++ b/tests/testthat/_snaps/buffers/buffers-no-margin.svg @@ -49,15 +49,15 @@ - - - - - - - + + + + + + + @@ -74,15 +74,15 @@ -A A -A -B -B -B -C -C +A +A +B +B +B +C C +C diff --git a/tests/testthat/_snaps/buffers/buffers-plasma-palette.svg b/tests/testthat/_snaps/buffers/buffers-plasma-palette.svg index d0e3835b..e36927bb 100644 --- a/tests/testthat/_snaps/buffers/buffers-plasma-palette.svg +++ b/tests/testthat/_snaps/buffers/buffers-plasma-palette.svg @@ -49,15 +49,15 @@ - - - - - - - + + + + + + + @@ -74,15 +74,15 @@ -A A -A -B -B -B -C -C +A +A +B +B +B +C C +C diff --git a/tests/testthat/_snaps/buffers/buffers-rotated-text.svg b/tests/testthat/_snaps/buffers/buffers-rotated-text.svg index 4dc673a8..0d97a333 100644 --- a/tests/testthat/_snaps/buffers/buffers-rotated-text.svg +++ b/tests/testthat/_snaps/buffers/buffers-rotated-text.svg @@ -49,15 +49,15 @@ - - - - - - - + + + + + + + @@ -74,15 +74,15 @@ -A A -A -B -B -B -C -C +A +A +B +B +B +C C +C diff --git a/tests/testthat/_snaps/buffers/buffers-with-legend-display.svg b/tests/testthat/_snaps/buffers/buffers-with-legend-display.svg index 747de30e..737dab89 100644 --- a/tests/testthat/_snaps/buffers/buffers-with-legend-display.svg +++ b/tests/testthat/_snaps/buffers/buffers-with-legend-display.svg @@ -49,15 +49,15 @@ - - - - - - - + + + + + + + @@ -74,15 +74,15 @@ -A A -A -B -B -B -C -C +A +A +B +B +B +C C +C diff --git a/tests/testthat/_snaps/buffers/buffers-with-margin.svg b/tests/testthat/_snaps/buffers/buffers-with-margin.svg index 13bc6e68..9fe7d2e0 100644 --- a/tests/testthat/_snaps/buffers/buffers-with-margin.svg +++ b/tests/testthat/_snaps/buffers/buffers-with-margin.svg @@ -49,15 +49,15 @@ - - - - - - - + + + + + + + @@ -74,15 +74,15 @@ -A A -A -B -B -B -C -C +A +A +B +B +B +C C +C diff --git a/tests/testthat/_snaps/buffers/speed-optimised-column-buffers.svg b/tests/testthat/_snaps/buffers/speed-optimised-column-buffers.svg index e926e59e..6638dab8 100644 --- a/tests/testthat/_snaps/buffers/speed-optimised-column-buffers.svg +++ b/tests/testthat/_snaps/buffers/speed-optimised-column-buffers.svg @@ -49,14 +49,14 @@ - - - - - - - - + + + + + + + + @@ -70,14 +70,14 @@ -A -A -A -B -B -B -C -C +A +A +A +B +B +B +C +C C diff --git a/tests/testthat/_snaps/buffers/speed-optimised-edge-buffers.svg b/tests/testthat/_snaps/buffers/speed-optimised-edge-buffers.svg index 303e37d5..e00c91b8 100644 --- a/tests/testthat/_snaps/buffers/speed-optimised-edge-buffers.svg +++ b/tests/testthat/_snaps/buffers/speed-optimised-edge-buffers.svg @@ -49,14 +49,14 @@ - - - - - - - - + + + + + + + + @@ -74,14 +74,14 @@ -A -A -A -B -B -B -C -C +A +A +A +B +B +B +C +C C diff --git a/tests/testthat/_snaps/buffers/speed-optimised-row-buffers.svg b/tests/testthat/_snaps/buffers/speed-optimised-row-buffers.svg index 88634c87..3ece4b05 100644 --- a/tests/testthat/_snaps/buffers/speed-optimised-row-buffers.svg +++ b/tests/testthat/_snaps/buffers/speed-optimised-row-buffers.svg @@ -49,14 +49,14 @@ - - - - - - - - + + + + + + + + @@ -70,14 +70,14 @@ -A -A -A -B -B -B -C -C +A +A +A +B +B +B +C +C C diff --git a/tests/testthat/_snaps/plotting/autoplot-blocked-margin-false.svg b/tests/testthat/_snaps/plotting/autoplot-blocked-margin-false.svg index 62e87528..5eac9a1c 100644 --- a/tests/testthat/_snaps/plotting/autoplot-blocked-margin-false.svg +++ b/tests/testthat/_snaps/plotting/autoplot-blocked-margin-false.svg @@ -49,52 +49,52 @@ - - + + + + - - - + + + - - - - + + - + - - + + -A A -A +A A +A B +B +B B -B -B -C +C +C +C C -C -C -D -D +D D +D D -E E +E E E -F -F +F +F F F diff --git a/tests/testthat/_snaps/plotting/autoplot-blocked-margin-true.svg b/tests/testthat/_snaps/plotting/autoplot-blocked-margin-true.svg index a1b8ebab..f18e5679 100644 --- a/tests/testthat/_snaps/plotting/autoplot-blocked-margin-true.svg +++ b/tests/testthat/_snaps/plotting/autoplot-blocked-margin-true.svg @@ -49,52 +49,52 @@ - - + + + + - - - + + + - - - - + + - + - - + + -A A -A +A A +A B +B +B B -B -B -C +C +C +C C -C -C -D -D +D D +D D -E E +E E E -F -F +F +F F F diff --git a/tests/testthat/_snaps/plotting/autoplot-blocks-inferno.svg b/tests/testthat/_snaps/plotting/autoplot-blocks-inferno.svg index d1139aae..75334ad2 100644 --- a/tests/testthat/_snaps/plotting/autoplot-blocks-inferno.svg +++ b/tests/testthat/_snaps/plotting/autoplot-blocks-inferno.svg @@ -49,52 +49,52 @@ - - + + + + - - - + + + - - - - + + - + - - + + -A A -A +A A +A B +B +B B -B -B -C +C +C +C C -C -C -D -D +D D +D D -E E +E E E -F -F +F +F F F diff --git a/tests/testthat/_snaps/plotting/autoplot-blocks-paired.svg b/tests/testthat/_snaps/plotting/autoplot-blocks-paired.svg index 2ed7040a..c6c37275 100644 --- a/tests/testthat/_snaps/plotting/autoplot-blocks-paired.svg +++ b/tests/testthat/_snaps/plotting/autoplot-blocks-paired.svg @@ -49,52 +49,52 @@ - - + + + + - - - + + + - - - - + + - + - - + + -A A -A +A A +A B +B +B B -B -B -C +C +C +C C -C -C -D -D +D D +D D -E E +E E E -F -F +F +F F F diff --git a/tests/testthat/_snaps/plotting/autoplot-custom-hex.svg b/tests/testthat/_snaps/plotting/autoplot-custom-hex.svg index c6258525..56d92846 100644 --- a/tests/testthat/_snaps/plotting/autoplot-custom-hex.svg +++ b/tests/testthat/_snaps/plotting/autoplot-custom-hex.svg @@ -41,24 +41,24 @@ - - + - - + - - - -A -A + + + + + +A A -B -B +A B -C -C -C +B +B +C +C +C diff --git a/tests/testthat/_snaps/plotting/autoplot-custom-mixed.svg b/tests/testthat/_snaps/plotting/autoplot-custom-mixed.svg index 665e9693..87583d95 100644 --- a/tests/testthat/_snaps/plotting/autoplot-custom-mixed.svg +++ b/tests/testthat/_snaps/plotting/autoplot-custom-mixed.svg @@ -41,24 +41,24 @@ - - + - - + - - - -A -A + + + + + +A A -B -B +A B -C -C -C +B +B +C +C +C diff --git a/tests/testthat/_snaps/plotting/autoplot-custom-rgb.svg b/tests/testthat/_snaps/plotting/autoplot-custom-rgb.svg index faafd238..25b7b6bd 100644 --- a/tests/testthat/_snaps/plotting/autoplot-custom-rgb.svg +++ b/tests/testthat/_snaps/plotting/autoplot-custom-rgb.svg @@ -41,24 +41,24 @@ - - + - - + - - - -A -A + + + + + +A A -B -B +A B -C -C -C +B +B +C +C +C diff --git a/tests/testthat/_snaps/plotting/autoplot-hierarchical-plasma-wp.svg b/tests/testthat/_snaps/plotting/autoplot-hierarchical-plasma-wp.svg index 95be8504..048ae649 100644 --- a/tests/testthat/_snaps/plotting/autoplot-hierarchical-plasma-wp.svg +++ b/tests/testthat/_snaps/plotting/autoplot-hierarchical-plasma-wp.svg @@ -49,50 +49,50 @@ - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + -A -A -A -A -A -A -A -A +A +A +A +A +A +A +A +A B B B B -B -B -B -B -C -C -C -C +B +B +B +B +C +C +C +C C C C diff --git a/tests/testthat/_snaps/plotting/autoplot-hierarchical-set3-sp.svg b/tests/testthat/_snaps/plotting/autoplot-hierarchical-set3-sp.svg index b557ff3a..fb86213c 100644 --- a/tests/testthat/_snaps/plotting/autoplot-hierarchical-set3-sp.svg +++ b/tests/testthat/_snaps/plotting/autoplot-hierarchical-set3-sp.svg @@ -52,51 +52,51 @@ - - - - + + + - - - - + + + + + - - + + - - - + + - - - + + + + a a a -a -a -a -b +a +a +a b -b -b -b -b +b +b +b +b +b c -c -c +c +c c -c -c -d +c +c d -d -d -d +d +d +d d +d diff --git a/tests/testthat/_snaps/plotting/autoplot-palette-large-treatments.svg b/tests/testthat/_snaps/plotting/autoplot-palette-large-treatments.svg index e52eb45e..7a6cabfe 100644 --- a/tests/testthat/_snaps/plotting/autoplot-palette-large-treatments.svg +++ b/tests/testthat/_snaps/plotting/autoplot-palette-large-treatments.svg @@ -53,70 +53,70 @@ - - - - - - - + + + + - - - - + + + + + + + + + - - - + - - - - - - - - - - + + + + + + + + + + - - - - -A -A -A -A -B -B -B + + + + +A +A +A +A B -C -C -C -C +B +B +B +C +C +C +C +D +D D -D -D -D +D E -E -E -E -F -F -F -F -G -G -G +E +E +E +F +F +F +F +G +G +G G -H -H -H -H +H +H +H +H diff --git a/tests/testthat/_snaps/speed-hierarchical/speed-split-split-ssp.svg b/tests/testthat/_snaps/speed-hierarchical/speed-split-split-ssp.svg index a1c47272..595d6d1e 100644 --- a/tests/testthat/_snaps/speed-hierarchical/speed-split-split-ssp.svg +++ b/tests/testthat/_snaps/speed-hierarchical/speed-split-split-ssp.svg @@ -79,294 +79,294 @@ - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - + + + - - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + - - - - - - - - - - - - - - - - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - - - - - - - - - - - - - - - - + + + + + - - - - - - - - + + - - - + + + + - - + - - - + + - - - + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + - - -x -x -x -x -x -x -x -x + + +x +x +x +x +x +x x +x +x +x +x x +x +x +x +x +x +x x -x -x -x -x -x x -x -x -x -x -x -x -x -x -x -x +x +x x x -x -x -x -x -x -x -x -x -x -x -x -x -x -x -x +x +x +x x -x -x +x x -y -y -y -y -y -y -y -y -y -y -y -y -y -y -y +x +x +x +x +x +x +x +x +x +x +x +x +x +x +x +x +x +x +y +y +y +y +y +y y -y +y +y +y +y +y y -y -y -y -y -y -y -y -y -y -y -y -y -y -y -y -y +y y -y -y -y +y +y +y +y +y +y +y +y +y +y +y +y +y +y +y +y +y +y +y +y +y +y +y +y +y y -y -y -y +y +y +y y -y -y -y -y -y -z -z -z -z -z -z -z -z -z -z -z -z -z +y +y +y +z +z z -z -z -z -z -z -z -z -z +z +z z -z -z -z +z +z +z +z z -z -z +z z z -z -z -z +z +z z -z -z -z +z +z +z +z +z +z +z +z +z +z +z +z +z +z +z +z +z +z z -z -z -z -z -z -z +z +z +z +z +z +z +z +z +z z -z -z +z +z diff --git a/tests/testthat/_snaps/speed-hierarchical/speed-splitplot-sp.svg b/tests/testthat/_snaps/speed-hierarchical/speed-splitplot-sp.svg index 336f26a5..58a68303 100644 --- a/tests/testthat/_snaps/speed-hierarchical/speed-splitplot-sp.svg +++ b/tests/testthat/_snaps/speed-hierarchical/speed-splitplot-sp.svg @@ -61,102 +61,102 @@ - - - + + - - + + + + + + + + - - - - - - + + + + + + + + + + - - - - - - - - - - - + + + + + - - - + + - - - - - - - - - + + + + + + + - + + - - - - -a -a -a + + + +a +a a -a -a +a +a +a +a +a +a +a +a a -a -a -a -a -a -b +b +b +b +b +b +b +b +b +b +b b -b -b -b b -b -b -b -b -b -b -c c -c +c +c +c +c +c c -c -c -c +c +c c -c -c -c -c -d -d -d -d -d +c +c +d +d +d +d +d d -d +d +d d -d -d -d -d +d +d +d diff --git a/tests/testthat/_snaps/speed-hierarchical/speed-splitplot-wp.svg b/tests/testthat/_snaps/speed-hierarchical/speed-splitplot-wp.svg index b3780dc9..8587958b 100644 --- a/tests/testthat/_snaps/speed-hierarchical/speed-splitplot-wp.svg +++ b/tests/testthat/_snaps/speed-hierarchical/speed-splitplot-wp.svg @@ -61,102 +61,102 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C diff --git a/tests/testthat/_snaps/speed-hierarchical/speed-strip-ht.svg b/tests/testthat/_snaps/speed-hierarchical/speed-strip-ht.svg index 3d33b7a7..a029ec27 100644 --- a/tests/testthat/_snaps/speed-hierarchical/speed-strip-ht.svg +++ b/tests/testthat/_snaps/speed-hierarchical/speed-strip-ht.svg @@ -65,150 +65,150 @@ - - - - - - - - - - - - - - - - + + + + + - + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + - - - - - - - - - - - + - - - + - - - - - - + - + + + + + + + + + + + + + - - - + + - - - + + + - - - - + + -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a -a + + +a +a +a +a +a a -a +a +a +a +a +a +a +a +a +a +a +a +a b b b +b +b +b +b +b +b +b b -b -b -b -b -b -b +b +b +b +b +b b -b -b -b -b b -b -b -c -c -c -c -c +c c -c -c -c +c c -c -c -c -c -c -c +c c -c +c +c +c +c +c +c +c +c +c +c +c +c +d d d -d d d -d -d +d d +d d -d -d -d +d +d +d d -d -d -d -d +d +d d +d +d diff --git a/tests/testthat/_snaps/speed-hierarchical/speed-strip-vt.svg b/tests/testthat/_snaps/speed-hierarchical/speed-strip-vt.svg index 1517967d..25b24893 100644 --- a/tests/testthat/_snaps/speed-hierarchical/speed-strip-vt.svg +++ b/tests/testthat/_snaps/speed-hierarchical/speed-strip-vt.svg @@ -65,150 +65,150 @@ - - - - - - + - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + - + - - - - - + - - - - - - + - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + + - + + - - -A -A -A -A -A -A + + + +A A -A -A -A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A A -A -A -A -A -A -A A -A -A -A -A -A -A -B -B -B -B -B -B -B +A +A +A +A +B +B +B +B +B B -B +B B -B -B -B -B -B +B B -B B -B -B -B -B -B +B B -C -C -C -C -C -C -C -C -C -C -C -C +B +B +B +B +B +B +B +B +B +B +B +C +C C -C -C -C -C -C +C C +C +C +C +C +C +C +C +C +C +C +C +C C -C +C +C C -C -C +C +C +C diff --git a/tests/testthat/_snaps/speed-layouts.md b/tests/testthat/_snaps/speed-layouts.md index 4df09564..d0abc94d 100644 --- a/tests/testthat/_snaps/speed-layouts.md +++ b/tests/testthat/_snaps/speed-layouts.md @@ -4,260 +4,260 @@ result$design_df Output row col block treatment - 1 1 1 1 P - 2 1 2 1 A - 3 1 3 1 B - 4 1 4 1 I - 5 1 5 1 J + 1 1 1 1 L + 2 1 2 1 N + 3 1 3 1 P + 4 1 4 1 B + 5 1 5 1 C 6 1 6 1 G - 7 1 7 1 L - 8 1 8 1 F - 9 1 9 1 A - 10 1 10 1 H - 11 1 11 1 O - 12 1 12 1 N - 13 1 13 1 C - 14 1 14 1 K - 15 1 15 1 M - 16 1 16 1 D - 17 2 1 1 D - 18 2 2 1 N + 7 1 7 1 E + 8 1 8 1 M + 9 1 9 1 O + 10 1 10 1 I + 11 1 11 1 H + 12 1 12 1 K + 13 1 13 1 F + 14 1 14 1 D + 15 1 15 1 A + 16 1 16 1 J + 17 2 1 1 O + 18 2 2 1 C 19 2 3 1 F - 20 2 4 1 K - 21 2 5 1 D - 22 2 6 1 I - 23 2 7 1 J - 24 2 8 1 L - 25 2 9 1 O - 26 2 10 1 G - 27 2 11 1 E - 28 2 12 1 C - 29 2 13 1 B - 30 2 14 1 M - 31 2 15 1 P - 32 2 16 1 H - 33 3 1 1 J - 34 3 2 1 L - 35 3 3 1 H - 36 3 4 1 O - 37 3 5 1 F - 38 3 6 1 C - 39 3 7 1 E - 40 3 8 1 B - 41 3 9 1 M - 42 3 10 1 I - 43 3 11 1 K - 44 3 12 1 A + 20 2 4 1 L + 21 2 5 1 B + 22 2 6 1 P + 23 2 7 1 D + 24 2 8 1 J + 25 2 9 1 K + 26 2 10 1 A + 27 2 11 1 M + 28 2 12 1 N + 29 2 13 1 H + 30 2 14 1 G + 31 2 15 1 E + 32 2 16 1 O + 33 3 1 1 E + 34 3 2 1 B + 35 3 3 1 J + 36 3 4 1 G + 37 3 5 1 D + 38 3 6 1 H + 39 3 7 1 K + 40 3 8 1 A + 41 3 9 1 I + 42 3 10 1 O + 43 3 11 1 L + 44 3 12 1 F 45 3 13 1 P - 46 3 14 1 G - 47 3 15 1 E - 48 3 16 1 N - 49 4 1 1 I - 50 4 2 1 H - 51 4 3 1 E - 52 4 4 1 J - 53 4 5 1 P - 54 4 6 1 N - 55 4 7 1 C - 56 4 8 1 K - 57 4 9 1 G - 58 4 10 1 L - 59 4 11 1 D - 60 4 12 1 F - 61 4 13 1 M - 62 4 14 1 O - 63 4 15 1 B - 64 4 16 1 A - 65 5 1 2 G - 66 5 2 2 P - 67 5 3 2 I - 68 5 4 2 N - 69 5 5 2 E - 70 5 6 2 D - 71 5 7 2 O - 72 5 8 2 M - 73 5 9 2 A - 74 5 10 2 B - 75 5 11 2 C - 76 5 12 2 H - 77 5 13 2 L - 78 5 14 2 J - 79 5 15 2 F - 80 5 16 2 K - 81 6 1 2 C - 82 6 2 2 K - 83 6 3 2 J - 84 6 4 2 E - 85 6 5 2 B - 86 6 6 2 O - 87 6 7 2 I - 88 6 8 2 A - 89 6 9 2 D + 46 3 14 1 N + 47 3 15 1 C + 48 3 16 1 I + 49 4 1 1 M + 50 4 2 1 K + 51 4 3 1 M + 52 4 4 1 H + 53 4 5 1 A + 54 4 6 1 J + 55 4 7 1 I + 56 4 8 1 L + 57 4 9 1 P + 58 4 10 1 D + 59 4 11 1 B + 60 4 12 1 C + 61 4 13 1 N + 62 4 14 1 E + 63 4 15 1 F + 64 4 16 1 G + 65 5 1 2 A + 66 5 2 2 B + 67 5 3 2 H + 68 5 4 2 F + 69 5 5 2 N + 70 5 6 2 M + 71 5 7 2 C + 72 5 8 2 K + 73 5 9 2 J + 74 5 10 2 E + 75 5 11 2 I + 76 5 12 2 P + 77 5 13 2 G + 78 5 14 2 O + 79 5 15 2 L + 80 5 16 2 D + 81 6 1 2 O + 82 6 2 2 I + 83 6 3 2 G + 84 6 4 2 K + 85 6 5 2 D + 86 6 6 2 E + 87 6 7 2 F + 88 6 8 2 D + 89 6 9 2 A 90 6 10 2 M 91 6 11 2 P - 92 6 12 2 G - 93 6 13 2 N - 94 6 14 2 H - 95 6 15 2 L - 96 6 16 2 F - 97 7 1 2 I - 98 7 2 2 H - 99 7 3 2 A - 100 7 4 2 L - 101 7 5 2 N - 102 7 6 2 K - 103 7 7 2 D - 104 7 8 2 J - 105 7 9 2 F - 106 7 10 2 N - 107 7 11 2 G - 108 7 12 2 M - 109 7 13 2 O - 110 7 14 2 E - 111 7 15 2 C - 112 7 16 2 B - 113 8 1 2 M - 114 8 2 2 J + 92 6 12 2 B + 93 6 13 2 H + 94 6 14 2 C + 95 6 15 2 J + 96 6 16 2 N + 97 7 1 2 D + 98 7 2 2 J + 99 7 3 2 I + 100 7 4 2 P + 101 7 5 2 G + 102 7 6 2 B + 103 7 7 2 A + 104 7 8 2 N + 105 7 9 2 E + 106 7 10 2 H + 107 7 11 2 F + 108 7 12 2 O + 109 7 13 2 L + 110 7 14 2 K + 111 7 15 2 M + 112 7 16 2 C + 113 8 1 2 H + 114 8 2 2 L 115 8 3 2 O - 116 8 4 2 D - 117 8 5 2 I + 116 8 4 2 C + 117 8 5 2 E 118 8 6 2 A - 119 8 7 2 P - 120 8 8 2 G - 121 8 9 2 L - 122 8 10 2 P - 123 8 11 2 E - 124 8 12 2 B - 125 8 13 2 H - 126 8 14 2 F - 127 8 15 2 K - 128 8 16 2 C - 129 9 1 3 H - 130 9 2 3 F - 131 9 3 3 L - 132 9 4 3 M - 133 9 5 3 K - 134 9 6 3 E - 135 9 7 3 A - 136 9 8 3 I - 137 9 9 3 B - 138 9 10 3 D - 139 9 11 3 J - 140 9 12 3 O - 141 9 13 3 J - 142 9 14 3 C - 143 9 15 3 G - 144 9 16 3 P - 145 10 1 3 A - 146 10 2 3 B - 147 10 3 3 C - 148 10 4 3 H - 149 10 5 3 L - 150 10 6 3 N - 151 10 7 3 G - 152 10 8 3 N - 153 10 9 3 C - 154 10 10 3 O - 155 10 11 3 F - 156 10 12 3 P - 157 10 13 3 E - 158 10 14 3 I + 119 8 7 2 F + 120 8 8 2 B + 121 8 9 2 M + 122 8 10 2 L + 123 8 11 2 N + 124 8 12 2 J + 125 8 13 2 K + 126 8 14 2 I + 127 8 15 2 G + 128 8 16 2 P + 129 9 1 3 I + 130 9 2 3 D + 131 9 3 3 N + 132 9 4 3 E + 133 9 5 3 I + 134 9 6 3 K + 135 9 7 3 J + 136 9 8 3 O + 137 9 9 3 F + 138 9 10 3 G + 139 9 11 3 C + 140 9 12 3 M + 141 9 13 3 E + 142 9 14 3 P + 143 9 15 3 L + 144 9 16 3 H + 145 10 1 3 J + 146 10 2 3 F + 147 10 3 3 H + 148 10 4 3 O + 149 10 5 3 P + 150 10 6 3 F + 151 10 7 3 C + 152 10 8 3 E + 153 10 9 3 N + 154 10 10 3 L + 155 10 11 3 K + 156 10 12 3 G + 157 10 13 3 B + 158 10 14 3 M 159 10 15 3 D - 160 10 16 3 M - 161 11 1 3 B - 162 11 2 3 M - 163 11 3 3 K - 164 11 4 3 A - 165 11 5 3 O - 166 11 6 3 J - 167 11 7 3 H - 168 11 8 3 P - 169 11 9 3 N + 160 10 16 3 I + 161 11 1 3 K + 162 11 2 3 A + 163 11 3 3 C + 164 11 4 3 N + 165 11 5 3 J + 166 11 6 3 M + 167 11 7 3 O + 168 11 8 3 H + 169 11 9 3 B 170 11 10 3 F - 171 11 11 3 L - 172 11 12 3 K - 173 11 13 3 G - 174 11 14 3 D - 175 11 15 3 I - 176 11 16 3 E - 177 12 1 3 N - 178 12 2 3 C - 179 12 3 3 P - 180 12 4 3 O - 181 12 5 3 F - 182 12 6 3 D - 183 12 7 3 K - 184 12 8 3 H + 171 11 11 3 G + 172 11 12 3 I + 173 11 13 3 D + 174 11 14 3 L + 175 11 15 3 P + 176 11 16 3 A + 177 12 1 3 B + 178 12 2 3 E + 179 12 3 3 B + 180 12 4 3 D + 181 12 5 3 M + 182 12 6 3 K + 183 12 7 3 P + 184 12 8 3 G 185 12 9 3 L - 186 12 10 3 I - 187 12 11 3 M - 188 12 12 3 E - 189 12 13 3 A - 190 12 14 3 B - 191 12 15 3 J - 192 12 16 3 G - 193 13 1 4 K + 186 12 10 3 C + 187 12 11 3 A + 188 12 12 3 H + 189 12 13 3 J + 190 12 14 3 A + 191 12 15 3 O + 192 12 16 3 N + 193 13 1 4 C 194 13 2 4 G - 195 13 3 4 D - 196 13 4 4 C - 197 13 5 4 M - 198 13 6 4 F - 199 13 7 4 N - 200 13 8 4 O - 201 13 9 4 E - 202 13 10 4 B - 203 13 11 4 A - 204 13 12 4 I - 205 13 13 4 P - 206 13 14 4 L - 207 13 15 4 H - 208 13 16 4 J - 209 14 1 4 L - 210 14 2 4 I - 211 14 3 4 M + 195 13 3 4 E + 196 13 4 4 I + 197 13 5 4 P + 198 13 6 4 N + 199 13 7 4 M + 200 13 8 4 F + 201 13 9 4 H + 202 13 10 4 J + 203 13 11 4 O + 204 13 12 4 D + 205 13 13 4 A + 206 13 14 4 B + 207 13 15 4 K + 208 13 16 4 L + 209 14 1 4 P + 210 14 2 4 M + 211 14 3 4 A 212 14 4 4 G - 213 14 5 4 J - 214 14 6 4 H - 215 14 7 4 F - 216 14 8 4 E - 217 14 9 4 P - 218 14 10 4 C - 219 14 11 4 B - 220 14 12 4 K - 221 14 13 4 G - 222 14 14 4 N - 223 14 15 4 A - 224 14 16 4 O - 225 15 1 4 C - 226 15 2 4 K - 227 15 3 4 G - 228 15 4 4 F + 213 14 5 4 L + 214 14 6 4 I + 215 14 7 4 N + 216 14 8 4 C + 217 14 9 4 D + 218 14 10 4 K + 219 14 11 4 J + 220 14 12 4 B + 221 14 13 4 O + 222 14 14 4 H + 223 14 15 4 I + 224 14 16 4 F + 225 15 1 4 K + 226 15 2 4 P + 227 15 3 4 L + 228 15 4 4 M 229 15 5 4 H - 230 15 6 4 M - 231 15 7 4 B - 232 15 8 4 D - 233 15 9 4 I - 234 15 10 4 A - 235 15 11 4 N - 236 15 12 4 J - 237 15 13 4 E - 238 15 14 4 P - 239 15 15 4 O - 240 15 16 4 L + 230 15 6 4 O + 231 15 7 4 A + 232 15 8 4 I + 233 15 9 4 C + 234 15 10 4 B + 235 15 11 4 D + 236 15 12 4 E + 237 15 13 4 G + 238 15 14 4 F + 239 15 15 4 N + 240 15 16 4 B 241 16 1 4 F - 242 16 2 4 D - 243 16 3 4 O - 244 16 4 4 J - 245 16 5 4 C - 246 16 6 4 B - 247 16 7 4 D - 248 16 8 4 M - 249 16 9 4 P - 250 16 10 4 E - 251 16 11 4 H - 252 16 12 4 L - 253 16 13 4 K - 254 16 14 4 A - 255 16 15 4 N - 256 16 16 4 I + 242 16 2 4 G + 243 16 3 4 D + 244 16 4 4 A + 245 16 5 4 O + 246 16 6 4 L + 247 16 7 4 M + 248 16 8 4 P + 249 16 9 4 K + 250 16 10 4 N + 251 16 11 4 E + 252 16 12 4 J + 253 16 13 4 C + 254 16 14 4 J + 255 16 15 4 H + 256 16 16 4 E diff --git a/tests/testthat/_snaps/speed-layouts/speed-custom-obj-func.svg b/tests/testthat/_snaps/speed-layouts/speed-custom-obj-func.svg index 68047add..f92b55ba 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-custom-obj-func.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-custom-obj-func.svg @@ -45,37 +45,37 @@ - - - - - - - - - - + + + + + + + + + + - - + + -A -A -A -A -B -B -B -B -C -C +A +A +A +A +B +B +B +B +C +C C C D -D -D +D +D D diff --git a/tests/testthat/_snaps/speed-layouts/speed-large-blocks.svg b/tests/testthat/_snaps/speed-layouts/speed-large-blocks.svg index 8b40b4db..e063d589 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-large-blocks.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-large-blocks.svg @@ -93,518 +93,518 @@ - - - - - - - - - - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + - - + + + + + + + + + - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + - - - - - - - - - - - -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A + + + + + + + + + + + + + + + +A +A +A +A +A A -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -D -D -D -D -D -D -D -D -D +A +A +A +A +A +A +A +A +A +A +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +D +D +D +D +D +D +D +D +D +D +D +D D -D -D -D -D -D -D -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -F -F -F -F -F -F -F +D +D +D +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +F +F +F +F +F +F +F +F +F +F F +F +F +F F -F -F -F -F -F -F -F -G -G -G -G -G -G -G +F +G G -G -G +G +G +G +G +G +G +G +G +G G -G -G -G -G -G -H -H -H -H -H +G +G +G +G +H +H +H +H +H +H +H +H +H H -H -H -H -H -H -H -H -H -H -H -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -K -K -K -K -K -K -K -K -K -K -K -K -K -K -K -K -L -L -L -L +H +H +H +H +H +H +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +K +K +K +K +K +K +K +K +K +K +K +K +K +K +K +K +L +L +L +L +L +L +L L -L -L -L -L -L -L -L -L -L -L -L -M -M -M -M +L +L +L +L +L +L +L +L +M +M M -M -M -M -M -M -M -M -M -M -M -M -N -N -N -N -N -N -N -N -N -N -N -N -N -N -N -N -O -O -O -O +M +M +M +M +M +M +M +M +M +M +M +M +M +N +N +N +N +N +N +N +N +N +N +N +N +N +N +N +N +O +O +O +O +O +O +O +O +O +O +O +O O -O -O -O -O -O -O -O -O -O -O -O -P -P -P -P +O +O +O P -P -P -P -P -P -P -P -P -P -P -P +P +P +P +P +P +P +P +P +P +P +P +P +P +P +P diff --git a/tests/testthat/_snaps/speed-layouts/speed-large-grid.svg b/tests/testthat/_snaps/speed-layouts/speed-large-grid.svg index c4d75595..4c1b8ed1 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-large-grid.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-large-grid.svg @@ -109,806 +109,806 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + - - - - + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A +A +A +A +A +A +A +A +A +A +A A -A -A -A -A -A -A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A A -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B +A +A +A +A +A +A +A +A +A +A +A +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B B -B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B B -B -C -C -C -C -C -C -C -C -C -C +B +B +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C C -C +C +C +C +C +C +C +C +C +C +C +C C -C -C -C -C +C C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -D +C +C +C +C +C +C +C +C +D +D +D +D +D +D +D +D +D D +D +D D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D +D +D +D +D D -D -D -D -D -D -D -D -D -D -D -D +D +D +D +D +D +D +D D -D -D -D -D -D -D -E -E -E -E -E -E -E +D +D +D +D +D +D +D +D +D +D +D +D +D +D +E +E +E +E +E +E E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E +E +E +E +E +E +E +E +E +E +E E +E +E +E +E +E +E +E +E +E +E +E E -E -E -E -E -E -E +E +E +E +E +E +E +E +E +E +E +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F F -F -F +F +F +F F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F +F +F +F F -F -G -G -G -G -G -G -G -G -G -G -G -G +F +G +G +G +G +G +G +G +G +G +G +G +G G -G -G -G -G +G +G +G +G +G +G +G +G +G +G +G +G +G +G G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -H -H -H -H -H +G +G +G +G +G +G +G +G +G +G +G +G +H +H +H +H H -H +H +H +H +H +H H -H H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H +H +H +H +H +H +H +H +H +H +H +H +H +H H -H -H -H -H -H -H -H -H -H -H -H -H -I -I -I -I -I -I -I -I -I -I -I -I +H +H +H +H +H +H +H +H +H +H +H +H +H +H +I I -I -I I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +J +J +J +J +J +J +J +J +J J -J -J -J -J -J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J +J +J +J +J J -J -J -J -J -J -J -J -J -J -J -J diff --git a/tests/testthat/_snaps/speed-layouts/speed-large-missing-clump.svg b/tests/testthat/_snaps/speed-layouts/speed-large-missing-clump.svg index 8440c619..eb70f051 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-large-missing-clump.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-large-missing-clump.svg @@ -109,774 +109,774 @@ - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - + - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - -A -A -A -A -A -A -A -A + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A A -A -A -A -A -A -A +A A -A -A -A -A -A -A -A -A -A +A +A +A A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -B -B -B -B -B -B -B -B +A +A +A +A +A +A +A +A +A +A +A +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B B -B -B -B +B +B +B +B +B +B +B +B +B +B +B B -B -B -B -B -B -B -B -B -B -B -B -B -B -B +B +B +B B -B -B -B -B -B -B -B -B -B -B -B -B -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C +C +C +C +C +C C -C -C -C -C -C -C -C -C -C -C -C -C +C +C +C C -C -C -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +D +D D -D -D -D -D -D -E -E +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E +E +E +E +E +E +E +E E -E -E -E -E -E -E -E -E +E +E +E +E +E +E +E +E +E E -E -E -E -E -E -E -E -F -F -F -F -F -F -F -F -F -F -F +E +E +E +E +E +E +F +F +F +F +F F -F -F -F -F +F +F +F +F +F +F +F +F +F +F +F +F +F +F F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -G -G -G -G +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +G +G +G G -G -G -G -G -G -G -G -G -G -G -G -G -G G -G -G -G -G +G +G +G +G +G +G +G +G +G +G +G +G G -G -G -G +G +G +G +G +G +G +G +G +G +G G -G -G -G -G -G -G -G -G -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H +G +G +G +G +G +G +G +H +H +H +H +H +H +H +H +H +H +H +H H -H -H -H -H +H +H +H +H +H +H +H +H +H +H +H +H +H +H H -H -H -H -H -H -H -H -H -H -I -I -I +H +H +H +H +H +H +H +H +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I I -I -I -I -I -I -I -I -I -I +I +I +I I -I -I -I -I -I -I -I -I -I -I -I -I -I +I +I +I +I +I +I I -I -I -I -I -I -I -I -I -J -J -J -J -J -J -J -J -J -J +J +J +J +J +J J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J diff --git a/tests/testthat/_snaps/speed-layouts/speed-large-missing-l.svg b/tests/testthat/_snaps/speed-layouts/speed-large-missing-l.svg index 8517f29f..28df3431 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-large-missing-l.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-large-missing-l.svg @@ -109,582 +109,582 @@ - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -A -A -A + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +A +A +A +A +A +A +A +A +A +A A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A +A A -A -A -A -A -A -A -A -A -A -A -A -B -B -B -B -B -B -B -B -B -B -B -B -B -B +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A B -B +B +B +B +B +B +B +B +B +B B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B +B B -B -B -B -B -B -B -B -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C +B +B +B +B +B +B +B +B +B +B +B +B +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C C -C -C -C -C -C -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D +C +C +C +C +C +C +C +C +C +C +D +D +D +D +D D -D -E -E -E -E -E -E +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D E -E -E -E -E -E -E -E +E +E +E E -E -E -E -E -E -E -E -E -E -E -E -F -F -F -F -F -F +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +F +F +F +F +F +F +F +F +F +F +F +F +F +F F -F +F +F +F +F +F +F +F +F +F F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -G -G +F +G +G +G +G +G +G +G +G +G +G +G +G G -G -G -G -G -G -G -G -G -G -G -G -G -G +G +G +G +G G +G +G +G +G G -G -G -G -G -G -G -G -G -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H +G +G +G +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H H -H -H -H -H -H -H -H -H -H -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J +H +H +H +H +H +H +H +H +H +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J diff --git a/tests/testthat/_snaps/speed-layouts/speed-large-missing.svg b/tests/testthat/_snaps/speed-layouts/speed-large-missing.svg index c0bfec24..641eea99 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-large-missing.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-large-missing.svg @@ -109,706 +109,706 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + - - + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A + + + + + + + + + + +A +A +A +A +A +A A -A -A -A -A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +A +B +B +B +B +B +B +B B -B +B +B +B +B +B +B +B +B +B +B +B B +B +B +B +B +B +B +B B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B -B +B +B B -B -B -B -B -B -B -B -B -B -C -C -C +B +B +B +B +B +B +C +C +C +C +C +C +C C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C -C +C +C +C +C C -C -C -C -C -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D -D +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +C +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D D -D -D -D -D -D -D -D -D -D -E -E -E -E -E -E -E -E -E -E +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +D +E +E +E +E E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E -E +E +E +E +E E -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F -F +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +E +F +F +F +F +F +F +F F -F -F -F -F -F -F -F -F -F -F -F -F -F -F +F +F +F F -F -F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F +F F -G -G +F +F +F +F +F +F +G +G +G +G +G +G +G +G +G +G +G +G +G +G +G +G G -G -G -G -G -G -G +G +G +G +G +G +G +G +G +G +G +G G -G -G -G -G -G -G -G -G -G G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -G -H -H -H -H -H -H +G +G +G +G +G H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H -H +H +H +H +H +H +H H -H -H -H -H -H -H -H -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I -I +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +H +I +I +I +I +I +I +I +I +I I -I -I -I -I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I +I I -I -I -I -I -J -J -J -J -J -J -J -J -J -J -J +J +J +J +J +J +J +J +J +J J -J -J -J -J +J +J +J +J +J +J +J +J +J +J +J +J +J +J +J J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J -J +J +J +J +J +J +J +J +J +J +J diff --git a/tests/testthat/_snaps/speed-layouts/speed-large-rcbd.svg b/tests/testthat/_snaps/speed-layouts/speed-large-rcbd.svg index d0e97f94..9024555c 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-large-rcbd.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-large-rcbd.svg @@ -209,4006 +209,4006 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -V1 -V1 -V1 -V1 -V10 -V10 -V10 -V10 -V100 -V100 -V100 -V100 -V101 -V101 -V101 -V101 -V102 -V102 -V102 -V102 -V103 -V103 -V103 -V103 -V104 -V104 -V104 -V104 -V105 -V105 -V105 -V105 -V106 -V106 -V106 -V106 -V107 -V107 -V107 -V107 -V108 -V108 -V108 -V108 -V109 -V109 -V109 -V109 -V11 -V11 -V11 -V11 -V110 -V110 -V110 -V110 -V111 -V111 -V111 -V111 -V112 -V112 -V112 -V112 -V113 -V113 -V113 -V113 -V114 -V114 -V114 -V114 -V115 -V115 -V115 -V115 -V116 -V116 -V116 -V116 -V117 -V117 -V117 -V117 -V118 -V118 -V118 -V118 -V119 -V119 -V119 -V119 -V12 -V12 -V12 -V12 -V120 -V120 -V120 -V120 -V121 -V121 -V121 -V121 -V122 -V122 -V122 -V122 -V123 -V123 -V123 -V123 -V124 -V124 -V124 -V124 -V125 -V125 -V125 -V125 -V126 -V126 -V126 -V126 -V127 -V127 -V127 -V127 -V128 -V128 -V128 -V128 -V129 -V129 -V129 -V129 -V13 -V13 -V13 -V13 -V130 -V130 -V130 -V130 -V131 -V131 -V131 -V131 -V132 -V132 -V132 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +V1 +V1 +V1 +V1 +V10 +V10 +V10 +V10 +V100 +V100 +V100 +V100 +V101 +V101 +V101 +V101 +V102 +V102 +V102 +V102 +V103 +V103 +V103 +V103 +V104 +V104 +V104 +V104 +V105 +V105 +V105 +V105 +V106 +V106 +V106 +V106 +V107 +V107 +V107 +V107 +V108 +V108 +V108 +V108 +V109 +V109 +V109 +V109 +V11 +V11 +V11 +V11 +V110 +V110 +V110 +V110 +V111 +V111 +V111 +V111 +V112 +V112 +V112 +V112 +V113 +V113 +V113 +V113 +V114 +V114 +V114 +V114 +V115 +V115 +V115 +V115 +V116 +V116 +V116 +V116 +V117 +V117 +V117 +V117 +V118 +V118 +V118 +V118 +V119 +V119 +V119 +V119 +V12 +V12 +V12 +V12 +V120 +V120 +V120 +V120 +V121 +V121 +V121 +V121 +V122 +V122 +V122 +V122 +V123 +V123 +V123 +V123 +V124 +V124 +V124 +V124 +V125 +V125 +V125 +V125 +V126 +V126 +V126 +V126 +V127 +V127 +V127 +V127 +V128 +V128 +V128 +V128 +V129 +V129 +V129 +V129 +V13 +V13 +V13 +V13 +V130 +V130 +V130 +V130 +V131 +V131 +V131 +V131 +V132 +V132 +V132 V132 -V133 -V133 -V133 -V133 -V134 -V134 -V134 -V134 -V135 -V135 -V135 -V135 -V136 -V136 -V136 -V136 -V137 -V137 -V137 -V137 -V138 -V138 -V138 -V138 -V139 -V139 -V139 -V139 -V14 -V14 -V14 -V14 -V140 -V140 -V140 -V140 -V141 -V141 -V141 -V141 -V142 -V142 -V142 -V142 -V143 -V143 -V143 -V143 -V144 -V144 -V144 -V144 -V145 -V145 -V145 -V145 -V146 -V146 -V146 -V146 -V147 -V147 -V147 -V147 -V148 -V148 -V148 -V148 -V149 -V149 -V149 -V149 -V15 -V15 -V15 -V15 -V150 -V150 -V150 -V150 -V151 -V151 -V151 -V151 -V152 -V152 +V133 +V133 +V133 +V133 +V134 +V134 +V134 +V134 +V135 +V135 +V135 +V135 +V136 +V136 +V136 +V136 +V137 +V137 +V137 +V137 +V138 +V138 +V138 +V138 +V139 +V139 +V139 +V139 +V14 +V14 +V14 +V14 +V140 +V140 +V140 +V140 +V141 +V141 +V141 +V141 +V142 +V142 +V142 +V142 +V143 +V143 +V143 +V143 +V144 +V144 +V144 +V144 +V145 +V145 +V145 +V145 +V146 +V146 +V146 +V146 +V147 +V147 +V147 +V147 +V148 +V148 +V148 +V148 +V149 +V149 +V149 +V149 +V15 +V15 +V15 +V15 +V150 +V150 +V150 +V150 +V151 +V151 +V151 +V151 +V152 +V152 V152 -V152 -V153 -V153 -V153 -V153 -V154 -V154 -V154 -V154 -V155 -V155 -V155 -V155 -V156 -V156 -V156 -V156 -V157 -V157 -V157 -V157 -V158 -V158 -V158 -V158 -V159 -V159 -V159 -V159 -V16 -V16 -V16 -V16 -V160 -V160 -V160 -V160 -V161 -V161 -V161 -V161 -V162 -V162 -V162 -V162 -V163 -V163 -V163 -V163 -V164 -V164 -V164 -V164 -V165 -V165 -V165 -V165 -V166 -V166 -V166 -V166 -V167 -V167 -V167 -V167 -V168 -V168 -V168 -V168 -V169 -V169 -V169 -V169 -V17 -V17 -V17 -V17 -V170 -V170 -V170 -V170 -V171 -V171 -V171 -V171 -V172 -V172 -V172 -V172 -V173 -V173 -V173 -V173 -V174 -V174 -V174 -V174 -V175 -V175 -V175 -V175 -V176 -V176 -V176 -V176 -V177 -V177 -V177 -V177 -V178 -V178 -V178 -V178 -V179 -V179 -V179 -V179 -V18 -V18 -V18 -V18 -V180 -V180 -V180 -V180 -V181 -V181 -V181 -V181 -V182 -V182 -V182 -V182 -V183 -V183 -V183 -V183 -V184 -V184 -V184 -V184 -V185 -V185 -V185 -V185 -V186 -V186 -V186 -V186 -V187 -V187 -V187 -V187 -V188 -V188 -V188 -V188 -V189 -V189 -V189 -V189 -V19 -V19 -V19 -V19 -V190 -V190 -V190 -V190 -V191 -V191 -V191 -V191 -V192 -V192 -V192 -V192 -V193 -V193 -V193 -V193 -V194 -V194 -V194 -V194 -V195 -V195 -V195 -V195 -V196 -V196 -V196 -V196 -V197 -V197 -V197 -V197 -V198 -V198 -V198 -V198 -V199 -V199 -V199 -V199 -V2 -V2 -V2 -V2 -V20 -V20 -V20 -V20 -V200 -V200 -V200 -V200 -V201 -V201 -V201 -V201 -V202 -V202 -V202 -V202 -V203 -V203 -V203 -V203 -V204 -V204 -V204 -V204 -V205 -V205 -V205 -V205 -V206 -V206 -V206 -V206 -V207 -V207 -V207 -V207 -V208 -V208 -V208 -V208 -V209 -V209 -V209 -V209 -V21 -V21 -V21 -V21 -V210 -V210 -V210 -V210 -V211 -V211 -V211 -V211 -V212 -V212 -V212 -V212 -V213 -V213 -V213 -V213 -V214 -V214 -V214 -V214 -V215 -V215 -V215 -V215 -V216 -V216 -V216 -V216 -V217 -V217 -V217 -V217 -V218 -V218 -V218 -V218 -V219 -V219 -V219 -V219 -V22 -V22 -V22 -V22 -V220 -V220 -V220 -V220 -V221 -V221 -V221 -V221 -V222 -V222 -V222 -V222 -V223 -V223 -V223 -V223 -V224 -V224 -V224 -V224 -V225 -V225 -V225 -V225 -V226 -V226 -V226 -V226 -V227 -V227 -V227 -V227 -V228 -V228 -V228 -V228 -V229 -V229 -V229 -V229 -V23 -V23 -V23 -V23 -V230 -V230 -V230 -V230 -V231 -V231 -V231 -V231 -V232 -V232 -V232 -V232 -V233 -V233 -V233 -V233 -V234 -V234 -V234 -V234 -V235 -V235 -V235 -V235 -V236 -V236 -V236 -V236 -V237 -V237 -V237 -V237 -V238 -V238 -V238 -V238 -V239 -V239 -V239 -V239 -V24 -V24 -V24 -V24 -V240 -V240 -V240 -V240 -V241 -V241 -V241 -V241 -V242 -V242 -V242 -V242 -V243 -V243 -V243 -V243 -V244 -V244 -V244 -V244 -V245 -V245 -V245 -V245 -V246 -V246 -V246 -V246 -V247 -V247 -V247 -V247 -V248 -V248 -V248 -V248 -V249 -V249 -V249 -V249 -V25 -V25 -V25 -V25 -V250 -V250 -V250 -V250 -V251 -V251 -V251 -V251 -V252 -V252 -V252 -V252 -V253 -V253 -V253 -V253 -V254 -V254 -V254 -V254 +V152 +V153 +V153 +V153 +V153 +V154 +V154 +V154 +V154 +V155 +V155 +V155 +V155 +V156 +V156 +V156 +V156 +V157 +V157 +V157 +V157 +V158 +V158 +V158 +V158 +V159 +V159 +V159 +V159 +V16 +V16 +V16 +V16 +V160 +V160 +V160 +V160 +V161 +V161 +V161 +V161 +V162 +V162 +V162 +V162 +V163 +V163 +V163 +V163 +V164 +V164 +V164 +V164 +V165 +V165 +V165 +V165 +V166 +V166 +V166 +V166 +V167 +V167 +V167 +V167 +V168 +V168 +V168 +V168 +V169 +V169 +V169 +V169 +V17 +V17 +V17 +V17 +V170 +V170 +V170 +V170 +V171 +V171 +V171 +V171 +V172 +V172 +V172 +V172 +V173 +V173 +V173 +V173 +V174 +V174 +V174 +V174 +V175 +V175 +V175 +V175 +V176 +V176 +V176 +V176 +V177 +V177 +V177 +V177 +V178 +V178 +V178 +V178 +V179 +V179 +V179 +V179 +V18 +V18 +V18 +V18 +V180 +V180 +V180 +V180 +V181 +V181 +V181 +V181 +V182 +V182 +V182 +V182 +V183 +V183 +V183 +V183 +V184 +V184 +V184 +V184 +V185 +V185 +V185 +V185 +V186 +V186 +V186 +V186 +V187 +V187 +V187 +V187 +V188 +V188 +V188 +V188 +V189 +V189 +V189 +V189 +V19 +V19 +V19 +V19 +V190 +V190 +V190 +V190 +V191 +V191 +V191 +V191 +V192 +V192 +V192 +V192 +V193 +V193 +V193 +V193 +V194 +V194 +V194 +V194 +V195 +V195 +V195 +V195 +V196 +V196 +V196 +V196 +V197 +V197 +V197 +V197 +V198 +V198 +V198 +V198 +V199 +V199 +V199 +V199 +V2 +V2 +V2 +V2 +V20 +V20 +V20 +V20 +V200 +V200 +V200 +V200 +V201 +V201 +V201 +V201 +V202 +V202 +V202 +V202 +V203 +V203 +V203 +V203 +V204 +V204 +V204 +V204 +V205 +V205 +V205 +V205 +V206 +V206 +V206 +V206 +V207 +V207 +V207 +V207 +V208 +V208 +V208 +V208 +V209 +V209 +V209 +V209 +V21 +V21 +V21 +V21 +V210 +V210 +V210 +V210 +V211 +V211 +V211 +V211 +V212 +V212 +V212 +V212 +V213 +V213 +V213 +V213 +V214 +V214 +V214 +V214 +V215 +V215 +V215 +V215 +V216 +V216 +V216 +V216 +V217 +V217 +V217 +V217 +V218 +V218 +V218 +V218 +V219 +V219 +V219 +V219 +V22 +V22 +V22 +V22 +V220 +V220 +V220 +V220 +V221 +V221 +V221 +V221 +V222 +V222 +V222 +V222 +V223 +V223 +V223 +V223 +V224 +V224 +V224 +V224 +V225 +V225 +V225 +V225 +V226 +V226 +V226 +V226 +V227 +V227 +V227 +V227 +V228 +V228 +V228 +V228 +V229 +V229 +V229 +V229 +V23 +V23 +V23 +V23 +V230 +V230 +V230 +V230 +V231 +V231 +V231 +V231 +V232 +V232 +V232 +V232 +V233 +V233 +V233 +V233 +V234 +V234 +V234 +V234 +V235 +V235 +V235 +V235 +V236 +V236 +V236 +V236 +V237 +V237 +V237 +V237 +V238 +V238 +V238 +V238 +V239 +V239 +V239 +V239 +V24 +V24 +V24 +V24 +V240 +V240 +V240 +V240 +V241 +V241 +V241 +V241 +V242 +V242 +V242 +V242 +V243 +V243 +V243 +V243 +V244 +V244 +V244 +V244 +V245 +V245 +V245 +V245 +V246 +V246 +V246 +V246 +V247 +V247 +V247 +V247 +V248 +V248 +V248 +V248 +V249 +V249 +V249 +V249 +V25 +V25 +V25 +V25 +V250 +V250 +V250 +V250 +V251 +V251 +V251 +V251 +V252 +V252 +V252 +V252 +V253 +V253 +V253 +V253 +V254 +V254 +V254 +V254 +V255 +V255 +V255 V255 -V255 -V255 -V255 -V256 -V256 -V256 -V256 -V257 -V257 -V257 -V257 -V258 -V258 -V258 -V258 -V259 -V259 -V259 -V259 -V26 -V26 -V26 -V26 -V260 -V260 -V260 -V260 -V261 -V261 -V261 -V261 -V262 -V262 -V262 -V262 -V263 -V263 -V263 -V263 -V264 -V264 -V264 -V264 -V265 -V265 -V265 -V265 -V266 -V266 -V266 -V266 -V267 -V267 -V267 -V267 -V268 -V268 -V268 -V268 -V269 -V269 -V269 -V269 -V27 -V27 -V27 -V27 -V270 -V270 -V270 -V270 -V271 -V271 -V271 -V271 -V272 -V272 -V272 -V272 -V273 -V273 -V273 -V273 -V274 -V274 -V274 -V274 -V275 -V275 -V275 -V275 -V276 -V276 -V276 -V276 -V277 -V277 -V277 -V277 -V278 -V278 -V278 -V278 -V279 -V279 -V279 -V279 -V28 -V28 -V28 -V28 -V280 -V280 -V280 -V280 -V281 -V281 -V281 -V281 -V282 -V282 -V282 -V282 -V283 -V283 -V283 -V283 -V284 -V284 -V284 -V284 -V285 -V285 -V285 -V285 -V286 -V286 -V286 -V286 -V287 -V287 -V287 -V287 -V288 -V288 -V288 -V288 -V289 -V289 -V289 -V289 -V29 -V29 -V29 -V29 -V290 -V290 -V290 -V290 -V291 -V291 -V291 -V291 -V292 -V292 -V292 -V292 -V293 -V293 -V293 -V293 -V294 -V294 -V294 -V294 -V295 -V295 -V295 -V295 -V296 -V296 -V296 -V296 -V297 -V297 -V297 -V297 -V298 -V298 -V298 -V298 -V299 -V299 -V299 -V299 -V3 -V3 -V3 -V3 -V30 -V30 -V30 -V30 -V300 -V300 -V300 -V300 -V301 -V301 -V301 -V301 -V302 -V302 -V302 -V302 -V303 -V303 -V303 -V303 -V304 -V304 -V304 -V304 -V305 -V305 -V305 -V305 -V306 -V306 -V306 -V306 -V307 -V307 -V307 -V307 -V308 -V308 -V308 -V308 -V309 -V309 -V309 -V309 -V31 -V31 -V31 -V31 -V310 -V310 -V310 -V310 -V311 -V311 -V311 -V311 -V312 -V312 -V312 -V312 -V313 -V313 -V313 -V313 -V314 -V314 -V314 -V314 -V315 -V315 -V315 -V315 -V316 -V316 -V316 -V316 -V317 -V317 -V317 -V317 -V318 -V318 -V318 -V318 -V319 -V319 -V319 -V319 -V32 -V32 -V32 -V32 -V320 -V320 -V320 -V320 -V321 -V321 -V321 -V321 -V322 -V322 -V322 -V322 -V323 -V323 -V323 -V323 -V324 -V324 -V324 -V324 -V325 -V325 -V325 -V325 -V326 -V326 -V326 -V326 -V327 -V327 -V327 -V327 -V328 -V328 -V328 -V328 -V329 -V329 -V329 -V329 -V33 -V33 -V33 -V33 -V330 -V330 -V330 -V330 -V331 -V331 -V331 -V331 -V332 -V332 -V332 -V332 -V333 -V333 -V333 -V333 -V334 -V334 -V334 -V334 -V335 -V335 -V335 -V335 -V336 -V336 -V336 -V336 -V337 -V337 -V337 -V337 -V338 -V338 -V338 -V338 -V339 -V339 -V339 -V339 -V34 -V34 -V34 -V34 -V340 -V340 -V340 -V340 -V341 -V341 -V341 -V341 -V342 -V342 -V342 -V342 -V343 -V343 -V343 -V343 -V344 -V344 -V344 -V344 -V345 -V345 -V345 -V345 -V346 -V346 -V346 -V346 -V347 -V347 -V347 -V347 -V348 -V348 -V348 -V348 -V349 -V349 -V349 -V349 -V35 -V35 -V35 -V35 -V350 -V350 -V350 -V350 -V351 -V351 -V351 -V351 -V352 -V352 -V352 -V352 -V353 -V353 -V353 -V353 -V354 -V354 -V354 -V354 -V355 -V355 -V355 -V355 -V356 -V356 -V356 -V356 -V357 -V357 -V357 -V357 -V358 -V358 -V358 -V358 -V359 -V359 -V359 -V359 -V36 -V36 -V36 -V36 -V360 -V360 -V360 -V360 -V361 -V361 -V361 -V361 -V362 -V362 -V362 -V362 -V363 -V363 -V363 -V363 -V364 -V364 -V364 -V364 -V365 -V365 -V365 -V365 -V366 -V366 -V366 -V366 -V367 -V367 -V367 -V367 -V368 -V368 -V368 -V368 -V369 -V369 -V369 -V369 -V37 -V37 -V37 -V37 -V370 -V370 -V370 -V370 -V371 -V371 -V371 -V371 -V372 -V372 -V372 -V372 -V373 -V373 -V373 -V373 -V374 -V374 -V374 -V374 -V375 -V375 -V375 -V375 -V376 -V376 -V376 -V376 -V377 -V377 -V377 -V377 -V378 -V378 -V378 -V378 -V379 -V379 -V379 -V379 -V38 -V38 -V38 -V38 -V380 -V380 -V380 -V380 -V381 -V381 -V381 -V381 -V382 -V382 -V382 -V382 -V383 -V383 -V383 -V383 -V384 -V384 -V384 -V384 -V385 -V385 -V385 -V385 -V386 -V386 -V386 -V386 -V387 -V387 -V387 -V387 -V388 -V388 -V388 -V388 -V389 -V389 -V389 -V389 -V39 -V39 -V39 -V39 -V390 -V390 -V390 -V390 -V391 -V391 -V391 -V391 -V392 -V392 -V392 -V392 -V393 -V393 -V393 -V393 -V394 -V394 -V394 -V394 -V395 -V395 -V395 -V395 -V396 -V396 -V396 -V396 -V397 -V397 -V397 -V397 -V398 -V398 -V398 -V398 -V399 -V399 -V399 -V399 -V4 -V4 -V4 -V4 -V40 -V40 -V40 -V40 -V400 -V400 -V400 -V400 -V401 -V401 -V401 -V401 -V402 -V402 -V402 -V402 -V403 -V403 -V403 -V403 -V404 -V404 -V404 -V404 -V405 -V405 -V405 -V405 -V406 -V406 -V406 -V406 -V407 -V407 -V407 -V407 -V408 -V408 -V408 -V408 -V409 -V409 -V409 -V409 -V41 -V41 -V41 -V41 -V410 -V410 -V410 -V410 -V411 -V411 -V411 -V411 -V412 -V412 -V412 -V412 -V413 -V413 -V413 -V413 -V414 -V414 -V414 -V414 -V415 -V415 -V415 -V415 -V416 -V416 -V416 -V416 -V417 -V417 -V417 -V417 -V418 -V418 -V418 -V418 -V419 -V419 -V419 -V419 -V42 -V42 -V42 -V42 -V420 -V420 -V420 -V420 -V421 -V421 -V421 -V421 -V422 -V422 -V422 -V422 -V423 -V423 -V423 -V423 -V424 -V424 -V424 -V424 -V425 -V425 -V425 -V425 -V426 -V426 -V426 -V426 -V427 -V427 -V427 -V427 -V428 -V428 -V428 -V428 -V429 -V429 -V429 -V429 -V43 -V43 -V43 -V43 -V430 -V430 -V430 -V430 -V431 -V431 -V431 -V431 -V432 -V432 -V432 -V432 -V433 +V256 +V256 +V256 +V256 +V257 +V257 +V257 +V257 +V258 +V258 +V258 +V258 +V259 +V259 +V259 +V259 +V26 +V26 +V26 +V26 +V260 +V260 +V260 +V260 +V261 +V261 +V261 +V261 +V262 +V262 +V262 +V262 +V263 +V263 +V263 +V263 +V264 +V264 +V264 +V264 +V265 +V265 +V265 +V265 +V266 +V266 +V266 +V266 +V267 +V267 +V267 +V267 +V268 +V268 +V268 +V268 +V269 +V269 +V269 +V269 +V27 +V27 +V27 +V27 +V270 +V270 +V270 +V270 +V271 +V271 +V271 +V271 +V272 +V272 +V272 +V272 +V273 +V273 +V273 +V273 +V274 +V274 +V274 +V274 +V275 +V275 +V275 +V275 +V276 +V276 +V276 +V276 +V277 +V277 +V277 +V277 +V278 +V278 +V278 +V278 +V279 +V279 +V279 +V279 +V28 +V28 +V28 +V28 +V280 +V280 +V280 +V280 +V281 +V281 +V281 +V281 +V282 +V282 +V282 +V282 +V283 +V283 +V283 +V283 +V284 +V284 +V284 +V284 +V285 +V285 +V285 +V285 +V286 +V286 +V286 +V286 +V287 +V287 +V287 +V287 +V288 +V288 +V288 +V288 +V289 +V289 +V289 +V289 +V29 +V29 +V29 +V29 +V290 +V290 +V290 +V290 +V291 +V291 +V291 +V291 +V292 +V292 +V292 +V292 +V293 +V293 +V293 +V293 +V294 +V294 +V294 +V294 +V295 +V295 +V295 +V295 +V296 +V296 +V296 +V296 +V297 +V297 +V297 +V297 +V298 +V298 +V298 +V298 +V299 +V299 +V299 +V299 +V3 +V3 +V3 +V3 +V30 +V30 +V30 +V30 +V300 +V300 +V300 +V300 +V301 +V301 +V301 +V301 +V302 +V302 +V302 +V302 +V303 +V303 +V303 +V303 +V304 +V304 +V304 +V304 +V305 +V305 +V305 +V305 +V306 +V306 +V306 +V306 +V307 +V307 +V307 +V307 +V308 +V308 +V308 +V308 +V309 +V309 +V309 +V309 +V31 +V31 +V31 +V31 +V310 +V310 +V310 +V310 +V311 +V311 +V311 +V311 +V312 +V312 +V312 +V312 +V313 +V313 +V313 +V313 +V314 +V314 +V314 +V314 +V315 +V315 +V315 +V315 +V316 +V316 +V316 +V316 +V317 +V317 +V317 +V317 +V318 +V318 +V318 +V318 +V319 +V319 +V319 +V319 +V32 +V32 +V32 +V32 +V320 +V320 +V320 +V320 +V321 +V321 +V321 +V321 +V322 +V322 +V322 +V322 +V323 +V323 +V323 +V323 +V324 +V324 +V324 +V324 +V325 +V325 +V325 +V325 +V326 +V326 +V326 +V326 +V327 +V327 +V327 +V327 +V328 +V328 +V328 +V328 +V329 +V329 +V329 +V329 +V33 +V33 +V33 +V33 +V330 +V330 +V330 +V330 +V331 +V331 +V331 +V331 +V332 +V332 +V332 +V332 +V333 +V333 +V333 +V333 +V334 +V334 +V334 +V334 +V335 +V335 +V335 +V335 +V336 +V336 +V336 +V336 +V337 +V337 +V337 +V337 +V338 +V338 +V338 +V338 +V339 +V339 +V339 +V339 +V34 +V34 +V34 +V34 +V340 +V340 +V340 +V340 +V341 +V341 +V341 +V341 +V342 +V342 +V342 +V342 +V343 +V343 +V343 +V343 +V344 +V344 +V344 +V344 +V345 +V345 +V345 +V345 +V346 +V346 +V346 +V346 +V347 +V347 +V347 +V347 +V348 +V348 +V348 +V348 +V349 +V349 +V349 +V349 +V35 +V35 +V35 +V35 +V350 +V350 +V350 +V350 +V351 +V351 +V351 +V351 +V352 +V352 +V352 +V352 +V353 +V353 +V353 +V353 +V354 +V354 +V354 +V354 +V355 +V355 +V355 +V355 +V356 +V356 +V356 +V356 +V357 +V357 +V357 +V357 +V358 +V358 +V358 +V358 +V359 +V359 +V359 +V359 +V36 +V36 +V36 +V36 +V360 +V360 +V360 +V360 +V361 +V361 +V361 +V361 +V362 +V362 +V362 +V362 +V363 +V363 +V363 +V363 +V364 +V364 +V364 +V364 +V365 +V365 +V365 +V365 +V366 +V366 +V366 +V366 +V367 +V367 +V367 +V367 +V368 +V368 +V368 +V368 +V369 +V369 +V369 +V369 +V37 +V37 +V37 +V37 +V370 +V370 +V370 +V370 +V371 +V371 +V371 +V371 +V372 +V372 +V372 +V372 +V373 +V373 +V373 +V373 +V374 +V374 +V374 +V374 +V375 +V375 +V375 +V375 +V376 +V376 +V376 +V376 +V377 +V377 +V377 +V377 +V378 +V378 +V378 +V378 +V379 +V379 +V379 +V379 +V38 +V38 +V38 +V38 +V380 +V380 +V380 +V380 +V381 +V381 +V381 +V381 +V382 +V382 +V382 +V382 +V383 +V383 +V383 +V383 +V384 +V384 +V384 +V384 +V385 +V385 +V385 +V385 +V386 +V386 +V386 +V386 +V387 +V387 +V387 +V387 +V388 +V388 +V388 +V388 +V389 +V389 +V389 +V389 +V39 +V39 +V39 +V39 +V390 +V390 +V390 +V390 +V391 +V391 +V391 +V391 +V392 +V392 +V392 +V392 +V393 +V393 +V393 +V393 +V394 +V394 +V394 +V394 +V395 +V395 +V395 +V395 +V396 +V396 +V396 +V396 +V397 +V397 +V397 +V397 +V398 +V398 +V398 +V398 +V399 +V399 +V399 +V399 +V4 +V4 +V4 +V4 +V40 +V40 +V40 +V40 +V400 +V400 +V400 +V400 +V401 +V401 +V401 +V401 +V402 +V402 +V402 +V402 +V403 +V403 +V403 +V403 +V404 +V404 +V404 +V404 +V405 +V405 +V405 +V405 +V406 +V406 +V406 +V406 +V407 +V407 +V407 +V407 +V408 +V408 +V408 +V408 +V409 +V409 +V409 +V409 +V41 +V41 +V41 +V41 +V410 +V410 +V410 +V410 +V411 +V411 +V411 +V411 +V412 +V412 +V412 +V412 +V413 +V413 +V413 +V413 +V414 +V414 +V414 +V414 +V415 +V415 +V415 +V415 +V416 +V416 +V416 +V416 +V417 +V417 +V417 +V417 +V418 +V418 +V418 +V418 +V419 +V419 +V419 +V419 +V42 +V42 +V42 +V42 +V420 +V420 +V420 +V420 +V421 +V421 +V421 +V421 +V422 +V422 +V422 +V422 +V423 +V423 +V423 +V423 +V424 +V424 +V424 +V424 +V425 +V425 +V425 +V425 +V426 +V426 +V426 +V426 +V427 +V427 +V427 +V427 +V428 +V428 +V428 +V428 +V429 +V429 +V429 +V429 +V43 +V43 +V43 +V43 +V430 +V430 +V430 +V430 +V431 +V431 +V431 +V431 +V432 +V432 +V432 +V432 V433 -V433 -V433 -V434 -V434 -V434 -V434 -V435 -V435 -V435 +V433 +V433 +V433 +V434 +V434 +V434 +V434 +V435 +V435 +V435 V435 -V436 -V436 -V436 -V436 -V437 -V437 -V437 -V437 -V438 -V438 -V438 -V438 -V439 -V439 -V439 -V439 -V44 -V44 -V44 -V44 -V440 -V440 -V440 -V440 -V441 -V441 -V441 -V441 -V442 -V442 -V442 -V442 -V443 -V443 -V443 -V443 -V444 -V444 -V444 -V444 -V445 -V445 -V445 -V445 -V446 -V446 -V446 -V446 -V447 -V447 -V447 -V447 -V448 -V448 -V448 -V448 -V449 -V449 -V449 -V449 -V45 -V45 -V45 -V45 -V450 -V450 -V450 -V450 -V451 -V451 -V451 -V451 -V452 -V452 -V452 -V452 -V453 -V453 -V453 -V453 -V454 -V454 -V454 -V454 -V455 -V455 -V455 -V455 -V456 -V456 -V456 -V456 -V457 -V457 -V457 -V457 -V458 -V458 -V458 -V458 -V459 -V459 -V459 -V459 -V46 -V46 -V46 -V46 -V460 -V460 -V460 -V460 -V461 -V461 -V461 -V461 -V462 -V462 -V462 -V462 -V463 -V463 -V463 -V463 -V464 -V464 -V464 -V464 -V465 -V465 -V465 -V465 -V466 -V466 -V466 -V466 -V467 -V467 -V467 -V467 -V468 -V468 -V468 -V468 -V469 -V469 -V469 -V469 -V47 -V47 -V47 -V47 -V470 -V470 -V470 -V470 -V471 -V471 -V471 -V471 -V472 -V472 -V472 -V472 -V473 -V473 -V473 -V473 -V474 -V474 -V474 -V474 -V475 -V475 -V475 -V475 -V476 -V476 -V476 -V476 -V477 -V477 -V477 -V477 -V478 -V478 -V478 -V478 -V479 -V479 -V479 -V479 -V48 -V48 -V48 -V48 -V480 -V480 -V480 -V480 -V481 -V481 -V481 -V481 -V482 -V482 -V482 -V482 -V483 -V483 -V483 -V483 -V484 -V484 -V484 -V484 -V485 -V485 -V485 -V485 -V486 -V486 -V486 -V486 -V487 -V487 -V487 -V487 -V488 -V488 -V488 -V488 -V489 -V489 -V489 -V489 -V49 -V49 -V49 -V49 -V490 -V490 -V490 -V490 -V491 -V491 -V491 -V491 -V492 -V492 -V492 -V492 -V493 -V493 -V493 -V493 -V494 -V494 -V494 -V494 -V495 -V495 -V495 -V495 -V496 -V496 -V496 -V496 -V497 -V497 -V497 -V497 -V498 -V498 -V498 -V498 -V499 -V499 -V499 -V499 -V5 -V5 -V5 -V5 -V50 -V50 -V50 -V50 -V500 -V500 -V500 -V500 -V51 -V51 -V51 -V51 -V52 -V52 -V52 -V52 -V53 -V53 -V53 -V53 -V54 -V54 -V54 -V54 -V55 -V55 -V55 -V55 -V56 -V56 -V56 -V56 -V57 -V57 -V57 -V57 -V58 -V58 -V58 -V58 -V59 -V59 -V59 -V59 -V6 -V6 -V6 -V6 -V60 -V60 -V60 -V60 -V61 -V61 -V61 -V61 -V62 -V62 -V62 -V62 -V63 -V63 -V63 -V63 -V64 -V64 -V64 -V64 -V65 -V65 -V65 -V65 -V66 -V66 -V66 -V66 -V67 -V67 -V67 -V67 -V68 -V68 -V68 -V68 -V69 -V69 -V69 -V69 -V7 -V7 -V7 -V7 -V70 -V70 -V70 -V70 -V71 -V71 -V71 -V71 -V72 -V72 -V72 -V72 -V73 -V73 -V73 -V73 -V74 -V74 -V74 -V74 -V75 -V75 -V75 -V75 -V76 -V76 -V76 -V76 -V77 -V77 -V77 -V77 -V78 -V78 -V78 -V78 -V79 -V79 -V79 -V79 -V8 -V8 -V8 -V8 -V80 -V80 -V80 -V80 -V81 -V81 -V81 -V81 -V82 -V82 -V82 -V82 -V83 -V83 -V83 -V83 -V84 -V84 -V84 -V84 -V85 -V85 -V85 -V85 -V86 -V86 -V86 -V86 -V87 -V87 -V87 -V87 -V88 -V88 -V88 -V88 -V89 -V89 -V89 -V89 -V9 -V9 -V9 -V9 -V90 -V90 -V90 -V90 -V91 -V91 -V91 -V91 -V92 -V92 -V92 -V92 -V93 -V93 -V93 -V93 -V94 -V94 -V94 -V94 -V95 -V95 -V95 -V95 -V96 -V96 -V96 -V96 -V97 -V97 -V97 -V97 -V98 -V98 -V98 -V98 -V99 -V99 -V99 -V99 +V436 +V436 +V436 +V436 +V437 +V437 +V437 +V437 +V438 +V438 +V438 +V438 +V439 +V439 +V439 +V439 +V44 +V44 +V44 +V44 +V440 +V440 +V440 +V440 +V441 +V441 +V441 +V441 +V442 +V442 +V442 +V442 +V443 +V443 +V443 +V443 +V444 +V444 +V444 +V444 +V445 +V445 +V445 +V445 +V446 +V446 +V446 +V446 +V447 +V447 +V447 +V447 +V448 +V448 +V448 +V448 +V449 +V449 +V449 +V449 +V45 +V45 +V45 +V45 +V450 +V450 +V450 +V450 +V451 +V451 +V451 +V451 +V452 +V452 +V452 +V452 +V453 +V453 +V453 +V453 +V454 +V454 +V454 +V454 +V455 +V455 +V455 +V455 +V456 +V456 +V456 +V456 +V457 +V457 +V457 +V457 +V458 +V458 +V458 +V458 +V459 +V459 +V459 +V459 +V46 +V46 +V46 +V46 +V460 +V460 +V460 +V460 +V461 +V461 +V461 +V461 +V462 +V462 +V462 +V462 +V463 +V463 +V463 +V463 +V464 +V464 +V464 +V464 +V465 +V465 +V465 +V465 +V466 +V466 +V466 +V466 +V467 +V467 +V467 +V467 +V468 +V468 +V468 +V468 +V469 +V469 +V469 +V469 +V47 +V47 +V47 +V47 +V470 +V470 +V470 +V470 +V471 +V471 +V471 +V471 +V472 +V472 +V472 +V472 +V473 +V473 +V473 +V473 +V474 +V474 +V474 +V474 +V475 +V475 +V475 +V475 +V476 +V476 +V476 +V476 +V477 +V477 +V477 +V477 +V478 +V478 +V478 +V478 +V479 +V479 +V479 +V479 +V48 +V48 +V48 +V48 +V480 +V480 +V480 +V480 +V481 +V481 +V481 +V481 +V482 +V482 +V482 +V482 +V483 +V483 +V483 +V483 +V484 +V484 +V484 +V484 +V485 +V485 +V485 +V485 +V486 +V486 +V486 +V486 +V487 +V487 +V487 +V487 +V488 +V488 +V488 +V488 +V489 +V489 +V489 +V489 +V49 +V49 +V49 +V49 +V490 +V490 +V490 +V490 +V491 +V491 +V491 +V491 +V492 +V492 +V492 +V492 +V493 +V493 +V493 +V493 +V494 +V494 +V494 +V494 +V495 +V495 +V495 +V495 +V496 +V496 +V496 +V496 +V497 +V497 +V497 +V497 +V498 +V498 +V498 +V498 +V499 +V499 +V499 +V499 +V5 +V5 +V5 +V5 +V50 +V50 +V50 +V50 +V500 +V500 +V500 +V500 +V51 +V51 +V51 +V51 +V52 +V52 +V52 +V52 +V53 +V53 +V53 +V53 +V54 +V54 +V54 +V54 +V55 +V55 +V55 +V55 +V56 +V56 +V56 +V56 +V57 +V57 +V57 +V57 +V58 +V58 +V58 +V58 +V59 +V59 +V59 +V59 +V6 +V6 +V6 +V6 +V60 +V60 +V60 +V60 +V61 +V61 +V61 +V61 +V62 +V62 +V62 +V62 +V63 +V63 +V63 +V63 +V64 +V64 +V64 +V64 +V65 +V65 +V65 +V65 +V66 +V66 +V66 +V66 +V67 +V67 +V67 +V67 +V68 +V68 +V68 +V68 +V69 +V69 +V69 +V69 +V7 +V7 +V7 +V7 +V70 +V70 +V70 +V70 +V71 +V71 +V71 +V71 +V72 +V72 +V72 +V72 +V73 +V73 +V73 +V73 +V74 +V74 +V74 +V74 +V75 +V75 +V75 +V75 +V76 +V76 +V76 +V76 +V77 +V77 +V77 +V77 +V78 +V78 +V78 +V78 +V79 +V79 +V79 +V79 +V8 +V8 +V8 +V8 +V80 +V80 +V80 +V80 +V81 +V81 +V81 +V81 +V82 +V82 +V82 +V82 +V83 +V83 +V83 +V83 +V84 +V84 +V84 +V84 +V85 +V85 +V85 +V85 +V86 +V86 +V86 +V86 +V87 +V87 +V87 +V87 +V88 +V88 +V88 +V88 +V89 +V89 +V89 +V89 +V9 +V9 +V9 +V9 +V90 +V90 +V90 +V90 +V91 +V91 +V91 +V91 +V92 +V92 +V92 +V92 +V93 +V93 +V93 +V93 +V94 +V94 +V94 +V94 +V95 +V95 +V95 +V95 +V96 +V96 +V96 +V96 +V97 +V97 +V97 +V97 +V98 +V98 +V98 +V98 +V99 +V99 +V99 +V99 diff --git a/tests/testthat/_snaps/speed-layouts/speed-multi-spatial-factors.svg b/tests/testthat/_snaps/speed-layouts/speed-multi-spatial-factors.svg index f123eb22..7c51ce3d 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-multi-spatial-factors.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-multi-spatial-factors.svg @@ -49,56 +49,56 @@ - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - + + + - -A +A A -A -A -A -B -B -B -B -B -C -C -C -C -C -D -D -D -D +A +A +A +B +B +B +B +B +C +C +C +C +C +D +D +D +D D -E -E +E E +E +E E -E diff --git a/tests/testthat/_snaps/speed-layouts/speed-non-uniform.svg b/tests/testthat/_snaps/speed-layouts/speed-non-uniform.svg index 48509b60..5394d2ef 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-non-uniform.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-non-uniform.svg @@ -63,150 +63,150 @@ - - - - - - - - - - - - - - - - - - - + + - - - - + + + + + + + + + - + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + - - - -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A -A + + + + + +A +A A -A -A -A -A +A +A +A +A +A +A +A +A +A A -A +A +A +A +A +A +A A -B -B -B -B -B -B -B -B -B -C -C -C -C -C +A +A +A +A +A +A +A +B +B +B +B +B +B +B +B +B +C +C +C +C +C +C C -C -C -C +C +C +D +D +D +D +D +D +D +D D -D -D -D -D -D -D -D -D -E -E -E -E -E -E -E -E -E -F -F -F -F -F +E +E +E +E +E +E +E +E +E +F +F +F F -F -F -F +F +F +F +F +F diff --git a/tests/testthat/_snaps/speed-layouts/speed-partial-rep.svg b/tests/testthat/_snaps/speed-layouts/speed-partial-rep.svg index 46784e43..a57641b5 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-partial-rep.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-partial-rep.svg @@ -89,406 +89,406 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -V1 -V10 -V100 -V101 -V102 -V103 -V104 -V105 -V106 -V106 -V107 -V108 -V109 -V11 -V11 -V110 -V111 -V112 -V113 -V114 -V114 -V115 -V116 -V117 -V118 -V119 -V12 -V12 -V120 -V121 -V122 -V122 -V123 -V124 -V125 -V126 -V126 -V127 -V128 -V129 -V13 -V130 -V130 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +V1 +V10 +V100 +V101 +V102 +V103 +V104 +V105 +V106 +V106 +V107 +V108 +V109 +V11 +V11 +V110 +V111 +V112 +V113 +V114 +V114 +V115 +V116 +V117 +V118 +V119 +V12 +V12 +V120 +V121 +V122 +V122 +V123 +V124 +V125 +V126 +V126 +V127 +V128 +V129 +V13 +V130 +V130 +V131 V131 -V131 -V132 -V133 -V134 -V135 -V136 -V137 -V138 -V139 -V14 -V140 -V141 -V142 -V143 -V144 -V144 -V145 -V145 -V146 -V146 -V147 -V147 -V148 -V148 -V149 -V149 -V15 -V150 -V150 -V16 -V17 -V18 -V18 -V19 -V19 -V2 -V2 -V20 -V21 -V21 -V22 -V22 -V23 -V23 -V24 -V25 -V26 -V27 -V28 -V28 -V29 -V3 -V3 -V30 -V30 -V31 -V32 -V32 -V33 -V34 -V35 -V36 -V37 -V38 -V39 -V39 -V4 -V40 -V40 -V41 -V41 -V42 -V43 -V44 -V45 -V45 -V46 +V132 +V133 +V134 +V135 +V136 +V137 +V138 +V139 +V14 +V140 +V141 +V142 +V143 +V144 +V144 +V145 +V145 +V146 +V146 +V147 +V147 +V148 +V148 +V149 +V149 +V15 +V150 +V150 +V16 +V17 +V18 +V18 +V19 +V19 +V2 +V2 +V20 +V21 +V21 +V22 +V22 +V23 +V23 +V24 +V25 +V26 +V27 +V28 +V28 +V29 +V3 +V3 +V30 +V30 +V31 +V32 +V32 +V33 +V34 +V35 +V36 +V37 +V38 +V39 +V39 +V4 +V40 +V40 +V41 +V41 +V42 +V43 +V44 +V45 +V45 +V46 V46 -V47 -V47 -V48 -V49 -V49 -V5 -V5 -V50 -V51 -V52 +V47 +V47 +V48 +V49 +V49 +V5 +V5 +V50 +V51 +V52 V53 -V54 -V54 -V55 -V56 -V57 -V57 -V58 -V59 -V59 -V6 -V6 -V60 -V60 -V61 -V62 -V63 -V63 -V64 -V65 -V66 -V67 -V67 -V68 -V69 -V7 -V7 -V70 -V71 -V72 -V72 -V73 -V74 -V75 -V76 -V77 -V78 -V79 -V79 -V8 -V8 -V80 -V80 -V81 -V82 -V83 -V84 -V85 -V86 -V87 -V88 -V88 -V89 -V89 -V9 -V90 -V91 -V92 -V93 -V93 -V94 -V95 -V96 -V97 -V97 -V98 -V98 -V99 +V54 +V54 +V55 +V56 +V57 +V57 +V58 +V59 +V59 +V6 +V6 +V60 +V60 +V61 +V62 +V63 +V63 +V64 +V65 +V66 +V67 +V67 +V68 +V69 +V7 +V7 +V70 +V71 +V72 +V72 +V73 +V74 +V75 +V76 +V77 +V78 +V79 +V79 +V8 +V8 +V80 +V80 +V81 +V82 +V83 +V84 +V85 +V86 +V87 +V88 +V88 +V89 +V89 +V9 +V90 +V91 +V92 +V93 +V93 +V94 +V95 +V96 +V97 +V97 +V98 +V98 +V99 diff --git a/tests/testthat/_snaps/speed-layouts/speed-rcbd-multi-reps.svg b/tests/testthat/_snaps/speed-layouts/speed-rcbd-multi-reps.svg index 6bf3673d..9febdb3e 100644 --- a/tests/testthat/_snaps/speed-layouts/speed-rcbd-multi-reps.svg +++ b/tests/testthat/_snaps/speed-layouts/speed-rcbd-multi-reps.svg @@ -119,1006 +119,1006 @@ - - - - - - + + + + + + - - - - - - + + + + + - - - - + + + - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + - - - - - + + - - - - - - - - + + + + - - - - - - - - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - -V1 -V1 -V1 -V1 -V1 -V1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +V1 +V1 +V1 +V1 +V1 +V1 V1 -V1 -V1 -V1 -V1 -V1 -V1 +V1 +V1 +V1 +V1 +V1 V1 -V1 -V1 -V1 -V1 +V1 +V1 +V1 V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 +V1 +V1 V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V1 -V10 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V1 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 V10 -V10 -V10 -V10 +V10 +V10 +V10 V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 +V10 +V10 +V10 +V10 +V10 +V10 +V10 V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V10 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 +V10 +V2 +V2 +V2 +V2 +V2 +V2 +V2 V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 +V2 +V2 +V2 +V2 +V2 +V2 V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 -V2 +V2 +V2 +V2 V2 -V2 -V2 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V2 +V3 +V3 +V3 +V3 +V3 V3 -V3 -V3 -V3 -V3 -V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 V3 -V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 +V3 V3 -V3 -V3 -V3 -V3 -V3 +V3 +V3 V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 +V3 +V3 +V3 +V3 V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V3 -V4 -V4 +V3 +V3 +V3 +V4 +V4 +V4 +V4 V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 -V4 +V4 +V4 +V4 +V4 V4 -V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 +V4 V4 -V4 -V4 -V4 -V4 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 +V4 +V4 +V4 +V4 +V4 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 V5 +V5 +V5 V5 V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 -V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 +V5 V5 -V5 -V5 -V5 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 -V6 +V5 +V5 +V5 +V5 +V6 +V6 +V6 +V6 +V6 V6 -V6 -V6 -V6 -V6 -V6 -V6 V6 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 -V7 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V6 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 V7 -V7 -V7 -V7 -V7 +V7 +V7 +V7 V7 -V7 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V7 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 V8 -V8 +V8 +V8 +V8 V8 -V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 V8 +V8 +V8 +V8 +V8 V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V8 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 -V9 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V8 +V9 +V9 +V9 V9 -V9 -V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 +V9 diff --git a/tests/testthat/_snaps/speed-output.md b/tests/testthat/_snaps/speed-output.md index e85ab738..1eed1937 100644 --- a/tests/testthat/_snaps/speed-output.md +++ b/tests/testthat/_snaps/speed-output.md @@ -23,7 +23,7 @@ row and col are used as row and column, respectively. Output Optimising level: wp - Level: wp Iteration: 1000 Score: 22 Best: 22 Since Improvement: 680 + Level: wp Iteration: 1000 Score: 22 Best: 22 Since Improvement: 480 Optimising level: sp - Level: sp Iteration: 1000 Score: 1.333333 Best: 1.333333 Since Improvement: 266 + Level: sp Iteration: 1000 Score: 1.333333 Best: 1.333333 Since Improvement: 14 diff --git a/tests/testthat/_snaps/speed-output/autoplot-factor-with-blocks.svg b/tests/testthat/_snaps/speed-output/autoplot-factor-with-blocks.svg index a460a8a3..53f431d9 100644 --- a/tests/testthat/_snaps/speed-output/autoplot-factor-with-blocks.svg +++ b/tests/testthat/_snaps/speed-output/autoplot-factor-with-blocks.svg @@ -37,54 +37,54 @@ - - - - - - + + + + + + + + - - - - - - - - - - + + + + + + + + - - - - - -A -A -A -B -B -B + + + + + +A +A +A +B +B +B +C +C C -C -C -D -D -D -E -E -E -F -F +D +D +D +E +E +E +F F +F G -G -G -H -H -H +G +G +H +H +H diff --git a/tests/testthat/_snaps/speed-output/autoplot-hierarchical-mixed-factors-sp.svg b/tests/testthat/_snaps/speed-output/autoplot-hierarchical-mixed-factors-sp.svg index 0f01c70d..64fe082a 100644 --- a/tests/testthat/_snaps/speed-output/autoplot-hierarchical-mixed-factors-sp.svg +++ b/tests/testthat/_snaps/speed-output/autoplot-hierarchical-mixed-factors-sp.svg @@ -52,150 +52,150 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - + + - + + + + + + - - - - - - + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - + + - - - - - - + + + + + + + + -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPa -SPb -SPb + + + +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa +SPa SPb -SPb +SPb +SPb SPb -SPb +SPb SPb +SPb +SPb +SPb +SPb +SPb SPb -SPb -SPb -SPb -SPb -SPb -SPb SPb +SPb SPb +SPb +SPb SPb -SPb -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc -SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc +SPc SPd -SPd -SPd -SPd -SPd -SPd -SPd -SPd +SPd +SPd SPd -SPd -SPd -SPd -SPd SPd -SPd -SPd SPd +SPd +SPd +SPd +SPd +SPd +SPd +SPd +SPd SPd +SPd +SPd +SPd diff --git a/tests/testthat/_snaps/speed-output/autoplot-hierarchical-mixed-factors-wp.svg b/tests/testthat/_snaps/speed-output/autoplot-hierarchical-mixed-factors-wp.svg index f20ea225..1be105c9 100644 --- a/tests/testthat/_snaps/speed-output/autoplot-hierarchical-mixed-factors-wp.svg +++ b/tests/testthat/_snaps/speed-output/autoplot-hierarchical-mixed-factors-wp.svg @@ -52,150 +52,150 @@ - - - - + - - - - - - + + + + + + - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -WPA -WPA -WPA -WPA + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +WPA WPA WPA -WPA -WPA -WPA -WPA -WPA -WPA +WPA WPA +WPA +WPA +WPA +WPA +WPA WPA -WPA -WPA -WPA -WPA -WPA -WPA +WPA +WPA +WPA WPA +WPA +WPA WPA +WPA +WPA +WPA WPA -WPA -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPB -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC -WPC +WPA +WPA +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPB +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC +WPC diff --git a/tests/testthat/_snaps/speed-output/autoplot-hierarchical-no-legend.svg b/tests/testthat/_snaps/speed-output/autoplot-hierarchical-no-legend.svg index 03c3e266..7d3784bd 100644 --- a/tests/testthat/_snaps/speed-output/autoplot-hierarchical-no-legend.svg +++ b/tests/testthat/_snaps/speed-output/autoplot-hierarchical-no-legend.svg @@ -53,10 +53,10 @@ - - - - + + + + @@ -69,18 +69,18 @@ - - - - + + + + A A A A -A -A -A -A +A +A +A +A B B B @@ -93,10 +93,10 @@ C C C -C -C -C -C +C +C +C +C diff --git a/tests/testthat/_snaps/speed-output/autoplot-hierarchical-with-legend.svg b/tests/testthat/_snaps/speed-output/autoplot-hierarchical-with-legend.svg index 546b69f1..44b01e41 100644 --- a/tests/testthat/_snaps/speed-output/autoplot-hierarchical-with-legend.svg +++ b/tests/testthat/_snaps/speed-output/autoplot-hierarchical-with-legend.svg @@ -53,10 +53,10 @@ - - - - + + + + @@ -69,18 +69,18 @@ - - - - + + + + A A A A -A -A -A -A +A +A +A +A B B B @@ -93,10 +93,10 @@ C C C -C -C -C -C +C +C +C +C diff --git a/tests/testthat/_snaps/speed-output/autoplot-no-legend.svg b/tests/testthat/_snaps/speed-output/autoplot-no-legend.svg index 45141454..1b082e4b 100644 --- a/tests/testthat/_snaps/speed-output/autoplot-no-legend.svg +++ b/tests/testthat/_snaps/speed-output/autoplot-no-legend.svg @@ -41,23 +41,23 @@ - - - - - - - - + + + + + + + + -A -A -A -B -B -B -C -C +A +A +A +B +B +B +C +C C diff --git a/tests/testthat/_snaps/speed-output/autoplot-with-legend.svg b/tests/testthat/_snaps/speed-output/autoplot-with-legend.svg index d72e618d..fb27a4b8 100644 --- a/tests/testthat/_snaps/speed-output/autoplot-with-legend.svg +++ b/tests/testthat/_snaps/speed-output/autoplot-with-legend.svg @@ -41,23 +41,23 @@ - - - - - - - - + + + + + + + + -A -A -A -B -B -B -C -C +A +A +A +B +B +B +C +C C diff --git a/tests/testthat/_snaps/speed/speed-blocks.svg b/tests/testthat/_snaps/speed/speed-blocks.svg index 1c4b3ac9..8f1f7003 100644 --- a/tests/testthat/_snaps/speed/speed-blocks.svg +++ b/tests/testthat/_snaps/speed/speed-blocks.svg @@ -47,45 +47,45 @@ - - - + + + - - - + + + - - - - + + + + - - - - - - + + + + + + -A -A -B +A +A +B B -C -C -D +C +C +D D -E -E -F -F +E +E +F +F G -G -H -H -I -I -J +G +H +H +I +I +J J diff --git a/tests/testthat/_snaps/speed/speed-small.svg b/tests/testthat/_snaps/speed/speed-small.svg index cf4e7293..c9865e49 100644 --- a/tests/testthat/_snaps/speed/speed-small.svg +++ b/tests/testthat/_snaps/speed/speed-small.svg @@ -48,45 +48,45 @@ - - - - - - - + + + + + + - - - - - - - - + + + + + + + + + + + - - A -A -A -A -A -B -B -B +A +A +A +A +B +B B -B -C -C -C -C -C -D -D +B +B +C +C +C +C +C +D +D +D +D D -D -D diff --git a/tests/testthat/test-build_design_matrix.R b/tests/testthat/test-build_design_matrix.R index 028d2a2d..69ec33b1 100644 --- a/tests/testthat/test-build_design_matrix.R +++ b/tests/testthat/test-build_design_matrix.R @@ -412,7 +412,7 @@ test_that("a design whose coordinates cannot form a grid still runs when no grid adj_weight = 0 ) ) - expect_equal(r$score, 3) + expect_equal(r$score, 4) }) test_that("grid_index() names a missing coordinate column", { diff --git a/tests/testthat/test-speed-hierarchical.R b/tests/testthat/test-speed-hierarchical.R index 31d47f92..302267b7 100644 --- a/tests/testthat/test-speed-hierarchical.R +++ b/tests/testthat/test-speed-hierarchical.R @@ -21,9 +21,9 @@ test_that("speed handles split plot designs", { ) expect_s3_class(result, "design") - expect_equal(result$score, 101) - expect_equal(result$iterations_run, 11001) - expect_equal(result$stopped_early, c(wp = TRUE, sp = FALSE)) + expect_equal(result$score, 100) + expect_equal(result$iterations_run, 1726) + expect_equal(result$stopped_early, c(wp = TRUE, sp = TRUE)) vdiffr::expect_doppelganger( "speed_splitplot_wp", @@ -97,7 +97,7 @@ test_that("speed handles split-split plot designs", { expect_equal(length(result$scores), 3) expect_equal(sapply(result$scores, length), c(wp = 229, sp = 201, ssp = 1000)) - expect_equal(result$score, 403) + expect_equal(result$score, 393) expect_equal(result$iterations_run, 1430) expect_equal(result$stopped_early, c(wp = TRUE, sp = TRUE, ssp = FALSE)) expect_equal(result$seed, 42) @@ -174,10 +174,10 @@ test_that("speed handles strip plot designs", { expect_equal(nrow(result$design_df), 72) # 16 rows × 9 cols expect_equal(ncol(result$design_df), 6) # All columns preserved expect_equal(length(result$scores), 2) - expect_equal(sapply(result$scores, length), c(ht = 279, vt = 258)) + expect_equal(sapply(result$scores, length), c(ht = 232, vt = 369)) expect_equal(result$score, 138) - expect_equal(result$iterations_run, 537) + expect_equal(result$iterations_run, 601) expect_equal(result$stopped_early, c(ht = TRUE, vt = TRUE)) expect_equal(result$seed, 42) diff --git a/tests/testthat/test-speed-layouts.R b/tests/testthat/test-speed-layouts.R index 1d4f9291..a9f4c529 100644 --- a/tests/testthat/test-speed-layouts.R +++ b/tests/testthat/test-speed-layouts.R @@ -71,7 +71,7 @@ test_that("speed handles non-uniform treatment distributions", { expect_equal(result$stopped_early, TRUE) expect_equal(result$score, 14) - expect_equal(result$iterations_run, 14965) + expect_equal(result$iterations_run, 13264) vdiffr::expect_doppelganger("speed_non_uniform", autoplot(result)) }) @@ -102,7 +102,7 @@ test_that("speed works with a custom objective function", { expect_s3_class(result, "design") expect_equal(result$score, 0) - expect_equal(result$iterations_run, 475) + expect_equal(result$iterations_run, 742) expect_equal(result$stopped_early, TRUE) vdiffr::expect_doppelganger("speed_custom_obj_func", autoplot(result)) diff --git a/tests/testthat/test-speed.R b/tests/testthat/test-speed.R index da1f3da1..3e1c571f 100644 --- a/tests/testthat/test-speed.R +++ b/tests/testthat/test-speed.R @@ -181,38 +181,6 @@ test_that("annealing accepts equal scores at zero temperature", { } }) -test_that("annealing accepts ties without drawing an acceptance probability", { - design <- data.frame( - row = rep(1:2, each = 2), - col = rep(1:2, times = 2), - treatment = LETTERS[1:4] - ) - proposal <- design - proposal$treatment[c(1, 2)] <- proposal$treatment[c(2, 1)] - objective <- function(layout_df, swap, spatial_cols, ...) { - return(list(score = 1)) - } - local_mocked_bindings( - generate_neighbour = function(...) { - return(list(design = proposal, swapped_items = c("A", "B"))) - }, - runif = function(...) { - stop("A tied score should not require an acceptance draw.") - } - ) - - result <- speed( - design, - swap = "treatment", - obj_function = objective, - iterations = 1, - seed = 1, - quiet = TRUE - ) - - expect_identical(as.character(result$design_df$treatment), proposal$treatment) -}) - test_that("speed throws error for missing columns", { test_data <- data.frame( row = rep(1:5, times = 4), From fb514b3759dfa061ba9117ffaac9667dc6f292fd Mon Sep 17 00:00:00 2001 From: Wasin Pipattungsakul Date: Tue, 17 Nov 2026 11:16:24 +1030 Subject: [PATCH 24/25] chore: clean up --- R/optim_params.R | 6 ++---- man/optim_params.Rd | 6 ++---- man/verify.Rd | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/R/optim_params.R b/R/optim_params.R index 205c05c6..a72353f2 100644 --- a/R/optim_params.R +++ b/R/optim_params.R @@ -24,10 +24,8 @@ #' them to [speed()] directly or through a level's `obj_args` in `optimise` instead. #' @param stop_at_optimal Logical; if `TRUE`, stops the level when the best score reaches its #' lower bound (default: `TRUE`). -#' @param lower_bound Optional finite numeric lower bound on the score, overriding the automatically -#' derived bound. `NULL` (default) derives a bound for the default [objective_function()] with -#' non-negative weights and no `relationship` matrix. If no bound is known, only the usual -#' iteration and no-improvement stopping rules apply. +#' @param lower_bound Lower bound of the score from the objective, used by `stop_at_optimal` (default: `NULL`, +#' derived for the default [objective_function()] with non-negative weights and no `relationship` matrix). #' #' @returns A named list of optimization parameters. #' diff --git a/man/optim_params.Rd b/man/optim_params.Rd index 8f39dcd7..98a1d23d 100644 --- a/man/optim_params.Rd +++ b/man/optim_params.Rd @@ -46,10 +46,8 @@ them to \code{\link[=speed]{speed()}} directly or through a level's \code{obj_ar \item{stop_at_optimal}{Logical; if \code{TRUE}, stops the level when the best score reaches its lower bound (default: \code{TRUE}).} -\item{lower_bound}{Optional finite numeric lower bound on the score, overriding the automatically -derived bound. \code{NULL} (default) derives a bound for the default \code{\link[=objective_function]{objective_function()}} with -non-negative weights and no \code{relationship} matrix. If no bound is known, only the usual -iteration and no-improvement stopping rules apply.} +\item{lower_bound}{Lower bound of the score from the objective, used by \code{stop_at_optimal} (default: \code{NULL}, +derived for the default \code{\link[=objective_function]{objective_function()}} with non-negative weights and no \code{relationship} matrix).} } \value{ A named list of optimization parameters. diff --git a/man/verify.Rd b/man/verify.Rd index edae837f..5796785f 100644 --- a/man/verify.Rd +++ b/man/verify.Rd @@ -150,10 +150,8 @@ them to \code{\link[=speed]{speed()}} directly or through a level's \code{obj_ar \item{stop_at_optimal}{Logical; if \code{TRUE}, stops the level when the best score reaches its lower bound (default: \code{TRUE}).} -\item{lower_bound}{Optional finite numeric lower bound on the score, overriding the automatically -derived bound. \code{NULL} (default) derives a bound for the default \code{\link[=objective_function]{objective_function()}} with -non-negative weights and no \code{relationship} matrix. If no bound is known, only the usual -iteration and no-improvement stopping rules apply.} +\item{lower_bound}{Lower bound of the score from the objective, used by \code{stop_at_optimal} (default: \code{NULL}, +derived for the default \code{\link[=objective_function]{objective_function()}} with non-negative weights and no \code{relationship} matrix).} } \description{ Validates the arguments as the user passed them, dispatching to the checker From aaa7a5a83795783aa6682a4ada4919529b924d72 Mon Sep 17 00:00:00 2001 From: Wasin Pipattungsakul Date: Tue, 17 Nov 2026 11:54:56 +1030 Subject: [PATCH 25/25] test: make tests leaner --- tests/testthat/test-objective_fisher.R | 175 ++++++++----------------- 1 file changed, 52 insertions(+), 123 deletions(-) diff --git a/tests/testthat/test-objective_fisher.R b/tests/testthat/test-objective_fisher.R index e709272b..3322bd93 100644 --- a/tests/testthat/test-objective_fisher.R +++ b/tests/testthat/test-objective_fisher.R @@ -1,5 +1,13 @@ # tests/testthat/test-objective_fisher.R +default_sigma <- function(nrows = 4, ncols = 6) cor_ar1_ar1(nrows, ncols, rho_row = 0.6, rho_col = 0.3) +default_design <- function(nrows = 4, ncols = 6) { + initialise_design_df( + items = ncols, nrows = nrows, ncols = ncols, + block_nrows = 1, block_ncols = ncols + ) +} + # ---- objective_function_info # all RCBDs are equally optimal @@ -174,11 +182,8 @@ test_that("a requested estimable contrast does not require full connectedness", }) test_that("custom contrasts require treatment column names", { - df <- initialise_design_df( - items = 10, nrows = 2, ncols = 10, - block_nrows = 1, block_ncols = 10 - ) - Sigma <- cor_ar1_ar1(2, 10, rho_row = 0.6, rho_col = 0.3) + df <- default_design(2, 10) + Sigma <- default_sigma(2, 10) contrast <- matrix(c(1, -1, rep(0, 8)), nrow = 1) expect_error( @@ -188,26 +193,14 @@ test_that("custom contrasts require treatment column names", { ), "must have column names" ) - expect_error( - speed( - df, swap = "treatment", swap_within = "block", - obj_function = objective_function_info, - Sigma = Sigma, contrast_matrix = contrast, - iterations = 20, seed = 1, quiet = TRUE - ), - "must have column names" - ) }) test_that("named contrasts match treatments rather than column positions", { - df <- initialise_design_df( - items = 10, nrows = 2, ncols = 10, - block_nrows = 1, block_ncols = 10 - ) + df <- default_design(2, 10) df <- df[order(df$row, df$col), ] treatments <- paste0("T", 1:10) df$treatment <- factor(df$treatment, levels = treatments) - Sigma <- cor_ar1_ar1(2, 10, rho_row = 0.6, rho_col = 0.3) + Sigma <- default_sigma(2, 10) contrast <- matrix( c(1, -1, rep(0, 8)), nrow = 1, dimnames = list("T1 - T2", treatments) @@ -260,7 +253,7 @@ test_that("incremental calculation matches full recalculation", { block = rep(1:3, each = 4), treatment = rep(LETTERS[1:4], 3) ) - Sigma <- cor_ar1_ar1(3, 4, rho_row = 0.6, rho_col = 0.3) + Sigma <- default_sigma(3, 4) current <- objective_function_info( df, "treatment", @@ -314,11 +307,8 @@ test_that("incremental calculation matches full recalculation", { }) test_that("covariance matrices remain aligned when layout rows are reordered", { - df <- initialise_design_df( - items = 6, nrows = 4, ncols = 6, - block_nrows = 1, block_ncols = 6 - ) - Sigma <- cor_ar1_ar1(4, 6, rho_row = 0.6, rho_col = 0.3) + df <- default_design() + Sigma <- default_sigma() sorted <- df[order(df$row, df$col), ] reordered <- df[rev(seq_len(nrow(df))), ] L <- compute_L_projection(df, Sigma) @@ -352,11 +342,8 @@ test_that("covariance matrices remain aligned when layout rows are reordered", { }) test_that("spatial scoring uses numeric coordinates and custom grid columns", { - df <- initialise_design_df( - items = 6, nrows = 4, ncols = 6, - block_nrows = 1, block_ncols = 6 - ) - Sigma <- cor_ar1_ar1(4, 6, rho_row = 0.6, rho_col = 0.3) + df <- default_design() + Sigma <- default_sigma() original <- objective_function_info(df, "treatment", c("row", "col"), Sigma = Sigma) names(df)[names(df) == "row"] <- "x" names(df)[names(df) == "col"] <- "y" @@ -373,14 +360,11 @@ test_that("spatial scoring uses numeric coordinates and custom grid columns", { }) test_that("spatial scoring orders multiple grids consistently", { - df <- initialise_design_df( - items = 4, nrows = 3, ncols = 4, - block_nrows = 1, block_ncols = 4 - ) + df <- default_design(3, 4) df <- rbind(transform(df, site = "A"), transform(df, site = "B")) df$block <- interaction(df$site, df$block, drop = TRUE) df$treatment[c(13, 16)] <- df$treatment[c(16, 13)] - Sigma <- kronecker(diag(c(1, 2)), cor_ar1_ar1(3, 4, rho_row = 0.6, rho_col = 0.3)) + Sigma <- kronecker(diag(c(1, 2)), default_sigma(3, 4)) original <- objective_function_info( df, "treatment", c("row", "col"), Sigma = Sigma, by = "site" ) @@ -421,14 +405,11 @@ test_that("spatial scoring orders multiple grids consistently", { }) test_that("spatial scoring accepts covariance for observed plots only", { - df <- initialise_design_df( - items = 4, nrows = 3, ncols = 4, - block_nrows = 1, block_ncols = 4 - ) + df <- default_design(3, 4) df <- df[order(df$row, df$col), ] observed <- setdiff(seq_len(nrow(df)), c(2, 7)) df <- df[observed, ] - Sigma <- cor_ar1_ar1(3, 4, rho_row = 0.6, rho_col = 0.3)[observed, observed] + Sigma <- default_sigma(3, 4)[observed, observed] original <- objective_function_info(df, "treatment", c("row", "col"), Sigma = Sigma) reordered <- objective_function_info( df[rev(seq_len(nrow(df))), ], "treatment", c("row", "col"), Sigma = Sigma @@ -440,11 +421,8 @@ test_that("spatial scoring accepts covariance for observed plots only", { }) test_that("cached projections are rebuilt when nuisance effects change", { - df <- initialise_design_df( - items = 6, nrows = 4, ncols = 6, - block_nrows = 1, block_ncols = 6 - ) - Sigma <- cor_ar1_ar1(4, 6, rho_row = 0.6, rho_col = 0.3) + df <- default_design() + Sigma <- default_sigma() for (covariance in list(NULL, Sigma)) { original <- objective_function_info(df, "treatment", c("row", "col"), Sigma = covariance) @@ -463,13 +441,10 @@ test_that("cached projections are rebuilt when nuisance effects change", { }) test_that("formula expansion and environment changes invalidate the projection", { - df <- initialise_design_df( - items = 4, nrows = 3, ncols = 4, - block_nrows = 1, block_ncols = 4 - ) + df <- default_design(3, 4) df <- df[order(df$row, df$col), ] df$block <- factor(df$block) - Sigma <- cor_ar1_ar1(3, 4, 0.6, 0.3) + Sigma <- default_sigma(3, 4) for (covariance in list(NULL, Sigma)) { nuisance <- ~ . - treatment - row - col @@ -525,11 +500,8 @@ test_that("the default nuisance model requires at least two blocks", { }) test_that("explicit nuisance models can replace the block model", { - df <- initialise_design_df( - items = 4, nrows = 3, ncols = 4, - block_nrows = 1, block_ncols = 4 - ) - Sigma <- cor_ar1_ar1(3, 4, rho_row = 0.6, rho_col = 0.3) + df <- default_design(3, 4) + Sigma <- default_sigma(3, 4) original <- objective_function_info(df, "treatment", c("row", "col"), Sigma = Sigma) L <- compute_L_projection(df, Sigma) @@ -581,51 +553,37 @@ test_that("Sigma and L_matrix are mutually exclusive", { # ---- Test with speed function -test_that("speed() does not treat negative D-optimality scores as an optimum", { - df <- initialise_design_df( - items = 6, nrows = 4, ncols = 6, - block_nrows = 1, block_ncols = 6 - ) - Sigma <- cor_ar1_ar1(4, 6, rho_row = 0.6, rho_col = 0.3) +test_that("speed() optimises with D-optimality", { + df <- default_design() + Sigma <- default_sigma() - for (covariance in list(NULL, Sigma)) { - result <- speed( - df, - swap = "treatment", - swap_within = "block", - obj_function = objective_function_info, - criterion = "D", - Sigma = covariance, - iterations = 100, - early_stop_iterations = 200, - seed = 1, - quiet = TRUE - ) - final <- objective_function_info( - result$design_df, "treatment", c("row", "col"), - criterion = "D", Sigma = covariance - ) + result <- speed( + df, + swap = "treatment", + swap_within = "block", + obj_function = objective_function_info, + criterion = "D", + Sigma = Sigma, + iterations = 100, + early_stop_iterations = 200, + seed = 1, + quiet = TRUE + ) + final <- objective_function_info( + result$design_df, "treatment", c("row", "col"), + criterion = "D", Sigma = Sigma + ) - expect_lt(result$score, 0) - expect_equal(result$iterations_run, 100) - expect_identical(result$metadata$per_level[[1]]$stop_reason, "iterations") - expect_equal(result$score, final$score, tolerance = 1e-10) - if (is.null(covariance)) { - expect_equal(result$scores, rep(-5 * log(4), 100), tolerance = 1e-10) - } - } + expect_lt(result$score, 0) + expect_equal(result$iterations_run, 100) + expect_identical(result$metadata$per_level[[1]]$stop_reason, "iterations") + expect_equal(result$score, final$score, tolerance = 1e-10) }) # Actually test by passing to speed test_that("speed() optimises an RCBD with the info objective under AR1xAR1", { - skip_if_not_installed("speed") - - df <- initialise_design_df( - items = 6, nrows = 4, ncols = 6, - block_nrows = 1, block_ncols = 6 - ) - - Sigma <- cor_ar1_ar1(4, 6, rho_row = 0.6, rho_col = 0.3) + df <- default_design() + Sigma <- default_sigma() result <- speed( df, @@ -640,7 +598,6 @@ test_that("speed() optimises an RCBD with the info objective under AR1xAR1", { quiet = TRUE ) - expect_s3_class(result, "design") expect_lt(result$score, Inf) info <- objective_function_info( @@ -652,31 +609,3 @@ test_that("speed() optimises an RCBD with the info objective under AR1xAR1", { expect_equal(info$rank, 5) expect_true(is.finite(info$A_value)) }) - -test_that("speed() optimises a BIBD with the info objective", { - skip_if_not_installed("speed") - - df <- initialise_design_df( - items = 5, nrows = 3, ncols = 10, - block_nrows = 3, block_ncols = 1 - ) - - result <- speed( - df, - swap = "treatment", - spatial_factors = ~ block + row + col, - obj_function = objective_function_info, - criterion = "A", - optimise_params = optim_params(random_initialisation = TRUE), - seed = 42, - quiet = TRUE - ) - - info <- objective_function_info( - result$design_df, - "treatment", - c("row", "col") - ) - expect_equal(info$rank, 4) - expect_true(is.finite(info$A_value)) -})