library(fmlogcondens)
# draw samples from normal distribution
X <- matrix(rnorm(500),250,2)
# estimate log-concave density
system.time(r <- fmlcd(X))
results(clang)
> system.time(r <- fmlcd(X))
user system elapsed
0.691 0.006 0.699
results(RTools)
> system.time(r <- fmlcd(X))
user system elapsed
4.34 2.29 2.53
# load `LogConcDEAD` library for plotting capatibilities
library(LogConcDEAD)
r <- LogConcDEAD::getinfolcd(X, r$logMLE) # create a `LogConcDEAD` object
# plot estimated density
par(mfrow = c(1, 2)) #square plots
plot(r, addp = FALSE, asp = 1, main="density")
plot(r, uselog = TRUE, addp = FALSE, asp = 1, main="log density")
results
calculate parameters of convex hull of X
# draw samples from normal distribution
X <- matrix(rnorm(200),100,2)
# calculate parameters of convex hull of X
r <- calcCvxHullFaces(X)
# draw random parameters of 10 hyperplanes
a <- matrix(runif(10*2),10,2)
b <- runif(10)
correctIntegral(X,rep(0,2),a,b,r$cvh)
Downloading GitHub repo JaneeChoi/SpMix@HEAD
✓ checking for file ‘/private/var/folders/ms/1b6mj3f10_gbwfdztvcjv4b00000gn/T/RtmpY7Kmmy/remotes772843d1c998/JaneeChoi-SpMix-08e2379/DESCRIPTION’ (334ms)
─ preparing ‘SpMix’:
✓ checking DESCRIPTION meta-information ...
─ checking for LF line-endings in source and make files and shell scripts
─ checking for empty or unneeded directories
Omitted ‘LazyData’ from DESCRIPTION
─ building ‘SpMix_1.0.0.tar.gz’
* installing *source* package ‘SpMix’ ...
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (SpMix)
results(Rtools)
The downloaded binary packages are in
C:\Users\serim\AppData\Local\Temp\RtmpMHYw3u\downloaded_packages
√ checking for file 'C:\Users\serim\AppData\Local\Temp\RtmpMHYw3u\remotes60ec572d5c48\JaneeChoi-SpMix-08e2379/DESCRIPTION' (566ms)
- preparing 'SpMix':
√ checking DESCRIPTION meta-information ...
- checking for LF line-endings in source and make files and shell scripts
- checking for empty or unneeded directories
Omitted 'LazyData' from DESCRIPTION
- building 'SpMix_1.0.0.tar.gz'
‘C:/Users/serim/Documents/R/win-library/4.1’의 위치에 패키지(들)을 설치합니다.
(왜냐하면 ‘lib’가 지정되지 않았기 때문입니다)
* installing *source* package 'SpMix' ...
** using staged installation
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
converting help for package 'SpMix'
finding HTML links ... done
sp.mix.1D html
sp.mix.multi html
** building package indices
** testing if installed package can be loaded from temporary location
*** arch - i386
*** arch - x64
** testing if installed package can be loaded from final location
*** arch - i386
*** arch - x64
** testing if installed package keeps a record of temporary installation path
* DONE (SpMix)
Warning message:
In file.copy(savedcopy, lib, recursive = TRUE) :
problem copying C:\Users\serim\Documents\R\win-library\4.1\00LOCK\mvtnorm\libs\x64\mvtnorm.dll to C:\Users\serim\Documents\R\win-library\4.1\mvtnorm\libs\x64\mvtnorm.dll: Permission denied
simple runtime check for JaneeChoi/SpMix
library(SpMix)
set.seed(222)
X = matrix(rnorm(2000), 1000, 2)
system.time(r <- fmlcd(X)) # < 3sec in R version 4.1.1 / CC:clang
str(r)
results(clang)
> system.time(r <- fmlcd(X))
user system elapsed
1.143 0.010 1.155
> str(r)
List of 6
$ a : num [1:904, 1:2] -5.294 -2.93 14.852 -0.732 -0.323 ...
$ b : num [1:904] -9.37 -3.21 -39.52 -1.46 -1.23 ...
$ aSparse: num [1:84, 1:2] 2.05 -2.483 -0.919 2.162 0.381 ...
$ bSparse: num [1:84] -2.683 -0.522 -3.855 -5.427 -1.727 ...
$ logMLE : num [1:1000] -2.95 -1.94 -2.85 -3.56 -2.99 ...
$ logLike: num [1, 1:1000] -2.95 -1.94 -2.85 -3.56 -2.99 ...
results(Rtools)
user system elapsed
8.39 4.07 4.50
runtime check for 2d normal mixture
SimMultNormal <- function(M, n, p0)
# [Multivariate] Null: Normal, Nonnull: Normal
{
library(copula)
param <- 0.5
library(mvtnorm)
rho12 <- 0.25
Sigma0 <- matrix(c(1, rho12,
rho12, 1),
ncol = 2, byrow = T)
result <- data.frame(p0hat = rep(NA, M),
Sensitivity = rep(NA, M),
Specificity = rep(NA, M),
t=rep(NA,M))
for ( r in 1:M ) {
cat(r, "/", M, "\n")
n0 <- rbinom(1, n, p0)
n1 <- n - n0
V <- rCopula(n1, ellipCopula(family = "normal", param = param, dim = 2))
z0 <- rmvnorm(n0, sigma = Sigma0)
z1 <- qnorm(V, mean = 3.5, sd = .5)
z <- rbind(z0, z1)
plot(z, col = c(rep(1, n0), rep(2, n1)), pch = 20)
runtime<-system.time(res <- sp.mix.multi(z))[3]
p0hat <- res$p.0
Nhat <- as.integer(res$localfdr <= 0.2)
TP <- sum(Nhat[-(1:n0)] == 1)
TN <- sum(Nhat[1:n0] == 0)
FP <- n0 - TN
FN <- n1 - TP
result$p0hat[r] <- p0hat
result$Sensitivity[r] <- TP/(TP + FN)
result$Specificity[r] <- TN/(TN + FP)
result$t[r] <- runtime
}
return(result)
}
Runtime for N=100,500,1000,5000,10000,15000,20000,25000
result_df=data.frame(N=c(),p0=c(),time=c())
for (N in c(100,500,1000,5000,10000,15000,20000,25000)){
for (p in c(0.95,0.90,0.80)){
Res<-SimMultNormal(M = 1, n = N, p0 = p)
result_df=rbind(result_df,data.frame(N=N,p0=p,time=Res$t))
}
}
# plot and save the results
library(ggplot2)
library(dplyr)
p1<-ggplot(data=result_df,aes(x=N,y=time,group=p0,colour=p0))+geom_line()
ggsave("time.png", plot=p1, height=6, width=8, dpi=600)
Install required packages
Install JaneeChoi/fmlogcondens
results(clang)
results(Rtools)
simple check for JaneeChoi/fmlogcondens
results(clang)
results(RTools)
results
calculate parameters of convex hull of X
results
find initial hyperplane parameters based on a smooth log-concave density
results are omitted
find initial hyperplane parameters based on a kernel density estimator with Gaussian kernel
results are omitted
Install JaneeChoi/SpMix which imports JaneeChoi/fmlogcondens
results(clang)
results(Rtools)
simple runtime check for JaneeChoi/SpMix
results(clang)
results(Rtools)
runtime check for 2d normal mixture
Runtime for N=100,500,1000,5000,10000,15000,20000,25000
results(clang)
results(RTools)