Skip to content

Commit

Permalink
Fix remaining linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sciome-bot committed Jan 13, 2024
1 parent 06673a4 commit 81b675d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 31 deletions.
12 changes: 4 additions & 8 deletions R/Log_Likelihood.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
#'
#' @examples
#' @noRd
negloglik_vecchia_ST <- function(logparms, res, vecchia.approx, param.seq,
scaling, nscale) {
negloglik_vecchia_ST <- function(logparms, res, vecchia.approx, param.seq, scaling, nscale) {
parms <- unlog.params(logparms, param.seq, 1)
locs.scaled <- vecchia.approx$locsord
for (j in 1:nscale) {
Expand Down Expand Up @@ -141,8 +140,7 @@ mvnegloglik <- function(logparams, vecchia.approx, y, param.seq, P) {
##############################################################################
### Flexible Spatiotemporal Multivariate Matern Negative Loglikelihood Function ###########

mvnegloglik_ST <- function(logparams, vecchia.approx, y, param.seq, P, scaling,
nscale) {
mvnegloglik_ST <- function(logparams, vecchia.approx, y, param.seq, P, scaling, nscale) {
# Input-
# logparams: A numeric vector of length (4*P)+(4*choose(P,2)).
# To construct these parameters we unlist a list of the 7 covariance
Expand Down Expand Up @@ -235,8 +233,7 @@ mvnegloglik.full <- function(logparams, locs, y, param.seq) {
}

##############################################################################
create.cov.upper.flex <- function(P, marg.var, marg.range, marg.smooth,
nugget, R.corr) {
create.cov.upper.flex <- function(P, marg.var, marg.range, marg.smooth, nugget, R.corr) {
# Create the symmetrical marginal+cross-covariance flexible matern from the
# given parameters. Output is a list of the 4 Matern parameters as matrices
sig2.mat <- diag(marg.var, P, P)
Expand Down Expand Up @@ -337,8 +334,7 @@ cat.covariances <- function(locs.list, sig2, range, smoothness, nugget) {
##############################################################################
### Create the likelihood initial values #########

create.initial.values.flex <- function(marg.var, marg.range, marg.smooth,
nugget, R.corr, P) {
create.initial.values.flex <- function(marg.var, marg.range, marg.smooth, nugget, R.corr, P) {
# Log-transform the covariance parameters and arrange in the proper order
# for the likelihood function
logparams.init <- c(
Expand Down
12 changes: 5 additions & 7 deletions R/PrestoGP_CreateU_Multivariate.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ max_min_ordering <- function(locs, dist_func) {
#' @param dist_func Any distance function with a signature of dist(query_location, locations_matrix)
#'
#' @return A vector containing the indices of the neighbors
knn_indices <- function(ordered_locs, query, n_neighbors,
dist_func, dist_func_code) {
knn_indices <- function(ordered_locs, query, n_neighbors, dist_func, dist_func_code) {
if (dist_func_code == "custom") {
dists <- dist_func(query, ordered_locs)
dists_order <- order(dists)
Expand All @@ -92,8 +91,7 @@ knn_indices <- function(ordered_locs, query, n_neighbors,
#'
#' @return A list containing two matrices, each with one row per location:
#' an indices matrix with the indices of nearest neighbors for each location, and a distance matrix with the associated distances
sparseNN <- function(ordered_locs, n_neighbors,
dist_func, dist_func_code, ordered_locs_pred = NULL) {
sparseNN <- function(ordered_locs, n_neighbors, dist_func, dist_func_code, ordered_locs_pred = NULL) {
ee <- min(apply(ordered_locs, 2, stats::sd))
n <- nrow(ordered_locs)
ordered_locs <- ordered_locs + matrix(
Expand Down Expand Up @@ -197,9 +195,9 @@ calc.q <- function(nn.obj, firstind.pred) {

#' @export
vecchia_Mspecify <- function(locs.list, m, locs.list.pred = NULL,
dist.func = NULL,
ordering.pred = c("obspred", "general"),
pred.cond = c("independent", "general")) {
dist.func = NULL,
ordering.pred = c("obspred", "general"),
pred.cond = c("independent", "general")) {
ordering.pred <- match.arg(ordering.pred)
pred.cond <- match.arg(pred.cond)

Expand Down
21 changes: 9 additions & 12 deletions R/PrestoGP_Model.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ setGeneric("show_theta", function(object, Y_names) standardGeneric("show_theta")
setGeneric(
"prestogp_fit",
function(model, Y, X, locs, scaling = NULL, apanasovich = FALSE,
covparams = NULL, beta.hat = NULL, tol = 0.999999, max_iters = 100, verbose = FALSE,
optim.method = "Nelder-Mead", optim.control = list(trace = 0, reltol = 1e-3, maxit = 5000),
parallel = FALSE, foldid = NULL) {
covparams = NULL, beta.hat = NULL, tol = 0.999999, max_iters = 100, verbose = FALSE,
optim.method = "Nelder-Mead", optim.control = list(trace = 0, reltol = 1e-3, maxit = 5000),
parallel = FALSE, foldid = NULL) {
standardGeneric("prestogp_fit")
}
)
setGeneric(
"prestogp_predict",
function(model, X = "matrix", locs = "matrix", m = "numeric", ordering.pred = c("obspred", "general"),
pred.cond = c("independent", "general"), return.values = c("mean", "meanvar")) {
pred.cond = c("independent", "general"), return.values = c("mean", "meanvar")) {
standardGeneric("prestogp_predict")
}
)
Expand Down Expand Up @@ -215,10 +215,10 @@ setMethod(
setMethod(
"prestogp_fit", "PrestoGPModel",
function(model, Y, X, locs, scaling = NULL, apanasovich = NULL,
covparams = NULL, beta.hat = NULL, tol = 0.999999,
max_iters = 100, verbose = FALSE, optim.method = "Nelder-Mead",
optim.control = list(trace = 0, reltol = 1e-3, maxit = 5000),
parallel = FALSE, foldid = NULL) {
covparams = NULL, beta.hat = NULL, tol = 0.999999,
max_iters = 100, verbose = FALSE, optim.method = "Nelder-Mead",
optim.control = list(trace = 0, reltol = 1e-3, maxit = 5000),
parallel = FALSE, foldid = NULL) {
model <- check_input(model, Y, X, locs)
if (!is.null(beta.hat)) {
if (!is.vector(beta.hat) | !is.numeric(beta.hat)) {
Expand Down Expand Up @@ -284,10 +284,7 @@ setMethod(
parallel = parallel,
foldid = foldid
)
beta.hat <- as.matrix(predict(beta0.glmnet,
type = "coefficients",
s = beta0.glmnet$lambda.1se
))
beta.hat <- as.matrix(predict(beta0.glmnet, type = "coefficients", s = beta0.glmnet$lambda.1se))
}
Y.hat <- beta.hat[1, 1] + model@X_train %*% beta.hat[-1, ]

Expand Down
4 changes: 2 additions & 2 deletions R/PrestoGP_Util_Functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ transform_iid <- function(data, vecchia.approx, covparms, nuggets) {

# return to original ordering
orig.order <- order(U.obj$ord)
transformed.data <- transform.ord[orig.order, ] # TODO: @Eric.Bair is this a required variable?
transformed.data <- transform.ord[orig.order, ] # nolint # TODO: @Eric.Bair is this a required variable?
return(transform.ord)
}

Expand Down Expand Up @@ -180,7 +180,7 @@ transform_miid <- function(data, vecchia.approx, params) {

# return to original ordering
orig.order <- order(U.obj$ord)
transformed.data <- transform.ord[orig.order, ] # TODO: @Eric.Bair is this a required variable?
transformed.data <- transform.ord[orig.order, ] # nolint TODO: @Eric.Bair is this a required variable?
return(transform.ord)
}

Expand Down
4 changes: 2 additions & 2 deletions R/PrestoGP_Vecchia.R
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ setMethod("prestogp_predict", "VecchiaModel",
} else {
warning("Variance estimates do not include model fitting variance and are anticonservative. Use with caution.")
# TODO: @Eric.Bair is this a typo/bug? Capital 'V' in Vec.sds but 'vec.sds' in return.list
Vec.sds <- sqrt(pred$var.pred + model@covparams[4])
return.list <- list(means = Vec.mean, sds = vec.sds)
Vec.sds <- sqrt(pred$var.pred + model@covparams[4]) # nolint
return.list <- list(means = Vec.mean, sds = vec.sds) # nolint
}

return(return.list)
Expand Down

0 comments on commit 81b675d

Please sign in to comment.