Comments (2)
# remotes::install_url("https://github.com/libKriging/rlibkriging/releases/download/0.8-0.1/rlibkriging_0.8-0_R_x86_64-pc-linux-gnu.tar.gz", dependencies = TRUE, build=FALSE)
library(rlibkriging)
# 1D function, small design
X <- as.matrix(c(0.0, 0.25, 0.33, 0.45, 0.5, 0.75, 1.0))
f <- function(x) 1 - 1 / 2 * (sin(4 * x) / (1 + x) + 2 * cos(12 * x) * x^6 + 0.7)
y <- f(X) #+ 0.5*rnorm(nrow(X))
plot(f)
points(X, y)
rlibkriging:::optim_log(4)
# Build Kriging (https://libkriging.readthedocs.io/en/latest/math/KrigingModels.html)
k <- Kriging(y, X, kernel="gauss", optim="BFGS")#, parameters=list(sigma2=var(y), is_sigma2_estim=FALSE))#, objective = "LL", optim = "BFGS", regmodel = "constant")
# kernel: https://libkriging.readthedocs.io/en/latest/math/kernel.html
# regmodel: https://libkriging.readthedocs.io/en/latest/math/trend.html
# parameters: https://libkriging.readthedocs.io/en/latest/math/parameters.html
print(k)
# # Predict
# .x <- sort(c(as.matrix(seq(0, 1, , 101)),X))
# p.x <- predict(k, .x, TRUE, FALSE)
#
# plot(f)
# points(X, y)
# lines(.x, p.x$mean, col = 'blue')
# polygon(c(.x, rev(.x)), c(p.x$mean - 2 * p.x$stdev, rev(p.x$mean + 2 * p.x$stdev)), border = NA, col = rgb(0, 0, 1, 0.2))
#
# # log-Likelihood (https://libkriging.readthedocs.io/en/latest/math/likelihood.html)
# print(k$logLikelihood())
#
# plot( function(t) k$logLikelihoodFun(t)$logLikelihood ,xlab=expression(theta),ylab="LL", xlim=c(0.001,10))
# abline(v=k$theta(),col='blue')
# abline(h=k$logLikelihood(),col='blue')
getR = function(k) {
# Save / load /inspect
save(k,"k.h5")
# install.packages("hdf5r")
k.h5 = hdf5r::h5file("k.h5")
# print(k.h5)
T = k.h5[['T']]$read()
R = (T) %*% t(T)
return(R)
}
Rcpp::sourceCpp('rcond.cpp') #library(Matrix)
# leave-one-out (https://libkriging.readthedocs.io/en/latest/math/leaveOneOut.html)
#print(k$leaveOneOut())
plot( function(t) k$logLikelihoodFun(t)$logLikelihood ,xlab=expression(theta),ylab="LL", xlim=c(0.00,10))
for (t in seq(0.00,10,,101)) {
k_t <- Kriging(y, X, kernel="gauss", optim="none", parameters=list(theta=matrix(t), is_theta_estim=FALSE))
R_t = getR(k_t)
if (rcond(R_t) > nrow(R_t) * 1e-13) {
points(t,k$logLikelihoodFun(t)$logLikelihood,col='blue')
} else {
points(t,k$logLikelihoodFun(t)$logLikelihood,col='red')
}
}
## # plot( function(t) k$leaveOneOutFun(t)$leaveOneOut ,xlab=expression(theta),ylab="LOO", xlim=c(0.01,10))
## # abline(v=k$theta(),col='blue')
## # abline(h=k$leaveOneOut(),col='blue')
##
## ## k <- Kriging(y, X, kernel="gauss", optim="none", parameters=list(theta=matrix(9.2), is_theta_estim=FALSE))#, objective = "LL", optim = "BFGS", regmodel = "constant")
## ##
##
## ## kappa(R)
## ## library(RcppArmadillo)
## ## Rcpp::sourceCpp("inv_sympd.cpp")
## ## inv_sympd(R)
##
##
plot( function(t) k$leaveOneOutFun(t)$leaveOneOut ,xlab=expression(theta),ylab="LOO", xlim=c(0.00,10))
for (t in seq(0.00,10,,101)) {
k_t <- Kriging(y, X, kernel="gauss", optim="none", parameters=list(theta=matrix(t), is_theta_estim=FALSE))
R_t = getR(k_t)
if (rcond(R_t) > nrow(R_t) * 1e-13) {
points(t,k$leaveOneOutFun(t)$leaveOneOut,col='blue')
} else {
points(t,k$leaveOneOutFun(t)$leaveOneOut,col='red')
}
}
plot( function(t) k$logMargPostFun(t)$logMargPost ,xlab=expression(theta),ylab="LMP", xlim=c(0.00,10))
for (t in seq(0.00,10,,101)) {
k_t <- Kriging(y, X, kernel="gauss", optim="none", objective="LMP",parameters=list(theta=matrix(t), is_theta_estim=FALSE))
R_t = getR(k_t)
if (rcond(R_t) > nrow(R_t) * 1e-13) {
points(t,k$logMargPostFun(t)$logMargPost,col='blue')
} else {
points(t,k$logMargPostFun(t)$logMargPost,col='red')
}
}
from libkriging.
fixed by commit 372ce0f
from libkriging.
Related Issues (20)
- Switch slapack external project as submodule
- implement pickle in python binding HOT 1
- Disable CacheFunction when C++17 is not available HOT 1
- "Empty" Kriging models in the R API
- Replace Python tests random generator by libK one
- logMargPost.Kriging HOT 2
- Windows 11 DLL not found
- Impossible to set sigma2 in the function Kriging. HOT 1
- Improve loader for dynamically typed languages
- how to call libKriging in C++ HOT 1
- [R] macOS build failure: rlibkriging.so: Symbol not found: _arma_H5T_NATIVE_DOUBLE HOT 5
- [R] Build failure under Ubuntu 22.04 because `../inst/hdf5` missing HOT 2
- Forcing libquadmath linking is wrong
- Build fails on macOS Catalina: error: no viable constructor or deduction guide for deduction of template arguments of 'CacheFunction'
- Build fails on macOS 10.12 and below when Clang is used: various linking errors
- Error in LMP/linear trend HOT 1
- What happened to 0.8.0 version? It was there but vanished HOT 1
- how to improve performance of libkriging?
- Check error in NuggetKriging::predict HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libkriging.