Skip to content

Commit 56686c4

Browse files
committed
change colSum
1 parent b36b511 commit 56686c4

20 files changed

+106
-36
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ renv.lock
1313
/doc/
1414
/Meta/
1515
functional_tests/*.html
16+
functional_tests/*_cache/*
17+
functional_tests/*_files/*

R/compute_deriv_nn.R

+5-2
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,13 @@ compute_deriv_nn <- function(w,
9898
Sigma_obs_inv <- chol2inv(chol(Sigma_obs))
9999

100100
all_weights <- sapply(id_all, function(id.ind){
101+
101102
cross_dist <- spatstat.geom::crossdist(obs_new[id.ind,1], obs_new[id.ind,2],
102103
obs_use[,1], obs_use[,2])
103-
Sigma_cross <- g_sigma*(1/alpha)*(2*outer(rep(w,length(id.ind))*(1/alpha), obs_use[,1], "-"))*
104-
kernel_deriv_fn(cross_dist^2)
104+
105+
Sigma_cross <- g_sigma*(1/alpha)*(2*outer(rep(w,length(id.ind))*(1/alpha),
106+
obs_use[,1], "-"))*
107+
kernel_deriv_fn(cross_dist^2)
105108
#mean
106109
wght <- Sigma_cross%*%Sigma_obs_inv
107110
colSums(wght)

R/compute_posterior_sd_nn.R

+8-1
Original file line numberDiff line numberDiff line change
@@ -106,5 +106,12 @@ compute_posterior_sd_nn <- function(hyperparam,
106106
obs_use[,1],obs_use[,2])^2)
107107

108108
sigma_sq2 <- c(calc_cross(cross_cov, cov_use_inv))/n^2
109-
return(sqrt(sigma_sq1 - sigma_sq2 + sigma2))
109+
posterior_sd <- sqrt(sigma_sq1 - sigma_sq2 + sigma2)
110+
111+
logger::log_debug("w: {w}, sigma_sq1: {sigma_sq1}, sigma_sq2: {sigma_sq2},",
112+
"sigma2: {sigma2}")
113+
114+
115+
116+
return(posterior_sd)
110117
}

R/compute_w_corr.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ compute_w_corr <- function(data, weights){
4949
w_sd <- sqrt(sum((w_obs - w_mean)^2*weights))
5050
w_stan <- (w_obs - w_mean)/w_sd
5151

52-
x_mean <- colMeans(x_design*weights)
52+
x_mean <- colSums(x_design*weights)
5353
x_cov <- (t(x_design) - x_mean)%*%diag(weights)%*%t(t(x_design) - x_mean)
5454
x_stan <- t(t(solve(chol(x_cov)))%*%(t(x_design) - x_mean))
5555
covariate_balance <- abs(c(t(x_stan)%*%diag(weights)%*%w_stan))

R/estimate_mean_sd_nn.R

+2
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ estimate_mean_sd_nn <- function(hyperparam,
136136
mean = GPS_m$e_gps_pred,
137137
sd = GPS_m$e_gps_std, log = T)
138138

139+
print(paste("Sigma2 is:", sigma2))
140+
139141
val <- compute_posterior_sd_nn(hyperparam = hyperparam,
140142
w = wi,
141143
GPS_w = GPS_w,

R/train_GPS.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#' as.matrix(mydata$treat))
2525
#'
2626
#'
27-
train_GPS <- function(cov.mt, w.all){
27+
train_GPS <- function(cov.mt, w.all, dnorm_log = FALSE){
2828
GPS_mod <- xgboost::xgboost(data = cov.mt,
2929
label = w.all,
3030
nrounds=50,
@@ -35,7 +35,7 @@ train_GPS <- function(cov.mt, w.all){
3535

3636
e_gps_pred <- predict(GPS_mod,cov.mt)
3737
e_gps_std <- sd(w.all-e_gps_pred)
38-
GPS <- c(stats::dnorm(w.all, mean = e_gps_pred, sd = e_gps_std, log = T))
38+
GPS <- c(stats::dnorm(w.all, mean = e_gps_pred, sd = e_gps_std, log = dnorm_log))
3939
GPS_m <- data.table::data.table(GPS = GPS,
4040
e_gps_pred = e_gps_pred,
4141
e_gps_std = e_gps_std)

docs/articles/GPCERF.html

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/pkgdown.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ articles:
55
Full-Gaussian-Processes: Full-Gaussian-Processes.html
66
GPCERF: GPCERF.html
77
Nearest-neighbor-Gaussian-Processes: Nearest-neighbor-Gaussian-Processes.html
8-
last_built: 2022-06-08T19:06Z
8+
last_built: 2022-06-13T18:58Z
99
urls:
1010
reference: https://fasrc.github.io/GPCERF/reference
1111
article: https://fasrc.github.io/GPCERF/articles

docs/reference/GPCERF-package.html

+8-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/compute_m_sigma.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/estimate_cerf_gp.html

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)