* using log directory ‘/data/localhost/ripley/R/packages/tests-noLD/emhawkes.Rcheck’ * using R Under development (unstable) (2026-10-18 r90703) * using platform: x86_64-pc-linux-gnu * R was compiled by gcc (GCC) 16.2.1 20260819 (Red Hat 16.2.1-2) GNU Fortran (GCC) 16.2.1 20260819 (Red Hat 16.2.1-2) * running under: Fedora Linux 44 (Server Edition) * using session charset: UTF-8 * current time: 2026-10-18 14:44:58 UTC * using option ‘--no-stop-on-test-error’ * checking for file ‘emhawkes/DESCRIPTION’ ... OK * this is package ‘emhawkes’ version ‘1.0.1’ * package encoding: UTF-8 * checking package namespace information ... OK * checking package dependencies ... OK * checking if this is a source package ... OK * checking if there is a namespace ... OK * checking for executable files ... OK * checking for hidden files and directories ... OK * checking for portable file names ... OK * checking for sufficient/correct file permissions ... OK * checking whether package ‘emhawkes’ can be installed ... [55s/44s] OK * used C++ compiler: ‘g++ (GCC) 16.2.1 20260819 (Red Hat 16.2.1-2)’ * checking package directory ... OK * checking ‘build’ directory ... OK * checking DESCRIPTION meta-information ... OK * checking top-level files ... OK * checking for left-over files ... OK * checking index information ... OK * checking package subdirectories ... OK * checking code files for non-ASCII characters ... OK * checking R files for syntax errors ... OK * checking whether the package can be loaded ... OK * checking whether the package can be loaded with stated dependencies ... OK * checking whether the package can be unloaded cleanly ... OK * checking whether the namespace can be loaded with stated dependencies ... OK * checking whether the namespace can be unloaded cleanly ... OK * checking loading without being on the library search path ... OK * checking whether startup messages can be suppressed ... OK * checking use of S3 registration ... OK * checking dependencies in R code ... OK * checking S3 generic/method consistency ... OK * checking replacement functions ... OK * checking foreign function calls ... OK * checking R code for possible problems ... [14s/30s] OK * checking Rd files ... OK * checking Rd metadata ... OK * checking Rd line widths ... OK * checking Rd cross-references ... OK * checking for missing documentation entries ... OK * checking for code/documentation mismatches ... OK * checking Rd \usage sections ... OK * checking Rd contents ... OK * checking for unstated dependencies in examples ... OK * checking line endings in C/C++/Fortran sources/headers ... OK * checking line endings in Makefiles ... OK * checking compilation flags in Makevars ... OK * checking for GNU extensions in Makefiles ... OK * checking for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) ... OK * checking use of PKG_*FLAGS in Makefiles ... OK * checking use of SHLIB_OPENMP_*FLAGS in Makefiles ... OK * checking pragmas in C/C++ headers and code ... OK * checking compilation flags used ... OK * checking compiled code ... OK * checking installed files from ‘inst/doc’ ... OK * checking files in ‘vignettes’ ... OK * checking examples ... OK * checking for unstated dependencies in ‘tests’ ... OK * checking tests ... Running ‘auto-function-engine.R’ Running ‘baseline-dispatch.R’ [6s/13s] Running ‘baseline-projection.R’ Running ‘callback-history-context.R’ Running ‘computation-regressions.R’ Running ‘constraint-alias.R’ Running ‘curvature-stress.R’ Running ‘expected-wait.R’ Running ‘fit-computation.R’ Running ‘fit-curvature.R’ Running ‘fit-messages.R’ Running ‘fit-rds-session.R’ Running ‘fit-reconstruction.R’ [5s/11s] Running ‘function-gradient.R’ Running ‘function-numeric.R’ Running ‘function-replay.R’ Running ‘initialization.R’ Running ‘interfaces.R’ Running ‘loglik-inference.R’ Running ‘native-callback-simulation.R’ Running ‘native-engine.R’ Running ‘native-fit.R’ [9s/19s] Running ‘native-gradient.R’ Running ‘native-simulation.R’ Running ‘native-unequal-simulation.R’ Running ‘native-unwind.R’ Running ‘observed-impact-gradient.R’ Running ‘observed-impact-numeric.R’ Running ‘observed-impact-replay.R’ Running ‘r-callback-dispatch.R’ Running ‘realization-print.R’ Running ‘s4-minimal-session.R’ Running ‘signed-components.R’ Running ‘simulation-decay-reuse.R’ Running ‘simulation-dispatch.R’ Running ‘simulation-subnormal.R’ Running ‘stable-final-hessian.R’ [7s/13s] Running ‘state-gradient.R’ Running ‘state-impact-numeric.R’ Running ‘state-replay.R’ Running ‘stats-isolated-session.R’ Running ‘stats-optimizer.R’ Running ‘tzexp-distribution.R’ Running ‘user-diagnostics.R’ Running ‘volatility.R’ [101s/202s] ERROR Running the tests in ‘tests/initialization.R’ failed. Complete output: > library(emhawkes) > > capture_initial <- function(expr) { + messages <- character(0) + value <- withCallingHandlers(force(expr), message = function(m) { + messages <<- c(messages, conditionMessage(m)); invokeRestart("muffleMessage") + }) + list(value = value, messages = messages) + } > fails_initial <- function(expr, pattern) { + result <- tryCatch(force(expr), error = identity) + stopifnot(inherits(result, "error"), grepl(pattern, conditionMessage(result))) + } > close_initial <- function(a, b, tolerance = 1e-10) + stopifnot(isTRUE(all.equal(as.numeric(a), as.numeric(b), tolerance = tolerance))) > old_initial_options <- options(emhawkes.engine = "auto") > u <- new("hspec", mu = 1, alpha = .4, beta = 1) > set.seed(814) > rng <- .Random.seed > one <- capture_initial(hsim(u, 1)) > stopifnot(identical(rng, .Random.seed), length(one$messages) == 1L, + grepl("auto -> mean", one$messages)) > close_initial(one$value$lambda_component[1, ], 2 / 3) > close_initial(one$value$lambda[1, ], 5 / 3) > close_initial(capture_initial(hsim(u, 1, lambda_component0 = NULL))$value$lambda, 5 / 3) > > # Verify stationary balance independently, including overlapping mappings. > models <- list(u, + new("hspec", mu = c(.7, 1), alpha = matrix(c(.12, .03, .04, .1), 2), beta = matrix(1.5, 2, 2)), + new("hspec", mu = c(.7, 1), alpha = matrix(seq(.01, .08, .01), 2, 4), beta = matrix(1.5, 2, 4), + type_col_map = list(c(1, 2, 3), c(2, 4)))) > for (h in models) { + out <- capture_initial(hsim(h, 1))$value + components <- matrix(out$lambda_component[1, ], h@dimens, byrow = TRUE) + rates <- as.vector(out$lambda[1, ]) + mapping <- if (is.null(h@type_col_map)) as.list(seq_len(h@dimens)) else h@type_col_map + expected <- matrix(0, nrow(h@beta), ncol(h@beta)) + for (j in seq_len(h@dimens)) expected[, mapping[[j]]] <- + expected[, mapping[[j]], drop = FALSE] + h@alpha[, mapping[[j]], drop = FALSE] / h@beta[, mapping[[j]], drop = FALSE] * rates[j] + close_initial(components, expected) + for (seed in c(1, 29, 704)) { + set.seed(seed); auto <- capture_initial(hsim(h, 41))$value; rng <- .Random.seed + set.seed(seed); explicit <- hsim(h, 41, lambda_component0 = components) + stopifnot(identical(auto, explicit), identical(rng, .Random.seed)) + set.seed(seed); reference <- capture_initial(emhawkes:::simulate_hawkes_r(h, 41))$value + stopifnot(identical(auto, reference), identical(rng, .Random.seed)) + for (engine in c("r", "cpp")) { + options(emhawkes.engine = engine) + replay <- capture_initial(logLik(h, auto$inter_arrival, auto$type, auto$mark, infer = TRUE))$value + stopifnot(identical(auto$lambda, replay$lambda), identical(auto$rambda, replay$rambda)) + } + } + } Error: identical(auto, reference) is not TRUE Execution halted Running the tests in ‘tests/native-callback-simulation.R’ failed. Complete output: > library(emhawkes) > r_sim <- getFromNamespace("simulate_hawkes_r", "emhawkes") > capture <- function(expr) { + warnings <- character() + value <- tryCatch(withCallingHandlers(force(expr), warning = function(w) { + warnings <<- c(warnings, conditionMessage(w)); invokeRestart("muffleWarning") + }), error = function(e) list(error = conditionMessage(e))) + list(value = value, warnings = warnings, seed = if (exists(".Random.seed", .GlobalEnv)) .Random.seed) + } > compare <- function(h, size = 31L, initial = .02, seed = 7361L) { + set.seed(seed) + old <- capture(r_sim(h, size, lambda_component0 = initial, N0 = 2, Nc0 = 5)) + set.seed(seed) + new <- capture(hsim(h, size, lambda_component0 = initial, N0 = 2, Nc0 = 5)) + if (!identical(old, new)) stop("Callback simulation mismatch at size=", size, + ", seed=", seed, ": ", paste(all.equal(old, new, tolerance = 0), collapse = "; ")) + new$value + } > models <- list() > for (d in c(1L, 2L, 4L)) for (k in unique(c(d, 2L * d))) local({ + h <- new("hspec", mu = seq(.3, .6, length.out = d), + alpha = matrix(.03 / k, d, k), beta = matrix(rep(seq(.8, 1.7, length.out = d), k), d), + type_col_map = if (k == d) NULL else lapply(seq_len(d), function(i) rev(c(i, i + d)))) + variants <- list( + current = function(lambda_component_n, param = c(scale = .02), unused = stop("unused")) + param[1] * lambda_component_n, + hidden_rng = function(lambda_component_n) .01 * lambda_component_n + runif(1, 0, .001), + no_args = function() matrix(0, d, k)) + for (name in names(variants)) { + x <- h; x@impact <- variants[[name]] + models[[paste(d, k, name)]] <<- x + } + h@rmark <- function(param = c(p = .7), unused = stop("unused")) rgeom(1, param[1]) + 1 + h@eta <- matrix(.002 / k, d, k) + models[[paste(d, k, "marked")]] <<- h + h@impact <- variants$current + models[[paste(d, k, "combined")]] <<- h + }) > models$signed <- new("hspec", mu = c(.2, .3), alpha = matrix(0, 2, 2), + beta = matrix(1, 2, 2), impact = function(lambda_component_n) { + matrix(rep(.1 - rowSums(lambda_component_n), 2), 2) + }) > saved_rng <- RNGkind() > for (kind in c("Mersenne-Twister", "L'Ecuyer-CMRG")) { + RNGkind(kind, "Inversion", "Rejection") + for (h in models) for (size in c(1L, 2L, 31L, 251L)) for (seed in c(1L, 62L, 7361L)) + compare(h, size, seed = seed) + } Error in compare(h, size, seed = seed) : Callback simulation mismatch at size=31, seed=62: Component "value": Component "inter_arrival": Mean relative difference: 3.364601e-16; Component "value": Component "lambda": Mean relative difference: 1.747034e-16; Component "value": Component "rambda": Mean relative difference: 1.776347e-16 Execution halted Running the tests in ‘tests/native-fit.R’ failed. Complete output: > # Legacy optimizer checks require the optional maxLik package. > if (requireNamespace("maxLik", quietly = TRUE)) { + library(emhawkes) + + fit_engine <- function(engine, ...) { + previous <- options(emhawkes.engine = engine) + on.exit(options(previous)) + suppressMessages(hfit(...)) + } + set.seed(105) + truth <- new("hspec", mu = c(.3, .25), alpha = matrix(c(.15, .05, .04, .1), 2), + beta = matrix(1.5, 2, 2)) + path <- hsim(truth, size = 701, lambda_component0 = .1) + start <- truth + start@mu[] <- .2 + map <- getFromNamespace("build_parameter_map", "emhawkes") + for (reduced in c(TRUE, FALSE)) { + parameters <- map(start, reduced)$start + fixed <- startsWith(names(parameters), "beta") + fit <- function(engine) fit_engine(engine, start, path$inter_arrival, path$type, + lambda_component0 = .1, reduced = reduced, fixed = fixed, + constraints = list(ineqA = diag(length(parameters)), ineqB = rep(-1e-6, length(parameters))), + control = list(iterlim = 200, reltol = 1e-9)) + reference <- fit("r") + native <- fit("cpp") + stopifnot(inherits(native, "maxLik"), reference$code == native$code, + identical(names(coef(reference)), names(coef(native))), + abs(as.numeric(logLik(reference)) - as.numeric(logLik(native))) < 1e-7, + max(abs(coef(reference) - coef(native))) < 1e-4) + } + + # Custom derivatives still pass through to maxLik. The Poisson special case + # has a closed-form optimum, independent of the Hawkes recurrence. + calls <- c(gradient = 0L, hessian = 0L) + gradient <- function(param) { + calls["gradient"] <<- calls["gradient"] + 1L + c(5 / param[1] - 3, 0, 0) + } + hessian <- function(param) { + calls["hessian"] <<- calls["hessian"] + 1L + diag(c(-5 / param[1]^2, 0, 0)) + } + poisson <- new("hspec", mu = 1, alpha = 0, beta = 1) + fit <- fit_engine("cpp", poisson, c(0, .2, .3, .5, 1, 1), lambda_component0 = 0, + fixed = c(FALSE, TRUE, TRUE), grad = gradient, hess = hessian, method = "NR") + stopifnot(all(calls > 0), abs(coef(fit)[1] - 5 / 3) < 1e-7) + + } Error: abs(as.numeric(logLik(reference)) - as.numeric(logLik(native))) < .... is not TRUE Execution halted Running the tests in ‘tests/native-simulation.R’ failed. Complete output: > library(emhawkes) > r_sim <- getFromNamespace("simulate_hawkes_r", "emhawkes") > data_only <- function(x) x[setdiff(names(x), "hspec")] > same <- function(h, size, initial, seed, N0 = c(2), Nc0 = c(5)) { + # Function environments can force existing promises during evaluation. + numeric_model <- !any(vapply(methods::slotNames(h), function(name) + is.function(methods::slot(h,name)),logical(1))) + before_object <- if(numeric_model) serialize(h, NULL) else NULL + capture <- function(expr) { + warnings <- character() + value <- withCallingHandlers(force(expr),warning=function(w) { + warnings <<- c(warnings,conditionMessage(w));invokeRestart("muffleWarning") + }) + list(value=value,warnings=warnings) + } + set.seed(seed) + reference <- capture(r_sim(h, size, lambda_component0 = initial, N0 = N0, Nc0 = Nc0)) + rng <- .Random.seed + set.seed(seed) + native <- capture(hsim(h, size, lambda_component0 = initial, N0 = N0, Nc0 = Nc0)) + stopifnot(identical(data_only(reference$value), data_only(native$value)), + identical(rng, .Random.seed),identical(reference$warnings,native$warnings)) + if(numeric_model) stopifnot(identical(before_object, serialize(h, NULL))) + native$value + } > models <- list() > for (d in c(1L, 2L, 3L, 4L, 8L)) for (k in unique(c(1L, d, 2L*d, 5L))) { + mapping <- if (k == d) NULL else lapply(seq_len(d), function(i) rev(unique(c(i %% k + 1L, k)))) + h <- new("hspec", mu = seq(.3, .7, length.out = d), alpha = matrix(.06 / k, d, k), + beta = matrix(rep(seq(.8, 1.9, length.out = d), k), d, k), type_col_map = mapping) + models[[paste(d, k, sep = ":")]] <- h + } > models$signed <- new("hspec", mu = c(.2, .3), + alpha = matrix(c(.08,-.04,.05,-.02,.05,-.02,.08,-.04),2,byrow=TRUE), + beta = matrix(c(1.1,1.5),2,4), type_col_map = list(c(2L,1L),c(4L,3L))) > models$poisson <- new("hspec", mu=.5,alpha=0,beta=1) > models$slow <- new("hspec",mu=1e-6,alpha=2e-7,beta=1e-5) > models$fast <- new("hspec",mu=1e5,alpha=1e3,beta=1e6) > saved_rng <- RNGkind() > for (kind in c("Mersenne-Twister", "L'Ecuyer-CMRG")) { + RNGkind(kind, "Inversion", "Rejection") + for (h in models) for (size in c(1L,2L,31L,251L)) for (seed in c(1L,62L,7361L)) { + initial <- if (identical(h,models$signed)) h@alpha/2 else .03/ncol(h@beta) + same(h,size,initial,seed,N0=seq_len(h@dimens),Nc0=seq_len(h@dimens)+2) + } + } Error in same(h, size, initial, seed, N0 = seq_len(h@dimens), Nc0 = seq_len(h@dimens) + : identical(data_only(reference$value), data_only(native$value)) is not TRUE Calls: same -> stopifnot Execution halted Running the tests in ‘tests/native-unequal-simulation.R’ failed. Complete output: > library(emhawkes) > r_sim <- getFromNamespace("simulate_hawkes_r","emhawkes") > compare <- function(h,size,initial,seed) { + before <- serialize(h,NULL) + capture <- function(expr) { + warnings <- character() + value <- withCallingHandlers(tryCatch(force(expr),error=identity),warning=function(w) { + warnings <<- c(warnings,conditionMessage(w));invokeRestart("muffleWarning") + }) + list(value=value,warnings=warnings) + } + set.seed(seed) + ref <- capture(r_sim(h,size,lambda_component0=initial,N0=2,Nc0=5));rng <- .Random.seed + set.seed(seed) + out <- capture(hsim(h,size,lambda_component0=initial,N0=2,Nc0=5)) + stopifnot(identical(rng,.Random.seed),identical(ref$warnings,out$warnings), + identical(before,serialize(h,NULL))) + if(inherits(ref$value,"error")) { + stopifnot(inherits(out$value,"error"),identical(conditionMessage(ref$value),conditionMessage(out$value))) + } else stopifnot(identical(ref$value,out$value)) + out$value + } > models <- list() > for(d in c(1L,2L,4L,8L)) for(k in unique(c(2L,d,2L*d,5L))) { + mapping <- if(k==d) NULL else lapply(seq_len(d),function(i) rev(unique(c(i%%k+1L,k)))) + beta <- outer(seq(.7,1.4,length.out=d),seq(.5,2,length.out=k)) + # One equal-rate row must also use thinning when another row is unequal. + if(d>1) beta[1,] <- 1 + models[[paste(d,k,sep=":")]] <- new("hspec",mu=seq(.1,.5,length.out=d), + alpha=matrix(.1/k,d,k),beta=beta,type_col_map=mapping) + } > models$signed <- new("hspec",mu=c(.2,.3), + alpha=matrix(c(.08,-.02,.08,-.02),2,4,byrow=TRUE), + beta=matrix(c(1,2,1,2),2,4,byrow=TRUE),type_col_map=list(c(2L,1L),c(4L,3L))) > permutation <- c(4L,1L,3L,2L) > models$permuted <- new("hspec",mu=models$signed@mu, + alpha=models$signed@alpha[,permutation],beta=models$signed@beta[,permutation], + type_col_map=list(c(4L,2L),c(1L,3L))) > models$rejection <- new("hspec",mu=c(.01,.02),alpha=matrix(.1,2,4), + beta=matrix(seq(10,80,length.out=8),2,4),type_col_map=list(1:2,3:4)) > saved <- RNGkind() > for(kind in c("Mersenne-Twister","L'Ecuyer-CMRG")) { + RNGkind(kind,"Inversion","Rejection") + for(h in models) for(size in c(1L,2L,31L,251L)) for(seed in c(1L,62L,7361L)) { + initial <- if(any(h@alpha<0)) h@alpha/2 else .03/ncol(h@beta) + if(identical(h,models$rejection)) initial <- 2 + compare(h,size,initial,seed) + } + } Error in compare(h, size, initial, seed) : identical(ref$value, out$value) is not TRUE Calls: compare -> stopifnot Execution halted Running the tests in ‘tests/simulation-decay-reuse.R’ failed. Complete output: > library(emhawkes) > r_sim <- getFromNamespace("simulate_hawkes_r", "emhawkes") > > # Wide mapped kernels expose accidental cross-row reuse or changed component > # summation. Compare the complete public result and RNG with the R reference. > for (d in c(1L, 4L)) for (k in c(16L, 32L, 128L)) { + mapping <- lapply(seq_len(d), function(i) rev(seq(i, k, by = d))) + h <- new("hspec", mu = seq(.3, .7, length.out = d), + alpha = matrix(.35 / k, d, k), + beta = matrix(rep(seq(.8, 1.9, length.out = d), k), d, k), + type_col_map = mapping) + initial <- matrix(seq(.01, .03, length.out = d * k) / k, d, k) + for (callback in c(FALSE, TRUE)) { + model <- h + if (callback) { + model@impact <- function(lambda_component_n) .006 * lambda_component_n + model@rmark <- function() runif(1, .5, 1.5) + model@eta <- matrix(.001 / k, d, k) + } + for (size in c(1L, 2L, 251L)) for (seed in c(62L, 7361L)) { + set.seed(seed) + expected <- r_sim(model, size, lambda_component0 = initial, N0 = 2, Nc0 = 5) + rng <- .Random.seed + set.seed(seed) + actual <- hsim(model, size, lambda_component0 = initial, N0 = 2, Nc0 = 5) + stopifnot(identical(expected, actual), identical(rng, .Random.seed)) + } + # Independently reconstruct every component before and after each event. + for (engine in c("r", "cpp")) { + old <- options(emhawkes.engine = engine) + replay <- logLik(model, actual$inter_arrival, actual$type, actual$mark, + lambda_component0 = initial, N0 = 2, Nc0 = 5, infer = TRUE) + options(old) + for (field in c("lambda", "rambda", "lambda_component", "rambda_component")) + stopifnot(identical(actual[[field]], replay[[field]])) + stopifnot(identical(rng, .Random.seed)) + } + } + } Error: identical(expected, actual) is not TRUE Execution halted Running the tests in ‘tests/state-impact-numeric.R’ failed. Complete output: > library(emhawkes) > old_options <- options(emhawkes.engine = "r") > old_jit <- compiler::enableJIT(0) > map_for <- emhawkes:::build_parameter_map > normalize <- emhawkes:::normalize_observation > objective <- emhawkes:::make_hawkes_objective > close <- function(x, y, tolerance = 1e-10) stopifnot(isTRUE(all.equal(as.numeric(x), as.numeric(y), tolerance = tolerance))) > fails <- function(expr, pattern) { + error <- tryCatch(force(expr), error = identity) + stopifnot(inherits(error, "error"), grepl(pattern, conditionMessage(error), ignore.case = TRUE)) + } > dt <- c(0, .3, 0, .7, .2, 1.1, .05) > type <- c(0, 1, 2, 2, 1, 2, 1) > mark <- c(0, 1, 3, .5, 2, 1, 2.5) > records <- list() > mu <- function(param = c(q = .2), n, Nc, ...) { + previous <- if (n == 1L) Nc[1, ] else Nc[n - 1L, ] + matrix(exp(param["q"]) * c(.5, .6) + .01 * previous, 2) + } > impact <- function(param = c(q = .2), n, N, Nc, mark, type, inter_arrival, + lambda_component_n, lambda, lambda_component, mu, alpha, beta, + extra = .001, ...) { + # Both full histories include the current pre-jump row. Future rows are zero. + stopifnot(identical(colnames(lambda), c("lambda1", "lambda2")), + identical(colnames(lambda_component), c("lambda11", "lambda12", "lambda13", "lambda21", "lambda22", "lambda23")), + is.function(mu)) + close(matrix(lambda_component[n, ], 2, byrow = TRUE), lambda_component_n, 0) + close(lambda[n, ], as.vector(mu(n = n, Nc = Nc)) + rowSums(lambda_component_n), 0) + if (n < length(mark)) { + stopifnot(all(lambda[(n + 1):length(mark), ] == 0), all(lambda_component[(n + 1):length(mark), ] == 0)) + } + records[[length(records) + 1L]] <<- list(n = n, current = lambda_component_n, + lambda = lambda, components = lambda_component, local = param, N = N, Nc = Nc) + value <- .02 * param["q"] + extra * (Nc[n, 1] - N[n - 1, 2]) - .03 * lambda_component_n + + matrix(c(-.01, .01, .02, 0, -.02, .01), 2) + # Local writes and retained arguments must not corrupt recursive storage. + lambda_component_n[1, 1] <- 999 + lambda_component[n, 1] <- 999 + lambda[n, 1] <- 999 + value + } > h <- new("hspec", mu = mu, alpha = matrix(c(.08, -.02, .12, .06, .03, .09), 2), + beta = matrix(c(.7, 1.1, 2.3, .9, 3.1, .9), 2), eta = matrix(.01, 2, 3), + impact = impact, type_col_map = list(c(3, 1), c(3, 2))) > initial <- matrix(c(.11, -.03, .07, .13, -.02, .08), 2) > obs <- normalize(h, dt, type, mark, N0 = c(2, 3), Nc0 = c(4, 5)) > reference <- function(model, point, initial = initial, reduced = TRUE) { + map <- map_for(model, reduced) + candidate <- model + for (name in names(map$components)) slot(candidate, name) <- emhawkes:::restore_parameters(map, point)[[name]] + suppressMessages(logLik(candidate, dt, type, mark, N0 = c(2, 3), Nc0 = c(4, 5), lambda_component0 = initial)) + } > set.seed(519) > seed <- .Random.seed > snap <- serialize(h, NULL) > for (reduced in c(TRUE, FALSE)) { + map <- map_for(h, reduced) + for (point in list(map$start, map$start + .001)) { + records <- list() + ref <- reference(h, point, initial, reduced) + expected <- records + records <- list() + fun <- objective(h, obs, initial, map, derivatives = FALSE) + close(fun$loglik(point), ref, 1e-12) + stopifnot(identical(records, expected)) # Includes retained snapshots and names. + count <- length(records) + close(fun$loglik(rev(point)), ref, 1e-12) + stopifnot(length(records) == count) + } + } > stopifnot(identical(seed, .Random.seed), identical(snap, serialize(h, NULL))) > > # Independent full-history reference with feedback and an observed baseline. > independent <- function() { + times <- cumsum(dt) + horizon <- tail(times, 1) + W <- function(t) -expm1(-h@beta * t) / h@beta + total <- -sum(initial * W(horizon)) + jumps <- list() + for (n in 2:length(dt)) { + baseline <- mu(n = n, Nc = obs$Nc) + state <- initial * exp(-h@beta * times[n]) + if (n > 2) for (k in 2:(n - 1)) state <- state + jumps[[k - 1]] * exp(-h@beta * (times[n] - times[k])) + total <- total + log(baseline[type[n]] + sum(state[type[n], ])) - sum(baseline * dt[n]) + extra <- .02 * .2 + .001 * (obs$Nc[n, 1] - obs$N[n - 1, 2]) - .03 * state + matrix(c(-.01, .01, .02, 0, -.02, .01), 2) + jump <- h@alpha + h@eta * (mark[n] - 1) + extra + unused <- setdiff(1:3, h@type_col_map[[type[n]]]) + jump[, unused] <- 0 + jumps[[n - 1]] <- jump + total <- total - sum(jump * W(horizon - times[n])) + } + total + } > map <- map_for(h, TRUE) > fun <- objective(h, obs, initial, map, derivatives = FALSE) > close(fun$loglik(map$start), independent(), 1e-12) > > # Public hfit dispatch: keep only q free to make the short fit well specified. > if (requireNamespace("maxLik", quietly = TRUE)) { + a <- list(object = h, inter_arrival = dt, type = type, mark = mark, + N0 = c(2, 3), Nc0 = c(4, 5), lambda_component0 = initial, + fixed = names(map$start) != "q", control = list(iterlim = 3)) + fit_with <- function(engine) { + options(emhawkes.engine = engine) + suppressWarnings(suppressMessages(do.call(hfit, c(a, list(jacobian = quote(stop("unused Jacobian"))))))) + } + r <- fit_with("r") + cpp <- fit_with("cpp") + close(coef(cpp), coef(r), 1e-8) + close(logLik(cpp), logLik(r), 1e-11) + close(cpp$hessian, r$hessian, 1e-3) + stopifnot(attr(cpp, "emhawkes")$gradient == "numeric", is.null(attr(cpp, "emhawkes")$jacobian)) + options(emhawkes.engine = "r") + close(suppressMessages(do.call(logLik, c(list(object = fitted_hspec(cpp), inter_arrival = dt, type = type, mark = mark), fit_initial_state(cpp)))), logLik(cpp), 1e-11) + } Error in close(lambda[n, ], as.vector(mu(n = n, Nc = Nc)) + rowSums(lambda_component_n), : isTRUE(all.equal(as.numeric(x), as.numeric(y), tolerance = tolerance)) is not TRUE Calls: fit_with Execution halted Running the tests in ‘tests/state-replay.R’ failed. Complete output: > library(emhawkes) > old <- options(emhawkes.engine = "auto") > old_jit <- compiler::enableJIT(0L) > evaluate <- function(engine, object, dt, infer = TRUE, initial = .1, ...) { + previous <- options(emhawkes.engine = engine) + on.exit(options(previous)) + suppressMessages(logLik(object, dt, infer = infer, lambda_component0 = initial, ...)) + } > close <- function(a, b, tolerance = 1e-11) stopifnot(isTRUE(all.equal(a, b, tolerance = tolerance))) > fails <- function(expr, pattern) { + e <- tryCatch(force(expr), error = identity) + stopifnot(inherits(e, "error"), grepl(pattern, conditionMessage(e), ignore.case = TRUE)) + } > native <- getFromNamespace("hawkes_loglik_cpp", "emhawkes") > native_calls <- 0L > assignInNamespace("hawkes_loglik_cpp", function(...) { native_calls <<- native_calls + 1L; native(...) }, "emhawkes") > # An independent piecewise-constant baseline fixes pre/post intensity, likelihood > # and residuals, including the terminal next baseline after the final event. > mu_calls <- integer() > mu <- function(param = c(m = .2), n, N, ...) { + mu_calls <<- c(mu_calls, n) + matrix(param + .01 * N[max(1L, n - 1L), ], 2) + } > h <- new("hspec", mu = mu, alpha = matrix(0, 2, 2), beta = matrix(c(.7, 1.1, 1.7, 2), 2)) > dt <- c(0, .2, .3, .4, .1, .5) > types <- c(0, 1, 2, 1, 1, 2) > counts <- cbind(2 + cumsum(types == 1), 3 + cumsum(types == 2)) > pre <- t(vapply(seq_along(dt), function(n) .2 + .01 * counts[max(1L, n - 1L), ], numeric(2))) > post <- rbind(pre[1, ], .2 + .01 * counts[-1, , drop = FALSE]) > phi <- pre * dt > expected <- sum(log(pre[cbind(2:length(dt), types[-1])])) - sum(phi) > for (initial in list(0, NULL)) for (infer in c(FALSE, TRUE)) for (engine in c("r", "auto", "cpp")) { + mu_calls <- integer(); native_calls <- 0L + value <- evaluate(engine, h, dt, infer, initial, type = types, N0 = c(2, 3)) + close(as.numeric(if (infer) value$loglikelihood else value), expected) + stopifnot(identical(as.integer(mu_calls), c(1L, seq.int(2L, length(dt) + 1L)))) + stopifnot(native_calls == if (engine == "r") 0L else 1L) + if (infer) { + close(unname(value$lambda), unname(pre)) + close(unname(value$rambda), unname(post)) + stopifnot(all(value$lambda_component == 0), all(value$rambda_component == 0)) + for (k in 1:2) close(value[[paste0("res_process", k)]], diff(cumsum(phi[, k])[which(types == k)])) + } + } > # State feedback, marks, maps and named/attributed kernels. Same-name defaults > # in mu, beta and impact intentionally have different values. > records <- list() > mu <- function(param = c(q = .2), n, Nc, ...) { + previous <- Nc[max(1L, n - 1L), ] + matrix(exp(param) * c(.5, .6) + .01 * previous, 2) + } > beta <- function(param = c(q = .9)) { + x <- matrix(param + c(.7, 1.1, 2.3, .9, 3.1, .9), 2, + dimnames = list(c("up", "down"), c("A", "B", "C"))) + attr(x, "label") <- "decay" + x + } > impact <- function(param = c(q = .03), n, N, Nc, lambda_component_n, lambda, lambda_component, mu, alpha, beta, ...) { + stopifnot(is.function(mu), identical(dimnames(lambda_component_n), dimnames(beta)), + identical(attr(lambda_component_n, "label"), "decay"), + identical(colnames(lambda), c("lambda1", "lambda2")), + identical(colnames(lambda_component), c("lambda11", "lambda12", "lambda13", "lambda21", "lambda22", "lambda23"))) + close(as.vector(matrix(lambda_component[n, ], 2, byrow = TRUE)), as.vector(lambda_component_n), 0) + close(as.numeric(lambda[n, ]), as.vector(mu(n = n, Nc = Nc)) + as.vector(rowSums(lambda_component_n)), 0) + if (n < length(N[, 1])) stopifnot(all(lambda[(n + 1L):nrow(lambda), ] == 0), + all(lambda_component[(n + 1L):nrow(lambda_component), ] == 0)) + records[[length(records) + 1L]] <<- list(n = n, current = lambda_component_n, + lambda = lambda, components = lambda_component, param = param) + value <- .02 * param + .001 * (Nc[n, 1] - N[n - 1L, 2]) - .03 * lambda_component_n + + .001 * lambda_component_n["up", "A"] + lambda_component_n[1, 1] <- 999 + lambda_component[n, 1] <- 999 + lambda[n, 1] <- 999 + alpha[1, 1] <- 999 + beta[1, 1] <- 999 + value + } > h <- new("hspec", mu = mu, alpha = matrix(c(.08, -.02, .12, .06, .03, .09), 2), + beta = beta, eta = matrix(.01, 2, 3), impact = impact, + type_col_map = list(c(3, 1), c(3, 2))) > dt <- c(0, .3, 0, .7, .2, 1.1, .05) > types <- c(0, 1, 2, 2, 1, 2, 1) > marks <- c(0, 1, 3, .5, 2, 1, 2.5) > initial <- matrix(c(.11, -.03, .07, .13, -.02, .08), 2) > for (infer in c(FALSE, TRUE)) { + records <- list() + reference <- evaluate("r", h, dt, infer, initial, type = types, mark = marks, N0 = c(2, 3), Nc0 = c(4, 5)) + expected_records <- records + for (engine in c("auto", "cpp")) { + records <- list(); native_calls <- 0L + close(evaluate(engine, h, dt, infer, initial, type = types, mark = marks, N0 = c(2, 3), Nc0 = c(4, 5)), reference) + stopifnot(identical(records, expected_records), native_calls == 1L) + } + } > # The R block-kernel cache and a named numeric beta have the same semantics. > long_dt <- c(0, rep(dt[-1], length.out = 39L)) > long_types <- c(0, rep(types[-1], length.out = 39L)) > long_marks <- c(0, rep(marks[-1], length.out = 39L)) > named_numeric <- h > named_numeric@beta <- emhawkes:::evalf(h@beta) > model_before <- serialize(named_numeric, NULL) > reference <- evaluate("r", named_numeric, long_dt, TRUE, initial, + type = long_types, mark = long_marks, N0 = c(2, 3), Nc0 = c(4, 5)) > close(evaluate("cpp", named_numeric, long_dt, TRUE, initial, + type = long_types, mark = long_marks, N0 = c(2, 3), Nc0 = c(4, 5)), reference) Error in close(as.numeric(lambda[n, ]), as.vector(mu(n = n, Nc = Nc)) + : isTRUE(all.equal(a, b, tolerance = tolerance)) is not TRUE Calls: close ... hawkes_loglik_cpp -> native -> -> close -> stopifnot Execution halted * checking for unstated dependencies in vignettes ... OK * checking package vignettes ... OK * checking re-building of vignette outputs ... [9s/16s] OK * checking PDF version of manual ... OK * checking HTML version of manual ... OK * checking for non-standard things in the check directory ... OK * checking for detritus in the temp directory ... OK * DONE Status: 1 ERROR See ‘/data/localhost/ripley/R/packages/tests-noLD/emhawkes.Rcheck/00check.log’ for details. Command exited with non-zero status 1 Time 5:54.52, 194.23 + 14.76