Comments (1)
derivative of lmp / trend linear is ok indeed.
... but the lmp itself is not
# 1D function, small design
X <- as.matrix(c(0.0, 0.25, 0.5, 0.75, 1.0))
f <- function(x) 1 - 1 / 2 * (sin(12 * x) / (1 + x) + 2 * cos(7 * x) * x^5 + 0.7)
y <- f(X) # + 10*rnorm(nrow(X))
library(rlibkriging)
k <- Kriging(y, X, kernel="matern5_2", objective = "LMP", optim = "BFGS", regmodel = "linear")
plot( function(t) k$logMargPostFun(t)$logMargPost ,xlab=expression(theta))
abline(v=k$theta(), col="red")
# LL
obj_fun = function(theta,...) logLikelihoodFun(k,theta)$logLikelihood
obj_grad = function(theta,...) logLikelihoodFun(k,theta,grad = T)$logLikelihoodGrad
obj_grad_fd = function(theta,...) (obj_fun(theta+0.01)-obj_fun(theta-0.01))/0.02
plot(Vectorize(obj_fun),col='blue')
for (x in seq(0.01,1,,11)){
fx = obj_fun(x)
gx = obj_grad(x)
gx_ref = obj_grad_fd(x)
arrows(x,fx,x+.1,fx+.1*gx,col='red')
arrows(x,fx,x+.11,fx+.11*gx_ref,col='blue')
}
# LMP
obj_fun = function(theta,...) logMargPostFun(k,theta)$logMargPost
obj_grad = function(theta,...) logMargPostFun(k,theta,grad = T)$logMargPostGrad
obj_grad_fd = function(theta,...) (obj_fun(theta+0.01)-obj_fun(theta-0.01))/0.02
plot(Vectorize(obj_fun),col='blue')
for (x in seq(0.01,1,,11)){
fx = obj_fun(x)
gx = obj_grad(x)
gx_ref = obj_grad_fd(x)
arrows(x,fx,x+.1,fx+.1*gx,col='red', lty=2)
arrows(x,fx,x+.11,fx+.11*gx_ref,col='blue')
}
library(RobustGaSP)
r = rgasp(design=X,response = y,kernel_type="matern_5_2",optimization = "lbfgs",trend=cbind(matrix(1,length(y),1),X))
obj_fun_rgasp = function(theta,...)
-RobustGaSP:::neg_log_marginal_post_approx_ref(param=log(1/theta),nugget=0, [email protected],
R0=r@R0,X=r@X, zero_mean=r@zero_mean,output=r@output,
CL=r@CL,
a=0.2,
b=1/(length(r@output))^{1/dim(as.matrix(r@input))[2]}*(0.2+dim(as.matrix(r@input))[2]),
kernel_type=rep(as.integer(3),ncol(X)),alpha=r@alpha)
obj_grad_rgasp = function(theta,...)
-RobustGaSP:::neg_log_marginal_post_approx_ref_deriv(param=log(1/theta),nugget=0, [email protected],
R0=r@R0,X=r@X, zero_mean=r@zero_mean,output=r@output,
CL=r@CL,
a=0.2,
b=1/(length(r@output))^{1/dim(as.matrix(r@input))[2]}*(0.2+dim(as.matrix(r@input))[2]),
kernel_type=rep(as.integer(3),ncol(X)),alpha=r@alpha) / -theta
lines(seq(0,1,,101),(Vectorize(obj_fun_rgasp)(seq(0,1,,101))),col='red')
abline(v=1/r@beta_hat,col='red')
for (x in seq(0.01,1,,11)){
fx = obj_fun_rgasp(x)
gx = obj_grad_rgasp(x)
arrows(x,fx,x+.1,fx+.1*gx,col='red', lty=1)
}
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
- unstable LL when theta to high HOT 2
- 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.