Skip to content

Commit

Permalink
Merge branch 'tweaks'
Browse files Browse the repository at this point in the history
- Update version number and change file
  • Loading branch information
mahendra-mariadassou committed Nov 28, 2023
2 parents fcc9555 + 2eae352 commit 64365fa
Show file tree
Hide file tree
Showing 26 changed files with 256 additions and 85 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: PLNmodels
Title: Poisson Lognormal Models
Version: 1.0.4-0300
Version: 1.0.5-0000
Authors@R: c(
person("Julien", "Chiquet", role = c("aut", "cre"), email = "[email protected]",
comment = c(ORCID = "0000-0002-3629-3429")),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
* Update documentation of PLN*_param() functions to include torch optimization parameters
* Add (somehow) explicit error message when torch convergence fails
* Change initialization in `variance_jackknife()` and `variance_bootstrap()` to prevent estimation recycling, results from those functions are now comparable to doing jackknife / bootstrap "by hand".
* Merge PR #110 from Cole Trapnell to add:
- bootstrap estimation of the variance of model parameter
- improved interface for model initialization / optimisation parameters, which
are now passed on to jackknife / bootstrap post-treatments
- better support of GPU when using torch backend

# PLNmodels 1.0.4 (2023-08-24)

Expand Down
4 changes: 2 additions & 2 deletions R/PLN.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) {

## post-treatment
if (control$trace > 0) cat("\n Post-treatments...")
myPLN$postTreatment(args$Y, args$X, args$O, args$w, control$config_post)
myPLN$postTreatment(args$Y, args$X, args$O, args$w, control$config_post, control$config_optim)

if (control$trace > 0) cat("\n DONE!\n")
myPLN
Expand Down Expand Up @@ -90,7 +90,7 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) {
#' * "etas" pair of multiplicative increase and decrease factors. Default is (0.5, 1.2). Only used in RPROP
#' * "centered" if TRUE, compute the centered RMSProp where the gradient is normalized by an estimation of its variance weight_decay (L2 penalty). Default to FALSE. Only used in RMSPROP
#'
#' The list of parameters `config_post` controls the post-treatment processing (for PLN and PLNLDA), with the following entries:
#' The list of parameters `config_post` controls the post-treatment processing (for most `PLN*()` functions), with the following entries (defaults may vary depending on the specific function, check `config_post_default_*` for defaults values):
#' * jackknife boolean indicating whether jackknife should be performed to evaluate bias and variance of the model parameters. Default is FALSE.
#' * bootstrap integer indicating the number of bootstrap resamples generated to evaluate the variance of the model parameters. Default is 0 (inactivated).
#' * variational_var boolean indicating whether variational Fisher information matrix should be computed to estimate the variance of the model parameters (highly underestimated). Default is FALSE.
Expand Down
2 changes: 1 addition & 1 deletion R/PLNLDA.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ PLNLDA <- function(formula, data, subset, weights, grouping, control = PLN_param
myLDA$optimize(grouping, args$Y, args$X, args$O, args$w, control$config_optim)

## Post-treatment: prepare LDA visualization
myLDA$postTreatment(grouping, args$Y, args$X, args$O, control$config_post)
myLDA$postTreatment(grouping, args$Y, args$X, args$O, control$config_post, control$config_optim)

if (control$trace > 0) cat("\n DONE!\n")
myLDA
Expand Down
9 changes: 5 additions & 4 deletions R/PLNLDAfit-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ PLNLDAfit <- R6Class(
## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
## Post treatment --------------------
#' @description Update R2, fisher and std_err fields and visualization
#' @param config list controlling the post-treatment
postTreatment = function(grouping, responses, covariates, offsets, config) {
#' @param config_post a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.).
#' @param config_optim list controlling the optimization parameters
postTreatment = function(grouping, responses, covariates, offsets, config_post, config_optim) {
covariates <- cbind(covariates, model.matrix( ~ grouping + 0))
super$postTreatment(responses, covariates, offsets, config = config)
super$postTreatment(responses, covariates, offsets, config_post = config_post, config_optim = config_optim)
rownames(private$C) <- colnames(private$C) <- colnames(responses)
colnames(private$S) <- 1:self$q
if (config$trace > 1) cat("\n\tCompute LD scores for visualization...")
if (config_post$trace > 1) cat("\n\tCompute LD scores for visualization...")
self$setVisualization()
},

Expand Down
11 changes: 9 additions & 2 deletions R/PLNPCA.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ PLNPCA <- function(formula, data, subset, weights, ranks = 1:5, control = PLNPCA

## Post-treatments: pseudo-R2, rearrange criteria and prepare PCA visualization
if (control$trace > 0) cat("\n Post-treatments")
config_post <- config_post_default_PLNPCA; config_post$trace <- control$trace
myPCA$postTreatment(config_post)
myPCA$postTreatment(control$config_post, control$config_optim)

if (control$trace > 0) cat("\n DONE!\n")
myPCA
Expand All @@ -65,6 +64,7 @@ PLNPCA <- function(formula, data, subset, weights, ranks = 1:5, control = PLNPCA
#' @param backend optimization back used, either "nlopt" or "torch". Default is "nlopt"
#' @param trace a integer for verbosity.
#' @param config_optim a list for controlling the optimizer (either "nlopt" or "torch" backend). See details
#' @param config_post a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.). See details
#' @param inception Set up the parameters initialization: by default, the model is initialized with a multivariate linear model applied on
#' log-transformed data, and with the same formula as the one provided by the user. However, the user can provide a PLNfit (typically obtained from a previous fit),
#' which sometimes speeds up the inference.
Expand All @@ -77,11 +77,17 @@ PLNPCA_param <- function(
backend = "nlopt",
trace = 1 ,
config_optim = list() ,
config_post = list() ,
inception = NULL # pretrained PLNfit used as initialization
) {

if (!is.null(inception)) stopifnot(isPLNfit(inception))

## post-treatment config
config_pst <- config_post_default_PLNPCA
config_pst[names(config_post)] <- config_post
config_pst$trace <- trace

## optimization config
backend <- match.arg(backend)
stopifnot(backend %in% c("nlopt", "torch"))
Expand All @@ -100,5 +106,6 @@ PLNPCA_param <- function(
backend = backend ,
trace = trace ,
config_optim = config_opt,
config_post = config_pst,
inception = inception ), class = "PLNmodels_param")
}
8 changes: 5 additions & 3 deletions R/PLNPCAfit-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,16 @@ PLNPCAfit <- R6Class(
},

#' @description Update R2, fisher, std_err fields and set up visualization
#' @details The list of parameters `config` controls the post-treatment processing, with the following entries:
#' @param config_optim a list for controlling the optimizer (either "nlopt" or "torch" backend). See details
#' @param config_post a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.). See details
#' @details The list of parameters `config_post` controls the post-treatment processing, with the following entries:
#' * jackknife boolean indicating whether jackknife should be performed to evaluate bias and variance of the model parameters. Default is FALSE.
#' * bootstrap integer indicating the number of bootstrap resamples generated to evaluate the variance of the model parameters. Default is 0 (inactivated).
#' * variational_var boolean indicating whether variational Fisher information matrix should be computed to estimate the variance of the model parameters (highly underestimated). Default is FALSE.
#' * rsquared boolean indicating whether approximation of R2 based on deviance should be computed. Default is TRUE
#' * trace integer for verbosity. should be > 1 to see output in post-treatments
postTreatment = function(responses, covariates, offsets, weights, config, nullModel) {
super$postTreatment(responses, covariates, offsets, weights, config, nullModel)
postTreatment = function(responses, covariates, offsets, weights, config_post, config_optim, nullModel) {
super$postTreatment(responses, covariates, offsets, weights, config_post, config_optim, nullModel)
colnames(private$C) <- colnames(private$M) <- 1:self$q
rownames(private$C) <- colnames(responses)
self$setVisualization()
Expand Down
14 changes: 10 additions & 4 deletions R/PLNfamily-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,22 @@ PLNfamily <-
## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
## Post treatment --------------------
#' @description Update fields after optimization
#' @param config a list for controlling the post-treatment.
postTreatment = function(config) {
nullModel <- nullModelPoisson(self$responses, self$covariates, self$offsets, self$weights)
#' @param config_post a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.).
#' @param config_optim a list for controlling the optimization parameters used during post_treatments
postTreatment = function(config_post, config_optim) {
if (config_post$rsquared) {
nullModel <- nullModelPoisson(self$responses, self$covariates, self$offsets, self$weights)
} else {
nullModel <- NULL
}
for (model in self$models)
model$postTreatment(
self$responses,
self$covariates,
self$offsets,
self$weights,
config,
config_post=config_post,
config_optim=config_optim,
nullModel = nullModel
)
},
Expand Down
Loading

0 comments on commit 64365fa

Please sign in to comment.