if (FALSE) {
# Compute probability P(X \in (-\infty,0]) with X~N(0,Sigma)
d<-200 # example dimension
mu<-rep(0,d) # mean of the normal vector
# correlation structure (Miwa et al. 2003, Craig 2008, Botev 2016)
Sigma<-0.5*diag(d)+ 0.5*rep(1,d)%*%t(rep(1,d))
pANMC<-ProbaMax(cBdg=20, q=min(50,d/2), E=seq(0,1,,d), threshold=0, mu=mu, Sigma=Sigma,
pn = NULL, lightReturn = TRUE, method = 3, verb = 2, Algo = "ANMC")
proba<-1-pANMC$probability
# Percentage error
abs(1-pANMC$probability-1/(d+1))/(1/(d+1))
# Implement ProbaMax with user defined function for active dimension probability estimate
if(!requireNamespace("TruncatedNormal", quietly = TRUE)) {
stop("Package TruncatedNormal needed for this example to work. Please install it.",
call. = FALSE)
}
# define pmvnorm_usr with the function mvNcdf from the package TruncatedNormal
pmvnorm_usr<-function(lower,upper,mean,sigma){
pMET<-TruncatedNormal::mvNcdf(l = lower-mean,u = upper-mean,Sig = sigma,n = 5e4)
res<-pMET$prob
attr(res,"error")<-pMET$relErr
return(res)
}
pANMC<-ProbaMax(cBdg=20, q=min(50,d/2), E=seq(0,1,,d), threshold=0, mu=mu, Sigma=Sigma,
pn = NULL, lightReturn = TRUE, method = 3, verb = 2, Algo = "ANMC",pmvnorm_usr=pmvnorm_usr)
proba<-1-pANMC$probability
# Percentage error
abs(1-pANMC$probability-1/(d+1))/(1/(d+1))
# Implement ProbaMax with user defined function for truncated normal sampling
if(!requireNamespace("tmg", quietly = TRUE)) {
stop("Package tmg needed for this example to work. Please install it.",
call. = FALSE)
}
trmvrnorm_usr<-function(n,mu,sigma,upper,lower,verb){
M<-chol2inv(chol(sigma))
r=as.vector(M%*%mu)
if(all(lower==-Inf) && all(upper==Inf)){
f<- NULL
g<- NULL
}else{
if(all(lower==-Inf)){
f<--diag(length(mu))
g<-upper
initial<-(upper-1)/2
}else if(all(upper==Inf)){
f<-diag(length(mu))
g<- -lower
initial<-2*(lower+1)
}else{
f<-rbind(-diag(length(mu)),diag(length(mu)))
g<-c(upper,-lower)
initial<-(upper-lower)/2
}
}
reals_tmg<-tmg::rtmg(n=n,M=M,r=r,initial = initial,f=f,g=g)
return(t(reals_tmg))
}
pANMC<-ProbaMax(cBdg=20, q=min(50,d/2), E=seq(0,1,,d), threshold=0, mu=mu, Sigma=Sigma,
pn = NULL, lightReturn = TRUE, method = 3, verb = 2, Algo = "ANMC",trmvrnorm=trmvrnorm_usr)
proba<-1-pANMC$probability
# Percentage error
abs(1-pANMC$probability-1/(d+1))/(1/(d+1))
}
Run the code above in your browser using DataLab