R Under development (unstable) (2024-09-15 r87152 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(testthat) > Sys.setenv('OMP_THREAD_LIMIT'=2) > library(rlibkriging) Attaching package: 'rlibkriging' The following objects are masked from 'package:base': load, save > > ##library(rlibkriging, lib.loc="bindings/R/Rlibs") > ##library(testthat) > > # f <- function(X) apply(X, 1, function(x) prod(sin((x-.5)^2))) > f <- function(X) apply(X, 1, function(x) + prod(sin(2*pi*( x * (seq(0,1,l=1+length(x))[-1])^2 ))) + ) > n <- 20 > set.seed(123) > X <- cbind(runif(n),runif(n)) > y <- f(X) > d = ncol(X) > > x=seq(0,1,,5) > contour(x,x,matrix(f(as.matrix(expand.grid(x,x))),nrow=length(x)),nlevels = 30) > points(X) > > k <- Kriging(y, X,"gauss",parameters = list(theta=matrix(runif(40),ncol=2))) > print(k) * data: 20x[0.0420595,0.956833],[0.0246137,0.99427] -> 20x[-0.884835,0.990808] * trend constant (est.): 0.254277 * variance (est.): 0.480222 * covariance: * kernel: gauss * range (est.): 0.921711, 0.286891 * fit: * objective: LL * optim: BFGS > > unlink("k.json") > rlibkriging::save(k, filename="k.json") > > k2 <- rlibkriging::load(filename="k.json") > print(k2) * data: 20x[0.0420595,0.956833],[0.0246137,0.99427] -> 20x[-0.884835,0.990808] * trend constant (est.): 0.254277 * variance (est.): 0.480222 * covariance: * kernel: gauss * range (est.): 0.921711, 0.286891 * fit: * objective: LL * optim: BFGS > > test_that("Save/Load NuggetKriging", expect_true( print(k) == print(k2))) * data: 20x[0.0420595,0.956833],[0.0246137,0.99427] -> 20x[-0.884835,0.990808] * trend constant (est.): 0.254277 * variance (est.): 0.480222 * covariance: * kernel: gauss * range (est.): 0.921711, 0.286891 * fit: * objective: LL * optim: BFGS * data: 20x[0.0420595,0.956833],[0.0246137,0.99427] -> 20x[-0.884835,0.990808] * trend constant (est.): 0.254277 * variance (est.): 0.480222 * covariance: * kernel: gauss * range (est.): 0.921711, 0.286891 * fit: * objective: LL * optim: BFGS Test passed 🎉 > > nuk <- NuggetKriging(y, X,"gauss",parameters = list(theta=matrix(runif(40),ncol=2))) > print(nuk) * data: 20x[0.0420595,0.956833],[0.0246137,0.99427] -> 20x[-0.884835,0.990808] * trend constant (est.): 0.254277 * variance (est.): 0.480222 * covariance: * kernel: gauss * range (est.): 0.92171, 0.286891 * nugget (est.): 0 * fit: * objective: LL * optim: BFGS > > unlink("nuk.json") > rlibkriging::save(nuk, filename="nuk.json") > > nuk2 <- rlibkriging::load(filename="nuk.json") > print(nuk2) * data: 20x[0.0420595,0.956833],[0.0246137,0.99427] -> 20x[-0.884835,0.990808] * trend constant (est.): 0.254277 * variance (est.): 0.480222 * covariance: * kernel: gauss * range (est.): 0.92171, 0.286891 * nugget (est.): 0 * fit: * objective: LL * optim: BFGS > > test_that("Save/Load NuggetKriging", expect_true( print(nuk) == print(nuk2))) * data: 20x[0.0420595,0.956833],[0.0246137,0.99427] -> 20x[-0.884835,0.990808] * trend constant (est.): 0.254277 * variance (est.): 0.480222 * covariance: * kernel: gauss * range (est.): 0.92171, 0.286891 * nugget (est.): 0 * fit: * objective: LL * optim: BFGS * data: 20x[0.0420595,0.956833],[0.0246137,0.99427] -> 20x[-0.884835,0.990808] * trend constant (est.): 0.254277 * variance (est.): 0.480222 * covariance: * kernel: gauss * range (est.): 0.92171, 0.286891 * nugget (est.): 0 * fit: * objective: LL * optim: BFGS Test passed 🎊 > > nok <- NoiseKriging(y, rep(0.1^2,nrow(X)), X,"gauss",parameters = list(theta=matrix(runif(40),ncol=2))) > print(nok) * data: 20x[0.0420595,0.956833],[0.0246137,0.99427] -> 20x[-0.884835,0.990808] * noise: 20x[0.01,0.01] * trend constant (est.): 0.146854 * variance (est.): 0.305097 * covariance: * kernel: gauss * range (est.): 0.749121, 0.241537 * fit: * objective: LL * optim: BFGS > > unlink("nok.json") > rlibkriging::save(nok, filename="nok.json") > > nok2 <- rlibkriging::load(filename="nok.json") > print(nok2) * data: 20x[0.0420595,0.956833],[0.0246137,0.99427] -> 20x[-0.884835,0.990808] * noise: 20x[0.01,0.01] * trend constant (est.): 0.146854 * variance (est.): 0.305097 * covariance: * kernel: gauss * range (est.): 0.749121, 0.241537 * fit: * objective: LL * optim: BFGS > > test_that("Save/Load NoiseKriging", expect_true( print(nok) == print(nok2))) * data: 20x[0.0420595,0.956833],[0.0246137,0.99427] -> 20x[-0.884835,0.990808] * noise: 20x[0.01,0.01] * trend constant (est.): 0.146854 * variance (est.): 0.305097 * covariance: * kernel: gauss * range (est.): 0.749121, 0.241537 * fit: * objective: LL * optim: BFGS * data: 20x[0.0420595,0.956833],[0.0246137,0.99427] -> 20x[-0.884835,0.990808] * noise: 20x[0.01,0.01] * trend constant (est.): 0.146854 * variance (est.): 0.305097 * covariance: * kernel: gauss * range (est.): 0.749121, 0.241537 * fit: * objective: LL * optim: BFGS Test passed 🎉 > > proc.time() user system elapsed 0.98 0.21 1.18