-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBB_par.R
More file actions
57 lines (50 loc) · 2.01 KB
/
BB_par.R
File metadata and controls
57 lines (50 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
library(stats)
library(MASS)
library(pcaPP)
library(Matrix)
library(fMultivar)
library(mnormt)
library(irlba)
library(chebpol)
library(foreach)
library(doFuture)
source("/scratch/user/sharkmanhmz/latentcor_git/latentcor/R/internal.R")
# For BB Case
BBvalue = function (tau_grid, d1_grid, d2_grid) {
l_tau_grid = length(tau_grid); l_d1_grid = length(d1_grid); l_d2_grid = length(d2_grid)
BBvalue = array(NA, c(l_tau_grid, l_d1_grid, l_d2_grid))
registerDoFuture()
plan(multicore, workers = 80)
value_list <-
foreach (i = 1:l_tau_grid) %:%
foreach (j = 1:l_d1_grid, .combine = rbind) %dopar% {
value <- rep(NA, l_d2_grid)
for (k in 1:l_d2_grid) {
zratio1 = d1_grid[j]; zratio2 = d2_grid[k]
tau = tau_grid[i] * bound_switch(comb = "11", zratio1 = zratio1, zratio2 = zratio2)
value[k] = r_sol(K = tau, zratio1 = zratio1, zratio2 = zratio2, comb = "11", tol = 1e-8, ratio = 0)
}
value_list <- value
}
for (i in 1:l_tau_grid) {
BBvalue[i, , ] = matrix(as.integer(10^7 * value_list[[i]]), l_d1_grid, l_d2_grid)
}
return (BBvalue)
}
# grid values that used to create precomputed values
d1 <- d2 <- seq(0.01, 0.99, length.out = 50)
tau1 <- c(seq(-0.5, -0.1, by = 0.007), seq(-0.095, -0.001, by = 0.005))
tau <- c(tau1, 0, rev(-tau1))
# create grid input for ipol
BBipolgrid <- list(tau, d1, d2)
# interpolation.
BBipol <- chebpol::ipol(BBvalue(tau_grid = tau, d1_grid = d1, d2_grid = d2), grid = BBipolgrid, method = "multilin")
save(BBipol, file = "BB_grid_mixedCCA.rda", compress = "xz")
# grid values that used to create precomputed values
tau_grid <- round(pnorm(seq(-1.2, 1.2, by =.06), sd = .5), 6) * 2 - 1
d1_grid <- d2_grid <- round(pnorm(seq(-1.2, 1.2, by =.06), sd = .5), 6)
# create grid input for ipol
BBipolgrid <- list(tau_grid, d1_grid, d2_grid)
# interpolation.
BBipol <- chebpol::ipol(BBvalue(tau_grid = tau_grid, d1_grid = d1_grid, d2_grid = d2_grid), grid = BBipolgrid, method = "multilin")
save(BBipol, file = "BB_grid.rda", compress = "xz")