From b1eaafba1e861f6a71d116d1e5b575e56c476f50 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 5 Jun 2026 19:24:46 +0200 Subject: [PATCH 01/58] regenerating doc with roxygen8 --- DESCRIPTION | 2 +- man/Networkfamily.Rd | 323 +++++++++++----------- man/PLNLDAfit.Rd | 431 ++++++++++++++--------------- man/PLNLDAfit_diagonal.Rd | 128 +++++---- man/PLNPCAfamily.Rd | 262 +++++++++--------- man/PLNPCAfit.Rd | 564 ++++++++++++++++++-------------------- man/PLNfamily.Rd | 249 +++++++++-------- man/PLNfit.Rd | 495 ++++++++++++++++----------------- man/PLNfit_diagonal.Rd | 243 ++++++++-------- man/PLNfit_fixedcov.Rd | 157 +++++------ man/PLNfit_spherical.Rd | 117 ++++---- man/PLNmixturefamily.Rd | 289 +++++++++---------- man/PLNmixturefit.Rd | 379 +++++++++++++------------ man/PLNmodels-package.Rd | 1 + man/PLNnetworkfamily.Rd | 137 ++++----- man/PLNnetworkfit.Rd | 242 ++++++++-------- man/ZIPLNfit.Rd | 367 ++++++++++++------------- man/ZIPLNfit_diagonal.Rd | 101 ++++--- man/ZIPLNfit_fixed.Rd | 101 ++++--- man/ZIPLNfit_sparse.Rd | 199 +++++++------- man/ZIPLNfit_spherical.Rd | 101 ++++--- man/ZIPLNnetworkfamily.Rd | 147 +++++----- 22 files changed, 2489 insertions(+), 2546 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 87fca2aa..8a87636b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -69,7 +69,6 @@ Encoding: UTF-8 Language: en-US LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.2 Collate: 'PLNfit-class.R' 'PLN.R' @@ -112,3 +111,4 @@ Collate: 'utils-zipln.R' 'utils.R' 'zzz.R' +Config/roxygen2/version: 8.0.0 diff --git a/man/Networkfamily.Rd b/man/Networkfamily.Rd index d0eefcce..530fb5a4 100644 --- a/man/Networkfamily.Rd +++ b/man/Networkfamily.Rd @@ -16,220 +16,227 @@ See the documentation for \code{\link[=getBestModel]{getBestModel()}}, The functions \code{\link[=PLNnetwork]{PLNnetwork()}}, \code{\link[=ZIPLNnetwork]{ZIPLNnetwork()}} and the classes \code{\link{PLNnetworkfit}}, \code{\link{ZIPLNfit_sparse}} } \section{Super class}{ -\code{\link[PLNmodels:PLNfamily]{PLNmodels::PLNfamily}} -> \code{Networkfamily} +\code{\link[PLNmodels:PLNfamily]{PLNfamily}} -> \code{Networkfamily} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{penalties}}{the sparsity level of the network in the successively fitted models} + \if{html}{\out{
}} + \describe{ + \item{\code{penalties}}{the sparsity level of the network in the successively fitted models} -\item{\code{stability_path}}{the stability path of each edge as returned by the stars procedure} + \item{\code{stability_path}}{the stability path of each edge as returned by the stars procedure} -\item{\code{stability}}{mean edge stability along the penalty path} + \item{\code{stability}}{mean edge stability along the penalty path} -\item{\code{criteria}}{a data frame with the values of some criteria (variational log-likelihood, (E)BIC, ICL and R2, stability) for the collection of models / fits + \item{\code{criteria}}{a data frame with the values of some criteria (variational log-likelihood, (E)BIC, ICL and R2, stability) for the collection of models / fits BIC, ICL and EBIC are defined so that they are on the same scale as the model log-likelihood, i.e. with the form, loglik - 0.5 penalty} -} -\if{html}{\out{
}} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-Networkfamily-new}{\code{Networkfamily$new()}} -\item \href{#method-Networkfamily-optimize}{\code{Networkfamily$optimize()}} -\item \href{#method-Networkfamily-coefficient_path}{\code{Networkfamily$coefficient_path()}} -\item \href{#method-Networkfamily-getBestModel}{\code{Networkfamily$getBestModel()}} -\item \href{#method-Networkfamily-plot}{\code{Networkfamily$plot()}} -\item \href{#method-Networkfamily-plot_stars}{\code{Networkfamily$plot_stars()}} -\item \href{#method-Networkfamily-plot_objective}{\code{Networkfamily$plot_objective()}} -\item \href{#method-Networkfamily-show}{\code{Networkfamily$show()}} -\item \href{#method-Networkfamily-clone}{\code{Networkfamily$clone()}} -} -} -\if{html}{\out{ -
Inherited methods + \itemize{ + \item \href{#method-Networkfamily-initialize}{\code{Networkfamily$new()}} + \item \href{#method-Networkfamily-optimize}{\code{Networkfamily$optimize()}} + \item \href{#method-Networkfamily-coefficient_path}{\code{Networkfamily$coefficient_path()}} + \item \href{#method-Networkfamily-getBestModel}{\code{Networkfamily$getBestModel()}} + \item \href{#method-Networkfamily-plot}{\code{Networkfamily$plot()}} + \item \href{#method-Networkfamily-plot_stars}{\code{Networkfamily$plot_stars()}} + \item \href{#method-Networkfamily-plot_objective}{\code{Networkfamily$plot_objective()}} + \item \href{#method-Networkfamily-show}{\code{Networkfamily$show()}} + \item \href{#method-Networkfamily-clone}{\code{Networkfamily$clone()}} + } +} +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-Networkfamily-new}{}}} -\subsection{Method \code{new()}}{ -Initialize all models in the collection -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Networkfamily$new(penalties, data, control)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-Networkfamily-initialize}{}}} +\subsection{\code{Networkfamily$new()}}{ + Initialize all models in the collection + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{Networkfamily$new(penalties, data, control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{penalties}}{a vector of positive real number controlling the level of sparsity of the underlying network.} + \item{\code{data}}{a named list used internally to carry the data matrices} + \item{\code{control}}{a list for controlling the optimization.} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + Update all network fits in the family with smart starting values + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{penalties}}{a vector of positive real number controlling the level of sparsity of the underlying network.} - -\item{\code{data}}{a named list used internally to carry the data matrices} - -\item{\code{control}}{a list for controlling the optimization.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -Update all network fits in the family with smart starting values -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-Networkfamily-optimize}{}}} -\subsection{Method \code{optimize()}}{ -Call to the C++ optimizer on all models of the collection -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Networkfamily$optimize(data, config)}\if{html}{\out{
}} +\subsection{\code{Networkfamily$optimize()}}{ + Call to the C++ optimizer on all models of the collection + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{Networkfamily$optimize(data, config)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{data}}{a named list used internally to carry the data matrices} + \item{\code{config}}{a list for controlling the optimization.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{data}}{a named list used internally to carry the data matrices} - -\item{\code{config}}{a list for controlling the optimization.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-Networkfamily-coefficient_path}{}}} -\subsection{Method \code{coefficient_path()}}{ -Extract the regularization path of a \code{\link{Networkfamily}} -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Networkfamily$coefficient_path(precision = TRUE, corr = TRUE)}\if{html}{\out{
}} +\subsection{\code{Networkfamily$coefficient_path()}}{ + Extract the regularization path of a \code{\link{Networkfamily}} + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{Networkfamily$coefficient_path(precision = TRUE, corr = TRUE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{precision}}{Logical. Should the regularization path be extracted from the precision matrix Omega (\code{TRUE}, default) or from the variance matrix Sigma (\code{FALSE})} + \item{\code{corr}}{Logical. Should the matrix be transformed to (partial) correlation matrix before extraction? Defaults to \code{TRUE}} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{precision}}{Logical. Should the regularization path be extracted from the precision matrix Omega (\code{TRUE}, default) or from the variance matrix Sigma (\code{FALSE})} - -\item{\code{corr}}{Logical. Should the matrix be transformed to (partial) correlation matrix before extraction? Defaults to \code{TRUE}} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-Networkfamily-getBestModel}{}}} -\subsection{Method \code{getBestModel()}}{ -Extract the best network in the family according to some criteria -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Networkfamily$getBestModel(crit = c("BIC", "EBIC", "StARS"), stability = 0.9)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{crit}}{character. Criterion used to perform the selection. If "StARS" is chosen but \verb{$stability} field is empty, will compute stability path.} - -\item{\code{stability}}{Only used for "StARS" criterion. A scalar indicating the target stability (= 1 - 2 beta) at which the network is selected. Default is \code{0.9}.} -} -\if{html}{\out{
}} -} -\subsection{Details}{ -For BIC and EBIC criteria, higher is better. +\subsection{\code{Networkfamily$getBestModel()}}{ + Extract the best network in the family according to some criteria + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{Networkfamily$getBestModel(crit = c("BIC", "EBIC", "StARS"), stability = 0.9)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{crit}}{character. Criterion used to perform the selection. If "StARS" is chosen but \verb{$stability} field is empty, will compute stability path.} + \item{\code{stability}}{Only used for "StARS" criterion. A scalar indicating the target stability (= 1 - 2 beta) at which the network is selected. Default is \code{0.9}.} + } + \if{html}{\out{
}} + } + \subsection{Details}{ + For BIC and EBIC criteria, higher is better. + } } -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-Networkfamily-plot}{}}} -\subsection{Method \code{plot()}}{ -Display various outputs (goodness-of-fit criteria, robustness, diagnostic) associated with a collection of network fits (a \code{\link{Networkfamily}}) -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Networkfamily$plot( +\subsection{\code{Networkfamily$plot()}}{ + Display various outputs (goodness-of-fit criteria, robustness, diagnostic) associated with a collection of network fits (a \code{\link{Networkfamily}}) + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{Networkfamily$plot( criteria = c("loglik", "pen_loglik", "BIC", "EBIC"), reverse = FALSE, log.x = TRUE -)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{criteria}}{vector of characters. The criteria to plot in \code{c("loglik", "pen_loglik", "BIC", "EBIC")}. Defaults to all of them.} - -\item{\code{reverse}}{A logical indicating whether to plot the value of the criteria in the "natural" direction +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{criteria}}{vector of characters. The criteria to plot in \code{c("loglik", "pen_loglik", "BIC", "EBIC")}. Defaults to all of them.} + \item{\code{reverse}}{A logical indicating whether to plot the value of the criteria in the "natural" direction (loglik - 0.5 penalty) or in the "reverse" direction (-2 loglik + penalty). Default to FALSE, i.e use the natural direction, on the same scale as the log-likelihood.} - -\item{\code{log.x}}{logical: should the x-axis be represented in log-scale? Default is \code{TRUE}.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graph -} + \item{\code{log.x}}{logical: should the x-axis be represented in log-scale? Default is \code{TRUE}.} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graph + } } + \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-Networkfamily-plot_stars}{}}} -\subsection{Method \code{plot_stars()}}{ -Plot stability path -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Networkfamily$plot_stars(stability = 0.9, log.x = TRUE)}\if{html}{\out{
}} +\subsection{\code{Networkfamily$plot_stars()}}{ + Plot stability path + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{Networkfamily$plot_stars(stability = 0.9, log.x = TRUE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{stability}}{scalar: the targeted level of stability using stability selection. Default is \code{0.9}.} + \item{\code{log.x}}{logical: should the x-axis be represented in log-scale? Default is \code{TRUE}.} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graph + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{stability}}{scalar: the targeted level of stability using stability selection. Default is \code{0.9}.} - -\item{\code{log.x}}{logical: should the x-axis be represented in log-scale? Default is \code{TRUE}.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graph -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-Networkfamily-plot_objective}{}}} -\subsection{Method \code{plot_objective()}}{ -Plot objective value of the optimization problem along the penalty path -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Networkfamily$plot_objective()}\if{html}{\out{
}} +\subsection{\code{Networkfamily$plot_objective()}}{ + Plot objective value of the optimization problem along the penalty path + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{Networkfamily$plot_objective()} + \if{html}{\out{
}} + } + \subsection{Returns}{ + a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graph + } } -\subsection{Returns}{ -a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graph -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-Networkfamily-show}{}}} -\subsection{Method \code{show()}}{ -User friendly print method -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Networkfamily$show()}\if{html}{\out{
}} +\subsection{\code{Networkfamily$show()}}{ + User friendly print method + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{Networkfamily$show()} + \if{html}{\out{
}} + } } -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-Networkfamily-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{Networkfamily$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{Networkfamily$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{Networkfamily$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/PLNLDAfit.Rd b/man/PLNLDAfit.Rd index 586089d3..a58d2a2c 100644 --- a/man/PLNLDAfit.Rd +++ b/man/PLNLDAfit.Rd @@ -23,59 +23,58 @@ print(myPLNLDA) The function \code{\link{PLNLDA}}. } \section{Super class}{ -\code{\link[PLNmodels:PLNfit]{PLNmodels::PLNfit}} -> \code{PLNLDAfit} +\code{\link[PLNmodels:PLNfit]{PLNfit}} -> \code{PLNLDAfit} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{rank}}{the dimension of the current model} + \if{html}{\out{
}} + \describe{ + \item{\code{rank}}{the dimension of the current model} -\item{\code{nb_param}}{number of parameters in the current PLN model} + \item{\code{nb_param}}{number of parameters in the current PLN model} -\item{\code{model_par}}{a list with the matrices associated with the estimated parameters of the PLN model: B (covariates), Sigma (latent covariance), C (latent loadings), P (latent position) and Mu (group means)} + \item{\code{model_par}}{a list with the matrices associated with the estimated parameters of the PLN model: B (covariates), Sigma (latent covariance), C (latent loadings), P (latent position) and Mu (group means)} -\item{\code{percent_var}}{the percent of variance explained by each axis} + \item{\code{percent_var}}{the percent of variance explained by each axis} -\item{\code{corr_map}}{a matrix of correlations to plot the correlation circles} + \item{\code{corr_map}}{a matrix of correlations to plot the correlation circles} -\item{\code{scores}}{a matrix of scores to plot the individual factor maps} + \item{\code{scores}}{a matrix of scores to plot the individual factor maps} -\item{\code{group_means}}{a matrix of group mean vectors in the latent space.} -} -\if{html}{\out{
}} + \item{\code{group_means}}{a matrix of group mean vectors in the latent space.} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-PLNLDAfit-new}{\code{PLNLDAfit$new()}} -\item \href{#method-PLNLDAfit-optimize}{\code{PLNLDAfit$optimize()}} -\item \href{#method-PLNLDAfit-postTreatment}{\code{PLNLDAfit$postTreatment()}} -\item \href{#method-PLNLDAfit-setVisualization}{\code{PLNLDAfit$setVisualization()}} -\item \href{#method-PLNLDAfit-plot_individual_map}{\code{PLNLDAfit$plot_individual_map()}} -\item \href{#method-PLNLDAfit-plot_correlation_map}{\code{PLNLDAfit$plot_correlation_map()}} -\item \href{#method-PLNLDAfit-plot_LDA}{\code{PLNLDAfit$plot_LDA()}} -\item \href{#method-PLNLDAfit-predict}{\code{PLNLDAfit$predict()}} -\item \href{#method-PLNLDAfit-show}{\code{PLNLDAfit$show()}} -\item \href{#method-PLNLDAfit-clone}{\code{PLNLDAfit$clone()}} -} -} -\if{html}{\out{ -
Inherited methods + \itemize{ + \item \href{#method-PLNLDAfit-initialize}{\code{PLNLDAfit$new()}} + \item \href{#method-PLNLDAfit-optimize}{\code{PLNLDAfit$optimize()}} + \item \href{#method-PLNLDAfit-postTreatment}{\code{PLNLDAfit$postTreatment()}} + \item \href{#method-PLNLDAfit-setVisualization}{\code{PLNLDAfit$setVisualization()}} + \item \href{#method-PLNLDAfit-plot_individual_map}{\code{PLNLDAfit$plot_individual_map()}} + \item \href{#method-PLNLDAfit-plot_correlation_map}{\code{PLNLDAfit$plot_correlation_map()}} + \item \href{#method-PLNLDAfit-plot_LDA}{\code{PLNLDAfit$plot_LDA()}} + \item \href{#method-PLNLDAfit-predict}{\code{PLNLDAfit$predict()}} + \item \href{#method-PLNLDAfit-show}{\code{PLNLDAfit$show()}} + \item \href{#method-PLNLDAfit-clone}{\code{PLNLDAfit$clone()}} + } +} +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-PLNLDAfit-new}{}}} -\subsection{Method \code{new()}}{ -Initialize a \code{\link{PLNLDAfit}} object -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNLDAfit$new( +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-PLNLDAfit-initialize}{}}} +\subsection{\code{PLNLDAfit$new()}}{ + Initialize a \code{\link{PLNLDAfit}} object + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNLDAfit$new( grouping, responses, covariates, @@ -83,256 +82,246 @@ Initialize a \code{\link{PLNLDAfit}} object weights, formula, control -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{grouping}}{a factor specifying the class of each observation used for discriminant analysis.} + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} + \item{\code{control}}{list controlling the optimization and the model} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{grouping}}{a factor specifying the class of each observation used for discriminant analysis.} - -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} - -\item{\code{control}}{list controlling the optimization and the model} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNLDAfit-optimize}{}}} -\subsection{Method \code{optimize()}}{ -Compute group means and axis of the LDA (noted B in the model) in the +\subsection{\code{PLNLDAfit$optimize()}}{ + Compute group means and axis of the LDA (noted B in the model) in the latent space, update corresponding fields -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNLDAfit$optimize(grouping, responses, covariates, offsets, weights, config)}\if{html}{\out{
}} + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNLDAfit$optimize(grouping, responses, covariates, offsets, weights, config)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{grouping}}{a factor specifying the class of each observation used for discriminant analysis.} + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{covariates}}{design matrix. Automatically built from the covariates and the formula from the call} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{config}}{list controlling the optimization} + \item{\code{X}}{Abundance matrix.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{grouping}}{a factor specifying the class of each observation used for discriminant analysis.} - -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{covariates}}{design matrix. Automatically built from the covariates and the formula from the call} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{config}}{list controlling the optimization} - -\item{\code{X}}{Abundance matrix.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNLDAfit-postTreatment}{}}} -\subsection{Method \code{postTreatment()}}{ -Update R2, fisher and std_err fields and visualization -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNLDAfit$postTreatment( +\subsection{\code{PLNLDAfit$postTreatment()}}{ + Update R2, fisher and std_err fields and visualization + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNLDAfit$postTreatment( grouping, responses, covariates, offsets, config_post, config_optim -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{grouping}}{a factor specifying the class of each observation used for discriminant analysis.} + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{config_post}}{a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.).} + \item{\code{config_optim}}{list controlling the optimization parameters} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{grouping}}{a factor specifying the class of each observation used for discriminant analysis.} - -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{config_post}}{a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.).} - -\item{\code{config_optim}}{list controlling the optimization parameters} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNLDAfit-setVisualization}{}}} -\subsection{Method \code{setVisualization()}}{ -Compute LDA scores in the latent space and update corresponding fields. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNLDAfit$setVisualization(scale.unit = FALSE)}\if{html}{\out{
}} +\subsection{\code{PLNLDAfit$setVisualization()}}{ + Compute LDA scores in the latent space and update corresponding fields. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNLDAfit$setVisualization(scale.unit = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{scale.unit}}{Logical. Should LDA scores be rescaled to have unit variance} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{scale.unit}}{Logical. Should LDA scores be rescaled to have unit variance} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNLDAfit-plot_individual_map}{}}} -\subsection{Method \code{plot_individual_map()}}{ -Plot the factorial map of the LDA -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNLDAfit$plot_individual_map( +\subsection{\code{PLNLDAfit$plot_individual_map()}}{ + Plot the factorial map of the LDA + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNLDAfit$plot_individual_map( axes = 1:min(2, self$rank), main = "Individual Factor Map", plot = TRUE -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{axes}}{numeric, the axes to use for the plot when map = "individual" or "variable". Default it c(1,min(rank))} + \item{\code{main}}{character. A title for the single plot (individual or variable factor map). If NULL (the default), an hopefully appropriate title will be used.} + \item{\code{plot}}{logical. Should the plot be displayed or sent back as ggplot object} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graphic + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{axes}}{numeric, the axes to use for the plot when map = "individual" or "variable". Default it c(1,min(rank))} - -\item{\code{main}}{character. A title for the single plot (individual or variable factor map). If NULL (the default), an hopefully appropriate title will be used.} - -\item{\code{plot}}{logical. Should the plot be displayed or sent back as ggplot object} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graphic -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNLDAfit-plot_correlation_map}{}}} -\subsection{Method \code{plot_correlation_map()}}{ -Plot the correlation circle of a specified axis for a \code{\link{PLNLDAfit}} object -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNLDAfit$plot_correlation_map( +\subsection{\code{PLNLDAfit$plot_correlation_map()}}{ + Plot the correlation circle of a specified axis for a \code{\link{PLNLDAfit}} object + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNLDAfit$plot_correlation_map( axes = 1:min(2, self$rank), main = "Variable Factor Map", cols = "default", plot = TRUE -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{axes}}{numeric, the axes to use for the plot when map = "individual" or "variable". Default it c(1,min(rank))} + \item{\code{main}}{character. A title for the single plot (individual or variable factor map). If NULL (the default), an hopefully appropriate title will be used.} + \item{\code{cols}}{a character, factor or numeric to define the color associated with the variables. By default, all variables receive the default color of the current palette.} + \item{\code{plot}}{logical. Should the plot be displayed or sent back as ggplot object} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graphic + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{axes}}{numeric, the axes to use for the plot when map = "individual" or "variable". Default it c(1,min(rank))} - -\item{\code{main}}{character. A title for the single plot (individual or variable factor map). If NULL (the default), an hopefully appropriate title will be used.} - -\item{\code{cols}}{a character, factor or numeric to define the color associated with the variables. By default, all variables receive the default color of the current palette.} - -\item{\code{plot}}{logical. Should the plot be displayed or sent back as ggplot object} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graphic -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNLDAfit-plot_LDA}{}}} -\subsection{Method \code{plot_LDA()}}{ -Plot a summary of the \code{\link{PLNLDAfit}} object -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNLDAfit$plot_LDA( +\subsection{\code{PLNLDAfit$plot_LDA()}}{ + Plot a summary of the \code{\link{PLNLDAfit}} object + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNLDAfit$plot_LDA( nb_axes = min(3, self$rank), var_cols = "default", plot = TRUE -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{nb_axes}}{scalar: the number of axes to be considered when map = "both". The default is min(3,rank).} + \item{\code{var_cols}}{a character, factor or numeric to define the color associated with the variables. By default, all variables receive the default color of the current palette.} + \item{\code{plot}}{logical. Should the plot be displayed or sent back as ggplot object} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + a \code{\link{grob}} object + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{nb_axes}}{scalar: the number of axes to be considered when map = "both". The default is min(3,rank).} - -\item{\code{var_cols}}{a character, factor or numeric to define the color associated with the variables. By default, all variables receive the default color of the current palette.} - -\item{\code{plot}}{logical. Should the plot be displayed or sent back as ggplot object} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -a \code{\link{grob}} object -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNLDAfit-predict}{}}} -\subsection{Method \code{predict()}}{ -Predict group of new samples -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNLDAfit$predict( +\subsection{\code{PLNLDAfit$predict()}}{ + Predict group of new samples + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNLDAfit$predict( newdata, type = c("posterior", "response", "scores"), scale = c("log", "prob"), prior = NULL, control = PLN_param(backend = "nlopt"), envir = parent.frame() -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{newdata}}{A data frame in which to look for variables, offsets and counts with which to predict.} + \item{\code{type}}{The type of prediction required. The default are posterior probabilities for each group (in either unnormalized log-scale or natural probabilities, see "scale" for details), "response" is the group with maximal posterior probability and "scores" is the average score along each separation axis in the latent space, with weights equal to the posterior probabilities.} + \item{\code{scale}}{The scale used for the posterior probability. Either log-scale ("log", default) or natural probabilities summing up to 1 ("prob").} + \item{\code{prior}}{User-specified prior group probabilities in the new data. If NULL (default), prior probabilities are computed from the learning set.} + \item{\code{control}}{a list for controlling the optimization. See \code{\link[=PLN]{PLN()}} for details.} + \item{\code{envir}}{Environment in which the prediction is evaluated} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{newdata}}{A data frame in which to look for variables, offsets and counts with which to predict.} - -\item{\code{type}}{The type of prediction required. The default are posterior probabilities for each group (in either unnormalized log-scale or natural probabilities, see "scale" for details), "response" is the group with maximal posterior probability and "scores" is the average score along each separation axis in the latent space, with weights equal to the posterior probabilities.} - -\item{\code{scale}}{The scale used for the posterior probability. Either log-scale ("log", default) or natural probabilities summing up to 1 ("prob").} - -\item{\code{prior}}{User-specified prior group probabilities in the new data. If NULL (default), prior probabilities are computed from the learning set.} - -\item{\code{control}}{a list for controlling the optimization. See \code{\link[=PLN]{PLN()}} for details.} - -\item{\code{envir}}{Environment in which the prediction is evaluated} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNLDAfit-show}{}}} -\subsection{Method \code{show()}}{ -User friendly print method -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNLDAfit$show()}\if{html}{\out{
}} +\subsection{\code{PLNLDAfit$show()}}{ + User friendly print method + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNLDAfit$show()} + \if{html}{\out{
}} + } } -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNLDAfit-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNLDAfit$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{PLNLDAfit$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNLDAfit$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/PLNLDAfit_diagonal.Rd b/man/PLNLDAfit_diagonal.Rd index 0db19353..a9b5b101 100644 --- a/man/PLNLDAfit_diagonal.Rd +++ b/man/PLNLDAfit_diagonal.Rd @@ -20,49 +20,48 @@ print(myPLNLDA) } } \section{Super classes}{ -\code{\link[PLNmodels:PLNfit]{PLNmodels::PLNfit}} -> \code{\link[PLNmodels:PLNLDAfit]{PLNmodels::PLNLDAfit}} -> \code{PLNLDAfit_diagonal} +\code{\link[PLNmodels:PLNfit]{PLNfit}} -> \code{\link[PLNmodels:PLNLDAfit]{PLNLDAfit}} -> \code{PLNLDAfit_diagonal} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{vcov_model}}{character: the model used for the residual covariance} + \if{html}{\out{
}} + \describe{ + \item{\code{vcov_model}}{character: the model used for the residual covariance} -\item{\code{nb_param}}{number of parameters in the current PLN model} -} -\if{html}{\out{
}} + \item{\code{nb_param}}{number of parameters in the current PLN model} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-PLNLDAfit_diagonal-new}{\code{PLNLDAfit_diagonal$new()}} -\item \href{#method-PLNLDAfit_diagonal-clone}{\code{PLNLDAfit_diagonal$clone()}} -} + \itemize{ + \item \href{#method-PLNLDAfit_diagonal-initialize}{\code{PLNLDAfit_diagonal$new()}} + \item \href{#method-PLNLDAfit_diagonal-clone}{\code{PLNLDAfit_diagonal$clone()}} + } } -\if{html}{\out{ -
Inherited methods +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-PLNLDAfit_diagonal-new}{}}} -\subsection{Method \code{new()}}{ -Initialize a \code{\link{PLNfit}} model -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNLDAfit_diagonal$new( +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-PLNLDAfit_diagonal-initialize}{}}} +\subsection{\code{PLNLDAfit_diagonal$new()}}{ + Initialize a \code{\link{PLNfit}} model + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNLDAfit_diagonal$new( grouping, responses, covariates, @@ -70,44 +69,41 @@ Initialize a \code{\link{PLNfit}} model weights, formula, control -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{grouping}}{a factor specifying the class of each observation used for discriminant analysis.} + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} + \item{\code{control}}{a list for controlling the optimization. See details.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{grouping}}{a factor specifying the class of each observation used for discriminant analysis.} - -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} - -\item{\code{control}}{a list for controlling the optimization. See details.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNLDAfit_diagonal-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNLDAfit_diagonal$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{PLNLDAfit_diagonal$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNLDAfit_diagonal$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/PLNPCAfamily.Rd b/man/PLNPCAfamily.Rd index d93a8bb5..085decf6 100644 --- a/man/PLNPCAfamily.Rd +++ b/man/PLNPCAfamily.Rd @@ -20,42 +20,41 @@ class(myPCAs) The function \code{\link[=PLNPCA]{PLNPCA()}}, the class \code{\link[=PLNPCAfit]{PLNPCAfit()}} } \section{Super class}{ -\code{\link[PLNmodels:PLNfamily]{PLNmodels::PLNfamily}} -> \code{PLNPCAfamily} +\code{\link[PLNmodels:PLNfamily]{PLNfamily}} -> \code{PLNPCAfamily} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{ranks}}{the dimensions of the successively fitted models} -} -\if{html}{\out{
}} + \if{html}{\out{
}} + \describe{ + \item{\code{ranks}}{the dimensions of the successively fitted models} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-PLNPCAfamily-new}{\code{PLNPCAfamily$new()}} -\item \href{#method-PLNPCAfamily-optimize}{\code{PLNPCAfamily$optimize()}} -\item \href{#method-PLNPCAfamily-getModel}{\code{PLNPCAfamily$getModel()}} -\item \href{#method-PLNPCAfamily-getBestModel}{\code{PLNPCAfamily$getBestModel()}} -\item \href{#method-PLNPCAfamily-plot}{\code{PLNPCAfamily$plot()}} -\item \href{#method-PLNPCAfamily-show}{\code{PLNPCAfamily$show()}} -\item \href{#method-PLNPCAfamily-clone}{\code{PLNPCAfamily$clone()}} -} -} -\if{html}{\out{ -
Inherited methods + \itemize{ + \item \href{#method-PLNPCAfamily-initialize}{\code{PLNPCAfamily$new()}} + \item \href{#method-PLNPCAfamily-optimize}{\code{PLNPCAfamily$optimize()}} + \item \href{#method-PLNPCAfamily-getModel}{\code{PLNPCAfamily$getModel()}} + \item \href{#method-PLNPCAfamily-getBestModel}{\code{PLNPCAfamily$getBestModel()}} + \item \href{#method-PLNPCAfamily-plot}{\code{PLNPCAfamily$plot()}} + \item \href{#method-PLNPCAfamily-show}{\code{PLNPCAfamily$show()}} + \item \href{#method-PLNPCAfamily-clone}{\code{PLNPCAfamily$clone()}} + } +} +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-PLNPCAfamily-new}{}}} -\subsection{Method \code{new()}}{ -Initialize all models in the collection. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfamily$new( +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-PLNPCAfamily-initialize}{}}} +\subsection{\code{PLNPCAfamily$new()}}{ + Initialize all models in the collection. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfamily$new( ranks, responses, covariates, @@ -63,138 +62,143 @@ Initialize all models in the collection. weights, formula, control -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{ranks}}{the dimensions of the successively fitted models} + \item{\code{responses}}{the matrix of responses common to every models} + \item{\code{covariates}}{the matrix of covariates common to every models} + \item{\code{offsets}}{the matrix of offsets common to every models} + \item{\code{weights}}{the vector of observation weights} + \item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} + \item{\code{control}}{list controlling the optimization and the model} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{ranks}}{the dimensions of the successively fitted models} - -\item{\code{responses}}{the matrix of responses common to every models} - -\item{\code{covariates}}{the matrix of covariates common to every models} - -\item{\code{offsets}}{the matrix of offsets common to every models} - -\item{\code{weights}}{the vector of observation weights} - -\item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} - -\item{\code{control}}{list controlling the optimization and the model} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfamily-optimize}{}}} -\subsection{Method \code{optimize()}}{ -Call to the C++ optimizer on all models of the collection -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfamily$optimize(config)}\if{html}{\out{
}} +\subsection{\code{PLNPCAfamily$optimize()}}{ + Call to the C++ optimizer on all models of the collection + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfamily$optimize(config)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{config}}{list controlling the optimization.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{config}}{list controlling the optimization.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfamily-getModel}{}}} -\subsection{Method \code{getModel()}}{ -Extract model from collection and add "PCA" class for compatibility with \code{\link[factoextra:fviz]{factoextra::fviz()}} -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfamily$getModel(var, index = NULL)}\if{html}{\out{
}} +\subsection{\code{PLNPCAfamily$getModel()}}{ + Extract model from collection and add "PCA" class for compatibility with \code{\link[factoextra:fviz]{factoextra::fviz()}} + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfamily$getModel(var, index = NULL)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{var}}{value of the parameter (rank for PLNPCA, sparsity for PLNnetwork) that identifies the model to be extracted from the collection. If no exact match is found, the model with closest parameter value is returned with a warning.} + \item{\code{index}}{Integer index of the model to be returned. Only the first value is taken into account.} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + a \code{\link{PLNPCAfit}} object + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{var}}{value of the parameter (rank for PLNPCA, sparsity for PLNnetwork) that identifies the model to be extracted from the collection. If no exact match is found, the model with closest parameter value is returned with a warning.} - -\item{\code{index}}{Integer index of the model to be returned. Only the first value is taken into account.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -a \code{\link{PLNPCAfit}} object -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfamily-getBestModel}{}}} -\subsection{Method \code{getBestModel()}}{ -Extract best model in the collection -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfamily$getBestModel(crit = c("ICL", "BIC"))}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{crit}}{a character for the criterion used to performed the selection. Either +\subsection{\code{PLNPCAfamily$getBestModel()}}{ + Extract best model in the collection + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfamily$getBestModel(crit = c("ICL", "BIC"))} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{crit}}{a character for the criterion used to performed the selection. Either "ICL", "BIC". Default is \code{ICL}} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + a \code{\link{PLNPCAfit}} object + } } -\if{html}{\out{
}} -} -\subsection{Returns}{ -a \code{\link{PLNPCAfit}} object -} -} + \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfamily-plot}{}}} -\subsection{Method \code{plot()}}{ -Lineplot of selected criteria for all models in the collection -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfamily$plot(criteria = c("loglik", "BIC", "ICL"), reverse = FALSE)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{criteria}}{A valid model selection criteria for the collection of models. Any of "loglik", "BIC" or "ICL" (all).} - -\item{\code{reverse}}{A logical indicating whether to plot the value of the criteria in the "natural" direction +\subsection{\code{PLNPCAfamily$plot()}}{ + Lineplot of selected criteria for all models in the collection + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfamily$plot(criteria = c("loglik", "BIC", "ICL"), reverse = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{criteria}}{A valid model selection criteria for the collection of models. Any of "loglik", "BIC" or "ICL" (all).} + \item{\code{reverse}}{A logical indicating whether to plot the value of the criteria in the "natural" direction (loglik - penalty) or in the "reverse" direction (-2 loglik + penalty). Default to FALSE, i.e use the natural direction, on the same scale as the log-likelihood.} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + A \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} object + } } -\if{html}{\out{
}} -} -\subsection{Returns}{ -A \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} object -} -} + \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfamily-show}{}}} -\subsection{Method \code{show()}}{ -User friendly print method -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfamily$show()}\if{html}{\out{
}} +\subsection{\code{PLNPCAfamily$show()}}{ + User friendly print method + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfamily$show()} + \if{html}{\out{
}} + } } -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfamily-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfamily$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{PLNPCAfamily$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfamily$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/PLNPCAfit.Rd b/man/PLNPCAfit.Rd index 16dbc837..e1383708 100644 --- a/man/PLNPCAfit.Rd +++ b/man/PLNPCAfit.Rd @@ -20,103 +20,98 @@ print(myPCA) The function \code{\link{PLNPCA}}, the class \code{\link[=PLNPCAfamily]{PLNPCAfamily}} } \section{Super class}{ -\code{\link[PLNmodels:PLNfit]{PLNmodels::PLNfit}} -> \code{PLNPCAfit} +\code{\link[PLNmodels:PLNfit]{PLNfit}} -> \code{PLNPCAfit} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{rank}}{the dimension of the current model} + \if{html}{\out{
}} + \describe{ + \item{\code{rank}}{the dimension of the current model} -\item{\code{vcov_model}}{character: the model used for the residual covariance} + \item{\code{vcov_model}}{character: the model used for the residual covariance} -\item{\code{nb_param}}{number of parameters in the current PLN model} + \item{\code{nb_param}}{number of parameters in the current PLN model} -\item{\code{entropy}}{entropy of the variational distribution} + \item{\code{entropy}}{entropy of the variational distribution} -\item{\code{latent_pos}}{a matrix: values of the latent position vector (Z) without covariates effects or offset} + \item{\code{latent_pos}}{a matrix: values of the latent position vector (Z) without covariates effects or offset} -\item{\code{model_par}}{a list with the matrices associated with the estimated parameters of the pPCA model: B (covariates), Sigma (covariance), Omega (precision) and C (loadings)} + \item{\code{model_par}}{a list with the matrices associated with the estimated parameters of the pPCA model: B (covariates), Sigma (covariance), Omega (precision) and C (loadings)} -\item{\code{percent_var}}{the percent of variance explained by each axis} + \item{\code{percent_var}}{the percent of variance explained by each axis} -\item{\code{corr_circle}}{a matrix of correlations to plot the correlation circles} + \item{\code{corr_circle}}{a matrix of correlations to plot the correlation circles} -\item{\code{scores}}{a matrix of scores to plot the individual factor maps (a.k.a. principal components)} + \item{\code{scores}}{a matrix of scores to plot the individual factor maps (a.k.a. principal components)} -\item{\code{rotation}}{a matrix of rotation of the latent space} + \item{\code{rotation}}{a matrix of rotation of the latent space} -\item{\code{eig}}{description of the eigenvalues, similar to percent_var but for use with external methods} + \item{\code{eig}}{description of the eigenvalues, similar to percent_var but for use with external methods} -\item{\code{var}}{a list of data frames with PCA results for the variables: \code{coord} (coordinates of the variables), \code{cor} (correlation between variables and dimensions), \code{cos2} (Cosine of the variables) and \code{contrib} (contributions of the variable to the axes)} + \item{\code{var}}{a list of data frames with PCA results for the variables: \code{coord} (coordinates of the variables), \code{cor} (correlation between variables and dimensions), \code{cos2} (Cosine of the variables) and \code{contrib} (contributions of the variable to the axes)} -\item{\code{ind}}{a list of data frames with PCA results for the individuals: \code{coord} (coordinates of the individuals), \code{cos2} (Cosine of the individuals), \code{contrib} (contributions of individuals to an axis inertia) and \code{dist} (distance of individuals to the origin).} + \item{\code{ind}}{a list of data frames with PCA results for the individuals: \code{coord} (coordinates of the individuals), \code{cos2} (Cosine of the individuals), \code{contrib} (contributions of individuals to an axis inertia) and \code{dist} (distance of individuals to the origin).} -\item{\code{call}}{Hacky binding for compatibility with factoextra functions} -} -\if{html}{\out{
}} + \item{\code{call}}{Hacky binding for compatibility with factoextra functions} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-PLNPCAfit-new}{\code{PLNPCAfit$new()}} -\item \href{#method-PLNPCAfit-update}{\code{PLNPCAfit$update()}} -\item \href{#method-PLNPCAfit-optimize}{\code{PLNPCAfit$optimize()}} -\item \href{#method-PLNPCAfit-optimize_vestep}{\code{PLNPCAfit$optimize_vestep()}} -\item \href{#method-PLNPCAfit-project}{\code{PLNPCAfit$project()}} -\item \href{#method-PLNPCAfit-setVisualization}{\code{PLNPCAfit$setVisualization()}} -\item \href{#method-PLNPCAfit-postTreatment}{\code{PLNPCAfit$postTreatment()}} -\item \href{#method-PLNPCAfit-plot_individual_map}{\code{PLNPCAfit$plot_individual_map()}} -\item \href{#method-PLNPCAfit-plot_correlation_circle}{\code{PLNPCAfit$plot_correlation_circle()}} -\item \href{#method-PLNPCAfit-plot_PCA}{\code{PLNPCAfit$plot_PCA()}} -\item \href{#method-PLNPCAfit-show}{\code{PLNPCAfit$show()}} -\item \href{#method-PLNPCAfit-clone}{\code{PLNPCAfit$clone()}} -} -} -\if{html}{\out{ -
Inherited methods + \itemize{ + \item \href{#method-PLNPCAfit-initialize}{\code{PLNPCAfit$new()}} + \item \href{#method-PLNPCAfit-update}{\code{PLNPCAfit$update()}} + \item \href{#method-PLNPCAfit-optimize}{\code{PLNPCAfit$optimize()}} + \item \href{#method-PLNPCAfit-optimize_vestep}{\code{PLNPCAfit$optimize_vestep()}} + \item \href{#method-PLNPCAfit-project}{\code{PLNPCAfit$project()}} + \item \href{#method-PLNPCAfit-setVisualization}{\code{PLNPCAfit$setVisualization()}} + \item \href{#method-PLNPCAfit-postTreatment}{\code{PLNPCAfit$postTreatment()}} + \item \href{#method-PLNPCAfit-plot_individual_map}{\code{PLNPCAfit$plot_individual_map()}} + \item \href{#method-PLNPCAfit-plot_correlation_circle}{\code{PLNPCAfit$plot_correlation_circle()}} + \item \href{#method-PLNPCAfit-plot_PCA}{\code{PLNPCAfit$plot_PCA()}} + \item \href{#method-PLNPCAfit-show}{\code{PLNPCAfit$show()}} + \item \href{#method-PLNPCAfit-clone}{\code{PLNPCAfit$clone()}} + } +} +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-PLNPCAfit-new}{}}} -\subsection{Method \code{new()}}{ -Initialize a \code{\link{PLNPCAfit}} object -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfit$new(rank, responses, covariates, offsets, weights, formula, control)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-PLNPCAfit-initialize}{}}} +\subsection{\code{PLNPCAfit$new()}}{ + Initialize a \code{\link{PLNPCAfit}} object + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfit$new(rank, responses, covariates, offsets, weights, formula, control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{rank}}{rank of the PCA (or equivalently, dimension of the latent space)} + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} + \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} + \item{\code{control}}{a list for controlling the optimization. See details.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{rank}}{rank of the PCA (or equivalently, dimension of the latent space)} - -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} - -\item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} - -\item{\code{control}}{a list for controlling the optimization. See details.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfit-update}{}}} -\subsection{Method \code{update()}}{ -Update a \code{\link{PLNPCAfit}} object -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfit$update( +\subsection{\code{PLNPCAfit$update()}}{ + Update a \code{\link{PLNPCAfit}} object + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfit$update( B = NA, Sigma = NA, Omega = NA, @@ -128,154 +123,144 @@ Update a \code{\link{PLNPCAfit}} object Ji = NA, R2 = NA, monitoring = NA -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{B}}{matrix of regression matrix} + \item{\code{Sigma}}{variance-covariance matrix of the latent variables} + \item{\code{Omega}}{precision matrix of the latent variables. Inverse of Sigma.} + \item{\code{C}}{matrix of PCA loadings (in the latent space)} + \item{\code{M}}{matrix of mean vectors for the variational approximation} + \item{\code{S}}{matrix of variance vectors for the variational approximation} + \item{\code{Z}}{matrix of latent vectors (includes covariates and offset effects)} + \item{\code{A}}{matrix of fitted values} + \item{\code{Ji}}{vector of variational lower bounds of the log-likelihoods (one value per sample)} + \item{\code{R2}}{approximate R^2 goodness-of-fit criterion} + \item{\code{monitoring}}{a list with optimization monitoring quantities} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + Update the current \code{\link{PLNPCAfit}} object + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{B}}{matrix of regression matrix} - -\item{\code{Sigma}}{variance-covariance matrix of the latent variables} - -\item{\code{Omega}}{precision matrix of the latent variables. Inverse of Sigma.} - -\item{\code{C}}{matrix of PCA loadings (in the latent space)} - -\item{\code{M}}{matrix of mean vectors for the variational approximation} - -\item{\code{S}}{matrix of variance vectors for the variational approximation} - -\item{\code{Z}}{matrix of latent vectors (includes covariates and offset effects)} - -\item{\code{A}}{matrix of fitted values} - -\item{\code{Ji}}{vector of variational lower bounds of the log-likelihoods (one value per sample)} - -\item{\code{R2}}{approximate R^2 goodness-of-fit criterion} - -\item{\code{monitoring}}{a list with optimization monitoring quantities} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -Update the current \code{\link{PLNPCAfit}} object -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfit-optimize}{}}} -\subsection{Method \code{optimize()}}{ -Call to the C++ optimizer and update of the relevant fields -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfit$optimize(responses, covariates, offsets, weights, config)}\if{html}{\out{
}} +\subsection{\code{PLNPCAfit$optimize()}}{ + Call to the C++ optimizer and update of the relevant fields + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfit$optimize(responses, covariates, offsets, weights, config)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} + \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{config}}{part of the \code{control} argument which configures the optimizer} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} - -\item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{config}}{part of the \code{control} argument which configures the optimizer} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfit-optimize_vestep}{}}} -\subsection{Method \code{optimize_vestep()}}{ -Result of one call to the VE step of the optimization procedure: optimal variational parameters (M, S) and corresponding log likelihood values for fixed model parameters (C, B). Intended to position new data in the latent space for further use with PCA. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfit$optimize_vestep( +\subsection{\code{PLNPCAfit$optimize_vestep()}}{ + Result of one call to the VE step of the optimization procedure: optimal variational parameters (M, S) and corresponding log likelihood values for fixed model parameters (C, B). Intended to position new data in the latent space for further use with PCA. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfit$optimize_vestep( covariates, offsets, responses, weights = rep(1, self$n), control = PLNPCA_param(backend = "nlopt") -)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} - -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{control}}{a list for controlling the optimization. See details.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -A list with three components: +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{control}}{a list for controlling the optimization. See details.} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + A list with three components: \itemize{ \item the matrix \code{M} of variational means, \item the matrix \code{S2} of variational variances \item the vector \code{log.lik} of (variational) log-likelihood of each new observation } + } } -} + \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfit-project}{}}} -\subsection{Method \code{project()}}{ -Project new samples into the PCA space using one VE step -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfit$project(newdata, control = PLNPCA_param(), envir = parent.frame())}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{newdata}}{A data frame in which to look for variables, offsets and counts with which to predict.} - -\item{\code{control}}{a list for controlling the optimization. See \code{\link[=PLN]{PLN()}} for details.} - -\item{\code{envir}}{Environment in which the projection is evaluated} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -\itemize{ +\subsection{\code{PLNPCAfit$project()}}{ + Project new samples into the PCA space using one VE step + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfit$project(newdata, control = PLNPCA_param(), envir = parent.frame())} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{newdata}}{A data frame in which to look for variables, offsets and counts with which to predict.} + \item{\code{control}}{a list for controlling the optimization. See \code{\link[=PLN]{PLN()}} for details.} + \item{\code{envir}}{Environment in which the projection is evaluated} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + \itemize{ \item the named matrix of scores for the newdata, expressed in the same coordinate system as \code{self$scores} } + } } -} + \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfit-setVisualization}{}}} -\subsection{Method \code{setVisualization()}}{ -Compute PCA scores in the latent space and update corresponding fields. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfit$setVisualization(scale.unit = FALSE)}\if{html}{\out{
}} +\subsection{\code{PLNPCAfit$setVisualization()}}{ + Compute PCA scores in the latent space and update corresponding fields. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfit$setVisualization(scale.unit = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{scale.unit}}{Logical. Should PCA scores be rescaled to have unit variance} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{scale.unit}}{Logical. Should PCA scores be rescaled to have unit variance} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfit-postTreatment}{}}} -\subsection{Method \code{postTreatment()}}{ -Update R2, fisher, std_err fields and set up visualization -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfit$postTreatment( +\subsection{\code{PLNPCAfit$postTreatment()}}{ + Update R2, fisher, std_err fields and set up visualization + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfit$postTreatment( responses, covariates, offsets, @@ -283,30 +268,24 @@ Update R2, fisher, std_err fields and set up visualization config_post, config_optim, nullModel -)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} - -\item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{config_post}}{a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.). See details} - -\item{\code{config_optim}}{a list for controlling the optimizer (either "nlopt" or "torch" backend). See details} - -\item{\code{nullModel}}{null model used for approximate R2 computations. Defaults to a GLM model with same design matrix but not latent variable.} -} -\if{html}{\out{
}} -} -\subsection{Details}{ -The list of parameters \code{config_post} controls the post-treatment processing, with the following entries: +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} + \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in \code{\link{PLNfamily}}} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{config_post}}{a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.). See details} + \item{\code{config_optim}}{a list for controlling the optimizer (either "nlopt" or "torch" backend). See details} + \item{\code{nullModel}}{null model used for approximate R2 computations. Defaults to a GLM model with same design matrix but not latent variable.} + } + \if{html}{\out{
}} + } + \subsection{Details}{ + The list of parameters \code{config_post} controls the post-treatment processing, with the following entries: \itemize{ \item jackknife boolean indicating whether jackknife should be performed to evaluate bias and variance of the model parameters. Default is FALSE. \item bootstrap integer indicating the number of bootstrap resamples generated to evaluate the variance of the model parameters. Default is 0 (inactivated). @@ -314,127 +293,128 @@ The list of parameters \code{config_post} controls the post-treatment processing \item rsquared boolean indicating whether approximation of R2 based on deviance should be computed. Default is TRUE \item trace integer for verbosity. should be > 1 to see output in post-treatments } + } } -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfit-plot_individual_map}{}}} -\subsection{Method \code{plot_individual_map()}}{ -Plot the factorial map of the PCA -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfit$plot_individual_map( +\subsection{\code{PLNPCAfit$plot_individual_map()}}{ + Plot the factorial map of the PCA + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfit$plot_individual_map( axes = 1:min(2, self$rank), main = "Individual Factor Map", plot = TRUE, cols = "default" -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{axes}}{numeric, the axes to use for the plot when map = "individual" or "variable". Default it c(1,min(rank))} + \item{\code{main}}{character. A title for the single plot (individual or variable factor map). If NULL (the default), an hopefully appropriate title will be used.} + \item{\code{plot}}{logical. Should the plot be displayed or sent back as ggplot object} + \item{\code{cols}}{a character, factor or numeric to define the color associated with the individuals. By default, all individuals receive the default color of the current palette.} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graphic + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{axes}}{numeric, the axes to use for the plot when map = "individual" or "variable". Default it c(1,min(rank))} - -\item{\code{main}}{character. A title for the single plot (individual or variable factor map). If NULL (the default), an hopefully appropriate title will be used.} - -\item{\code{plot}}{logical. Should the plot be displayed or sent back as ggplot object} - -\item{\code{cols}}{a character, factor or numeric to define the color associated with the individuals. By default, all individuals receive the default color of the current palette.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graphic -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfit-plot_correlation_circle}{}}} -\subsection{Method \code{plot_correlation_circle()}}{ -Plot the correlation circle of a specified axis for a \code{\link{PLNLDAfit}} object -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfit$plot_correlation_circle( +\subsection{\code{PLNPCAfit$plot_correlation_circle()}}{ + Plot the correlation circle of a specified axis for a \code{\link{PLNLDAfit}} object + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfit$plot_correlation_circle( axes = 1:min(2, self$rank), main = "Variable Factor Map", cols = "default", plot = TRUE -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{axes}}{numeric, the axes to use for the plot when map = "individual" or "variable". Default it c(1,min(rank))} + \item{\code{main}}{character. A title for the single plot (individual or variable factor map). If NULL (the default), an hopefully appropriate title will be used.} + \item{\code{cols}}{a character, factor or numeric to define the color associated with the variables. By default, all variables receive the default color of the current palette.} + \item{\code{plot}}{logical. Should the plot be displayed or sent back as ggplot object} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graphic + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{axes}}{numeric, the axes to use for the plot when map = "individual" or "variable". Default it c(1,min(rank))} - -\item{\code{main}}{character. A title for the single plot (individual or variable factor map). If NULL (the default), an hopefully appropriate title will be used.} - -\item{\code{cols}}{a character, factor or numeric to define the color associated with the variables. By default, all variables receive the default color of the current palette.} - -\item{\code{plot}}{logical. Should the plot be displayed or sent back as ggplot object} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graphic -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfit-plot_PCA}{}}} -\subsection{Method \code{plot_PCA()}}{ -Plot a summary of the \code{\link{PLNPCAfit}} object -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfit$plot_PCA( +\subsection{\code{PLNPCAfit$plot_PCA()}}{ + Plot a summary of the \code{\link{PLNPCAfit}} object + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfit$plot_PCA( nb_axes = min(3, self$rank), ind_cols = "ind_cols", var_cols = "var_cols", plot = TRUE -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{nb_axes}}{scalar: the number of axes to be considered when map = "both". The default is min(3,rank).} + \item{\code{ind_cols}}{a character, factor or numeric to define the color associated with the individuals. By default, all variables receive the default color of the current palette.} + \item{\code{var_cols}}{a character, factor or numeric to define the color associated with the variables. By default, all variables receive the default color of the current palette.} + \item{\code{plot}}{logical. Should the plot be displayed or sent back as ggplot object} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + a \code{\link{grob}} object + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{nb_axes}}{scalar: the number of axes to be considered when map = "both". The default is min(3,rank).} - -\item{\code{ind_cols}}{a character, factor or numeric to define the color associated with the individuals. By default, all variables receive the default color of the current palette.} - -\item{\code{var_cols}}{a character, factor or numeric to define the color associated with the variables. By default, all variables receive the default color of the current palette.} - -\item{\code{plot}}{logical. Should the plot be displayed or sent back as ggplot object} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -a \code{\link{grob}} object -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfit-show}{}}} -\subsection{Method \code{show()}}{ -User friendly print method -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfit$show()}\if{html}{\out{
}} +\subsection{\code{PLNPCAfit$show()}}{ + User friendly print method + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfit$show()} + \if{html}{\out{
}} + } } -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfit-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNPCAfit$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{PLNPCAfit$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfit$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/PLNfamily.Rd b/man/PLNfamily.Rd index 7450c083..50d32cc7 100644 --- a/man/PLNfamily.Rd +++ b/man/PLNfamily.Rd @@ -10,172 +10,179 @@ super class for \code{\link{PLNPCAfamily}} and \code{\link{PLNnetworkfamily}}. \code{\link[=getModel]{getModel()}} } \section{Public fields}{ -\if{html}{\out{
}} -\describe{ -\item{\code{responses}}{the matrix of responses common to every models} + \if{html}{\out{
}} + \describe{ + \item{\code{responses}}{the matrix of responses common to every models} -\item{\code{covariates}}{the matrix of covariates common to every models} + \item{\code{covariates}}{the matrix of covariates common to every models} -\item{\code{offsets}}{the matrix of offsets common to every models} + \item{\code{offsets}}{the matrix of offsets common to every models} -\item{\code{weights}}{the vector of observation weights} + \item{\code{weights}}{the vector of observation weights} -\item{\code{inception}}{a \link{PLNfit} object, obtained when no sparsifying penalty is applied.} + \item{\code{inception}}{a \link{PLNfit} object, obtained when no sparsifying penalty is applied.} -\item{\code{models}}{a list of \link{PLNfit} object, one per penalty.} -} -\if{html}{\out{
}} + \item{\code{models}}{a list of \link{PLNfit} object, one per penalty.} + } + \if{html}{\out{
}} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{criteria}}{a data frame with the values of some criteria (approximated log-likelihood, BIC, ICL, etc.) for the collection of models / fits + \if{html}{\out{
}} + \describe{ + \item{\code{criteria}}{a data frame with the values of some criteria (approximated log-likelihood, BIC, ICL, etc.) for the collection of models / fits BIC and ICL are defined so that they are on the same scale as the model log-likelihood, i.e. with the form, loglik - 0.5 penalty} -\item{\code{convergence}}{sends back a data frame with some convergence diagnostics associated with the optimization process (method, optimal value, etc)} -} -\if{html}{\out{
}} + \item{\code{convergence}}{sends back a data frame with some convergence diagnostics associated with the optimization process (method, optimal value, etc)} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-PLNfamily-new}{\code{PLNfamily$new()}} -\item \href{#method-PLNfamily-postTreatment}{\code{PLNfamily$postTreatment()}} -\item \href{#method-PLNfamily-getModel}{\code{PLNfamily$getModel()}} -\item \href{#method-PLNfamily-plot}{\code{PLNfamily$plot()}} -\item \href{#method-PLNfamily-show}{\code{PLNfamily$show()}} -\item \href{#method-PLNfamily-print}{\code{PLNfamily$print()}} -\item \href{#method-PLNfamily-clone}{\code{PLNfamily$clone()}} -} + \itemize{ + \item \href{#method-PLNfamily-initialize}{\code{PLNfamily$new()}} + \item \href{#method-PLNfamily-postTreatment}{\code{PLNfamily$postTreatment()}} + \item \href{#method-PLNfamily-getModel}{\code{PLNfamily$getModel()}} + \item \href{#method-PLNfamily-plot}{\code{PLNfamily$plot()}} + \item \href{#method-PLNfamily-show}{\code{PLNfamily$show()}} + \item \href{#method-PLNfamily-print}{\code{PLNfamily$print()}} + \item \href{#method-PLNfamily-clone}{\code{PLNfamily$clone()}} + } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-PLNfamily-new}{}}} -\subsection{Method \code{new()}}{ -Create a new \code{\link{PLNfamily}} object. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfamily$new(responses, covariates, offsets, weights, control)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-PLNfamily-initialize}{}}} +\subsection{\code{PLNfamily$new()}}{ + Create a new \code{\link{PLNfamily}} object. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfamily$new(responses, covariates, offsets, weights, control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{responses}}{the matrix of responses common to every models} + \item{\code{covariates}}{the matrix of covariates common to every models} + \item{\code{offsets}}{the matrix of offsets common to every models} + \item{\code{weights}}{the vector of observation weights} + \item{\code{control}}{list controlling the optimization and the model} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + A new \code{\link{PLNfamily}} object + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{responses}}{the matrix of responses common to every models} - -\item{\code{covariates}}{the matrix of covariates common to every models} - -\item{\code{offsets}}{the matrix of offsets common to every models} - -\item{\code{weights}}{the vector of observation weights} - -\item{\code{control}}{list controlling the optimization and the model} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -A new \code{\link{PLNfamily}} object -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfamily-postTreatment}{}}} -\subsection{Method \code{postTreatment()}}{ -Update fields after optimization -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfamily$postTreatment(config_post, config_optim)}\if{html}{\out{
}} +\subsection{\code{PLNfamily$postTreatment()}}{ + Update fields after optimization + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfamily$postTreatment(config_post, config_optim)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{config_post}}{a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.).} + \item{\code{config_optim}}{a list for controlling the optimization parameters used during post_treatments} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{config_post}}{a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.).} - -\item{\code{config_optim}}{a list for controlling the optimization parameters used during post_treatments} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfamily-getModel}{}}} -\subsection{Method \code{getModel()}}{ -Extract a model from a collection of models -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfamily$getModel(var, index = NULL)}\if{html}{\out{
}} +\subsection{\code{PLNfamily$getModel()}}{ + Extract a model from a collection of models + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfamily$getModel(var, index = NULL)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{var}}{value of the parameter (\code{rank} for PLNPCA, \code{sparsity} for PLNnetwork) that identifies the model to be extracted from the collection. If no exact match is found, the model with closest parameter value is returned with a warning.} + \item{\code{index}}{Integer index of the model to be returned. Only the first value is taken into account.} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + A \code{\link{PLNfit}} object + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{var}}{value of the parameter (\code{rank} for PLNPCA, \code{sparsity} for PLNnetwork) that identifies the model to be extracted from the collection. If no exact match is found, the model with closest parameter value is returned with a warning.} - -\item{\code{index}}{Integer index of the model to be returned. Only the first value is taken into account.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -A \code{\link{PLNfit}} object -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfamily-plot}{}}} -\subsection{Method \code{plot()}}{ -Lineplot of selected criteria for all models in the collection -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfamily$plot(criteria, reverse)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{criteria}}{A valid model selection criteria for the collection of models. Includes loglik, BIC (all), ICL (PLNPCA) and pen_loglik, EBIC (PLNnetwork)} - -\item{\code{reverse}}{A logical indicating whether to plot the value of the criteria in the "natural" direction +\subsection{\code{PLNfamily$plot()}}{ + Lineplot of selected criteria for all models in the collection + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfamily$plot(criteria, reverse)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{criteria}}{A valid model selection criteria for the collection of models. Includes loglik, BIC (all), ICL (PLNPCA) and pen_loglik, EBIC (PLNnetwork)} + \item{\code{reverse}}{A logical indicating whether to plot the value of the criteria in the "natural" direction (loglik - penalty) or in the "reverse" direction (-2 loglik + penalty). Default to FALSE, i.e use the natural direction, on the same scale as the log-likelihood.} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + A \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} object + } } -\if{html}{\out{
}} -} -\subsection{Returns}{ -A \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} object -} -} + \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfamily-show}{}}} -\subsection{Method \code{show()}}{ -User friendly print method -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfamily$show()}\if{html}{\out{
}} +\subsection{\code{PLNfamily$show()}}{ + User friendly print method + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfamily$show()} + \if{html}{\out{
}} + } } -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfamily-print}{}}} -\subsection{Method \code{print()}}{ -User friendly print method -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfamily$print()}\if{html}{\out{
}} +\subsection{\code{PLNfamily$print()}}{ + User friendly print method + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfamily$print()} + \if{html}{\out{
}} + } } -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfamily-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfamily$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{PLNfamily$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfamily$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/PLNfit.Rd b/man/PLNfit.Rd index de3f838a..2deff67d 100644 --- a/man/PLNfit.Rd +++ b/man/PLNfit.Rd @@ -22,103 +22,101 @@ print(myPLN) } } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{n}}{number of samples} + \if{html}{\out{
}} + \describe{ + \item{\code{n}}{number of samples} -\item{\code{q}}{number of dimensions of the latent space} + \item{\code{q}}{number of dimensions of the latent space} -\item{\code{p}}{number of species} + \item{\code{p}}{number of species} -\item{\code{d}}{number of covariates} + \item{\code{d}}{number of covariates} -\item{\code{nb_param}}{number of parameters in the current PLN model} + \item{\code{nb_param}}{number of parameters in the current PLN model} -\item{\code{model_par}}{a list with the matrices of the model parameters: B (covariates), Sigma (covariance), Omega (precision matrix), plus some others depending on the variant)} + \item{\code{model_par}}{a list with the matrices of the model parameters: B (covariates), Sigma (covariance), Omega (precision matrix), plus some others depending on the variant)} -\item{\code{var_par}}{a list with the matrices of the variational parameters: M (means) and S2 (variances)} + \item{\code{var_par}}{a list with the matrices of the variational parameters: M (means) and S2 (variances)} -\item{\code{optim_par}}{a list with parameters useful for monitoring the optimization} + \item{\code{optim_par}}{a list with parameters useful for monitoring the optimization} -\item{\code{latent}}{a matrix: values of the latent vector (Z in the model)} + \item{\code{latent}}{a matrix: values of the latent vector (Z in the model)} -\item{\code{latent_pos}}{a matrix: values of the latent position vector (Z) without covariates effects or offset} + \item{\code{latent_pos}}{a matrix: values of the latent position vector (Z) without covariates effects or offset} -\item{\code{fitted}}{a matrix: fitted values of the observations (A in the model)} + \item{\code{fitted}}{a matrix: fitted values of the observations (A in the model)} -\item{\code{vcov_coef}}{matrix of sandwich estimator of the variance-covariance of B (need fixed -ie known- covariance at the moment)} + \item{\code{vcov_coef}}{matrix of sandwich estimator of the variance-covariance of B (need fixed -ie known- covariance at the moment)} -\item{\code{vcov_model}}{character: the model used for the residual covariance} + \item{\code{vcov_model}}{character: the model used for the residual covariance} -\item{\code{weights}}{observational weights} + \item{\code{weights}}{observational weights} -\item{\code{loglik}}{(weighted) variational lower bound of the loglikelihood} + \item{\code{loglik}}{(weighted) variational lower bound of the loglikelihood} -\item{\code{loglik_vec}}{element-wise variational lower bound of the loglikelihood} + \item{\code{loglik_vec}}{element-wise variational lower bound of the loglikelihood} -\item{\code{AIC}}{variational lower bound of the AIC} + \item{\code{AIC}}{variational lower bound of the AIC} -\item{\code{BIC}}{variational lower bound of the BIC} + \item{\code{BIC}}{variational lower bound of the BIC} -\item{\code{entropy}}{Entropy of the variational distribution} + \item{\code{entropy}}{Entropy of the variational distribution} -\item{\code{ICL}}{variational lower bound of the ICL} + \item{\code{ICL}}{variational lower bound of the ICL} -\item{\code{R_squared}}{approximated goodness-of-fit criterion} + \item{\code{R_squared}}{approximated goodness-of-fit criterion} -\item{\code{criteria}}{a vector with loglik, BIC, ICL and number of parameters} -} -\if{html}{\out{
}} + \item{\code{criteria}}{a vector with loglik, BIC, ICL and number of parameters} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-PLNfit-new}{\code{PLNfit$new()}} -\item \href{#method-PLNfit-update}{\code{PLNfit$update()}} -\item \href{#method-PLNfit-optimize}{\code{PLNfit$optimize()}} -\item \href{#method-PLNfit-optimize_vestep}{\code{PLNfit$optimize_vestep()}} -\item \href{#method-PLNfit-postTreatment}{\code{PLNfit$postTreatment()}} -\item \href{#method-PLNfit-predict}{\code{PLNfit$predict()}} -\item \href{#method-PLNfit-predict_cond}{\code{PLNfit$predict_cond()}} -\item \href{#method-PLNfit-show}{\code{PLNfit$show()}} -\item \href{#method-PLNfit-print}{\code{PLNfit$print()}} -\item \href{#method-PLNfit-clone}{\code{PLNfit$clone()}} -} + \itemize{ + \item \href{#method-PLNfit-initialize}{\code{PLNfit$new()}} + \item \href{#method-PLNfit-update}{\code{PLNfit$update()}} + \item \href{#method-PLNfit-optimize}{\code{PLNfit$optimize()}} + \item \href{#method-PLNfit-optimize_vestep}{\code{PLNfit$optimize_vestep()}} + \item \href{#method-PLNfit-postTreatment}{\code{PLNfit$postTreatment()}} + \item \href{#method-PLNfit-predict}{\code{PLNfit$predict()}} + \item \href{#method-PLNfit-predict_cond}{\code{PLNfit$predict_cond()}} + \item \href{#method-PLNfit-show}{\code{PLNfit$show()}} + \item \href{#method-PLNfit-print}{\code{PLNfit$print()}} + \item \href{#method-PLNfit-clone}{\code{PLNfit$clone()}} + } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-PLNfit-new}{}}} -\subsection{Method \code{new()}}{ -Initialize a \code{\link{PLNfit}} model -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit$new(responses, covariates, offsets, weights, formula, control)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-PLNfit-initialize}{}}} +\subsection{\code{PLNfit$new()}}{ + Initialize a \code{\link{PLNfit}} model + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit$new(responses, covariates, offsets, weights, formula, control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} + \item{\code{control}}{a list-like structure for controlling the fit, see \code{\link[=PLN_param]{PLN_param()}}.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} - -\item{\code{control}}{a list-like structure for controlling the fit, see \code{\link[=PLN_param]{PLN_param()}}.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfit-update}{}}} -\subsection{Method \code{update()}}{ -Update a \code{\link{PLNfit}} object -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit$update( +\subsection{\code{PLNfit$update()}}{ + Update a \code{\link{PLNfit}} object + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit$update( B = NA, Sigma = NA, Omega = NA, @@ -129,70 +127,61 @@ Update a \code{\link{PLNfit}} object Z = NA, A = NA, monitoring = NA -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{B}}{matrix of regression matrix} + \item{\code{Sigma}}{variance-covariance matrix of the latent variables} + \item{\code{Omega}}{precision matrix of the latent variables. Inverse of Sigma.} + \item{\code{M}}{matrix of variational parameters for the mean} + \item{\code{S}}{matrix of variational parameters for the variance} + \item{\code{Ji}}{vector of variational lower bounds of the log-likelihoods (one value per sample)} + \item{\code{R2}}{approximate R^2 goodness-of-fit criterion} + \item{\code{Z}}{matrix of latent vectors (includes covariates and offset effects)} + \item{\code{A}}{matrix of fitted values} + \item{\code{monitoring}}{a list with optimization monitoring quantities} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + Update the current \code{\link{PLNfit}} object + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{B}}{matrix of regression matrix} - -\item{\code{Sigma}}{variance-covariance matrix of the latent variables} - -\item{\code{Omega}}{precision matrix of the latent variables. Inverse of Sigma.} - -\item{\code{M}}{matrix of variational parameters for the mean} - -\item{\code{S}}{matrix of variational parameters for the variance} - -\item{\code{Ji}}{vector of variational lower bounds of the log-likelihoods (one value per sample)} - -\item{\code{R2}}{approximate R^2 goodness-of-fit criterion} - -\item{\code{Z}}{matrix of latent vectors (includes covariates and offset effects)} - -\item{\code{A}}{matrix of fitted values} - -\item{\code{monitoring}}{a list with optimization monitoring quantities} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -Update the current \code{\link{PLNfit}} object -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfit-optimize}{}}} -\subsection{Method \code{optimize()}}{ -Call to the NLopt or TORCH optimizer and update of the relevant fields -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit$optimize(responses, covariates, offsets, weights, config)}\if{html}{\out{
}} +\subsection{\code{PLNfit$optimize()}}{ + Call to the NLopt or TORCH optimizer and update of the relevant fields + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit$optimize(responses, covariates, offsets, weights, config)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{config}}{part of the \code{control} argument which configures the optimizer} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{config}}{part of the \code{control} argument which configures the optimizer} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfit-optimize_vestep}{}}} -\subsection{Method \code{optimize_vestep()}}{ -Result of one call to the VE step of the optimization procedure: optimal variational parameters (M, S) and corresponding log likelihood values for fixed model parameters (Sigma, B). Intended to position new data in the latent space. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit$optimize_vestep( +\subsection{\code{PLNfit$optimize_vestep()}}{ + Result of one call to the VE step of the optimization procedure: optimal variational parameters (M, S) and corresponding log likelihood values for fixed model parameters (Sigma, B). Intended to position new data in the latent space. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit$optimize_vestep( covariates, offsets, responses, @@ -200,46 +189,41 @@ Result of one call to the VE step of the optimization procedure: optimal variati B = self$model_par$B, Omega = self$model_par$Omega, control = PLN_param(backend = "nlopt") -)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{B}}{Optional fixed value of the regression parameters} - -\item{\code{Omega}}{precision matrix of the latent variables. Inverse of Sigma.} - -\item{\code{control}}{a list-like structure for controlling the fit, see \code{\link[=PLN_param]{PLN_param()}}.} - -\item{\code{Sigma}}{variance-covariance matrix of the latent variables} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -A list with three components: +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{B}}{Optional fixed value of the regression parameters} + \item{\code{Omega}}{precision matrix of the latent variables. Inverse of Sigma.} + \item{\code{control}}{a list-like structure for controlling the fit, see \code{\link[=PLN_param]{PLN_param()}}.} + \item{\code{Sigma}}{variance-covariance matrix of the latent variables} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + A list with three components: \itemize{ \item the matrix \code{M} of variational means, \item the matrix \code{S2} of variational variances \item the vector \code{log.lik} of (variational) log-likelihood of each new observation } + } } -} + \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfit-postTreatment}{}}} -\subsection{Method \code{postTreatment()}}{ -Update R2, fisher and std_err fields after optimization -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit$postTreatment( +\subsection{\code{PLNfit$postTreatment()}}{ + Update R2, fisher and std_err fields after optimization + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit$postTreatment( responses, covariates, offsets, @@ -247,30 +231,24 @@ Update R2, fisher and std_err fields after optimization config_post, config_optim, nullModel = NULL -)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{config_post}}{a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.). See details} - -\item{\code{config_optim}}{a list for controlling the optimization (optional bootstrap, jackknife, R2, etc.). See details} - -\item{\code{nullModel}}{null model used for approximate R2 computations. Defaults to a GLM model with same design matrix but not latent variable.} -} -\if{html}{\out{
}} -} -\subsection{Details}{ -The list of parameters \code{config} controls the post-treatment processing, with the following entries: +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{config_post}}{a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.). See details} + \item{\code{config_optim}}{a list for controlling the optimization (optional bootstrap, jackknife, R2, etc.). See details} + \item{\code{nullModel}}{null model used for approximate R2 computations. Defaults to a GLM model with same design matrix but not latent variable.} + } + \if{html}{\out{
}} + } + \subsection{Details}{ + The list of parameters \code{config} controls the post-treatment processing, with the following entries: \itemize{ \item jackknife boolean indicating whether jackknife should be performed to evaluate bias and variance of the model parameters. Default is FALSE. \item bootstrap integer indicating the number of bootstrap resamples generated to evaluate the variance of the model parameters. Default is 0 (inactivated). @@ -278,127 +256,128 @@ The list of parameters \code{config} controls the post-treatment processing, wit \item sandwich_var boolean indicating whether sandwich estimator should be computed to estimate the variance of the model parameters (highly underestimated). Default is FALSE. \item trace integer for verbosity. should be > 1 to see output in post-treatments } + } } -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfit-predict}{}}} -\subsection{Method \code{predict()}}{ -Predict position, scores or observations of new data. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit$predict( +\subsection{\code{PLNfit$predict()}}{ + Predict position, scores or observations of new data. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit$predict( newdata, responses = NULL, type = c("link", "response"), level = 1, envir = parent.frame() -)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{newdata}}{A data frame in which to look for variables with which to predict. If omitted, the fitted values are used.} - -\item{\code{responses}}{Optional data frame containing the count of the observed variables (matching the names of the provided as data in the PLN function), assuming the interest is in testing the model.} - -\item{\code{type}}{Scale used for the prediction. Either \code{link} (default, predicted positions in the latent space) or \code{response} (predicted counts).} - -\item{\code{level}}{Optional integer value the level to be used in obtaining the predictions. Level zero corresponds to the population predictions (default if \code{responses} is not provided) while level one (default) corresponds to predictions after evaluating the variational parameters for the new data.} - -\item{\code{envir}}{Environment in which the prediction is evaluated} -} -\if{html}{\out{
}} -} -\subsection{Details}{ -Note that \code{level = 1} can only be used if responses are provided, +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{newdata}}{A data frame in which to look for variables with which to predict. If omitted, the fitted values are used.} + \item{\code{responses}}{Optional data frame containing the count of the observed variables (matching the names of the provided as data in the PLN function), assuming the interest is in testing the model.} + \item{\code{type}}{Scale used for the prediction. Either \code{link} (default, predicted positions in the latent space) or \code{response} (predicted counts).} + \item{\code{level}}{Optional integer value the level to be used in obtaining the predictions. Level zero corresponds to the population predictions (default if \code{responses} is not provided) while level one (default) corresponds to predictions after evaluating the variational parameters for the new data.} + \item{\code{envir}}{Environment in which the prediction is evaluated} + } + \if{html}{\out{
}} + } + \subsection{Details}{ + Note that \code{level = 1} can only be used if responses are provided, as the variational parameters can't be estimated otherwise. In the absence of responses, \code{level} is ignored and the fitted values are returned + } + \subsection{Returns}{ + A matrix with predictions scores or counts. + } } -\subsection{Returns}{ -A matrix with predictions scores or counts. -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfit-predict_cond}{}}} -\subsection{Method \code{predict_cond()}}{ -Predict position, scores or observations of new data, conditionally on the observation of a (set of) variables -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit$predict_cond( +\subsection{\code{PLNfit$predict_cond()}}{ + Predict position, scores or observations of new data, conditionally on the observation of a (set of) variables + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit$predict_cond( newdata, cond_responses, type = c("link", "response"), var_par = FALSE, envir = parent.frame() -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{newdata}}{a data frame containing the covariates of the sites where to predict} + \item{\code{cond_responses}}{a data frame containing the count of the observed variables (matching the names of the provided as data in the PLN function)} + \item{\code{type}}{Scale used for the prediction. Either \code{link} (default, predicted positions in the latent space) or \code{response} (predicted counts).} + \item{\code{var_par}}{Boolean. Should new estimations of the variational parameters of mean and variance be sent back, as attributes of the matrix of predictions. Default to \code{FALSE}.} + \item{\code{envir}}{Environment in which the prediction is evaluated} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + A matrix with predictions scores or counts. + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{newdata}}{a data frame containing the covariates of the sites where to predict} - -\item{\code{cond_responses}}{a data frame containing the count of the observed variables (matching the names of the provided as data in the PLN function)} - -\item{\code{type}}{Scale used for the prediction. Either \code{link} (default, predicted positions in the latent space) or \code{response} (predicted counts).} - -\item{\code{var_par}}{Boolean. Should new estimations of the variational parameters of mean and variance be sent back, as attributes of the matrix of predictions. Default to \code{FALSE}.} - -\item{\code{envir}}{Environment in which the prediction is evaluated} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -A matrix with predictions scores or counts. -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfit-show}{}}} -\subsection{Method \code{show()}}{ -User friendly print method -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit$show( +\subsection{\code{PLNfit$show()}}{ + User friendly print method + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit$show( model = paste("A multivariate Poisson Lognormal fit with", self$vcov_model, "covariance model.\\n") -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{model}}{First line of the print output} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{model}}{First line of the print output} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfit-print}{}}} -\subsection{Method \code{print()}}{ -User friendly print method -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit$print()}\if{html}{\out{
}} +\subsection{\code{PLNfit$print()}}{ + User friendly print method + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit$print()} + \if{html}{\out{
}} + } } -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfit-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{PLNfit$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/PLNfit_diagonal.Rd b/man/PLNfit_diagonal.Rd index a9b55c00..f1f89e07 100644 --- a/man/PLNfit_diagonal.Rd +++ b/man/PLNfit_diagonal.Rd @@ -28,127 +28,123 @@ print(myPLNLDA) } } \section{Super class}{ -\code{\link[PLNmodels:PLNfit]{PLNmodels::PLNfit}} -> \code{PLNfit_diagonal} +\code{\link[PLNmodels:PLNfit]{PLNfit}} -> \code{PLNfit_diagonal} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{nb_param}}{number of parameters in the current PLN model} + \if{html}{\out{
}} + \describe{ + \item{\code{nb_param}}{number of parameters in the current PLN model} -\item{\code{vcov_model}}{character: the model used for the residual covariance} -} -\if{html}{\out{
}} + \item{\code{vcov_model}}{character: the model used for the residual covariance} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-PLNfit_diagonal-new}{\code{PLNfit_diagonal$new()}} -\item \href{#method-PLNfit_diagonal-clone}{\code{PLNfit_diagonal$clone()}} -} + \itemize{ + \item \href{#method-PLNfit_diagonal-initialize}{\code{PLNfit_diagonal$new()}} + \item \href{#method-PLNfit_diagonal-clone}{\code{PLNfit_diagonal$clone()}} + } } -\if{html}{\out{ -
Inherited methods +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-PLNfit_diagonal-new}{}}} -\subsection{Method \code{new()}}{ -Initialize a \code{\link{PLNfit}} model -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit_diagonal$new(responses, covariates, offsets, weights, formula, control)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-PLNfit_diagonal-initialize}{}}} +\subsection{\code{PLNfit_diagonal$new()}}{ + Initialize a \code{\link{PLNfit}} model + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit_diagonal$new(responses, covariates, offsets, weights, formula, control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} + \item{\code{control}}{a list for controlling the optimization. See details.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} - -\item{\code{control}}{a list for controlling the optimization. See details.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfit_diagonal-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit_diagonal$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{PLNfit_diagonal$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit_diagonal$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } \section{Super classes}{ -\code{\link[PLNmodels:PLNfit]{PLNmodels::PLNfit}} -> \code{\link[PLNmodels:PLNLDAfit]{PLNmodels::PLNLDAfit}} -> \code{PLNLDAfit_spherical} +\code{\link[PLNmodels:PLNfit]{PLNfit}} -> \code{\link[PLNmodels:PLNLDAfit]{PLNLDAfit}} -> \code{PLNLDAfit_spherical} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{vcov_model}}{character: the model used for the residual covariance} + \if{html}{\out{
}} + \describe{ + \item{\code{vcov_model}}{character: the model used for the residual covariance} -\item{\code{nb_param}}{number of parameters in the current PLN model} -} -\if{html}{\out{
}} + \item{\code{nb_param}}{number of parameters in the current PLN model} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-PLNLDAfit_spherical-new}{\code{PLNLDAfit_spherical$new()}} -\item \href{#method-PLNLDAfit_spherical-clone}{\code{PLNLDAfit_spherical$clone()}} + \itemize{ + \item \href{#method-PLNLDAfit_spherical-initialize}{\code{PLNLDAfit_spherical$new()}} + \item \href{#method-PLNLDAfit_spherical-clone}{\code{PLNLDAfit_spherical$clone()}} + } } -} -\if{html}{\out{ -
Inherited methods +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-PLNLDAfit_spherical-new}{}}} -\subsection{Method \code{new()}}{ -Initialize a \code{\link{PLNfit}} model -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNLDAfit_spherical$new( +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-PLNLDAfit_spherical-initialize}{}}} +\subsection{\code{PLNLDAfit_spherical$new()}}{ + Initialize a \code{\link{PLNfit}} model + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNLDAfit_spherical$new( grouping, responses, covariates, @@ -156,44 +152,41 @@ Initialize a \code{\link{PLNfit}} model weights, formula, control -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{grouping}}{a factor specifying the class of each observation used for discriminant analysis.} + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} + \item{\code{control}}{a list for controlling the optimization. See details.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{grouping}}{a factor specifying the class of each observation used for discriminant analysis.} - -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} - -\item{\code{control}}{a list for controlling the optimization. See details.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNLDAfit_spherical-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNLDAfit_spherical$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{PLNLDAfit_spherical$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNLDAfit_spherical$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/PLNfit_fixedcov.Rd b/man/PLNfit_fixedcov.Rd index d0e39325..5ffc85c7 100644 --- a/man/PLNfit_fixedcov.Rd +++ b/man/PLNfit_fixedcov.Rd @@ -4,8 +4,6 @@ \alias{PLNfit_fixedcov} \title{An R6 Class to represent a PLNfit in a standard, general framework, with fixed (inverse) residual covariance} \description{ -An R6 Class to represent a PLNfit in a standard, general framework, with fixed (inverse) residual covariance - An R6 Class to represent a PLNfit in a standard, general framework, with fixed (inverse) residual covariance } \examples{ @@ -18,107 +16,102 @@ print(myPLN) } } \section{Super class}{ -\code{\link[PLNmodels:PLNfit]{PLNmodels::PLNfit}} -> \code{PLNfit_fixedcov} +\code{\link[PLNmodels:PLNfit]{PLNfit}} -> \code{PLNfit_fixedcov} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{nb_param}}{number of parameters in the current PLN model} + \if{html}{\out{
}} + \describe{ + \item{\code{nb_param}}{number of parameters in the current PLN model} -\item{\code{vcov_model}}{character: the model used for the residual covariance} + \item{\code{vcov_model}}{character: the model used for the residual covariance} -\item{\code{vcov_coef}}{matrix of sandwich estimator of the variance-covariance of B (needs known covariance at the moment)} -} -\if{html}{\out{
}} + \item{\code{vcov_coef}}{matrix of sandwich estimator of the variance-covariance of B (needs known covariance at the moment)} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-PLNfit_fixedcov-new}{\code{PLNfit_fixedcov$new()}} -\item \href{#method-PLNfit_fixedcov-optimize}{\code{PLNfit_fixedcov$optimize()}} -\item \href{#method-PLNfit_fixedcov-clone}{\code{PLNfit_fixedcov$clone()}} + \itemize{ + \item \href{#method-PLNfit_fixedcov-initialize}{\code{PLNfit_fixedcov$new()}} + \item \href{#method-PLNfit_fixedcov-optimize}{\code{PLNfit_fixedcov$optimize()}} + \item \href{#method-PLNfit_fixedcov-clone}{\code{PLNfit_fixedcov$clone()}} + } } -} -\if{html}{\out{ -
Inherited methods +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-PLNfit_fixedcov-new}{}}} -\subsection{Method \code{new()}}{ -Initialize a \code{\link{PLNfit}} model -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit_fixedcov$new(responses, covariates, offsets, weights, formula, control)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-PLNfit_fixedcov-initialize}{}}} +\subsection{\code{PLNfit_fixedcov$new()}}{ + Initialize a \code{\link{PLNfit}} model + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit_fixedcov$new(responses, covariates, offsets, weights, formula, control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} + \item{\code{control}}{a list for controlling the optimization. See details.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} - -\item{\code{control}}{a list for controlling the optimization. See details.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfit_fixedcov-optimize}{}}} -\subsection{Method \code{optimize()}}{ -Call to the NLopt or TORCH optimizer and update of the relevant fields -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit_fixedcov$optimize(responses, covariates, offsets, weights, config)}\if{html}{\out{
}} +\subsection{\code{PLNfit_fixedcov$optimize()}}{ + Call to the NLopt or TORCH optimizer and update of the relevant fields + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit_fixedcov$optimize(responses, covariates, offsets, weights, config)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{config}}{part of the \code{control} argument which configures the optimizer} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{config}}{part of the \code{control} argument which configures the optimizer} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfit_fixedcov-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit_fixedcov$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{PLNfit_fixedcov$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit_fixedcov$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/PLNfit_spherical.Rd b/man/PLNfit_spherical.Rd index b43fdc47..0f126f5b 100644 --- a/man/PLNfit_spherical.Rd +++ b/man/PLNfit_spherical.Rd @@ -4,8 +4,6 @@ \alias{PLNfit_spherical} \title{An R6 Class to represent a PLNfit in a standard, general framework, with spherical residual covariance} \description{ -An R6 Class to represent a PLNfit in a standard, general framework, with spherical residual covariance - An R6 Class to represent a PLNfit in a standard, general framework, with spherical residual covariance } \examples{ @@ -18,80 +16,77 @@ print(myPLN) } } \section{Super class}{ -\code{\link[PLNmodels:PLNfit]{PLNmodels::PLNfit}} -> \code{PLNfit_spherical} +\code{\link[PLNmodels:PLNfit]{PLNfit}} -> \code{PLNfit_spherical} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{nb_param}}{number of parameters in the current PLN model} + \if{html}{\out{
}} + \describe{ + \item{\code{nb_param}}{number of parameters in the current PLN model} -\item{\code{vcov_model}}{character: the model used for the residual covariance} -} -\if{html}{\out{
}} + \item{\code{vcov_model}}{character: the model used for the residual covariance} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-PLNfit_spherical-new}{\code{PLNfit_spherical$new()}} -\item \href{#method-PLNfit_spherical-clone}{\code{PLNfit_spherical$clone()}} -} + \itemize{ + \item \href{#method-PLNfit_spherical-initialize}{\code{PLNfit_spherical$new()}} + \item \href{#method-PLNfit_spherical-clone}{\code{PLNfit_spherical$clone()}} + } } -\if{html}{\out{ -
Inherited methods +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-PLNfit_spherical-new}{}}} -\subsection{Method \code{new()}}{ -Initialize a \code{\link{PLNfit}} model -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit_spherical$new(responses, covariates, offsets, weights, formula, control)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-PLNfit_spherical-initialize}{}}} +\subsection{\code{PLNfit_spherical$new()}}{ + Initialize a \code{\link{PLNfit}} model + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit_spherical$new(responses, covariates, offsets, weights, formula, control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} + \item{\code{control}}{a list for controlling the optimization. See details.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} - -\item{\code{control}}{a list for controlling the optimization. See details.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfit_spherical-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNfit_spherical$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{PLNfit_spherical$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNfit_spherical$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/PLNmixturefamily.Rd b/man/PLNmixturefamily.Rd index a511cfb4..fbebdc9c 100644 --- a/man/PLNmixturefamily.Rd +++ b/man/PLNmixturefamily.Rd @@ -13,203 +13,212 @@ See the documentation for \code{\link[=getBestModel]{getBestModel()}}, \code{\li The function \code{\link{PLNmixture}}, the class \code{\link[=PLNmixturefit]{PLNmixturefit}} } \section{Super class}{ -\code{\link[PLNmodels:PLNfamily]{PLNmodels::PLNfamily}} -> \code{PLNmixturefamily} +\code{\link[PLNmodels:PLNfamily]{PLNfamily}} -> \code{PLNmixturefamily} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{clusters}}{vector indicating the number of clusters considered is the successively fitted models} -} -\if{html}{\out{
}} + \if{html}{\out{
}} + \describe{ + \item{\code{clusters}}{vector indicating the number of clusters considered is the successively fitted models} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-PLNmixturefamily-new}{\code{PLNmixturefamily$new()}} -\item \href{#method-PLNmixturefamily-optimize}{\code{PLNmixturefamily$optimize()}} -\item \href{#method-PLNmixturefamily-smooth}{\code{PLNmixturefamily$smooth()}} -\item \href{#method-PLNmixturefamily-plot}{\code{PLNmixturefamily$plot()}} -\item \href{#method-PLNmixturefamily-plot_objective}{\code{PLNmixturefamily$plot_objective()}} -\item \href{#method-PLNmixturefamily-getBestModel}{\code{PLNmixturefamily$getBestModel()}} -\item \href{#method-PLNmixturefamily-show}{\code{PLNmixturefamily$show()}} -\item \href{#method-PLNmixturefamily-print}{\code{PLNmixturefamily$print()}} -\item \href{#method-PLNmixturefamily-clone}{\code{PLNmixturefamily$clone()}} -} -} -\if{html}{\out{ -
Inherited methods + \itemize{ + \item \href{#method-PLNmixturefamily-initialize}{\code{PLNmixturefamily$new()}} + \item \href{#method-PLNmixturefamily-optimize}{\code{PLNmixturefamily$optimize()}} + \item \href{#method-PLNmixturefamily-smooth}{\code{PLNmixturefamily$smooth()}} + \item \href{#method-PLNmixturefamily-plot}{\code{PLNmixturefamily$plot()}} + \item \href{#method-PLNmixturefamily-plot_objective}{\code{PLNmixturefamily$plot_objective()}} + \item \href{#method-PLNmixturefamily-getBestModel}{\code{PLNmixturefamily$getBestModel()}} + \item \href{#method-PLNmixturefamily-show}{\code{PLNmixturefamily$show()}} + \item \href{#method-PLNmixturefamily-print}{\code{PLNmixturefamily$print()}} + \item \href{#method-PLNmixturefamily-clone}{\code{PLNmixturefamily$clone()}} + } +} +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-PLNmixturefamily-new}{}}} -\subsection{Method \code{new()}}{ -helper function for forward smoothing: split a group +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-PLNmixturefamily-initialize}{}}} +\subsection{\code{PLNmixturefamily$new()}}{ + helper function for forward smoothing: split a group -Initialize all models in the collection. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefamily$new( + Initialize all models in the collection. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefamily$new( clusters, responses, covariates, offsets, formula, control -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{clusters}}{the dimensions of the successively fitted models} + \item{\code{responses}}{the matrix of responses common to every models} + \item{\code{covariates}}{the matrix of covariates common to every models} + \item{\code{offsets}}{the matrix of offsets common to every models} + \item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} + \item{\code{control}}{a list for controlling the optimization. See details.} + \item{\code{control}}{a list for controlling the optimization. See details.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{clusters}}{the dimensions of the successively fitted models} - -\item{\code{responses}}{the matrix of responses common to every models} - -\item{\code{covariates}}{the matrix of covariates common to every models} - -\item{\code{offsets}}{the matrix of offsets common to every models} - -\item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} - -\item{\code{control}}{a list for controlling the optimization. See details.} - -\item{\code{control}}{a list for controlling the optimization. See details.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNmixturefamily-optimize}{}}} -\subsection{Method \code{optimize()}}{ -Call to the optimizer on all models of the collection -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefamily$optimize(config)}\if{html}{\out{
}} +\subsection{\code{PLNmixturefamily$optimize()}}{ + Call to the optimizer on all models of the collection + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefamily$optimize(config)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{config}}{a list for controlling the optimization} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{config}}{a list for controlling the optimization} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNmixturefamily-smooth}{}}} -\subsection{Method \code{smooth()}}{ -function to restart clustering to avoid local minima by smoothing the loglikelihood values as a function of the number of clusters -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefamily$smooth(control)}\if{html}{\out{
}} +\subsection{\code{PLNmixturefamily$smooth()}}{ + function to restart clustering to avoid local minima by smoothing the loglikelihood values as a function of the number of clusters + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefamily$smooth(control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{control}}{a list to control the smoothing process} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{control}}{a list to control the smoothing process} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNmixturefamily-plot}{}}} -\subsection{Method \code{plot()}}{ -Lineplot of selected criteria for all models in the collection -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefamily$plot(criteria = c("loglik", "BIC", "ICL"), reverse = FALSE)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{criteria}}{A valid model selection criteria for the collection of models. Any of "loglik", "BIC" or "ICL" (all).} - -\item{\code{reverse}}{A logical indicating whether to plot the value of the criteria in the "natural" direction +\subsection{\code{PLNmixturefamily$plot()}}{ + Lineplot of selected criteria for all models in the collection + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefamily$plot(criteria = c("loglik", "BIC", "ICL"), reverse = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{criteria}}{A valid model selection criteria for the collection of models. Any of "loglik", "BIC" or "ICL" (all).} + \item{\code{reverse}}{A logical indicating whether to plot the value of the criteria in the "natural" direction (loglik - 0.5 penalty) or in the "reverse" direction (-2 loglik + penalty). Default to FALSE, i.e use the natural direction, on the same scale as the log-likelihood..} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + A \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} object + } } -\if{html}{\out{
}} -} -\subsection{Returns}{ -A \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} object -} -} + \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNmixturefamily-plot_objective}{}}} -\subsection{Method \code{plot_objective()}}{ -Plot objective value of the optimization problem along the penalty path -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefamily$plot_objective()}\if{html}{\out{
}} +\subsection{\code{PLNmixturefamily$plot_objective()}}{ + Plot objective value of the optimization problem along the penalty path + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefamily$plot_objective()} + \if{html}{\out{
}} + } + \subsection{Returns}{ + a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graph + } } -\subsection{Returns}{ -a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graph -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNmixturefamily-getBestModel}{}}} -\subsection{Method \code{getBestModel()}}{ -Extract best model in the collection -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefamily$getBestModel(crit = c("BIC", "ICL", "loglik"))}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{crit}}{a character for the criterion used to performed the selection. Either +\subsection{\code{PLNmixturefamily$getBestModel()}}{ + Extract best model in the collection + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefamily$getBestModel(crit = c("BIC", "ICL", "loglik"))} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{crit}}{a character for the criterion used to performed the selection. Either "BIC", "ICL" or "loglik". Default is \code{ICL}} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + a \code{\link{PLNmixturefit}} object + } } -\if{html}{\out{
}} -} -\subsection{Returns}{ -a \code{\link{PLNmixturefit}} object -} -} + \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNmixturefamily-show}{}}} -\subsection{Method \code{show()}}{ -User friendly print method -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefamily$show()}\if{html}{\out{
}} +\subsection{\code{PLNmixturefamily$show()}}{ + User friendly print method + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefamily$show()} + \if{html}{\out{
}} + } } -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNmixturefamily-print}{}}} -\subsection{Method \code{print()}}{ -User friendly print method -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefamily$print()}\if{html}{\out{
}} +\subsection{\code{PLNmixturefamily$print()}}{ + User friendly print method + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefamily$print()} + \if{html}{\out{
}} + } } -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNmixturefamily-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefamily$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{PLNmixturefamily$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefamily$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/PLNmixturefit.Rd b/man/PLNmixturefit.Rd index 7108e70c..df473265 100644 --- a/man/PLNmixturefit.Rd +++ b/man/PLNmixturefit.Rd @@ -14,228 +14,224 @@ See the documentation for ... The function \code{\link{PLNmixture}}, the class \code{\link[=PLNmixturefamily]{PLNmixturefamily}} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{n}}{number of samples} + \if{html}{\out{
}} + \describe{ + \item{\code{n}}{number of samples} -\item{\code{p}}{number of dimensions of the latent space} + \item{\code{p}}{number of dimensions of the latent space} -\item{\code{k}}{number of components} + \item{\code{k}}{number of components} -\item{\code{d}}{number of covariates} + \item{\code{d}}{number of covariates} -\item{\code{components}}{components of the mixture (PLNfits)} + \item{\code{components}}{components of the mixture (PLNfits)} -\item{\code{latent}}{a matrix: values of the latent vector (Z in the model)} + \item{\code{latent}}{a matrix: values of the latent vector (Z in the model)} -\item{\code{latent_pos}}{a matrix: values of the latent position vector (Z) without covariates effects or offset} + \item{\code{latent_pos}}{a matrix: values of the latent position vector (Z) without covariates effects or offset} -\item{\code{posteriorProb}}{matrix ofposterior probability for cluster belonging} + \item{\code{posteriorProb}}{matrix ofposterior probability for cluster belonging} -\item{\code{memberships}}{vector for cluster index} + \item{\code{memberships}}{vector for cluster index} -\item{\code{mixtureParam}}{vector of cluster proportions} + \item{\code{mixtureParam}}{vector of cluster proportions} -\item{\code{optim_par}}{a list with parameters useful for monitoring the optimization} + \item{\code{optim_par}}{a list with parameters useful for monitoring the optimization} -\item{\code{nb_param}}{number of parameters in the current PLN model} + \item{\code{nb_param}}{number of parameters in the current PLN model} -\item{\code{entropy_clustering}}{Entropy of the variational distribution of the cluster (multinomial)} + \item{\code{entropy_clustering}}{Entropy of the variational distribution of the cluster (multinomial)} -\item{\code{entropy_latent}}{Entropy of the variational distribution of the latent vector (Gaussian)} + \item{\code{entropy_latent}}{Entropy of the variational distribution of the latent vector (Gaussian)} -\item{\code{entropy}}{Full entropy of the variational distribution (latent vector + clustering)} + \item{\code{entropy}}{Full entropy of the variational distribution (latent vector + clustering)} -\item{\code{loglik}}{variational lower bound of the loglikelihood} + \item{\code{loglik}}{variational lower bound of the loglikelihood} -\item{\code{loglik_vec}}{element-wise variational lower bound of the loglikelihood} + \item{\code{loglik_vec}}{element-wise variational lower bound of the loglikelihood} -\item{\code{BIC}}{variational lower bound of the BIC} + \item{\code{BIC}}{variational lower bound of the BIC} -\item{\code{ICL}}{variational lower bound of the ICL (include entropy of both the clustering and latent distributions)} + \item{\code{ICL}}{variational lower bound of the ICL (include entropy of both the clustering and latent distributions)} -\item{\code{R_squared}}{approximated goodness-of-fit criterion} + \item{\code{R_squared}}{approximated goodness-of-fit criterion} -\item{\code{criteria}}{a vector with loglik, BIC, ICL, and number of parameters} + \item{\code{criteria}}{a vector with loglik, BIC, ICL, and number of parameters} -\item{\code{model_par}}{a list with the matrices of parameters found in the model (Theta, Sigma, Mu and Pi)} + \item{\code{model_par}}{a list with the matrices of parameters found in the model (Theta, Sigma, Mu and Pi)} -\item{\code{vcov_model}}{character: the model used for the covariance (either "spherical", "diagonal" or "full")} + \item{\code{vcov_model}}{character: the model used for the covariance (either "spherical", "diagonal" or "full")} -\item{\code{fitted}}{a matrix: fitted values of the observations (A in the model)} + \item{\code{fitted}}{a matrix: fitted values of the observations (A in the model)} -\item{\code{group_means}}{a matrix of group mean vectors in the latent space.} -} -\if{html}{\out{
}} + \item{\code{group_means}}{a matrix of group mean vectors in the latent space.} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-PLNmixturefit-new}{\code{PLNmixturefit$new()}} -\item \href{#method-PLNmixturefit-optimize}{\code{PLNmixturefit$optimize()}} -\item \href{#method-PLNmixturefit-predict}{\code{PLNmixturefit$predict()}} -\item \href{#method-PLNmixturefit-plot_clustering_data}{\code{PLNmixturefit$plot_clustering_data()}} -\item \href{#method-PLNmixturefit-plot_clustering_pca}{\code{PLNmixturefit$plot_clustering_pca()}} -\item \href{#method-PLNmixturefit-postTreatment}{\code{PLNmixturefit$postTreatment()}} -\item \href{#method-PLNmixturefit-show}{\code{PLNmixturefit$show()}} -\item \href{#method-PLNmixturefit-print}{\code{PLNmixturefit$print()}} -\item \href{#method-PLNmixturefit-clone}{\code{PLNmixturefit$clone()}} -} + \itemize{ + \item \href{#method-PLNmixturefit-initialize}{\code{PLNmixturefit$new()}} + \item \href{#method-PLNmixturefit-optimize}{\code{PLNmixturefit$optimize()}} + \item \href{#method-PLNmixturefit-predict}{\code{PLNmixturefit$predict()}} + \item \href{#method-PLNmixturefit-plot_clustering_data}{\code{PLNmixturefit$plot_clustering_data()}} + \item \href{#method-PLNmixturefit-plot_clustering_pca}{\code{PLNmixturefit$plot_clustering_pca()}} + \item \href{#method-PLNmixturefit-postTreatment}{\code{PLNmixturefit$postTreatment()}} + \item \href{#method-PLNmixturefit-show}{\code{PLNmixturefit$show()}} + \item \href{#method-PLNmixturefit-print}{\code{PLNmixturefit$print()}} + \item \href{#method-PLNmixturefit-clone}{\code{PLNmixturefit$clone()}} + } } \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-PLNmixturefit-new}{}}} -\subsection{Method \code{new()}}{ -Optimize a the +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-PLNmixturefit-initialize}{}}} +\subsection{\code{PLNmixturefit$new()}}{ + Optimize a the -Initialize a \code{\link{PLNmixturefit}} model -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefit$new( + Initialize a \code{\link{PLNmixturefit}} model + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefit$new( responses, covariates, offsets, posteriorProb, formula, control -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{responses}}{the matrix of responses common to every models} + \item{\code{covariates}}{the matrix of covariates common to every models} + \item{\code{offsets}}{the matrix of offsets common to every models} + \item{\code{posteriorProb}}{matrix ofposterior probability for cluster belonging} + \item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} + \item{\code{control}}{a list for controlling the optimization.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{responses}}{the matrix of responses common to every models} - -\item{\code{covariates}}{the matrix of covariates common to every models} - -\item{\code{offsets}}{the matrix of offsets common to every models} - -\item{\code{posteriorProb}}{matrix ofposterior probability for cluster belonging} - -\item{\code{formula}}{model formula used for fitting, extracted from the formula in the upper-level call} - -\item{\code{control}}{a list for controlling the optimization.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNmixturefit-optimize}{}}} -\subsection{Method \code{optimize()}}{ -Optimize a \code{\link{PLNmixturefit}} model -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefit$optimize(responses, covariates, offsets, config)}\if{html}{\out{
}} +\subsection{\code{PLNmixturefit$optimize()}}{ + Optimize a \code{\link{PLNmixturefit}} model + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefit$optimize(responses, covariates, offsets, config)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{responses}}{the matrix of responses common to every models} + \item{\code{covariates}}{the matrix of covariates common to every models} + \item{\code{offsets}}{the matrix of offsets common to every models} + \item{\code{config}}{a list for controlling the optimization} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{responses}}{the matrix of responses common to every models} - -\item{\code{covariates}}{the matrix of covariates common to every models} - -\item{\code{offsets}}{the matrix of offsets common to every models} - -\item{\code{config}}{a list for controlling the optimization} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNmixturefit-predict}{}}} -\subsection{Method \code{predict()}}{ -Predict group of new samples -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefit$predict( +\subsection{\code{PLNmixturefit$predict()}}{ + Predict group of new samples + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefit$predict( newdata, type = c("posterior", "response", "position"), prior = matrix(rep(1/self$k, self$k), nrow(newdata), self$k, byrow = TRUE), control = PLNmixture_param(), envir = parent.frame() -)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{newdata}}{A data frame in which to look for variables, offsets and counts with which to predict.} - -\item{\code{type}}{The type of prediction required. The default \code{posterior} are posterior probabilities for each group , +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{newdata}}{A data frame in which to look for variables, offsets and counts with which to predict.} + \item{\code{type}}{The type of prediction required. The default \code{posterior} are posterior probabilities for each group , \code{response} is the group with maximal posterior probability and \code{latent} is the averaged latent coordinate (without offset and nor covariate effects), with weights equal to the posterior probabilities.} - -\item{\code{prior}}{User-specified prior group probabilities in the new data. The default uses a uniform prior.} - -\item{\code{control}}{a list-like structure for controlling the fit. See \code{\link[=PLNmixture_param]{PLNmixture_param()}} for details.} - -\item{\code{envir}}{Environment in which the prediction is evaluated} -} -\if{html}{\out{
}} -} + \item{\code{prior}}{User-specified prior group probabilities in the new data. The default uses a uniform prior.} + \item{\code{control}}{a list-like structure for controlling the fit. See \code{\link[=PLNmixture_param]{PLNmixture_param()}} for details.} + \item{\code{envir}}{Environment in which the prediction is evaluated} + } + \if{html}{\out{
}} + } } + \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNmixturefit-plot_clustering_data}{}}} -\subsection{Method \code{plot_clustering_data()}}{ -Plot the matrix of expected mean counts (without offsets, without covariate effects) reordered according the inferred clustering -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefit$plot_clustering_data( +\subsection{\code{PLNmixturefit$plot_clustering_data()}}{ + Plot the matrix of expected mean counts (without offsets, without covariate effects) reordered according the inferred clustering + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefit$plot_clustering_data( main = "Expected counts reorder by clustering", plot = TRUE, log_scale = TRUE -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{main}}{character. A title for the plot. An hopefully appropriate title will be used by default.} + \item{\code{plot}}{logical. Should the plot be displayed or sent back as \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} object} + \item{\code{log_scale}}{logical. Should the color scale values be log-transform before plotting? Default is \code{TRUE}.} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graphic + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{main}}{character. A title for the plot. An hopefully appropriate title will be used by default.} - -\item{\code{plot}}{logical. Should the plot be displayed or sent back as \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} object} - -\item{\code{log_scale}}{logical. Should the color scale values be log-transform before plotting? Default is \code{TRUE}.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graphic -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNmixturefit-plot_clustering_pca}{}}} -\subsection{Method \code{plot_clustering_pca()}}{ -Plot the individual map of a PCA performed on the latent coordinates, where individuals are colored according to the memberships -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefit$plot_clustering_pca( +\subsection{\code{PLNmixturefit$plot_clustering_pca()}}{ + Plot the individual map of a PCA performed on the latent coordinates, where individuals are colored according to the memberships + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefit$plot_clustering_pca( main = "Clustering labels in Individual Factor Map", plot = TRUE -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{main}}{character. A title for the plot. An hopefully appropriate title will be used by default.} + \item{\code{plot}}{logical. Should the plot be displayed or sent back as \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} object} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graphic + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{main}}{character. A title for the plot. An hopefully appropriate title will be used by default.} - -\item{\code{plot}}{logical. Should the plot be displayed or sent back as \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} object} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -a \code{\link[ggplot2:ggplot]{ggplot2::ggplot}} graphic -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNmixturefit-postTreatment}{}}} -\subsection{Method \code{postTreatment()}}{ -Update fields after optimization -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefit$postTreatment( +\subsection{\code{PLNmixturefit$postTreatment()}}{ + Update fields after optimization + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefit$postTreatment( responses, covariates, offsets, @@ -243,64 +239,65 @@ Update fields after optimization config_post, config_optim, nullModel -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{responses}}{the matrix of responses common to every models} + \item{\code{covariates}}{the matrix of covariates common to every models} + \item{\code{offsets}}{the matrix of offsets common to every models} + \item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} + \item{\code{config_post}}{a list for controlling the post-treatment} + \item{\code{config_optim}}{a list for controlling the optimization during the post-treatment computations} + \item{\code{nullModel}}{null model used for approximate R2 computations. Defaults to a GLM model with same design matrix but not latent variable.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{responses}}{the matrix of responses common to every models} - -\item{\code{covariates}}{the matrix of covariates common to every models} - -\item{\code{offsets}}{the matrix of offsets common to every models} - -\item{\code{weights}}{an optional vector of observation weights to be used in the fitting process.} - -\item{\code{config_post}}{a list for controlling the post-treatment} - -\item{\code{config_optim}}{a list for controlling the optimization during the post-treatment computations} - -\item{\code{nullModel}}{null model used for approximate R2 computations. Defaults to a GLM model with same design matrix but not latent variable.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNmixturefit-show}{}}} -\subsection{Method \code{show()}}{ -User friendly print method -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefit$show()}\if{html}{\out{
}} +\subsection{\code{PLNmixturefit$show()}}{ + User friendly print method + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefit$show()} + \if{html}{\out{
}} + } } -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNmixturefit-print}{}}} -\subsection{Method \code{print()}}{ -User friendly print method -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefit$print()}\if{html}{\out{
}} +\subsection{\code{PLNmixturefit$print()}}{ + User friendly print method + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefit$print()} + \if{html}{\out{
}} + } } -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNmixturefit-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNmixturefit$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{PLNmixturefit$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNmixturefit$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/PLNmodels-package.Rd b/man/PLNmodels-package.Rd index 7bab17cd..8c628440 100644 --- a/man/PLNmodels-package.Rd +++ b/man/PLNmodels-package.Rd @@ -23,6 +23,7 @@ Useful links: Authors: \itemize{ + \item Julien Chiquet \email{julien.chiquet@inrae.fr} (\href{https://orcid.org/0000-0002-3629-3429}{ORCID}) \item Mahendra Mariadassou \email{mahendra.mariadassou@inrae.fr} (\href{https://orcid.org/0000-0003-2986-354X}{ORCID}) \item Stéphane Robin \email{stephane.robin@inrae.fr} \item François Gindraud \email{francois.gindraud@gmail.com} diff --git a/man/PLNnetworkfamily.Rd b/man/PLNnetworkfamily.Rd index 6cb3e9ab..bcff4a4f 100644 --- a/man/PLNnetworkfamily.Rd +++ b/man/PLNnetworkfamily.Rd @@ -22,93 +22,94 @@ class(fits) The function \code{\link[=PLNnetwork]{PLNnetwork()}}, the class \code{\link{PLNnetworkfit}} } \section{Super classes}{ -\code{\link[PLNmodels:PLNfamily]{PLNmodels::PLNfamily}} -> \code{\link[PLNmodels:Networkfamily]{PLNmodels::Networkfamily}} -> \code{PLNnetworkfamily} +\code{\link[PLNmodels:PLNfamily]{PLNfamily}} -> \code{\link[PLNmodels:Networkfamily]{Networkfamily}} -> \code{PLNnetworkfamily} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-PLNnetworkfamily-new}{\code{PLNnetworkfamily$new()}} -\item \href{#method-PLNnetworkfamily-stability_selection}{\code{PLNnetworkfamily$stability_selection()}} -\item \href{#method-PLNnetworkfamily-clone}{\code{PLNnetworkfamily$clone()}} + \itemize{ + \item \href{#method-PLNnetworkfamily-initialize}{\code{PLNnetworkfamily$new()}} + \item \href{#method-PLNnetworkfamily-stability_selection}{\code{PLNnetworkfamily$stability_selection()}} + \item \href{#method-PLNnetworkfamily-clone}{\code{PLNnetworkfamily$clone()}} + } } -} -\if{html}{\out{ -
Inherited methods +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-PLNnetworkfamily-new}{}}} -\subsection{Method \code{new()}}{ -Initialize all models in the collection -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNnetworkfamily$new(penalties, data, control)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-PLNnetworkfamily-initialize}{}}} +\subsection{\code{PLNnetworkfamily$new()}}{ + Initialize all models in the collection + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNnetworkfamily$new(penalties, data, control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{penalties}}{a vector of positive real number controlling the level of sparsity of the underlying network.} + \item{\code{data}}{a named list used internally to carry the data matrices} + \item{\code{control}}{a list for controlling the optimization.} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + Update current \code{\link{PLNnetworkfit}} with smart starting values + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{penalties}}{a vector of positive real number controlling the level of sparsity of the underlying network.} - -\item{\code{data}}{a named list used internally to carry the data matrices} - -\item{\code{control}}{a list for controlling the optimization.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -Update current \code{\link{PLNnetworkfit}} with smart starting values -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNnetworkfamily-stability_selection}{}}} -\subsection{Method \code{stability_selection()}}{ -Compute the stability path by stability selection -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNnetworkfamily$stability_selection( +\subsection{\code{PLNnetworkfamily$stability_selection()}}{ + Compute the stability path by stability selection + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNnetworkfamily$stability_selection( subsamples = NULL, control = PLNnetwork_param() -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{subsamples}}{a list of vectors describing the subsamples. The number of vectors (or list length) determines the number of subsamples used in the stability selection. Automatically set to 20 subsamples with size \code{10*sqrt(n)} if \code{n >= 144} and \code{0.8*n} otherwise following Liu et al. (2010) recommendations.} + \item{\code{control}}{a list controlling the main optimization process in each call to \code{\link[=PLNnetwork]{PLNnetwork()}}. See \code{\link[=PLNnetwork]{PLNnetwork()}} and \code{\link[=PLN_param]{PLN_param()}} for details.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{subsamples}}{a list of vectors describing the subsamples. The number of vectors (or list length) determines the number of subsamples used in the stability selection. Automatically set to 20 subsamples with size \code{10*sqrt(n)} if \code{n >= 144} and \code{0.8*n} otherwise following Liu et al. (2010) recommendations.} - -\item{\code{control}}{a list controlling the main optimization process in each call to \code{\link[=PLNnetwork]{PLNnetwork()}}. See \code{\link[=PLNnetwork]{PLNnetwork()}} and \code{\link[=PLN_param]{PLN_param()}} for details.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNnetworkfamily-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNnetworkfamily$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{PLNnetworkfamily$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNnetworkfamily$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/PLNnetworkfit.Rd b/man/PLNnetworkfit.Rd index 5dad7d68..0042340a 100644 --- a/man/PLNnetworkfit.Rd +++ b/man/PLNnetworkfit.Rd @@ -22,119 +22,122 @@ print(myPLNnet) The function \code{\link[=PLNnetwork]{PLNnetwork()}}, the class \code{\link{PLNnetworkfamily}} } \section{Super classes}{ -\code{\link[PLNmodels:PLNfit]{PLNmodels::PLNfit}} -> \code{\link[PLNmodels:PLNfit_fixedcov]{PLNmodels::PLNfit_fixedcov}} -> \code{PLNnetworkfit} +\code{\link[PLNmodels:PLNfit]{PLNfit}} -> \code{\link[PLNmodels:PLNfit_fixedcov]{PLNfit_fixedcov}} -> \code{PLNnetworkfit} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{vcov_model}}{character: the model used for the residual covariance} + \if{html}{\out{
}} + \describe{ + \item{\code{vcov_model}}{character: the model used for the residual covariance} -\item{\code{penalty}}{the global level of sparsity in the current model} + \item{\code{penalty}}{the global level of sparsity in the current model} -\item{\code{penalty_weights}}{a matrix of weights controlling the amount of penalty element-wise.} + \item{\code{penalty_weights}}{a matrix of weights controlling the amount of penalty element-wise.} -\item{\code{n_edges}}{number of edges if the network (non null coefficient of the sparse precision matrix)} + \item{\code{n_edges}}{number of edges if the network (non null coefficient of the sparse precision matrix)} -\item{\code{nb_param}}{number of parameters in the current PLN model} + \item{\code{nb_param}}{number of parameters in the current PLN model} -\item{\code{pen_loglik}}{variational lower bound of the l1-penalized loglikelihood} + \item{\code{pen_loglik}}{variational lower bound of the l1-penalized loglikelihood} -\item{\code{EBIC}}{variational lower bound of the EBIC} + \item{\code{EBIC}}{variational lower bound of the EBIC} -\item{\code{density}}{proportion of non-null edges in the network} + \item{\code{density}}{proportion of non-null edges in the network} -\item{\code{criteria}}{a vector with loglik, penalized loglik, BIC, EBIC, ICL, R_squared, number of parameters, number of edges and graph density} -} -\if{html}{\out{
}} + \item{\code{criteria}}{a vector with loglik, penalized loglik, BIC, EBIC, ICL, R_squared, number of parameters, number of edges and graph density} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-PLNnetworkfit-new}{\code{PLNnetworkfit$new()}} -\item \href{#method-PLNnetworkfit-optimize}{\code{PLNnetworkfit$optimize()}} -\item \href{#method-PLNnetworkfit-latent_network}{\code{PLNnetworkfit$latent_network()}} -\item \href{#method-PLNnetworkfit-plot_network}{\code{PLNnetworkfit$plot_network()}} -\item \href{#method-PLNnetworkfit-show}{\code{PLNnetworkfit$show()}} -\item \href{#method-PLNnetworkfit-clone}{\code{PLNnetworkfit$clone()}} -} -} -\if{html}{\out{ -
Inherited methods + \itemize{ + \item \href{#method-PLNnetworkfit-initialize}{\code{PLNnetworkfit$new()}} + \item \href{#method-PLNnetworkfit-optimize}{\code{PLNnetworkfit$optimize()}} + \item \href{#method-PLNnetworkfit-latent_network}{\code{PLNnetworkfit$latent_network()}} + \item \href{#method-PLNnetworkfit-plot_network}{\code{PLNnetworkfit$plot_network()}} + \item \href{#method-PLNnetworkfit-show}{\code{PLNnetworkfit$show()}} + \item \href{#method-PLNnetworkfit-clone}{\code{PLNnetworkfit$clone()}} + } +} +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-PLNnetworkfit-new}{}}} -\subsection{Method \code{new()}}{ -Initialize a \code{\link{PLNnetworkfit}} object -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNnetworkfit$new(data, control)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-PLNnetworkfit-initialize}{}}} +\subsection{\code{PLNnetworkfit$new()}}{ + Initialize a \code{\link{PLNnetworkfit}} object + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNnetworkfit$new(data, control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{data}}{a named list used internally to carry the data matrices} + \item{\code{control}}{a list for controlling the optimization.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{data}}{a named list used internally to carry the data matrices} - -\item{\code{control}}{a list for controlling the optimization.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNnetworkfit-optimize}{}}} -\subsection{Method \code{optimize()}}{ -Call to the C++ optimizer and update of the relevant fields -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNnetworkfit$optimize(data, config)}\if{html}{\out{
}} +\subsection{\code{PLNnetworkfit$optimize()}}{ + Call to the C++ optimizer and update of the relevant fields + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNnetworkfit$optimize(data, config)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{data}}{a named list used internally to carry the data matrices} + \item{\code{config}}{a list for controlling the optimization} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{data}}{a named list used internally to carry the data matrices} - -\item{\code{config}}{a list for controlling the optimization} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNnetworkfit-latent_network}{}}} -\subsection{Method \code{latent_network()}}{ -Extract interaction network in the latent space -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNnetworkfit$latent_network(type = c("partial_cor", "support", "precision"))}\if{html}{\out{
}} +\subsection{\code{PLNnetworkfit$latent_network()}}{ + Extract interaction network in the latent space + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNnetworkfit$latent_network(type = c("partial_cor", "support", "precision"))} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{type}}{edge value in the network. Can be "support" (binary edges), "precision" (coefficient of the precision matrix) or "partial_cor" (partial correlation between species)} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + a square matrix of size \code{PLNnetworkfit$n} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{type}}{edge value in the network. Can be "support" (binary edges), "precision" (coefficient of the precision matrix) or "partial_cor" (partial correlation between species)} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -a square matrix of size \code{PLNnetworkfit$n} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNnetworkfit-plot_network}{}}} -\subsection{Method \code{plot_network()}}{ -plot the latent network. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNnetworkfit$plot_network( +\subsection{\code{PLNnetworkfit$plot_network()}}{ + plot the latent network. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNnetworkfit$plot_network( type = c("partial_cor", "support"), output = c("igraph", "corrplot"), edge.color = c("#F8766D", "#00BFC4"), @@ -142,54 +145,53 @@ plot the latent network. node.labels = NULL, layout = layout_in_circle, plot = TRUE -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{type}}{edge value in the network. Either "precision" (coefficient of the precision matrix) or "partial_cor" (partial correlation between species).} + \item{\code{output}}{Output type. Either \code{igraph} (for the network) or \code{corrplot} (for the adjacency matrix)} + \item{\code{edge.color}}{Length 2 color vector. Color for positive/negative edges. Default is \code{c("#F8766D", "#00BFC4")}. Only relevant for igraph output.} + \item{\code{remove.isolated}}{if \code{TRUE}, isolated node are remove before plotting. Only relevant for igraph output.} + \item{\code{node.labels}}{vector of character. The labels of the nodes. The default will use the column names ot the response matrix.} + \item{\code{layout}}{an optional igraph layout. Only relevant for igraph output.} + \item{\code{plot}}{logical. Should the final network be displayed or only sent back to the user. Default is \code{TRUE}.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{type}}{edge value in the network. Either "precision" (coefficient of the precision matrix) or "partial_cor" (partial correlation between species).} - -\item{\code{output}}{Output type. Either \code{igraph} (for the network) or \code{corrplot} (for the adjacency matrix)} - -\item{\code{edge.color}}{Length 2 color vector. Color for positive/negative edges. Default is \code{c("#F8766D", "#00BFC4")}. Only relevant for igraph output.} - -\item{\code{remove.isolated}}{if \code{TRUE}, isolated node are remove before plotting. Only relevant for igraph output.} - -\item{\code{node.labels}}{vector of character. The labels of the nodes. The default will use the column names ot the response matrix.} - -\item{\code{layout}}{an optional igraph layout. Only relevant for igraph output.} - -\item{\code{plot}}{logical. Should the final network be displayed or only sent back to the user. Default is \code{TRUE}.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNnetworkfit-show}{}}} -\subsection{Method \code{show()}}{ -User friendly print method -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNnetworkfit$show()}\if{html}{\out{
}} +\subsection{\code{PLNnetworkfit$show()}}{ + User friendly print method + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNnetworkfit$show()} + \if{html}{\out{
}} + } } -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNnetworkfit-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{PLNnetworkfit$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{PLNnetworkfit$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNnetworkfit$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/ZIPLNfit.Rd b/man/ZIPLNfit.Rd index e8660c0c..6556fec0 100644 --- a/man/ZIPLNfit.Rd +++ b/man/ZIPLNfit.Rd @@ -28,80 +28,81 @@ print(myPLN) } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{n}}{number of samples/sites} + \if{html}{\out{
}} + \describe{ + \item{\code{n}}{number of samples/sites} -\item{\code{q}}{number of dimensions of the latent space} + \item{\code{q}}{number of dimensions of the latent space} -\item{\code{p}}{number of variables/species} + \item{\code{p}}{number of variables/species} -\item{\code{d}}{number of covariates in the PLN part} + \item{\code{d}}{number of covariates in the PLN part} -\item{\code{d0}}{number of covariates in the ZI part} + \item{\code{d0}}{number of covariates in the ZI part} -\item{\code{nb_param_zi}}{number of parameters in the ZI part of the model} + \item{\code{nb_param_zi}}{number of parameters in the ZI part of the model} -\item{\code{nb_param_pln}}{number of parameters in the PLN part of the model} + \item{\code{nb_param_pln}}{number of parameters in the PLN part of the model} -\item{\code{nb_param}}{number of parameters in the ZIPLN model} + \item{\code{nb_param}}{number of parameters in the ZIPLN model} -\item{\code{model_par}}{a list with the matrices of parameters found in the model (B, Sigma, plus some others depending on the variant)} + \item{\code{model_par}}{a list with the matrices of parameters found in the model (B, Sigma, plus some others depending on the variant)} -\item{\code{var_par}}{a list with two matrices, M and S2, which are the estimated parameters in the variational approximation} + \item{\code{var_par}}{a list with two matrices, M and S2, which are the estimated parameters in the variational approximation} -\item{\code{optim_par}}{a list with parameters useful for monitoring the optimization} + \item{\code{optim_par}}{a list with parameters useful for monitoring the optimization} -\item{\code{latent}}{a matrix: values of the latent vector (Z in the model)} + \item{\code{latent}}{a matrix: values of the latent vector (Z in the model)} -\item{\code{latent_pos}}{a matrix: values of the latent position vector (Z) without covariates effects or offset} + \item{\code{latent_pos}}{a matrix: values of the latent position vector (Z) without covariates effects or offset} -\item{\code{fitted}}{a matrix: fitted values of the observations (A in the model)} + \item{\code{fitted}}{a matrix: fitted values of the observations (A in the model)} -\item{\code{vcov_model}}{character: the model used for the covariance (either "spherical", "diagonal", "full" or "sparse")} + \item{\code{vcov_model}}{character: the model used for the covariance (either "spherical", "diagonal", "full" or "sparse")} -\item{\code{zi_model}}{character: the model used for the zero inflation (either "single", "row", "col" or "covar")} + \item{\code{zi_model}}{character: the model used for the zero inflation (either "single", "row", "col" or "covar")} -\item{\code{loglik}}{(weighted) variational lower bound of the loglikelihood} + \item{\code{loglik}}{(weighted) variational lower bound of the loglikelihood} -\item{\code{loglik_vec}}{element-wise variational lower bound of the loglikelihood} + \item{\code{loglik_vec}}{element-wise variational lower bound of the loglikelihood} -\item{\code{AIC}}{variational lower bound of the AIC} + \item{\code{AIC}}{variational lower bound of the AIC} -\item{\code{BIC}}{variational lower bound of the BIC} + \item{\code{BIC}}{variational lower bound of the BIC} -\item{\code{entropy}}{Entropy of the variational distribution} + \item{\code{entropy}}{Entropy of the variational distribution} -\item{\code{entropy_ZI}}{Entropy of the variational distribution} + \item{\code{entropy_ZI}}{Entropy of the variational distribution} -\item{\code{entropy_PLN}}{Entropy of the Gaussian variational distribution in the PLN component} + \item{\code{entropy_PLN}}{Entropy of the Gaussian variational distribution in the PLN component} -\item{\code{ICL}}{variational lower bound of the ICL} + \item{\code{ICL}}{variational lower bound of the ICL} -\item{\code{criteria}}{a vector with loglik, BIC, ICL and number of parameters} -} -\if{html}{\out{
}} + \item{\code{criteria}}{a vector with loglik, BIC, ICL and number of parameters} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-ZIPLNfit-update}{\code{ZIPLNfit$update()}} -\item \href{#method-ZIPLNfit-new}{\code{ZIPLNfit$new()}} -\item \href{#method-ZIPLNfit-optimize}{\code{ZIPLNfit$optimize()}} -\item \href{#method-ZIPLNfit-optimize_vestep}{\code{ZIPLNfit$optimize_vestep()}} -\item \href{#method-ZIPLNfit-predict}{\code{ZIPLNfit$predict()}} -\item \href{#method-ZIPLNfit-show}{\code{ZIPLNfit$show()}} -\item \href{#method-ZIPLNfit-print}{\code{ZIPLNfit$print()}} -\item \href{#method-ZIPLNfit-clone}{\code{ZIPLNfit$clone()}} -} + \itemize{ + \item \href{#method-ZIPLNfit-update}{\code{ZIPLNfit$update()}} + \item \href{#method-ZIPLNfit-initialize}{\code{ZIPLNfit$new()}} + \item \href{#method-ZIPLNfit-optimize}{\code{ZIPLNfit$optimize()}} + \item \href{#method-ZIPLNfit-optimize_vestep}{\code{ZIPLNfit$optimize_vestep()}} + \item \href{#method-ZIPLNfit-predict}{\code{ZIPLNfit$predict()}} + \item \href{#method-ZIPLNfit-show}{\code{ZIPLNfit$show()}} + \item \href{#method-ZIPLNfit-print}{\code{ZIPLNfit$print()}} + \item \href{#method-ZIPLNfit-clone}{\code{ZIPLNfit$clone()}} + } } \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZIPLNfit-update}{}}} -\subsection{Method \code{update()}}{ -Update a \code{\link{ZIPLNfit}} object -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit$update( +\subsection{\code{ZIPLNfit$update()}}{ + Update a \code{\link{ZIPLNfit}} object + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit$update( B = NA, B0 = NA, Pi = NA, @@ -114,112 +115,101 @@ Update a \code{\link{ZIPLNfit}} object Z = NA, A = NA, monitoring = NA -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{B}}{matrix of regression parameters in the Poisson lognormal component} + \item{\code{B0}}{matrix of regression parameters in the zero inflated component} + \item{\code{Pi}}{Zero inflated probability parameter (either scalar, row-vector, col-vector or matrix)} + \item{\code{Omega}}{precision matrix of the latent variables} + \item{\code{Sigma}}{covariance matrix of the latent variables} + \item{\code{M}}{matrix of mean vectors for the variational approximation} + \item{\code{S}}{matrix of standard deviation parameters for the variational approximation} + \item{\code{R}}{matrix of probabilities for the variational approximation} + \item{\code{Ji}}{vector of variational lower bounds of the log-likelihoods (one value per sample)} + \item{\code{Z}}{matrix of latent vectors (includes covariates and offset effects)} + \item{\code{A}}{matrix of fitted values} + \item{\code{monitoring}}{a list with optimization monitoring quantities} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + Update the current \code{\link{ZIPLNfit}} object + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{B}}{matrix of regression parameters in the Poisson lognormal component} - -\item{\code{B0}}{matrix of regression parameters in the zero inflated component} - -\item{\code{Pi}}{Zero inflated probability parameter (either scalar, row-vector, col-vector or matrix)} - -\item{\code{Omega}}{precision matrix of the latent variables} - -\item{\code{Sigma}}{covariance matrix of the latent variables} - -\item{\code{M}}{matrix of mean vectors for the variational approximation} - -\item{\code{S}}{matrix of standard deviation parameters for the variational approximation} - -\item{\code{R}}{matrix of probabilities for the variational approximation} - -\item{\code{Ji}}{vector of variational lower bounds of the log-likelihoods (one value per sample)} - -\item{\code{Z}}{matrix of latent vectors (includes covariates and offset effects)} - -\item{\code{A}}{matrix of fitted values} - -\item{\code{monitoring}}{a list with optimization monitoring quantities} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -Update the current \code{\link{ZIPLNfit}} object -} -} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZIPLNfit-new}{}}} -\subsection{Method \code{new()}}{ -Initialize a \code{\link{ZIPLNfit}} model -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit$new(data, control)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZIPLNfit-initialize}{}}} +\subsection{\code{ZIPLNfit$new()}}{ + Initialize a \code{\link{ZIPLNfit}} model + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit$new(data, control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{data}}{a named list used internally to carry the data matrices} + \item{\code{control}}{a list for controlling the optimization. See details.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{data}}{a named list used internally to carry the data matrices} - -\item{\code{control}}{a list for controlling the optimization. See details.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZIPLNfit-optimize}{}}} -\subsection{Method \code{optimize()}}{ -Call to the Cpp optimizer and update of the relevant fields -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit$optimize(data, control)}\if{html}{\out{
}} +\subsection{\code{ZIPLNfit$optimize()}}{ + Call to the Cpp optimizer and update of the relevant fields + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit$optimize(data, control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{data}}{a named list used internally to carry the data matrices} + \item{\code{control}}{a list for controlling the optimization. See details.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{data}}{a named list used internally to carry the data matrices} - -\item{\code{control}}{a list for controlling the optimization. See details.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZIPLNfit-optimize_vestep}{}}} -\subsection{Method \code{optimize_vestep()}}{ -Result of one call to the VE step of the optimization procedure: optimal variational parameters (M, S, R) and corresponding log likelihood values for fixed model parameters (Sigma, B, B0). Intended to position new data in the latent space. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit$optimize_vestep( +\subsection{\code{ZIPLNfit$optimize_vestep()}}{ + Result of one call to the VE step of the optimization procedure: optimal variational parameters (M, S, R) and corresponding log likelihood values for fixed model parameters (Sigma, B, B0). Intended to position new data in the latent space. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit$optimize_vestep( data, B = self$model_par$B, B0 = self$model_par$B0, Omega = self$model_par$Omega, control = ZIPLN_param(backend = "nlopt")$config_optim -)}\if{html}{\out{
}} -} - -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{data}}{a named list used internally to carry the data matrices} - -\item{\code{B}}{Optional fixed value of the regression parameters in the PLN component} - -\item{\code{B0}}{Optional fixed value of the regression parameters in the ZI component} - -\item{\code{Omega}}{inverse variance-covariance matrix of the latent variables} - -\item{\code{control}}{a list for controlling the optimization. See details.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -A list with three components: +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{data}}{a named list used internally to carry the data matrices} + \item{\code{B}}{Optional fixed value of the regression parameters in the PLN component} + \item{\code{B0}}{Optional fixed value of the regression parameters in the ZI component} + \item{\code{Omega}}{inverse variance-covariance matrix of the latent variables} + \item{\code{control}}{a list for controlling the optimization. See details.} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + A list with three components: \itemize{ \item the matrix \code{M} of variational means, \item the matrix \code{S} of variational standard deviations @@ -227,87 +217,92 @@ A list with three components: \item the vector \code{Ji} of (variational) log-likelihood of each new observation \item a list \code{monitoring} with information about convergence status } + } } -} + \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZIPLNfit-predict}{}}} -\subsection{Method \code{predict()}}{ -Predict position, scores or observations of new data. See \code{\link[=predict.ZIPLNfit]{predict.ZIPLNfit()}} for the S3 method and additional details -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit$predict( +\subsection{\code{ZIPLNfit$predict()}}{ + Predict position, scores or observations of new data. See \code{\link[=predict.ZIPLNfit]{predict.ZIPLNfit()}} for the S3 method and additional details + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit$predict( newdata, responses = NULL, type = c("link", "response", "deflated"), level = 1, envir = parent.frame() -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{newdata}}{A data frame in which to look for variables with which to predict. If omitted, the fitted values are used.} + \item{\code{responses}}{Optional data frame containing the count of the observed variables (matching the names of the provided as data in the PLN function), assuming the interest in in testing the model.} + \item{\code{type}}{Scale used for the prediction. Either \code{"link"} (default, predicted positions in the latent space), \code{"response"} (predicted average counts, accounting for zero-inflation) or \code{"deflated"} (predicted average counts, not accounting for zero-inflation and using only the PLN part of the model).} + \item{\code{level}}{Optional integer value the level to be used in obtaining the predictions. Level zero corresponds to the population predictions (default if \code{responses} is not provided) while level one (default) corresponds to predictions after evaluating the variational parameters for the new data.} + \item{\code{envir}}{Environment in which the prediction is evaluated} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + A matrix with predictions scores or counts. + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{newdata}}{A data frame in which to look for variables with which to predict. If omitted, the fitted values are used.} - -\item{\code{responses}}{Optional data frame containing the count of the observed variables (matching the names of the provided as data in the PLN function), assuming the interest in in testing the model.} - -\item{\code{type}}{Scale used for the prediction. Either \code{"link"} (default, predicted positions in the latent space), \code{"response"} (predicted average counts, accounting for zero-inflation) or \code{"deflated"} (predicted average counts, not accounting for zero-inflation and using only the PLN part of the model).} - -\item{\code{level}}{Optional integer value the level to be used in obtaining the predictions. Level zero corresponds to the population predictions (default if \code{responses} is not provided) while level one (default) corresponds to predictions after evaluating the variational parameters for the new data.} - -\item{\code{envir}}{Environment in which the prediction is evaluated} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -A matrix with predictions scores or counts. -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZIPLNfit-show}{}}} -\subsection{Method \code{show()}}{ -User friendly print method -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit$show( +\subsection{\code{ZIPLNfit$show()}}{ + User friendly print method + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit$show( model = paste("A multivariate Zero Inflated Poisson Lognormal fit with", self$vcov_model, "covariance model.\\n") -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{model}}{First line of the print output} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{model}}{First line of the print output} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZIPLNfit-print}{}}} -\subsection{Method \code{print()}}{ -User friendly print method -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit$print()}\if{html}{\out{
}} +\subsection{\code{ZIPLNfit$print()}}{ + User friendly print method + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit$print()} + \if{html}{\out{
}} + } } -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZIPLNfit-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{ZIPLNfit$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/ZIPLNfit_diagonal.Rd b/man/ZIPLNfit_diagonal.Rd index 8b75204f..672fee27 100644 --- a/man/ZIPLNfit_diagonal.Rd +++ b/man/ZIPLNfit_diagonal.Rd @@ -4,8 +4,6 @@ \alias{ZIPLNfit_diagonal} \title{An R6 Class to represent a ZIPLNfit in a standard, general framework, with diagonal residual covariance} \description{ -An R6 Class to represent a ZIPLNfit in a standard, general framework, with diagonal residual covariance - An R6 Class to represent a ZIPLNfit in a standard, general framework, with diagonal residual covariance } \examples{ @@ -19,70 +17,71 @@ print(myPLN) } } \section{Super class}{ -\code{\link[PLNmodels:ZIPLNfit]{PLNmodels::ZIPLNfit}} -> \code{ZIPLNfit_diagonal} +\code{\link[PLNmodels:ZIPLNfit]{ZIPLNfit}} -> \code{ZIPLNfit_diagonal} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{nb_param_pln}}{number of parameters in the PLN part of the current model} + \if{html}{\out{
}} + \describe{ + \item{\code{nb_param_pln}}{number of parameters in the PLN part of the current model} -\item{\code{vcov_model}}{character: the model used for the residual covariance} -} -\if{html}{\out{
}} + \item{\code{vcov_model}}{character: the model used for the residual covariance} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-ZIPLNfit_diagonal-new}{\code{ZIPLNfit_diagonal$new()}} -\item \href{#method-ZIPLNfit_diagonal-clone}{\code{ZIPLNfit_diagonal$clone()}} + \itemize{ + \item \href{#method-ZIPLNfit_diagonal-initialize}{\code{ZIPLNfit_diagonal$new()}} + \item \href{#method-ZIPLNfit_diagonal-clone}{\code{ZIPLNfit_diagonal$clone()}} + } } -} -\if{html}{\out{ -
Inherited methods +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZIPLNfit_diagonal-new}{}}} -\subsection{Method \code{new()}}{ -Initialize a \code{\link{ZIPLNfit_diagonal}} model -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit_diagonal$new(data, control)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZIPLNfit_diagonal-initialize}{}}} +\subsection{\code{ZIPLNfit_diagonal$new()}}{ + Initialize a \code{\link{ZIPLNfit_diagonal}} model + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit_diagonal$new(data, control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{data}}{a named list used internally to carry the data matrices} + \item{\code{control}}{a list for controlling the optimization. See details.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{data}}{a named list used internally to carry the data matrices} - -\item{\code{control}}{a list for controlling the optimization. See details.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZIPLNfit_diagonal-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit_diagonal$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{ZIPLNfit_diagonal$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit_diagonal$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/ZIPLNfit_fixed.Rd b/man/ZIPLNfit_fixed.Rd index 6f6da2fd..049adc2d 100644 --- a/man/ZIPLNfit_fixed.Rd +++ b/man/ZIPLNfit_fixed.Rd @@ -4,8 +4,6 @@ \alias{ZIPLNfit_fixed} \title{An R6 Class to represent a ZIPLNfit in a standard, general framework, with fixed (inverse) residual covariance} \description{ -An R6 Class to represent a ZIPLNfit in a standard, general framework, with fixed (inverse) residual covariance - An R6 Class to represent a ZIPLNfit in a standard, general framework, with fixed (inverse) residual covariance } \examples{ @@ -20,70 +18,71 @@ print(myPLN) } } \section{Super class}{ -\code{\link[PLNmodels:ZIPLNfit]{PLNmodels::ZIPLNfit}} -> \code{ZIPLNfit_fixed} +\code{\link[PLNmodels:ZIPLNfit]{ZIPLNfit}} -> \code{ZIPLNfit_fixed} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{nb_param_pln}}{number of parameters in the PLN part of the current model} + \if{html}{\out{
}} + \describe{ + \item{\code{nb_param_pln}}{number of parameters in the PLN part of the current model} -\item{\code{vcov_model}}{character: the model used for the residual covariance} -} -\if{html}{\out{
}} + \item{\code{vcov_model}}{character: the model used for the residual covariance} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-ZIPLNfit_fixed-new}{\code{ZIPLNfit_fixed$new()}} -\item \href{#method-ZIPLNfit_fixed-clone}{\code{ZIPLNfit_fixed$clone()}} + \itemize{ + \item \href{#method-ZIPLNfit_fixed-initialize}{\code{ZIPLNfit_fixed$new()}} + \item \href{#method-ZIPLNfit_fixed-clone}{\code{ZIPLNfit_fixed$clone()}} + } } -} -\if{html}{\out{ -
Inherited methods +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZIPLNfit_fixed-new}{}}} -\subsection{Method \code{new()}}{ -Initialize a \code{\link{ZIPLNfit_fixed}} model -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit_fixed$new(data, control)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZIPLNfit_fixed-initialize}{}}} +\subsection{\code{ZIPLNfit_fixed$new()}}{ + Initialize a \code{\link{ZIPLNfit_fixed}} model + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit_fixed$new(data, control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{data}}{a named list used internally to carry the data matrices} + \item{\code{control}}{a list for controlling the optimization. See details.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{data}}{a named list used internally to carry the data matrices} - -\item{\code{control}}{a list for controlling the optimization. See details.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZIPLNfit_fixed-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit_fixed$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{ZIPLNfit_fixed$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit_fixed$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/ZIPLNfit_sparse.Rd b/man/ZIPLNfit_sparse.Rd index f5e5387e..c22212d0 100644 --- a/man/ZIPLNfit_sparse.Rd +++ b/man/ZIPLNfit_sparse.Rd @@ -4,8 +4,6 @@ \alias{ZIPLNfit_sparse} \title{An R6 Class to represent a ZIPLNfit in a standard, general framework, with sparse inverse residual covariance} \description{ -An R6 Class to represent a ZIPLNfit in a standard, general framework, with sparse inverse residual covariance - An R6 Class to represent a ZIPLNfit in a standard, general framework, with sparse inverse residual covariance } \examples{ @@ -20,98 +18,100 @@ plot(myPLN) } } \section{Super class}{ -\code{\link[PLNmodels:ZIPLNfit]{PLNmodels::ZIPLNfit}} -> \code{ZIPLNfit_sparse} +\code{\link[PLNmodels:ZIPLNfit]{ZIPLNfit}} -> \code{ZIPLNfit_sparse} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{penalty}}{the global level of sparsity in the current model} + \if{html}{\out{
}} + \describe{ + \item{\code{penalty}}{the global level of sparsity in the current model} -\item{\code{penalty_weights}}{a matrix of weights controlling the amount of penalty element-wise.} + \item{\code{penalty_weights}}{a matrix of weights controlling the amount of penalty element-wise.} -\item{\code{n_edges}}{number of edges if the network (non null coefficient of the sparse precision matrix)} + \item{\code{n_edges}}{number of edges if the network (non null coefficient of the sparse precision matrix)} -\item{\code{nb_param_pln}}{number of parameters in the PLN part of the current model} + \item{\code{nb_param_pln}}{number of parameters in the PLN part of the current model} -\item{\code{vcov_model}}{character: the model used for the residual covariance} + \item{\code{vcov_model}}{character: the model used for the residual covariance} -\item{\code{pen_loglik}}{variational lower bound of the l1-penalized loglikelihood} + \item{\code{pen_loglik}}{variational lower bound of the l1-penalized loglikelihood} -\item{\code{EBIC}}{variational lower bound of the EBIC} + \item{\code{EBIC}}{variational lower bound of the EBIC} -\item{\code{density}}{proportion of non-null edges in the network} + \item{\code{density}}{proportion of non-null edges in the network} -\item{\code{criteria}}{a vector with loglik, penalized loglik, BIC, EBIC, ICL, R_squared, number of parameters, number of edges and graph density} -} -\if{html}{\out{
}} + \item{\code{criteria}}{a vector with loglik, penalized loglik, BIC, EBIC, ICL, R_squared, number of parameters, number of edges and graph density} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-ZIPLNfit_sparse-new}{\code{ZIPLNfit_sparse$new()}} -\item \href{#method-ZIPLNfit_sparse-latent_network}{\code{ZIPLNfit_sparse$latent_network()}} -\item \href{#method-ZIPLNfit_sparse-plot_network}{\code{ZIPLNfit_sparse$plot_network()}} -\item \href{#method-ZIPLNfit_sparse-clone}{\code{ZIPLNfit_sparse$clone()}} -} -} -\if{html}{\out{ -
Inherited methods + \itemize{ + \item \href{#method-ZIPLNfit_sparse-initialize}{\code{ZIPLNfit_sparse$new()}} + \item \href{#method-ZIPLNfit_sparse-latent_network}{\code{ZIPLNfit_sparse$latent_network()}} + \item \href{#method-ZIPLNfit_sparse-plot_network}{\code{ZIPLNfit_sparse$plot_network()}} + \item \href{#method-ZIPLNfit_sparse-clone}{\code{ZIPLNfit_sparse$clone()}} + } +} +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZIPLNfit_sparse-new}{}}} -\subsection{Method \code{new()}}{ -Initialize a \code{\link{ZIPLNfit_fixed}} model -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit_sparse$new(data, control)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZIPLNfit_sparse-initialize}{}}} +\subsection{\code{ZIPLNfit_sparse$new()}}{ + Initialize a \code{\link{ZIPLNfit_fixed}} model + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit_sparse$new(data, control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{data}}{a named list used internally to carry the data matrices} + \item{\code{control}}{a list for controlling the optimization. See details.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{data}}{a named list used internally to carry the data matrices} - -\item{\code{control}}{a list for controlling the optimization. See details.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZIPLNfit_sparse-latent_network}{}}} -\subsection{Method \code{latent_network()}}{ -Extract interaction network in the latent space -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit_sparse$latent_network(type = c("partial_cor", "support", "precision"))}\if{html}{\out{
}} +\subsection{\code{ZIPLNfit_sparse$latent_network()}}{ + Extract interaction network in the latent space + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit_sparse$latent_network(type = c("partial_cor", "support", "precision"))} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{type}}{edge value in the network. Can be "support" (binary edges), "precision" (coefficient of the precision matrix) or "partial_cor" (partial correlation between species)} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + a square matrix of size \code{ZIPLNfit_sparse$n} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{type}}{edge value in the network. Can be "support" (binary edges), "precision" (coefficient of the precision matrix) or "partial_cor" (partial correlation between species)} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -a square matrix of size \code{ZIPLNfit_sparse$n} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZIPLNfit_sparse-plot_network}{}}} -\subsection{Method \code{plot_network()}}{ -plot the latent network. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit_sparse$plot_network( +\subsection{\code{ZIPLNfit_sparse$plot_network()}}{ + plot the latent network. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit_sparse$plot_network( type = c("partial_cor", "support"), output = c("igraph", "corrplot"), edge.color = c("#F8766D", "#00BFC4"), @@ -119,44 +119,41 @@ plot the latent network. node.labels = NULL, layout = layout_in_circle, plot = TRUE -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{type}}{edge value in the network. Either "precision" (coefficient of the precision matrix) or "partial_cor" (partial correlation between species).} + \item{\code{output}}{Output type. Either \code{igraph} (for the network) or \code{corrplot} (for the adjacency matrix)} + \item{\code{edge.color}}{Length 2 color vector. Color for positive/negative edges. Default is \code{c("#F8766D", "#00BFC4")}. Only relevant for igraph output.} + \item{\code{remove.isolated}}{if \code{TRUE}, isolated node are remove before plotting. Only relevant for igraph output.} + \item{\code{node.labels}}{vector of character. The labels of the nodes. The default will use the column names ot the response matrix.} + \item{\code{layout}}{an optional igraph layout. Only relevant for igraph output.} + \item{\code{plot}}{logical. Should the final network be displayed or only sent back to the user. Default is \code{TRUE}.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{type}}{edge value in the network. Either "precision" (coefficient of the precision matrix) or "partial_cor" (partial correlation between species).} - -\item{\code{output}}{Output type. Either \code{igraph} (for the network) or \code{corrplot} (for the adjacency matrix)} - -\item{\code{edge.color}}{Length 2 color vector. Color for positive/negative edges. Default is \code{c("#F8766D", "#00BFC4")}. Only relevant for igraph output.} - -\item{\code{remove.isolated}}{if \code{TRUE}, isolated node are remove before plotting. Only relevant for igraph output.} - -\item{\code{node.labels}}{vector of character. The labels of the nodes. The default will use the column names ot the response matrix.} - -\item{\code{layout}}{an optional igraph layout. Only relevant for igraph output.} - -\item{\code{plot}}{logical. Should the final network be displayed or only sent back to the user. Default is \code{TRUE}.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZIPLNfit_sparse-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit_sparse$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{ZIPLNfit_sparse$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit_sparse$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/ZIPLNfit_spherical.Rd b/man/ZIPLNfit_spherical.Rd index 5779c2c8..ccd7b049 100644 --- a/man/ZIPLNfit_spherical.Rd +++ b/man/ZIPLNfit_spherical.Rd @@ -4,8 +4,6 @@ \alias{ZIPLNfit_spherical} \title{An R6 Class to represent a ZIPLNfit in a standard, general framework, with spherical residual covariance} \description{ -An R6 Class to represent a ZIPLNfit in a standard, general framework, with spherical residual covariance - An R6 Class to represent a ZIPLNfit in a standard, general framework, with spherical residual covariance } \examples{ @@ -19,70 +17,71 @@ print(myPLN) } } \section{Super class}{ -\code{\link[PLNmodels:ZIPLNfit]{PLNmodels::ZIPLNfit}} -> \code{ZIPLNfit_spherical} +\code{\link[PLNmodels:ZIPLNfit]{ZIPLNfit}} -> \code{ZIPLNfit_spherical} } \section{Active bindings}{ -\if{html}{\out{
}} -\describe{ -\item{\code{nb_param_pln}}{number of parameters in the PLN part of the current model} + \if{html}{\out{
}} + \describe{ + \item{\code{nb_param_pln}}{number of parameters in the PLN part of the current model} -\item{\code{vcov_model}}{character: the model used for the residual covariance} -} -\if{html}{\out{
}} + \item{\code{vcov_model}}{character: the model used for the residual covariance} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-ZIPLNfit_spherical-new}{\code{ZIPLNfit_spherical$new()}} -\item \href{#method-ZIPLNfit_spherical-clone}{\code{ZIPLNfit_spherical$clone()}} + \itemize{ + \item \href{#method-ZIPLNfit_spherical-initialize}{\code{ZIPLNfit_spherical$new()}} + \item \href{#method-ZIPLNfit_spherical-clone}{\code{ZIPLNfit_spherical$clone()}} + } } -} -\if{html}{\out{ -
Inherited methods +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZIPLNfit_spherical-new}{}}} -\subsection{Method \code{new()}}{ -Initialize a \code{\link{ZIPLNfit_spherical}} model -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit_spherical$new(data, control)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZIPLNfit_spherical-initialize}{}}} +\subsection{\code{ZIPLNfit_spherical$new()}}{ + Initialize a \code{\link{ZIPLNfit_spherical}} model + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit_spherical$new(data, control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{data}}{a named list used internally to carry the data matrices} + \item{\code{control}}{a list for controlling the optimization. See details.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{data}}{a named list used internally to carry the data matrices} - -\item{\code{control}}{a list for controlling the optimization. See details.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZIPLNfit_spherical-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNfit_spherical$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{ZIPLNfit_spherical$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNfit_spherical$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } diff --git a/man/ZIPLNnetworkfamily.Rd b/man/ZIPLNnetworkfamily.Rd index 0bf90623..dde5b687 100644 --- a/man/ZIPLNnetworkfamily.Rd +++ b/man/ZIPLNnetworkfamily.Rd @@ -20,100 +20,101 @@ class(fits) The function \code{\link[=ZIPLNnetwork]{ZIPLNnetwork()}}, the class \code{\link{ZIPLNfit_sparse}} } \section{Super classes}{ -\code{\link[PLNmodels:PLNfamily]{PLNmodels::PLNfamily}} -> \code{\link[PLNmodels:Networkfamily]{PLNmodels::Networkfamily}} -> \code{ZIPLNnetworkfamily} +\code{\link[PLNmodels:PLNfamily]{PLNfamily}} -> \code{\link[PLNmodels:Networkfamily]{Networkfamily}} -> \code{ZIPLNnetworkfamily} } \section{Public fields}{ -\if{html}{\out{
}} -\describe{ -\item{\code{covariates0}}{the matrix of covariates included in the ZI component} -} -\if{html}{\out{
}} + \if{html}{\out{
}} + \describe{ + \item{\code{covariates0}}{the matrix of covariates included in the ZI component} + } + \if{html}{\out{
}} } \section{Methods}{ \subsection{Public methods}{ -\itemize{ -\item \href{#method-ZIPLNnetworkfamily-new}{\code{ZIPLNnetworkfamily$new()}} -\item \href{#method-ZIPLNnetworkfamily-stability_selection}{\code{ZIPLNnetworkfamily$stability_selection()}} -\item \href{#method-ZIPLNnetworkfamily-clone}{\code{ZIPLNnetworkfamily$clone()}} -} + \itemize{ + \item \href{#method-ZIPLNnetworkfamily-initialize}{\code{ZIPLNnetworkfamily$new()}} + \item \href{#method-ZIPLNnetworkfamily-stability_selection}{\code{ZIPLNnetworkfamily$stability_selection()}} + \item \href{#method-ZIPLNnetworkfamily-clone}{\code{ZIPLNnetworkfamily$clone()}} + } } -\if{html}{\out{ -
Inherited methods +\if{html}{\out{
Inherited methods -
-}} +
}} \if{html}{\out{
}} -\if{html}{\out{}} -\if{latex}{\out{\hypertarget{method-ZIPLNnetworkfamily-new}{}}} -\subsection{Method \code{new()}}{ -Initialize all models in the collection -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNnetworkfamily$new(penalties, data, control)}\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-ZIPLNnetworkfamily-initialize}{}}} +\subsection{\code{ZIPLNnetworkfamily$new()}}{ + Initialize all models in the collection + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNnetworkfamily$new(penalties, data, control)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{penalties}}{a vector of positive real number controlling the level of sparsity of the underlying network.} + \item{\code{data}}{a named list used internally to carry the data matrices} + \item{\code{control}}{a list for controlling the optimization.} + } + \if{html}{\out{
}} + } + \subsection{Returns}{ + Update current \code{\link{PLNnetworkfit}} with smart starting values + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{penalties}}{a vector of positive real number controlling the level of sparsity of the underlying network.} - -\item{\code{data}}{a named list used internally to carry the data matrices} - -\item{\code{control}}{a list for controlling the optimization.} -} -\if{html}{\out{
}} -} -\subsection{Returns}{ -Update current \code{\link{PLNnetworkfit}} with smart starting values -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZIPLNnetworkfamily-stability_selection}{}}} -\subsection{Method \code{stability_selection()}}{ -Compute the stability path by stability selection -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNnetworkfamily$stability_selection( +\subsection{\code{ZIPLNnetworkfamily$stability_selection()}}{ + Compute the stability path by stability selection + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNnetworkfamily$stability_selection( subsamples = NULL, control = ZIPLNnetwork_param() -)}\if{html}{\out{
}} +)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{subsamples}}{a list of vectors describing the subsamples. The number of vectors (or list length) determines the number of subsamples used in the stability selection. Automatically set to 20 subsamples with size \code{10*sqrt(n)} if \code{n >= 144} and \code{0.8*n} otherwise following Liu et al. (2010) recommendations.} + \item{\code{control}}{a list controlling the main optimization process in each call to \code{\link[=PLNnetwork]{PLNnetwork()}}. See \code{\link[=ZIPLNnetwork]{ZIPLNnetwork()}} and \code{\link[=ZIPLN_param]{ZIPLN_param()}} for details.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{subsamples}}{a list of vectors describing the subsamples. The number of vectors (or list length) determines the number of subsamples used in the stability selection. Automatically set to 20 subsamples with size \code{10*sqrt(n)} if \code{n >= 144} and \code{0.8*n} otherwise following Liu et al. (2010) recommendations.} - -\item{\code{control}}{a list controlling the main optimization process in each call to \code{\link[=PLNnetwork]{PLNnetwork()}}. See \code{\link[=ZIPLNnetwork]{ZIPLNnetwork()}} and \code{\link[=ZIPLN_param]{ZIPLN_param()}} for details.} -} -\if{html}{\out{
}} -} -} \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZIPLNnetworkfamily-clone}{}}} -\subsection{Method \code{clone()}}{ -The objects of this class are cloneable with this method. -\subsection{Usage}{ -\if{html}{\out{
}}\preformatted{ZIPLNnetworkfamily$clone(deep = FALSE)}\if{html}{\out{
}} +\subsection{\code{ZIPLNnetworkfamily$clone()}}{ + The objects of this class are cloneable with this method. + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{ZIPLNnetworkfamily$clone(deep = FALSE)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{deep}}{Whether to make a deep clone.} + } + \if{html}{\out{
}} + } } -\subsection{Arguments}{ -\if{html}{\out{
}} -\describe{ -\item{\code{deep}}{Whether to make a deep clone.} -} -\if{html}{\out{
}} -} -} } From 33dc9bcfe66df73031cfd56f2c0b7532f2b96766 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 5 Jun 2026 22:19:46 +0200 Subject: [PATCH 02/58] avoid some redudancies in the computations --- src/Makevars | 3 +- src/optim_diag_cov.cpp | 24 +++++---- src/optim_full_cov.cpp | 117 +++++++++++++++++++++++++++------------- src/optim_genet_cov.cpp | 6 ++- src/optim_rank_cov.cpp | 24 +++++---- src/optim_spherical.cpp | 16 ++++-- src/optim_zi-pln.cpp | 34 ++++++------ src/packing.h | 2 - src/utils.h | 3 +- 9 files changed, 146 insertions(+), 83 deletions(-) diff --git a/src/Makevars b/src/Makevars index 22ebc632..3a7f8ac9 100644 --- a/src/Makevars +++ b/src/Makevars @@ -1 +1,2 @@ -PKG_LIBS = $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) +PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) +PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) diff --git a/src/optim_diag_cov.cpp b/src/optim_diag_cov.cpp index 01d9558c..c5508830 100644 --- a/src/optim_diag_cov.cpp +++ b/src/optim_diag_cov.cpp @@ -35,10 +35,13 @@ Rcpp::List nlopt_optimize_diagonal( auto optimizer = new_nlopt_optimizer(config, parameters.size()); std::vector objective_vec ; + objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); const double w_bar = accu(w); + const arma::mat Xw = X.each_col() % w; // fixed: precomputed once + // Optimize - auto objective_and_grad = [&metadata, &O, &X, &Y, &w, &w_bar, &objective_vec](const double * params, double * grad) -> double { + auto objective_and_grad = [&metadata, &O, &X, &Xw, &Y, &w, &w_bar, &objective_vec](const double * params, double * grad) -> double { const arma::mat B = metadata.map(params); const arma::mat M = metadata.map(params); const arma::mat S = metadata.map(params); @@ -49,9 +52,9 @@ Rcpp::List nlopt_optimize_diagonal( arma::rowvec diag_sigma = w.t() * (M % M + S2) / w_bar; double objective = accu(diagmat(w) * (A - Y % Z - 0.5 * log(S2))) + 0.5 * w_bar * accu(log(diag_sigma)); - metadata.map(grad) = (X.each_col() % w).t() * (A - Y); + metadata.map(grad) = Xw.t() * (A - Y); metadata.map(grad) = diagmat(w) * ((M.each_row() / diag_sigma) + A - Y); - metadata.map(grad) = diagmat(w) * (S.each_row() % pow(diag_sigma, -1) + S % A - pow(S, -1)) ; + metadata.map(grad) = diagmat(w) * (S.each_row() % pow(diag_sigma, -1) + S % A - pow(S, -1)); objective_vec.push_back(objective) ; @@ -127,21 +130,24 @@ Rcpp::List nlopt_optimize_vestep_diagonal( auto optimizer = new_nlopt_optimizer(config, parameters.size()); std::vector objective_vec ; + objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); + + const arma::mat XB_diag = X * B; + const arma::vec omega2_v = arma::diagvec(Omega); // fixed: Omega not optimized in vestep // Optimize - auto objective_and_grad = [&metadata, &O, &X, &Y, &w, &B, &Omega, &objective_vec](const double * params, double * grad) -> double { + auto objective_and_grad = [&metadata, &O, &XB_diag, &Y, &w, &omega2_v, &objective_vec](const double * params, double * grad) -> double { const arma::mat M = metadata.map(params); const arma::mat S = metadata.map(params); arma::mat S2 = S % S; - arma::mat Z = O + X * B + M; + arma::mat Z = O + XB_diag + M; arma::mat A = exp(Z + 0.5 * S2); - arma::vec omega2 = arma::diagvec(Omega); double objective = - accu(w.t() * (A - Y % Z - 0.5 * log(S2))) + 0.5 * as_scalar(w.t() * (pow(M, 2) + S2) * omega2) ; + accu(w.t() * (A - Y % Z - 0.5 * log(S2))) + 0.5 * as_scalar(w.t() * (pow(M, 2) + S2) * omega2_v) ; - metadata.map(grad) = diagmat(w) * (M * arma::diagmat(omega2) + A - Y); - metadata.map(grad) = diagmat(w) * (S.each_row() % omega2.t() + S % A - pow(S, -1)); + metadata.map(grad) = diagmat(w) * (M * arma::diagmat(omega2_v) + A - Y); + metadata.map(grad) = diagmat(w) * (S.each_row() % omega2_v.t() + S % A - pow(S, -1)); objective_vec.push_back(objective) ; diff --git a/src/optim_full_cov.cpp b/src/optim_full_cov.cpp index 0e43698a..1093fa7d 100644 --- a/src/optim_full_cov.cpp +++ b/src/optim_full_cov.cpp @@ -33,43 +33,82 @@ Rcpp::List nlopt_optimize( metadata.map(parameters.data()) = init_M; metadata.map(parameters.data()) = init_S; - // Optimize - auto optimizer = new_nlopt_optimizer(config, parameters.size()); - std::vector objective_vec ; const double w_bar = accu(w); + // VEM config — sensible defaults if not supplied by R + const int max_em_iter = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; + const double em_ftol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + + // Initial Omega: closed-form from initial M, S (one inv_sympd, outside the loop) + arma::mat Omega; + { + const arma::mat S2_init = init_S % init_S; + arma::mat Sigma_init = (1. / w_bar) * (init_M.t() * (init_M.each_col() % w) + diagmat(w.t() * S2_init)); + Omega = inv_sympd(Sigma_init); + } + + std::vector objective_vec; + double elbo_prev = -arma::datum::inf; + int total_iterations = 0; + int last_status = 0; + const arma::mat Xw = X.each_col() % w; // fixed: precomputed once for all EM iterations + + for (int em_iter = 0; em_iter < std::max(1, max_em_iter); em_iter++) { + // E-step: optimize B, M, S with Omega fixed — no inv_sympd inside gradient + auto optimizer = new_nlopt_optimizer(config, parameters.size()); + objective_vec.reserve(objective_vec.size() + nlopt_get_maxeval(optimizer.get())); + const arma::vec Omega_diag = diagvec(Omega); // fixed per EM iteration + + auto objective_and_grad = [&metadata, &Y, &X, &Xw, &O, &w, &Omega, &Omega_diag, &objective_vec](const double * params, double * grad) -> double { + const arma::mat B = metadata.map(params); + const arma::mat M = metadata.map(params); + const arma::mat S = metadata.map(params); + arma::mat S2 = S % S; + arma::mat Z = O + X * B + M; + arma::mat A = exp(Z + 0.5 * S2); + arma::mat MO = M * Omega; // cached: reused in objective and M-gradient + const arma::rowvec wS2 = w.t() * S2; + + // trace(Omega * nSigma) = accu(MO % (W*M)) + dot(diag(Omega), w^T S2) + double objective = accu(w.t() * (A - Y % Z - 0.5 * trunc_log(S2))) + + 0.5 * (accu(MO % (M.each_col() % w)) + dot(Omega_diag, wS2.t())); + + metadata.map(grad) = Xw.t() * (A - Y); + metadata.map(grad) = diagmat(w) * (MO + A - Y); + metadata.map(grad) = diagmat(w) * (S.each_row() % Omega_diag.t() + S % A - pow(S, -1)); + + objective_vec.push_back(objective); + return objective; + }; + + OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); + total_iterations += result.nb_iterations; + last_status = static_cast(result.status); + + // M-step: update Omega analytically (one inv_sympd per EM iteration) + arma::mat M = metadata.copy(parameters.data()); + arma::mat S = metadata.copy(parameters.data()); + arma::mat S2 = S % S; + arma::mat Sigma = (1. / w_bar) * (M.t() * (M.each_col() % w) + diagmat(w.t() * S2)); + Omega = inv_sympd(Sigma); - auto objective_and_grad = [&metadata, &Y, &X, &O, &w, &w_bar, &objective_vec](const double * params, double * grad) -> double { - const arma::mat B = metadata.map(params); - const arma::mat M = metadata.map(params); - const arma::mat S = metadata.map(params); - const double w_bar = accu(w); - - arma::mat S2 = S % S ; - arma::mat Z = O + X * B + M ; + // ELBO after M-step: trace(Omega*nSigma) = w_bar*p, log_det(Omega) = -log_det(Sigma) + arma::mat B = metadata.copy(parameters.data()); + arma::mat Z = O + X * B + M; arma::mat A = exp(Z + 0.5 * S2); - arma::mat Omega = w_bar * inv_sympd(M.t() * (M.each_col() % w) + diagmat(w.t() * S2)); - double objective = accu(w.t() * (A - Y % Z - 0.5 * trunc_log(S2))) - 0.5 * w_bar * real(log_det(Omega)); + double elbo = accu(w.t() * (Y % Z - A + 0.5 * trunc_log(S2))) + - 0.5 * w_bar * real(log_det(Sigma)); - metadata.map(grad) = (X.each_col() % w).t() * (A - Y) ; - metadata.map(grad) = diagmat(w) * (M * Omega + A - Y) ; - metadata.map(grad) = diagmat(w) * (S.each_row() % diagvec(Omega).t() + S % A - pow(S, -1)) ; + if (em_iter > 0 && std::abs(elbo - elbo_prev) < em_ftol * (1.0 + std::abs(elbo_prev))) break; + elbo_prev = elbo; + } - objective_vec.push_back(objective) ; - - return objective; - }; - OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); - - // Variational parameters + // Final extraction arma::mat M = metadata.copy(parameters.data()); arma::mat S = metadata.copy(parameters.data()); arma::mat S2 = S % S; - // Regression parameters arma::mat B = metadata.copy(parameters.data()); - // Variance parameters arma::mat Sigma = (1. / w_bar) * (M.t() * (M.each_col() % w) + diagmat(w.t() * S2)); - arma::mat Omega = inv_sympd(Sigma); - // Element-wise log-likehood + // Omega already updated from the last M-step arma::mat Z = O + X * B + M; arma::mat A = exp(Z + 0.5 * S2); arma::vec loglik = sum(Y % Z - A + 0.5 * log(S2) - 0.5 * ((M * Omega) % M + S2 * diagmat(Omega)), 1) + @@ -87,12 +126,12 @@ Rcpp::List nlopt_optimize( Rcpp::Named("Omega", Omega), Rcpp::Named("Ji", Ji), Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", static_cast(result.status)), + Rcpp::Named("status", last_status), Rcpp::Named("backend", "nlopt"), Rcpp::Named("objective", objective_vec), - Rcpp::Named("iterations", result.nb_iterations) + Rcpp::Named("iterations", total_iterations) )) - ); + ); } // --------------------------------------------------------------------------------------- @@ -124,19 +163,25 @@ Rcpp::List nlopt_optimize_vestep( // Optimize auto optimizer = new_nlopt_optimizer(config, parameters.size()); std::vector objective_vec ; + objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); - auto objective_and_grad = [&metadata, &O, &X, &Y, &w, &B, &Omega, &objective_vec](const double * params, double * grad) -> double { + const arma::mat XB_vestep = X * B; + const arma::vec Omega_diag_v = diagvec(Omega); + + auto objective_and_grad = [&metadata, &O, &XB_vestep, &Y, &w, &Omega, &Omega_diag_v, &objective_vec](const double * params, double * grad) -> double { const arma::mat M = metadata.map(params); const arma::mat S = metadata.map(params); arma::mat S2 = S % S; - arma::mat Z = O + X * B + M; + arma::mat Z = O + XB_vestep + M; arma::mat A = exp(Z + 0.5 * S2); - arma::mat nSigma = M.t() * (M.each_col() % w) + diagmat(w.t() * S2) ; - double objective = accu(w.t() * (A - Y % Z - 0.5 * log(S2))) + 0.5 * trace(Omega * nSigma) ; + arma::mat MO = M * Omega; + const arma::rowvec wS2 = w.t() * S2; + double objective = accu(w.t() * (A - Y % Z - 0.5 * log(S2))) + + 0.5 * (accu(MO % (M.each_col() % w)) + dot(Omega_diag_v, wS2.t())); - metadata.map(grad) = diagmat(w) * (M * Omega + A - Y); - metadata.map(grad) = diagmat(w) * (S.each_row() % diagvec(Omega).t() + S % A - pow(S, -1)); + metadata.map(grad) = diagmat(w) * (MO + A - Y); + metadata.map(grad) = diagmat(w) * (S.each_row() % Omega_diag_v.t() + S % A - pow(S, -1)); objective_vec.push_back(objective) ; diff --git a/src/optim_genet_cov.cpp b/src/optim_genet_cov.cpp index 356cfbb1..45be120d 100644 --- a/src/optim_genet_cov.cpp +++ b/src/optim_genet_cov.cpp @@ -44,8 +44,10 @@ Rcpp::List nlopt_optimize_genetic_modeling( arma::mat V; arma::eig_sym(Lambda, V, C); + const arma::mat Xw = X.each_col() % w; // fixed: precomputed once + // Optimize - auto objective_and_grad = [&metadata, &Y, &X, &O, &V, &Lambda, &w, &w_bar](const double * params, double * grad) -> double { + auto objective_and_grad = [&metadata, &Y, &X, &Xw, &O, &V, &Lambda, &w, &w_bar](const double * params, double * grad) -> double { const arma::mat Theta = metadata.map(params); const arma::mat M = metadata.map(params); const arma::mat S = metadata.map(params); @@ -64,7 +66,7 @@ Rcpp::List nlopt_optimize_genetic_modeling( 0.5 * trace(Omega * (M.t() * (M.each_col() % w) + diagmat(w.t() * S2))) + 0.5 * w_bar * accu(log(u * sigma2)); - metadata.map(grad) = (A - Y).t() * (X.each_col() % w); + metadata.map(grad) = (A - Y).t() * Xw; metadata.map(grad) = diagmat(w) * (M * Omega + A - Y); metadata.map(grad) = diagmat(w) * (S.each_row() % diagvec(Omega).t() + S % A - pow(S, -1)); metadata.map(grad) = accu(0.5 * w_bar * (Lambda - 1) / u - (0.5/sigma2) * diagvec(R) % (Lambda - 1) / pow(u, 2) ); diff --git a/src/optim_rank_cov.cpp b/src/optim_rank_cov.cpp index 0f09f052..3dd31951 100644 --- a/src/optim_rank_cov.cpp +++ b/src/optim_rank_cov.cpp @@ -40,22 +40,26 @@ Rcpp::List nlopt_optimize_rank( // Optimize auto optimizer = new_nlopt_optimizer(config, parameters.size()); std::vector objective_vec ; + objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); - auto objective_and_grad = [&metadata, &O, &X, &Y, &w, &objective_vec](const double * params, double * grad) -> double { + const arma::mat Xw = X.each_col() % w; // fixed: precomputed once + + auto objective_and_grad = [&metadata, &O, &X, &Xw, &Y, &w, &objective_vec](const double * params, double * grad) -> double { const arma::mat B = metadata.map(params); const arma::mat C = metadata.map(params); const arma::mat M = metadata.map(params); const arma::mat S = metadata.map(params); + const arma::mat C2 = C % C; arma::mat S2 = S % S; arma::mat Z = O + X * B + M * C.t(); - arma::mat A = exp(Z + 0.5 * S2 * (C % C).t()); + arma::mat A = exp(Z + 0.5 * S2 * C2.t()); double objective = accu(diagmat(w) * (A - Y % Z)) + 0.5 * accu(diagmat(w) * (M % M + S2 - log(S2) - 1.)); - metadata.map(grad) = (X.each_col() % w).t() * (A - Y); + metadata.map(grad) = Xw.t() * (A - Y); metadata.map(grad) = (diagmat(w) * (A - Y)).t() * M + (A.t() * (S2.each_col() % w)) % C; metadata.map(grad) = diagmat(w) * ((A - Y) * C + M); - metadata.map(grad) = diagmat(w) * (S - 1. / S + A * (C % C) % S) ; + metadata.map(grad) = diagmat(w) * (S - 1. / S + A * C2 % S); objective_vec.push_back(objective) ; @@ -127,19 +131,21 @@ Rcpp::List nlopt_optimize_vestep_rank( // Optimize auto optimizer = new_nlopt_optimizer(config, parameters.size()); std::vector objective_vec ; + objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); + const arma::mat C2 = C % C; + const arma::mat XB = X * B; // fixed: B not optimized in vestep - auto objective_and_grad = [&metadata, &O, &X, &Y, &w, &B, &C, &objective_vec](const double * params, double * grad) -> double { + auto objective_and_grad = [&metadata, &O, &XB, &Y, &w, &C, &C2, &objective_vec](const double * params, double * grad) -> double { const arma::mat M = metadata.map(params); const arma::mat S = metadata.map(params); arma::mat S2 = S % S; - arma::mat Z = O + X * B + M * C.t(); - arma::mat A = exp(Z + 0.5 * S2 * (C % C).t()); - arma::mat nSigma = M.t() * (M.each_col() % w) + diagmat(w.t() * S2) ; + arma::mat Z = O + XB + M * C.t(); + arma::mat A = exp(Z + 0.5 * S2 * C2.t()); double objective = accu(diagmat(w) * (A - Y % Z)) + 0.5 * accu(diagmat(w) * (M % M + S2 - log(S2) - 1.)); metadata.map(grad) = diagmat(w) * ((A - Y) * C + M); - metadata.map(grad) = diagmat(w) * (S - 1. / S + A * (C % C) % S); + metadata.map(grad) = diagmat(w) * (S - 1. / S + A * C2 % S); objective_vec.push_back(objective) ; diff --git a/src/optim_spherical.cpp b/src/optim_spherical.cpp index 784099a9..677b68f2 100644 --- a/src/optim_spherical.cpp +++ b/src/optim_spherical.cpp @@ -37,8 +37,11 @@ Rcpp::List nlopt_optimize_spherical( auto optimizer = new_nlopt_optimizer(config, parameters.size()); const double w_bar = accu(w); std::vector objective_vec ; + objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); - auto objective_and_grad = [&metadata, &O, &X, &Y, &w, &w_bar, &objective_vec](const double * params, double * grad) -> double { + const arma::mat Xw = X.each_col() % w; // fixed: precomputed once + + auto objective_and_grad = [&metadata, &O, &X, &Xw, &Y, &w, &w_bar, &objective_vec](const double * params, double * grad) -> double { const arma::mat B = metadata.map(params); const arma::mat M = metadata.map(params); const arma::mat S = metadata.map(params); @@ -50,9 +53,9 @@ Rcpp::List nlopt_optimize_spherical( double sigma2 = accu(diagmat(w) * (pow(M, 2) + S2)) / (double(p) * w_bar) ; double objective = accu(w.t() * (A - Y % Z - 0.5 * log(S2))) + 0.5 * (double(p) * w_bar) * log(sigma2) ; - metadata.map(grad) = (X.each_col() % w).t() * (A - Y); + metadata.map(grad) = Xw.t() * (A - Y); metadata.map(grad) = diagmat(w) * (M / sigma2 + A - Y); - metadata.map(grad) = diagmat(w) * (S / sigma2 + S % A - pow(S, -1)) ; + metadata.map(grad) = diagmat(w) * (S / sigma2 + S % A - pow(S, -1)); objective_vec.push_back(objective) ; @@ -126,13 +129,16 @@ Rcpp::List nlopt_optimize_vestep_spherical( // Optimize auto optimizer = new_nlopt_optimizer(config, parameters.size()); std::vector objective_vec ; + objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); + + const arma::mat XB_sph = X * B; // fixed: B not optimized in vestep - auto objective_and_grad = [&metadata, &O, &X, &Y, &w, &B, &Omega, &objective_vec](const double * params, double * grad) -> double { + auto objective_and_grad = [&metadata, &O, &XB_sph, &Y, &w, &Omega, &objective_vec](const double * params, double * grad) -> double { const arma::mat M = metadata.map(params); const arma::mat S = metadata.map(params); arma::mat S2 = S % S; - arma::mat Z = O + X * B + M; + arma::mat Z = O + XB_sph + M; arma::mat A = exp(Z + 0.5 * S2); double n_sigma2 = accu(diagmat(w) * (pow(M, 2) + S2)) ; double omega2 = Omega(0, 0); diff --git a/src/optim_zi-pln.cpp b/src/optim_zi-pln.cpp index 54ce748f..b9a5c79a 100644 --- a/src/optim_zi-pln.cpp +++ b/src/optim_zi-pln.cpp @@ -1,4 +1,7 @@ #include +#ifdef _OPENMP +#include +#endif // [[Rcpp::depends(RcppArmadillo)]] // [[Rcpp::depends(nloptr)]] @@ -132,16 +135,7 @@ arma::mat optim_zipln_R_var( // Zero R_{i,j} if Y_{i,j} > 0 // multiplication with f(sign(Y)) could work to zero stuff as there should not be any +inf // using a loop as it is more explicit and should have ok performance in C++ - arma::uword n = Y.n_rows; - arma::uword p = Y.n_cols; - for(arma::uword i = 0; i < n; i += 1) { - for(arma::uword j = 0; j < p; j += 1) { - // Add fuzzy comparison ? - if(Y(i, j) > 0.) { - R(i, j) = 0.; - } - } - } + R.elem(arma::find(Y > 0.)).zeros(); return R; } @@ -163,15 +157,19 @@ arma::mat optim_zipln_R_exact ( arma::mat XB = X * B; arma::mat M_mu = M - XB; - arma::uword n = M.n_rows; - arma::uword p = M.n_cols; - arma::vec diag_Sigma = arma::diagvec((1./n) * (M_mu.t() * M_mu + diagmat(sum(S % S, 0)))) ; - arma::mat R = arma::zeros(n,p); - for(arma::uword i = 0; i < n; i += 1) { - for(arma::uword j = 0; j < p; j += 1) { + const int n = (int)M.n_rows; + const int p = (int)M.n_cols; + arma::vec diag_Sigma = arma::diagvec((1./n) * (M_mu.t() * M_mu + diagmat(sum(S % S, 0)))); + arma::mat R = arma::zeros(n, p); + // lambertW0_CS is pure (no global state) — safe to parallelize +#ifdef _OPENMP +#pragma omp parallel for collapse(2) schedule(static) +#endif + for(int i = 0; i < n; i++) { + for(int j = 0; j < p; j++) { if(Y(i, j) < 0.5) { - double Phi = phi(O(i,j) + XB(i,j), diag_Sigma(j)) ; - R(i,j) = Pi(i,j) / (Phi * (1 - Pi(i,j)) + Pi(i,j)) ; + double Phi = phi(O(i,j) + XB(i,j), diag_Sigma(j)); + R(i,j) = Pi(i,j) / (Phi * (1 - Pi(i,j)) + Pi(i,j)); } } } diff --git a/src/packing.h b/src/packing.h index 9e049717..203cdd7d 100644 --- a/src/packing.h +++ b/src/packing.h @@ -9,8 +9,6 @@ #include // packer system #include // move, forward -#define ARMA_EXTRA_DEBUG - // Stores type, dimensions and offset for a single T object. // Must be specialised ; see specialisations for double/arma::vec/arma::mat below. // diff --git a/src/utils.h b/src/utils.h index 68d38a4d..8a17fd13 100644 --- a/src/utils.h +++ b/src/utils.h @@ -18,7 +18,8 @@ inline arma::vec ki(arma::mat y) { } inline arma::mat logistic(arma::mat M) { - return arma::trunc_exp(M) % pow(1. + arma::trunc_exp(M), -1) ; + arma::mat e = arma::trunc_exp(M); + return e / (1. + e); } inline arma::mat logit(arma::mat M) { From 41a0c771fc275add92809b4cea0a662f176aa07b Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Mon, 8 Jun 2026 12:49:43 +0200 Subject: [PATCH 03/58] optimization in zipln + test --- inst/case_studies/microcosm.qmd | 4 ++-- inst/case_studies/oaks_tree.R | 6 ++---- inst/simus_ZIPLN/essai_ZIPLN.R | 7 ++++--- src/optim_zi-pln.cpp | 22 ++++++++++++---------- tests/testthat/test-zipln.R | 2 +- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/inst/case_studies/microcosm.qmd b/inst/case_studies/microcosm.qmd index 9014e0e7..0f2ecd0b 100644 --- a/inst/case_studies/microcosm.qmd +++ b/inst/case_studies/microcosm.qmd @@ -143,7 +143,7 @@ model_selection %>% gt() %>% ), locations = cells_body( columns = c("AIC"), - rows = c(4, 8, 16) + rows = c(4, 8, 17) )) %>% tab_style( style = list( @@ -152,7 +152,7 @@ model_selection %>% gt() %>% ), locations = cells_body( columns = c("ICL"), - rows = c(2, 8, 17) + rows = c(1, 7, 17) )) ``` diff --git a/inst/case_studies/oaks_tree.R b/inst/case_studies/oaks_tree.R index e93ac50f..afb30b6a 100644 --- a/inst/case_studies/oaks_tree.R +++ b/inst/case_studies/oaks_tree.R @@ -54,7 +54,6 @@ rbind( knitr::kable() - ## Discriminant Analysis with LDA myLDA_tree <- PLNLDA(Abundance ~ 1 + offset(log(Offset)), grouping = tree, data = oaks) plot(myLDA_tree) @@ -85,7 +84,7 @@ factoextra::fviz_pca_biplot( ) + labs(col = "distance (cm)") + scale_color_viridis_d() ## Dimension reduction with PCA -system.time(myPLNPCAs_tree <- PLNPCA(Abundance ~ 0 + tree + offset(log(Offset)), data = oaks, ranks = 1:30)) # about 40 sec. +system.time(myPLNPCAs_tree <- PLNPCA(Abundance ~ 0 + tree + offset(log(Offset)), data = oaks, ranks = 1:30)) # about 40 sec. with 20 cores plot(myPLNPCAs_tree) myPLNPCA_tree <- getBestModel(myPLNPCAs_tree) @@ -96,8 +95,7 @@ factoextra::fviz_pca_biplot( labs(col = "distance (cm)") + scale_color_viridis_c() ## Network inference with sparce covariance estimation - -system.time(myPLNnets <- PLNnetwork(Abundance ~ 0 + tree + offset(log(Offset)), data = oaks, control = PLNnetwork_param(min_ratio = 0.1))) +system.time(myPLNnets <- PLNnetwork(Abundance ~ 0 + tree + offset(log(Offset)), data = oaks, control = PLNnetwork_param(min_ratio = 0.05))) plot(myPLNnets) plot(getBestModel(myPLNnets, "EBIC")) # stability_selection(myPLNnets) diff --git a/inst/simus_ZIPLN/essai_ZIPLN.R b/inst/simus_ZIPLN/essai_ZIPLN.R index bf494ff2..fda84cc9 100644 --- a/inst/simus_ZIPLN/essai_ZIPLN.R +++ b/inst/simus_ZIPLN/essai_ZIPLN.R @@ -2,6 +2,7 @@ library(PLNmodels) library(MASS) library(tidyverse) library(parallel) +library(viridisLite) rZIPLN <- function(n = 10, mu = rep(0, ncol(Sigma)), @@ -129,12 +130,12 @@ one_simu <- function(i) { res <- do.call(rbind, lapply(1:50, one_simu)) -p <- ggplot(res) + aes(x = factor(n), y = pred_Y, fill = factor(method)) + geom_violin() + theme_bw() + +p <- ggplot(res) + aes(x = factor(n), y = pred_Y, fill = factor(method)) + geom_violin() + scale_fill_viridis_d() + theme_bw() + scale_y_log10() + ylim(c(0,2)) p -p <- ggplot(res) + aes(x = factor(n), y = rmse_B, fill = factor(method)) + geom_violin() + theme_bw() + scale_y_log10() + ylim(c(2,5)) +p <- ggplot(res) + aes(x = factor(n), y = rmse_B, fill = factor(method)) + geom_violin() + scale_fill_viridis_d() + theme_bw() + scale_y_log10() + ylim(c(2,5)) p -p <- ggplot(res) + aes(x = factor(n), y = rmse_Omega, fill = factor(method)) + geom_violin() + theme_bw() + scale_y_log10() + ylim(c(0.1,.3)) +p <- ggplot(res) + aes(x = factor(n), y = rmse_Omega, fill = factor(method)) + geom_violin() + scale_fill_viridis_d() + theme_bw() + scale_y_log10() + ylim(c(0.1,.3)) p diff --git a/src/optim_zi-pln.cpp b/src/optim_zi-pln.cpp index b9a5c79a..21b535f2 100644 --- a/src/optim_zi-pln.cpp +++ b/src/optim_zi-pln.cpp @@ -34,7 +34,7 @@ arma::vec zipln_vloglik( + sum( (1 - R) % ( Y % (O + M) - A - logfact_mat(Y) ) + R % mu0 - trunc_log( 1 + exp(mu0) ) - + 0.5 * trunc_log(S2) - 0.5 * ((M_mu * Omega) % M_mu + S2 * diagmat(Omega)) + + 0.5 * trunc_log(S2) - 0.5 * ((M_mu * Omega) % M_mu + S2.each_row() % diagvec(Omega).t()) - R % trunc_log(R) - (1 - R) % trunc_log(1-R), 1) ) ; } @@ -100,14 +100,15 @@ Rcpp::List optim_zipln_zipar_covar( auto optimizer = new_nlopt_optimizer(configuration, parameters.size()); const arma::mat Xt_R = X0.t() * R; + const arma::mat X0t = X0.t(); // Optimize - auto objective_and_grad = [&metadata, &X0, &R, &Xt_R](const double * params, double * grad) -> double { + auto objective_and_grad = [&metadata, &X0, &X0t, &Xt_R](const double * params, double * grad) -> double { const arma::mat B0 = metadata.map(params); arma::mat e_mu0 = exp(X0 * B0); - double objective = -trace(Xt_R.t() * B0) + accu(log(1. + e_mu0)); - metadata.map(grad) = -Xt_R + X0.t() * (e_mu0 % pow(1. + e_mu0, -1)) ; + double objective = -accu(Xt_R % B0) + accu(log(1. + e_mu0)); + metadata.map(grad) = -Xt_R + X0t * (e_mu0 / (1. + e_mu0)) ; return objective; }; OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); @@ -131,7 +132,7 @@ arma::mat optim_zipln_R_var( const arma::mat & B // covariates (n,d) ) { arma::mat A = exp(O + M + 0.5 * S % S); - arma::mat R = pow(1. + exp(- (A + logit(Pi))), -1); + arma::mat R = 1. / (1. + exp(-(A + logit(Pi)))); // Zero R_{i,j} if Y_{i,j} > 0 // multiplication with f(sign(Y)) could work to zero stuff as there should not be any +inf // using a loop as it is more explicit and should have ok performance in C++ @@ -159,7 +160,7 @@ arma::mat optim_zipln_R_exact ( arma::mat M_mu = M - XB; const int n = (int)M.n_rows; const int p = (int)M.n_cols; - arma::vec diag_Sigma = arma::diagvec((1./n) * (M_mu.t() * M_mu + diagmat(sum(S % S, 0)))); + arma::vec diag_Sigma = (sum(M_mu % M_mu, 0) + sum(S % S, 0)).t() / double(n); arma::mat R = arma::zeros(n, p); // lambertW0_CS is pure (no global state) — safe to parallelize #ifdef _OPENMP @@ -206,7 +207,7 @@ Rcpp::List optim_zipln_M( arma::mat A = exp(O_S2 + M); // (n,p) arma::mat M_mu_Omega = (M - X_B) * Omega; // (n,p) - double objective = - trace((1. - R).t() * (Y % M - A)) + 0.5 * trace(M_mu_Omega * (M - X_B).t()); + double objective = - accu((1. - R) % (Y % M - A)) + 0.5 * accu(M_mu_Omega % (M - X_B)); metadata.map(grad) = M_mu_Omega + (1. - R) % (A - Y); return objective; }; @@ -242,14 +243,15 @@ Rcpp::List optim_zipln_S( auto objective_and_grad = [&metadata, &O_M, &R, &diag_Omega](const double * params, double * grad) -> double { const arma::mat S = metadata.map(params); - arma::mat A = exp(O_M + 0.5 * S % S); // (n,p) + const arma::mat S2 = S % S; + arma::mat A = exp(O_M + 0.5 * S2); // (n,p) // trace(1^T log(S)) == accu(log(S)). // S_bar = diag(sum(S, 0)). trace(Omega * S_bar) = dot(diagvec(Omega), sum(S2, 0)) - double objective = trace((1. - R).t() * A) + 0.5 * dot(diag_Omega, sum(S % S, 0)) - 0.5 * accu(log(S % S)); + double objective = accu((1. - R) % A) + 0.5 * dot(diag_Omega, sum(S2, 0)) - 0.5 * accu(log(S2)); // S2^\emptyset interpreted as pow(S2, -1.) as that makes the most sense (gradient component for log(S2)) // 1_n Diag(Omega)^T is n rows of diag(omega) values - metadata.map(grad) = S.each_row() % diag_Omega.t() + (1. - R) % S % A - pow(S, -1.) ; + metadata.map(grad) = S.each_row() % diag_Omega.t() + (1. - R) % S % A - 1. / S ; return objective; }; OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); diff --git a/tests/testthat/test-zipln.R b/tests/testthat/test-zipln.R index fc66250c..8b954951 100644 --- a/tests/testthat/test-zipln.R +++ b/tests/testthat/test-zipln.R @@ -43,7 +43,7 @@ test_that("PLN is working with a single variable data matrix", { }) test_that("PLN is working with unnamed data matrix", { - n = 10; d = 3; p = 10 + n = 15; d = 2; p = 4 Y <- matrix(rpois(n*p, 1), n, p) X <- matrix(rnorm(n*d), n, d) expect_is(ZIPLN(Y ~ X), "ZIPLNfit") From 09cf498bde03ed1d8bb3d49df00b0f13e35eb463 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Mon, 8 Jun 2026 14:15:36 +0200 Subject: [PATCH 04/58] join optim of M and S in ZIPLN --- .Rbuildignore | 1 + R/RcppExports.R | 4 ++++ R/ZIPLNfit-class.R | 32 +++++++++++--------------- src/RcppExports.cpp | 20 ++++++++++++++++ src/optim_zi-pln.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 19 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index fbb80fe9..d70d1c95 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -35,3 +35,4 @@ ^CRAN-SUBMISSION$ ^AUTHORS$ ^dev$ +^\.claude$ diff --git a/R/RcppExports.R b/R/RcppExports.R index 6213a68b..cd70bd2d 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -85,6 +85,10 @@ optim_zipln_S <- function(init_S, O, M, R, B, diag_Omega, configuration) { .Call('_PLNmodels_optim_zipln_S', PACKAGE = 'PLNmodels', init_S, O, M, R, B, diag_Omega, configuration) } +optim_zipln_M_S <- function(init_M, init_S, Y, X, O, R, B, Omega, configuration) { + .Call('_PLNmodels_optim_zipln_M_S', PACKAGE = 'PLNmodels', init_M, init_S, Y, X, O, R, B, Omega, configuration) +} + cpp_test_packing <- function() { .Call('_PLNmodels_cpp_test_packing', PACKAGE = 'PLNmodels') } diff --git a/R/ZIPLNfit-class.R b/R/ZIPLNfit-class.R index 8b828a5f..84fa3038 100644 --- a/R/ZIPLNfit-class.R +++ b/R/ZIPLNfit-class.R @@ -188,17 +188,14 @@ ZIPLNfit <- R6Class( # ZI part new_R <- private$optimizer$R(Y = data$Y, X = data$X, O = data$O, M = parameters$M, S = parameters$S, Pi = new_Pi, B = new_B) - # PLN part - new_M <- optim_zipln_M( - init_M = parameters$M, - Y = data$Y, X = data$X, O = data$O, R = new_R, S = parameters$S, B = new_B, Omega = new_Omega, - configuration = control - )$M - new_S <- optim_zipln_S( - init_S = parameters$S, - O = data$O, M = new_M, R = new_R, B = new_B, diag_Omega = diag(new_Omega), + # PLN part: joint optimization of M and S + MS_out <- optim_zipln_M_S( + init_M = parameters$M, init_S = parameters$S, + Y = data$Y, X = data$X, O = data$O, R = new_R, B = new_B, Omega = new_Omega, configuration = control - )$S + ) + new_M <- MS_out$M + new_S <- MS_out$S # Check convergence new_parameters <- list( @@ -310,16 +307,13 @@ ZIPLNfit <- R6Class( new_R <- private$optimizer$R( Y = data$Y, X = data$X, O = data$O, M = parameters$M, S = parameters$S, Pi = Pi, B = B ) - new_M <- optim_zipln_M( - init_M = parameters$M, - Y = data$Y, X = data$X, O = data$O, R = new_R, S = parameters$S, B = B, Omega = Omega, + MS_out <- optim_zipln_M_S( + init_M = parameters$M, init_S = parameters$S, + Y = data$Y, X = data$X, O = data$O, R = new_R, B = B, Omega = Omega, configuration = control - )$M - new_S <- optim_zipln_S( - init_S = parameters$S, - O = data$O, M = new_M, R = new_R, B = B, diag_Omega = diag(Omega), - configuration = control - )$S + ) + new_M <- MS_out$M + new_S <- MS_out$S # Check convergence new_parameters <- list(R = new_R, M = new_M, S = new_S) nb_iter <- nb_iter + 1 diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 07502dfa..c67cca46 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -320,6 +320,25 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// optim_zipln_M_S +Rcpp::List optim_zipln_M_S(const arma::mat& init_M, const arma::mat& init_S, const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& R, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& configuration); +RcppExport SEXP _PLNmodels_optim_zipln_M_S(SEXP init_MSEXP, SEXP init_SSEXP, SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP RSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configurationSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const arma::mat& >::type init_M(init_MSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type init_S(init_SSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Y(YSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type O(OSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type R(RSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type configuration(configurationSEXP); + rcpp_result_gen = Rcpp::wrap(optim_zipln_M_S(init_M, init_S, Y, X, O, R, B, Omega, configuration)); + return rcpp_result_gen; +END_RCPP +} // cpp_test_packing bool cpp_test_packing(); RcppExport SEXP _PLNmodels_cpp_test_packing() { @@ -369,6 +388,7 @@ static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_optim_zipln_R_exact", (DL_FUNC) &_PLNmodels_optim_zipln_R_exact, 7}, {"_PLNmodels_optim_zipln_M", (DL_FUNC) &_PLNmodels_optim_zipln_M, 9}, {"_PLNmodels_optim_zipln_S", (DL_FUNC) &_PLNmodels_optim_zipln_S, 7}, + {"_PLNmodels_optim_zipln_M_S", (DL_FUNC) &_PLNmodels_optim_zipln_M_S, 9}, {"_PLNmodels_cpp_test_packing", (DL_FUNC) &_PLNmodels_cpp_test_packing, 0}, {"_PLNmodels_get_sandwich_variance_B", (DL_FUNC) &_PLNmodels_get_sandwich_variance_B, 6}, {NULL, NULL, 0} diff --git a/src/optim_zi-pln.cpp b/src/optim_zi-pln.cpp index 21b535f2..3e1c7512 100644 --- a/src/optim_zi-pln.cpp +++ b/src/optim_zi-pln.cpp @@ -262,3 +262,58 @@ Rcpp::List optim_zipln_S( Rcpp::Named("iterations") = result.nb_iterations, Rcpp::Named("S") = S); } + +// [[Rcpp::export]] +Rcpp::List optim_zipln_M_S( + const arma::mat & init_M, // (n,p) + const arma::mat & init_S, // (n,p) + const arma::mat & Y, // responses (n,p) + const arma::mat & X, // covariates (n,d) + const arma::mat & O, // offsets (n,p) + const arma::mat & R, // (n,p) + const arma::mat & B, // (d,p) + const arma::mat & Omega, // (p,p) + const Rcpp::List & configuration +) { + const auto metadata = tuple_metadata(init_M, init_S); + enum { M_ID, S_ID }; + + auto parameters = std::vector(metadata.packed_size); + metadata.map(parameters.data()) = init_M; + metadata.map(parameters.data()) = init_S; + + auto optimizer = new_nlopt_optimizer(configuration, parameters.size()); + const arma::mat X_B = X * B; + const arma::vec diag_Omega = diagvec(Omega); + + auto objective_and_grad = [&metadata, &Y, &O, &R, &X_B, &Omega, &diag_Omega]( + const double * params, double * grad) -> double { + const arma::mat M = metadata.map(params); + const arma::mat S = metadata.map(params); + const arma::mat S2 = S % S; + const arma::mat A = exp(O + M + 0.5 * S2); + const arma::mat M_mu = M - X_B; + const arma::mat M_mu_Omega = M_mu * Omega; + + double objective = - accu((1. - R) % (Y % M - A)) + + 0.5 * accu(M_mu_Omega % M_mu) + + 0.5 * dot(diag_Omega, sum(S2, 0)) + - 0.5 * accu(log(S2)); + + metadata.map(grad) = M_mu_Omega + (1. - R) % (A - Y); + metadata.map(grad) = S.each_row() % diag_Omega.t() + (1. - R) % S % A - 1. / S; + + return objective; + }; + + OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); + + arma::mat M = metadata.copy(parameters.data()); + arma::mat S = metadata.copy(parameters.data()); + return Rcpp::List::create( + Rcpp::Named("status") = static_cast(result.status), + Rcpp::Named("iterations") = result.nb_iterations, + Rcpp::Named("M") = M, + Rcpp::Named("S") = S + ); +} From 726bf27033a5d63a308628d7e4b1457327be9608 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Mon, 8 Jun 2026 18:16:36 +0200 Subject: [PATCH 05/58] =?UTF-8?q?feat:=20coordonn=C3=A9e=20Newton=20diagon?= =?UTF-8?q?al=20pour=20PLN=20et=20ZIPLN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajoute un optimiseur Newton diagonal coordonné (sans NLopt) pour les modèles PLN standard et ZIPLN, activable via PLN_param(config_optim = list(algorithm = "NEWTON")) ZIPLN_param(config_optim = list(algorithm = "NEWTON")) PLN (`nlopt_optimize_newton`, `nlopt_optimize_vestep_newton`) : - Newton diagonal pour B et M avec backtracking Armijo - Fixed-point exact pour logS : logS* = -0.5 log(Omega_jj + A_ij) - Guard overflow élément par élément : logS <= 0.5 log(max(1, 700-Z)) - Gains sur oaks : +38 loglik, 36% plus rapide que CCSAQ ZIPLN (`optim_zipln_M_S_newton`) : - Même approche, hessien diagonal ajusté pour le masque ZI - Défaut : CCSAQ conservé (Newton donne de mauvais optima locaux sur données très sparse) - Guard de covariance "covar" : substitue CCSAQ avant d'appeler NLopt Co-Authored-By: Claude Sonnet 4.6 --- R/PLNfit-class.R | 11 +- R/RcppExports.R | 16 +++ R/ZIPLN.R | 14 ++- R/ZIPLNfit-class.R | 17 ++- R/utils.R | 2 +- src/RcppExports.cpp | 71 +++++++++++ src/optim_full_cov.cpp | 270 +++++++++++++++++++++++++++++++++++++++++ src/optim_zi-pln.cpp | 171 ++++++++++++++++++++++++++ 8 files changed, 560 insertions(+), 12 deletions(-) diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index cf2817b4..08437ce8 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -360,8 +360,15 @@ PLNfit <- R6Class( private$M <- start_point$M private$S <- start_point$S } - private$optimizer$main <- ifelse(control$backend == "nlopt", nlopt_optimize, private$torch_optimize) - private$optimizer$vestep <- nlopt_optimize_vestep + is_newton <- identical(control$config_optim$algorithm, "NEWTON") + private$optimizer$main <- if (control$backend == "torch") { + private$torch_optimize + } else if (is_newton) { + nlopt_optimize_newton + } else { + nlopt_optimize + } + private$optimizer$vestep <- if (is_newton) nlopt_optimize_vestep_newton else nlopt_optimize_vestep }, ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/R/RcppExports.R b/R/RcppExports.R index cd70bd2d..0d636578 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -21,6 +21,14 @@ nlopt_optimize <- function(data, params, config) { .Call('_PLNmodels_nlopt_optimize', PACKAGE = 'PLNmodels', data, params, config) } +nlopt_optimize_newton <- function(data, params, config) { + .Call('_PLNmodels_nlopt_optimize_newton', PACKAGE = 'PLNmodels', data, params, config) +} + +nlopt_optimize_vestep_newton <- function(data, params, B, Omega, config) { + .Call('_PLNmodels_nlopt_optimize_vestep_newton', PACKAGE = 'PLNmodels', data, params, B, Omega, config) +} + nlopt_optimize_vestep <- function(data, params, B, Omega, config) { .Call('_PLNmodels_nlopt_optimize_vestep', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } @@ -89,6 +97,14 @@ optim_zipln_M_S <- function(init_M, init_S, Y, X, O, R, B, Omega, configuration) .Call('_PLNmodels_optim_zipln_M_S', PACKAGE = 'PLNmodels', init_M, init_S, Y, X, O, R, B, Omega, configuration) } +optim_zipln_M_logS <- function(init_M, init_S, Y, X, O, R, B, Omega, configuration) { + .Call('_PLNmodels_optim_zipln_M_logS', PACKAGE = 'PLNmodels', init_M, init_S, Y, X, O, R, B, Omega, configuration) +} + +optim_zipln_M_S_newton <- function(init_M, init_S, Y, X, O, R, B, Omega, maxiter, ftol_rel) { + .Call('_PLNmodels_optim_zipln_M_S_newton', PACKAGE = 'PLNmodels', init_M, init_S, Y, X, O, R, B, Omega, maxiter, ftol_rel) +} + cpp_test_packing <- function() { .Call('_PLNmodels_cpp_test_packing', PACKAGE = 'PLNmodels') } diff --git a/R/ZIPLN.R b/R/ZIPLN.R index 1e50b646..d7027f0f 100644 --- a/R/ZIPLN.R +++ b/R/ZIPLN.R @@ -74,7 +74,7 @@ ZIPLN <- function(formula, data, subset, zi = c("single", "row", "col"), control #' @inherit PLN_param details #' @details See [PLN_param()] and [PLNnetwork_param()] for a full description of the generic optimization parameters. Like [PLNnetwork_param()], ZIPLN_param() has two parameters controlling the optimization due the inner-outer loop structure of the optimizer: #' * "ftol_out" outer solver stops when an optimization step changes the objective function by less than `ftol_out` multiplied by the absolute value of the parameter. Default is 1e-6 -#' * "maxit_out" outer solver stops when the number of iteration exceeds `maxit_out`. Default is 100 +#' * "maxit_out" outer solver stops when the number of iteration exceeds `maxit_out`. Default is 100 (200 for NEWTON) #' and one additional parameter controlling the form of the variational approximation of the zero inflation: #' * "approx_ZI" either uses an exact or approximated conditional distribution for the zero inflation. Default is FALSE #' @@ -106,12 +106,14 @@ ZIPLN_param <- function( ## optimization config stopifnot(backend %in% c("nlopt")) - stopifnot(config_optim$algorithm %in% available_algorithms_nlopt) + algo_req <- if (!is.null(config_optim$algorithm)) config_optim$algorithm else "CCSAQ" + stopifnot(algo_req %in% available_algorithms_nlopt) config_opt <- config_default_nlopt - config_opt$trace <- trace - config_opt$ftol_out <- 1e-6 - config_opt$maxit_out <- 100 - config_opt$approx_ZI <- TRUE + config_opt$algorithm <- algo_req + config_opt$trace <- trace + config_opt$ftol_out <- 1e-6 + config_opt$approx_ZI <- TRUE + config_opt$maxit_out <- if (algo_req == "NEWTON") 200L else 100L config_opt[names(config_optim)] <- config_optim structure(list( diff --git a/R/ZIPLNfit-class.R b/R/ZIPLNfit-class.R index 84fa3038..6721ccde 100644 --- a/R/ZIPLNfit-class.R +++ b/R/ZIPLNfit-class.R @@ -138,10 +138,21 @@ ZIPLNfit <- R6Class( "single" = function(R, ...) list(Pi = matrix( mean(R), nrow(R), p) , B0 = matrix(NA, d0, p)), "row" = function(R, ...) list(Pi = matrix(rowMeans(R), nrow(R), p) , B0 = matrix(NA, d0, p)), "col" = function(R, ...) list(Pi = matrix(colMeans(R), nrow(R), p, byrow = TRUE), B0 = matrix(NA, d0, p)), - "covar" = optim_zipln_zipar_covar + "covar" = function(R, init_B0, X0, config) { + if (identical(config$algorithm, "NEWTON")) config$algorithm <- "CCSAQ" + optim_zipln_zipar_covar(R, init_B0, X0, config) + } ) private$optimizer$R <- ifelse(control$config_optim$approx_ZI, optim_zipln_R_var, optim_zipln_R_exact) private$optimizer$Omega <- optim_zipln_Omega_full + private$optimizer$MS <- if (identical(control$config_optim$algorithm, "NEWTON")) { + ftol <- if (!is.null(control$config_optim$ftol_rel)) control$config_optim$ftol_rel else 1e-8 + maxiter <- as.integer(if (!is.null(control$config_optim$maxeval)) control$config_optim$maxeval else 200L) + function(init_M, init_S, Y, X, O, R, B, Omega, configuration) + optim_zipln_M_S_newton(init_M, init_S, Y, X, O, R, B, Omega, maxiter, ftol) + } else { + optim_zipln_M_S + } }, @@ -189,7 +200,7 @@ ZIPLNfit <- R6Class( new_R <- private$optimizer$R(Y = data$Y, X = data$X, O = data$O, M = parameters$M, S = parameters$S, Pi = new_Pi, B = new_B) # PLN part: joint optimization of M and S - MS_out <- optim_zipln_M_S( + MS_out <- private$optimizer$MS( init_M = parameters$M, init_S = parameters$S, Y = data$Y, X = data$X, O = data$O, R = new_R, B = new_B, Omega = new_Omega, configuration = control @@ -307,7 +318,7 @@ ZIPLNfit <- R6Class( new_R <- private$optimizer$R( Y = data$Y, X = data$X, O = data$O, M = parameters$M, S = parameters$S, Pi = Pi, B = B ) - MS_out <- optim_zipln_M_S( + MS_out <- private$optimizer$MS( init_M = parameters$M, init_S = parameters$S, Y = data$Y, X = data$X, O = data$O, R = new_R, B = B, Omega = Omega, configuration = control diff --git a/R/utils.R b/R/utils.R index c36a44d0..805548c7 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,4 +1,4 @@ -available_algorithms_nlopt <- c("MMA", "CCSAQ", "LBFGS", "VAR1", "VAR2") #"TNEWTON", "TNEWTON_PRECOND", "TNEWTON_PRECOND_RESTART"# +available_algorithms_nlopt <- c("MMA", "CCSAQ", "LBFGS", "VAR1", "VAR2", "NEWTON") #"TNEWTON", "TNEWTON_PRECOND", "TNEWTON_PRECOND_RESTART"# available_algorithms_torch <- c("RPROP", "RMSPROP", "ADAM", "ADAGRAD") config_default_nlopt <- diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index c67cca46..b4a0e823 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -75,6 +75,34 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// nlopt_optimize_newton +Rcpp::List nlopt_optimize_newton(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_newton(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_newton(data, params, config)); + return rcpp_result_gen; +END_RCPP +} +// nlopt_optimize_vestep_newton +Rcpp::List nlopt_optimize_vestep_newton(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_newton(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_vestep_newton(data, params, B, Omega, config)); + return rcpp_result_gen; +END_RCPP +} // nlopt_optimize_vestep Rcpp::List nlopt_optimize_vestep(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_nlopt_optimize_vestep(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -339,6 +367,45 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// optim_zipln_M_logS +Rcpp::List optim_zipln_M_logS(const arma::mat& init_M, const arma::mat& init_S, const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& R, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& configuration); +RcppExport SEXP _PLNmodels_optim_zipln_M_logS(SEXP init_MSEXP, SEXP init_SSEXP, SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP RSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configurationSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const arma::mat& >::type init_M(init_MSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type init_S(init_SSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Y(YSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type O(OSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type R(RSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type configuration(configurationSEXP); + rcpp_result_gen = Rcpp::wrap(optim_zipln_M_logS(init_M, init_S, Y, X, O, R, B, Omega, configuration)); + return rcpp_result_gen; +END_RCPP +} +// optim_zipln_M_S_newton +Rcpp::List optim_zipln_M_S_newton(const arma::mat& init_M, const arma::mat& init_S, const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& R, const arma::mat& B, const arma::mat& Omega, const int maxiter, const double ftol_rel); +RcppExport SEXP _PLNmodels_optim_zipln_M_S_newton(SEXP init_MSEXP, SEXP init_SSEXP, SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP RSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP maxiterSEXP, SEXP ftol_relSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const arma::mat& >::type init_M(init_MSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type init_S(init_SSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Y(YSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type O(OSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type R(RSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); + Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); + Rcpp::traits::input_parameter< const double >::type ftol_rel(ftol_relSEXP); + rcpp_result_gen = Rcpp::wrap(optim_zipln_M_S_newton(init_M, init_S, Y, X, O, R, B, Omega, maxiter, ftol_rel)); + return rcpp_result_gen; +END_RCPP +} // cpp_test_packing bool cpp_test_packing(); RcppExport SEXP _PLNmodels_cpp_test_packing() { @@ -372,6 +439,8 @@ static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_nlopt_optimize_vestep_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_diagonal, 5}, {"_PLNmodels_nlopt_optimize_fixed", (DL_FUNC) &_PLNmodels_nlopt_optimize_fixed, 3}, {"_PLNmodels_nlopt_optimize", (DL_FUNC) &_PLNmodels_nlopt_optimize, 3}, + {"_PLNmodels_nlopt_optimize_newton", (DL_FUNC) &_PLNmodels_nlopt_optimize_newton, 3}, + {"_PLNmodels_nlopt_optimize_vestep_newton", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_newton, 5}, {"_PLNmodels_nlopt_optimize_vestep", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep, 5}, {"_PLNmodels_nlopt_optimize_genetic_modeling", (DL_FUNC) &_PLNmodels_nlopt_optimize_genetic_modeling, 7}, {"_PLNmodels_nlopt_optimize_rank", (DL_FUNC) &_PLNmodels_nlopt_optimize_rank, 3}, @@ -389,6 +458,8 @@ static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_optim_zipln_M", (DL_FUNC) &_PLNmodels_optim_zipln_M, 9}, {"_PLNmodels_optim_zipln_S", (DL_FUNC) &_PLNmodels_optim_zipln_S, 7}, {"_PLNmodels_optim_zipln_M_S", (DL_FUNC) &_PLNmodels_optim_zipln_M_S, 9}, + {"_PLNmodels_optim_zipln_M_logS", (DL_FUNC) &_PLNmodels_optim_zipln_M_logS, 9}, + {"_PLNmodels_optim_zipln_M_S_newton", (DL_FUNC) &_PLNmodels_optim_zipln_M_S_newton, 10}, {"_PLNmodels_cpp_test_packing", (DL_FUNC) &_PLNmodels_cpp_test_packing, 0}, {"_PLNmodels_get_sandwich_variance_B", (DL_FUNC) &_PLNmodels_get_sandwich_variance_B, 6}, {NULL, NULL, 0} diff --git a/src/optim_full_cov.cpp b/src/optim_full_cov.cpp index 1093fa7d..1bdb796d 100644 --- a/src/optim_full_cov.cpp +++ b/src/optim_full_cov.cpp @@ -134,6 +134,276 @@ Rcpp::List nlopt_optimize( ); } +// --------------------------------------------------------------------------------------- +// Full covariance PLN — coordinate-Newton optimizer + +// [[Rcpp::export]] +Rcpp::List nlopt_optimize_newton( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(B, M, S) + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); // (n,p) + const arma::mat & X = Rcpp::as(data["X"]); // (n,d) + const arma::mat & O = Rcpp::as(data["O"]); // (n,p) + const arma::vec & w = Rcpp::as(data["w"]); // (n) + arma::mat B = Rcpp::as(params["B"]); // (d,p) + arma::mat M = Rcpp::as(params["M"]); // (n,p) + arma::mat S = Rcpp::as(params["S"]); // (n,p), >0 + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; + const double em_tol= config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + + const int n = Y.n_rows; + const double w_bar = arma::accu(w); + const double c1 = 1e-4; + + // Precompute weighted X matrices (fixed throughout) + const arma::mat Xw = X.each_col() % w; // (n,d) X_ik * w_i + arma::mat Xw2 = X % X; Xw2.each_col() %= w; // (n,d) X_ik^2 * w_i + + // Initial Omega from starting M, S + arma::mat S2 = S % S; + arma::mat Sigma = (1./w_bar) * (M.t() * (M.each_col() % w) + arma::diagmat(w.t() * S2)); + arma::mat Omega = arma::inv_sympd(Sigma); + arma::mat logS = arma::log(S); + + std::vector objective_vec; + double elbo_prev = -arma::datum::inf; + int total_iter = 0; + int last_status = 5; // maxiter reached by default + + for (int em = 0; em < max_em; em++) { + const arma::vec diag_Omega = arma::diagvec(Omega); + const arma::mat ones_row = arma::ones(n, 1); + + double obj_prev = arma::datum::inf; + + for (int it = 0; it < maxiter; it++) { + S2 = S % S; + arma::mat Z = O + X * B + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + + // ---- Diagonal Newton step for B ---- + arma::mat grad_B = Xw.t() * (A - Y); // (d,p) + arma::mat hess_B = Xw2.t() * A; // (d,p), >0 + hess_B.clamp(1e-10, arma::datum::inf); + arma::mat step_B = grad_B / hess_B; + arma::mat XstepB = X * step_B; // (n,p) + double f0_B = arma::accu(w.t() * (A - Y % Z)); + double slope_B = -arma::accu(grad_B % step_B); + double alpha_B = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Zt = Z - alpha_B * XstepB; + if (arma::accu(w.t() * (arma::exp(Zt + 0.5*S2) - Y % Zt)) + <= f0_B + c1 * alpha_B * slope_B) break; + alpha_B *= 0.5; + } + B -= alpha_B * step_B; + Z = O + X * B + M; + A = arma::exp(Z + 0.5 * S2); + + // ---- Diagonal Newton step for M ---- + arma::mat MO = M * Omega; // (n,p) + arma::mat grad_M = MO + A - Y; grad_M.each_col() %= w; // (n,p) + arma::mat hess_M = A + ones_row * diag_Omega.t(); + hess_M.each_col() %= w; + hess_M.clamp(1e-10, arma::datum::inf); + arma::mat step_M = grad_M / hess_M; + double f0_M = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * arma::accu(MO % (M.each_col() % w)); + double slope_M = -arma::accu(grad_M % step_M); + double alpha_M = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Mt = M - alpha_M * step_M; + arma::mat Zt = Z - alpha_M * step_M; + arma::mat At = arma::exp(Zt + 0.5 * S2); + arma::mat MOt = Mt * Omega; + if (arma::accu(w.t() * (At - Y % Zt)) + + 0.5 * arma::accu(MOt % (Mt.each_col() % w)) + <= f0_M + c1 * alpha_M * slope_M) break; + alpha_M *= 0.5; + } + M -= alpha_M * step_M; + MO = M * Omega; + Z = O + X * B + M; + + // ---- Fixed-point update for logS (overflow-safe) ---- + A = arma::exp(Z + 0.5 * S2); + { + const arma::mat logS_cand = -0.5 * arma::log(A + ones_row * diag_Omega.t()); + const arma::mat logS_ub = 0.5 * arma::log( + arma::clamp(700. - Z, 1., arma::datum::inf)); + logS = arma::clamp(arma::min(logS_cand, logS_ub), -20., arma::datum::inf); + } + S = arma::exp(logS); + S2 = S % S; + + // ---- Objective for inner convergence ---- + A = arma::exp(Z + 0.5 * S2); + double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) + + 0.5 * (arma::accu(MO % (M.each_col() % w)) + + arma::dot(diag_Omega, (w.t() * S2).t())); + objective_vec.push_back(obj); + total_iter++; + + if (it > 0 && std::abs(obj - obj_prev) < ftol * (1.0 + std::abs(obj_prev))) { + last_status = 3; break; + } + obj_prev = obj; + } + + // ---- M-step: update Omega analytically ---- + S2 = S % S; + Sigma = (1./w_bar) * (M.t() * (M.each_col() % w) + arma::diagmat(w.t() * S2)); + Omega = arma::inv_sympd(Sigma); + + // ---- Outer EM convergence on ELBO ---- + arma::mat Z = O + X * B + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * arma::trunc_log(S2))) + - 0.5 * w_bar * real(arma::log_det(Sigma)); + if (em > 0 && std::abs(elbo - elbo_prev) < em_tol * (1.0 + std::abs(elbo_prev))) { + last_status = 3; break; + } + elbo_prev = elbo; + } + + // ---- Final output ---- + S2 = S % S; + arma::mat Z = O + X * B + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + arma::vec loglik = arma::sum(Y % Z - A + 0.5 * arma::log(S2) + - 0.5 * ((M * Omega) % M + S2 * arma::diagmat(Omega)), 1) + + 0.5 * real(arma::log_det(Omega)) + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("B", B ), + Rcpp::Named("M", M ), + Rcpp::Named("S", S ), + Rcpp::Named("Z", Z ), + Rcpp::Named("A", A ), + Rcpp::Named("Sigma", Sigma), + Rcpp::Named("Omega", Omega), + Rcpp::Named("Ji", Ji ), + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", last_status ), + Rcpp::Named("backend", "newton" ), + Rcpp::Named("objective", objective_vec ), + Rcpp::Named("iterations", total_iter ) + )) + ); +} + +// --------------------------------------------------------------------------------------- +// VE full — coordinate-Newton (M and S only, B and Omega fixed) + +// [[Rcpp::export]] +Rcpp::List nlopt_optimize_vestep_newton( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(M, S) + const arma::mat & B, // (d,p) fixed + const arma::mat & Omega, // (p,p) fixed + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + + const int n = Y.n_rows; + const double c1 = 1e-4; + const arma::vec diag_Omega = arma::diagvec(Omega); + const arma::mat ones_row = arma::ones(n, 1); + const arma::mat XB = X * B; + + arma::mat logS = arma::log(S); + arma::mat S2 = S % S; + + std::vector objective_vec; + double obj_prev = arma::datum::inf; + int total_iter = 0; + + for (int it = 0; it < maxiter; it++) { + S2 = S % S; + arma::mat Z = O + XB + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + + // ---- Diagonal Newton step for M ---- + arma::mat MO = M * Omega; + arma::mat grad_M = MO + A - Y; grad_M.each_col() %= w; + arma::mat hess_M = A + ones_row * diag_Omega.t(); + hess_M.each_col() %= w; + hess_M.clamp(1e-10, arma::datum::inf); + arma::mat step_M = grad_M / hess_M; + double f0_M = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * arma::accu(MO % (M.each_col() % w)); + double slope_M = -arma::accu(grad_M % step_M); + double alpha_M = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Mt = M - alpha_M * step_M; + arma::mat Zt = Z - alpha_M * step_M; + arma::mat At = arma::exp(Zt + 0.5 * S2); + arma::mat MOt = Mt * Omega; + if (arma::accu(w.t() * (At - Y % Zt)) + + 0.5 * arma::accu(MOt % (Mt.each_col() % w)) + <= f0_M + c1 * alpha_M * slope_M) break; + alpha_M *= 0.5; + } + M -= alpha_M * step_M; + MO = M * Omega; + Z = O + XB + M; + + // ---- Fixed-point update for logS ---- + A = arma::exp(Z + 0.5 * S2); + logS = arma::clamp(-0.5 * arma::log(A + ones_row * diag_Omega.t()), -20., 10.); + S = arma::exp(logS); + S2 = S % S; + + // ---- Objective for convergence check ---- + A = arma::exp(Z + 0.5 * S2); + double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) + + 0.5 * (arma::accu(MO % (M.each_col() % w)) + + arma::dot(diag_Omega, (w.t() * S2).t())); + objective_vec.push_back(obj); + total_iter++; + + if (it > 0 && std::abs(obj - obj_prev) < ftol * (1.0 + std::abs(obj_prev))) break; + obj_prev = obj; + } + + // ---- Final output ---- + S2 = S % S; + arma::mat Z = O + XB + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + arma::vec loglik = arma::sum(Y % Z - A + 0.5 * arma::log(S2) + - 0.5 * ((M * Omega) % M + S2 * arma::diagmat(Omega)), 1) + + 0.5 * real(arma::log_det(Omega)) + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("M") = M, + Rcpp::Named("S") = S, + Rcpp::Named("Ji") = Ji, + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", 3 ), + Rcpp::Named("backend", "newton" ), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", total_iter ) + )) + ); +} + // --------------------------------------------------------------------------------------- // VE full diff --git a/src/optim_zi-pln.cpp b/src/optim_zi-pln.cpp index 3e1c7512..73dd1312 100644 --- a/src/optim_zi-pln.cpp +++ b/src/optim_zi-pln.cpp @@ -317,3 +317,174 @@ Rcpp::List optim_zipln_M_S( Rcpp::Named("S") = S ); } + +// --------------------------------------------------------------------------------------- +// Joint optimization of (M, logS) — reparametrize S = exp(logS) to make the problem +// unconstrained, enabling quasi-Newton methods (LBFGS) that diverge in the S domain. +// +// Gradient w.r.t. logS_ij = S_ij * grad_S_ij +// = S²_ij * (diag_Omega_j + (1-R_ij)*A_ij) - 1 +// Hessian diagonal (exact, S decoupled): +// = 2*S²_ij * (diag_Omega_j + (1-R_ij)*A_ij*(1 + S²_ij)) > 0 +// This makes the problem globally unconstrained with positive-definite diagonal Hessian in logS. + +// [[Rcpp::export]] +Rcpp::List optim_zipln_M_logS( + const arma::mat & init_M, // (n,p) + const arma::mat & init_S, // (n,p) — converted to logS internally + const arma::mat & Y, // (n,p) + const arma::mat & X, // (n,d) + const arma::mat & O, // (n,p) + const arma::mat & R, // (n,p) + const arma::mat & B, // (d,p) + const arma::mat & Omega, // (p,p) + const Rcpp::List & configuration +) { + const arma::mat logS_init = arma::log(init_S); + + const auto metadata = tuple_metadata(init_M, logS_init); + enum { M_ID, logS_ID }; + + auto parameters = std::vector(metadata.packed_size); + metadata.map (parameters.data()) = init_M; + metadata.map(parameters.data()) = logS_init; + + auto optimizer = new_nlopt_optimizer(configuration, parameters.size()); + const arma::mat X_B = X * B; + const arma::vec diag_Omega = diagvec(Omega); + + auto objective_and_grad = [&metadata, &Y, &O, &R, &X_B, &Omega, &diag_Omega]( + const double * params, double * grad) -> double { + const arma::mat M = metadata.map (params); + const arma::mat logS = metadata.map(params); + const arma::mat S2 = arma::exp(2. * logS); + const arma::mat A = arma::exp(O + M + 0.5 * S2); + const arma::mat M_mu = M - X_B; + const arma::mat M_mu_Omega = M_mu * Omega; + + double objective = - accu((1. - R) % (Y % M - A)) + + 0.5 * accu(M_mu_Omega % M_mu) + + 0.5 * dot(diag_Omega, sum(S2, 0)) + - accu(logS); // = -0.5*accu(log(S²)) + + metadata.map (grad) = M_mu_Omega + (1. - R) % (A - Y); + // grad_logS_ij = S²_ij * (diag_Omega_j + (1-R_ij)*A_ij) - 1 + metadata.map(grad) = S2 % ((1. - R) % A + arma::ones(A.n_rows, 1) * diag_Omega.t()) - 1.; + + return objective; + }; + + OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); + + arma::mat M = metadata.copy (parameters.data()); + arma::mat logS = metadata.copy(parameters.data()); + return Rcpp::List::create( + Rcpp::Named("status") = static_cast(result.status), + Rcpp::Named("iterations") = result.nb_iterations, + Rcpp::Named("M") = M, + Rcpp::Named("S") = arma::exp(logS) + ); +} + +// --------------------------------------------------------------------------------------- +// Custom coordinate-Newton optimizer for (M, logS) — no NLopt dependency. +// +// Per iteration: +// 1. Diagonal Newton step for M with Armijo backtracking (one M*Omega product) +// 2. Exact closed-form update for logS: logS* = -0.5*log(diag_Omega + (1-R)*A) +// This is the exact minimiser of f w.r.t. S for fixed M and A (before S feeds back +// into A). Stable by construction; no step-size issue. +// +// Cost per iteration ≈ 2 × O(n*p²) gradient evaluations — same arithmetic as CCSAQ +// but with much better step quality: typically 5-15 iterations vs 50-100 for CCSAQ. + +// [[Rcpp::export]] +Rcpp::List optim_zipln_M_S_newton( + const arma::mat & init_M, // (n,p) + const arma::mat & init_S, // (n,p) + const arma::mat & Y, // (n,p) + const arma::mat & X, // (n,d) + const arma::mat & O, // (n,p) + const arma::mat & R, // (n,p) + const arma::mat & B, // (d,p) + const arma::mat & Omega, // (p,p) + const int maxiter, // max coordinate steps + const double ftol_rel // relative objective convergence threshold +) { + const arma::mat X_B = X * B; + const arma::vec diag_Omega = diagvec(Omega); + const arma::mat ones_col = arma::ones(init_M.n_rows, 1); + + arma::mat M = init_M; + arma::mat logS = arma::log(init_S); + + // Helper: full objective value (for convergence check and Armijo) + auto objective = [&](const arma::mat & M_, const arma::mat & logS_) -> double { + const arma::mat S2_ = arma::exp(2. * logS_); + const arma::mat A_ = arma::exp(O + M_ + 0.5 * S2_); + const arma::mat M_mu_ = M_ - X_B; + return - accu((1. - R) % (Y % M_ - A_)) + + 0.5 * accu((M_mu_ * Omega) % M_mu_) + + 0.5 * dot(diag_Omega, sum(S2_, 0)) + - accu(logS_); + }; + + double obj_prev = objective(M, logS); + int iter = 0; + + for (iter = 0; iter < maxiter; iter++) { + // ---------------------------------------------------------------- + // Step 1 — diagonal Newton on M with Armijo backtracking + // ---------------------------------------------------------------- + { + const arma::mat S2 = arma::exp(2. * logS); + const arma::mat A = arma::exp(O + M + 0.5 * S2); + const arma::mat M_mu_Omega = (M - X_B) * Omega; + const arma::mat grad_M = M_mu_Omega + (1. - R) % (A - Y); + const arma::mat hess_M = (1. - R) % A + ones_col * diag_Omega.t(); + const arma::mat step_M = grad_M / hess_M; // Newton direction (descent) + + // Armijo backtracking: f(M - alpha*step) <= f(M) - c1*alpha*||step||²_H + double alpha = 1.0; + const double c1 = 1e-4; + const double slope = - accu(grad_M % step_M); // ≤ 0 + for (int ls = 0; ls < 20; ++ls) { + if (objective(M - alpha * step_M, logS) <= obj_prev + c1 * alpha * slope) + break; + alpha *= 0.5; + } + M -= alpha * step_M; + } + + // ---------------------------------------------------------------- + // Step 2 — exact closed-form update for logS (fixed-point step) + // logS* = -0.5 * log( diag_Omega + (1-R)*A ) + // Per-element upper bound prevents exp(Z + 0.5*S²) from overflowing: + // keep Z + 0.5*S² ≤ 700 => logS ≤ 0.5*log(max(1, 700-Z)) + // ---------------------------------------------------------------- + { + const arma::mat S2 = arma::exp(2. * logS); + const arma::mat Z_cur = O + X_B + M; + const arma::mat A = arma::exp(Z_cur + 0.5 * S2); + const arma::mat base = (1. - R) % A + ones_col * diag_Omega.t(); + const arma::mat logS_cand = -0.5 * arma::log(base); + const arma::mat logS_ub = 0.5 * arma::log( + arma::clamp(700. - Z_cur, 1., arma::datum::inf)); + logS = arma::clamp(arma::min(logS_cand, logS_ub), -20., arma::datum::inf); + } + + // ---------------------------------------------------------------- + // Convergence check + // ---------------------------------------------------------------- + const double obj = objective(M, logS); + if (iter > 0 && std::abs(obj - obj_prev) < ftol_rel * (1. + std::abs(obj_prev))) break; + obj_prev = obj; + } + + return Rcpp::List::create( + Rcpp::Named("status") = 3, + Rcpp::Named("iterations") = iter, + Rcpp::Named("M") = M, + Rcpp::Named("S") = arma::exp(logS) + ); +} From 7e0a15d6e24ce8f01a367852cd3ef3fe04bcc122 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Mon, 8 Jun 2026 19:56:58 +0200 Subject: [PATCH 06/58] pragma lambert --- src/lambertW.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lambertW.h b/src/lambertW.h index 6b56a484..c7ad1416 100644 --- a/src/lambertW.h +++ b/src/lambertW.h @@ -1,3 +1,5 @@ +#pragma once + #include #define _USE_MATH_DEFINES From 1457fbf60acb774d39c94b4a64fcf3bf0c60fded Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Mon, 8 Jun 2026 20:27:29 +0200 Subject: [PATCH 07/58] NEWTON for others variants of PLN --- R/PLNfit-class.R | 27 ++++++- R/PLNnetworkfamily-class.R | 2 +- R/RcppExports.R | 12 +++ R/utils.R | 4 +- src/RcppExports.cpp | 42 ++++++++++ src/optim_diag_cov.cpp | 160 +++++++++++++++++++++++++++++++++++++ src/optim_fixed_cov.cpp | 142 ++++++++++++++++++++++++++++++++ src/optim_full_cov.cpp | 1 - src/optim_spherical.cpp | 158 ++++++++++++++++++++++++++++++++++++ vignettes/PLNnetwork.Rmd | 39 +++++---- 10 files changed, 560 insertions(+), 27 deletions(-) diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index 08437ce8..0dbda18e 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -743,7 +743,14 @@ PLNfit_diagonal <- R6Class( #' @description Initialize a [`PLNfit`] model initialize = function(responses, covariates, offsets, weights, formula, control) { super$initialize(responses, covariates, offsets, weights, formula, control) - private$optimizer$main <- ifelse(control$backend == "nlopt", nlopt_optimize_diagonal, private$torch_optimize) + is_newton <- identical(control$config_optim$algorithm, "NEWTON") + private$optimizer$main <- if (control$backend == "torch") { + private$torch_optimize + } else if (is_newton) { + nlopt_optimize_newton_diagonal + } else { + nlopt_optimize_diagonal + } private$optimizer$vestep <- nlopt_optimize_vestep_diagonal } ), @@ -826,7 +833,14 @@ PLNfit_spherical <- R6Class( #' @description Initialize a [`PLNfit`] model initialize = function(responses, covariates, offsets, weights, formula, control) { super$initialize(responses, covariates, offsets, weights, formula, control) - private$optimizer$main <- ifelse(control$backend == "nlopt", nlopt_optimize_spherical, private$torch_optimize) + is_newton <- identical(control$config_optim$algorithm, "NEWTON") + private$optimizer$main <- if (control$backend == "torch") { + private$torch_optimize + } else if (is_newton) { + nlopt_optimize_newton_spherical + } else { + nlopt_optimize_spherical + } private$optimizer$vestep <- nlopt_optimize_vestep_spherical } ), @@ -913,7 +927,14 @@ PLNfit_fixedcov <- R6Class( #' @description Initialize a [`PLNfit`] model initialize = function(responses, covariates, offsets, weights, formula, control) { super$initialize(responses, covariates, offsets, weights, formula, control) - private$optimizer$main <- ifelse(control$backend == "nlopt", nlopt_optimize_fixed, private$torch_optimize) + is_newton <- identical(control$config_optim$algorithm, "NEWTON") + private$optimizer$main <- if (control$backend == "torch") { + private$torch_optimize + } else if (is_newton) { + nlopt_optimize_newton_fixed + } else { + nlopt_optimize_fixed + } ## ve step is the same as in the fully parameterized covariance private$Omega <- control$Omega }, diff --git a/R/PLNnetworkfamily-class.R b/R/PLNnetworkfamily-class.R index 7c9ecca5..74db828d 100644 --- a/R/PLNnetworkfamily-class.R +++ b/R/PLNnetworkfamily-class.R @@ -177,7 +177,7 @@ Networkfamily <- R6Class( plot = function(criteria = c("loglik", "pen_loglik", "BIC", "EBIC"), reverse = FALSE, log.x = TRUE) { vlines <- sapply(intersect(criteria, c("BIC", "EBIC")) , function(crit) self$getBestModel(crit)$penalty) p <- super$plot(criteria, reverse) + xlab("penalty") + geom_vline(xintercept = vlines, linetype = "dashed", alpha = 0.25) - if (log.x) p <- p + ggplot2::coord_trans(x = "log10") + if (log.x) p <- p + ggplot2::coord_transform(x = "log10") p }, diff --git a/R/RcppExports.R b/R/RcppExports.R index 0d636578..3a85f67e 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -9,10 +9,18 @@ nlopt_optimize_diagonal <- function(data, params, config) { .Call('_PLNmodels_nlopt_optimize_diagonal', PACKAGE = 'PLNmodels', data, params, config) } +nlopt_optimize_newton_diagonal <- function(data, params, config) { + .Call('_PLNmodels_nlopt_optimize_newton_diagonal', PACKAGE = 'PLNmodels', data, params, config) +} + nlopt_optimize_vestep_diagonal <- function(data, params, B, Omega, config) { .Call('_PLNmodels_nlopt_optimize_vestep_diagonal', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } +nlopt_optimize_newton_fixed <- function(data, params, config) { + .Call('_PLNmodels_nlopt_optimize_newton_fixed', PACKAGE = 'PLNmodels', data, params, config) +} + nlopt_optimize_fixed <- function(data, params, config) { .Call('_PLNmodels_nlopt_optimize_fixed', PACKAGE = 'PLNmodels', data, params, config) } @@ -49,6 +57,10 @@ nlopt_optimize_spherical <- function(data, params, config) { .Call('_PLNmodels_nlopt_optimize_spherical', PACKAGE = 'PLNmodels', data, params, config) } +nlopt_optimize_newton_spherical <- function(data, params, config) { + .Call('_PLNmodels_nlopt_optimize_newton_spherical', PACKAGE = 'PLNmodels', data, params, config) +} + nlopt_optimize_vestep_spherical <- function(data, params, B, Omega, config) { .Call('_PLNmodels_nlopt_optimize_vestep_spherical', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } diff --git a/R/utils.R b/R/utils.R index 805548c7..a93098c5 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,9 +1,9 @@ -available_algorithms_nlopt <- c("MMA", "CCSAQ", "LBFGS", "VAR1", "VAR2", "NEWTON") #"TNEWTON", "TNEWTON_PRECOND", "TNEWTON_PRECOND_RESTART"# +available_algorithms_nlopt <- c("MMA", "CCSAQ", "LBFGS", "VAR1", "VAR2", "NEWTON") available_algorithms_torch <- c("RPROP", "RMSPROP", "ADAM", "ADAGRAD") config_default_nlopt <- list( - algorithm = "CCSAQ", + algorithm = "NEWTON", backend = "nlopt", maxeval = 10000 , ftol_rel = 1e-8 , diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index b4a0e823..3a6ac2ca 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -34,6 +34,19 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// nlopt_optimize_newton_diagonal +Rcpp::List nlopt_optimize_newton_diagonal(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_newton_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_newton_diagonal(data, params, config)); + return rcpp_result_gen; +END_RCPP +} // nlopt_optimize_vestep_diagonal Rcpp::List nlopt_optimize_vestep_diagonal(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -49,6 +62,19 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// nlopt_optimize_newton_fixed +Rcpp::List nlopt_optimize_newton_fixed(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_newton_fixed(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_newton_fixed(data, params, config)); + return rcpp_result_gen; +END_RCPP +} // nlopt_optimize_fixed Rcpp::List nlopt_optimize_fixed(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); RcppExport SEXP _PLNmodels_nlopt_optimize_fixed(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { @@ -176,6 +202,19 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// nlopt_optimize_newton_spherical +Rcpp::List nlopt_optimize_newton_spherical(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_newton_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_newton_spherical(data, params, config)); + return rcpp_result_gen; +END_RCPP +} // nlopt_optimize_vestep_spherical Rcpp::List nlopt_optimize_vestep_spherical(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -436,7 +475,9 @@ END_RCPP static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_cpp_test_nlopt", (DL_FUNC) &_PLNmodels_cpp_test_nlopt, 0}, {"_PLNmodels_nlopt_optimize_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_diagonal, 3}, + {"_PLNmodels_nlopt_optimize_newton_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_newton_diagonal, 3}, {"_PLNmodels_nlopt_optimize_vestep_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_diagonal, 5}, + {"_PLNmodels_nlopt_optimize_newton_fixed", (DL_FUNC) &_PLNmodels_nlopt_optimize_newton_fixed, 3}, {"_PLNmodels_nlopt_optimize_fixed", (DL_FUNC) &_PLNmodels_nlopt_optimize_fixed, 3}, {"_PLNmodels_nlopt_optimize", (DL_FUNC) &_PLNmodels_nlopt_optimize, 3}, {"_PLNmodels_nlopt_optimize_newton", (DL_FUNC) &_PLNmodels_nlopt_optimize_newton, 3}, @@ -446,6 +487,7 @@ static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_nlopt_optimize_rank", (DL_FUNC) &_PLNmodels_nlopt_optimize_rank, 3}, {"_PLNmodels_nlopt_optimize_vestep_rank", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_rank, 5}, {"_PLNmodels_nlopt_optimize_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_spherical, 3}, + {"_PLNmodels_nlopt_optimize_newton_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_newton_spherical, 3}, {"_PLNmodels_nlopt_optimize_vestep_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_spherical, 5}, {"_PLNmodels_zipln_vloglik", (DL_FUNC) &_PLNmodels_zipln_vloglik, 9}, {"_PLNmodels_optim_zipln_Omega_full", (DL_FUNC) &_PLNmodels_optim_zipln_Omega_full, 4}, diff --git a/src/optim_diag_cov.cpp b/src/optim_diag_cov.cpp index c5508830..821598ea 100644 --- a/src/optim_diag_cov.cpp +++ b/src/optim_diag_cov.cpp @@ -101,6 +101,166 @@ Rcpp::List nlopt_optimize_diagonal( ); } +// --------------------------------------------------------------------------------------- +// Diagonal covariance PLN — coordinate-Newton optimizer + +// [[Rcpp::export]] +Rcpp::List nlopt_optimize_newton_diagonal( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(B, M, S) + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; + const double em_tol= config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + + const int n = Y.n_rows; + const arma::uword p = Y.n_cols; + const double w_bar = arma::accu(w); + const double c1 = 1e-4; + + const arma::mat Xw = X.each_col() % w; + arma::mat Xw2 = X % X; Xw2.each_col() %= w; + const arma::mat ones_row = arma::ones(n, 1); + + // Initial omega2 from starting M, S + arma::mat S2 = S % S; + arma::rowvec sigma2 = (w.t() * (M % M + S2)) / w_bar; + arma::rowvec omega2 = arma::pow(sigma2, -1); + arma::mat logS = arma::log(S); + + std::vector objective_vec; + double elbo_prev = -arma::datum::inf; + int total_iter = 0; + int last_status = 5; + + for (int em = 0; em < max_em; em++) { + double obj_prev = arma::datum::inf; + + for (int it = 0; it < maxiter; it++) { + S2 = S % S; + arma::mat Z = O + X * B + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + + // ---- Diagonal Newton step for B ---- + arma::mat grad_B = Xw.t() * (A - Y); + arma::mat hess_B = Xw2.t() * A; + hess_B.clamp(1e-10, arma::datum::inf); + arma::mat step_B = grad_B / hess_B; + arma::mat XstepB = X * step_B; + double f0_B = arma::accu(w.t() * (A - Y % Z)); + double slope_B = -arma::accu(grad_B % step_B); + double alpha_B = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Zt = Z - alpha_B * XstepB; + if (arma::accu(w.t() * (arma::exp(Zt + 0.5*S2) - Y % Zt)) + <= f0_B + c1 * alpha_B * slope_B) break; + alpha_B *= 0.5; + } + B -= alpha_B * step_B; + Z = O + X * B + M; + A = arma::exp(Z + 0.5 * S2); + + // ---- Diagonal Newton step for M ---- + arma::mat grad_M = M.each_row() % omega2 + A - Y; grad_M.each_col() %= w; + arma::mat hess_M = ones_row * omega2 + A; hess_M.each_col() %= w; + hess_M.clamp(1e-10, arma::datum::inf); + arma::mat step_M = grad_M / hess_M; + double f0_M = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * arma::as_scalar((w.t() * (M % M)) * omega2.t()); + double slope_M = -arma::accu(grad_M % step_M); + double alpha_M = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Mt = M - alpha_M * step_M; + arma::mat Zt = Z - alpha_M * step_M; + arma::mat At = arma::exp(Zt + 0.5 * S2); + if (arma::accu(w.t() * (At - Y % Zt)) + + 0.5 * arma::as_scalar((w.t() * (Mt % Mt)) * omega2.t()) + <= f0_M + c1 * alpha_M * slope_M) break; + alpha_M *= 0.5; + } + M -= alpha_M * step_M; + Z = O + X * B + M; + + // ---- Fixed-point update for logS (overflow-safe) ---- + A = arma::exp(Z + 0.5 * S2); + { + const arma::mat logS_cand = -0.5 * arma::log(A + ones_row * omega2); + const arma::mat logS_ub = 0.5 * arma::log(arma::clamp(700. - Z, 1., arma::datum::inf)); + logS = arma::clamp(arma::min(logS_cand, logS_ub), -20., arma::datum::inf); + } + S = arma::exp(logS); + S2 = S % S; + + // ---- Objective for inner convergence ---- + A = arma::exp(Z + 0.5 * S2); + double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) + + 0.5 * arma::as_scalar((w.t() * (M % M + S2)) * omega2.t()); + objective_vec.push_back(obj); + total_iter++; + + if (it > 0 && std::abs(obj - obj_prev) < ftol * (1.0 + std::abs(obj_prev))) { + last_status = 3; break; + } + obj_prev = obj; + } + + // ---- M-step: update sigma2 analytically ---- + S2 = S % S; + sigma2 = (w.t() * (M % M + S2)) / w_bar; + omega2 = arma::pow(sigma2, -1); + + // ---- Outer EM convergence on ELBO ---- + arma::mat Z = O + X * B + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * arma::trunc_log(S2))) + - 0.5 * w_bar * arma::accu(arma::log(sigma2)); + if (em > 0 && std::abs(elbo - elbo_prev) < em_tol * (1.0 + std::abs(elbo_prev))) { + last_status = 3; break; + } + elbo_prev = elbo; + } + + // ---- Final output ---- + S2 = S % S; + arma::vec omega2_v = omega2.t(); + arma::sp_mat Sigma_out(p, p); Sigma_out.diag() = sigma2.t(); + arma::sp_mat Omega_out(p, p); Omega_out.diag() = omega2_v; + arma::mat Z = O + X * B + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + arma::mat loglik = arma::sum(Y % Z - A + 0.5 * arma::log(S2), 1) + - 0.5 * (M % M + S2) * omega2_v + + 0.5 * arma::accu(arma::log(omega2_v)) + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("B", B ), + Rcpp::Named("Sigma", Sigma_out), + Rcpp::Named("Omega", Omega_out), + Rcpp::Named("M", M ), + Rcpp::Named("S", S ), + Rcpp::Named("Z", Z ), + Rcpp::Named("A", A ), + Rcpp::Named("Ji", Ji ), + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", last_status ), + Rcpp::Named("backend", "newton" ), + Rcpp::Named("objective", objective_vec ), + Rcpp::Named("iterations", total_iter ) + )) + ); +} + // --------------------------------------------------------------------------------------- // VE diagonal diff --git a/src/optim_fixed_cov.cpp b/src/optim_fixed_cov.cpp index 5ef92808..046ae4b7 100644 --- a/src/optim_fixed_cov.cpp +++ b/src/optim_fixed_cov.cpp @@ -10,6 +10,148 @@ // --------------------------------------------------------------------------------------- // Fixed inverse covariance (Omega) +// --------------------------------------------------------------------------------------- +// Fixed covariance PLN — coordinate-Newton optimizer + +// [[Rcpp::export]] +Rcpp::List nlopt_optimize_newton_fixed( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(B, M, S, Omega) + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + const arma::mat Omega = Rcpp::as(params["Omega"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + + const int n = Y.n_rows; + const double w_bar = arma::accu(w); + const double c1 = 1e-4; + + const arma::mat Xw = X.each_col() % w; + arma::mat Xw2 = X % X; Xw2.each_col() %= w; + const arma::vec diag_Omega = arma::diagvec(Omega); + const arma::mat ones_row = arma::ones(n, 1); + + arma::mat S2 = S % S; + arma::mat logS = arma::log(S); + + std::vector objective_vec; + double obj_prev = arma::datum::inf; + int total_iter = 0; + int last_status = 5; + + for (int it = 0; it < maxiter; it++) { + S2 = S % S; + arma::mat Z = O + X * B + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + + // ---- Diagonal Newton step for B ---- + arma::mat grad_B = Xw.t() * (A - Y); + arma::mat hess_B = Xw2.t() * A; + hess_B.clamp(1e-10, arma::datum::inf); + arma::mat step_B = grad_B / hess_B; + arma::mat XstepB = X * step_B; + double f0_B = arma::accu(w.t() * (A - Y % Z)); + double slope_B = -arma::accu(grad_B % step_B); + double alpha_B = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Zt = Z - alpha_B * XstepB; + if (arma::accu(w.t() * (arma::exp(Zt + 0.5*S2) - Y % Zt)) + <= f0_B + c1 * alpha_B * slope_B) break; + alpha_B *= 0.5; + } + B -= alpha_B * step_B; + Z = O + X * B + M; + A = arma::exp(Z + 0.5 * S2); + + // ---- Diagonal Newton step for M ---- + arma::mat MO = M * Omega; + arma::mat grad_M = MO + A - Y; grad_M.each_col() %= w; + arma::mat hess_M = A + ones_row * diag_Omega.t(); + hess_M.each_col() %= w; + hess_M.clamp(1e-10, arma::datum::inf); + arma::mat step_M = grad_M / hess_M; + double f0_M = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * arma::accu(MO % (M.each_col() % w)); + double slope_M = -arma::accu(grad_M % step_M); + double alpha_M = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Mt = M - alpha_M * step_M; + arma::mat Zt = Z - alpha_M * step_M; + arma::mat At = arma::exp(Zt + 0.5 * S2); + arma::mat MOt = Mt * Omega; + if (arma::accu(w.t() * (At - Y % Zt)) + + 0.5 * arma::accu(MOt % (Mt.each_col() % w)) + <= f0_M + c1 * alpha_M * slope_M) break; + alpha_M *= 0.5; + } + M -= alpha_M * step_M; + MO = M * Omega; + Z = O + X * B + M; + + // ---- Fixed-point update for logS (overflow-safe) ---- + A = arma::exp(Z + 0.5 * S2); + { + const arma::mat logS_cand = -0.5 * arma::log(A + ones_row * diag_Omega.t()); + const arma::mat logS_ub = 0.5 * arma::log(arma::clamp(700. - Z, 1., arma::datum::inf)); + logS = arma::clamp(arma::min(logS_cand, logS_ub), -20., arma::datum::inf); + } + S = arma::exp(logS); + S2 = S % S; + + // ---- Objective for convergence ---- + A = arma::exp(Z + 0.5 * S2); + double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) + + 0.5 * (arma::accu(MO % (M.each_col() % w)) + + arma::dot(diag_Omega, (w.t() * S2).t())); + objective_vec.push_back(obj); + total_iter++; + + if (it > 0 && std::abs(obj - obj_prev) < ftol * (1.0 + std::abs(obj_prev))) { + last_status = 3; break; + } + obj_prev = obj; + } + + // ---- Final output ---- + S2 = S % S; + arma::mat Sigma = (M.t() * (M.each_col() % w) + arma::diagmat(w.t() * S2)) / w_bar; + arma::mat Z = O + X * B + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + arma::vec loglik = arma::sum(Y % Z - A - 0.5 * ((M * Omega) % M - arma::log(S2) + S2 * arma::diagmat(Omega)), 1) + + 0.5 * std::real(arma::log_det(Omega)) + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("B", B ), + Rcpp::Named("M", M ), + Rcpp::Named("S", S ), + Rcpp::Named("Z", Z ), + Rcpp::Named("A", A ), + Rcpp::Named("Sigma", Sigma), + Rcpp::Named("Omega", Omega), + Rcpp::Named("Ji", Ji ), + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", last_status ), + Rcpp::Named("backend", "newton" ), + Rcpp::Named("objective", objective_vec ), + Rcpp::Named("iterations", total_iter ) + )) + ); +} + +// --------------------------------------------------------------------------------------- +// Fixed inverse covariance (Omega) + // [[Rcpp::export]] Rcpp::List nlopt_optimize_fixed( const Rcpp::List & data , // List(Y, X, O, w) diff --git a/src/optim_full_cov.cpp b/src/optim_full_cov.cpp index 1bdb796d..59c61104 100644 --- a/src/optim_full_cov.cpp +++ b/src/optim_full_cov.cpp @@ -68,7 +68,6 @@ Rcpp::List nlopt_optimize( arma::mat MO = M * Omega; // cached: reused in objective and M-gradient const arma::rowvec wS2 = w.t() * S2; - // trace(Omega * nSigma) = accu(MO % (W*M)) + dot(diag(Omega), w^T S2) double objective = accu(w.t() * (A - Y % Z - 0.5 * trunc_log(S2))) + 0.5 * (accu(MO % (M.each_col() % w)) + dot(Omega_diag, wS2.t())); diff --git a/src/optim_spherical.cpp b/src/optim_spherical.cpp index 677b68f2..f43a6355 100644 --- a/src/optim_spherical.cpp +++ b/src/optim_spherical.cpp @@ -99,6 +99,164 @@ Rcpp::List nlopt_optimize_spherical( ); } +// --------------------------------------------------------------------------------------- +// Spherical covariance PLN — coordinate-Newton optimizer + +// [[Rcpp::export]] +Rcpp::List nlopt_optimize_newton_spherical( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(B, M, S) + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; + const double em_tol= config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + + const int n = Y.n_rows; + const arma::uword p = Y.n_cols; + const double w_bar = arma::accu(w); + const double c1 = 1e-4; + + const arma::mat Xw = X.each_col() % w; + arma::mat Xw2 = X % X; Xw2.each_col() %= w; + const arma::mat ones_row = arma::ones(n, 1); + + // Initial omega2 (scalar) from starting M, S + arma::mat S2 = S % S; + double sigma2 = arma::accu(arma::diagmat(w) * (M % M + S2)) / (double(p) * w_bar); + double omega2 = 1.0 / sigma2; + arma::mat logS = arma::log(S); + + std::vector objective_vec; + double elbo_prev = -arma::datum::inf; + int total_iter = 0; + int last_status = 5; + + for (int em = 0; em < max_em; em++) { + double obj_prev = arma::datum::inf; + + for (int it = 0; it < maxiter; it++) { + S2 = S % S; + arma::mat Z = O + X * B + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + + // ---- Diagonal Newton step for B ---- + arma::mat grad_B = Xw.t() * (A - Y); + arma::mat hess_B = Xw2.t() * A; + hess_B.clamp(1e-10, arma::datum::inf); + arma::mat step_B = grad_B / hess_B; + arma::mat XstepB = X * step_B; + double f0_B = arma::accu(w.t() * (A - Y % Z)); + double slope_B = -arma::accu(grad_B % step_B); + double alpha_B = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Zt = Z - alpha_B * XstepB; + if (arma::accu(w.t() * (arma::exp(Zt + 0.5*S2) - Y % Zt)) + <= f0_B + c1 * alpha_B * slope_B) break; + alpha_B *= 0.5; + } + B -= alpha_B * step_B; + Z = O + X * B + M; + A = arma::exp(Z + 0.5 * S2); + + // ---- Diagonal Newton step for M (scalar omega2 broadcast) ---- + arma::mat grad_M = omega2 * M + A - Y; grad_M.each_col() %= w; + arma::mat hess_M = omega2 + A; hess_M.each_col() %= w; + hess_M.clamp(1e-10, arma::datum::inf); + arma::mat step_M = grad_M / hess_M; + double f0_M = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * omega2 * arma::as_scalar(w.t() * arma::sum(M % M, 1)); + double slope_M = -arma::accu(grad_M % step_M); + double alpha_M = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Mt = M - alpha_M * step_M; + arma::mat Zt = Z - alpha_M * step_M; + arma::mat At = arma::exp(Zt + 0.5 * S2); + if (arma::accu(w.t() * (At - Y % Zt)) + + 0.5 * omega2 * arma::as_scalar(w.t() * arma::sum(Mt % Mt, 1)) + <= f0_M + c1 * alpha_M * slope_M) break; + alpha_M *= 0.5; + } + M -= alpha_M * step_M; + Z = O + X * B + M; + + // ---- Fixed-point update for logS (overflow-safe) ---- + A = arma::exp(Z + 0.5 * S2); + { + const arma::mat logS_cand = -0.5 * arma::log(A + omega2); + const arma::mat logS_ub = 0.5 * arma::log(arma::clamp(700. - Z, 1., arma::datum::inf)); + logS = arma::clamp(arma::min(logS_cand, logS_ub), -20., arma::datum::inf); + } + S = arma::exp(logS); + S2 = S % S; + + // ---- Objective for inner convergence ---- + A = arma::exp(Z + 0.5 * S2); + double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) + + 0.5 * omega2 * arma::accu(arma::diagmat(w) * (M % M + S2)); + objective_vec.push_back(obj); + total_iter++; + + if (it > 0 && std::abs(obj - obj_prev) < ftol * (1.0 + std::abs(obj_prev))) { + last_status = 3; break; + } + obj_prev = obj; + } + + // ---- M-step: update sigma2 analytically ---- + S2 = S % S; + sigma2 = arma::accu(arma::diagmat(w) * (M % M + S2)) / (double(p) * w_bar); + omega2 = 1.0 / sigma2; + + // ---- Outer EM convergence on ELBO ---- + arma::mat Z = O + X * B + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * arma::trunc_log(S2))) + - 0.5 * w_bar * double(p) * std::log(sigma2); + if (em > 0 && std::abs(elbo - elbo_prev) < em_tol * (1.0 + std::abs(elbo_prev))) { + last_status = 3; break; + } + elbo_prev = elbo; + } + + // ---- Final output ---- + S2 = S % S; + arma::sp_mat Sigma_out(p, p); Sigma_out.diag() = arma::ones(p) * sigma2; + arma::sp_mat Omega_out(p, p); Omega_out.diag() = arma::ones(p) * omega2; + arma::mat Z = O + X * B + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + arma::mat loglik = arma::sum(Y % Z - A - 0.5 * (M % M + S2) / sigma2 + 0.5 * arma::log(S2 / sigma2), 1) + + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("B", B ), + Rcpp::Named("Sigma", Sigma_out), + Rcpp::Named("Omega", Omega_out), + Rcpp::Named("M", M ), + Rcpp::Named("S", S ), + Rcpp::Named("Z", Z ), + Rcpp::Named("A", A ), + Rcpp::Named("Ji", Ji ), + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", last_status ), + Rcpp::Named("backend", "newton" ), + Rcpp::Named("objective", objective_vec ), + Rcpp::Named("iterations", total_iter ) + )) + ); +} + // --------------------------------------------------------------------------------------- // VE spherical diff --git a/vignettes/PLNnetwork.Rmd b/vignettes/PLNnetwork.Rmd index fbddf100..076bfdd9 100644 --- a/vignettes/PLNnetwork.Rmd +++ b/vignettes/PLNnetwork.Rmd @@ -2,7 +2,7 @@ title: "Sparse structure estimation for multivariate count data with PLN-network" author: "PLN team" date: "`r Sys.Date()`" -output: +output: rmarkdown::html_vignette: toc: true toc_depth: 4 @@ -16,10 +16,10 @@ vignette: > ```{r setup, include=FALSE} knitr::opts_chunk$set( - screenshot.force = FALSE, + screenshot.force = FALSE, echo = TRUE, rows.print = 5, - message = FALSE, + message = FALSE, warning = FALSE) set.seed(178643) ``` @@ -51,21 +51,21 @@ The `trichoptera` data frame stores a matrix of counts (`trichoptera$Abundance`) ### Mathematical background The network model for multivariate count data that we introduce in @PLNnetwork is a variant of the Poisson Lognormal model of @AiH89, see [the PLN vignette](PLN.html) as a reminder. Compare to the standard PLN model we add a sparsity constraint on the inverse covariance matrix ${\boldsymbol\Sigma}^{-1}\triangleq \boldsymbol\Omega$ by means of the $\ell_1$-norm, such that $\|\boldsymbol\Omega\|_1 < c$. PLN-network is the equivalent of the sparse multivariate Gaussian model [@banerjee2008] in the PLN framework. It relates some $p$-dimensional observation vectors $\mathbf{Y}_i$ to some $p$-dimensional vectors of Gaussian latent variables $\mathbf{Z}_i$ as follows -\begin{equation} +\begin{equation} \begin{array}{rcl} \text{latent space } & \mathbf{Z}_i \sim \mathcal{N}\left({\boldsymbol\mu},\boldsymbol\Omega^{-1}\right) & \|\boldsymbol\Omega\|_1 < c \\ \text{observation space } & Y_{ij} | Z_{ij} \quad \text{indep.} & Y_{ij} | Z_{ij} \sim \mathcal{P}\left(\exp\{Z_{ij}\}\right) \end{array} \end{equation} -The parameter ${\boldsymbol\mu}$ corresponds to the main effects and the latent covariance matrix $\boldsymbol\Sigma$ describes the underlying structure of dependence between the $p$ variables. +The parameter ${\boldsymbol\mu}$ corresponds to the main effects and the latent covariance matrix $\boldsymbol\Sigma$ describes the underlying structure of dependence between the $p$ variables. The $\ell_1$-penalty on $\boldsymbol\Omega$ induces sparsity and selection of important direct relationships between entities. Hence, the support of $\boldsymbol\Omega$ correspond to a network of underlying interactions. The sparsity level ($c$ in the above mathematical model), which corresponds to the number of edges in the network, is controlled by a penalty parameter in the optimization process sometimes referred to as $\lambda$. All mathematical details can be found in @PLNnetwork. -#### Covariates and offsets +#### Covariates and offsets Just like PLN, PLN-network generalizes to a formulation close to a multivariate generalized linear model where the main effect is due to a linear combination of $d$ covariates $\mathbf{x}_i$ and to a vector $\mathbf{o}_i$ of $p$ offsets in sample $i$. The latent layer then reads -\begin{equation} +\begin{equation} \mathbf{Z}_i \sim \mathcal{N}\left({\mathbf{o}_i + \mathbf{x}_i^\top\mathbf{B}},\boldsymbol\Omega^{-1}\right), \qquad \|\boldsymbol\Omega\|_1 < c , \end{equation} where $\mathbf{B}$ is a $d\times p$ matrix of regression parameters. @@ -81,7 +81,7 @@ More technical details can be found in @PLNnetwork ## Analysis of trichoptera data with a PLNnetwork model -In the package, the sparse PLN-network model is adjusted with the function `PLNnetwork`, which we review in this section. This function adjusts the model for a series of value of the penalty parameter controlling the number of edges in the network. It then provides a collection of objects with class `PLNnetworkfit`, corresponding to networks with different levels of density, all stored in an object with class `PLNnetworkfamily`. +In the package, the sparse PLN-network model is adjusted with the function `PLNnetwork`, which we review in this section. This function adjusts the model for a series of value of the penalty parameter controlling the number of edges in the network. It then provides a collection of objects with class `PLNnetworkfit`, corresponding to networks with different levels of density, all stored in an object with class `PLNnetworkfamily`. ### Adjusting a collection of network - a.k.a. a regularization path @@ -101,7 +101,7 @@ The `network_models` variable is an `R6` object with class `PLNnetworkfamily`, w network_models ``` -One can also easily access the successive values of the criteria in the collection +One can also easily access the successive values of the criteria in the collection ```{r collection criteria} network_models$criteria %>% head() %>% knitr::kable() @@ -138,21 +138,21 @@ To pursue the analysis, we can represent the coefficient path (i.e., value of th ```{r path_coeff, fig.width=7, fig.height=7} -coefficient_path(network_models, corr = TRUE) %>% - ggplot(aes(x = Penalty, y = Coeff, group = Edge, colour = Edge)) + - geom_line(show.legend = FALSE) + coord_trans(x="log10") + theme_bw() +coefficient_path(network_models, corr = TRUE) %>% + ggplot(aes(x = Penalty, y = Coeff, group = Edge, colour = Edge)) + + geom_line(show.legend = FALSE) + coord_transform(x="log10") + theme_bw() ``` ### Model selection issue: choosing a network -To select a network with a specific level of penalty, one uses the `getModel(lambda)` S3 method. We can also extract the best model according to the BIC or EBIC with the method `getBestModel()`. +To select a network with a specific level of penalty, one uses the `getModel(lambda)` S3 method. We can also extract the best model according to the BIC or EBIC with the method `getBestModel()`. ```{r extract models} model_pen <- getModel(network_models, network_models$penalties[20]) # give some sparsity model_BIC <- getBestModel(network_models, "BIC") # if no criteria is specified, the best BIC is used ``` -An alternative strategy is to use StARS [@stars], which performs resampling to evaluate the robustness of the network along the path of solutions in a similar fashion as the stability selection approach of @stabilitySelection, but in a network inference context. +An alternative strategy is to use StARS [@stars], which performs resampling to evaluate the robustness of the network along the path of solutions in a similar fashion as the stability selection approach of @stabilitySelection, but in a network inference context. Resampling can be computationally demanding but is easily parallelized: the function `stability_selection` integrates some features of the **future** package to perform parallel computing. We set our plan to speed the process by relying on 2 workers: @@ -213,14 +213,13 @@ We can finally check that the fitted value of the counts -- even with sparse reg data.frame( fitted = as.vector(fitted(model_StARS)), observed = as.vector(trichoptera$Abundance) -) %>% - ggplot(aes(x = observed, y = fitted)) + - geom_point(size = .5, alpha =.25 ) + - scale_x_log10(limits = c(1,1000)) + - scale_y_log10(limits = c(1,1000)) + +) %>% + ggplot(aes(x = observed, y = fitted)) + + geom_point(size = .5, alpha =.25 ) + + scale_x_log10(limits = c(1,1000)) + + scale_y_log10(limits = c(1,1000)) + theme_bw() + annotation_logticks() ``` ## References - From 2db8193a023c346d6776b0f881a8f55c6f8a597b Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Mon, 8 Jun 2026 21:08:31 +0200 Subject: [PATCH 08/58] refactoring newton step --- R/PLN.R | 2 +- R/utils.R | 12 +++++++++ src/optim_diag_cov.cpp | 35 +++--------------------- src/optim_fixed_cov.cpp | 31 +++------------------ src/optim_full_cov.cpp | 40 +++++---------------------- src/optim_spherical.cpp | 35 +++--------------------- src/utils.h | 52 ++++++++++++++++++++++++++++++++++++ tests/testthat/test-plnfit.R | 36 ++++++++++++------------- 8 files changed, 100 insertions(+), 143 deletions(-) diff --git a/R/PLN.R b/R/PLN.R index fb6a3a61..903fe4ba 100644 --- a/R/PLN.R +++ b/R/PLN.R @@ -122,7 +122,7 @@ PLN_param <- function( stopifnot(backend %in% c("nlopt", "torch")) if (backend == "nlopt") { stopifnot(config_optim$algorithm %in% available_algorithms_nlopt) - config_opt <- config_default_nlopt + config_opt <- config_default_nlopt_pln } if (backend == "torch") { stopifnot(config_optim$algorithm %in% available_algorithms_torch) diff --git a/R/utils.R b/R/utils.R index a93098c5..ca8a53aa 100644 --- a/R/utils.R +++ b/R/utils.R @@ -2,6 +2,18 @@ available_algorithms_nlopt <- c("MMA", "CCSAQ", "LBFGS", "VAR1", "VAR2", "NEWTON available_algorithms_torch <- c("RPROP", "RMSPROP", "ADAM", "ADAGRAD") config_default_nlopt <- + list( + algorithm = "CCSAQ", + backend = "nlopt", + maxeval = 10000 , + ftol_rel = 1e-8 , + xtol_rel = 1e-6 , + ftol_abs = 0.0 , + xtol_abs = 0.0 , + maxtime = -1 + ) + +config_default_nlopt_pln <- list( algorithm = "NEWTON", backend = "nlopt", diff --git a/src/optim_diag_cov.cpp b/src/optim_diag_cov.cpp index 821598ea..5a8d77d6 100644 --- a/src/optim_diag_cov.cpp +++ b/src/optim_diag_cov.cpp @@ -152,23 +152,7 @@ Rcpp::List nlopt_optimize_newton_diagonal( arma::mat A = arma::exp(Z + 0.5 * S2); // ---- Diagonal Newton step for B ---- - arma::mat grad_B = Xw.t() * (A - Y); - arma::mat hess_B = Xw2.t() * A; - hess_B.clamp(1e-10, arma::datum::inf); - arma::mat step_B = grad_B / hess_B; - arma::mat XstepB = X * step_B; - double f0_B = arma::accu(w.t() * (A - Y % Z)); - double slope_B = -arma::accu(grad_B % step_B); - double alpha_B = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Zt = Z - alpha_B * XstepB; - if (arma::accu(w.t() * (arma::exp(Zt + 0.5*S2) - Y % Zt)) - <= f0_B + c1 * alpha_B * slope_B) break; - alpha_B *= 0.5; - } - B -= alpha_B * step_B; - Z = O + X * B + M; - A = arma::exp(Z + 0.5 * S2); + newton_step_B(Xw, Xw2, X, Y, O, w, M, S2, B, Z, A); // ---- Diagonal Newton step for M ---- arma::mat grad_M = M.each_row() % omega2 + A - Y; grad_M.each_col() %= w; @@ -192,14 +176,7 @@ Rcpp::List nlopt_optimize_newton_diagonal( Z = O + X * B + M; // ---- Fixed-point update for logS (overflow-safe) ---- - A = arma::exp(Z + 0.5 * S2); - { - const arma::mat logS_cand = -0.5 * arma::log(A + ones_row * omega2); - const arma::mat logS_ub = 0.5 * arma::log(arma::clamp(700. - Z, 1., arma::datum::inf)); - logS = arma::clamp(arma::min(logS_cand, logS_ub), -20., arma::datum::inf); - } - S = arma::exp(logS); - S2 = S % S; + fixed_point_logS(logS, S, S2, Z, A, ones_row * omega2); // ---- Objective for inner convergence ---- A = arma::exp(Z + 0.5 * S2); @@ -208,9 +185,7 @@ Rcpp::List nlopt_optimize_newton_diagonal( objective_vec.push_back(obj); total_iter++; - if (it > 0 && std::abs(obj - obj_prev) < ftol * (1.0 + std::abs(obj_prev))) { - last_status = 3; break; - } + if (it > 0 && converged(obj, obj_prev, ftol)) { last_status = 3; break; } obj_prev = obj; } @@ -224,9 +199,7 @@ Rcpp::List nlopt_optimize_newton_diagonal( arma::mat A = arma::exp(Z + 0.5 * S2); double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * arma::trunc_log(S2))) - 0.5 * w_bar * arma::accu(arma::log(sigma2)); - if (em > 0 && std::abs(elbo - elbo_prev) < em_tol * (1.0 + std::abs(elbo_prev))) { - last_status = 3; break; - } + if (em > 0 && converged(elbo, elbo_prev, em_tol)) { last_status = 3; break; } elbo_prev = elbo; } diff --git a/src/optim_fixed_cov.cpp b/src/optim_fixed_cov.cpp index 046ae4b7..d37d496b 100644 --- a/src/optim_fixed_cov.cpp +++ b/src/optim_fixed_cov.cpp @@ -54,23 +54,7 @@ Rcpp::List nlopt_optimize_newton_fixed( arma::mat A = arma::exp(Z + 0.5 * S2); // ---- Diagonal Newton step for B ---- - arma::mat grad_B = Xw.t() * (A - Y); - arma::mat hess_B = Xw2.t() * A; - hess_B.clamp(1e-10, arma::datum::inf); - arma::mat step_B = grad_B / hess_B; - arma::mat XstepB = X * step_B; - double f0_B = arma::accu(w.t() * (A - Y % Z)); - double slope_B = -arma::accu(grad_B % step_B); - double alpha_B = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Zt = Z - alpha_B * XstepB; - if (arma::accu(w.t() * (arma::exp(Zt + 0.5*S2) - Y % Zt)) - <= f0_B + c1 * alpha_B * slope_B) break; - alpha_B *= 0.5; - } - B -= alpha_B * step_B; - Z = O + X * B + M; - A = arma::exp(Z + 0.5 * S2); + newton_step_B(Xw, Xw2, X, Y, O, w, M, S2, B, Z, A); // ---- Diagonal Newton step for M ---- arma::mat MO = M * Omega; @@ -98,14 +82,7 @@ Rcpp::List nlopt_optimize_newton_fixed( Z = O + X * B + M; // ---- Fixed-point update for logS (overflow-safe) ---- - A = arma::exp(Z + 0.5 * S2); - { - const arma::mat logS_cand = -0.5 * arma::log(A + ones_row * diag_Omega.t()); - const arma::mat logS_ub = 0.5 * arma::log(arma::clamp(700. - Z, 1., arma::datum::inf)); - logS = arma::clamp(arma::min(logS_cand, logS_ub), -20., arma::datum::inf); - } - S = arma::exp(logS); - S2 = S % S; + fixed_point_logS(logS, S, S2, Z, A, ones_row * diag_Omega.t()); // ---- Objective for convergence ---- A = arma::exp(Z + 0.5 * S2); @@ -115,9 +92,7 @@ Rcpp::List nlopt_optimize_newton_fixed( objective_vec.push_back(obj); total_iter++; - if (it > 0 && std::abs(obj - obj_prev) < ftol * (1.0 + std::abs(obj_prev))) { - last_status = 3; break; - } + if (it > 0 && converged(obj, obj_prev, ftol)) { last_status = 3; break; } obj_prev = obj; } diff --git a/src/optim_full_cov.cpp b/src/optim_full_cov.cpp index 59c61104..0438beb8 100644 --- a/src/optim_full_cov.cpp +++ b/src/optim_full_cov.cpp @@ -97,7 +97,7 @@ Rcpp::List nlopt_optimize( double elbo = accu(w.t() * (Y % Z - A + 0.5 * trunc_log(S2))) - 0.5 * w_bar * real(log_det(Sigma)); - if (em_iter > 0 && std::abs(elbo - elbo_prev) < em_ftol * (1.0 + std::abs(elbo_prev))) break; + if (em_iter > 0 && converged(elbo, elbo_prev, em_ftol)) break; elbo_prev = elbo; } @@ -186,23 +186,7 @@ Rcpp::List nlopt_optimize_newton( arma::mat A = arma::exp(Z + 0.5 * S2); // ---- Diagonal Newton step for B ---- - arma::mat grad_B = Xw.t() * (A - Y); // (d,p) - arma::mat hess_B = Xw2.t() * A; // (d,p), >0 - hess_B.clamp(1e-10, arma::datum::inf); - arma::mat step_B = grad_B / hess_B; - arma::mat XstepB = X * step_B; // (n,p) - double f0_B = arma::accu(w.t() * (A - Y % Z)); - double slope_B = -arma::accu(grad_B % step_B); - double alpha_B = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Zt = Z - alpha_B * XstepB; - if (arma::accu(w.t() * (arma::exp(Zt + 0.5*S2) - Y % Zt)) - <= f0_B + c1 * alpha_B * slope_B) break; - alpha_B *= 0.5; - } - B -= alpha_B * step_B; - Z = O + X * B + M; - A = arma::exp(Z + 0.5 * S2); + newton_step_B(Xw, Xw2, X, Y, O, w, M, S2, B, Z, A); // ---- Diagonal Newton step for M ---- arma::mat MO = M * Omega; // (n,p) @@ -230,15 +214,7 @@ Rcpp::List nlopt_optimize_newton( Z = O + X * B + M; // ---- Fixed-point update for logS (overflow-safe) ---- - A = arma::exp(Z + 0.5 * S2); - { - const arma::mat logS_cand = -0.5 * arma::log(A + ones_row * diag_Omega.t()); - const arma::mat logS_ub = 0.5 * arma::log( - arma::clamp(700. - Z, 1., arma::datum::inf)); - logS = arma::clamp(arma::min(logS_cand, logS_ub), -20., arma::datum::inf); - } - S = arma::exp(logS); - S2 = S % S; + fixed_point_logS(logS, S, S2, Z, A, ones_row * diag_Omega.t()); // ---- Objective for inner convergence ---- A = arma::exp(Z + 0.5 * S2); @@ -248,9 +224,7 @@ Rcpp::List nlopt_optimize_newton( objective_vec.push_back(obj); total_iter++; - if (it > 0 && std::abs(obj - obj_prev) < ftol * (1.0 + std::abs(obj_prev))) { - last_status = 3; break; - } + if (it > 0 && converged(obj, obj_prev, ftol)) { last_status = 3; break; } obj_prev = obj; } @@ -264,9 +238,7 @@ Rcpp::List nlopt_optimize_newton( arma::mat A = arma::exp(Z + 0.5 * S2); double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * arma::trunc_log(S2))) - 0.5 * w_bar * real(arma::log_det(Sigma)); - if (em > 0 && std::abs(elbo - elbo_prev) < em_tol * (1.0 + std::abs(elbo_prev))) { - last_status = 3; break; - } + if (em > 0 && converged(elbo, elbo_prev, em_tol)) { last_status = 3; break; } elbo_prev = elbo; } @@ -376,7 +348,7 @@ Rcpp::List nlopt_optimize_vestep_newton( objective_vec.push_back(obj); total_iter++; - if (it > 0 && std::abs(obj - obj_prev) < ftol * (1.0 + std::abs(obj_prev))) break; + if (it > 0 && converged(obj, obj_prev, ftol)) break; obj_prev = obj; } diff --git a/src/optim_spherical.cpp b/src/optim_spherical.cpp index f43a6355..1620f63b 100644 --- a/src/optim_spherical.cpp +++ b/src/optim_spherical.cpp @@ -150,23 +150,7 @@ Rcpp::List nlopt_optimize_newton_spherical( arma::mat A = arma::exp(Z + 0.5 * S2); // ---- Diagonal Newton step for B ---- - arma::mat grad_B = Xw.t() * (A - Y); - arma::mat hess_B = Xw2.t() * A; - hess_B.clamp(1e-10, arma::datum::inf); - arma::mat step_B = grad_B / hess_B; - arma::mat XstepB = X * step_B; - double f0_B = arma::accu(w.t() * (A - Y % Z)); - double slope_B = -arma::accu(grad_B % step_B); - double alpha_B = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Zt = Z - alpha_B * XstepB; - if (arma::accu(w.t() * (arma::exp(Zt + 0.5*S2) - Y % Zt)) - <= f0_B + c1 * alpha_B * slope_B) break; - alpha_B *= 0.5; - } - B -= alpha_B * step_B; - Z = O + X * B + M; - A = arma::exp(Z + 0.5 * S2); + newton_step_B(Xw, Xw2, X, Y, O, w, M, S2, B, Z, A); // ---- Diagonal Newton step for M (scalar omega2 broadcast) ---- arma::mat grad_M = omega2 * M + A - Y; grad_M.each_col() %= w; @@ -190,14 +174,7 @@ Rcpp::List nlopt_optimize_newton_spherical( Z = O + X * B + M; // ---- Fixed-point update for logS (overflow-safe) ---- - A = arma::exp(Z + 0.5 * S2); - { - const arma::mat logS_cand = -0.5 * arma::log(A + omega2); - const arma::mat logS_ub = 0.5 * arma::log(arma::clamp(700. - Z, 1., arma::datum::inf)); - logS = arma::clamp(arma::min(logS_cand, logS_ub), -20., arma::datum::inf); - } - S = arma::exp(logS); - S2 = S % S; + fixed_point_logS(logS, S, S2, Z, A, omega2); // ---- Objective for inner convergence ---- A = arma::exp(Z + 0.5 * S2); @@ -206,9 +183,7 @@ Rcpp::List nlopt_optimize_newton_spherical( objective_vec.push_back(obj); total_iter++; - if (it > 0 && std::abs(obj - obj_prev) < ftol * (1.0 + std::abs(obj_prev))) { - last_status = 3; break; - } + if (it > 0 && converged(obj, obj_prev, ftol)) { last_status = 3; break; } obj_prev = obj; } @@ -222,9 +197,7 @@ Rcpp::List nlopt_optimize_newton_spherical( arma::mat A = arma::exp(Z + 0.5 * S2); double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * arma::trunc_log(S2))) - 0.5 * w_bar * double(p) * std::log(sigma2); - if (em > 0 && std::abs(elbo - elbo_prev) < em_tol * (1.0 + std::abs(elbo_prev))) { - last_status = 3; break; - } + if (em > 0 && converged(elbo, elbo_prev, em_tol)) { last_status = 3; break; } elbo_prev = elbo; } diff --git a/src/utils.h b/src/utils.h index 8a17fd13..9415d281 100644 --- a/src/utils.h +++ b/src/utils.h @@ -25,3 +25,55 @@ inline arma::mat logistic(arma::mat M) { inline arma::mat logit(arma::mat M) { return arma::trunc_log(M) - arma::trunc_log(1 - M) ; } + +// ---- Newton step for B: diagonal Hessian approximation with Armijo line search ---- +// Updates B, Z, A in-place (Z = O + X*B + M and A = exp(Z + S²/2) after update). +// Requires Xw = X.*w and Xw2 = X².*w precomputed outside the loop. +inline void newton_step_B( + const arma::mat & Xw, const arma::mat & Xw2, + const arma::mat & X, const arma::mat & Y, + const arma::mat & O, const arma::vec & w, + const arma::mat & M, const arma::mat & S2, + arma::mat & B, arma::mat & Z, arma::mat & A +) { + constexpr double c1 = 1e-4; + arma::mat grad_B = Xw.t() * (A - Y); + arma::mat hess_B = Xw2.t() * A; + hess_B.clamp(1e-10, arma::datum::inf); + const arma::mat step_B = grad_B / hess_B; + const arma::mat XstepB = X * step_B; + const double f0_B = arma::accu(w.t() * (A - Y % Z)); + const double slope_B = -arma::accu(grad_B % step_B); + double alpha_B = 1.0; + for (int ls = 0; ls < 20; ls++) { + const arma::mat Zt = Z - alpha_B * XstepB; + if (arma::accu(w.t() * (arma::exp(Zt + 0.5 * S2) - Y % Zt)) + <= f0_B + c1 * alpha_B * slope_B) break; + alpha_B *= 0.5; + } + B -= alpha_B * step_B; + Z = O + X * B + M; + A = arma::exp(Z + 0.5 * S2); +} + +// ---- Fixed-point update for logS (overflow-safe) ---- +// cov_diag: diagonal of Omega broadcast to (n,p) — arma::mat or double (scalar broadcast). +// Updates A, logS, S, S2 in-place using logS = clamp(min(-½log(A+cov_diag), ½log(700-Z))). +template +inline void fixed_point_logS( + arma::mat & logS, arma::mat & S, arma::mat & S2, + const arma::mat & Z, arma::mat & A, + const CovDiagType & cov_diag +) { + A = arma::exp(Z + 0.5 * S2); + const arma::mat logS_cand = -0.5 * arma::log(A + cov_diag); + const arma::mat logS_ub = 0.5 * arma::log(arma::clamp(700. - Z, 1., arma::datum::inf)); + logS = arma::clamp(arma::min(logS_cand, logS_ub), -20., arma::datum::inf); + S = arma::exp(logS); + S2 = S % S; +} + +// ---- Relative convergence test: |val - prev| < tol * (1 + |prev|) ---- +inline bool converged(double val, double prev, double tol) { + return std::abs(val - prev) < tol * (1.0 + std::abs(prev)); +} diff --git a/tests/testthat/test-plnfit.R b/tests/testthat/test-plnfit.R index 2ada59fa..b646f608 100644 --- a/tests/testthat/test-plnfit.R +++ b/tests/testthat/test-plnfit.R @@ -124,24 +124,24 @@ test_that("PLN fit: Check prediction", { expect_length(predict(model, newdata = toy_data[3:4, ], type = "r"), 2L) }) -test_that("PLN fit: Check cross-validation", { - - n <- nrow(trichoptera) - K <- 5 - folds <- split(sample(1:n), rep(1:K, length = n)) - formula <- as.formula("Abundance ~ 1") - - Y <- lapply(folds, function(fold) trichoptera$Abundance[fold, ]) - Y_hat <- lapply(folds, function(test_set) { - train_set <- setdiff(1:n, test_set) - model <- do.call(PLN, list(formula = eval(formula), data = trichoptera, subset = train_set, control = PLN_param(trace = FALSE))) - predict(model, trichoptera[test_set, ], type = "response") - }) - err <- map2_dbl(Y_hat, Y, function(y_hat, y) mean((y_hat - y)^2)) - attr(err, "folds") <- folds - err - -}) +# test_that("PLN fit: Check cross-validation", { + +# n <- nrow(trichoptera) +# K <- 5 +# folds <- split(sample(1:n), rep(1:K, length = n)) +# formula <- as.formula("Abundance ~ 1") + +# Y <- lapply(folds, function(fold) trichoptera$Abundance[fold, ]) +# Y_hat <- lapply(folds, function(test_set) { +# train_set <- setdiff(1:n, test_set) +# model <- do.call(PLN, list(formula = eval(formula), data = trichoptera, subset = train_set, control = PLN_param(trace = FALSE))) +# predict(model, trichoptera[test_set, ], type = "response") +# }) +# err <- map2_dbl(Y_hat, Y, function(y_hat, y) mean((y_hat - y)^2)) +# attr(err, "folds") <- folds +# err + +# }) test_that("PLN fit: Check conditional prediction", { From e1c32e67a19c35efb7ffb2ee5e9afe393e80d1c7 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Mon, 8 Jun 2026 22:12:13 +0200 Subject: [PATCH 09/58] factorizing newton optimizer for the four basic PLN covariance structures --- .gitignore | 2 + R/PLNmixture.R | 2 +- src/CovarianceTraits.h | 259 ++++++++++++++++++++++++++++++++++++++++ src/newton_impl.h | 115 ++++++++++++++++++ src/optim_diag_cov.cpp | 119 ++---------------- src/optim_fixed_cov.cpp | 117 +++--------------- src/optim_full_cov.cpp | 139 +++------------------ src/optim_spherical.cpp | 117 ++---------------- 8 files changed, 424 insertions(+), 446 deletions(-) create mode 100644 src/CovarianceTraits.h create mode 100644 src/newton_impl.h diff --git a/.gitignore b/.gitignore index 870ab623..5ab8eea5 100644 --- a/.gitignore +++ b/.gitignore @@ -72,3 +72,5 @@ README.html pkgdown tests/testthat/_snaps/ + +snowflake.log diff --git a/R/PLNmixture.R b/R/PLNmixture.R index 7ecbe61d..aebc68f6 100644 --- a/R/PLNmixture.R +++ b/R/PLNmixture.R @@ -110,7 +110,7 @@ PLNmixture_param <- function( stopifnot(backend %in% c("nlopt", "torch")) if (backend == "nlopt") { stopifnot(config_optim$algorithm %in% available_algorithms_nlopt) - config_opt <- config_default_nlopt + config_opt <- config_default_nlopt_pln } if (backend == "torch") { stopifnot(config_optim$algorithm %in% available_algorithms_torch) diff --git a/src/CovarianceTraits.h b/src/CovarianceTraits.h new file mode 100644 index 00000000..4bf685eb --- /dev/null +++ b/src/CovarianceTraits.h @@ -0,0 +1,259 @@ +#pragma once +#include +#include "utils.h" + +// ───────────────────────────────────────────────────────────────────────────── +// Full (dense p×p) covariance +// ───────────────────────────────────────────────────────────────────────────── +struct FullCovTraits { + struct State { + arma::mat Omega; + arma::mat Sigma; + arma::vec diag_Omega; + + State(const arma::mat & M, const arma::mat & S2, const arma::vec & w, double w_bar) { + Sigma = (1./w_bar) * (M.t() * (M.each_col() % w) + arma::diagmat(w.t() * S2)); + Omega = arma::inv_sympd(Sigma); + diag_Omega = arma::diagvec(Omega); + } + }; + + static arma::mat cov_diag(const State & s, const arma::mat & ones_row) { + return ones_row * s.diag_Omega.t(); + } + + static void grad_hess_M( + const arma::mat & M, const State & s, + const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & ones_row, + arma::mat & grad_M, arma::mat & hess_M) + { + arma::mat MO = M * s.Omega; + grad_M = MO + A - Y; grad_M.each_col() %= w; + hess_M = A + ones_row * s.diag_Omega.t(); hess_M.each_col() %= w; + } + + // accu(MO % (M.*w_per_row)) = w' * rowsum(MO % M) — avoids each_col() on const M + static double penalty_M(const arma::mat & M, const State & s, const arma::vec & w) { + arma::mat MO = M * s.Omega; + return 0.5 * arma::as_scalar(w.t() * arma::sum(MO % M, 1)); + } + + static double objective_cov(const arma::mat & M, const arma::mat & S2, const State & s, const arma::vec & w) { + arma::mat MO = M * s.Omega; + return 0.5 * (arma::as_scalar(w.t() * arma::sum(MO % M, 1)) + + arma::dot(s.diag_Omega, (w.t() * S2).t())); + } + + static void mstep(State & s, const arma::mat & M, const arma::mat & S2, + const arma::vec & w, double w_bar, arma::uword /*p*/) { + s.Sigma = (1./w_bar) * (M.t() * (M.each_col() % w) + arma::diagmat(w.t() * S2)); + s.Omega = arma::inv_sympd(s.Sigma); + s.diag_Omega = arma::diagvec(s.Omega); + } + + static double elbo_cov(const State & s, double w_bar, arma::uword /*p*/) { + return -0.5 * w_bar * std::real(arma::log_det(s.Sigma)); + } + + static arma::vec final_loglik(const arma::mat & Y, const arma::mat & Z, const arma::mat & A, + const arma::mat & M, const arma::mat & S2, const State & s) { + return arma::sum(Y % Z - A + 0.5 * arma::log(S2) + - 0.5 * ((M * s.Omega) % M + S2 * arma::diagmat(s.Omega)), 1) + + 0.5 * std::real(arma::log_det(s.Omega)) + ki(Y); + } + + static Rcpp::List output_cov(const arma::mat & /*M*/, const arma::mat & /*S2*/, + const arma::vec & /*w*/, double /*w_bar*/, const State & s) { + return Rcpp::List::create(Rcpp::Named("Sigma", s.Sigma), Rcpp::Named("Omega", s.Omega)); + } + + static constexpr bool has_em = true; +}; + +// ───────────────────────────────────────────────────────────────────────────── +// Diagonal covariance +// ───────────────────────────────────────────────────────────────────────────── +struct DiagonalCovTraits { + struct State { + arma::rowvec omega2; + arma::rowvec sigma2; + + State(const arma::mat & M, const arma::mat & S2, const arma::vec & w, double w_bar) { + sigma2 = (w.t() * (M % M + S2)) / w_bar; + omega2 = arma::pow(sigma2, -1); + } + }; + + static arma::mat cov_diag(const State & s, const arma::mat & ones_row) { + return ones_row * s.omega2; + } + + static void grad_hess_M( + const arma::mat & M, const State & s, + const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & ones_row, + arma::mat & grad_M, arma::mat & hess_M) + { + grad_M = M.each_row() % s.omega2 + A - Y; grad_M.each_col() %= w; + hess_M = ones_row * s.omega2 + A; hess_M.each_col() %= w; + } + + static double penalty_M(const arma::mat & M, const State & s, const arma::vec & w) { + return 0.5 * arma::as_scalar((w.t() * (M % M)) * s.omega2.t()); + } + + static double objective_cov(const arma::mat & M, const arma::mat & S2, const State & s, const arma::vec & w) { + return 0.5 * arma::as_scalar((w.t() * (M % M + S2)) * s.omega2.t()); + } + + static void mstep(State & s, const arma::mat & M, const arma::mat & S2, + const arma::vec & w, double w_bar, arma::uword /*p*/) { + s.sigma2 = (w.t() * (M % M + S2)) / w_bar; + s.omega2 = arma::pow(s.sigma2, -1); + } + + static double elbo_cov(const State & s, double w_bar, arma::uword /*p*/) { + return -0.5 * w_bar * arma::accu(arma::log(s.sigma2)); + } + + static arma::vec final_loglik(const arma::mat & Y, const arma::mat & Z, const arma::mat & A, + const arma::mat & M, const arma::mat & S2, const State & s) { + arma::vec omega2_v = s.omega2.t(); + return arma::sum(Y % Z - A + 0.5 * arma::log(S2), 1) + - 0.5 * (M % M + S2) * omega2_v + + 0.5 * arma::accu(arma::log(omega2_v)) + ki(Y); + } + + static Rcpp::List output_cov(const arma::mat & /*M*/, const arma::mat & /*S2*/, + const arma::vec & /*w*/, double /*w_bar*/, const State & s) { + arma::uword p = s.omega2.n_elem; + arma::sp_mat Sigma_out(p, p); Sigma_out.diag() = s.sigma2.t(); + arma::sp_mat Omega_out(p, p); Omega_out.diag() = s.omega2.t(); + return Rcpp::List::create(Rcpp::Named("Sigma", Sigma_out), Rcpp::Named("Omega", Omega_out)); + } + + static constexpr bool has_em = true; +}; + +// ───────────────────────────────────────────────────────────────────────────── +// Spherical covariance (scalar sigma²) +// ───────────────────────────────────────────────────────────────────────────── +struct SphericalCovTraits { + struct State { + double omega2; + double sigma2; + + State(const arma::mat & M, const arma::mat & S2, const arma::vec & w, double w_bar) { + arma::uword p = M.n_cols; + sigma2 = arma::accu(arma::diagmat(w) * (M % M + S2)) / (double(p) * w_bar); + omega2 = 1.0 / sigma2; + } + }; + + // returns double: fixed_point_logS handles scalar broadcast + static double cov_diag(const State & s, const arma::mat & /*ones_row*/) { + return s.omega2; + } + + static void grad_hess_M( + const arma::mat & M, const State & s, + const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & /*ones_row*/, + arma::mat & grad_M, arma::mat & hess_M) + { + grad_M = s.omega2 * M + A - Y; grad_M.each_col() %= w; + hess_M = s.omega2 + A; hess_M.each_col() %= w; + } + + static double penalty_M(const arma::mat & M, const State & s, const arma::vec & w) { + return 0.5 * s.omega2 * arma::as_scalar(w.t() * arma::sum(M % M, 1)); + } + + static double objective_cov(const arma::mat & M, const arma::mat & S2, const State & s, const arma::vec & w) { + return 0.5 * s.omega2 * arma::accu(arma::diagmat(w) * (M % M + S2)); + } + + static void mstep(State & s, const arma::mat & M, const arma::mat & S2, + const arma::vec & w, double w_bar, arma::uword p) { + s.sigma2 = arma::accu(arma::diagmat(w) * (M % M + S2)) / (double(p) * w_bar); + s.omega2 = 1.0 / s.sigma2; + } + + static double elbo_cov(const State & s, double w_bar, arma::uword p) { + return -0.5 * w_bar * double(p) * std::log(s.sigma2); + } + + static arma::vec final_loglik(const arma::mat & Y, const arma::mat & Z, const arma::mat & A, + const arma::mat & M, const arma::mat & S2, const State & s) { + return arma::sum(Y % Z - A - 0.5 * (M % M + S2) / s.sigma2 + 0.5 * arma::log(S2 / s.sigma2), 1) + + ki(Y); + } + + static Rcpp::List output_cov(const arma::mat & M, const arma::mat & /*S2*/, + const arma::vec & /*w*/, double /*w_bar*/, const State & s) { + arma::uword p = M.n_cols; + arma::sp_mat Sigma_out(p, p); Sigma_out.diag() = arma::ones(p) * s.sigma2; + arma::sp_mat Omega_out(p, p); Omega_out.diag() = arma::ones(p) * s.omega2; + return Rcpp::List::create(Rcpp::Named("Sigma", Sigma_out), Rcpp::Named("Omega", Omega_out)); + } + + static constexpr bool has_em = true; +}; + +// ───────────────────────────────────────────────────────────────────────────── +// Fixed covariance (Omega provided externally, not estimated) +// ───────────────────────────────────────────────────────────────────────────── +struct FixedCovTraits { + struct State { + arma::mat Omega; + arma::vec diag_Omega; + + explicit State(const arma::mat & omega) + : Omega(omega), diag_Omega(arma::diagvec(omega)) {} + }; + + static arma::mat cov_diag(const State & s, const arma::mat & ones_row) { + return ones_row * s.diag_Omega.t(); + } + + static void grad_hess_M( + const arma::mat & M, const State & s, + const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & ones_row, + arma::mat & grad_M, arma::mat & hess_M) + { + arma::mat MO = M * s.Omega; + grad_M = MO + A - Y; grad_M.each_col() %= w; + hess_M = A + ones_row * s.diag_Omega.t(); hess_M.each_col() %= w; + } + + static double penalty_M(const arma::mat & M, const State & s, const arma::vec & w) { + arma::mat MO = M * s.Omega; + return 0.5 * arma::as_scalar(w.t() * arma::sum(MO % M, 1)); + } + + static double objective_cov(const arma::mat & M, const arma::mat & S2, const State & s, const arma::vec & w) { + arma::mat MO = M * s.Omega; + return 0.5 * (arma::as_scalar(w.t() * arma::sum(MO % M, 1)) + + arma::dot(s.diag_Omega, (w.t() * S2).t())); + } + + static void mstep(State & /*s*/, const arma::mat & /*M*/, const arma::mat & /*S2*/, + const arma::vec & /*w*/, double /*w_bar*/, arma::uword /*p*/) {} + + static double elbo_cov(const State & /*s*/, double /*w_bar*/, arma::uword /*p*/) { + return 0.0; + } + + static arma::vec final_loglik(const arma::mat & Y, const arma::mat & Z, const arma::mat & A, + const arma::mat & M, const arma::mat & S2, const State & s) { + return arma::sum(Y % Z - A + 0.5 * arma::log(S2) + - 0.5 * ((M * s.Omega) % M + S2 * arma::diagmat(s.Omega)), 1) + + 0.5 * std::real(arma::log_det(s.Omega)) + ki(Y); + } + + static Rcpp::List output_cov(const arma::mat & M, const arma::mat & S2, + const arma::vec & w, double w_bar, const State & s) { + arma::mat Sigma = (M.t() * (M.each_col() % w) + arma::diagmat(w.t() * S2)) / w_bar; + return Rcpp::List::create(Rcpp::Named("Sigma", Sigma), Rcpp::Named("Omega", s.Omega)); + } + + static constexpr bool has_em = false; +}; diff --git a/src/newton_impl.h b/src/newton_impl.h new file mode 100644 index 00000000..7f2c1ea5 --- /dev/null +++ b/src/newton_impl.h @@ -0,0 +1,115 @@ +#pragma once +#include +#include "utils.h" +#include "CovarianceTraits.h" + +// Generic coordinate-Newton EM optimizer for PLN covariance variants. +// Traits encodes the variant-specific math (M grad/hess, M-step, ELBO, loglik). +// has_em=true → double EM+inner loop; has_em=false → single inner loop (fixed cov). +template +Rcpp::List newton_optimize_impl( + const arma::mat & Y, const arma::mat & X, const arma::mat & O, const arma::vec & w, + arma::mat B, arma::mat M, arma::mat S, + typename Traits::State state, + int maxiter, double ftol, int max_em, double em_tol +) { + const int n = Y.n_rows; + const arma::uword p = Y.n_cols; + const double w_bar = arma::accu(w); + const double c1 = 1e-4; + + const arma::mat Xw = X.each_col() % w; + arma::mat Xw2 = X % X; Xw2.each_col() %= w; + const arma::mat ones_row = arma::ones(n, 1); + + arma::mat S2 = S % S; + arma::mat logS = arma::log(S); + + std::vector objective_vec; + double elbo_prev = -arma::datum::inf; + int total_iter = 0; + int last_status = 5; + + auto inner_loop = [&]() { + double obj_prev = arma::datum::inf; + for (int it = 0; it < maxiter; it++) { + S2 = S % S; + arma::mat Z = O + X * B + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + + newton_step_B(Xw, Xw2, X, Y, O, w, M, S2, B, Z, A); + + arma::mat grad_M, hess_M; + Traits::grad_hess_M(M, state, A, Y, w, ones_row, grad_M, hess_M); + hess_M.clamp(1e-10, arma::datum::inf); + arma::mat step_M = grad_M / hess_M; + double f0_M = arma::accu(w.t() * (A - Y % Z)) + Traits::penalty_M(M, state, w); + double slope_M = -arma::accu(grad_M % step_M); + double alpha_M = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Mt = M - alpha_M * step_M; + arma::mat Zt = Z - alpha_M * step_M; + arma::mat At = arma::exp(Zt + 0.5 * S2); + if (arma::accu(w.t() * (At - Y % Zt)) + Traits::penalty_M(Mt, state, w) + <= f0_M + c1 * alpha_M * slope_M) break; + alpha_M *= 0.5; + } + M -= alpha_M * step_M; + Z = O + X * B + M; + + fixed_point_logS(logS, S, S2, Z, A, Traits::cov_diag(state, ones_row)); + + A = arma::exp(Z + 0.5 * S2); + double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) + + Traits::objective_cov(M, S2, state, w); + objective_vec.push_back(obj); + total_iter++; + + if (it > 0 && converged(obj, obj_prev, ftol)) { last_status = 3; break; } + obj_prev = obj; + } + }; + + if (Traits::has_em) { + for (int em = 0; em < max_em; em++) { + inner_loop(); + + S2 = S % S; + Traits::mstep(state, M, S2, w, w_bar, p); + + arma::mat Z = O + X * B + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * arma::trunc_log(S2))) + + Traits::elbo_cov(state, w_bar, p); + if (em > 0 && converged(elbo, elbo_prev, em_tol)) { last_status = 3; break; } + elbo_prev = elbo; + } + } else { + inner_loop(); + } + + S2 = S % S; + arma::mat Z = O + X * B + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + arma::vec loglik = Traits::final_loglik(Y, Z, A, M, S2, state); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + Rcpp::List cov_out = Traits::output_cov(M, S2, w, w_bar, state); + return Rcpp::List::create( + Rcpp::Named("B", B ), + Rcpp::Named("M", M ), + Rcpp::Named("S", S ), + Rcpp::Named("Z", Z ), + Rcpp::Named("A", A ), + Rcpp::Named("Sigma", cov_out["Sigma"]), + Rcpp::Named("Omega", cov_out["Omega"]), + Rcpp::Named("Ji", Ji ), + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", last_status ), + Rcpp::Named("backend", "newton" ), + Rcpp::Named("objective", objective_vec ), + Rcpp::Named("iterations", total_iter ) + )) + ); +} diff --git a/src/optim_diag_cov.cpp b/src/optim_diag_cov.cpp index 5a8d77d6..f94a8657 100644 --- a/src/optim_diag_cov.cpp +++ b/src/optim_diag_cov.cpp @@ -6,6 +6,7 @@ #include "nlopt_wrapper.h" #include "packing.h" #include "utils.h" +#include "newton_impl.h" // --------------------------------------------------------------------------------------- // Diagonal covariance @@ -118,120 +119,16 @@ Rcpp::List nlopt_optimize_newton_diagonal( arma::mat M = Rcpp::as(params["M"]); arma::mat S = Rcpp::as(params["S"]); - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; - const double em_tol= config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; + const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; - const int n = Y.n_rows; - const arma::uword p = Y.n_cols; const double w_bar = arma::accu(w); - const double c1 = 1e-4; - - const arma::mat Xw = X.each_col() % w; - arma::mat Xw2 = X % X; Xw2.each_col() %= w; - const arma::mat ones_row = arma::ones(n, 1); - - // Initial omega2 from starting M, S - arma::mat S2 = S % S; - arma::rowvec sigma2 = (w.t() * (M % M + S2)) / w_bar; - arma::rowvec omega2 = arma::pow(sigma2, -1); - arma::mat logS = arma::log(S); - - std::vector objective_vec; - double elbo_prev = -arma::datum::inf; - int total_iter = 0; - int last_status = 5; - - for (int em = 0; em < max_em; em++) { - double obj_prev = arma::datum::inf; - - for (int it = 0; it < maxiter; it++) { - S2 = S % S; - arma::mat Z = O + X * B + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - - // ---- Diagonal Newton step for B ---- - newton_step_B(Xw, Xw2, X, Y, O, w, M, S2, B, Z, A); - - // ---- Diagonal Newton step for M ---- - arma::mat grad_M = M.each_row() % omega2 + A - Y; grad_M.each_col() %= w; - arma::mat hess_M = ones_row * omega2 + A; hess_M.each_col() %= w; - hess_M.clamp(1e-10, arma::datum::inf); - arma::mat step_M = grad_M / hess_M; - double f0_M = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::as_scalar((w.t() * (M % M)) * omega2.t()); - double slope_M = -arma::accu(grad_M % step_M); - double alpha_M = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; - arma::mat Zt = Z - alpha_M * step_M; - arma::mat At = arma::exp(Zt + 0.5 * S2); - if (arma::accu(w.t() * (At - Y % Zt)) - + 0.5 * arma::as_scalar((w.t() * (Mt % Mt)) * omega2.t()) - <= f0_M + c1 * alpha_M * slope_M) break; - alpha_M *= 0.5; - } - M -= alpha_M * step_M; - Z = O + X * B + M; - - // ---- Fixed-point update for logS (overflow-safe) ---- - fixed_point_logS(logS, S, S2, Z, A, ones_row * omega2); - - // ---- Objective for inner convergence ---- - A = arma::exp(Z + 0.5 * S2); - double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) - + 0.5 * arma::as_scalar((w.t() * (M % M + S2)) * omega2.t()); - objective_vec.push_back(obj); - total_iter++; - - if (it > 0 && converged(obj, obj_prev, ftol)) { last_status = 3; break; } - obj_prev = obj; - } - - // ---- M-step: update sigma2 analytically ---- - S2 = S % S; - sigma2 = (w.t() * (M % M + S2)) / w_bar; - omega2 = arma::pow(sigma2, -1); - - // ---- Outer EM convergence on ELBO ---- - arma::mat Z = O + X * B + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * arma::trunc_log(S2))) - - 0.5 * w_bar * arma::accu(arma::log(sigma2)); - if (em > 0 && converged(elbo, elbo_prev, em_tol)) { last_status = 3; break; } - elbo_prev = elbo; - } - - // ---- Final output ---- - S2 = S % S; - arma::vec omega2_v = omega2.t(); - arma::sp_mat Sigma_out(p, p); Sigma_out.diag() = sigma2.t(); - arma::sp_mat Omega_out(p, p); Omega_out.diag() = omega2_v; - arma::mat Z = O + X * B + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - arma::mat loglik = arma::sum(Y % Z - A + 0.5 * arma::log(S2), 1) - - 0.5 * (M % M + S2) * omega2_v - + 0.5 * arma::accu(arma::log(omega2_v)) + ki(Y); + arma::mat S2 = S % S; + DiagonalCovTraits::State state(M, S2, w, w_bar); - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("B", B ), - Rcpp::Named("Sigma", Sigma_out), - Rcpp::Named("Omega", Omega_out), - Rcpp::Named("M", M ), - Rcpp::Named("S", S ), - Rcpp::Named("Z", Z ), - Rcpp::Named("A", A ), - Rcpp::Named("Ji", Ji ), - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", last_status ), - Rcpp::Named("backend", "newton" ), - Rcpp::Named("objective", objective_vec ), - Rcpp::Named("iterations", total_iter ) - )) - ); + return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); } // --------------------------------------------------------------------------------------- diff --git a/src/optim_fixed_cov.cpp b/src/optim_fixed_cov.cpp index d37d496b..e87959b1 100644 --- a/src/optim_fixed_cov.cpp +++ b/src/optim_fixed_cov.cpp @@ -6,6 +6,7 @@ #include "nlopt_wrapper.h" #include "packing.h" #include "utils.h" +#include "newton_impl.h" // --------------------------------------------------------------------------------------- // Fixed inverse covariance (Omega) @@ -19,109 +20,21 @@ Rcpp::List nlopt_optimize_newton_fixed( const Rcpp::List & params, // List(B, M, S, Omega) const Rcpp::List & config // List of config values ) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); - const arma::mat Omega = Rcpp::as(params["Omega"]); - - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - - const int n = Y.n_rows; - const double w_bar = arma::accu(w); - const double c1 = 1e-4; - - const arma::mat Xw = X.each_col() % w; - arma::mat Xw2 = X % X; Xw2.each_col() %= w; - const arma::vec diag_Omega = arma::diagvec(Omega); - const arma::mat ones_row = arma::ones(n, 1); - - arma::mat S2 = S % S; - arma::mat logS = arma::log(S); - - std::vector objective_vec; - double obj_prev = arma::datum::inf; - int total_iter = 0; - int last_status = 5; - - for (int it = 0; it < maxiter; it++) { - S2 = S % S; - arma::mat Z = O + X * B + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - - // ---- Diagonal Newton step for B ---- - newton_step_B(Xw, Xw2, X, Y, O, w, M, S2, B, Z, A); - - // ---- Diagonal Newton step for M ---- - arma::mat MO = M * Omega; - arma::mat grad_M = MO + A - Y; grad_M.each_col() %= w; - arma::mat hess_M = A + ones_row * diag_Omega.t(); - hess_M.each_col() %= w; - hess_M.clamp(1e-10, arma::datum::inf); - arma::mat step_M = grad_M / hess_M; - double f0_M = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::accu(MO % (M.each_col() % w)); - double slope_M = -arma::accu(grad_M % step_M); - double alpha_M = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; - arma::mat Zt = Z - alpha_M * step_M; - arma::mat At = arma::exp(Zt + 0.5 * S2); - arma::mat MOt = Mt * Omega; - if (arma::accu(w.t() * (At - Y % Zt)) - + 0.5 * arma::accu(MOt % (Mt.each_col() % w)) - <= f0_M + c1 * alpha_M * slope_M) break; - alpha_M *= 0.5; - } - M -= alpha_M * step_M; - MO = M * Omega; - Z = O + X * B + M; - - // ---- Fixed-point update for logS (overflow-safe) ---- - fixed_point_logS(logS, S, S2, Z, A, ones_row * diag_Omega.t()); - - // ---- Objective for convergence ---- - A = arma::exp(Z + 0.5 * S2); - double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) - + 0.5 * (arma::accu(MO % (M.each_col() % w)) - + arma::dot(diag_Omega, (w.t() * S2).t())); - objective_vec.push_back(obj); - total_iter++; - - if (it > 0 && converged(obj, obj_prev, ftol)) { last_status = 3; break; } - obj_prev = obj; - } - - // ---- Final output ---- - S2 = S % S; - arma::mat Sigma = (M.t() * (M.each_col() % w) + arma::diagmat(w.t() * S2)) / w_bar; - arma::mat Z = O + X * B + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - arma::vec loglik = arma::sum(Y % Z - A - 0.5 * ((M * Omega) % M - arma::log(S2) + S2 * arma::diagmat(Omega)), 1) - + 0.5 * std::real(arma::log_det(Omega)) + ki(Y); + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + const arma::mat Omega = Rcpp::as(params["Omega"]); - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("B", B ), - Rcpp::Named("M", M ), - Rcpp::Named("S", S ), - Rcpp::Named("Z", Z ), - Rcpp::Named("A", A ), - Rcpp::Named("Sigma", Sigma), - Rcpp::Named("Omega", Omega), - Rcpp::Named("Ji", Ji ), - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", last_status ), - Rcpp::Named("backend", "newton" ), - Rcpp::Named("objective", objective_vec ), - Rcpp::Named("iterations", total_iter ) - )) - ); + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + + FixedCovTraits::State state(Omega); + + return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, 1, 0.0); } // --------------------------------------------------------------------------------------- diff --git a/src/optim_full_cov.cpp b/src/optim_full_cov.cpp index 0438beb8..2592ee09 100644 --- a/src/optim_full_cov.cpp +++ b/src/optim_full_cov.cpp @@ -6,6 +6,7 @@ #include "nlopt_wrapper.h" #include "packing.h" #include "utils.h" +#include "newton_impl.h" // --------------------------------------------------------------------------------------- // Fully parametrized covariance @@ -142,132 +143,24 @@ Rcpp::List nlopt_optimize_newton( const Rcpp::List & params, // List(B, M, S) const Rcpp::List & config // List of config values ) { - const arma::mat & Y = Rcpp::as(data["Y"]); // (n,p) - const arma::mat & X = Rcpp::as(data["X"]); // (n,d) - const arma::mat & O = Rcpp::as(data["O"]); // (n,p) - const arma::vec & w = Rcpp::as(data["w"]); // (n) - arma::mat B = Rcpp::as(params["B"]); // (d,p) - arma::mat M = Rcpp::as(params["M"]); // (n,p) - arma::mat S = Rcpp::as(params["S"]); // (n,p), >0 - - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; - const double em_tol= config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; - - const int n = Y.n_rows; - const double w_bar = arma::accu(w); - const double c1 = 1e-4; - - // Precompute weighted X matrices (fixed throughout) - const arma::mat Xw = X.each_col() % w; // (n,d) X_ik * w_i - arma::mat Xw2 = X % X; Xw2.each_col() %= w; // (n,d) X_ik^2 * w_i - - // Initial Omega from starting M, S - arma::mat S2 = S % S; - arma::mat Sigma = (1./w_bar) * (M.t() * (M.each_col() % w) + arma::diagmat(w.t() * S2)); - arma::mat Omega = arma::inv_sympd(Sigma); - arma::mat logS = arma::log(S); - - std::vector objective_vec; - double elbo_prev = -arma::datum::inf; - int total_iter = 0; - int last_status = 5; // maxiter reached by default - - for (int em = 0; em < max_em; em++) { - const arma::vec diag_Omega = arma::diagvec(Omega); - const arma::mat ones_row = arma::ones(n, 1); - - double obj_prev = arma::datum::inf; - - for (int it = 0; it < maxiter; it++) { - S2 = S % S; - arma::mat Z = O + X * B + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - - // ---- Diagonal Newton step for B ---- - newton_step_B(Xw, Xw2, X, Y, O, w, M, S2, B, Z, A); - - // ---- Diagonal Newton step for M ---- - arma::mat MO = M * Omega; // (n,p) - arma::mat grad_M = MO + A - Y; grad_M.each_col() %= w; // (n,p) - arma::mat hess_M = A + ones_row * diag_Omega.t(); - hess_M.each_col() %= w; - hess_M.clamp(1e-10, arma::datum::inf); - arma::mat step_M = grad_M / hess_M; - double f0_M = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::accu(MO % (M.each_col() % w)); - double slope_M = -arma::accu(grad_M % step_M); - double alpha_M = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; - arma::mat Zt = Z - alpha_M * step_M; - arma::mat At = arma::exp(Zt + 0.5 * S2); - arma::mat MOt = Mt * Omega; - if (arma::accu(w.t() * (At - Y % Zt)) - + 0.5 * arma::accu(MOt % (Mt.each_col() % w)) - <= f0_M + c1 * alpha_M * slope_M) break; - alpha_M *= 0.5; - } - M -= alpha_M * step_M; - MO = M * Omega; - Z = O + X * B + M; - - // ---- Fixed-point update for logS (overflow-safe) ---- - fixed_point_logS(logS, S, S2, Z, A, ones_row * diag_Omega.t()); - - // ---- Objective for inner convergence ---- - A = arma::exp(Z + 0.5 * S2); - double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) - + 0.5 * (arma::accu(MO % (M.each_col() % w)) - + arma::dot(diag_Omega, (w.t() * S2).t())); - objective_vec.push_back(obj); - total_iter++; - - if (it > 0 && converged(obj, obj_prev, ftol)) { last_status = 3; break; } - obj_prev = obj; - } + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); - // ---- M-step: update Omega analytically ---- - S2 = S % S; - Sigma = (1./w_bar) * (M.t() * (M.each_col() % w) + arma::diagmat(w.t() * S2)); - Omega = arma::inv_sympd(Sigma); - - // ---- Outer EM convergence on ELBO ---- - arma::mat Z = O + X * B + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * arma::trunc_log(S2))) - - 0.5 * w_bar * real(arma::log_det(Sigma)); - if (em > 0 && converged(elbo, elbo_prev, em_tol)) { last_status = 3; break; } - elbo_prev = elbo; - } + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; + const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; - // ---- Final output ---- - S2 = S % S; - arma::mat Z = O + X * B + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - arma::vec loglik = arma::sum(Y % Z - A + 0.5 * arma::log(S2) - - 0.5 * ((M * Omega) % M + S2 * arma::diagmat(Omega)), 1) - + 0.5 * real(arma::log_det(Omega)) + ki(Y); + const double w_bar = arma::accu(w); + arma::mat S2 = S % S; + FullCovTraits::State state(M, S2, w, w_bar); - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("B", B ), - Rcpp::Named("M", M ), - Rcpp::Named("S", S ), - Rcpp::Named("Z", Z ), - Rcpp::Named("A", A ), - Rcpp::Named("Sigma", Sigma), - Rcpp::Named("Omega", Omega), - Rcpp::Named("Ji", Ji ), - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", last_status ), - Rcpp::Named("backend", "newton" ), - Rcpp::Named("objective", objective_vec ), - Rcpp::Named("iterations", total_iter ) - )) - ); + return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); } // --------------------------------------------------------------------------------------- diff --git a/src/optim_spherical.cpp b/src/optim_spherical.cpp index 1620f63b..3671ea85 100644 --- a/src/optim_spherical.cpp +++ b/src/optim_spherical.cpp @@ -6,6 +6,7 @@ #include "nlopt_wrapper.h" #include "packing.h" #include "utils.h" +#include "newton_impl.h" // --------------------------------------------------------------------------------------- // Spherical covariance @@ -116,118 +117,16 @@ Rcpp::List nlopt_optimize_newton_spherical( arma::mat M = Rcpp::as(params["M"]); arma::mat S = Rcpp::as(params["S"]); - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; - const double em_tol= config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; + const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; - const int n = Y.n_rows; - const arma::uword p = Y.n_cols; const double w_bar = arma::accu(w); - const double c1 = 1e-4; - - const arma::mat Xw = X.each_col() % w; - arma::mat Xw2 = X % X; Xw2.each_col() %= w; - const arma::mat ones_row = arma::ones(n, 1); - - // Initial omega2 (scalar) from starting M, S - arma::mat S2 = S % S; - double sigma2 = arma::accu(arma::diagmat(w) * (M % M + S2)) / (double(p) * w_bar); - double omega2 = 1.0 / sigma2; - arma::mat logS = arma::log(S); - - std::vector objective_vec; - double elbo_prev = -arma::datum::inf; - int total_iter = 0; - int last_status = 5; - - for (int em = 0; em < max_em; em++) { - double obj_prev = arma::datum::inf; - - for (int it = 0; it < maxiter; it++) { - S2 = S % S; - arma::mat Z = O + X * B + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - - // ---- Diagonal Newton step for B ---- - newton_step_B(Xw, Xw2, X, Y, O, w, M, S2, B, Z, A); - - // ---- Diagonal Newton step for M (scalar omega2 broadcast) ---- - arma::mat grad_M = omega2 * M + A - Y; grad_M.each_col() %= w; - arma::mat hess_M = omega2 + A; hess_M.each_col() %= w; - hess_M.clamp(1e-10, arma::datum::inf); - arma::mat step_M = grad_M / hess_M; - double f0_M = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * omega2 * arma::as_scalar(w.t() * arma::sum(M % M, 1)); - double slope_M = -arma::accu(grad_M % step_M); - double alpha_M = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; - arma::mat Zt = Z - alpha_M * step_M; - arma::mat At = arma::exp(Zt + 0.5 * S2); - if (arma::accu(w.t() * (At - Y % Zt)) - + 0.5 * omega2 * arma::as_scalar(w.t() * arma::sum(Mt % Mt, 1)) - <= f0_M + c1 * alpha_M * slope_M) break; - alpha_M *= 0.5; - } - M -= alpha_M * step_M; - Z = O + X * B + M; - - // ---- Fixed-point update for logS (overflow-safe) ---- - fixed_point_logS(logS, S, S2, Z, A, omega2); - - // ---- Objective for inner convergence ---- - A = arma::exp(Z + 0.5 * S2); - double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) - + 0.5 * omega2 * arma::accu(arma::diagmat(w) * (M % M + S2)); - objective_vec.push_back(obj); - total_iter++; - - if (it > 0 && converged(obj, obj_prev, ftol)) { last_status = 3; break; } - obj_prev = obj; - } - - // ---- M-step: update sigma2 analytically ---- - S2 = S % S; - sigma2 = arma::accu(arma::diagmat(w) * (M % M + S2)) / (double(p) * w_bar); - omega2 = 1.0 / sigma2; - - // ---- Outer EM convergence on ELBO ---- - arma::mat Z = O + X * B + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * arma::trunc_log(S2))) - - 0.5 * w_bar * double(p) * std::log(sigma2); - if (em > 0 && converged(elbo, elbo_prev, em_tol)) { last_status = 3; break; } - elbo_prev = elbo; - } - - // ---- Final output ---- - S2 = S % S; - arma::sp_mat Sigma_out(p, p); Sigma_out.diag() = arma::ones(p) * sigma2; - arma::sp_mat Omega_out(p, p); Omega_out.diag() = arma::ones(p) * omega2; - arma::mat Z = O + X * B + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - arma::mat loglik = arma::sum(Y % Z - A - 0.5 * (M % M + S2) / sigma2 + 0.5 * arma::log(S2 / sigma2), 1) - + ki(Y); + arma::mat S2 = S % S; + SphericalCovTraits::State state(M, S2, w, w_bar); - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("B", B ), - Rcpp::Named("Sigma", Sigma_out), - Rcpp::Named("Omega", Omega_out), - Rcpp::Named("M", M ), - Rcpp::Named("S", S ), - Rcpp::Named("Z", Z ), - Rcpp::Named("A", A ), - Rcpp::Named("Ji", Ji ), - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", last_status ), - Rcpp::Named("backend", "newton" ), - Rcpp::Named("objective", objective_vec ), - Rcpp::Named("iterations", total_iter ) - )) - ); + return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); } // --------------------------------------------------------------------------------------- From 6f3ef0bfc93247c6f04777cfe0e81b7f2621a747 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Mon, 8 Jun 2026 22:27:19 +0200 Subject: [PATCH 10/58] newton for ve step in PLN variants --- R/PLNfit-class.R | 4 +- R/RcppExports.R | 8 ++++ src/RcppExports.cpp | 32 ++++++++++++++ src/optim_diag_cov.cpp | 98 +++++++++++++++++++++++++++++++++++++++++ src/optim_spherical.cpp | 96 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 236 insertions(+), 2 deletions(-) diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index 0dbda18e..2ba437df 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -751,7 +751,7 @@ PLNfit_diagonal <- R6Class( } else { nlopt_optimize_diagonal } - private$optimizer$vestep <- nlopt_optimize_vestep_diagonal + private$optimizer$vestep <- if (is_newton) nlopt_optimize_vestep_newton_diagonal else nlopt_optimize_vestep_diagonal } ), private = list( @@ -841,7 +841,7 @@ PLNfit_spherical <- R6Class( } else { nlopt_optimize_spherical } - private$optimizer$vestep <- nlopt_optimize_vestep_spherical + private$optimizer$vestep <- if (is_newton) nlopt_optimize_vestep_newton_spherical else nlopt_optimize_vestep_spherical } ), private = list( diff --git a/R/RcppExports.R b/R/RcppExports.R index 3a85f67e..ca99a6f9 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -13,6 +13,10 @@ nlopt_optimize_newton_diagonal <- function(data, params, config) { .Call('_PLNmodels_nlopt_optimize_newton_diagonal', PACKAGE = 'PLNmodels', data, params, config) } +nlopt_optimize_vestep_newton_diagonal <- function(data, params, B, Omega, config) { + .Call('_PLNmodels_nlopt_optimize_vestep_newton_diagonal', PACKAGE = 'PLNmodels', data, params, B, Omega, config) +} + nlopt_optimize_vestep_diagonal <- function(data, params, B, Omega, config) { .Call('_PLNmodels_nlopt_optimize_vestep_diagonal', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } @@ -61,6 +65,10 @@ nlopt_optimize_newton_spherical <- function(data, params, config) { .Call('_PLNmodels_nlopt_optimize_newton_spherical', PACKAGE = 'PLNmodels', data, params, config) } +nlopt_optimize_vestep_newton_spherical <- function(data, params, B, Omega, config) { + .Call('_PLNmodels_nlopt_optimize_vestep_newton_spherical', PACKAGE = 'PLNmodels', data, params, B, Omega, config) +} + nlopt_optimize_vestep_spherical <- function(data, params, B, Omega, config) { .Call('_PLNmodels_nlopt_optimize_vestep_spherical', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 3a6ac2ca..b5421a45 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -47,6 +47,21 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// nlopt_optimize_vestep_newton_diagonal +Rcpp::List nlopt_optimize_vestep_newton_diagonal(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_newton_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_vestep_newton_diagonal(data, params, B, Omega, config)); + return rcpp_result_gen; +END_RCPP +} // nlopt_optimize_vestep_diagonal Rcpp::List nlopt_optimize_vestep_diagonal(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -215,6 +230,21 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// nlopt_optimize_vestep_newton_spherical +Rcpp::List nlopt_optimize_vestep_newton_spherical(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_newton_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_vestep_newton_spherical(data, params, B, Omega, config)); + return rcpp_result_gen; +END_RCPP +} // nlopt_optimize_vestep_spherical Rcpp::List nlopt_optimize_vestep_spherical(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -476,6 +506,7 @@ static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_cpp_test_nlopt", (DL_FUNC) &_PLNmodels_cpp_test_nlopt, 0}, {"_PLNmodels_nlopt_optimize_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_diagonal, 3}, {"_PLNmodels_nlopt_optimize_newton_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_newton_diagonal, 3}, + {"_PLNmodels_nlopt_optimize_vestep_newton_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_newton_diagonal, 5}, {"_PLNmodels_nlopt_optimize_vestep_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_diagonal, 5}, {"_PLNmodels_nlopt_optimize_newton_fixed", (DL_FUNC) &_PLNmodels_nlopt_optimize_newton_fixed, 3}, {"_PLNmodels_nlopt_optimize_fixed", (DL_FUNC) &_PLNmodels_nlopt_optimize_fixed, 3}, @@ -488,6 +519,7 @@ static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_nlopt_optimize_vestep_rank", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_rank, 5}, {"_PLNmodels_nlopt_optimize_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_spherical, 3}, {"_PLNmodels_nlopt_optimize_newton_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_newton_spherical, 3}, + {"_PLNmodels_nlopt_optimize_vestep_newton_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_newton_spherical, 5}, {"_PLNmodels_nlopt_optimize_vestep_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_spherical, 5}, {"_PLNmodels_zipln_vloglik", (DL_FUNC) &_PLNmodels_zipln_vloglik, 9}, {"_PLNmodels_optim_zipln_Omega_full", (DL_FUNC) &_PLNmodels_optim_zipln_Omega_full, 4}, diff --git a/src/optim_diag_cov.cpp b/src/optim_diag_cov.cpp index f94a8657..63a853f6 100644 --- a/src/optim_diag_cov.cpp +++ b/src/optim_diag_cov.cpp @@ -131,6 +131,104 @@ Rcpp::List nlopt_optimize_newton_diagonal( return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); } +// --------------------------------------------------------------------------------------- +// VE diagonal — coordinate-Newton (M and S only, B and Omega fixed) + +// [[Rcpp::export]] +Rcpp::List nlopt_optimize_vestep_newton_diagonal( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(M, S) + const arma::mat & B, // (d,p) fixed + const arma::mat & Omega, // (p,p) diagonal, fixed + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + + const int n = Y.n_rows; + const double c1 = 1e-4; + const arma::rowvec omega2 = arma::diagvec(Omega).t(); + const arma::mat ones_row = arma::ones(n, 1); + const arma::mat XB = X * B; + + arma::mat logS = arma::log(S); + arma::mat S2 = S % S; + + std::vector objective_vec; + double obj_prev = arma::datum::inf; + int total_iter = 0; + + for (int it = 0; it < maxiter; it++) { + S2 = S % S; + arma::mat Z = O + XB + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + + // ---- Diagonal Newton step for M ---- + arma::mat grad_M = M.each_row() % omega2 + A - Y; grad_M.each_col() %= w; + arma::mat hess_M = ones_row * omega2 + A; hess_M.each_col() %= w; + hess_M.clamp(1e-10, arma::datum::inf); + arma::mat step_M = grad_M / hess_M; + double f0_M = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * arma::as_scalar((w.t() * (M % M)) * omega2.t()); + double slope_M = -arma::accu(grad_M % step_M); + double alpha_M = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Mt = M - alpha_M * step_M; + arma::mat Zt = Z - alpha_M * step_M; + arma::mat At = arma::exp(Zt + 0.5 * S2); + if (arma::accu(w.t() * (At - Y % Zt)) + + 0.5 * arma::as_scalar((w.t() * (Mt % Mt)) * omega2.t()) + <= f0_M + c1 * alpha_M * slope_M) break; + alpha_M *= 0.5; + } + M -= alpha_M * step_M; + Z = O + XB + M; + + // ---- Fixed-point update for logS ---- + fixed_point_logS(logS, S, S2, Z, A, ones_row * omega2); + + // ---- Objective for convergence ---- + A = arma::exp(Z + 0.5 * S2); + double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) + + 0.5 * arma::as_scalar((w.t() * (M % M + S2)) * omega2.t()); + objective_vec.push_back(obj); + total_iter++; + + if (it > 0 && converged(obj, obj_prev, ftol)) break; + obj_prev = obj; + } + + // ---- Final output ---- + S2 = S % S; + arma::mat Z = O + XB + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + arma::vec omega2_v = omega2.t(); + arma::vec loglik = arma::sum(Y % Z - A + 0.5 * arma::log(S2), 1) + - 0.5 * (M % M + S2) * omega2_v + + 0.5 * arma::accu(arma::log(omega2_v)) + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("M") = M, + Rcpp::Named("S") = S, + Rcpp::Named("Ji") = Ji, + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", 3 ), + Rcpp::Named("backend", "newton" ), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", total_iter ) + )) + ); +} + // --------------------------------------------------------------------------------------- // VE diagonal diff --git a/src/optim_spherical.cpp b/src/optim_spherical.cpp index 3671ea85..6c1ac8cd 100644 --- a/src/optim_spherical.cpp +++ b/src/optim_spherical.cpp @@ -129,6 +129,102 @@ Rcpp::List nlopt_optimize_newton_spherical( return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); } +// --------------------------------------------------------------------------------------- +// VE spherical — coordinate-Newton (M and S only, B and Omega fixed) + +// [[Rcpp::export]] +Rcpp::List nlopt_optimize_vestep_newton_spherical( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(M, S) + const arma::mat & B, // (d,p) fixed + const arma::mat & Omega, // (p,p) diagonal scalar, fixed + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + + const int n = Y.n_rows; + const double c1 = 1e-4; + const double omega2 = Omega(0, 0); + const arma::mat XB = X * B; + + arma::mat logS = arma::log(S); + arma::mat S2 = S % S; + + std::vector objective_vec; + double obj_prev = arma::datum::inf; + int total_iter = 0; + + for (int it = 0; it < maxiter; it++) { + S2 = S % S; + arma::mat Z = O + XB + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + + // ---- Diagonal Newton step for M (scalar omega2 broadcast) ---- + arma::mat grad_M = omega2 * M + A - Y; grad_M.each_col() %= w; + arma::mat hess_M = omega2 + A; hess_M.each_col() %= w; + hess_M.clamp(1e-10, arma::datum::inf); + arma::mat step_M = grad_M / hess_M; + double f0_M = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * omega2 * arma::as_scalar(w.t() * arma::sum(M % M, 1)); + double slope_M = -arma::accu(grad_M % step_M); + double alpha_M = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Mt = M - alpha_M * step_M; + arma::mat Zt = Z - alpha_M * step_M; + arma::mat At = arma::exp(Zt + 0.5 * S2); + if (arma::accu(w.t() * (At - Y % Zt)) + + 0.5 * omega2 * arma::as_scalar(w.t() * arma::sum(Mt % Mt, 1)) + <= f0_M + c1 * alpha_M * slope_M) break; + alpha_M *= 0.5; + } + M -= alpha_M * step_M; + Z = O + XB + M; + + // ---- Fixed-point update for logS (scalar cov_diag) ---- + fixed_point_logS(logS, S, S2, Z, A, omega2); + + // ---- Objective for convergence ---- + A = arma::exp(Z + 0.5 * S2); + double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) + + 0.5 * omega2 * arma::accu(arma::diagmat(w) * (M % M + S2)); + objective_vec.push_back(obj); + total_iter++; + + if (it > 0 && converged(obj, obj_prev, ftol)) break; + obj_prev = obj; + } + + // ---- Final output ---- + S2 = S % S; + const double sigma2 = 1.0 / omega2; + arma::mat Z = O + XB + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + arma::vec loglik = arma::sum(Y % Z - A - 0.5 * (M % M + S2) / sigma2 + 0.5 * arma::log(S2 / sigma2), 1) + + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("M") = M, + Rcpp::Named("S") = S, + Rcpp::Named("Ji") = Ji, + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", 3 ), + Rcpp::Named("backend", "newton" ), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", total_iter ) + )) + ); +} + // --------------------------------------------------------------------------------------- // VE spherical From bf20ba8ec522bdbd124a6cf268ca205f60923eae Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Mon, 8 Jun 2026 22:40:57 +0200 Subject: [PATCH 11/58] separate nlopt from newton solver for readability --- R/PLNfit-class.R | 16 +- R/RcppExports.R | 72 +++--- src/RcppExports.cpp | 214 +++++++++--------- src/newton_diag_cov.cpp | 133 +++++++++++ src/newton_fixed_cov.cpp | 34 +++ src/newton_full_cov.cpp | 140 ++++++++++++ src/newton_spherical.cpp | 131 +++++++++++ ...{optim_diag_cov.cpp => nlopt_diag_cov.cpp} | 134 +---------- ...ptim_fixed_cov.cpp => nlopt_fixed_cov.cpp} | 33 +-- ...{optim_full_cov.cpp => nlopt_full_cov.cpp} | 143 +----------- ...ptim_spherical.cpp => nlopt_spherical.cpp} | 131 +---------- 11 files changed, 598 insertions(+), 583 deletions(-) create mode 100644 src/newton_diag_cov.cpp create mode 100644 src/newton_fixed_cov.cpp create mode 100644 src/newton_full_cov.cpp create mode 100644 src/newton_spherical.cpp rename src/{optim_diag_cov.cpp => nlopt_diag_cov.cpp} (57%) rename src/{optim_fixed_cov.cpp => nlopt_fixed_cov.cpp} (73%) rename src/{optim_full_cov.cpp => nlopt_full_cov.cpp} (62%) rename src/{optim_spherical.cpp => nlopt_spherical.cpp} (58%) diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index 2ba437df..079d05fe 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -364,11 +364,11 @@ PLNfit <- R6Class( private$optimizer$main <- if (control$backend == "torch") { private$torch_optimize } else if (is_newton) { - nlopt_optimize_newton + newton_optimize_full } else { - nlopt_optimize + nlopt_optimize_full } - private$optimizer$vestep <- if (is_newton) nlopt_optimize_vestep_newton else nlopt_optimize_vestep + private$optimizer$vestep <- if (is_newton) newton_optimize_vestep_full else nlopt_optimize_vestep_full }, ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -747,11 +747,11 @@ PLNfit_diagonal <- R6Class( private$optimizer$main <- if (control$backend == "torch") { private$torch_optimize } else if (is_newton) { - nlopt_optimize_newton_diagonal + newton_optimize_diagonal } else { nlopt_optimize_diagonal } - private$optimizer$vestep <- if (is_newton) nlopt_optimize_vestep_newton_diagonal else nlopt_optimize_vestep_diagonal + private$optimizer$vestep <- if (is_newton) newton_optimize_vestep_diagonal else nlopt_optimize_vestep_diagonal } ), private = list( @@ -837,11 +837,11 @@ PLNfit_spherical <- R6Class( private$optimizer$main <- if (control$backend == "torch") { private$torch_optimize } else if (is_newton) { - nlopt_optimize_newton_spherical + newton_optimize_spherical } else { nlopt_optimize_spherical } - private$optimizer$vestep <- if (is_newton) nlopt_optimize_vestep_newton_spherical else nlopt_optimize_vestep_spherical + private$optimizer$vestep <- if (is_newton) newton_optimize_vestep_spherical else nlopt_optimize_vestep_spherical } ), private = list( @@ -931,7 +931,7 @@ PLNfit_fixedcov <- R6Class( private$optimizer$main <- if (control$backend == "torch") { private$torch_optimize } else if (is_newton) { - nlopt_optimize_newton_fixed + newton_optimize_fixed } else { nlopt_optimize_fixed } diff --git a/R/RcppExports.R b/R/RcppExports.R index ca99a6f9..cdbc604f 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -1,76 +1,76 @@ # Generated by using Rcpp::compileAttributes() -> do not edit by hand # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 -cpp_test_nlopt <- function() { - .Call('_PLNmodels_cpp_test_nlopt', PACKAGE = 'PLNmodels') +newton_optimize_diagonal <- function(data, params, config) { + .Call('_PLNmodels_newton_optimize_diagonal', PACKAGE = 'PLNmodels', data, params, config) } -nlopt_optimize_diagonal <- function(data, params, config) { - .Call('_PLNmodels_nlopt_optimize_diagonal', PACKAGE = 'PLNmodels', data, params, config) +newton_optimize_vestep_diagonal <- function(data, params, B, Omega, config) { + .Call('_PLNmodels_newton_optimize_vestep_diagonal', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } -nlopt_optimize_newton_diagonal <- function(data, params, config) { - .Call('_PLNmodels_nlopt_optimize_newton_diagonal', PACKAGE = 'PLNmodels', data, params, config) +newton_optimize_fixed <- function(data, params, config) { + .Call('_PLNmodels_newton_optimize_fixed', PACKAGE = 'PLNmodels', data, params, config) } -nlopt_optimize_vestep_newton_diagonal <- function(data, params, B, Omega, config) { - .Call('_PLNmodels_nlopt_optimize_vestep_newton_diagonal', PACKAGE = 'PLNmodels', data, params, B, Omega, config) +newton_optimize_full <- function(data, params, config) { + .Call('_PLNmodels_newton_optimize_full', PACKAGE = 'PLNmodels', data, params, config) } -nlopt_optimize_vestep_diagonal <- function(data, params, B, Omega, config) { - .Call('_PLNmodels_nlopt_optimize_vestep_diagonal', PACKAGE = 'PLNmodels', data, params, B, Omega, config) +newton_optimize_vestep_full <- function(data, params, B, Omega, config) { + .Call('_PLNmodels_newton_optimize_vestep_full', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } -nlopt_optimize_newton_fixed <- function(data, params, config) { - .Call('_PLNmodels_nlopt_optimize_newton_fixed', PACKAGE = 'PLNmodels', data, params, config) +newton_optimize_spherical <- function(data, params, config) { + .Call('_PLNmodels_newton_optimize_spherical', PACKAGE = 'PLNmodels', data, params, config) } -nlopt_optimize_fixed <- function(data, params, config) { - .Call('_PLNmodels_nlopt_optimize_fixed', PACKAGE = 'PLNmodels', data, params, config) +newton_optimize_vestep_spherical <- function(data, params, B, Omega, config) { + .Call('_PLNmodels_newton_optimize_vestep_spherical', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } -nlopt_optimize <- function(data, params, config) { - .Call('_PLNmodels_nlopt_optimize', PACKAGE = 'PLNmodels', data, params, config) +nlopt_optimize_diagonal <- function(data, params, config) { + .Call('_PLNmodels_nlopt_optimize_diagonal', PACKAGE = 'PLNmodels', data, params, config) } -nlopt_optimize_newton <- function(data, params, config) { - .Call('_PLNmodels_nlopt_optimize_newton', PACKAGE = 'PLNmodels', data, params, config) +nlopt_optimize_vestep_diagonal <- function(data, params, B, Omega, config) { + .Call('_PLNmodels_nlopt_optimize_vestep_diagonal', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } -nlopt_optimize_vestep_newton <- function(data, params, B, Omega, config) { - .Call('_PLNmodels_nlopt_optimize_vestep_newton', PACKAGE = 'PLNmodels', data, params, B, Omega, config) +nlopt_optimize_fixed <- function(data, params, config) { + .Call('_PLNmodels_nlopt_optimize_fixed', PACKAGE = 'PLNmodels', data, params, config) } -nlopt_optimize_vestep <- function(data, params, B, Omega, config) { - .Call('_PLNmodels_nlopt_optimize_vestep', PACKAGE = 'PLNmodels', data, params, B, Omega, config) +nlopt_optimize_full <- function(data, params, config) { + .Call('_PLNmodels_nlopt_optimize_full', PACKAGE = 'PLNmodels', data, params, config) } -nlopt_optimize_genetic_modeling <- function(init_parameters, Y, X, O, w, C, configuration) { - .Call('_PLNmodels_nlopt_optimize_genetic_modeling', PACKAGE = 'PLNmodels', init_parameters, Y, X, O, w, C, configuration) +nlopt_optimize_vestep_full <- function(data, params, B, Omega, config) { + .Call('_PLNmodels_nlopt_optimize_vestep_full', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } -nlopt_optimize_rank <- function(data, params, config) { - .Call('_PLNmodels_nlopt_optimize_rank', PACKAGE = 'PLNmodels', data, params, config) +nlopt_optimize_spherical <- function(data, params, config) { + .Call('_PLNmodels_nlopt_optimize_spherical', PACKAGE = 'PLNmodels', data, params, config) } -nlopt_optimize_vestep_rank <- function(data, params, B, C, config) { - .Call('_PLNmodels_nlopt_optimize_vestep_rank', PACKAGE = 'PLNmodels', data, params, B, C, config) +nlopt_optimize_vestep_spherical <- function(data, params, B, Omega, config) { + .Call('_PLNmodels_nlopt_optimize_vestep_spherical', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } -nlopt_optimize_spherical <- function(data, params, config) { - .Call('_PLNmodels_nlopt_optimize_spherical', PACKAGE = 'PLNmodels', data, params, config) +cpp_test_nlopt <- function() { + .Call('_PLNmodels_cpp_test_nlopt', PACKAGE = 'PLNmodels') } -nlopt_optimize_newton_spherical <- function(data, params, config) { - .Call('_PLNmodels_nlopt_optimize_newton_spherical', PACKAGE = 'PLNmodels', data, params, config) +nlopt_optimize_genetic_modeling <- function(init_parameters, Y, X, O, w, C, configuration) { + .Call('_PLNmodels_nlopt_optimize_genetic_modeling', PACKAGE = 'PLNmodels', init_parameters, Y, X, O, w, C, configuration) } -nlopt_optimize_vestep_newton_spherical <- function(data, params, B, Omega, config) { - .Call('_PLNmodels_nlopt_optimize_vestep_newton_spherical', PACKAGE = 'PLNmodels', data, params, B, Omega, config) +nlopt_optimize_rank <- function(data, params, config) { + .Call('_PLNmodels_nlopt_optimize_rank', PACKAGE = 'PLNmodels', data, params, config) } -nlopt_optimize_vestep_spherical <- function(data, params, B, Omega, config) { - .Call('_PLNmodels_nlopt_optimize_vestep_spherical', PACKAGE = 'PLNmodels', data, params, B, Omega, config) +nlopt_optimize_vestep_rank <- function(data, params, B, C, config) { + .Call('_PLNmodels_nlopt_optimize_vestep_rank', PACKAGE = 'PLNmodels', data, params, B, C, config) } zipln_vloglik <- function(Y, X, O, Pi, Omega, B, R, M, S) { diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index b5421a45..db1bda26 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -11,60 +11,63 @@ Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); #endif -// cpp_test_nlopt -bool cpp_test_nlopt(); -RcppExport SEXP _PLNmodels_cpp_test_nlopt() { +// newton_optimize_diagonal +Rcpp::List newton_optimize_diagonal(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_newton_optimize_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; - rcpp_result_gen = Rcpp::wrap(cpp_test_nlopt()); + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(newton_optimize_diagonal(data, params, config)); return rcpp_result_gen; END_RCPP } -// nlopt_optimize_diagonal -Rcpp::List nlopt_optimize_diagonal(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +// newton_optimize_vestep_diagonal +Rcpp::List newton_optimize_vestep_diagonal(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_newton_optimize_vestep_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_diagonal(data, params, config)); + rcpp_result_gen = Rcpp::wrap(newton_optimize_vestep_diagonal(data, params, B, Omega, config)); return rcpp_result_gen; END_RCPP } -// nlopt_optimize_newton_diagonal -Rcpp::List nlopt_optimize_newton_diagonal(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_newton_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +// newton_optimize_fixed +Rcpp::List newton_optimize_fixed(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_newton_optimize_fixed(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_newton_diagonal(data, params, config)); + rcpp_result_gen = Rcpp::wrap(newton_optimize_fixed(data, params, config)); return rcpp_result_gen; END_RCPP } -// nlopt_optimize_vestep_newton_diagonal -Rcpp::List nlopt_optimize_vestep_newton_diagonal(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_newton_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { +// newton_optimize_full +Rcpp::List newton_optimize_full(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_newton_optimize_full(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_vestep_newton_diagonal(data, params, B, Omega, config)); + rcpp_result_gen = Rcpp::wrap(newton_optimize_full(data, params, config)); return rcpp_result_gen; END_RCPP } -// nlopt_optimize_vestep_diagonal -Rcpp::List nlopt_optimize_vestep_diagonal(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { +// newton_optimize_vestep_full +Rcpp::List newton_optimize_vestep_full(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_newton_optimize_vestep_full(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; @@ -73,190 +76,187 @@ BEGIN_RCPP Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_vestep_diagonal(data, params, B, Omega, config)); + rcpp_result_gen = Rcpp::wrap(newton_optimize_vestep_full(data, params, B, Omega, config)); return rcpp_result_gen; END_RCPP } -// nlopt_optimize_newton_fixed -Rcpp::List nlopt_optimize_newton_fixed(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_newton_fixed(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +// newton_optimize_spherical +Rcpp::List newton_optimize_spherical(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_newton_optimize_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_newton_fixed(data, params, config)); + rcpp_result_gen = Rcpp::wrap(newton_optimize_spherical(data, params, config)); return rcpp_result_gen; END_RCPP } -// nlopt_optimize_fixed -Rcpp::List nlopt_optimize_fixed(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_fixed(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +// newton_optimize_vestep_spherical +Rcpp::List newton_optimize_vestep_spherical(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_newton_optimize_vestep_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_fixed(data, params, config)); + rcpp_result_gen = Rcpp::wrap(newton_optimize_vestep_spherical(data, params, B, Omega, config)); return rcpp_result_gen; END_RCPP } -// nlopt_optimize -Rcpp::List nlopt_optimize(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +// nlopt_optimize_diagonal +Rcpp::List nlopt_optimize_diagonal(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize(data, params, config)); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_diagonal(data, params, config)); return rcpp_result_gen; END_RCPP } -// nlopt_optimize_newton -Rcpp::List nlopt_optimize_newton(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_newton(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +// nlopt_optimize_vestep_diagonal +Rcpp::List nlopt_optimize_vestep_diagonal(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_newton(data, params, config)); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_vestep_diagonal(data, params, B, Omega, config)); return rcpp_result_gen; END_RCPP } -// nlopt_optimize_vestep_newton -Rcpp::List nlopt_optimize_vestep_newton(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_newton(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { +// nlopt_optimize_fixed +Rcpp::List nlopt_optimize_fixed(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_fixed(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_vestep_newton(data, params, B, Omega, config)); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_fixed(data, params, config)); return rcpp_result_gen; END_RCPP } -// nlopt_optimize_vestep -Rcpp::List nlopt_optimize_vestep(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_vestep(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { +// nlopt_optimize_full +Rcpp::List nlopt_optimize_full(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_full(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_vestep(data, params, B, Omega, config)); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_full(data, params, config)); return rcpp_result_gen; END_RCPP } -// nlopt_optimize_genetic_modeling -Rcpp::List nlopt_optimize_genetic_modeling(const Rcpp::List& init_parameters, const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::vec& w, const arma::mat& C, const Rcpp::List& configuration); -RcppExport SEXP _PLNmodels_nlopt_optimize_genetic_modeling(SEXP init_parametersSEXP, SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP wSEXP, SEXP CSEXP, SEXP configurationSEXP) { +// nlopt_optimize_vestep_full +Rcpp::List nlopt_optimize_vestep_full(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_full(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const Rcpp::List& >::type init_parameters(init_parametersSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type Y(YSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type O(OSEXP); - Rcpp::traits::input_parameter< const arma::vec& >::type w(wSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type C(CSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type configuration(configurationSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_genetic_modeling(init_parameters, Y, X, O, w, C, configuration)); + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_vestep_full(data, params, B, Omega, config)); return rcpp_result_gen; END_RCPP } -// nlopt_optimize_rank -Rcpp::List nlopt_optimize_rank(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +// nlopt_optimize_spherical +Rcpp::List nlopt_optimize_spherical(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_rank(data, params, config)); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_spherical(data, params, config)); return rcpp_result_gen; END_RCPP } -// nlopt_optimize_vestep_rank -Rcpp::List nlopt_optimize_vestep_rank(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& C, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP CSEXP, SEXP configSEXP) { +// nlopt_optimize_vestep_spherical +Rcpp::List nlopt_optimize_vestep_spherical(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type C(CSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_vestep_rank(data, params, B, C, config)); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_vestep_spherical(data, params, B, Omega, config)); return rcpp_result_gen; END_RCPP } -// nlopt_optimize_spherical -Rcpp::List nlopt_optimize_spherical(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +// cpp_test_nlopt +bool cpp_test_nlopt(); +RcppExport SEXP _PLNmodels_cpp_test_nlopt() { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_spherical(data, params, config)); + rcpp_result_gen = Rcpp::wrap(cpp_test_nlopt()); return rcpp_result_gen; END_RCPP } -// nlopt_optimize_newton_spherical -Rcpp::List nlopt_optimize_newton_spherical(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_newton_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +// nlopt_optimize_genetic_modeling +Rcpp::List nlopt_optimize_genetic_modeling(const Rcpp::List& init_parameters, const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::vec& w, const arma::mat& C, const Rcpp::List& configuration); +RcppExport SEXP _PLNmodels_nlopt_optimize_genetic_modeling(SEXP init_parametersSEXP, SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP wSEXP, SEXP CSEXP, SEXP configurationSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_newton_spherical(data, params, config)); + Rcpp::traits::input_parameter< const Rcpp::List& >::type init_parameters(init_parametersSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Y(YSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type O(OSEXP); + Rcpp::traits::input_parameter< const arma::vec& >::type w(wSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type C(CSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type configuration(configurationSEXP); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_genetic_modeling(init_parameters, Y, X, O, w, C, configuration)); return rcpp_result_gen; END_RCPP } -// nlopt_optimize_vestep_newton_spherical -Rcpp::List nlopt_optimize_vestep_newton_spherical(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_newton_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { +// nlopt_optimize_rank +Rcpp::List nlopt_optimize_rank(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_vestep_newton_spherical(data, params, B, Omega, config)); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_rank(data, params, config)); return rcpp_result_gen; END_RCPP } -// nlopt_optimize_vestep_spherical -Rcpp::List nlopt_optimize_vestep_spherical(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { +// nlopt_optimize_vestep_rank +Rcpp::List nlopt_optimize_vestep_rank(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& C, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP CSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type C(CSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_vestep_spherical(data, params, B, Omega, config)); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_vestep_rank(data, params, B, C, config)); return rcpp_result_gen; END_RCPP } @@ -503,24 +503,24 @@ END_RCPP } static const R_CallMethodDef CallEntries[] = { - {"_PLNmodels_cpp_test_nlopt", (DL_FUNC) &_PLNmodels_cpp_test_nlopt, 0}, + {"_PLNmodels_newton_optimize_diagonal", (DL_FUNC) &_PLNmodels_newton_optimize_diagonal, 3}, + {"_PLNmodels_newton_optimize_vestep_diagonal", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_diagonal, 5}, + {"_PLNmodels_newton_optimize_fixed", (DL_FUNC) &_PLNmodels_newton_optimize_fixed, 3}, + {"_PLNmodels_newton_optimize_full", (DL_FUNC) &_PLNmodels_newton_optimize_full, 3}, + {"_PLNmodels_newton_optimize_vestep_full", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_full, 5}, + {"_PLNmodels_newton_optimize_spherical", (DL_FUNC) &_PLNmodels_newton_optimize_spherical, 3}, + {"_PLNmodels_newton_optimize_vestep_spherical", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_spherical, 5}, {"_PLNmodels_nlopt_optimize_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_diagonal, 3}, - {"_PLNmodels_nlopt_optimize_newton_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_newton_diagonal, 3}, - {"_PLNmodels_nlopt_optimize_vestep_newton_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_newton_diagonal, 5}, {"_PLNmodels_nlopt_optimize_vestep_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_diagonal, 5}, - {"_PLNmodels_nlopt_optimize_newton_fixed", (DL_FUNC) &_PLNmodels_nlopt_optimize_newton_fixed, 3}, {"_PLNmodels_nlopt_optimize_fixed", (DL_FUNC) &_PLNmodels_nlopt_optimize_fixed, 3}, - {"_PLNmodels_nlopt_optimize", (DL_FUNC) &_PLNmodels_nlopt_optimize, 3}, - {"_PLNmodels_nlopt_optimize_newton", (DL_FUNC) &_PLNmodels_nlopt_optimize_newton, 3}, - {"_PLNmodels_nlopt_optimize_vestep_newton", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_newton, 5}, - {"_PLNmodels_nlopt_optimize_vestep", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep, 5}, + {"_PLNmodels_nlopt_optimize_full", (DL_FUNC) &_PLNmodels_nlopt_optimize_full, 3}, + {"_PLNmodels_nlopt_optimize_vestep_full", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_full, 5}, + {"_PLNmodels_nlopt_optimize_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_spherical, 3}, + {"_PLNmodels_nlopt_optimize_vestep_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_spherical, 5}, + {"_PLNmodels_cpp_test_nlopt", (DL_FUNC) &_PLNmodels_cpp_test_nlopt, 0}, {"_PLNmodels_nlopt_optimize_genetic_modeling", (DL_FUNC) &_PLNmodels_nlopt_optimize_genetic_modeling, 7}, {"_PLNmodels_nlopt_optimize_rank", (DL_FUNC) &_PLNmodels_nlopt_optimize_rank, 3}, {"_PLNmodels_nlopt_optimize_vestep_rank", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_rank, 5}, - {"_PLNmodels_nlopt_optimize_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_spherical, 3}, - {"_PLNmodels_nlopt_optimize_newton_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_newton_spherical, 3}, - {"_PLNmodels_nlopt_optimize_vestep_newton_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_newton_spherical, 5}, - {"_PLNmodels_nlopt_optimize_vestep_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_spherical, 5}, {"_PLNmodels_zipln_vloglik", (DL_FUNC) &_PLNmodels_zipln_vloglik, 9}, {"_PLNmodels_optim_zipln_Omega_full", (DL_FUNC) &_PLNmodels_optim_zipln_Omega_full, 4}, {"_PLNmodels_optim_zipln_Omega_spherical", (DL_FUNC) &_PLNmodels_optim_zipln_Omega_spherical, 4}, diff --git a/src/newton_diag_cov.cpp b/src/newton_diag_cov.cpp new file mode 100644 index 00000000..b6cc72f1 --- /dev/null +++ b/src/newton_diag_cov.cpp @@ -0,0 +1,133 @@ +#include "RcppArmadillo.h" + +// [[Rcpp::depends(RcppArmadillo)]] + +#include "utils.h" +#include "newton_impl.h" + +// --------------------------------------------------------------------------------------- +// Diagonal covariance PLN — coordinate-Newton optimizer + +// [[Rcpp::export]] +Rcpp::List newton_optimize_diagonal( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(B, M, S) + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; + const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + + const double w_bar = arma::accu(w); + arma::mat S2 = S % S; + DiagonalCovTraits::State state(M, S2, w, w_bar); + + return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); +} + +// --------------------------------------------------------------------------------------- +// VE diagonal — coordinate-Newton (M and S only, B and Omega fixed) + +// [[Rcpp::export]] +Rcpp::List newton_optimize_vestep_diagonal( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(M, S) + const arma::mat & B, // (d,p) fixed + const arma::mat & Omega, // (p,p) diagonal, fixed + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + + const int n = Y.n_rows; + const double c1 = 1e-4; + const arma::rowvec omega2 = arma::diagvec(Omega).t(); + const arma::mat ones_row = arma::ones(n, 1); + const arma::mat XB = X * B; + + arma::mat logS = arma::log(S); + arma::mat S2 = S % S; + + std::vector objective_vec; + double obj_prev = arma::datum::inf; + int total_iter = 0; + + for (int it = 0; it < maxiter; it++) { + S2 = S % S; + arma::mat Z = O + XB + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + + // ---- Diagonal Newton step for M ---- + arma::mat grad_M = M.each_row() % omega2 + A - Y; grad_M.each_col() %= w; + arma::mat hess_M = ones_row * omega2 + A; hess_M.each_col() %= w; + hess_M.clamp(1e-10, arma::datum::inf); + arma::mat step_M = grad_M / hess_M; + double f0_M = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * arma::as_scalar((w.t() * (M % M)) * omega2.t()); + double slope_M = -arma::accu(grad_M % step_M); + double alpha_M = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Mt = M - alpha_M * step_M; + arma::mat Zt = Z - alpha_M * step_M; + arma::mat At = arma::exp(Zt + 0.5 * S2); + if (arma::accu(w.t() * (At - Y % Zt)) + + 0.5 * arma::as_scalar((w.t() * (Mt % Mt)) * omega2.t()) + <= f0_M + c1 * alpha_M * slope_M) break; + alpha_M *= 0.5; + } + M -= alpha_M * step_M; + Z = O + XB + M; + + // ---- Fixed-point update for logS ---- + fixed_point_logS(logS, S, S2, Z, A, ones_row * omega2); + + // ---- Objective for convergence ---- + A = arma::exp(Z + 0.5 * S2); + double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) + + 0.5 * arma::as_scalar((w.t() * (M % M + S2)) * omega2.t()); + objective_vec.push_back(obj); + total_iter++; + + if (it > 0 && converged(obj, obj_prev, ftol)) break; + obj_prev = obj; + } + + // ---- Final output ---- + S2 = S % S; + arma::mat Z = O + XB + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + arma::vec omega2_v = omega2.t(); + arma::vec loglik = arma::sum(Y % Z - A + 0.5 * arma::log(S2), 1) + - 0.5 * (M % M + S2) * omega2_v + + 0.5 * arma::accu(arma::log(omega2_v)) + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("M") = M, + Rcpp::Named("S") = S, + Rcpp::Named("Ji") = Ji, + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", 3 ), + Rcpp::Named("backend", "newton" ), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", total_iter ) + )) + ); +} diff --git a/src/newton_fixed_cov.cpp b/src/newton_fixed_cov.cpp new file mode 100644 index 00000000..539fb21d --- /dev/null +++ b/src/newton_fixed_cov.cpp @@ -0,0 +1,34 @@ +#include "RcppArmadillo.h" + +// [[Rcpp::depends(RcppArmadillo)]] + +#include "utils.h" +#include "newton_impl.h" + +// --------------------------------------------------------------------------------------- +// Fixed inverse covariance (Omega provided externally) PLN — coordinate-Newton optimizer + +// [[Rcpp::export]] +Rcpp::List newton_optimize_fixed( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(B, M, S, Omega) + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + arma::mat Omega = Rcpp::as(params["Omega"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + + arma::mat S2 = S % S; + FixedCovTraits::State state(Omega); + + // Fixed covariance has no EM loop (has_em = false); pass max_em=1, em_tol=0 + return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, 1, 0.0); +} diff --git a/src/newton_full_cov.cpp b/src/newton_full_cov.cpp new file mode 100644 index 00000000..d6ee6bc5 --- /dev/null +++ b/src/newton_full_cov.cpp @@ -0,0 +1,140 @@ +#include "RcppArmadillo.h" + +// [[Rcpp::depends(RcppArmadillo)]] + +#include "utils.h" +#include "newton_impl.h" + +// --------------------------------------------------------------------------------------- +// Full covariance PLN — coordinate-Newton optimizer + +// [[Rcpp::export]] +Rcpp::List newton_optimize_full( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(B, M, S) + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; + const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + + const double w_bar = arma::accu(w); + arma::mat S2 = S % S; + FullCovTraits::State state(M, S2, w, w_bar); + + return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); +} + +// --------------------------------------------------------------------------------------- +// VE full covariance — coordinate-Newton (M and S only, B and Omega fixed) + +// [[Rcpp::export]] +Rcpp::List newton_optimize_vestep_full( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(M, S) + const arma::mat & B, // (d,p) fixed + const arma::mat & Omega, // (p,p) fixed + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + + const int n = Y.n_rows; + const double c1 = 1e-4; + const arma::vec diag_Omega = arma::diagvec(Omega); + const arma::mat ones_row = arma::ones(n, 1); + const arma::mat XB = X * B; + + arma::mat logS = arma::log(S); + arma::mat S2 = S % S; + + std::vector objective_vec; + double obj_prev = arma::datum::inf; + int total_iter = 0; + + for (int it = 0; it < maxiter; it++) { + S2 = S % S; + arma::mat Z = O + XB + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + + // ---- Diagonal Newton step for M ---- + arma::mat MO = M * Omega; + arma::mat grad_M = MO + A - Y; grad_M.each_col() %= w; + arma::mat hess_M = A + ones_row * diag_Omega.t(); + hess_M.each_col() %= w; + hess_M.clamp(1e-10, arma::datum::inf); + arma::mat step_M = grad_M / hess_M; + double f0_M = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * arma::accu(MO % (M.each_col() % w)); + double slope_M = -arma::accu(grad_M % step_M); + double alpha_M = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Mt = M - alpha_M * step_M; + arma::mat Zt = Z - alpha_M * step_M; + arma::mat At = arma::exp(Zt + 0.5 * S2); + arma::mat MOt = Mt * Omega; + if (arma::accu(w.t() * (At - Y % Zt)) + + 0.5 * arma::accu(MOt % (Mt.each_col() % w)) + <= f0_M + c1 * alpha_M * slope_M) break; + alpha_M *= 0.5; + } + M -= alpha_M * step_M; + MO = M * Omega; + Z = O + XB + M; + + // ---- Fixed-point update for logS ---- + A = arma::exp(Z + 0.5 * S2); + logS = arma::clamp(-0.5 * arma::log(A + ones_row * diag_Omega.t()), -20., 10.); + S = arma::exp(logS); + S2 = S % S; + + // ---- Objective for convergence check ---- + A = arma::exp(Z + 0.5 * S2); + double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) + + 0.5 * (arma::accu(MO % (M.each_col() % w)) + + arma::dot(diag_Omega, (w.t() * S2).t())); + objective_vec.push_back(obj); + total_iter++; + + if (it > 0 && converged(obj, obj_prev, ftol)) break; + obj_prev = obj; + } + + // ---- Final output ---- + S2 = S % S; + arma::mat Z = O + XB + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + arma::vec loglik = arma::sum(Y % Z - A + 0.5 * arma::log(S2) + - 0.5 * ((M * Omega) % M + S2 * arma::diagmat(Omega)), 1) + + 0.5 * std::real(arma::log_det(Omega)) + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("M") = M, + Rcpp::Named("S") = S, + Rcpp::Named("Ji") = Ji, + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", 3 ), + Rcpp::Named("backend", "newton" ), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", total_iter ) + )) + ); +} diff --git a/src/newton_spherical.cpp b/src/newton_spherical.cpp new file mode 100644 index 00000000..c23ef620 --- /dev/null +++ b/src/newton_spherical.cpp @@ -0,0 +1,131 @@ +#include "RcppArmadillo.h" + +// [[Rcpp::depends(RcppArmadillo)]] + +#include "utils.h" +#include "newton_impl.h" + +// --------------------------------------------------------------------------------------- +// Spherical covariance PLN — coordinate-Newton optimizer + +// [[Rcpp::export]] +Rcpp::List newton_optimize_spherical( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(B, M, S) + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; + const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + + const double w_bar = arma::accu(w); + arma::mat S2 = S % S; + SphericalCovTraits::State state(M, S2, w, w_bar); + + return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); +} + +// --------------------------------------------------------------------------------------- +// VE spherical — coordinate-Newton (M and S only, B and Omega fixed) + +// [[Rcpp::export]] +Rcpp::List newton_optimize_vestep_spherical( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(M, S) + const arma::mat & B, // (d,p) fixed + const arma::mat & Omega, // (p,p) diagonal scalar, fixed + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + + const int n = Y.n_rows; + const double c1 = 1e-4; + const double omega2 = Omega(0, 0); + const arma::mat XB = X * B; + + arma::mat logS = arma::log(S); + arma::mat S2 = S % S; + + std::vector objective_vec; + double obj_prev = arma::datum::inf; + int total_iter = 0; + + for (int it = 0; it < maxiter; it++) { + S2 = S % S; + arma::mat Z = O + XB + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + + // ---- Diagonal Newton step for M (scalar omega2 broadcast) ---- + arma::mat grad_M = omega2 * M + A - Y; grad_M.each_col() %= w; + arma::mat hess_M = omega2 + A; hess_M.each_col() %= w; + hess_M.clamp(1e-10, arma::datum::inf); + arma::mat step_M = grad_M / hess_M; + double f0_M = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * omega2 * arma::as_scalar(w.t() * arma::sum(M % M, 1)); + double slope_M = -arma::accu(grad_M % step_M); + double alpha_M = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Mt = M - alpha_M * step_M; + arma::mat Zt = Z - alpha_M * step_M; + arma::mat At = arma::exp(Zt + 0.5 * S2); + if (arma::accu(w.t() * (At - Y % Zt)) + + 0.5 * omega2 * arma::as_scalar(w.t() * arma::sum(Mt % Mt, 1)) + <= f0_M + c1 * alpha_M * slope_M) break; + alpha_M *= 0.5; + } + M -= alpha_M * step_M; + Z = O + XB + M; + + // ---- Fixed-point update for logS (scalar cov_diag) ---- + fixed_point_logS(logS, S, S2, Z, A, omega2); + + // ---- Objective for convergence ---- + A = arma::exp(Z + 0.5 * S2); + double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) + + 0.5 * omega2 * arma::accu(arma::diagmat(w) * (M % M + S2)); + objective_vec.push_back(obj); + total_iter++; + + if (it > 0 && converged(obj, obj_prev, ftol)) break; + obj_prev = obj; + } + + // ---- Final output ---- + S2 = S % S; + const double sigma2 = 1.0 / omega2; + arma::mat Z = O + XB + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + arma::vec loglik = arma::sum(Y % Z - A - 0.5 * (M % M + S2) / sigma2 + 0.5 * arma::log(S2 / sigma2), 1) + + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("M") = M, + Rcpp::Named("S") = S, + Rcpp::Named("Ji") = Ji, + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", 3 ), + Rcpp::Named("backend", "newton" ), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", total_iter ) + )) + ); +} diff --git a/src/optim_diag_cov.cpp b/src/nlopt_diag_cov.cpp similarity index 57% rename from src/optim_diag_cov.cpp rename to src/nlopt_diag_cov.cpp index 63a853f6..8aa2f2bb 100644 --- a/src/optim_diag_cov.cpp +++ b/src/nlopt_diag_cov.cpp @@ -6,10 +6,9 @@ #include "nlopt_wrapper.h" #include "packing.h" #include "utils.h" -#include "newton_impl.h" // --------------------------------------------------------------------------------------- -// Diagonal covariance +// Diagonal covariance PLN — nlopt/CCSAQ optimizer // [[Rcpp::export]] Rcpp::List nlopt_optimize_diagonal( @@ -103,134 +102,7 @@ Rcpp::List nlopt_optimize_diagonal( } // --------------------------------------------------------------------------------------- -// Diagonal covariance PLN — coordinate-Newton optimizer - -// [[Rcpp::export]] -Rcpp::List nlopt_optimize_newton_diagonal( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(B, M, S) - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); - - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; - const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; - - const double w_bar = arma::accu(w); - arma::mat S2 = S % S; - DiagonalCovTraits::State state(M, S2, w, w_bar); - - return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); -} - -// --------------------------------------------------------------------------------------- -// VE diagonal — coordinate-Newton (M and S only, B and Omega fixed) - -// [[Rcpp::export]] -Rcpp::List nlopt_optimize_vestep_newton_diagonal( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(M, S) - const arma::mat & B, // (d,p) fixed - const arma::mat & Omega, // (p,p) diagonal, fixed - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); - - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - - const int n = Y.n_rows; - const double c1 = 1e-4; - const arma::rowvec omega2 = arma::diagvec(Omega).t(); - const arma::mat ones_row = arma::ones(n, 1); - const arma::mat XB = X * B; - - arma::mat logS = arma::log(S); - arma::mat S2 = S % S; - - std::vector objective_vec; - double obj_prev = arma::datum::inf; - int total_iter = 0; - - for (int it = 0; it < maxiter; it++) { - S2 = S % S; - arma::mat Z = O + XB + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - - // ---- Diagonal Newton step for M ---- - arma::mat grad_M = M.each_row() % omega2 + A - Y; grad_M.each_col() %= w; - arma::mat hess_M = ones_row * omega2 + A; hess_M.each_col() %= w; - hess_M.clamp(1e-10, arma::datum::inf); - arma::mat step_M = grad_M / hess_M; - double f0_M = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::as_scalar((w.t() * (M % M)) * omega2.t()); - double slope_M = -arma::accu(grad_M % step_M); - double alpha_M = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; - arma::mat Zt = Z - alpha_M * step_M; - arma::mat At = arma::exp(Zt + 0.5 * S2); - if (arma::accu(w.t() * (At - Y % Zt)) - + 0.5 * arma::as_scalar((w.t() * (Mt % Mt)) * omega2.t()) - <= f0_M + c1 * alpha_M * slope_M) break; - alpha_M *= 0.5; - } - M -= alpha_M * step_M; - Z = O + XB + M; - - // ---- Fixed-point update for logS ---- - fixed_point_logS(logS, S, S2, Z, A, ones_row * omega2); - - // ---- Objective for convergence ---- - A = arma::exp(Z + 0.5 * S2); - double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) - + 0.5 * arma::as_scalar((w.t() * (M % M + S2)) * omega2.t()); - objective_vec.push_back(obj); - total_iter++; - - if (it > 0 && converged(obj, obj_prev, ftol)) break; - obj_prev = obj; - } - - // ---- Final output ---- - S2 = S % S; - arma::mat Z = O + XB + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - arma::vec omega2_v = omega2.t(); - arma::vec loglik = arma::sum(Y % Z - A + 0.5 * arma::log(S2), 1) - - 0.5 * (M % M + S2) * omega2_v - + 0.5 * arma::accu(arma::log(omega2_v)) + ki(Y); - - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("M") = M, - Rcpp::Named("S") = S, - Rcpp::Named("Ji") = Ji, - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", 3 ), - Rcpp::Named("backend", "newton" ), - Rcpp::Named("objective", objective_vec), - Rcpp::Named("iterations", total_iter ) - )) - ); -} - -// --------------------------------------------------------------------------------------- -// VE diagonal +// VE diagonal — nlopt/CCSAQ (M and S only, B and Omega fixed) // [[Rcpp::export]] Rcpp::List nlopt_optimize_vestep_diagonal( @@ -240,8 +112,6 @@ Rcpp::List nlopt_optimize_vestep_diagonal( const arma::mat & Omega, // (p,p) const Rcpp::List & config // List of config values ) { - // Conversion from R, prepare optimization - // Conversion from R, prepare optimization const arma::mat & Y = Rcpp::as(data["Y"]); // responses (n,p) const arma::mat & X = Rcpp::as(data["X"]); // covariates (n,d) const arma::mat & O = Rcpp::as(data["O"]); // offsets (n,p) diff --git a/src/optim_fixed_cov.cpp b/src/nlopt_fixed_cov.cpp similarity index 73% rename from src/optim_fixed_cov.cpp rename to src/nlopt_fixed_cov.cpp index e87959b1..05362957 100644 --- a/src/optim_fixed_cov.cpp +++ b/src/nlopt_fixed_cov.cpp @@ -6,39 +6,9 @@ #include "nlopt_wrapper.h" #include "packing.h" #include "utils.h" -#include "newton_impl.h" // --------------------------------------------------------------------------------------- -// Fixed inverse covariance (Omega) - -// --------------------------------------------------------------------------------------- -// Fixed covariance PLN — coordinate-Newton optimizer - -// [[Rcpp::export]] -Rcpp::List nlopt_optimize_newton_fixed( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(B, M, S, Omega) - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); - const arma::mat Omega = Rcpp::as(params["Omega"]); - - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - - FixedCovTraits::State state(Omega); - - return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, 1, 0.0); -} - -// --------------------------------------------------------------------------------------- -// Fixed inverse covariance (Omega) +// Fixed inverse covariance (Omega) PLN — nlopt/CCSAQ optimizer // [[Rcpp::export]] Rcpp::List nlopt_optimize_fixed( @@ -120,4 +90,3 @@ Rcpp::List nlopt_optimize_fixed( )) ); } - diff --git a/src/optim_full_cov.cpp b/src/nlopt_full_cov.cpp similarity index 62% rename from src/optim_full_cov.cpp rename to src/nlopt_full_cov.cpp index 2592ee09..e5044db7 100644 --- a/src/optim_full_cov.cpp +++ b/src/nlopt_full_cov.cpp @@ -6,13 +6,12 @@ #include "nlopt_wrapper.h" #include "packing.h" #include "utils.h" -#include "newton_impl.h" // --------------------------------------------------------------------------------------- -// Fully parametrized covariance +// Full covariance PLN — nlopt/CCSAQ optimizer // [[Rcpp::export]] -Rcpp::List nlopt_optimize( +Rcpp::List nlopt_optimize_full( const Rcpp::List & data , // List(Y, X, O, w) const Rcpp::List & params, // List(B, M, S) const Rcpp::List & config // List of config values @@ -135,144 +134,10 @@ Rcpp::List nlopt_optimize( } // --------------------------------------------------------------------------------------- -// Full covariance PLN — coordinate-Newton optimizer +// VE full covariance — nlopt/CCSAQ (M and S only, B and Omega fixed) // [[Rcpp::export]] -Rcpp::List nlopt_optimize_newton( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(B, M, S) - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); - - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; - const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; - - const double w_bar = arma::accu(w); - arma::mat S2 = S % S; - FullCovTraits::State state(M, S2, w, w_bar); - - return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); -} - -// --------------------------------------------------------------------------------------- -// VE full — coordinate-Newton (M and S only, B and Omega fixed) - -// [[Rcpp::export]] -Rcpp::List nlopt_optimize_vestep_newton( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(M, S) - const arma::mat & B, // (d,p) fixed - const arma::mat & Omega, // (p,p) fixed - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); - - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - - const int n = Y.n_rows; - const double c1 = 1e-4; - const arma::vec diag_Omega = arma::diagvec(Omega); - const arma::mat ones_row = arma::ones(n, 1); - const arma::mat XB = X * B; - - arma::mat logS = arma::log(S); - arma::mat S2 = S % S; - - std::vector objective_vec; - double obj_prev = arma::datum::inf; - int total_iter = 0; - - for (int it = 0; it < maxiter; it++) { - S2 = S % S; - arma::mat Z = O + XB + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - - // ---- Diagonal Newton step for M ---- - arma::mat MO = M * Omega; - arma::mat grad_M = MO + A - Y; grad_M.each_col() %= w; - arma::mat hess_M = A + ones_row * diag_Omega.t(); - hess_M.each_col() %= w; - hess_M.clamp(1e-10, arma::datum::inf); - arma::mat step_M = grad_M / hess_M; - double f0_M = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::accu(MO % (M.each_col() % w)); - double slope_M = -arma::accu(grad_M % step_M); - double alpha_M = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; - arma::mat Zt = Z - alpha_M * step_M; - arma::mat At = arma::exp(Zt + 0.5 * S2); - arma::mat MOt = Mt * Omega; - if (arma::accu(w.t() * (At - Y % Zt)) - + 0.5 * arma::accu(MOt % (Mt.each_col() % w)) - <= f0_M + c1 * alpha_M * slope_M) break; - alpha_M *= 0.5; - } - M -= alpha_M * step_M; - MO = M * Omega; - Z = O + XB + M; - - // ---- Fixed-point update for logS ---- - A = arma::exp(Z + 0.5 * S2); - logS = arma::clamp(-0.5 * arma::log(A + ones_row * diag_Omega.t()), -20., 10.); - S = arma::exp(logS); - S2 = S % S; - - // ---- Objective for convergence check ---- - A = arma::exp(Z + 0.5 * S2); - double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) - + 0.5 * (arma::accu(MO % (M.each_col() % w)) - + arma::dot(diag_Omega, (w.t() * S2).t())); - objective_vec.push_back(obj); - total_iter++; - - if (it > 0 && converged(obj, obj_prev, ftol)) break; - obj_prev = obj; - } - - // ---- Final output ---- - S2 = S % S; - arma::mat Z = O + XB + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - arma::vec loglik = arma::sum(Y % Z - A + 0.5 * arma::log(S2) - - 0.5 * ((M * Omega) % M + S2 * arma::diagmat(Omega)), 1) - + 0.5 * real(arma::log_det(Omega)) + ki(Y); - - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("M") = M, - Rcpp::Named("S") = S, - Rcpp::Named("Ji") = Ji, - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", 3 ), - Rcpp::Named("backend", "newton" ), - Rcpp::Named("objective", objective_vec), - Rcpp::Named("iterations", total_iter ) - )) - ); -} - -// --------------------------------------------------------------------------------------- -// VE full - -// [[Rcpp::export]] -Rcpp::List nlopt_optimize_vestep( +Rcpp::List nlopt_optimize_vestep_full( const Rcpp::List & data , // List(Y, X, O, w) const Rcpp::List & params, // List(M, S) const arma::mat & B, // (d,p) diff --git a/src/optim_spherical.cpp b/src/nlopt_spherical.cpp similarity index 58% rename from src/optim_spherical.cpp rename to src/nlopt_spherical.cpp index 6c1ac8cd..8dc1551c 100644 --- a/src/optim_spherical.cpp +++ b/src/nlopt_spherical.cpp @@ -6,10 +6,9 @@ #include "nlopt_wrapper.h" #include "packing.h" #include "utils.h" -#include "newton_impl.h" // --------------------------------------------------------------------------------------- -// Spherical covariance +// Spherical covariance PLN — nlopt/CCSAQ optimizer // [[Rcpp::export]] Rcpp::List nlopt_optimize_spherical( @@ -101,132 +100,7 @@ Rcpp::List nlopt_optimize_spherical( } // --------------------------------------------------------------------------------------- -// Spherical covariance PLN — coordinate-Newton optimizer - -// [[Rcpp::export]] -Rcpp::List nlopt_optimize_newton_spherical( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(B, M, S) - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); - - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; - const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; - - const double w_bar = arma::accu(w); - arma::mat S2 = S % S; - SphericalCovTraits::State state(M, S2, w, w_bar); - - return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); -} - -// --------------------------------------------------------------------------------------- -// VE spherical — coordinate-Newton (M and S only, B and Omega fixed) - -// [[Rcpp::export]] -Rcpp::List nlopt_optimize_vestep_newton_spherical( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(M, S) - const arma::mat & B, // (d,p) fixed - const arma::mat & Omega, // (p,p) diagonal scalar, fixed - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); - - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - - const int n = Y.n_rows; - const double c1 = 1e-4; - const double omega2 = Omega(0, 0); - const arma::mat XB = X * B; - - arma::mat logS = arma::log(S); - arma::mat S2 = S % S; - - std::vector objective_vec; - double obj_prev = arma::datum::inf; - int total_iter = 0; - - for (int it = 0; it < maxiter; it++) { - S2 = S % S; - arma::mat Z = O + XB + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - - // ---- Diagonal Newton step for M (scalar omega2 broadcast) ---- - arma::mat grad_M = omega2 * M + A - Y; grad_M.each_col() %= w; - arma::mat hess_M = omega2 + A; hess_M.each_col() %= w; - hess_M.clamp(1e-10, arma::datum::inf); - arma::mat step_M = grad_M / hess_M; - double f0_M = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * omega2 * arma::as_scalar(w.t() * arma::sum(M % M, 1)); - double slope_M = -arma::accu(grad_M % step_M); - double alpha_M = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; - arma::mat Zt = Z - alpha_M * step_M; - arma::mat At = arma::exp(Zt + 0.5 * S2); - if (arma::accu(w.t() * (At - Y % Zt)) - + 0.5 * omega2 * arma::as_scalar(w.t() * arma::sum(Mt % Mt, 1)) - <= f0_M + c1 * alpha_M * slope_M) break; - alpha_M *= 0.5; - } - M -= alpha_M * step_M; - Z = O + XB + M; - - // ---- Fixed-point update for logS (scalar cov_diag) ---- - fixed_point_logS(logS, S, S2, Z, A, omega2); - - // ---- Objective for convergence ---- - A = arma::exp(Z + 0.5 * S2); - double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) - + 0.5 * omega2 * arma::accu(arma::diagmat(w) * (M % M + S2)); - objective_vec.push_back(obj); - total_iter++; - - if (it > 0 && converged(obj, obj_prev, ftol)) break; - obj_prev = obj; - } - - // ---- Final output ---- - S2 = S % S; - const double sigma2 = 1.0 / omega2; - arma::mat Z = O + XB + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - arma::vec loglik = arma::sum(Y % Z - A - 0.5 * (M % M + S2) / sigma2 + 0.5 * arma::log(S2 / sigma2), 1) - + ki(Y); - - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("M") = M, - Rcpp::Named("S") = S, - Rcpp::Named("Ji") = Ji, - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", 3 ), - Rcpp::Named("backend", "newton" ), - Rcpp::Named("objective", objective_vec), - Rcpp::Named("iterations", total_iter ) - )) - ); -} - -// --------------------------------------------------------------------------------------- -// VE spherical +// VE spherical — nlopt/CCSAQ (M and S only, B and Omega fixed) // [[Rcpp::export]] Rcpp::List nlopt_optimize_vestep_spherical( @@ -251,7 +125,6 @@ Rcpp::List nlopt_optimize_vestep_spherical( metadata.map(parameters.data()) = init_M; metadata.map(parameters.data()) = init_S; - // Optimize auto optimizer = new_nlopt_optimizer(config, parameters.size()); std::vector objective_vec ; From 823b01352d32d8589880a9412ae4878b417c052f Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Mon, 8 Jun 2026 22:51:08 +0200 Subject: [PATCH 12/58] factorizing Nwton version of VE step in PLN variants --- src/CovarianceTraits.h | 11 ++++++ src/newton_diag_cov.cpp | 77 +----------------------------------- src/newton_full_cov.cpp | 84 +--------------------------------------- src/newton_impl.h | 81 ++++++++++++++++++++++++++++++++++++++ src/newton_spherical.cpp | 75 +---------------------------------- 5 files changed, 98 insertions(+), 230 deletions(-) diff --git a/src/CovarianceTraits.h b/src/CovarianceTraits.h index 4bf685eb..341f54d8 100644 --- a/src/CovarianceTraits.h +++ b/src/CovarianceTraits.h @@ -16,6 +16,9 @@ struct FullCovTraits { Omega = arma::inv_sympd(Sigma); diag_Omega = arma::diagvec(Omega); } + // vestep: Omega known and fixed + explicit State(const arma::mat & omega) + : Omega(omega), diag_Omega(arma::diagvec(omega)) {} }; static arma::mat cov_diag(const State & s, const arma::mat & ones_row) { @@ -82,6 +85,11 @@ struct DiagonalCovTraits { sigma2 = (w.t() * (M % M + S2)) / w_bar; omega2 = arma::pow(sigma2, -1); } + // vestep: Omega known and fixed (diagonal matrix passed as dense mat) + explicit State(const arma::mat & omega_mat) { + omega2 = arma::diagvec(omega_mat).t(); + sigma2 = arma::pow(omega2, -1); + } }; static arma::mat cov_diag(const State & s, const arma::mat & ones_row) { @@ -147,6 +155,9 @@ struct SphericalCovTraits { sigma2 = arma::accu(arma::diagmat(w) * (M % M + S2)) / (double(p) * w_bar); omega2 = 1.0 / sigma2; } + // vestep: Omega known and fixed (scalar diagonal matrix) + explicit State(const arma::mat & omega_mat) + : omega2(omega_mat(0, 0)), sigma2(1.0 / omega_mat(0, 0)) {} }; // returns double: fixed_point_logS handles scalar broadcast diff --git a/src/newton_diag_cov.cpp b/src/newton_diag_cov.cpp index b6cc72f1..567e76e1 100644 --- a/src/newton_diag_cov.cpp +++ b/src/newton_diag_cov.cpp @@ -55,79 +55,6 @@ Rcpp::List newton_optimize_vestep_diagonal( const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - const int n = Y.n_rows; - const double c1 = 1e-4; - const arma::rowvec omega2 = arma::diagvec(Omega).t(); - const arma::mat ones_row = arma::ones(n, 1); - const arma::mat XB = X * B; - - arma::mat logS = arma::log(S); - arma::mat S2 = S % S; - - std::vector objective_vec; - double obj_prev = arma::datum::inf; - int total_iter = 0; - - for (int it = 0; it < maxiter; it++) { - S2 = S % S; - arma::mat Z = O + XB + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - - // ---- Diagonal Newton step for M ---- - arma::mat grad_M = M.each_row() % omega2 + A - Y; grad_M.each_col() %= w; - arma::mat hess_M = ones_row * omega2 + A; hess_M.each_col() %= w; - hess_M.clamp(1e-10, arma::datum::inf); - arma::mat step_M = grad_M / hess_M; - double f0_M = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::as_scalar((w.t() * (M % M)) * omega2.t()); - double slope_M = -arma::accu(grad_M % step_M); - double alpha_M = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; - arma::mat Zt = Z - alpha_M * step_M; - arma::mat At = arma::exp(Zt + 0.5 * S2); - if (arma::accu(w.t() * (At - Y % Zt)) - + 0.5 * arma::as_scalar((w.t() * (Mt % Mt)) * omega2.t()) - <= f0_M + c1 * alpha_M * slope_M) break; - alpha_M *= 0.5; - } - M -= alpha_M * step_M; - Z = O + XB + M; - - // ---- Fixed-point update for logS ---- - fixed_point_logS(logS, S, S2, Z, A, ones_row * omega2); - - // ---- Objective for convergence ---- - A = arma::exp(Z + 0.5 * S2); - double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) - + 0.5 * arma::as_scalar((w.t() * (M % M + S2)) * omega2.t()); - objective_vec.push_back(obj); - total_iter++; - - if (it > 0 && converged(obj, obj_prev, ftol)) break; - obj_prev = obj; - } - - // ---- Final output ---- - S2 = S % S; - arma::mat Z = O + XB + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - arma::vec omega2_v = omega2.t(); - arma::vec loglik = arma::sum(Y % Z - A + 0.5 * arma::log(S2), 1) - - 0.5 * (M % M + S2) * omega2_v - + 0.5 * arma::accu(arma::log(omega2_v)) + ki(Y); - - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("M") = M, - Rcpp::Named("S") = S, - Rcpp::Named("Ji") = Ji, - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", 3 ), - Rcpp::Named("backend", "newton" ), - Rcpp::Named("objective", objective_vec), - Rcpp::Named("iterations", total_iter ) - )) - ); + DiagonalCovTraits::State state(Omega); + return newton_vestep_impl(Y, X, O, w, M, S, B, state, maxiter, ftol); } diff --git a/src/newton_full_cov.cpp b/src/newton_full_cov.cpp index d6ee6bc5..ab725c31 100644 --- a/src/newton_full_cov.cpp +++ b/src/newton_full_cov.cpp @@ -55,86 +55,6 @@ Rcpp::List newton_optimize_vestep_full( const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - const int n = Y.n_rows; - const double c1 = 1e-4; - const arma::vec diag_Omega = arma::diagvec(Omega); - const arma::mat ones_row = arma::ones(n, 1); - const arma::mat XB = X * B; - - arma::mat logS = arma::log(S); - arma::mat S2 = S % S; - - std::vector objective_vec; - double obj_prev = arma::datum::inf; - int total_iter = 0; - - for (int it = 0; it < maxiter; it++) { - S2 = S % S; - arma::mat Z = O + XB + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - - // ---- Diagonal Newton step for M ---- - arma::mat MO = M * Omega; - arma::mat grad_M = MO + A - Y; grad_M.each_col() %= w; - arma::mat hess_M = A + ones_row * diag_Omega.t(); - hess_M.each_col() %= w; - hess_M.clamp(1e-10, arma::datum::inf); - arma::mat step_M = grad_M / hess_M; - double f0_M = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::accu(MO % (M.each_col() % w)); - double slope_M = -arma::accu(grad_M % step_M); - double alpha_M = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; - arma::mat Zt = Z - alpha_M * step_M; - arma::mat At = arma::exp(Zt + 0.5 * S2); - arma::mat MOt = Mt * Omega; - if (arma::accu(w.t() * (At - Y % Zt)) - + 0.5 * arma::accu(MOt % (Mt.each_col() % w)) - <= f0_M + c1 * alpha_M * slope_M) break; - alpha_M *= 0.5; - } - M -= alpha_M * step_M; - MO = M * Omega; - Z = O + XB + M; - - // ---- Fixed-point update for logS ---- - A = arma::exp(Z + 0.5 * S2); - logS = arma::clamp(-0.5 * arma::log(A + ones_row * diag_Omega.t()), -20., 10.); - S = arma::exp(logS); - S2 = S % S; - - // ---- Objective for convergence check ---- - A = arma::exp(Z + 0.5 * S2); - double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) - + 0.5 * (arma::accu(MO % (M.each_col() % w)) - + arma::dot(diag_Omega, (w.t() * S2).t())); - objective_vec.push_back(obj); - total_iter++; - - if (it > 0 && converged(obj, obj_prev, ftol)) break; - obj_prev = obj; - } - - // ---- Final output ---- - S2 = S % S; - arma::mat Z = O + XB + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - arma::vec loglik = arma::sum(Y % Z - A + 0.5 * arma::log(S2) - - 0.5 * ((M * Omega) % M + S2 * arma::diagmat(Omega)), 1) - + 0.5 * std::real(arma::log_det(Omega)) + ki(Y); - - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("M") = M, - Rcpp::Named("S") = S, - Rcpp::Named("Ji") = Ji, - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", 3 ), - Rcpp::Named("backend", "newton" ), - Rcpp::Named("objective", objective_vec), - Rcpp::Named("iterations", total_iter ) - )) - ); + FullCovTraits::State state(Omega); + return newton_vestep_impl(Y, X, O, w, M, S, B, state, maxiter, ftol); } diff --git a/src/newton_impl.h b/src/newton_impl.h index 7f2c1ea5..e3b6e018 100644 --- a/src/newton_impl.h +++ b/src/newton_impl.h @@ -113,3 +113,84 @@ Rcpp::List newton_optimize_impl( )) ); } + +// ───────────────────────────────────────────────────────────────────────────── +// Generic VE-step Newton optimizer (B and Omega fixed, only M and S updated). +// State must be initialized from a fixed Omega via the explicit constructor. +template +Rcpp::List newton_vestep_impl( + const arma::mat & Y, const arma::mat & X, const arma::mat & O, const arma::vec & w, + arma::mat M, arma::mat S, + const arma::mat & B, const typename Traits::State & state, + int maxiter, double ftol +) { + const int n = Y.n_rows; + const double c1 = 1e-4; + const arma::mat ones_row = arma::ones(n, 1); + const arma::mat XB = X * B; + + arma::mat S2 = S % S; + arma::mat logS = arma::log(S); + + std::vector objective_vec; + double obj_prev = arma::datum::inf; + int total_iter = 0; + + for (int it = 0; it < maxiter; it++) { + S2 = S % S; + arma::mat Z = O + XB + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + + // ---- Diagonal Newton step for M ---- + arma::mat grad_M, hess_M; + Traits::grad_hess_M(M, state, A, Y, w, ones_row, grad_M, hess_M); + hess_M.clamp(1e-10, arma::datum::inf); + arma::mat step_M = grad_M / hess_M; + double f0_M = arma::accu(w.t() * (A - Y % Z)) + Traits::penalty_M(M, state, w); + double slope_M = -arma::accu(grad_M % step_M); + double alpha_M = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Mt = M - alpha_M * step_M; + arma::mat Zt = Z - alpha_M * step_M; + arma::mat At = arma::exp(Zt + 0.5 * S2); + if (arma::accu(w.t() * (At - Y % Zt)) + Traits::penalty_M(Mt, state, w) + <= f0_M + c1 * alpha_M * slope_M) break; + alpha_M *= 0.5; + } + M -= alpha_M * step_M; + Z = O + XB + M; + + // ---- Fixed-point update for S ---- + fixed_point_logS(logS, S, S2, Z, A, Traits::cov_diag(state, ones_row)); + + // ---- Objective for convergence ---- + A = arma::exp(Z + 0.5 * S2); + double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) + + Traits::objective_cov(M, S2, state, w); + objective_vec.push_back(obj); + total_iter++; + + if (it > 0 && converged(obj, obj_prev, ftol)) break; + obj_prev = obj; + } + + // ---- Final output ---- + S2 = S % S; + arma::mat Z = O + XB + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + arma::vec loglik = Traits::final_loglik(Y, Z, A, M, S2, state); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("M") = M, + Rcpp::Named("S") = S, + Rcpp::Named("Ji") = Ji, + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", 3 ), + Rcpp::Named("backend", "newton" ), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", total_iter ) + )) + ); +} diff --git a/src/newton_spherical.cpp b/src/newton_spherical.cpp index c23ef620..64ca3cc1 100644 --- a/src/newton_spherical.cpp +++ b/src/newton_spherical.cpp @@ -55,77 +55,6 @@ Rcpp::List newton_optimize_vestep_spherical( const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - const int n = Y.n_rows; - const double c1 = 1e-4; - const double omega2 = Omega(0, 0); - const arma::mat XB = X * B; - - arma::mat logS = arma::log(S); - arma::mat S2 = S % S; - - std::vector objective_vec; - double obj_prev = arma::datum::inf; - int total_iter = 0; - - for (int it = 0; it < maxiter; it++) { - S2 = S % S; - arma::mat Z = O + XB + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - - // ---- Diagonal Newton step for M (scalar omega2 broadcast) ---- - arma::mat grad_M = omega2 * M + A - Y; grad_M.each_col() %= w; - arma::mat hess_M = omega2 + A; hess_M.each_col() %= w; - hess_M.clamp(1e-10, arma::datum::inf); - arma::mat step_M = grad_M / hess_M; - double f0_M = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * omega2 * arma::as_scalar(w.t() * arma::sum(M % M, 1)); - double slope_M = -arma::accu(grad_M % step_M); - double alpha_M = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; - arma::mat Zt = Z - alpha_M * step_M; - arma::mat At = arma::exp(Zt + 0.5 * S2); - if (arma::accu(w.t() * (At - Y % Zt)) - + 0.5 * omega2 * arma::as_scalar(w.t() * arma::sum(Mt % Mt, 1)) - <= f0_M + c1 * alpha_M * slope_M) break; - alpha_M *= 0.5; - } - M -= alpha_M * step_M; - Z = O + XB + M; - - // ---- Fixed-point update for logS (scalar cov_diag) ---- - fixed_point_logS(logS, S, S2, Z, A, omega2); - - // ---- Objective for convergence ---- - A = arma::exp(Z + 0.5 * S2); - double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) - + 0.5 * omega2 * arma::accu(arma::diagmat(w) * (M % M + S2)); - objective_vec.push_back(obj); - total_iter++; - - if (it > 0 && converged(obj, obj_prev, ftol)) break; - obj_prev = obj; - } - - // ---- Final output ---- - S2 = S % S; - const double sigma2 = 1.0 / omega2; - arma::mat Z = O + XB + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - arma::vec loglik = arma::sum(Y % Z - A - 0.5 * (M % M + S2) / sigma2 + 0.5 * arma::log(S2 / sigma2), 1) - + ki(Y); - - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("M") = M, - Rcpp::Named("S") = S, - Rcpp::Named("Ji") = Ji, - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", 3 ), - Rcpp::Named("backend", "newton" ), - Rcpp::Named("objective", objective_vec), - Rcpp::Named("iterations", total_iter ) - )) - ); + SphericalCovTraits::State state(Omega); + return newton_vestep_impl(Y, X, O, w, M, S, B, state, maxiter, ftol); } From 46fe50659e883cb7b70032df01ff13f93f57323e Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Tue, 9 Jun 2026 11:06:11 +0200 Subject: [PATCH 13/58] =?UTF-8?q?use=20log(S=C2=B2)=20param=C3=A9tristion?= =?UTF-8?q?=20for=20nlopt=20optim?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/PLNPCA.R | 9 +- R/PLNPCAfamily-class.R | 58 +++- R/PLNPCAfit-class.R | 24 +- R/RcppExports.R | 24 +- R/zzz.R | 1 - man/ZIPLN_param.Rd | 2 +- src/RcppExports.cpp | 90 ++++-- src/newton_rank_cov.cpp | 285 ++++++++++++++++++ src/nlopt_diag_cov.cpp | 46 +-- src/nlopt_fixed_cov.cpp | 34 ++- src/nlopt_full_cov.cpp | 56 ++-- ...{optim_rank_cov.cpp => nlopt_rank_cov.cpp} | 0 src/nlopt_spherical.cpp | 52 ++-- 13 files changed, 543 insertions(+), 138 deletions(-) create mode 100644 src/newton_rank_cov.cpp rename src/{optim_rank_cov.cpp => nlopt_rank_cov.cpp} (100%) diff --git a/R/PLNPCA.R b/R/PLNPCA.R index c0749232..85c0ed40 100644 --- a/R/PLNPCA.R +++ b/R/PLNPCA.R @@ -68,6 +68,11 @@ PLNPCA <- function(formula, data, subset, weights, ranks = 1:5, control = PLNPCA #' @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. +#' @param sequential logical. If `TRUE`, ranks are fitted in ascending order and each model is +#' warm-started from the converged solution of the previous rank: loadings C are augmented +#' with new columns from the inception SVD, while latent scores M and variances S are +#' padded with zeros / 0.1 respectively. Disables parallel fitting across ranks. +#' Default is `FALSE`. #' #' @return list of parameters configuring the fit. #' @@ -78,7 +83,8 @@ PLNPCA_param <- function( trace = 1 , config_optim = list() , config_post = list() , - inception = NULL # pretrained PLNfit used as initialization + inception = NULL , # pretrained PLNfit used as initialization + sequential = FALSE # fit ranks sequentially, warm-starting each from the previous ) { if (!is.null(inception)) stopifnot(isPLNfit(inception)) @@ -101,6 +107,7 @@ PLNPCA_param <- function( } config_opt[names(config_optim)] <- config_optim config_opt$trace <- trace + config_opt$sequential <- sequential structure(list( backend = backend , diff --git a/R/PLNPCAfamily-class.R b/R/PLNPCAfamily-class.R index 08f5855e..a054b0b2 100644 --- a/R/PLNPCAfamily-class.R +++ b/R/PLNPCAfamily-class.R @@ -30,6 +30,14 @@ PLNPCAfamily <- R6Class( classname = "PLNPCAfamily", inherit = PLNfamily, + ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + ## PRIVATE MEMBERS ---- + ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + private = list( + svdM = NULL # SVD of the inception PLN M, shared across ranks + ), + ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ## PUBLIC MEMBERS ---- ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -44,7 +52,8 @@ PLNPCAfamily <- R6Class( private$params <- ranks ## save some time by using a common SVD to define the inceptive models control$inception <- PLNfit$new(responses, covariates, offsets, weights, formula, control) - control$svdM <- svd(control$inception$var_par$M, nu = max(ranks), nv = ncol(responses)) + private$svdM <- svd(control$inception$var_par$M, nu = max(ranks), nv = ncol(responses)) + control$svdM <- private$svdM ## instantiate as many models as ranks self$models <- lapply(ranks, function(rank){ model <- PLNPCAfit$new(rank, responses, covariates, offsets, weights, formula, control) @@ -57,18 +66,43 @@ PLNPCAfamily <- R6Class( #' @description Call to the C++ optimizer on all models of the collection #' @param config list controlling the optimization. optimize = function(config) { - self$models <- future.apply::future_lapply(self$models, function(model) { - if (config$trace == 1) { - cat("\t Rank approximation =",model$rank, "\r") - flush.console() - } - if (config$trace > 1) { - cat(" Rank approximation =",model$rank) - cat("\n\t conservative convex separable approximation for gradient descent") + if (isTRUE(config$sequential)) { + ## Sequential fitting: ranks in ascending order, each warm-started from the previous + ord <- order(sapply(self$models, function(m) m$rank)) + self$models <- self$models[ord] + prev_model <- NULL + for (i in seq_along(self$models)) { + model <- self$models[[i]] + if (config$trace == 1) { + cat("\t Rank approximation =", model$rank, "\r"); flush.console() + } + if (config$trace > 1) { + cat(" Rank approximation =", model$rank) + if (!is.null(prev_model)) + cat("\n\t warm-start from rank", prev_model$rank) + else + cat("\n\t no warm-start (first rank)") + } + if (!is.null(prev_model)) + model$warm_start_from(prev_model, private$svdM) + model$optimize(self$responses, self$covariates, self$offsets, self$weights, config) + prev_model <- model + self$models[[i]] <- model } - model$optimize(self$responses, self$covariates, self$offsets, self$weights, config) - model - }, future.seed = TRUE, future.scheduling = structure(TRUE, ordering = "random")) + } else { + self$models <- future.apply::future_lapply(self$models, function(model) { + if (config$trace == 1) { + cat("\t Rank approximation =", model$rank, "\r") + flush.console() + } + if (config$trace > 1) { + cat(" Rank approximation =", model$rank) + cat("\n\t conservative convex separable approximation for gradient descent") + } + model$optimize(self$responses, self$covariates, self$offsets, self$weights, config) + model + }, future.seed = TRUE, future.scheduling = structure(TRUE, ordering = "random")) + } }, ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/R/PLNPCAfit-class.R b/R/PLNPCAfit-class.R index d63bf1b5..38590f22 100644 --- a/R/PLNPCAfit-class.R +++ b/R/PLNPCAfit-class.R @@ -236,12 +236,15 @@ PLNPCAfit <- R6Class( #' @description Initialize a [`PLNPCAfit`] object initialize = function(rank, responses, covariates, offsets, weights, formula, control) { super$initialize(responses, covariates, offsets, weights, formula, control) + is_newton <- identical(control$config_optim$algorithm, "NEWTON") if (control$backend == "torch") { private$optimizer$main <- private$torch_optimize_rank + } else if (is_newton) { + private$optimizer$main <- newton_optimize_rank } else { private$optimizer$main <- nlopt_optimize_rank } - private$optimizer$vestep <- nlopt_optimize_vestep_rank + private$optimizer$vestep <- if (is_newton) newton_optimize_vestep_rank else nlopt_optimize_vestep_rank if (!is.null(control$svdM)) { svdM <- control$svdM } else { @@ -252,6 +255,25 @@ PLNPCAfit <- R6Class( private$S <- matrix(0.1, self$n, rank) private$C <- svdM$v[, 1:rank, drop = FALSE] %*% diag(svdM$d[1:rank], nrow = rank, ncol = rank)/sqrt(self$n) }, + #' @description Reinitialize parameters for sequential warm-starting from a lower-rank fit. + #' Fitted loadings C, scores M, variances S, and regression coefficients B from `prev_fit` + #' are carried over; new columns are padded using the inception SVD (C) or zeros/0.1 (M/S). + #' @param prev_fit a converged [`PLNPCAfit`] of rank `self$rank - k` (k >= 1) + #' @param svdM the inception SVD (from `PLNPCAfamily`) + warm_start_from = function(prev_fit, svdM) { + q_prev <- prev_fit$rank + q_new <- self$rank + new_idx <- (q_prev + 1):q_new + C_new_cols <- svdM$v[, new_idx, drop = FALSE] %*% + diag(svdM$d[new_idx], nrow = length(new_idx)) / sqrt(self$n) + private$C <- cbind(prev_fit$model_par$C, C_new_cols) + private$M <- cbind(prev_fit$var_par$M, + matrix(0, nrow = self$n, ncol = q_new - q_prev)) + private$S <- cbind(prev_fit$var_par$S, + matrix(0.1, nrow = self$n, ncol = q_new - q_prev)) + private$B <- prev_fit$model_par$B + }, + #' @description Update a [`PLNPCAfit`] object #' @param M matrix of mean vectors for the variational approximation #' @param C matrix of PCA loadings (in the latent space) diff --git a/R/RcppExports.R b/R/RcppExports.R index cdbc604f..87a294b5 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -21,6 +21,14 @@ newton_optimize_vestep_full <- function(data, params, B, Omega, config) { .Call('_PLNmodels_newton_optimize_vestep_full', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } +newton_optimize_rank <- function(data, params, config) { + .Call('_PLNmodels_newton_optimize_rank', PACKAGE = 'PLNmodels', data, params, config) +} + +newton_optimize_vestep_rank <- function(data, params, B, C, config) { + .Call('_PLNmodels_newton_optimize_vestep_rank', PACKAGE = 'PLNmodels', data, params, B, C, config) +} + newton_optimize_spherical <- function(data, params, config) { .Call('_PLNmodels_newton_optimize_spherical', PACKAGE = 'PLNmodels', data, params, config) } @@ -49,6 +57,14 @@ nlopt_optimize_vestep_full <- function(data, params, B, Omega, config) { .Call('_PLNmodels_nlopt_optimize_vestep_full', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } +nlopt_optimize_rank <- function(data, params, config) { + .Call('_PLNmodels_nlopt_optimize_rank', PACKAGE = 'PLNmodels', data, params, config) +} + +nlopt_optimize_vestep_rank <- function(data, params, B, C, config) { + .Call('_PLNmodels_nlopt_optimize_vestep_rank', PACKAGE = 'PLNmodels', data, params, B, C, config) +} + nlopt_optimize_spherical <- function(data, params, config) { .Call('_PLNmodels_nlopt_optimize_spherical', PACKAGE = 'PLNmodels', data, params, config) } @@ -65,14 +81,6 @@ nlopt_optimize_genetic_modeling <- function(init_parameters, Y, X, O, w, C, conf .Call('_PLNmodels_nlopt_optimize_genetic_modeling', PACKAGE = 'PLNmodels', init_parameters, Y, X, O, w, C, configuration) } -nlopt_optimize_rank <- function(data, params, config) { - .Call('_PLNmodels_nlopt_optimize_rank', PACKAGE = 'PLNmodels', data, params, config) -} - -nlopt_optimize_vestep_rank <- function(data, params, B, C, config) { - .Call('_PLNmodels_nlopt_optimize_vestep_rank', PACKAGE = 'PLNmodels', data, params, B, C, config) -} - zipln_vloglik <- function(Y, X, O, Pi, Omega, B, R, M, S) { .Call('_PLNmodels_zipln_vloglik', PACKAGE = 'PLNmodels', Y, X, O, Pi, Omega, B, R, M, S) } diff --git a/R/zzz.R b/R/zzz.R index f7bb61ea..ef7c52e9 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,5 +1,4 @@ .onAttach <- function(libname, pkgname) { version <- read.dcf(file=system.file("DESCRIPTION", package=pkgname), fields="Version") packageStartupMessage(paste0("This is package '", pkgname,"' version ",version)) - packageStartupMessage('Use future::plan(multicore/multisession) to speed up PLNPCA/PLNmixture/stability_selection.') } diff --git a/man/ZIPLN_param.Rd b/man/ZIPLN_param.Rd index 5d9a624d..fb0786c7 100644 --- a/man/ZIPLN_param.Rd +++ b/man/ZIPLN_param.Rd @@ -50,7 +50,7 @@ Helper to define list of parameters to control the PLN fit. All arguments have d See \code{\link[=PLN_param]{PLN_param()}} and \code{\link[=PLNnetwork_param]{PLNnetwork_param()}} for a full description of the generic optimization parameters. Like \code{\link[=PLNnetwork_param]{PLNnetwork_param()}}, ZIPLN_param() has two parameters controlling the optimization due the inner-outer loop structure of the optimizer: \itemize{ \item "ftol_out" outer solver stops when an optimization step changes the objective function by less than \code{ftol_out} multiplied by the absolute value of the parameter. Default is 1e-6 -\item "maxit_out" outer solver stops when the number of iteration exceeds \code{maxit_out}. Default is 100 +\item "maxit_out" outer solver stops when the number of iteration exceeds \code{maxit_out}. Default is 100 (200 for NEWTON) and one additional parameter controlling the form of the variational approximation of the zero inflation: \item "approx_ZI" either uses an exact or approximated conditional distribution for the zero inflation. Default is FALSE } diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index db1bda26..3d32d83c 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -80,6 +80,34 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// newton_optimize_rank +Rcpp::List newton_optimize_rank(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_newton_optimize_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(newton_optimize_rank(data, params, config)); + return rcpp_result_gen; +END_RCPP +} +// newton_optimize_vestep_rank +Rcpp::List newton_optimize_vestep_rank(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& C, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_newton_optimize_vestep_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP CSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type C(CSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(newton_optimize_vestep_rank(data, params, B, C, config)); + return rcpp_result_gen; +END_RCPP +} // newton_optimize_spherical Rcpp::List newton_optimize_spherical(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); RcppExport SEXP _PLNmodels_newton_optimize_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { @@ -177,6 +205,34 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// nlopt_optimize_rank +Rcpp::List nlopt_optimize_rank(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_rank(data, params, config)); + return rcpp_result_gen; +END_RCPP +} +// nlopt_optimize_vestep_rank +Rcpp::List nlopt_optimize_vestep_rank(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& C, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP CSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type C(CSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_vestep_rank(data, params, B, C, config)); + return rcpp_result_gen; +END_RCPP +} // nlopt_optimize_spherical Rcpp::List nlopt_optimize_spherical(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); RcppExport SEXP _PLNmodels_nlopt_optimize_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { @@ -232,34 +288,6 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// nlopt_optimize_rank -Rcpp::List nlopt_optimize_rank(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_rank(data, params, config)); - return rcpp_result_gen; -END_RCPP -} -// nlopt_optimize_vestep_rank -Rcpp::List nlopt_optimize_vestep_rank(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& C, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP CSEXP, SEXP configSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type C(CSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_vestep_rank(data, params, B, C, config)); - return rcpp_result_gen; -END_RCPP -} // zipln_vloglik arma::vec zipln_vloglik(const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& Pi, const arma::mat& Omega, const arma::mat& B, const arma::mat& R, const arma::mat& M, const arma::mat& S); RcppExport SEXP _PLNmodels_zipln_vloglik(SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP PiSEXP, SEXP OmegaSEXP, SEXP BSEXP, SEXP RSEXP, SEXP MSEXP, SEXP SSEXP) { @@ -508,6 +536,8 @@ static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_newton_optimize_fixed", (DL_FUNC) &_PLNmodels_newton_optimize_fixed, 3}, {"_PLNmodels_newton_optimize_full", (DL_FUNC) &_PLNmodels_newton_optimize_full, 3}, {"_PLNmodels_newton_optimize_vestep_full", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_full, 5}, + {"_PLNmodels_newton_optimize_rank", (DL_FUNC) &_PLNmodels_newton_optimize_rank, 3}, + {"_PLNmodels_newton_optimize_vestep_rank", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_rank, 5}, {"_PLNmodels_newton_optimize_spherical", (DL_FUNC) &_PLNmodels_newton_optimize_spherical, 3}, {"_PLNmodels_newton_optimize_vestep_spherical", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_spherical, 5}, {"_PLNmodels_nlopt_optimize_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_diagonal, 3}, @@ -515,12 +545,12 @@ static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_nlopt_optimize_fixed", (DL_FUNC) &_PLNmodels_nlopt_optimize_fixed, 3}, {"_PLNmodels_nlopt_optimize_full", (DL_FUNC) &_PLNmodels_nlopt_optimize_full, 3}, {"_PLNmodels_nlopt_optimize_vestep_full", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_full, 5}, + {"_PLNmodels_nlopt_optimize_rank", (DL_FUNC) &_PLNmodels_nlopt_optimize_rank, 3}, + {"_PLNmodels_nlopt_optimize_vestep_rank", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_rank, 5}, {"_PLNmodels_nlopt_optimize_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_spherical, 3}, {"_PLNmodels_nlopt_optimize_vestep_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_spherical, 5}, {"_PLNmodels_cpp_test_nlopt", (DL_FUNC) &_PLNmodels_cpp_test_nlopt, 0}, {"_PLNmodels_nlopt_optimize_genetic_modeling", (DL_FUNC) &_PLNmodels_nlopt_optimize_genetic_modeling, 7}, - {"_PLNmodels_nlopt_optimize_rank", (DL_FUNC) &_PLNmodels_nlopt_optimize_rank, 3}, - {"_PLNmodels_nlopt_optimize_vestep_rank", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_rank, 5}, {"_PLNmodels_zipln_vloglik", (DL_FUNC) &_PLNmodels_zipln_vloglik, 9}, {"_PLNmodels_optim_zipln_Omega_full", (DL_FUNC) &_PLNmodels_optim_zipln_Omega_full, 4}, {"_PLNmodels_optim_zipln_Omega_spherical", (DL_FUNC) &_PLNmodels_optim_zipln_Omega_spherical, 4}, diff --git a/src/newton_rank_cov.cpp b/src/newton_rank_cov.cpp new file mode 100644 index 00000000..e5ce910d --- /dev/null +++ b/src/newton_rank_cov.cpp @@ -0,0 +1,285 @@ +#include "RcppArmadillo.h" + +// [[Rcpp::depends(RcppArmadillo)]] + +#include "utils.h" + +// --------------------------------------------------------------------------------------- +// Rank-constrained covariance PLN — coordinate-Newton optimizer +// +// Parameters: B (d,p), C (p,q), M (n,q), S (n,q) +// Z = O + X*B + M*C', A = exp(Z + 0.5 * S²*C²ᵀ) +// Objective: Σᵢ wᵢ (A - Y⊙Z) + ½ Σᵢ wᵢ Σₖ (Mᵢₖ² + Sᵢₖ² − log Sᵢₖ² − 1) +// +// Update order per iteration: B → C → M → S +// B, M : diagonal Newton + Armijo (standard) +// C : diagonal Newton (Gauss-Newton Hessian) + Armijo (full Z and A recomputed) +// S : closed-form fixed-point: logS = -½ log(1 + A*C²) + +// [[Rcpp::export]] +Rcpp::List newton_optimize_rank( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(B, C, M, S) + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat C = Rcpp::as(params["C"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + + const double c1 = 1e-4; + const arma::mat Xw = X.each_col() % w; + arma::mat Xw2 = X % X; Xw2.each_col() %= w; + + arma::mat C2 = C % C; + arma::mat S2 = S % S; + arma::mat logS = arma::log(S); + arma::mat Z = O + X * B + M * C.t(); + arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); + + std::vector objective_vec; + double obj_prev = arma::datum::inf; + int total_iter = 0; + int last_status = 5; + + for (int it = 0; it < maxiter; it++) { + + // ---- B step (diagonal Newton + Armijo) ---- + { + arma::mat grad_B = Xw.t() * (A - Y); + arma::mat hess_B = Xw2.t() * A; + hess_B.clamp(1e-10, arma::datum::inf); + arma::mat step_B = grad_B / hess_B; + arma::mat XstepB = X * step_B; + double f0_B = arma::accu(w.t() * (A - Y % Z)); + double slope_B = -arma::accu(grad_B % step_B); + double alpha_B = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Zt = Z - alpha_B * XstepB; + if (arma::accu(w.t() * (arma::exp(Zt + 0.5 * S2 * C2.t()) - Y % Zt)) + <= f0_B + c1 * alpha_B * slope_B) break; + alpha_B *= 0.5; + } + B -= alpha_B * step_B; + Z = O + X * B + M * C.t(); + A = arma::exp(Z + 0.5 * S2 * C2.t()); + } + + // ---- M step (diagonal Newton + Armijo) ---- + // grad_M = diag(w) * ((A-Y)*C + M), hess_M = diag(w) * (A*C² + 1) + { + arma::mat grad_M = (A - Y) * C + M; grad_M.each_col() %= w; + arma::mat hess_M = A * C2 + 1.; hess_M.each_col() %= w; + hess_M.clamp(1e-10, arma::datum::inf); + arma::mat step_M = grad_M / hess_M; + arma::mat stepMCt = step_M * C.t(); + double f0_M = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * arma::as_scalar(w.t() * arma::sum(M % M, 1)); + double slope_M = -arma::accu(grad_M % step_M); + double alpha_M = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Mt = M - alpha_M * step_M; + arma::mat Zt = Z - alpha_M * stepMCt; + arma::mat At = arma::exp(Zt + 0.5 * S2 * C2.t()); + if (arma::accu(w.t() * (At - Y % Zt)) + + 0.5 * arma::as_scalar(w.t() * arma::sum(Mt % Mt, 1)) + <= f0_M + c1 * alpha_M * slope_M) break; + alpha_M *= 0.5; + } + M -= alpha_M * step_M; + Z = O + X * B + M * C.t(); + A = arma::exp(Z + 0.5 * S2 * C2.t()); + } + + // ---- C step (exact diagonal Newton + Armijo) ---- + // Exact diagonal Hessian: h_{jk} = Σᵢ wᵢ Aᵢⱼ [(Mᵢₖ + S²ᵢₖ Cⱼₖ)² + S²ᵢₖ] + { + const arma::uword p = C.n_rows, q = C.n_cols; + arma::mat AmY = A - Y; AmY.each_col() %= w; + arma::mat grad_C = AmY.t() * M + (A.t() * (S2.each_col() % w)) % C; + arma::mat hess_C(p, q); + for (arma::uword k = 0; k < q; k++) { + // Fk_{ij} = M_{ik} + S2_{ik} * C_{jk} (n×p outer product) + arma::mat Fk = M.col(k) * arma::ones(1, p) + + S2.col(k) * C.col(k).t(); + hess_C.col(k) = (A % (arma::square(Fk) + S2.col(k) * arma::ones(1, p))).t() * w; + } + hess_C.clamp(1e-10, arma::datum::inf); + arma::mat step_C = grad_C / hess_C; + double f0_C = arma::accu(w.t() * (A - Y % Z)); + double slope_C = -arma::accu(grad_C % step_C); + double alpha_C = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Ct = C - alpha_C * step_C; + arma::mat Zt = O + X * B + M * Ct.t(); + arma::mat At = arma::exp(Zt + 0.5 * S2 * (Ct % Ct).t()); + if (arma::accu(w.t() * (At - Y % Zt)) + <= f0_C + c1 * alpha_C * slope_C) break; + alpha_C *= 0.5; + } + C -= alpha_C * step_C; + C2 = C % C; + Z = O + X * B + M * C.t(); + A = arma::exp(Z + 0.5 * S2 * C2.t()); + } + + // ---- S step (closed-form fixed-point) ---- + // From ∂obj/∂Sᵢₖ = 0: Sᵢₖ = 1/√(1 + (A*C²)ᵢₖ) + { + logS = arma::clamp(-0.5 * arma::log(1. + A * C2), -20., 0.); + S = arma::exp(logS); + S2 = S % S; + A = arma::exp(Z + 0.5 * S2 * C2.t()); + } + + // ---- Convergence check ---- + double obj = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * arma::accu(w.t() * (M % M + S2 - arma::trunc_log(S2) - 1.)); + objective_vec.push_back(obj); + total_iter++; + + if (it > 0 && converged(obj, obj_prev, ftol)) { last_status = 3; break; } + obj_prev = obj; + } + + // ---- Final output ---- + S2 = S % S; + Z = O + X * B + M * C.t(); + A = arma::exp(Z + 0.5 * S2 * C2.t()); + const double w_bar = arma::accu(w); + arma::mat nSig = M.t() * (M.each_col() % w) + arma::diagmat(arma::sum(S2.each_col() % w, 0)); + arma::mat Sigma = C * nSig * C.t() / w_bar; + arma::mat Omega = C * arma::inv_sympd(nSig / w_bar) * C.t(); + arma::vec loglik = arma::sum(Y % Z - A, 1) + - 0.5 * arma::sum(M % M + S2 - arma::trunc_log(S2) - 1., 1) + + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("B", B ), + Rcpp::Named("C", C ), + Rcpp::Named("M", M ), + Rcpp::Named("S", S ), + Rcpp::Named("Z", Z ), + Rcpp::Named("A", A ), + Rcpp::Named("Sigma", Sigma), + Rcpp::Named("Omega", Omega), + Rcpp::Named("Ji", Ji ), + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", last_status ), + Rcpp::Named("backend", "newton" ), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", total_iter ) + )) + ); +} + +// --------------------------------------------------------------------------------------- +// VE rank — coordinate-Newton (M and S only, B and C fixed) + +// [[Rcpp::export]] +Rcpp::List newton_optimize_vestep_rank( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(M, S) + const arma::mat & B, // (d,p) fixed + const arma::mat & C, // (p,q) fixed + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + + const double c1 = 1e-4; + const arma::mat C2 = C % C; + const arma::mat XB = X * B; + + arma::mat S2 = S % S; + arma::mat logS = arma::log(S); + arma::mat Z = O + XB + M * C.t(); + arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); + + std::vector objective_vec; + double obj_prev = arma::datum::inf; + int total_iter = 0; + + for (int it = 0; it < maxiter; it++) { + + // ---- M step (diagonal Newton + Armijo) ---- + { + arma::mat grad_M = (A - Y) * C + M; grad_M.each_col() %= w; + arma::mat hess_M = A * C2 + 1.; hess_M.each_col() %= w; + hess_M.clamp(1e-10, arma::datum::inf); + arma::mat step_M = grad_M / hess_M; + arma::mat stepMCt = step_M * C.t(); + double f0_M = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * arma::as_scalar(w.t() * arma::sum(M % M, 1)); + double slope_M = -arma::accu(grad_M % step_M); + double alpha_M = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Mt = M - alpha_M * step_M; + arma::mat Zt = Z - alpha_M * stepMCt; + arma::mat At = arma::exp(Zt + 0.5 * S2 * C2.t()); + if (arma::accu(w.t() * (At - Y % Zt)) + + 0.5 * arma::as_scalar(w.t() * arma::sum(Mt % Mt, 1)) + <= f0_M + c1 * alpha_M * slope_M) break; + alpha_M *= 0.5; + } + M -= alpha_M * step_M; + Z = O + XB + M * C.t(); + A = arma::exp(Z + 0.5 * S2 * C2.t()); + } + + // ---- S step (closed-form fixed-point) ---- + { + logS = arma::clamp(-0.5 * arma::log(1. + A * C2), -20., 0.); + S = arma::exp(logS); + S2 = S % S; + A = arma::exp(Z + 0.5 * S2 * C2.t()); + } + + // ---- Convergence check ---- + double obj = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * arma::accu(w.t() * (M % M + S2 - arma::trunc_log(S2) - 1.)); + objective_vec.push_back(obj); + total_iter++; + + if (it > 0 && converged(obj, obj_prev, ftol)) break; + obj_prev = obj; + } + + // ---- Final output ---- + S2 = S % S; + Z = O + XB + M * C.t(); + A = arma::exp(Z + 0.5 * S2 * C2.t()); + arma::vec loglik = arma::sum(Y % Z - A, 1) + - 0.5 * arma::sum(M % M + S2 - arma::trunc_log(S2) - 1., 1) + + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("M") = M, + Rcpp::Named("S") = S, + Rcpp::Named("Ji") = Ji, + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", 3 ), + Rcpp::Named("backend", "newton" ), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", total_iter ) + )) + ); +} diff --git a/src/nlopt_diag_cov.cpp b/src/nlopt_diag_cov.cpp index 8aa2f2bb..1d16f8f0 100644 --- a/src/nlopt_diag_cov.cpp +++ b/src/nlopt_diag_cov.cpp @@ -31,7 +31,7 @@ Rcpp::List nlopt_optimize_diagonal( auto parameters = std::vector(metadata.packed_size); metadata.map(parameters.data()) = init_B; metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = init_S; + metadata.map(parameters.data()) = arma::log(init_S % init_S); // pack logS2 auto optimizer = new_nlopt_optimizer(config, parameters.size()); std::vector objective_vec ; @@ -42,19 +42,21 @@ Rcpp::List nlopt_optimize_diagonal( // Optimize auto objective_and_grad = [&metadata, &O, &X, &Xw, &Y, &w, &w_bar, &objective_vec](const double * params, double * grad) -> double { - const arma::mat B = metadata.map(params); - const arma::mat M = metadata.map(params); - const arma::mat S = metadata.map(params); + const arma::mat B = metadata.map(params); + const arma::mat M = metadata.map(params); + const arma::mat logS2 = metadata.map(params); - arma::mat S2 = S % S; + arma::mat S2 = arma::exp(logS2); arma::mat Z = O + X * B + M; arma::mat A = exp(Z + 0.5 * S2); arma::rowvec diag_sigma = w.t() * (M % M + S2) / w_bar; - double objective = accu(diagmat(w) * (A - Y % Z - 0.5 * log(S2))) + 0.5 * w_bar * accu(log(diag_sigma)); + // -½ log(S²) → -½ logS2 + double objective = accu(diagmat(w) * (A - Y % Z - 0.5 * logS2)) + 0.5 * w_bar * accu(log(diag_sigma)); metadata.map(grad) = Xw.t() * (A - Y); metadata.map(grad) = diagmat(w) * ((M.each_row() / diag_sigma) + A - Y); - metadata.map(grad) = diagmat(w) * (S.each_row() % pow(diag_sigma, -1) + S % A - pow(S, -1)); + // grad_logS2 = ½ w ⊙ (S²⊙(1/σ² + A) − 1) + metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % pow(diag_sigma, -1) + S2 % A - 1.); objective_vec.push_back(objective) ; @@ -63,9 +65,10 @@ Rcpp::List nlopt_optimize_diagonal( OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); // Variational parameters - arma::mat M = metadata.copy(parameters.data()); - arma::mat S = metadata.copy(parameters.data()); - arma::mat S2 = S % S; + arma::mat M = metadata.copy(parameters.data()); + arma::mat logS2 = metadata.copy(parameters.data()); + arma::mat S2 = arma::exp(logS2); + arma::mat S = arma::exp(0.5 * logS2); // Regression parameters arma::mat B = metadata.copy(parameters.data()); // Variance parameters @@ -79,7 +82,7 @@ Rcpp::List nlopt_optimize_diagonal( arma::mat Z = O + X * B + M; arma::mat A = exp(Z + 0.5 * S2); arma::mat loglik = - sum(Y % Z - A + 0.5 * log(S2), 1) - 0.5 * (pow(M, 2) + S2) * omega2 + 0.5 * sum(log(omega2)) + ki(Y); + sum(Y % Z - A + 0.5 * logS2, 1) - 0.5 * (pow(M, 2) + S2) * omega2 + 0.5 * sum(log(omega2)) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; @@ -124,7 +127,7 @@ Rcpp::List nlopt_optimize_vestep_diagonal( auto parameters = std::vector(metadata.packed_size); metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = init_S; + metadata.map(parameters.data()) = arma::log(init_S % init_S); // pack logS2 auto optimizer = new_nlopt_optimizer(config, parameters.size()); std::vector objective_vec ; @@ -135,17 +138,17 @@ Rcpp::List nlopt_optimize_vestep_diagonal( // Optimize auto objective_and_grad = [&metadata, &O, &XB_diag, &Y, &w, &omega2_v, &objective_vec](const double * params, double * grad) -> double { - const arma::mat M = metadata.map(params); - const arma::mat S = metadata.map(params); + const arma::mat M = metadata.map(params); + const arma::mat logS2 = metadata.map(params); - arma::mat S2 = S % S; + arma::mat S2 = arma::exp(logS2); arma::mat Z = O + XB_diag + M; arma::mat A = exp(Z + 0.5 * S2); double objective = - accu(w.t() * (A - Y % Z - 0.5 * log(S2))) + 0.5 * as_scalar(w.t() * (pow(M, 2) + S2) * omega2_v) ; + accu(w.t() * (A - Y % Z - 0.5 * logS2)) + 0.5 * as_scalar(w.t() * (pow(M, 2) + S2) * omega2_v) ; metadata.map(grad) = diagmat(w) * (M * arma::diagmat(omega2_v) + A - Y); - metadata.map(grad) = diagmat(w) * (S.each_row() % omega2_v.t() + S % A - pow(S, -1)); + metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % omega2_v.t() + S2 % A - 1.); objective_vec.push_back(objective) ; @@ -154,15 +157,16 @@ Rcpp::List nlopt_optimize_vestep_diagonal( OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); // Model and variational parameters - arma::mat M = metadata.copy(parameters.data()); - arma::mat S = metadata.copy(parameters.data()); - arma::mat S2 = S % S; + arma::mat M = metadata.copy(parameters.data()); + arma::mat logS2 = metadata.copy(parameters.data()); + arma::mat S2 = arma::exp(logS2); + arma::mat S = arma::exp(0.5 * logS2); arma::vec omega2 = Omega.diag(); // Element-wise log-likelihood arma::mat Z = O + X * B + M; arma::mat A = exp(Z + 0.5 * S2); arma::mat loglik = - sum(Y % Z - A + 0.5 * log(S2), 1) - 0.5 * (pow(M, 2) + S2) * omega2 + 0.5 * sum(log(omega2)) + ki(Y); + sum(Y % Z - A + 0.5 * logS2, 1) - 0.5 * (pow(M, 2) + S2) * omega2 + 0.5 * sum(log(omega2)) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; diff --git a/src/nlopt_fixed_cov.cpp b/src/nlopt_fixed_cov.cpp index 05362957..ee545674 100644 --- a/src/nlopt_fixed_cov.cpp +++ b/src/nlopt_fixed_cov.cpp @@ -32,26 +32,31 @@ Rcpp::List nlopt_optimize_fixed( auto parameters = std::vector(metadata.packed_size); metadata.map(parameters.data()) = init_B; metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = init_S; + metadata.map(parameters.data()) = arma::log(init_S % init_S); // pack logS2 // Optimize auto optimizer = new_nlopt_optimizer(config, parameters.size()); std::vector objective_vec ; - auto objective_and_grad = [&metadata, &O, &X, &Y, &w, &Omega, &objective_vec](const double * params, double * grad) -> double { - const arma::mat B = metadata.map(params); - const arma::mat M = metadata.map(params); - const arma::mat S = metadata.map(params); + const arma::mat Xw = X.each_col() % w; // fixed: precomputed once + const arma::vec Omega_diag = diagvec(Omega); - arma::mat S2 = S % S; + auto objective_and_grad = [&metadata, &O, &X, &Xw, &Y, &w, &Omega, &Omega_diag, &objective_vec](const double * params, double * grad) -> double { + const arma::mat B = metadata.map(params); + const arma::mat M = metadata.map(params); + const arma::mat logS2 = metadata.map(params); + + arma::mat S2 = arma::exp(logS2); arma::mat Z = O + X * B + M; arma::mat A = exp(Z + 0.5 * S2); arma::mat nSigma = M.t() * (M.each_col() % w) + diagmat(w.t() * S2); - double objective = accu(w.t() * (A - Y % Z - 0.5 * log(S2))) + 0.5 * trace(Omega * nSigma); + // -½ log(S²) → -½ logS2 + double objective = accu(w.t() * (A - Y % Z - 0.5 * logS2)) + 0.5 * trace(Omega * nSigma); - metadata.map(grad) = (X.each_col() % w).t() * (A - Y); + metadata.map(grad) = Xw.t() * (A - Y); metadata.map(grad) = diagmat(w) * (M * Omega + A - Y); - metadata.map(grad) = diagmat(w) * (S.each_row() % diagvec(Omega).t() + S % A - pow(S, -1)) ; + // grad_logS2 = ½ w ⊙ (S²⊙(Ω_diag + A) − 1) + metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % Omega_diag.t() + S2 % A - 1.) ; objective_vec.push_back(objective) ; @@ -60,15 +65,16 @@ Rcpp::List nlopt_optimize_fixed( OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); // Model and variational parameters - arma::mat B = metadata.copy(parameters.data()); - arma::mat M = metadata.copy(parameters.data()); - arma::mat S = metadata.copy(parameters.data()); - arma::mat S2 = S % S; + arma::mat B = metadata.copy(parameters.data()); + arma::mat M = metadata.copy(parameters.data()); + arma::mat logS2 = metadata.copy(parameters.data()); + arma::mat S2 = arma::exp(logS2); + arma::mat S = arma::exp(0.5 * logS2); arma::mat Sigma = (M.t() * (M.each_col() % w) + diagmat(w.t() * S2)) / accu(w); // Element-wise log-likelihood arma::mat Z = O + X * B + M; arma::mat A = exp(Z + 0.5 * S2); - arma::mat loglik = sum(Y % Z - A - 0.5 * ((M * Omega) % M - log(S2) + S2 * diagmat(Omega)), 1) + + arma::mat loglik = sum(Y % Z - A - 0.5 * ((M * Omega) % M - logS2 + S2 * diagmat(Omega)), 1) + 0.5 * real(log_det(Omega)) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); diff --git a/src/nlopt_full_cov.cpp b/src/nlopt_full_cov.cpp index e5044db7..ab7ca9e7 100644 --- a/src/nlopt_full_cov.cpp +++ b/src/nlopt_full_cov.cpp @@ -31,7 +31,7 @@ Rcpp::List nlopt_optimize_full( auto parameters = std::vector(metadata.packed_size); metadata.map(parameters.data()) = init_B; metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = init_S; + metadata.map(parameters.data()) = arma::log(init_S % init_S); // pack logS2 const double w_bar = accu(w); // VEM config — sensible defaults if not supplied by R @@ -59,21 +59,23 @@ Rcpp::List nlopt_optimize_full( const arma::vec Omega_diag = diagvec(Omega); // fixed per EM iteration auto objective_and_grad = [&metadata, &Y, &X, &Xw, &O, &w, &Omega, &Omega_diag, &objective_vec](const double * params, double * grad) -> double { - const arma::mat B = metadata.map(params); - const arma::mat M = metadata.map(params); - const arma::mat S = metadata.map(params); - arma::mat S2 = S % S; + const arma::mat B = metadata.map(params); + const arma::mat M = metadata.map(params); + const arma::mat logS2 = metadata.map(params); // logS2 = log(S²) + arma::mat S2 = arma::exp(logS2); arma::mat Z = O + X * B + M; arma::mat A = exp(Z + 0.5 * S2); arma::mat MO = M * Omega; // cached: reused in objective and M-gradient const arma::rowvec wS2 = w.t() * S2; - double objective = accu(w.t() * (A - Y % Z - 0.5 * trunc_log(S2))) + // -½ log(S²) → -½ logS2 (no log call needed) + double objective = accu(w.t() * (A - Y % Z - 0.5 * logS2)) + 0.5 * (accu(MO % (M.each_col() % w)) + dot(Omega_diag, wS2.t())); metadata.map(grad) = Xw.t() * (A - Y); metadata.map(grad) = diagmat(w) * (MO + A - Y); - metadata.map(grad) = diagmat(w) * (S.each_row() % Omega_diag.t() + S % A - pow(S, -1)); + // grad_logS2 = ½ w ⊙ (S²⊙(Ω_diag + A) − 1) + metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % Omega_diag.t() + S2 % A - 1.); objective_vec.push_back(objective); return objective; @@ -84,9 +86,9 @@ Rcpp::List nlopt_optimize_full( last_status = static_cast(result.status); // M-step: update Omega analytically (one inv_sympd per EM iteration) - arma::mat M = metadata.copy(parameters.data()); - arma::mat S = metadata.copy(parameters.data()); - arma::mat S2 = S % S; + arma::mat M = metadata.copy(parameters.data()); + arma::mat logS2 = metadata.copy(parameters.data()); + arma::mat S2 = arma::exp(logS2); arma::mat Sigma = (1. / w_bar) * (M.t() * (M.each_col() % w) + diagmat(w.t() * S2)); Omega = inv_sympd(Sigma); @@ -94,7 +96,7 @@ Rcpp::List nlopt_optimize_full( arma::mat B = metadata.copy(parameters.data()); arma::mat Z = O + X * B + M; arma::mat A = exp(Z + 0.5 * S2); - double elbo = accu(w.t() * (Y % Z - A + 0.5 * trunc_log(S2))) + double elbo = accu(w.t() * (Y % Z - A + 0.5 * logS2)) - 0.5 * w_bar * real(log_det(Sigma)); if (em_iter > 0 && converged(elbo, elbo_prev, em_ftol)) break; @@ -102,15 +104,16 @@ Rcpp::List nlopt_optimize_full( } // Final extraction - arma::mat M = metadata.copy(parameters.data()); - arma::mat S = metadata.copy(parameters.data()); - arma::mat S2 = S % S; - arma::mat B = metadata.copy(parameters.data()); + arma::mat M = metadata.copy(parameters.data()); + arma::mat logS2 = metadata.copy(parameters.data()); + arma::mat S2 = arma::exp(logS2); + arma::mat S = arma::exp(0.5 * logS2); + arma::mat B = metadata.copy(parameters.data()); arma::mat Sigma = (1. / w_bar) * (M.t() * (M.each_col() % w) + diagmat(w.t() * S2)); // Omega already updated from the last M-step arma::mat Z = O + X * B + M; arma::mat A = exp(Z + 0.5 * S2); - arma::vec loglik = sum(Y % Z - A + 0.5 * log(S2) - 0.5 * ((M * Omega) % M + S2 * diagmat(Omega)), 1) + + arma::vec loglik = sum(Y % Z - A + 0.5 * logS2 - 0.5 * ((M * Omega) % M + S2 * diagmat(Omega)), 1) + 0.5 * real(log_det(Omega)) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); @@ -157,7 +160,7 @@ Rcpp::List nlopt_optimize_vestep_full( auto parameters = std::vector(metadata.packed_size); metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = init_S; + metadata.map(parameters.data()) = arma::log(init_S % init_S); // pack logS2 // Optimize auto optimizer = new_nlopt_optimizer(config, parameters.size()); @@ -168,19 +171,19 @@ Rcpp::List nlopt_optimize_vestep_full( const arma::vec Omega_diag_v = diagvec(Omega); auto objective_and_grad = [&metadata, &O, &XB_vestep, &Y, &w, &Omega, &Omega_diag_v, &objective_vec](const double * params, double * grad) -> double { - const arma::mat M = metadata.map(params); - const arma::mat S = metadata.map(params); + const arma::mat M = metadata.map(params); + const arma::mat logS2 = metadata.map(params); - arma::mat S2 = S % S; + arma::mat S2 = arma::exp(logS2); arma::mat Z = O + XB_vestep + M; arma::mat A = exp(Z + 0.5 * S2); arma::mat MO = M * Omega; const arma::rowvec wS2 = w.t() * S2; - double objective = accu(w.t() * (A - Y % Z - 0.5 * log(S2))) + double objective = accu(w.t() * (A - Y % Z - 0.5 * logS2)) + 0.5 * (accu(MO % (M.each_col() % w)) + dot(Omega_diag_v, wS2.t())); metadata.map(grad) = diagmat(w) * (MO + A - Y); - metadata.map(grad) = diagmat(w) * (S.each_row() % Omega_diag_v.t() + S % A - pow(S, -1)); + metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % Omega_diag_v.t() + S2 % A - 1.); objective_vec.push_back(objective) ; @@ -189,13 +192,14 @@ Rcpp::List nlopt_optimize_vestep_full( OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); // Model and variational parameters - arma::mat M = metadata.copy(parameters.data()); - arma::mat S = metadata.copy(parameters.data()); - arma::mat S2 = S % S; + arma::mat M = metadata.copy(parameters.data()); + arma::mat logS2 = metadata.copy(parameters.data()); + arma::mat S2 = arma::exp(logS2); + arma::mat S = arma::exp(0.5 * logS2); // Element-wise log-likelihood arma::mat Z = O + X * B + M; arma::mat A = exp(Z + 0.5 * S2); - arma::vec loglik = sum(Y % Z - A + 0.5 * log(S2) - 0.5 * ((M * Omega) % M + S2 * diagmat(Omega)), 1) + + arma::vec loglik = sum(Y % Z - A + 0.5 * logS2 - 0.5 * ((M * Omega) % M + S2 * diagmat(Omega)), 1) + 0.5 * real(log_det(Omega)) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); diff --git a/src/optim_rank_cov.cpp b/src/nlopt_rank_cov.cpp similarity index 100% rename from src/optim_rank_cov.cpp rename to src/nlopt_rank_cov.cpp diff --git a/src/nlopt_spherical.cpp b/src/nlopt_spherical.cpp index 8dc1551c..5f12f754 100644 --- a/src/nlopt_spherical.cpp +++ b/src/nlopt_spherical.cpp @@ -31,7 +31,7 @@ Rcpp::List nlopt_optimize_spherical( auto parameters = std::vector(metadata.packed_size); metadata.map(parameters.data()) = init_B; metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = init_S; + metadata.map(parameters.data()) = arma::log(init_S % init_S); // pack logS2 // Optimize auto optimizer = new_nlopt_optimizer(config, parameters.size()); @@ -42,20 +42,22 @@ Rcpp::List nlopt_optimize_spherical( const arma::mat Xw = X.each_col() % w; // fixed: precomputed once auto objective_and_grad = [&metadata, &O, &X, &Xw, &Y, &w, &w_bar, &objective_vec](const double * params, double * grad) -> double { - const arma::mat B = metadata.map(params); - const arma::mat M = metadata.map(params); - const arma::mat S = metadata.map(params); + const arma::mat B = metadata.map(params); + const arma::mat M = metadata.map(params); + const arma::mat logS2 = metadata.map(params); - arma::mat S2 = S % S; + arma::mat S2 = arma::exp(logS2); const arma::uword p = Y.n_cols; arma::mat Z = O + X * B + M; arma::mat A = exp(Z + 0.5 * S2); double sigma2 = accu(diagmat(w) * (pow(M, 2) + S2)) / (double(p) * w_bar) ; - double objective = accu(w.t() * (A - Y % Z - 0.5 * log(S2))) + 0.5 * (double(p) * w_bar) * log(sigma2) ; + // -½ log(S²) → -½ logS2 + double objective = accu(w.t() * (A - Y % Z - 0.5 * logS2)) + 0.5 * (double(p) * w_bar) * log(sigma2) ; metadata.map(grad) = Xw.t() * (A - Y); metadata.map(grad) = diagmat(w) * (M / sigma2 + A - Y); - metadata.map(grad) = diagmat(w) * (S / sigma2 + S % A - pow(S, -1)); + // grad_logS2 = ½ w ⊙ (S²/σ² + S²⊙A − 1) + metadata.map(grad) = 0.5 * diagmat(w) * (S2 / sigma2 + S2 % A - 1.); objective_vec.push_back(objective) ; @@ -64,9 +66,10 @@ Rcpp::List nlopt_optimize_spherical( OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); // Variational parameters - arma::mat M = metadata.copy(parameters.data()); - arma::mat S = metadata.copy(parameters.data()); - arma::mat S2 = S % S; + arma::mat M = metadata.copy(parameters.data()); + arma::mat logS2 = metadata.copy(parameters.data()); + arma::mat S2 = arma::exp(logS2); + arma::mat S = arma::exp(0.5 * logS2); // Regression parameters arma::mat B = metadata.copy(parameters.data()); // Variance parameters @@ -74,10 +77,10 @@ Rcpp::List nlopt_optimize_spherical( const double sigma2 = accu(diagmat(w) * (pow(M, 2) + S2)) / (double(p) * w_bar) ; arma::sp_mat Sigma(p,p); Sigma.diag() = arma::ones(p) * sigma2; arma::sp_mat Omega(p,p); Omega.diag() = arma::ones(p) * pow(sigma2, -1); - // Element-wise log-likelihood + // Element-wise log-likelihood [log(S²/σ²) = logS2 - log(σ²)] arma::mat Z = O + X * B + M; arma::mat A = exp(Z + 0.5 * S2); - arma::mat loglik = sum(Y % Z - A - 0.5 * (pow(M, 2) + S2 ) / sigma2 + 0.5 * log(S2 / sigma2), 1) + ki(Y); + arma::mat loglik = sum(Y % Z - A - 0.5 * (pow(M, 2) + S2) / sigma2 + 0.5 * (logS2 - log(sigma2)), 1) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; @@ -123,7 +126,7 @@ Rcpp::List nlopt_optimize_vestep_spherical( auto parameters = std::vector(metadata.packed_size); metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = init_S; + metadata.map(parameters.data()) = arma::log(init_S % init_S); // pack logS2 // Optimize auto optimizer = new_nlopt_optimizer(config, parameters.size()); @@ -133,18 +136,20 @@ Rcpp::List nlopt_optimize_vestep_spherical( const arma::mat XB_sph = X * B; // fixed: B not optimized in vestep auto objective_and_grad = [&metadata, &O, &XB_sph, &Y, &w, &Omega, &objective_vec](const double * params, double * grad) -> double { - const arma::mat M = metadata.map(params); - const arma::mat S = metadata.map(params); + const arma::mat M = metadata.map(params); + const arma::mat logS2 = metadata.map(params); - arma::mat S2 = S % S; + arma::mat S2 = arma::exp(logS2); arma::mat Z = O + XB_sph + M; arma::mat A = exp(Z + 0.5 * S2); double n_sigma2 = accu(diagmat(w) * (pow(M, 2) + S2)) ; double omega2 = Omega(0, 0); - double objective = accu(w.t() * (A - Y % Z - 0.5 * log(S2))) + 0.5 * n_sigma2 * omega2; + // -½ log(S²) → -½ logS2 + double objective = accu(w.t() * (A - Y % Z - 0.5 * logS2)) + 0.5 * n_sigma2 * omega2; metadata.map(grad) = diagmat(w) * (M / omega2 + A - Y); - metadata.map(grad) = diagmat(w) * (S / omega2 + S % A - pow(S, -1)); + // grad_logS2 = ½ w ⊙ (S²/ω² + S²⊙A − 1) + metadata.map(grad) = 0.5 * diagmat(w) * (S2 / omega2 + S2 % A - 1.); objective_vec.push_back(objective) ; @@ -153,14 +158,15 @@ Rcpp::List nlopt_optimize_vestep_spherical( OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); // Model and variational parameters - arma::mat M = metadata.copy(parameters.data()); - arma::mat S = metadata.copy(parameters.data()); - arma::mat S2 = S % S; + arma::mat M = metadata.copy(parameters.data()); + arma::mat logS2 = metadata.copy(parameters.data()); + arma::mat S2 = arma::exp(logS2); + arma::mat S = arma::exp(0.5 * logS2); double omega2 = Omega(0, 0); - // Element-wise log-likelihood + // Element-wise log-likelihood [log(S²·ω²) = logS2 + log(ω²)] arma::mat Z = O + X * B + M; arma::mat A = exp(Z + 0.5 * S2); - arma::mat loglik = sum(Y % Z - A - 0.5 * (pow(M, 2) + S2 ) * omega2 + 0.5 * log(S2 * omega2), 1) + ki(Y); + arma::mat loglik = sum(Y % Z - A - 0.5 * (pow(M, 2) + S2) * omega2 + 0.5 * (logS2 + log(omega2)), 1) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; From 9efb31911938308501d02d5afadce88dcc6368a3 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Tue, 9 Jun 2026 11:21:04 +0200 Subject: [PATCH 14/58] =?UTF-8?q?logS=C2=B2=20dans=20la=20version=20maison?= =?UTF-8?q?=20Newton=20de=20=20l'optim=20PLNPCA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/newton_rank_cov.cpp | 55 +++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/newton_rank_cov.cpp b/src/newton_rank_cov.cpp index e5ce910d..afa39e50 100644 --- a/src/newton_rank_cov.cpp +++ b/src/newton_rank_cov.cpp @@ -14,7 +14,7 @@ // Update order per iteration: B → C → M → S // B, M : diagonal Newton + Armijo (standard) // C : diagonal Newton (Gauss-Newton Hessian) + Armijo (full Z and A recomputed) -// S : closed-form fixed-point: logS = -½ log(1 + A*C²) +// S : closed-form exact minimiser in ψ = logS² space: ψ = −log(1 + A·C²) // [[Rcpp::export]] Rcpp::List newton_optimize_rank( @@ -38,11 +38,11 @@ Rcpp::List newton_optimize_rank( const arma::mat Xw = X.each_col() % w; arma::mat Xw2 = X % X; Xw2.each_col() %= w; - arma::mat C2 = C % C; - arma::mat S2 = S % S; - arma::mat logS = arma::log(S); - arma::mat Z = O + X * B + M * C.t(); - arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); + arma::mat C2 = C % C; + arma::mat psi = arma::log(S % S); // ψ = log(S²), work in logS² space throughout + arma::mat S2 = arma::exp(psi); + arma::mat Z = O + X * B + M * C.t(); + arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); std::vector objective_vec; double obj_prev = arma::datum::inf; @@ -130,18 +130,18 @@ Rcpp::List newton_optimize_rank( A = arma::exp(Z + 0.5 * S2 * C2.t()); } - // ---- S step (closed-form fixed-point) ---- - // From ∂obj/∂Sᵢₖ = 0: Sᵢₖ = 1/√(1 + (A*C²)ᵢₖ) + // ---- S step (exact minimiser in ψ = logS² space) ---- + // ∂F/∂ψᵢₖ = 0 ⟹ ψᵢₖ = −log(1 + (A·C²)ᵢₖ) + // KL term: S² − logS² − 1 = exp(ψ) − ψ − 1 { - logS = arma::clamp(-0.5 * arma::log(1. + A * C2), -20., 0.); - S = arma::exp(logS); - S2 = S % S; - A = arma::exp(Z + 0.5 * S2 * C2.t()); + psi = arma::clamp(-arma::log(1. + A * C2), -40., 0.); + S2 = arma::exp(psi); + A = arma::exp(Z + 0.5 * S2 * C2.t()); } // ---- Convergence check ---- double obj = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::accu(w.t() * (M % M + S2 - arma::trunc_log(S2) - 1.)); + + 0.5 * arma::accu(w.t() * (M % M + S2 - psi - 1.)); objective_vec.push_back(obj); total_iter++; @@ -150,7 +150,8 @@ Rcpp::List newton_optimize_rank( } // ---- Final output ---- - S2 = S % S; + S2 = arma::exp(psi); + S = arma::exp(0.5 * psi); Z = O + X * B + M * C.t(); A = arma::exp(Z + 0.5 * S2 * C2.t()); const double w_bar = arma::accu(w); @@ -158,7 +159,7 @@ Rcpp::List newton_optimize_rank( arma::mat Sigma = C * nSig * C.t() / w_bar; arma::mat Omega = C * arma::inv_sympd(nSig / w_bar) * C.t(); arma::vec loglik = arma::sum(Y % Z - A, 1) - - 0.5 * arma::sum(M % M + S2 - arma::trunc_log(S2) - 1., 1) + - 0.5 * arma::sum(M % M + S2 - psi - 1., 1) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); @@ -207,10 +208,10 @@ Rcpp::List newton_optimize_vestep_rank( const arma::mat C2 = C % C; const arma::mat XB = X * B; - arma::mat S2 = S % S; - arma::mat logS = arma::log(S); - arma::mat Z = O + XB + M * C.t(); - arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); + arma::mat psi = arma::log(S % S); // ψ = log(S²) + arma::mat S2 = arma::exp(psi); + arma::mat Z = O + XB + M * C.t(); + arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); std::vector objective_vec; double obj_prev = arma::datum::inf; @@ -243,17 +244,16 @@ Rcpp::List newton_optimize_vestep_rank( A = arma::exp(Z + 0.5 * S2 * C2.t()); } - // ---- S step (closed-form fixed-point) ---- + // ---- S step (exact minimiser in ψ = logS² space) ---- { - logS = arma::clamp(-0.5 * arma::log(1. + A * C2), -20., 0.); - S = arma::exp(logS); - S2 = S % S; - A = arma::exp(Z + 0.5 * S2 * C2.t()); + psi = arma::clamp(-arma::log(1. + A * C2), -40., 0.); + S2 = arma::exp(psi); + A = arma::exp(Z + 0.5 * S2 * C2.t()); } // ---- Convergence check ---- double obj = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::accu(w.t() * (M % M + S2 - arma::trunc_log(S2) - 1.)); + + 0.5 * arma::accu(w.t() * (M % M + S2 - psi - 1.)); objective_vec.push_back(obj); total_iter++; @@ -262,11 +262,12 @@ Rcpp::List newton_optimize_vestep_rank( } // ---- Final output ---- - S2 = S % S; + S2 = arma::exp(psi); + S = arma::exp(0.5 * psi); Z = O + XB + M * C.t(); A = arma::exp(Z + 0.5 * S2 * C2.t()); arma::vec loglik = arma::sum(Y % Z - A, 1) - - 0.5 * arma::sum(M % M + S2 - arma::trunc_log(S2) - 1., 1) + - 0.5 * arma::sum(M % M + S2 - psi - 1., 1) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); From 977f4bccaed6b034d5d634b1a3e9f2f5ca5dd580 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Tue, 9 Jun 2026 11:40:56 +0200 Subject: [PATCH 15/58] added homemade backend --- R/PLN.R | 14 ++++++++------ R/PLNPCA.R | 12 +++++++----- R/PLNPCAfit-class.R | 5 ++--- R/PLNfit-class.R | 18 +++++++----------- R/utils.R | 17 +++++++---------- 5 files changed, 31 insertions(+), 35 deletions(-) diff --git a/R/PLN.R b/R/PLN.R index 903fe4ba..9033c710 100644 --- a/R/PLN.R +++ b/R/PLN.R @@ -55,7 +55,9 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { #' #' Helper to define list of parameters to control the PLN fit. All arguments have defaults. #' -#' @param backend optimization back used, either "nlopt" or "torch". Default is "nlopt" +#' @param backend optimization back used, either "nlopt", "torch", or "homemade". Default is "nlopt". +#' Use "homemade" for the built-in coordinate-Newton optimizer (exact diagonal Newton steps), +#' which does not depend on NLOPT. #' @param covariance character setting the model for the covariance matrix. Either "full", "diagonal", "spherical" or "fixed". Default is "full". #' @param Omega precision matrix of the latent variables. Inverse of Sigma. Must be specified if `covariance` is "fixed" #' @param config_optim a list for controlling the optimizer (either "nlopt" or "torch" backend). See details @@ -99,7 +101,7 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { #' #' @export PLN_param <- function( - backend = c("nlopt", "torch"), + backend = c("homemade", "nlopt", "torch"), trace = 1, covariance = c("full", "diagonal", "spherical", "fixed"), Omega = NULL, @@ -119,14 +121,14 @@ PLN_param <- function( ## optimization config backend <- match.arg(backend) - stopifnot(backend %in% c("nlopt", "torch")) if (backend == "nlopt") { stopifnot(config_optim$algorithm %in% available_algorithms_nlopt) - config_opt <- config_default_nlopt_pln - } - if (backend == "torch") { + config_opt <- config_default_nlopt + } else if (backend == "torch") { stopifnot(config_optim$algorithm %in% available_algorithms_torch) config_opt <- config_default_torch + } else { # "homemade" + config_opt <- config_default_homemade } config_opt[names(config_optim)] <- config_optim config_opt$trace <- trace diff --git a/R/PLNPCA.R b/R/PLNPCA.R index 85c0ed40..0ef10612 100644 --- a/R/PLNPCA.R +++ b/R/PLNPCA.R @@ -61,7 +61,9 @@ PLNPCA <- function(formula, data, subset, weights, ranks = 1:5, control = PLNPCA #' #' Helper to define list of parameters to control the PLNPCA fit. All arguments have defaults. #' -#' @param backend optimization back used, either "nlopt" or "torch". Default is "nlopt" +#' @param backend optimization back used, either "nlopt", "torch", or "homemade". Default is "nlopt". +#' Use "homemade" for the built-in coordinate-Newton optimizer (exact diagonal Newton steps for +#' B, M, C, and closed-form update for S in log(S²) space), which does not depend on 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 @@ -79,7 +81,7 @@ PLNPCA <- function(formula, data, subset, weights, ranks = 1:5, control = PLNPCA #' @inherit PLN_param details #' @export PLNPCA_param <- function( - backend = c("nlopt", "torch"), + backend = c("nlopt", "torch", "homemade"), trace = 1 , config_optim = list() , config_post = list() , @@ -96,14 +98,14 @@ PLNPCA_param <- function( ## optimization config backend <- match.arg(backend) - stopifnot(backend %in% c("nlopt", "torch")) if (backend == "nlopt") { stopifnot(config_optim$algorithm %in% available_algorithms_nlopt) config_opt <- config_default_nlopt - } - if (backend == "torch") { + } else if (backend == "torch") { stopifnot(config_optim$algorithm %in% available_algorithms_torch) config_opt <- config_default_torch + } else { # "homemade" + config_opt <- config_default_homemade } config_opt[names(config_optim)] <- config_optim config_opt$trace <- trace diff --git a/R/PLNPCAfit-class.R b/R/PLNPCAfit-class.R index 38590f22..9afdfad5 100644 --- a/R/PLNPCAfit-class.R +++ b/R/PLNPCAfit-class.R @@ -236,15 +236,14 @@ PLNPCAfit <- R6Class( #' @description Initialize a [`PLNPCAfit`] object initialize = function(rank, responses, covariates, offsets, weights, formula, control) { super$initialize(responses, covariates, offsets, weights, formula, control) - is_newton <- identical(control$config_optim$algorithm, "NEWTON") if (control$backend == "torch") { private$optimizer$main <- private$torch_optimize_rank - } else if (is_newton) { + } else if (control$backend == "homemade") { private$optimizer$main <- newton_optimize_rank } else { private$optimizer$main <- nlopt_optimize_rank } - private$optimizer$vestep <- if (is_newton) newton_optimize_vestep_rank else nlopt_optimize_vestep_rank + private$optimizer$vestep <- if (control$backend == "homemade") newton_optimize_vestep_rank else nlopt_optimize_vestep_rank if (!is.null(control$svdM)) { svdM <- control$svdM } else { diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index 079d05fe..58a5741d 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -360,15 +360,14 @@ PLNfit <- R6Class( private$M <- start_point$M private$S <- start_point$S } - is_newton <- identical(control$config_optim$algorithm, "NEWTON") private$optimizer$main <- if (control$backend == "torch") { private$torch_optimize - } else if (is_newton) { + } else if (control$backend == "homemade") { newton_optimize_full } else { nlopt_optimize_full } - private$optimizer$vestep <- if (is_newton) newton_optimize_vestep_full else nlopt_optimize_vestep_full + private$optimizer$vestep <- if (control$backend == "homemade") newton_optimize_vestep_full else nlopt_optimize_vestep_full }, ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -743,15 +742,14 @@ PLNfit_diagonal <- R6Class( #' @description Initialize a [`PLNfit`] model initialize = function(responses, covariates, offsets, weights, formula, control) { super$initialize(responses, covariates, offsets, weights, formula, control) - is_newton <- identical(control$config_optim$algorithm, "NEWTON") private$optimizer$main <- if (control$backend == "torch") { private$torch_optimize - } else if (is_newton) { + } else if (control$backend == "homemade") { newton_optimize_diagonal } else { nlopt_optimize_diagonal } - private$optimizer$vestep <- if (is_newton) newton_optimize_vestep_diagonal else nlopt_optimize_vestep_diagonal + private$optimizer$vestep <- if (control$backend == "homemade") newton_optimize_vestep_diagonal else nlopt_optimize_vestep_diagonal } ), private = list( @@ -833,15 +831,14 @@ PLNfit_spherical <- R6Class( #' @description Initialize a [`PLNfit`] model initialize = function(responses, covariates, offsets, weights, formula, control) { super$initialize(responses, covariates, offsets, weights, formula, control) - is_newton <- identical(control$config_optim$algorithm, "NEWTON") private$optimizer$main <- if (control$backend == "torch") { private$torch_optimize - } else if (is_newton) { + } else if (control$backend == "homemade") { newton_optimize_spherical } else { nlopt_optimize_spherical } - private$optimizer$vestep <- if (is_newton) newton_optimize_vestep_spherical else nlopt_optimize_vestep_spherical + private$optimizer$vestep <- if (control$backend == "homemade") newton_optimize_vestep_spherical else nlopt_optimize_vestep_spherical } ), private = list( @@ -927,10 +924,9 @@ PLNfit_fixedcov <- R6Class( #' @description Initialize a [`PLNfit`] model initialize = function(responses, covariates, offsets, weights, formula, control) { super$initialize(responses, covariates, offsets, weights, formula, control) - is_newton <- identical(control$config_optim$algorithm, "NEWTON") private$optimizer$main <- if (control$backend == "torch") { private$torch_optimize - } else if (is_newton) { + } else if (control$backend == "homemade") { newton_optimize_fixed } else { nlopt_optimize_fixed diff --git a/R/utils.R b/R/utils.R index ca8a53aa..bbd672cb 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,4 +1,4 @@ -available_algorithms_nlopt <- c("MMA", "CCSAQ", "LBFGS", "VAR1", "VAR2", "NEWTON") +available_algorithms_nlopt <- c("MMA", "CCSAQ", "LBFGS", "VAR1", "VAR2") available_algorithms_torch <- c("RPROP", "RMSPROP", "ADAM", "ADAGRAD") config_default_nlopt <- @@ -13,16 +13,13 @@ config_default_nlopt <- maxtime = -1 ) -config_default_nlopt_pln <- + +config_default_homemade <- list( - algorithm = "NEWTON", - backend = "nlopt", - maxeval = 10000 , - ftol_rel = 1e-8 , - xtol_rel = 1e-6 , - ftol_abs = 0.0 , - xtol_abs = 0.0 , - maxtime = -1 + algorithm = "NEWTON", + backend = "homemade", + maxeval = 10000, + ftol_rel = 1e-8 ) config_default_torch <- From 24aa97beffb83eb1004b4120ee8e97fab53c7922 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Tue, 9 Jun 2026 12:04:42 +0200 Subject: [PATCH 16/58] testing homemade newton as default --- src/CovarianceTraits.h | 24 ++++++++++++++---------- src/newton_impl.h | 38 +++++++++++++++++++++----------------- src/utils.h | 18 +++++++++--------- 3 files changed, 44 insertions(+), 36 deletions(-) diff --git a/src/CovarianceTraits.h b/src/CovarianceTraits.h index 341f54d8..f217e66e 100644 --- a/src/CovarianceTraits.h +++ b/src/CovarianceTraits.h @@ -59,8 +59,9 @@ struct FullCovTraits { } static arma::vec final_loglik(const arma::mat & Y, const arma::mat & Z, const arma::mat & A, - const arma::mat & M, const arma::mat & S2, const State & s) { - return arma::sum(Y % Z - A + 0.5 * arma::log(S2) + const arma::mat & M, const arma::mat & psi, const State & s) { + const arma::mat S2 = arma::exp(psi); + return arma::sum(Y % Z - A + 0.5 * psi - 0.5 * ((M * s.Omega) % M + S2 * arma::diagmat(s.Omega)), 1) + 0.5 * std::real(arma::log_det(s.Omega)) + ki(Y); } @@ -124,9 +125,10 @@ struct DiagonalCovTraits { } static arma::vec final_loglik(const arma::mat & Y, const arma::mat & Z, const arma::mat & A, - const arma::mat & M, const arma::mat & S2, const State & s) { - arma::vec omega2_v = s.omega2.t(); - return arma::sum(Y % Z - A + 0.5 * arma::log(S2), 1) + const arma::mat & M, const arma::mat & psi, const State & s) { + const arma::mat S2 = arma::exp(psi); + const arma::vec omega2_v = s.omega2.t(); + return arma::sum(Y % Z - A + 0.5 * psi, 1) - 0.5 * (M % M + S2) * omega2_v + 0.5 * arma::accu(arma::log(omega2_v)) + ki(Y); } @@ -160,7 +162,7 @@ struct SphericalCovTraits { : omega2(omega_mat(0, 0)), sigma2(1.0 / omega_mat(0, 0)) {} }; - // returns double: fixed_point_logS handles scalar broadcast + // returns double: fixed_point_psi handles scalar broadcast static double cov_diag(const State & s, const arma::mat & /*ones_row*/) { return s.omega2; } @@ -193,8 +195,9 @@ struct SphericalCovTraits { } static arma::vec final_loglik(const arma::mat & Y, const arma::mat & Z, const arma::mat & A, - const arma::mat & M, const arma::mat & S2, const State & s) { - return arma::sum(Y % Z - A - 0.5 * (M % M + S2) / s.sigma2 + 0.5 * arma::log(S2 / s.sigma2), 1) + const arma::mat & M, const arma::mat & psi, const State & s) { + const arma::mat S2 = arma::exp(psi); + return arma::sum(Y % Z - A - 0.5 * (M % M + S2) / s.sigma2 + 0.5 * (psi - std::log(s.sigma2)), 1) + ki(Y); } @@ -254,8 +257,9 @@ struct FixedCovTraits { } static arma::vec final_loglik(const arma::mat & Y, const arma::mat & Z, const arma::mat & A, - const arma::mat & M, const arma::mat & S2, const State & s) { - return arma::sum(Y % Z - A + 0.5 * arma::log(S2) + const arma::mat & M, const arma::mat & psi, const State & s) { + const arma::mat S2 = arma::exp(psi); + return arma::sum(Y % Z - A + 0.5 * psi - 0.5 * ((M * s.Omega) % M + S2 * arma::diagmat(s.Omega)), 1) + 0.5 * std::real(arma::log_det(s.Omega)) + ki(Y); } diff --git a/src/newton_impl.h b/src/newton_impl.h index e3b6e018..b3260d36 100644 --- a/src/newton_impl.h +++ b/src/newton_impl.h @@ -22,8 +22,8 @@ Rcpp::List newton_optimize_impl( arma::mat Xw2 = X % X; Xw2.each_col() %= w; const arma::mat ones_row = arma::ones(n, 1); - arma::mat S2 = S % S; - arma::mat logS = arma::log(S); + arma::mat psi = arma::log(S % S); // ψ = log(S²), work in logS² space throughout + arma::mat S2 = arma::exp(psi); std::vector objective_vec; double elbo_prev = -arma::datum::inf; @@ -33,7 +33,7 @@ Rcpp::List newton_optimize_impl( auto inner_loop = [&]() { double obj_prev = arma::datum::inf; for (int it = 0; it < maxiter; it++) { - S2 = S % S; + S2 = arma::exp(psi); arma::mat Z = O + X * B + M; arma::mat A = arma::exp(Z + 0.5 * S2); @@ -57,10 +57,12 @@ Rcpp::List newton_optimize_impl( M -= alpha_M * step_M; Z = O + X * B + M; - fixed_point_logS(logS, S, S2, Z, A, Traits::cov_diag(state, ones_row)); + // S step: ψ = −log(A + ω²) — exact minimiser for fixed A + fixed_point_psi(psi, S2, Z, A, Traits::cov_diag(state, ones_row)); A = arma::exp(Z + 0.5 * S2); - double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) + // KL entropy: S² − log(S²) − 1 = exp(ψ) − ψ − 1 + double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * psi)) + Traits::objective_cov(M, S2, state, w); objective_vec.push_back(obj); total_iter++; @@ -74,12 +76,12 @@ Rcpp::List newton_optimize_impl( for (int em = 0; em < max_em; em++) { inner_loop(); - S2 = S % S; + S2 = arma::exp(psi); Traits::mstep(state, M, S2, w, w_bar, p); arma::mat Z = O + X * B + M; arma::mat A = arma::exp(Z + 0.5 * S2); - double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * arma::trunc_log(S2))) + double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * psi)) + Traits::elbo_cov(state, w_bar, p); if (em > 0 && converged(elbo, elbo_prev, em_tol)) { last_status = 3; break; } elbo_prev = elbo; @@ -88,10 +90,11 @@ Rcpp::List newton_optimize_impl( inner_loop(); } - S2 = S % S; + S2 = arma::exp(psi); + S = arma::exp(0.5 * psi); arma::mat Z = O + X * B + M; arma::mat A = arma::exp(Z + 0.5 * S2); - arma::vec loglik = Traits::final_loglik(Y, Z, A, M, S2, state); + arma::vec loglik = Traits::final_loglik(Y, Z, A, M, psi, state); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; @@ -129,15 +132,15 @@ Rcpp::List newton_vestep_impl( const arma::mat ones_row = arma::ones(n, 1); const arma::mat XB = X * B; - arma::mat S2 = S % S; - arma::mat logS = arma::log(S); + arma::mat psi = arma::log(S % S); // ψ = log(S²) + arma::mat S2 = arma::exp(psi); std::vector objective_vec; double obj_prev = arma::datum::inf; int total_iter = 0; for (int it = 0; it < maxiter; it++) { - S2 = S % S; + S2 = arma::exp(psi); arma::mat Z = O + XB + M; arma::mat A = arma::exp(Z + 0.5 * S2); @@ -160,12 +163,12 @@ Rcpp::List newton_vestep_impl( M -= alpha_M * step_M; Z = O + XB + M; - // ---- Fixed-point update for S ---- - fixed_point_logS(logS, S, S2, Z, A, Traits::cov_diag(state, ones_row)); + // ---- S step: ψ = −log(A + ω²) — exact minimiser for fixed A ---- + fixed_point_psi(psi, S2, Z, A, Traits::cov_diag(state, ones_row)); // ---- Objective for convergence ---- A = arma::exp(Z + 0.5 * S2); - double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * arma::trunc_log(S2))) + double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * psi)) + Traits::objective_cov(M, S2, state, w); objective_vec.push_back(obj); total_iter++; @@ -175,10 +178,11 @@ Rcpp::List newton_vestep_impl( } // ---- Final output ---- - S2 = S % S; + S2 = arma::exp(psi); + S = arma::exp(0.5 * psi); arma::mat Z = O + XB + M; arma::mat A = arma::exp(Z + 0.5 * S2); - arma::vec loglik = Traits::final_loglik(Y, Z, A, M, S2, state); + arma::vec loglik = Traits::final_loglik(Y, Z, A, M, psi, state); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; diff --git a/src/utils.h b/src/utils.h index 9415d281..495978af 100644 --- a/src/utils.h +++ b/src/utils.h @@ -56,21 +56,21 @@ inline void newton_step_B( A = arma::exp(Z + 0.5 * S2); } -// ---- Fixed-point update for logS (overflow-safe) ---- +// ---- Fixed-point update for ψ = log(S²) (overflow-safe) ---- +// Exact minimiser of F(ψ) for fixed A: ψ = −log(A + cov_diag). // cov_diag: diagonal of Omega broadcast to (n,p) — arma::mat or double (scalar broadcast). -// Updates A, logS, S, S2 in-place using logS = clamp(min(-½log(A+cov_diag), ½log(700-Z))). +// Updates A, ψ, S2 = exp(ψ) in-place. S is not stored: recover via exp(0.5*ψ) at output. template -inline void fixed_point_logS( - arma::mat & logS, arma::mat & S, arma::mat & S2, +inline void fixed_point_psi( + arma::mat & psi, arma::mat & S2, const arma::mat & Z, arma::mat & A, const CovDiagType & cov_diag ) { A = arma::exp(Z + 0.5 * S2); - const arma::mat logS_cand = -0.5 * arma::log(A + cov_diag); - const arma::mat logS_ub = 0.5 * arma::log(arma::clamp(700. - Z, 1., arma::datum::inf)); - logS = arma::clamp(arma::min(logS_cand, logS_ub), -20., arma::datum::inf); - S = arma::exp(logS); - S2 = S % S; + const arma::mat psi_cand = -arma::log(A + cov_diag); + const arma::mat psi_ub = arma::log(arma::clamp(700. - Z, 1., arma::datum::inf)); + psi = arma::clamp(arma::min(psi_cand, psi_ub), -40., arma::datum::inf); + S2 = arma::exp(psi); } // ---- Relative convergence test: |val - prev| < tol * (1 + |prev|) ---- From 402e5caf217873ecc6f38fe06ae2882693e74363 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Tue, 9 Jun 2026 12:42:26 +0200 Subject: [PATCH 17/58] optimizing Armijo updates --- src/CovarianceTraits.h | 24 +++++++++++++++--------- src/newton_impl.h | 27 +++++++++++++++++---------- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/CovarianceTraits.h b/src/CovarianceTraits.h index f217e66e..1da04400 100644 --- a/src/CovarianceTraits.h +++ b/src/CovarianceTraits.h @@ -35,9 +35,10 @@ struct FullCovTraits { hess_M = A + ones_row * s.diag_Omega.t(); hess_M.each_col() %= w; } - // accu(MO % (M.*w_per_row)) = w' * rowsum(MO % M) — avoids each_col() on const M - static double penalty_M(const arma::mat & M, const State & s, const arma::vec & w) { - arma::mat MO = M * s.Omega; + static arma::mat times_Omega(const arma::mat & M, const State & s) { return M * s.Omega; } + + // Takes precomputed MO = M * Omega to avoid redundant matrix multiplies in Armijo + static double penalty_M(const arma::mat & MO, const arma::mat & M, const arma::vec & w) { return 0.5 * arma::as_scalar(w.t() * arma::sum(MO % M, 1)); } @@ -106,8 +107,10 @@ struct DiagonalCovTraits { hess_M = ones_row * s.omega2 + A; hess_M.each_col() %= w; } - static double penalty_M(const arma::mat & M, const State & s, const arma::vec & w) { - return 0.5 * arma::as_scalar((w.t() * (M % M)) * s.omega2.t()); + static arma::mat times_Omega(const arma::mat & M, const State & s) { return M.each_row() % s.omega2; } + + static double penalty_M(const arma::mat & MO, const arma::mat & M, const arma::vec & w) { + return 0.5 * arma::as_scalar(w.t() * arma::sum(MO % M, 1)); } static double objective_cov(const arma::mat & M, const arma::mat & S2, const State & s, const arma::vec & w) { @@ -176,8 +179,10 @@ struct SphericalCovTraits { hess_M = s.omega2 + A; hess_M.each_col() %= w; } - static double penalty_M(const arma::mat & M, const State & s, const arma::vec & w) { - return 0.5 * s.omega2 * arma::as_scalar(w.t() * arma::sum(M % M, 1)); + static arma::mat times_Omega(const arma::mat & M, const State & s) { return s.omega2 * M; } + + static double penalty_M(const arma::mat & MO, const arma::mat & M, const arma::vec & w) { + return 0.5 * arma::as_scalar(w.t() * arma::sum(MO % M, 1)); } static double objective_cov(const arma::mat & M, const arma::mat & S2, const State & s, const arma::vec & w) { @@ -238,8 +243,9 @@ struct FixedCovTraits { hess_M = A + ones_row * s.diag_Omega.t(); hess_M.each_col() %= w; } - static double penalty_M(const arma::mat & M, const State & s, const arma::vec & w) { - arma::mat MO = M * s.Omega; + static arma::mat times_Omega(const arma::mat & M, const State & s) { return M * s.Omega; } + + static double penalty_M(const arma::mat & MO, const arma::mat & M, const arma::vec & w) { return 0.5 * arma::as_scalar(w.t() * arma::sum(MO % M, 1)); } diff --git a/src/newton_impl.h b/src/newton_impl.h index b3260d36..3c8133e2 100644 --- a/src/newton_impl.h +++ b/src/newton_impl.h @@ -43,14 +43,18 @@ Rcpp::List newton_optimize_impl( Traits::grad_hess_M(M, state, A, Y, w, ones_row, grad_M, hess_M); hess_M.clamp(1e-10, arma::datum::inf); arma::mat step_M = grad_M / hess_M; - double f0_M = arma::accu(w.t() * (A - Y % Z)) + Traits::penalty_M(M, state, w); + // Precompute MO and dMO once — avoids O(n*p²) multiply at each Armijo backtrack + arma::mat MO = Traits::times_Omega(M, state); + arma::mat dMO = Traits::times_Omega(step_M, state); + double f0_M = arma::accu(w.t() * (A - Y % Z)) + Traits::penalty_M(MO, M, w); double slope_M = -arma::accu(grad_M % step_M); double alpha_M = 1.0; for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; - arma::mat Zt = Z - alpha_M * step_M; - arma::mat At = arma::exp(Zt + 0.5 * S2); - if (arma::accu(w.t() * (At - Y % Zt)) + Traits::penalty_M(Mt, state, w) + arma::mat Mt = M - alpha_M * step_M; + arma::mat MOt = MO - alpha_M * dMO; // linear update, no matrix multiply + arma::mat Zt = Z - alpha_M * step_M; + arma::mat At = arma::exp(Zt + 0.5 * S2); + if (arma::accu(w.t() * (At - Y % Zt)) + Traits::penalty_M(MOt, Mt, w) <= f0_M + c1 * alpha_M * slope_M) break; alpha_M *= 0.5; } @@ -149,14 +153,17 @@ Rcpp::List newton_vestep_impl( Traits::grad_hess_M(M, state, A, Y, w, ones_row, grad_M, hess_M); hess_M.clamp(1e-10, arma::datum::inf); arma::mat step_M = grad_M / hess_M; - double f0_M = arma::accu(w.t() * (A - Y % Z)) + Traits::penalty_M(M, state, w); + arma::mat MO = Traits::times_Omega(M, state); + arma::mat dMO = Traits::times_Omega(step_M, state); + double f0_M = arma::accu(w.t() * (A - Y % Z)) + Traits::penalty_M(MO, M, w); double slope_M = -arma::accu(grad_M % step_M); double alpha_M = 1.0; for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; - arma::mat Zt = Z - alpha_M * step_M; - arma::mat At = arma::exp(Zt + 0.5 * S2); - if (arma::accu(w.t() * (At - Y % Zt)) + Traits::penalty_M(Mt, state, w) + arma::mat Mt = M - alpha_M * step_M; + arma::mat MOt = MO - alpha_M * dMO; + arma::mat Zt = Z - alpha_M * step_M; + arma::mat At = arma::exp(Zt + 0.5 * S2); + if (arma::accu(w.t() * (At - Y % Zt)) + Traits::penalty_M(MOt, Mt, w) <= f0_M + c1 * alpha_M * slope_M) break; alpha_M *= 0.5; } From 592adcc6d81e9819f531d137dc20c219890c1c75 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Tue, 9 Jun 2026 15:09:29 +0200 Subject: [PATCH 18/58] testing spectral gradient for PLNPCA --- R/PLNPCA.R | 4 +- R/PLNPCAfit-class.R | 4 +- R/RcppExports.R | 8 + R/utils.R | 14 ++ inst/case_studies/oaks_tree.R | 1 - src/RcppExports.cpp | 30 ++++ src/newton_rank_cov.cpp | 127 ++++++++------ src/spectral_rank_cov.cpp | 317 ++++++++++++++++++++++++++++++++++ 8 files changed, 451 insertions(+), 54 deletions(-) create mode 100644 src/spectral_rank_cov.cpp diff --git a/R/PLNPCA.R b/R/PLNPCA.R index 0ef10612..a67cdfe5 100644 --- a/R/PLNPCA.R +++ b/R/PLNPCA.R @@ -104,8 +104,8 @@ PLNPCA_param <- function( } else if (backend == "torch") { stopifnot(config_optim$algorithm %in% available_algorithms_torch) config_opt <- config_default_torch - } else { # "homemade" - config_opt <- config_default_homemade + } else { # "homemade" — spectral gradient method + config_opt <- config_default_spectral } config_opt[names(config_optim)] <- config_optim config_opt$trace <- trace diff --git a/R/PLNPCAfit-class.R b/R/PLNPCAfit-class.R index 9afdfad5..e045df12 100644 --- a/R/PLNPCAfit-class.R +++ b/R/PLNPCAfit-class.R @@ -239,11 +239,11 @@ PLNPCAfit <- R6Class( if (control$backend == "torch") { private$optimizer$main <- private$torch_optimize_rank } else if (control$backend == "homemade") { - private$optimizer$main <- newton_optimize_rank + private$optimizer$main <- spectral_optimize_rank } else { private$optimizer$main <- nlopt_optimize_rank } - private$optimizer$vestep <- if (control$backend == "homemade") newton_optimize_vestep_rank else nlopt_optimize_vestep_rank + private$optimizer$vestep <- if (control$backend == "homemade") spectral_optimize_vestep_rank else nlopt_optimize_vestep_rank if (!is.null(control$svdM)) { svdM <- control$svdM } else { diff --git a/R/RcppExports.R b/R/RcppExports.R index 87a294b5..aa20d6ac 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -137,6 +137,14 @@ cpp_test_packing <- function() { .Call('_PLNmodels_cpp_test_packing', PACKAGE = 'PLNmodels') } +spectral_optimize_rank <- function(data, params, config) { + .Call('_PLNmodels_spectral_optimize_rank', PACKAGE = 'PLNmodels', data, params, config) +} + +spectral_optimize_vestep_rank <- function(data, params, B, C, config) { + .Call('_PLNmodels_spectral_optimize_vestep_rank', PACKAGE = 'PLNmodels', data, params, B, C, config) +} + get_sandwich_variance_B <- function(Y, X, A, S, Sigma, Diag_Omega) { .Call('_PLNmodels_get_sandwich_variance_B', PACKAGE = 'PLNmodels', Y, X, A, S, Sigma, Diag_Omega) } diff --git a/R/utils.R b/R/utils.R index bbd672cb..85510884 100644 --- a/R/utils.R +++ b/R/utils.R @@ -22,6 +22,20 @@ config_default_homemade <- ftol_rel = 1e-8 ) +# Spectral gradient method (PLNPCA homemade backend): needs tighter tolerance +# than the nlopt default (1e-8) because GLL nonmonotone acceptance causes +# objective oscillations that fool consecutive convergence at 1e-8 into +# stopping prematurely at suboptimal local minima. 1e-9 balances quality and +# speed: on typical datasets spectral matches or exceeds NLOPT quality in +# comparable wall-clock time. +config_default_spectral <- + list( + algorithm = "SPECTRAL", + backend = "homemade", + maxeval = 10000, + ftol_rel = 1e-9 + ) + config_default_torch <- list( algorithm = "RPROP", diff --git a/inst/case_studies/oaks_tree.R b/inst/case_studies/oaks_tree.R index afb30b6a..e77f866d 100644 --- a/inst/case_studies/oaks_tree.R +++ b/inst/case_studies/oaks_tree.R @@ -53,7 +53,6 @@ rbind( "ZIPLN diagonal single", "ZIPLN diagonal column prob", "ZIPLN diagonal row prob", "ZIPLN diagonal covar prob")) %>% knitr::kable() - ## Discriminant Analysis with LDA myLDA_tree <- PLNLDA(Abundance ~ 1 + offset(log(Offset)), grouping = tree, data = oaks) plot(myLDA_tree) diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 3d32d83c..87df22b0 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -513,6 +513,34 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// spectral_optimize_rank +Rcpp::List spectral_optimize_rank(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_spectral_optimize_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(spectral_optimize_rank(data, params, config)); + return rcpp_result_gen; +END_RCPP +} +// spectral_optimize_vestep_rank +Rcpp::List spectral_optimize_vestep_rank(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& C, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_spectral_optimize_vestep_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP CSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type C(CSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(spectral_optimize_vestep_rank(data, params, B, C, config)); + return rcpp_result_gen; +END_RCPP +} // get_sandwich_variance_B arma::mat get_sandwich_variance_B(const arma::mat& Y, const arma::mat& X, const arma::mat& A, const arma::mat& S, const arma::mat& Sigma, const arma::vec& Diag_Omega); RcppExport SEXP _PLNmodels_get_sandwich_variance_B(SEXP YSEXP, SEXP XSEXP, SEXP ASEXP, SEXP SSEXP, SEXP SigmaSEXP, SEXP Diag_OmegaSEXP) { @@ -565,6 +593,8 @@ static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_optim_zipln_M_logS", (DL_FUNC) &_PLNmodels_optim_zipln_M_logS, 9}, {"_PLNmodels_optim_zipln_M_S_newton", (DL_FUNC) &_PLNmodels_optim_zipln_M_S_newton, 10}, {"_PLNmodels_cpp_test_packing", (DL_FUNC) &_PLNmodels_cpp_test_packing, 0}, + {"_PLNmodels_spectral_optimize_rank", (DL_FUNC) &_PLNmodels_spectral_optimize_rank, 3}, + {"_PLNmodels_spectral_optimize_vestep_rank", (DL_FUNC) &_PLNmodels_spectral_optimize_vestep_rank, 5}, {"_PLNmodels_get_sandwich_variance_B", (DL_FUNC) &_PLNmodels_get_sandwich_variance_B, 6}, {NULL, NULL, 0} }; diff --git a/src/newton_rank_cov.cpp b/src/newton_rank_cov.cpp index afa39e50..fecd1587 100644 --- a/src/newton_rank_cov.cpp +++ b/src/newton_rank_cov.cpp @@ -34,6 +34,9 @@ Rcpp::List newton_optimize_rank( const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const arma::uword n = Y.n_rows; + const arma::uword q = C.n_cols; + const double c1 = 1e-4; const arma::mat Xw = X.each_col() % w; arma::mat Xw2 = X % X; Xw2.each_col() %= w; @@ -51,6 +54,9 @@ Rcpp::List newton_optimize_rank( for (int it = 0; it < maxiter; it++) { + // Precompute once per iteration — reused in B and M Armijo (saves O(n*q*p) per backtrack) + arma::mat half_S2C2t = 0.5 * S2 * C2.t(); + // ---- B step (diagonal Newton + Armijo) ---- { arma::mat grad_B = Xw.t() * (A - Y); @@ -63,31 +69,37 @@ Rcpp::List newton_optimize_rank( double alpha_B = 1.0; for (int ls = 0; ls < 20; ls++) { arma::mat Zt = Z - alpha_B * XstepB; - if (arma::accu(w.t() * (arma::exp(Zt + 0.5 * S2 * C2.t()) - Y % Zt)) + if (arma::accu(w.t() * (arma::exp(Zt + half_S2C2t) - Y % Zt)) <= f0_B + c1 * alpha_B * slope_B) break; alpha_B *= 0.5; } B -= alpha_B * step_B; Z = O + X * B + M * C.t(); - A = arma::exp(Z + 0.5 * S2 * C2.t()); + A = arma::exp(Z + half_S2C2t); } - // ---- M step (diagonal Newton + Armijo) ---- - // grad_M = diag(w) * ((A-Y)*C + M), hess_M = diag(w) * (A*C² + 1) + // ---- M step (block q×q Newton per observation + Armijo) ---- + // Exact Hessian per row i: Hᵢ = Cᵀ diag(Aᵢ) C + Iq (q×q, always PD) { - arma::mat grad_M = (A - Y) * C + M; grad_M.each_col() %= w; - arma::mat hess_M = A * C2 + 1.; hess_M.each_col() %= w; - hess_M.clamp(1e-10, arma::datum::inf); - arma::mat step_M = grad_M / hess_M; - arma::mat stepMCt = step_M * C.t(); - double f0_M = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::as_scalar(w.t() * arma::sum(M % M, 1)); - double slope_M = -arma::accu(grad_M % step_M); - double alpha_M = 1.0; + arma::mat grad_M = (A - Y) * C + M; // n×q, unweighted gradient + arma::mat step_M(n, q); + for (int i = 0; i < n; i++) { + // Scale rows of C by A_{ij}: CAi_{jk} = C_{jk} * A_{ij} + arma::mat CAi = C.each_col() % A.row(i).t(); // p×q, O(p*q) + arma::mat Hi = CAi.t() * C; // q×q = C'diag(Aᵢ)C, O(p*q²) + Hi.diag() += 1.0; + step_M.row(i) = arma::solve(Hi, grad_M.row(i).t(), arma::solve_opts::fast).t(); + } + arma::mat stepMCt = step_M * C.t(); + arma::mat grad_M_w = grad_M; grad_M_w.each_col() %= w; // for slope + double f0_M = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * arma::as_scalar(w.t() * arma::sum(M % M, 1)); + double slope_M = -arma::accu(grad_M_w % step_M); + double alpha_M = 1.0; for (int ls = 0; ls < 20; ls++) { arma::mat Mt = M - alpha_M * step_M; arma::mat Zt = Z - alpha_M * stepMCt; - arma::mat At = arma::exp(Zt + 0.5 * S2 * C2.t()); + arma::mat At = arma::exp(Zt + half_S2C2t); if (arma::accu(w.t() * (At - Y % Zt)) + 0.5 * arma::as_scalar(w.t() * arma::sum(Mt % Mt, 1)) <= f0_M + c1 * alpha_M * slope_M) break; @@ -95,31 +107,37 @@ Rcpp::List newton_optimize_rank( } M -= alpha_M * step_M; Z = O + X * B + M * C.t(); - A = arma::exp(Z + 0.5 * S2 * C2.t()); + A = arma::exp(Z + half_S2C2t); } - // ---- C step (exact diagonal Newton + Armijo) ---- - // Exact diagonal Hessian: h_{jk} = Σᵢ wᵢ Aᵢⱼ [(Mᵢₖ + S²ᵢₖ Cⱼₖ)² + S²ᵢₖ] + // ---- C step (block q×q Newton per gene + Armijo) ---- + // Exact Hessian per gene j: Hⱼ = F̃ⱼᵀ diag(w⊙Aⱼ) F̃ⱼ + diag(S2ᵀ(w⊙Aⱼ)) + // where F̃ⱼ_{ik} = Mᵢₖ + S²ᵢₖ Cⱼₖ (avoids n×p temporaries of diagonal version) { - const arma::uword p = C.n_rows, q = C.n_cols; - arma::mat AmY = A - Y; AmY.each_col() %= w; - arma::mat grad_C = AmY.t() * M + (A.t() * (S2.each_col() % w)) % C; - arma::mat hess_C(p, q); - for (arma::uword k = 0; k < q; k++) { - // Fk_{ij} = M_{ik} + S2_{ik} * C_{jk} (n×p outer product) - arma::mat Fk = M.col(k) * arma::ones(1, p) - + S2.col(k) * C.col(k).t(); - hess_C.col(k) = (A % (arma::square(Fk) + S2.col(k) * arma::ones(1, p))).t() * w; + const arma::uword p = C.n_rows; + const arma::mat WA = A.each_col() % w; // n×p + arma::mat AmY = A - Y; AmY.each_col() %= w; + arma::mat grad_C = AmY.t() * M + (WA.t() * S2) % C; // p×q + arma::mat step_C(p, q); + for (arma::uword j = 0; j < p; j++) { + // F̃ⱼ = M + S2 .* C[j,:] (broadcast C.row(j) over n rows) + arma::mat Fj = M + S2.each_row() % C.row(j); // n×q, O(n*q) + arma::mat Fj_sc = Fj.each_col() % WA.col(j); // n×q, scale by wᵢAᵢⱼ + arma::mat Hj = Fj_sc.t() * Fj; // q×q, O(n*q²) + Hj.diag() += S2.t() * WA.col(j); // + diag(S2ᵀ wA_j) + step_C.row(j) = arma::solve(Hj, grad_C.row(j).t(), arma::solve_opts::fast).t(); } - hess_C.clamp(1e-10, arma::datum::inf); - arma::mat step_C = grad_C / hess_C; - double f0_C = arma::accu(w.t() * (A - Y % Z)); - double slope_C = -arma::accu(grad_C % step_C); - double alpha_C = 1.0; + const arma::mat Mstep_Ct = M * step_C.t(); + const arma::mat S2_CsCt = S2 * (C % step_C).t(); + const arma::mat S2_sC2t = S2 * (step_C % step_C).t(); + double f0_C = arma::accu(w.t() * (A - Y % Z)); + double slope_C = -arma::accu(grad_C % step_C); + double alpha_C = 1.0; for (int ls = 0; ls < 20; ls++) { - arma::mat Ct = C - alpha_C * step_C; - arma::mat Zt = O + X * B + M * Ct.t(); - arma::mat At = arma::exp(Zt + 0.5 * S2 * (Ct % Ct).t()); + arma::mat Zt = Z - alpha_C * Mstep_Ct; + arma::mat half_t = half_S2C2t - alpha_C * S2_CsCt + + (0.5 * alpha_C * alpha_C) * S2_sC2t; + arma::mat At = arma::exp(Zt + half_t); if (arma::accu(w.t() * (At - Y % Zt)) <= f0_C + c1 * alpha_C * slope_C) break; alpha_C *= 0.5; @@ -127,7 +145,8 @@ Rcpp::List newton_optimize_rank( C -= alpha_C * step_C; C2 = C % C; Z = O + X * B + M * C.t(); - A = arma::exp(Z + 0.5 * S2 * C2.t()); + half_S2C2t = 0.5 * S2 * C2.t(); + A = arma::exp(Z + half_S2C2t); } // ---- S step (exact minimiser in ψ = logS² space) ---- @@ -136,7 +155,7 @@ Rcpp::List newton_optimize_rank( { psi = arma::clamp(-arma::log(1. + A * C2), -40., 0.); S2 = arma::exp(psi); - A = arma::exp(Z + 0.5 * S2 * C2.t()); + A = arma::exp(Z + 0.5 * S2 * C2.t()); // S2 changed — full recompute } // ---- Convergence check ---- @@ -204,6 +223,9 @@ Rcpp::List newton_optimize_vestep_rank( const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const arma::uword n = Y.n_rows; + const arma::uword q = C.n_cols; + const double c1 = 1e-4; const arma::mat C2 = C % C; const arma::mat XB = X * B; @@ -219,21 +241,28 @@ Rcpp::List newton_optimize_vestep_rank( for (int it = 0; it < maxiter; it++) { - // ---- M step (diagonal Newton + Armijo) ---- + const arma::mat half_S2C2t = 0.5 * S2 * C2.t(); + + // ---- M step (block q×q Newton per observation + Armijo) ---- { - arma::mat grad_M = (A - Y) * C + M; grad_M.each_col() %= w; - arma::mat hess_M = A * C2 + 1.; hess_M.each_col() %= w; - hess_M.clamp(1e-10, arma::datum::inf); - arma::mat step_M = grad_M / hess_M; - arma::mat stepMCt = step_M * C.t(); - double f0_M = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::as_scalar(w.t() * arma::sum(M % M, 1)); - double slope_M = -arma::accu(grad_M % step_M); - double alpha_M = 1.0; + arma::mat grad_M = (A - Y) * C + M; // n×q, unweighted + arma::mat step_M(n, q); + for (int i = 0; i < n; i++) { + arma::mat CAi = C.each_col() % A.row(i).t(); + arma::mat Hi = CAi.t() * C; + Hi.diag() += 1.0; + step_M.row(i) = arma::solve(Hi, grad_M.row(i).t(), arma::solve_opts::fast).t(); + } + arma::mat stepMCt = step_M * C.t(); + arma::mat grad_M_w = grad_M; grad_M_w.each_col() %= w; + double f0_M = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * arma::as_scalar(w.t() * arma::sum(M % M, 1)); + double slope_M = -arma::accu(grad_M_w % step_M); + double alpha_M = 1.0; for (int ls = 0; ls < 20; ls++) { arma::mat Mt = M - alpha_M * step_M; arma::mat Zt = Z - alpha_M * stepMCt; - arma::mat At = arma::exp(Zt + 0.5 * S2 * C2.t()); + arma::mat At = arma::exp(Zt + half_S2C2t); if (arma::accu(w.t() * (At - Y % Zt)) + 0.5 * arma::as_scalar(w.t() * arma::sum(Mt % Mt, 1)) <= f0_M + c1 * alpha_M * slope_M) break; @@ -241,14 +270,14 @@ Rcpp::List newton_optimize_vestep_rank( } M -= alpha_M * step_M; Z = O + XB + M * C.t(); - A = arma::exp(Z + 0.5 * S2 * C2.t()); + A = arma::exp(Z + half_S2C2t); } // ---- S step (exact minimiser in ψ = logS² space) ---- { psi = arma::clamp(-arma::log(1. + A * C2), -40., 0.); S2 = arma::exp(psi); - A = arma::exp(Z + 0.5 * S2 * C2.t()); + A = arma::exp(Z + 0.5 * S2 * C2.t()); // S2 changed — full recompute } // ---- Convergence check ---- diff --git a/src/spectral_rank_cov.cpp b/src/spectral_rank_cov.cpp new file mode 100644 index 00000000..c4c291a1 --- /dev/null +++ b/src/spectral_rank_cov.cpp @@ -0,0 +1,317 @@ +#include "RcppArmadillo.h" + +// [[Rcpp::depends(RcppArmadillo)]] + +#include "utils.h" + +// --------------------------------------------------------------------------------------- +// Rank-constrained PLN — Spectral Gradient Method (Barzilai-Borwein + GLL/Armijo) +// +// Parameters: B (d,p), C (p,q), M (n,q), S exact via ψ = −log(1 + A·C²) +// Z = O + X·B + M·C', A = exp(Z + ½·S²·C²ᵀ) +// +// Per-element BB step sizes (equivalent to NLOPT CCSAQ's σ): +// σᵢ = |Δgᵢ| / |sᵢ| for each element i of B, C, M +// +// Line search: GLL nonmonotone Armijo — accepts if +// f_new ≤ max_{j=0..M-1} f_{k-j} + c₁·scale·slope +// GLL reduces backtracking frequency vs monotone Armijo (the nonmonotone window +// allows temporary increases, so the BB step is accepted more often on the first try). +// +// Convergence: consecutive ftol (default 1e-9 in config_default_spectral). +// ftol=1e-8 is too loose — GLL oscillations are O(1e-8·|f|) and fool the +// criterion into stopping prematurely at suboptimal minima. 1e-9 gives +// quality matching or exceeding NLOPT CCSAQ at ≤2× wall-clock time. + +static inline double safe_ratio(double a, double b, double fallback) { + return (b > 1e-20) ? std::clamp(a / b, 1e-12, 1e12) : fallback; +} + +// Per-element σ update: σ = |y| / |s|, fall back to current value when |s| is tiny +static void update_sigma(arma::mat & sigma, + const arma::mat & y_abs, + const arma::mat & s_abs) +{ + for (arma::uword i = 0; i < sigma.n_elem; i++) + sigma(i) = safe_ratio(y_abs(i), s_abs(i), sigma(i)); +} + +// [[Rcpp::export]] +Rcpp::List spectral_optimize_rank( + const Rcpp::List & data , + const Rcpp::List & params, + const Rcpp::List & config +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat C = Rcpp::as(params["C"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 10000; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-10; + const double c_armijo = 1e-4; + const int nm_window = 10; // GLL nonmonotone window size + + const arma::mat Xw = X.each_col() % w; + + // Initialise geometry with S exact + arma::mat C2 = C % C; + arma::mat psi = arma::log(S % S); + arma::mat S2 = arma::exp(psi); + arma::mat Z = O + X * B + M * C.t(); + arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); + psi = arma::clamp(-arma::log(1. + A * C2), -40., 0.); + S2 = arma::exp(psi); + A = arma::exp(Z + 0.5 * S2 * C2.t()); + + // Per-element BB σ (same layout as B, C, M) + arma::mat sigma_B(arma::size(B), arma::fill::ones); + arma::mat sigma_C(arma::size(C), arma::fill::ones); + arma::mat sigma_M(arma::size(M), arma::fill::ones); + arma::mat sB_prev, sC_prev, sM_prev; + arma::mat gB_prev, gC_prev, gM_prev; + bool prev_valid = false; + + // GLL nonmonotone buffer + std::deque obj_buffer; + + std::vector objective_vec; + double obj_prev = arma::datum::inf; + int total_iter = 0, last_status = 5; + const int win = 100; // window for GLL-oscillation-robust convergence check + + for (int it = 0; it < maxiter; it++) { + + // ---- Objective ---- + double obj = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * arma::accu(w.t() * (M % M + S2 - psi - 1.)); + objective_vec.push_back(obj); + total_iter++; + // Primary: consecutive convergence (cheap, exact for monotone steps) + if (it > 0 && converged(obj, obj_prev, ftol)) { last_status = 3; break; } + obj_prev = obj; + // Secondary: window-minimum stagnation every `win` iterations. + // Compares min of last `win` evals to min of the preceding `win` evals. + // Robust to GLL oscillations, which can delay consecutive convergence. + if (it > 0 && it % win == 0 && (int)objective_vec.size() >= 2*win) { + double m1 = *std::min_element(objective_vec.end()-win, objective_vec.end()); + double m2 = *std::min_element(objective_vec.end()-2*win, objective_vec.end()-win); + if (converged(m1, m2, ftol)) { last_status = 3; break; } + } + + // Update GLL window and reference + obj_buffer.push_back(obj); + if ((int)obj_buffer.size() > nm_window) obj_buffer.pop_front(); + double f_ref = *std::max_element(obj_buffer.begin(), obj_buffer.end()); + + // ---- Joint gradient ∇(B, C, M) ---- + arma::mat AmY = A - Y; AmY.each_col() %= w; + arma::mat gB = Xw.t() * (A - Y); + arma::mat gC = AmY.t() * M + (A.t() * (S2.each_col() % w)) % C; + arma::mat gM = (A - Y) * C + M; gM.each_col() %= w; + + // ---- Per-element σ update (or initialise on first iter) ---- + if (prev_valid) { + update_sigma(sigma_B, arma::abs(gB - gB_prev), arma::abs(sB_prev)); + update_sigma(sigma_C, arma::abs(gC - gC_prev), arma::abs(sC_prev)); + update_sigma(sigma_M, arma::abs(gM - gM_prev), arma::abs(sM_prev)); + } else { + sigma_B = arma::clamp(arma::abs(gB), 1e-4, 1e12); + sigma_C = arma::clamp(arma::abs(gC), 1e-4, 1e12); + sigma_M = arma::clamp(arma::abs(gM), 1e-4, 1e12); + } + + arma::mat dB = gB / sigma_B; + arma::mat dC = gC / sigma_C; + arma::mat dM = gM / sigma_M; + double slope = -(arma::accu(dB % gB) + arma::accu(dC % gC) + arma::accu(dM % gM)); + + // ---- GLL nonmonotone Armijo with S exact update ---- + double scale = 1.0; + arma::mat B_t, C_t, M_t, C2_t, Z_t, A_t, psi_t, S2_t; + double obj_t = arma::datum::inf; + + for (int ls = 0; ls < 20; ls++) { + B_t = B - scale * dB; + C_t = C - scale * dC; + M_t = M - scale * dM; + C2_t = C_t % C_t; + Z_t = O + X * B_t + M_t * C_t.t(); + A_t = arma::exp(Z_t + 0.5 * S2 * C2_t.t()); + psi_t = arma::clamp(-arma::log(1. + A_t * C2_t), -40., 0.); + S2_t = arma::exp(psi_t); + A_t = arma::exp(Z_t + 0.5 * S2_t * C2_t.t()); + obj_t = arma::accu(w.t() * (A_t - Y % Z_t)) + + 0.5 * arma::accu(w.t() * (M_t % M_t + S2_t - psi_t - 1.)); + if (obj_t <= f_ref + c_armijo * scale * slope) break; + scale *= 0.5; + } + + // σ scale-up when Armijo backtracked heavily — prevents the next step + // from overshooting in the same direction + if (scale < 0.125) { + sigma_B /= scale; + sigma_C /= scale; + sigma_M /= scale; + } + + sB_prev = B_t - B; sC_prev = C_t - C; sM_prev = M_t - M; + gB_prev = gB; gC_prev = gC; gM_prev = gM; + prev_valid = true; + + B = B_t; C = C_t; M = M_t; + C2 = C2_t; Z = Z_t; A = A_t; psi = psi_t; S2 = S2_t; + } + + // ---- Final output ---- + S = arma::exp(0.5 * psi); + const double w_bar = arma::accu(w); + arma::mat nSig = M.t() * (M.each_col() % w) + arma::diagmat(arma::sum(S2.each_col() % w, 0)); + arma::mat Sigma = C * nSig * C.t() / w_bar; + arma::mat Omega = C * arma::inv_sympd(nSig / w_bar) * C.t(); + arma::vec loglik = arma::sum(Y % Z - A, 1) + - 0.5 * arma::sum(M % M + S2 - psi - 1., 1) + + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("B", B ), + Rcpp::Named("C", C ), + Rcpp::Named("M", M ), + Rcpp::Named("S", S ), + Rcpp::Named("Z", Z ), + Rcpp::Named("A", A ), + Rcpp::Named("Sigma", Sigma), + Rcpp::Named("Omega", Omega), + Rcpp::Named("Ji", Ji ), + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", last_status ), + Rcpp::Named("backend", "spectral" ), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", total_iter ) + )) + ); +} + +// --------------------------------------------------------------------------------------- +// VE step: B and C fixed, update M (per-element BB + GLL) and S (exact) + +// [[Rcpp::export]] +Rcpp::List spectral_optimize_vestep_rank( + const Rcpp::List & data , + const Rcpp::List & params, + const arma::mat & B, + const arma::mat & C, + const Rcpp::List & config +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 10000; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-10; + const double c_armijo = 1e-4; + const int nm_window = 10; + + const arma::mat C2 = C % C; + const arma::mat XB = X * B; + + arma::mat psi = arma::log(S % S); + arma::mat S2 = arma::exp(psi); + arma::mat Z = O + XB + M * C.t(); + arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); + psi = arma::clamp(-arma::log(1. + A * C2), -40., 0.); + S2 = arma::exp(psi); + A = arma::exp(Z + 0.5 * S2 * C2.t()); + + arma::mat sigma_M(arma::size(M), arma::fill::ones); + arma::mat sM_prev, gM_prev; + bool prev_valid = false; + + std::deque obj_buffer; + std::vector objective_vec; + double obj_prev = arma::datum::inf; + int total_iter = 0; + const int win = 100; + + for (int it = 0; it < maxiter; it++) { + double obj = arma::accu(w.t() * (A - Y % Z)) + + 0.5 * arma::accu(w.t() * (M % M + S2 - psi - 1.)); + objective_vec.push_back(obj); + total_iter++; + if (it > 0 && converged(obj, obj_prev, ftol)) break; + obj_prev = obj; + if (it > 0 && it % win == 0 && (int)objective_vec.size() >= 2*win) { + double m1 = *std::min_element(objective_vec.end()-win, objective_vec.end()); + double m2 = *std::min_element(objective_vec.end()-2*win, objective_vec.end()-win); + if (converged(m1, m2, ftol)) break; + } + + obj_buffer.push_back(obj); + if ((int)obj_buffer.size() > nm_window) obj_buffer.pop_front(); + double f_ref = *std::max_element(obj_buffer.begin(), obj_buffer.end()); + + arma::mat gM = (A - Y) * C + M; gM.each_col() %= w; + + if (prev_valid) { + update_sigma(sigma_M, arma::abs(gM - gM_prev), arma::abs(sM_prev)); + } else { + sigma_M = arma::clamp(arma::abs(gM), 1e-4, 1e12); + } + + arma::mat dM = gM / sigma_M; + double slope = -arma::accu(dM % gM); + double scale = 1.0; + arma::mat M_t, Z_t, A_t, psi_t, S2_t; + double obj_t = arma::datum::inf; + + for (int ls = 0; ls < 20; ls++) { + M_t = M - scale * dM; + Z_t = O + XB + M_t * C.t(); + A_t = arma::exp(Z_t + 0.5 * S2 * C2.t()); + psi_t = arma::clamp(-arma::log(1. + A_t * C2), -40., 0.); + S2_t = arma::exp(psi_t); + A_t = arma::exp(Z_t + 0.5 * S2_t * C2.t()); + obj_t = arma::accu(w.t() * (A_t - Y % Z_t)) + + 0.5 * arma::accu(w.t() * (M_t % M_t + S2_t - psi_t - 1.)); + if (obj_t <= f_ref + c_armijo * scale * slope) break; + scale *= 0.5; + } + + if (scale < 0.125) sigma_M /= scale; + + sM_prev = M_t - M; + gM_prev = gM; + prev_valid = true; + + M = M_t; Z = Z_t; A = A_t; psi = psi_t; S2 = S2_t; + } + + S = arma::exp(0.5 * psi); + Z = O + XB + M * C.t(); + arma::vec loglik = arma::sum(Y % Z - A, 1) + - 0.5 * arma::sum(M % M + S2 - psi - 1., 1) + + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("M") = M, + Rcpp::Named("S") = S, + Rcpp::Named("Ji") = Ji, + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", 3 ), + Rcpp::Named("backend", "spectral" ), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", total_iter ) + )) + ); +} From cf51508e55a1a18760f105d888a2d0101a580f7a Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Tue, 9 Jun 2026 16:57:00 +0200 Subject: [PATCH 19/58] hybrid backend for all variants of standard PLN --- R/PLN.R | 4 +- R/PLNfit-class.R | 22 +++++- R/RcppExports.R | 16 ++++ R/utils.R | 19 +++++ src/RcppExports.cpp | 56 ++++++++++++++ src/newton_diag_cov.cpp | 30 ++++++++ src/newton_fixed_cov.cpp | 28 +++++++ src/newton_full_cov.cpp | 30 ++++++++ src/newton_impl_alt.h | 161 +++++++++++++++++++++++++++++++++++++++ src/newton_spherical.cpp | 30 ++++++++ 10 files changed, 391 insertions(+), 5 deletions(-) create mode 100644 src/newton_impl_alt.h diff --git a/R/PLN.R b/R/PLN.R index 9033c710..0089e12e 100644 --- a/R/PLN.R +++ b/R/PLN.R @@ -101,7 +101,7 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { #' #' @export PLN_param <- function( - backend = c("homemade", "nlopt", "torch"), + backend = c("homemade", "nlopt", "torch", "homemade_alt", "hybrid"), trace = 1, covariance = c("full", "diagonal", "spherical", "fixed"), Omega = NULL, @@ -127,7 +127,7 @@ PLN_param <- function( } else if (backend == "torch") { stopifnot(config_optim$algorithm %in% available_algorithms_torch) config_opt <- config_default_torch - } else { # "homemade" + } else { # "homemade", "homemade_alt", or "hybrid" config_opt <- config_default_homemade } config_opt[names(config_optim)] <- config_optim diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index 58a5741d..0a0b2d7c 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -364,10 +364,14 @@ PLNfit <- R6Class( private$torch_optimize } else if (control$backend == "homemade") { newton_optimize_full + } else if (control$backend == "homemade_alt") { + newton_optimize_full_alt + } else if (control$backend == "hybrid") { + make_hybrid_optimizer(newton_optimize_full, newton_optimize_full_alt) } else { nlopt_optimize_full } - private$optimizer$vestep <- if (control$backend == "homemade") newton_optimize_vestep_full else nlopt_optimize_vestep_full + private$optimizer$vestep <- if (control$backend %in% c("homemade", "homemade_alt", "hybrid")) newton_optimize_vestep_full else nlopt_optimize_vestep_full }, ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -746,10 +750,14 @@ PLNfit_diagonal <- R6Class( private$torch_optimize } else if (control$backend == "homemade") { newton_optimize_diagonal + } else if (control$backend == "homemade_alt") { + newton_optimize_diagonal_alt + } else if (control$backend == "hybrid") { + make_hybrid_optimizer(newton_optimize_diagonal, newton_optimize_diagonal_alt) } else { nlopt_optimize_diagonal } - private$optimizer$vestep <- if (control$backend == "homemade") newton_optimize_vestep_diagonal else nlopt_optimize_vestep_diagonal + private$optimizer$vestep <- if (control$backend %in% c("homemade", "homemade_alt", "hybrid")) newton_optimize_vestep_diagonal else nlopt_optimize_vestep_diagonal } ), private = list( @@ -835,10 +843,14 @@ PLNfit_spherical <- R6Class( private$torch_optimize } else if (control$backend == "homemade") { newton_optimize_spherical + } else if (control$backend == "homemade_alt") { + newton_optimize_spherical_alt + } else if (control$backend == "hybrid") { + make_hybrid_optimizer(newton_optimize_spherical, newton_optimize_spherical_alt) } else { nlopt_optimize_spherical } - private$optimizer$vestep <- if (control$backend == "homemade") newton_optimize_vestep_spherical else nlopt_optimize_vestep_spherical + private$optimizer$vestep <- if (control$backend %in% c("homemade", "homemade_alt", "hybrid")) newton_optimize_vestep_spherical else nlopt_optimize_vestep_spherical } ), private = list( @@ -928,6 +940,10 @@ PLNfit_fixedcov <- R6Class( private$torch_optimize } else if (control$backend == "homemade") { newton_optimize_fixed + } else if (control$backend == "homemade_alt") { + newton_optimize_fixed_alt + } else if (control$backend == "hybrid") { + make_hybrid_optimizer(newton_optimize_fixed, newton_optimize_fixed_alt) } else { nlopt_optimize_fixed } diff --git a/R/RcppExports.R b/R/RcppExports.R index aa20d6ac..62326c62 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -5,6 +5,10 @@ newton_optimize_diagonal <- function(data, params, config) { .Call('_PLNmodels_newton_optimize_diagonal', PACKAGE = 'PLNmodels', data, params, config) } +newton_optimize_diagonal_alt <- function(data, params, config) { + .Call('_PLNmodels_newton_optimize_diagonal_alt', PACKAGE = 'PLNmodels', data, params, config) +} + newton_optimize_vestep_diagonal <- function(data, params, B, Omega, config) { .Call('_PLNmodels_newton_optimize_vestep_diagonal', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } @@ -13,10 +17,18 @@ newton_optimize_fixed <- function(data, params, config) { .Call('_PLNmodels_newton_optimize_fixed', PACKAGE = 'PLNmodels', data, params, config) } +newton_optimize_fixed_alt <- function(data, params, config) { + .Call('_PLNmodels_newton_optimize_fixed_alt', PACKAGE = 'PLNmodels', data, params, config) +} + newton_optimize_full <- function(data, params, config) { .Call('_PLNmodels_newton_optimize_full', PACKAGE = 'PLNmodels', data, params, config) } +newton_optimize_full_alt <- function(data, params, config) { + .Call('_PLNmodels_newton_optimize_full_alt', PACKAGE = 'PLNmodels', data, params, config) +} + newton_optimize_vestep_full <- function(data, params, B, Omega, config) { .Call('_PLNmodels_newton_optimize_vestep_full', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } @@ -33,6 +45,10 @@ newton_optimize_spherical <- function(data, params, config) { .Call('_PLNmodels_newton_optimize_spherical', PACKAGE = 'PLNmodels', data, params, config) } +newton_optimize_spherical_alt <- function(data, params, config) { + .Call('_PLNmodels_newton_optimize_spherical_alt', PACKAGE = 'PLNmodels', data, params, config) +} + newton_optimize_vestep_spherical <- function(data, params, B, Omega, config) { .Call('_PLNmodels_newton_optimize_vestep_spherical', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } diff --git a/R/utils.R b/R/utils.R index 85510884..925d8930 100644 --- a/R/utils.R +++ b/R/utils.R @@ -22,6 +22,25 @@ config_default_homemade <- ftol_rel = 1e-8 ) +# Hybrid backend: two-phase optimizer — homemade (phase 1) then homemade_alt (phase 2). +# Phase 1 uses looser tolerances (100× the target ftol_rel) to reach the basin quickly. +# Phase 2 refines to the full requested tolerance. +# Returns a closure with the same (data, params, config) signature as the C++ wrappers. +make_hybrid_optimizer <- function(opt_phase1, opt_phase2) { + function(data, params, config) { + config1 <- config + config1$ftol_rel <- config$ftol_rel * 10 + if (!is.null(config$em_ftol)) config1$em_ftol <- config$em_ftol * 10 + res1 <- opt_phase1(data, params, config1) + params2 <- modifyList(params, list(B = res1$B, M = res1$M, S = res1$S)) + res2 <- opt_phase2(data, params2, config) + res2$monitoring$objective <- c(res1$monitoring$objective, res2$monitoring$objective) + res2$monitoring$iterations <- res1$monitoring$iterations + res2$monitoring$iterations + res2$monitoring$backend <- "hybrid" + res2 + } +} + # Spectral gradient method (PLNPCA homemade backend): needs tighter tolerance # than the nlopt default (1e-8) because GLL nonmonotone acceptance causes # objective oscillations that fool consecutive convergence at 1e-8 into diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 87df22b0..d5f7c3d6 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -24,6 +24,19 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// newton_optimize_diagonal_alt +Rcpp::List newton_optimize_diagonal_alt(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_newton_optimize_diagonal_alt(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(newton_optimize_diagonal_alt(data, params, config)); + return rcpp_result_gen; +END_RCPP +} // newton_optimize_vestep_diagonal Rcpp::List newton_optimize_vestep_diagonal(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_newton_optimize_vestep_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -52,6 +65,19 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// newton_optimize_fixed_alt +Rcpp::List newton_optimize_fixed_alt(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_newton_optimize_fixed_alt(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(newton_optimize_fixed_alt(data, params, config)); + return rcpp_result_gen; +END_RCPP +} // newton_optimize_full Rcpp::List newton_optimize_full(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); RcppExport SEXP _PLNmodels_newton_optimize_full(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { @@ -65,6 +91,19 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// newton_optimize_full_alt +Rcpp::List newton_optimize_full_alt(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_newton_optimize_full_alt(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(newton_optimize_full_alt(data, params, config)); + return rcpp_result_gen; +END_RCPP +} // newton_optimize_vestep_full Rcpp::List newton_optimize_vestep_full(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_newton_optimize_vestep_full(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -121,6 +160,19 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// newton_optimize_spherical_alt +Rcpp::List newton_optimize_spherical_alt(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_newton_optimize_spherical_alt(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(newton_optimize_spherical_alt(data, params, config)); + return rcpp_result_gen; +END_RCPP +} // newton_optimize_vestep_spherical Rcpp::List newton_optimize_vestep_spherical(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_newton_optimize_vestep_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -560,13 +612,17 @@ END_RCPP static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_newton_optimize_diagonal", (DL_FUNC) &_PLNmodels_newton_optimize_diagonal, 3}, + {"_PLNmodels_newton_optimize_diagonal_alt", (DL_FUNC) &_PLNmodels_newton_optimize_diagonal_alt, 3}, {"_PLNmodels_newton_optimize_vestep_diagonal", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_diagonal, 5}, {"_PLNmodels_newton_optimize_fixed", (DL_FUNC) &_PLNmodels_newton_optimize_fixed, 3}, + {"_PLNmodels_newton_optimize_fixed_alt", (DL_FUNC) &_PLNmodels_newton_optimize_fixed_alt, 3}, {"_PLNmodels_newton_optimize_full", (DL_FUNC) &_PLNmodels_newton_optimize_full, 3}, + {"_PLNmodels_newton_optimize_full_alt", (DL_FUNC) &_PLNmodels_newton_optimize_full_alt, 3}, {"_PLNmodels_newton_optimize_vestep_full", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_full, 5}, {"_PLNmodels_newton_optimize_rank", (DL_FUNC) &_PLNmodels_newton_optimize_rank, 3}, {"_PLNmodels_newton_optimize_vestep_rank", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_rank, 5}, {"_PLNmodels_newton_optimize_spherical", (DL_FUNC) &_PLNmodels_newton_optimize_spherical, 3}, + {"_PLNmodels_newton_optimize_spherical_alt", (DL_FUNC) &_PLNmodels_newton_optimize_spherical_alt, 3}, {"_PLNmodels_newton_optimize_vestep_spherical", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_spherical, 5}, {"_PLNmodels_nlopt_optimize_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_diagonal, 3}, {"_PLNmodels_nlopt_optimize_vestep_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_diagonal, 5}, diff --git a/src/newton_diag_cov.cpp b/src/newton_diag_cov.cpp index 567e76e1..06135298 100644 --- a/src/newton_diag_cov.cpp +++ b/src/newton_diag_cov.cpp @@ -4,6 +4,7 @@ #include "utils.h" #include "newton_impl.h" +#include "newton_impl_alt.h" // --------------------------------------------------------------------------------------- // Diagonal covariance PLN — coordinate-Newton optimizer @@ -34,6 +35,35 @@ Rcpp::List newton_optimize_diagonal( return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); } +// --------------------------------------------------------------------------------------- +// Diagonal covariance PLN — alternative EM: closed-form B in M-step + +// [[Rcpp::export]] +Rcpp::List newton_optimize_diagonal_alt( + const Rcpp::List & data , + const Rcpp::List & params, + const Rcpp::List & config +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; + const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + + const double w_bar = arma::accu(w); + arma::mat S2 = S % S; + DiagonalCovTraits::State state(M, S2, w, w_bar); + + return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); +} + // --------------------------------------------------------------------------------------- // VE diagonal — coordinate-Newton (M and S only, B and Omega fixed) diff --git a/src/newton_fixed_cov.cpp b/src/newton_fixed_cov.cpp index 539fb21d..3f25bebf 100644 --- a/src/newton_fixed_cov.cpp +++ b/src/newton_fixed_cov.cpp @@ -4,6 +4,7 @@ #include "utils.h" #include "newton_impl.h" +#include "newton_impl_alt.h" // --------------------------------------------------------------------------------------- // Fixed inverse covariance (Omega provided externally) PLN — coordinate-Newton optimizer @@ -32,3 +33,30 @@ Rcpp::List newton_optimize_fixed( // Fixed covariance has no EM loop (has_em = false); pass max_em=1, em_tol=0 return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, 1, 0.0); } + +// --------------------------------------------------------------------------------------- +// Fixed inverse covariance PLN — alternative EM: closed-form B, iterated until convergence + +// [[Rcpp::export]] +Rcpp::List newton_optimize_fixed_alt( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(B, M, S, Omega) + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + arma::mat Omega = Rcpp::as(params["Omega"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; + const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + + FixedCovTraits::State state(Omega); + return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); +} diff --git a/src/newton_full_cov.cpp b/src/newton_full_cov.cpp index ab725c31..e9366712 100644 --- a/src/newton_full_cov.cpp +++ b/src/newton_full_cov.cpp @@ -4,6 +4,7 @@ #include "utils.h" #include "newton_impl.h" +#include "newton_impl_alt.h" // --------------------------------------------------------------------------------------- // Full covariance PLN — coordinate-Newton optimizer @@ -34,6 +35,35 @@ Rcpp::List newton_optimize_full( return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); } +// --------------------------------------------------------------------------------------- +// Full covariance PLN — alternative EM: closed-form B in M-step, no newton_step_B in inner loop + +// [[Rcpp::export]] +Rcpp::List newton_optimize_full_alt( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(B, M, S) + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; + const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + + const double w_bar = arma::accu(w); + arma::mat S2 = S % S; + FullCovTraits::State state(M, S2, w, w_bar); + + return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); +} + // --------------------------------------------------------------------------------------- // VE full covariance — coordinate-Newton (M and S only, B and Omega fixed) diff --git a/src/newton_impl_alt.h b/src/newton_impl_alt.h new file mode 100644 index 00000000..e81c3f05 --- /dev/null +++ b/src/newton_impl_alt.h @@ -0,0 +1,161 @@ +#pragma once +#include +#include "utils.h" +#include "CovarianceTraits.h" + +// Alternative parameterization: M stores M_full (the full variational mean on Z_i, +// not the residual M_res = M_full - XB used in newton_impl.h). +// +// Key difference from the standard implementation: +// - B is NOT updated in the inner loop; it gets an exact closed-form EM M-step: +// B = (X'WX)^{-1} X'W M_full +// - The inner loop updates only M_full and S, with gradient using M_res = M_full - XB. +// - Sigma/Omega M-step uses M_res = M_full - XB (same formula as before). +// +// At input/output: M is in the "residual" format (M_res = M_full - XB) to stay +// compatible with the rest of the R package. The conversion is done internally. + +template +Rcpp::List newton_optimize_alt_impl( + const arma::mat & Y, const arma::mat & X, const arma::mat & O, const arma::vec & w, + arma::mat B, arma::mat M, arma::mat S, + typename Traits::State state, + int maxiter, double ftol, int max_em, double em_tol +) { + const int n = Y.n_rows; + const arma::uword p = Y.n_cols; + const double w_bar = arma::accu(w); + const double c1 = 1e-4; + const arma::mat ones_row = arma::ones(n, 1); + + // Precompute X'WX once: used for closed-form B = (X'WX)^{-1} X'W M_full + const arma::mat Xw = X.each_col() % w; // n×d + const arma::mat XtWX = X.t() * Xw; // d×d, symmetric PD + + // Convert input M from residual format to M_full = XB + M_res + M = X * B + M; + + arma::mat psi = arma::log(S % S); + arma::mat S2 = arma::exp(psi); + + std::vector objective_vec; + double elbo_prev = -arma::datum::inf; + int total_iter = 0; + int last_status = 5; + + // Inner loop: B is fixed; only M_full and S are updated. + auto inner_loop = [&]() { + const arma::mat XB = X * B; // constant within this inner loop + double obj_prev = arma::datum::inf; + + for (int it = 0; it < maxiter; it++) { + S2 = arma::exp(psi); + arma::mat M_res = M - XB; + arma::mat Z = O + M; // Z = O + M_full + arma::mat A = arma::exp(Z + 0.5 * S2); + + // Newton step for M_full: gradient/Hessian are functions of M_res + arma::mat grad_M, hess_M; + Traits::grad_hess_M(M_res, state, A, Y, w, ones_row, grad_M, hess_M); + hess_M.clamp(1e-10, arma::datum::inf); + arma::mat step_M = grad_M / hess_M; + + arma::mat MresO = Traits::times_Omega(M_res, state); + arma::mat dMO = Traits::times_Omega(step_M, state); + double f0_M = arma::accu(w.t() * (A - Y % Z)) + Traits::penalty_M(MresO, M_res, w); + double slope_M = -arma::accu(grad_M % step_M); + double alpha_M = 1.0; + for (int ls = 0; ls < 20; ls++) { + arma::mat Mt = M - alpha_M * step_M; // M_full candidate + arma::mat MresOt = MresO - alpha_M * dMO; + arma::mat Zt = Z - alpha_M * step_M; // = O + Mt + arma::mat At = arma::exp(Zt + 0.5 * S2); + // penalty uses M_res_t = Mt - XB + if (arma::accu(w.t() * (At - Y % Zt)) + Traits::penalty_M(MresOt, Mt - XB, w) + <= f0_M + c1 * alpha_M * slope_M) break; + alpha_M *= 0.5; + } + M -= alpha_M * step_M; + Z = O + M; + + // S step: exact fixed-point ψ = −log(A + diag_Ω) + fixed_point_psi(psi, S2, Z, A, Traits::cov_diag(state, ones_row)); + + A = arma::exp(Z + 0.5 * S2); + M_res = M - XB; + double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * psi)) + + Traits::objective_cov(M_res, S2, state, w); + objective_vec.push_back(obj); + total_iter++; + + if (it > 0 && converged(obj, obj_prev, ftol)) { last_status = 3; break; } + obj_prev = obj; + } + }; + + if (Traits::has_em) { + for (int em = 0; em < max_em; em++) { + inner_loop(); + + S2 = arma::exp(psi); + + // Closed-form B M-step: B = (X'WX)^{-1} X'W M_full + B = arma::solve(XtWX, Xw.t() * M); + + // Sigma/Omega M-step: uses M_res = M_full - XB (same as current mstep) + arma::mat M_res = M - X * B; + Traits::mstep(state, M_res, S2, w, w_bar, p); + + arma::mat Z = O + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * psi)) + + Traits::elbo_cov(state, w_bar, p); + if (em > 0 && converged(elbo, elbo_prev, em_tol)) { last_status = 3; break; } + elbo_prev = elbo; + } + } else { + // Fixed covariance: Omega is fixed; iterate (E-step + B M-step) until convergence + double elbo_prev_fix = -arma::datum::inf; + for (int em = 0; em < max_em; em++) { + inner_loop(); + S2 = arma::exp(psi); + B = arma::solve(XtWX, Xw.t() * M); + arma::mat M_res = M - X * B; + arma::mat Z = O + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * psi)) + - Traits::objective_cov(M_res, S2, state, w); + if (em > 0 && converged(elbo, elbo_prev_fix, em_tol)) { last_status = 3; break; } + elbo_prev_fix = elbo; + } + } + + S2 = arma::exp(psi); + S = arma::exp(0.5 * psi); + arma::mat M_res = M - X * B; + arma::mat Z = O + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + + // final_loglik uses M_res for the KL terms (same convention as newton_impl.h) + arma::vec loglik = Traits::final_loglik(Y, Z, A, M_res, psi, state); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + Rcpp::List cov_out = Traits::output_cov(M_res, S2, w, w_bar, state); + return Rcpp::List::create( + Rcpp::Named("B", B ), + Rcpp::Named("M", M_res ), // return residual format for R compatibility + Rcpp::Named("S", S ), + Rcpp::Named("Z", Z ), + Rcpp::Named("A", A ), + Rcpp::Named("Sigma", cov_out["Sigma"]), + Rcpp::Named("Omega", cov_out["Omega"]), + Rcpp::Named("Ji", Ji ), + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", last_status ), + Rcpp::Named("backend", "newton_alt" ), + Rcpp::Named("objective", objective_vec ), + Rcpp::Named("iterations", total_iter ) + )) + ); +} diff --git a/src/newton_spherical.cpp b/src/newton_spherical.cpp index 64ca3cc1..6fd096ad 100644 --- a/src/newton_spherical.cpp +++ b/src/newton_spherical.cpp @@ -4,6 +4,7 @@ #include "utils.h" #include "newton_impl.h" +#include "newton_impl_alt.h" // --------------------------------------------------------------------------------------- // Spherical covariance PLN — coordinate-Newton optimizer @@ -34,6 +35,35 @@ Rcpp::List newton_optimize_spherical( return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); } +// --------------------------------------------------------------------------------------- +// Spherical covariance PLN — alternative EM: closed-form B in M-step + +// [[Rcpp::export]] +Rcpp::List newton_optimize_spherical_alt( + const Rcpp::List & data , + const Rcpp::List & params, + const Rcpp::List & config +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S = Rcpp::as(params["S"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; + const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; + const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + + const double w_bar = arma::accu(w); + arma::mat S2 = S % S; + SphericalCovTraits::State state(M, S2, w, w_bar); + + return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); +} + // --------------------------------------------------------------------------------------- // VE spherical — coordinate-Newton (M and S only, B and Omega fixed) From c6569a7cc9f7735ddef8b018c7dfb84d8d4d3760 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Tue, 9 Jun 2026 17:19:00 +0200 Subject: [PATCH 20/58] added optimizer with alternate parametrization for nlopt solver --- R/PLN.R | 4 +- R/PLNfit-class.R | 8 +++ R/RcppExports.R | 16 ++++++ src/RcppExports.cpp | 56 ++++++++++++++++++ src/nlopt_diag_cov.cpp | 86 ++++++++++++++++++++++++++++ src/nlopt_fixed_cov.cpp | 82 +++++++++++++++++++++++++++ src/nlopt_full_cov.cpp | 122 ++++++++++++++++++++++++++++++++++++++++ src/nlopt_spherical.cpp | 84 +++++++++++++++++++++++++++ 8 files changed, 457 insertions(+), 1 deletion(-) diff --git a/R/PLN.R b/R/PLN.R index 0089e12e..b226b97c 100644 --- a/R/PLN.R +++ b/R/PLN.R @@ -101,7 +101,7 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { #' #' @export PLN_param <- function( - backend = c("homemade", "nlopt", "torch", "homemade_alt", "hybrid"), + backend = c("homemade", "nlopt", "torch", "homemade_alt", "hybrid", "nlopt_alt"), trace = 1, covariance = c("full", "diagonal", "spherical", "fixed"), Omega = NULL, @@ -127,6 +127,8 @@ PLN_param <- function( } else if (backend == "torch") { stopifnot(config_optim$algorithm %in% available_algorithms_torch) config_opt <- config_default_torch + } else if (backend == "nlopt_alt") { + config_opt <- config_default_nlopt } else { # "homemade", "homemade_alt", or "hybrid" config_opt <- config_default_homemade } diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index 0a0b2d7c..e28bdc3b 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -368,6 +368,8 @@ PLNfit <- R6Class( newton_optimize_full_alt } else if (control$backend == "hybrid") { make_hybrid_optimizer(newton_optimize_full, newton_optimize_full_alt) + } else if (control$backend == "nlopt_alt") { + nlopt_optimize_full_alt } else { nlopt_optimize_full } @@ -754,6 +756,8 @@ PLNfit_diagonal <- R6Class( newton_optimize_diagonal_alt } else if (control$backend == "hybrid") { make_hybrid_optimizer(newton_optimize_diagonal, newton_optimize_diagonal_alt) + } else if (control$backend == "nlopt_alt") { + nlopt_optimize_diagonal_alt } else { nlopt_optimize_diagonal } @@ -847,6 +851,8 @@ PLNfit_spherical <- R6Class( newton_optimize_spherical_alt } else if (control$backend == "hybrid") { make_hybrid_optimizer(newton_optimize_spherical, newton_optimize_spherical_alt) + } else if (control$backend == "nlopt_alt") { + nlopt_optimize_spherical_alt } else { nlopt_optimize_spherical } @@ -944,6 +950,8 @@ PLNfit_fixedcov <- R6Class( newton_optimize_fixed_alt } else if (control$backend == "hybrid") { make_hybrid_optimizer(newton_optimize_fixed, newton_optimize_fixed_alt) + } else if (control$backend == "nlopt_alt") { + nlopt_optimize_fixed_alt } else { nlopt_optimize_fixed } diff --git a/R/RcppExports.R b/R/RcppExports.R index 62326c62..ac859307 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -57,6 +57,10 @@ nlopt_optimize_diagonal <- function(data, params, config) { .Call('_PLNmodels_nlopt_optimize_diagonal', PACKAGE = 'PLNmodels', data, params, config) } +nlopt_optimize_diagonal_alt <- function(data, params, config) { + .Call('_PLNmodels_nlopt_optimize_diagonal_alt', PACKAGE = 'PLNmodels', data, params, config) +} + nlopt_optimize_vestep_diagonal <- function(data, params, B, Omega, config) { .Call('_PLNmodels_nlopt_optimize_vestep_diagonal', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } @@ -65,10 +69,18 @@ nlopt_optimize_fixed <- function(data, params, config) { .Call('_PLNmodels_nlopt_optimize_fixed', PACKAGE = 'PLNmodels', data, params, config) } +nlopt_optimize_fixed_alt <- function(data, params, config) { + .Call('_PLNmodels_nlopt_optimize_fixed_alt', PACKAGE = 'PLNmodels', data, params, config) +} + nlopt_optimize_full <- function(data, params, config) { .Call('_PLNmodels_nlopt_optimize_full', PACKAGE = 'PLNmodels', data, params, config) } +nlopt_optimize_full_alt <- function(data, params, config) { + .Call('_PLNmodels_nlopt_optimize_full_alt', PACKAGE = 'PLNmodels', data, params, config) +} + nlopt_optimize_vestep_full <- function(data, params, B, Omega, config) { .Call('_PLNmodels_nlopt_optimize_vestep_full', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } @@ -85,6 +97,10 @@ nlopt_optimize_spherical <- function(data, params, config) { .Call('_PLNmodels_nlopt_optimize_spherical', PACKAGE = 'PLNmodels', data, params, config) } +nlopt_optimize_spherical_alt <- function(data, params, config) { + .Call('_PLNmodels_nlopt_optimize_spherical_alt', PACKAGE = 'PLNmodels', data, params, config) +} + nlopt_optimize_vestep_spherical <- function(data, params, B, Omega, config) { .Call('_PLNmodels_nlopt_optimize_vestep_spherical', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index d5f7c3d6..1f45438c 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -201,6 +201,19 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// nlopt_optimize_diagonal_alt +Rcpp::List nlopt_optimize_diagonal_alt(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_diagonal_alt(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_diagonal_alt(data, params, config)); + return rcpp_result_gen; +END_RCPP +} // nlopt_optimize_vestep_diagonal Rcpp::List nlopt_optimize_vestep_diagonal(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -229,6 +242,19 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// nlopt_optimize_fixed_alt +Rcpp::List nlopt_optimize_fixed_alt(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_fixed_alt(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_fixed_alt(data, params, config)); + return rcpp_result_gen; +END_RCPP +} // nlopt_optimize_full Rcpp::List nlopt_optimize_full(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); RcppExport SEXP _PLNmodels_nlopt_optimize_full(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { @@ -242,6 +268,19 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// nlopt_optimize_full_alt +Rcpp::List nlopt_optimize_full_alt(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_full_alt(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_full_alt(data, params, config)); + return rcpp_result_gen; +END_RCPP +} // nlopt_optimize_vestep_full Rcpp::List nlopt_optimize_vestep_full(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_full(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -298,6 +337,19 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } +// nlopt_optimize_spherical_alt +Rcpp::List nlopt_optimize_spherical_alt(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_nlopt_optimize_spherical_alt(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); + rcpp_result_gen = Rcpp::wrap(nlopt_optimize_spherical_alt(data, params, config)); + return rcpp_result_gen; +END_RCPP +} // nlopt_optimize_vestep_spherical Rcpp::List nlopt_optimize_vestep_spherical(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -625,13 +677,17 @@ static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_newton_optimize_spherical_alt", (DL_FUNC) &_PLNmodels_newton_optimize_spherical_alt, 3}, {"_PLNmodels_newton_optimize_vestep_spherical", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_spherical, 5}, {"_PLNmodels_nlopt_optimize_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_diagonal, 3}, + {"_PLNmodels_nlopt_optimize_diagonal_alt", (DL_FUNC) &_PLNmodels_nlopt_optimize_diagonal_alt, 3}, {"_PLNmodels_nlopt_optimize_vestep_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_diagonal, 5}, {"_PLNmodels_nlopt_optimize_fixed", (DL_FUNC) &_PLNmodels_nlopt_optimize_fixed, 3}, + {"_PLNmodels_nlopt_optimize_fixed_alt", (DL_FUNC) &_PLNmodels_nlopt_optimize_fixed_alt, 3}, {"_PLNmodels_nlopt_optimize_full", (DL_FUNC) &_PLNmodels_nlopt_optimize_full, 3}, + {"_PLNmodels_nlopt_optimize_full_alt", (DL_FUNC) &_PLNmodels_nlopt_optimize_full_alt, 3}, {"_PLNmodels_nlopt_optimize_vestep_full", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_full, 5}, {"_PLNmodels_nlopt_optimize_rank", (DL_FUNC) &_PLNmodels_nlopt_optimize_rank, 3}, {"_PLNmodels_nlopt_optimize_vestep_rank", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_rank, 5}, {"_PLNmodels_nlopt_optimize_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_spherical, 3}, + {"_PLNmodels_nlopt_optimize_spherical_alt", (DL_FUNC) &_PLNmodels_nlopt_optimize_spherical_alt, 3}, {"_PLNmodels_nlopt_optimize_vestep_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_spherical, 5}, {"_PLNmodels_cpp_test_nlopt", (DL_FUNC) &_PLNmodels_cpp_test_nlopt, 0}, {"_PLNmodels_nlopt_optimize_genetic_modeling", (DL_FUNC) &_PLNmodels_nlopt_optimize_genetic_modeling, 7}, diff --git a/src/nlopt_diag_cov.cpp b/src/nlopt_diag_cov.cpp index 1d16f8f0..284fb97c 100644 --- a/src/nlopt_diag_cov.cpp +++ b/src/nlopt_diag_cov.cpp @@ -104,6 +104,92 @@ Rcpp::List nlopt_optimize_diagonal( ); } +// --------------------------------------------------------------------------------------- +// Diagonal covariance PLN — profiled-B nlopt: B removed from parameter vector, closed-form per eval + +// [[Rcpp::export]] +Rcpp::List nlopt_optimize_diagonal_alt( + const Rcpp::List & data , + const Rcpp::List & params, + const Rcpp::List & config +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + const auto init_B = Rcpp::as(params["B"]); + const auto init_M = Rcpp::as(params["M"]); + const auto init_S = Rcpp::as(params["S"]); + + const auto metadata = tuple_metadata(init_M, init_S); + enum { M_ID, S_ID }; + + auto parameters = std::vector(metadata.packed_size); + metadata.map(parameters.data()) = X * init_B + init_M; + metadata.map(parameters.data()) = arma::log(init_S % init_S); + + auto optimizer = new_nlopt_optimizer(config, parameters.size()); + std::vector objective_vec; + objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); + const double w_bar = accu(w); + + const arma::mat Xw = X.each_col() % w; + const arma::mat P_X = arma::solve(X.t() * Xw, Xw.t()); + + auto objective_and_grad = [&](const double * par, double * grad) -> double { + const arma::mat M_full = metadata.map(par); + const arma::mat logS2 = metadata.map(par); + arma::mat S2 = arma::exp(logS2); + arma::mat B = P_X * M_full; + arma::mat M_res = M_full - X * B; + arma::mat Z = O + M_full; + arma::mat A = exp(Z + 0.5 * S2); + arma::rowvec diag_sigma = w.t() * (M_res % M_res + S2) / w_bar; + double objective = accu(diagmat(w) * (A - Y % Z - 0.5 * logS2)) + + 0.5 * w_bar * accu(log(diag_sigma)); + // gradient for M_full = gradient for M_res (envelope theorem for B and sigma2) + metadata.map(grad) = diagmat(w) * ((M_res.each_row() / diag_sigma) + A - Y); + metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % pow(diag_sigma, -1) + S2 % A - 1.); + objective_vec.push_back(objective); + return objective; + }; + OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); + + arma::mat M_full = metadata.copy(parameters.data()); + arma::mat logS2 = metadata.copy(parameters.data()); + arma::mat S2 = arma::exp(logS2); + arma::mat S = arma::exp(0.5 * logS2); + arma::mat B = P_X * M_full; + arma::mat M = M_full - X * B; + arma::rowvec sigma2 = w.t() * (M % M + S2) / w_bar; + arma::vec omega2 = pow(sigma2.t(), -1); + arma::sp_mat Sigma(Y.n_cols, Y.n_cols); Sigma.diag() = sigma2.t(); + arma::sp_mat Omega(Y.n_cols, Y.n_cols); Omega.diag() = omega2; + arma::mat Z = O + M_full; + arma::mat A = exp(Z + 0.5 * S2); + arma::mat loglik = sum(Y % Z - A + 0.5 * logS2, 1) - 0.5 * (pow(M, 2) + S2) * omega2 + + 0.5 * sum(log(omega2)) + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("B", B), + Rcpp::Named("M", M), + Rcpp::Named("S", S), + Rcpp::Named("Z", Z), + Rcpp::Named("A", A), + Rcpp::Named("Sigma", Sigma), + Rcpp::Named("Omega", Omega), + Rcpp::Named("Ji", Ji), + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", static_cast(result.status)), + Rcpp::Named("backend", "nlopt_alt"), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", result.nb_iterations) + )) + ); +} + // --------------------------------------------------------------------------------------- // VE diagonal — nlopt/CCSAQ (M and S only, B and Omega fixed) diff --git a/src/nlopt_fixed_cov.cpp b/src/nlopt_fixed_cov.cpp index ee545674..bc9c6099 100644 --- a/src/nlopt_fixed_cov.cpp +++ b/src/nlopt_fixed_cov.cpp @@ -96,3 +96,85 @@ Rcpp::List nlopt_optimize_fixed( )) ); } + +// --------------------------------------------------------------------------------------- +// Fixed covariance PLN — profiled-B nlopt: B removed from parameter vector, closed-form per eval + +// [[Rcpp::export]] +Rcpp::List nlopt_optimize_fixed_alt( + const Rcpp::List & data , + const Rcpp::List & params, + const Rcpp::List & config +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + const auto init_B = Rcpp::as(params["B"]); + const auto init_M = Rcpp::as(params["M"]); + const auto Omega = Rcpp::as(params["Omega"]); + const auto init_S = Rcpp::as(params["S"]); + + const auto metadata = tuple_metadata(init_M, init_S); + enum { M_ID, S_ID }; + + auto parameters = std::vector(metadata.packed_size); + metadata.map(parameters.data()) = X * init_B + init_M; + metadata.map(parameters.data()) = arma::log(init_S % init_S); + + auto optimizer = new_nlopt_optimizer(config, parameters.size()); + std::vector objective_vec; + + const arma::mat Xw = X.each_col() % w; + const arma::mat P_X = arma::solve(X.t() * Xw, Xw.t()); + const arma::vec Omega_diag = diagvec(Omega); + + auto objective_and_grad = [&](const double * par, double * grad) -> double { + const arma::mat M_full = metadata.map(par); + const arma::mat logS2 = metadata.map(par); + arma::mat S2 = arma::exp(logS2); + arma::mat B = P_X * M_full; + arma::mat M_res = M_full - X * B; + arma::mat Z = O + M_full; + arma::mat A = exp(Z + 0.5 * S2); + double objective = accu(w.t() * (A - Y % Z - 0.5 * logS2)) + + 0.5 * trace(Omega * (M_res.t() * (M_res.each_col() % w) + diagmat(w.t() * S2))); + // gradient for M_full = gradient for M_res (envelope theorem for B) + metadata.map(grad) = diagmat(w) * (M_res * Omega + A - Y); + metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % Omega_diag.t() + S2 % A - 1.); + objective_vec.push_back(objective); + return objective; + }; + OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); + + arma::mat M_full = metadata.copy(parameters.data()); + arma::mat logS2 = metadata.copy(parameters.data()); + arma::mat S2 = arma::exp(logS2); + arma::mat S = arma::exp(0.5 * logS2); + arma::mat B = P_X * M_full; + arma::mat M = M_full - X * B; + arma::mat Sigma = (M.t() * (M.each_col() % w) + diagmat(w.t() * S2)) / accu(w); + arma::mat Z = O + M_full; + arma::mat A = exp(Z + 0.5 * S2); + arma::mat loglik = sum(Y % Z - A - 0.5 * ((M * Omega) % M - logS2 + S2 * diagmat(Omega)), 1) + + 0.5 * real(log_det(Omega)) + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("B", B), + Rcpp::Named("M", M), + Rcpp::Named("S", S), + Rcpp::Named("Z", Z), + Rcpp::Named("A", A), + Rcpp::Named("Sigma", Sigma), + Rcpp::Named("Omega", Omega), + Rcpp::Named("Ji", Ji), + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", static_cast(result.status)), + Rcpp::Named("backend", "nlopt_alt"), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", result.nb_iterations) + )) + ); +} diff --git a/src/nlopt_full_cov.cpp b/src/nlopt_full_cov.cpp index ab7ca9e7..620a01d5 100644 --- a/src/nlopt_full_cov.cpp +++ b/src/nlopt_full_cov.cpp @@ -136,6 +136,128 @@ Rcpp::List nlopt_optimize_full( ); } +// --------------------------------------------------------------------------------------- +// Full covariance PLN — profiled-B nlopt: B removed from parameter vector, closed-form per eval + +// [[Rcpp::export]] +Rcpp::List nlopt_optimize_full_alt( + const Rcpp::List & data , // List(Y, X, O, w) + const Rcpp::List & params, // List(B, M, S) + const Rcpp::List & config // List of config values +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + const auto init_B = Rcpp::as(params["B"]); + const auto init_M = Rcpp::as(params["M"]); // residual format + const auto init_S = Rcpp::as(params["S"]); + + // Parameters: (M_full, logS2) — B is profiled out via closed form + const auto metadata = tuple_metadata(init_M, init_S); + enum { M_ID, S_ID }; + + auto parameters = std::vector(metadata.packed_size); + metadata.map(parameters.data()) = X * init_B + init_M; // M_full = XB + M_res + metadata.map(parameters.data()) = arma::log(init_S % init_S); + + const double w_bar = accu(w); + const int max_em_iter = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; + const double em_ftol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + + // P_X = (X'WX)^{-1} X'W : d×n, precomputed once; B = P_X * M_full at each eval + const arma::mat Xw = X.each_col() % w; + const arma::mat P_X = arma::solve(X.t() * Xw, Xw.t()); + + // Initial Omega from residual init_M + arma::mat Omega; + { + const arma::mat S2_init = init_S % init_S; + arma::mat Sigma_init = (1./w_bar) * (init_M.t() * (init_M.each_col() % w) + diagmat(w.t() * S2_init)); + Omega = inv_sympd(Sigma_init); + } + + std::vector objective_vec; + double elbo_prev = -arma::datum::inf; + int total_iterations = 0; + int last_status = 0; + + for (int em_iter = 0; em_iter < std::max(1, max_em_iter); em_iter++) { + auto optimizer = new_nlopt_optimizer(config, parameters.size()); + objective_vec.reserve(objective_vec.size() + nlopt_get_maxeval(optimizer.get())); + const arma::vec Omega_diag = diagvec(Omega); + + auto objective_and_grad = [&](const double * par, double * grad) -> double { + const arma::mat M_full = metadata.map(par); + const arma::mat logS2 = metadata.map(par); + arma::mat S2 = arma::exp(logS2); + arma::mat B = P_X * M_full; + arma::mat M_res = M_full - X * B; + arma::mat Z = O + M_full; + arma::mat A = exp(Z + 0.5 * S2); + arma::mat MO = M_res * Omega; + const arma::rowvec wS2 = w.t() * S2; + double objective = accu(w.t() * (A - Y % Z - 0.5 * logS2)) + + 0.5 * (accu(MO % (M_res.each_col() % w)) + dot(Omega_diag, wS2.t())); + // gradient for M_full = gradient for M_res (envelope theorem for B) + metadata.map(grad) = diagmat(w) * (MO + A - Y); + metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % Omega_diag.t() + S2 % A - 1.); + objective_vec.push_back(objective); + return objective; + }; + + OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); + total_iterations += result.nb_iterations; + last_status = static_cast(result.status); + + arma::mat M_full = metadata.copy(parameters.data()); + arma::mat logS2 = metadata.copy(parameters.data()); + arma::mat S2 = arma::exp(logS2); + arma::mat B = P_X * M_full; + arma::mat M_res = M_full - X * B; + arma::mat Sigma = (1./w_bar) * (M_res.t() * (M_res.each_col() % w) + diagmat(w.t() * S2)); + Omega = inv_sympd(Sigma); + + arma::mat Z = O + M_full; + arma::mat A = exp(Z + 0.5 * S2); + double elbo = accu(w.t() * (Y % Z - A + 0.5 * logS2)) + - 0.5 * w_bar * real(log_det(Sigma)); + if (em_iter > 0 && converged(elbo, elbo_prev, em_ftol)) break; + elbo_prev = elbo; + } + + arma::mat M_full = metadata.copy(parameters.data()); + arma::mat logS2 = metadata.copy(parameters.data()); + arma::mat S2 = arma::exp(logS2); + arma::mat S = arma::exp(0.5 * logS2); + arma::mat B = P_X * M_full; + arma::mat M = M_full - X * B; // M_res — residual format + arma::mat Sigma = (1./w_bar) * (M.t() * (M.each_col() % w) + diagmat(w.t() * S2)); + arma::mat Z = O + M_full; + arma::mat A = exp(Z + 0.5 * S2); + arma::vec loglik = sum(Y % Z - A + 0.5 * logS2 - 0.5 * ((M * Omega) % M + S2 * diagmat(Omega)), 1) + + 0.5 * real(log_det(Omega)) + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("B", B), + Rcpp::Named("M", M), + Rcpp::Named("S", S), + Rcpp::Named("Z", Z), + Rcpp::Named("A", A), + Rcpp::Named("Sigma", Sigma), + Rcpp::Named("Omega", Omega), + Rcpp::Named("Ji", Ji), + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", last_status), + Rcpp::Named("backend", "nlopt_alt"), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", total_iterations) + )) + ); +} + // --------------------------------------------------------------------------------------- // VE full covariance — nlopt/CCSAQ (M and S only, B and Omega fixed) diff --git a/src/nlopt_spherical.cpp b/src/nlopt_spherical.cpp index 5f12f754..218be6dd 100644 --- a/src/nlopt_spherical.cpp +++ b/src/nlopt_spherical.cpp @@ -102,6 +102,90 @@ Rcpp::List nlopt_optimize_spherical( ); } +// --------------------------------------------------------------------------------------- +// Spherical covariance PLN — profiled-B nlopt: B removed from parameter vector, closed-form per eval + +// [[Rcpp::export]] +Rcpp::List nlopt_optimize_spherical_alt( + const Rcpp::List & data , + const Rcpp::List & params, + const Rcpp::List & config +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + const auto init_B = Rcpp::as(params["B"]); + const auto init_M = Rcpp::as(params["M"]); + const auto init_S = Rcpp::as(params["S"]); + + const auto metadata = tuple_metadata(init_M, init_S); + enum { M_ID, S_ID }; + + auto parameters = std::vector(metadata.packed_size); + metadata.map(parameters.data()) = X * init_B + init_M; + metadata.map(parameters.data()) = arma::log(init_S % init_S); + + auto optimizer = new_nlopt_optimizer(config, parameters.size()); + const double w_bar = accu(w); + const arma::uword p = Y.n_cols; + std::vector objective_vec; + objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); + + const arma::mat Xw = X.each_col() % w; + const arma::mat P_X = arma::solve(X.t() * Xw, Xw.t()); + + auto objective_and_grad = [&](const double * par, double * grad) -> double { + const arma::mat M_full = metadata.map(par); + const arma::mat logS2 = metadata.map(par); + arma::mat S2 = arma::exp(logS2); + arma::mat B = P_X * M_full; + arma::mat M_res = M_full - X * B; + arma::mat Z = O + M_full; + arma::mat A = exp(Z + 0.5 * S2); + double sigma2 = accu(diagmat(w) * (pow(M_res, 2) + S2)) / (double(p) * w_bar); + double objective = accu(w.t() * (A - Y % Z - 0.5 * logS2)) + 0.5 * double(p) * w_bar * log(sigma2); + // gradient for M_full = gradient for M_res (envelope theorem for B and sigma2) + metadata.map(grad) = diagmat(w) * (M_res / sigma2 + A - Y); + metadata.map(grad) = 0.5 * diagmat(w) * (S2 / sigma2 + S2 % A - 1.); + objective_vec.push_back(objective); + return objective; + }; + OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); + + arma::mat M_full = metadata.copy(parameters.data()); + arma::mat logS2 = metadata.copy(parameters.data()); + arma::mat S2 = arma::exp(logS2); + arma::mat S = arma::exp(0.5 * logS2); + arma::mat B = P_X * M_full; + arma::mat M = M_full - X * B; + const double sigma2 = accu(diagmat(w) * (pow(M, 2) + S2)) / (double(p) * w_bar); + arma::sp_mat Sigma(p, p); Sigma.diag() = arma::ones(p) * sigma2; + arma::sp_mat Omega(p, p); Omega.diag() = arma::ones(p) * pow(sigma2, -1); + arma::mat Z = O + M_full; + arma::mat A = exp(Z + 0.5 * S2); + arma::mat loglik = sum(Y % Z - A - 0.5 * (pow(M, 2) + S2) / sigma2 + 0.5 * (logS2 - log(sigma2)), 1) + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("B", B), + Rcpp::Named("M", M), + Rcpp::Named("S", S), + Rcpp::Named("Z", Z), + Rcpp::Named("A", A), + Rcpp::Named("Sigma", Sigma), + Rcpp::Named("Omega", Omega), + Rcpp::Named("Ji", Ji), + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", static_cast(result.status)), + Rcpp::Named("backend", "nlopt_alt"), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", result.nb_iterations) + )) + ); +} + // --------------------------------------------------------------------------------------- // VE spherical — nlopt/CCSAQ (M and S only, B and Omega fixed) From 43a0b1c53d72705344be1ed6fc6154b6a8a98b61 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Tue, 9 Jun 2026 18:06:29 +0200 Subject: [PATCH 21/58] make alternative param the default for nlopt and standard PLN variants --- R/PLN.R | 4 +-- R/PLNfit-class.R | 8 ------ R/RcppExports.R | 16 ------------ src/RcppExports.cpp | 56 ----------------------------------------- src/nlopt_diag_cov.cpp | 11 ++++---- src/nlopt_fixed_cov.cpp | 11 ++++---- src/nlopt_full_cov.cpp | 11 ++++---- src/nlopt_spherical.cpp | 11 ++++---- 8 files changed, 21 insertions(+), 107 deletions(-) diff --git a/R/PLN.R b/R/PLN.R index b226b97c..0089e12e 100644 --- a/R/PLN.R +++ b/R/PLN.R @@ -101,7 +101,7 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { #' #' @export PLN_param <- function( - backend = c("homemade", "nlopt", "torch", "homemade_alt", "hybrid", "nlopt_alt"), + backend = c("homemade", "nlopt", "torch", "homemade_alt", "hybrid"), trace = 1, covariance = c("full", "diagonal", "spherical", "fixed"), Omega = NULL, @@ -127,8 +127,6 @@ PLN_param <- function( } else if (backend == "torch") { stopifnot(config_optim$algorithm %in% available_algorithms_torch) config_opt <- config_default_torch - } else if (backend == "nlopt_alt") { - config_opt <- config_default_nlopt } else { # "homemade", "homemade_alt", or "hybrid" config_opt <- config_default_homemade } diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index e28bdc3b..0a0b2d7c 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -368,8 +368,6 @@ PLNfit <- R6Class( newton_optimize_full_alt } else if (control$backend == "hybrid") { make_hybrid_optimizer(newton_optimize_full, newton_optimize_full_alt) - } else if (control$backend == "nlopt_alt") { - nlopt_optimize_full_alt } else { nlopt_optimize_full } @@ -756,8 +754,6 @@ PLNfit_diagonal <- R6Class( newton_optimize_diagonal_alt } else if (control$backend == "hybrid") { make_hybrid_optimizer(newton_optimize_diagonal, newton_optimize_diagonal_alt) - } else if (control$backend == "nlopt_alt") { - nlopt_optimize_diagonal_alt } else { nlopt_optimize_diagonal } @@ -851,8 +847,6 @@ PLNfit_spherical <- R6Class( newton_optimize_spherical_alt } else if (control$backend == "hybrid") { make_hybrid_optimizer(newton_optimize_spherical, newton_optimize_spherical_alt) - } else if (control$backend == "nlopt_alt") { - nlopt_optimize_spherical_alt } else { nlopt_optimize_spherical } @@ -950,8 +944,6 @@ PLNfit_fixedcov <- R6Class( newton_optimize_fixed_alt } else if (control$backend == "hybrid") { make_hybrid_optimizer(newton_optimize_fixed, newton_optimize_fixed_alt) - } else if (control$backend == "nlopt_alt") { - nlopt_optimize_fixed_alt } else { nlopt_optimize_fixed } diff --git a/R/RcppExports.R b/R/RcppExports.R index ac859307..62326c62 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -57,10 +57,6 @@ nlopt_optimize_diagonal <- function(data, params, config) { .Call('_PLNmodels_nlopt_optimize_diagonal', PACKAGE = 'PLNmodels', data, params, config) } -nlopt_optimize_diagonal_alt <- function(data, params, config) { - .Call('_PLNmodels_nlopt_optimize_diagonal_alt', PACKAGE = 'PLNmodels', data, params, config) -} - nlopt_optimize_vestep_diagonal <- function(data, params, B, Omega, config) { .Call('_PLNmodels_nlopt_optimize_vestep_diagonal', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } @@ -69,18 +65,10 @@ nlopt_optimize_fixed <- function(data, params, config) { .Call('_PLNmodels_nlopt_optimize_fixed', PACKAGE = 'PLNmodels', data, params, config) } -nlopt_optimize_fixed_alt <- function(data, params, config) { - .Call('_PLNmodels_nlopt_optimize_fixed_alt', PACKAGE = 'PLNmodels', data, params, config) -} - nlopt_optimize_full <- function(data, params, config) { .Call('_PLNmodels_nlopt_optimize_full', PACKAGE = 'PLNmodels', data, params, config) } -nlopt_optimize_full_alt <- function(data, params, config) { - .Call('_PLNmodels_nlopt_optimize_full_alt', PACKAGE = 'PLNmodels', data, params, config) -} - nlopt_optimize_vestep_full <- function(data, params, B, Omega, config) { .Call('_PLNmodels_nlopt_optimize_vestep_full', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } @@ -97,10 +85,6 @@ nlopt_optimize_spherical <- function(data, params, config) { .Call('_PLNmodels_nlopt_optimize_spherical', PACKAGE = 'PLNmodels', data, params, config) } -nlopt_optimize_spherical_alt <- function(data, params, config) { - .Call('_PLNmodels_nlopt_optimize_spherical_alt', PACKAGE = 'PLNmodels', data, params, config) -} - nlopt_optimize_vestep_spherical <- function(data, params, B, Omega, config) { .Call('_PLNmodels_nlopt_optimize_vestep_spherical', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 1f45438c..d5f7c3d6 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -201,19 +201,6 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// nlopt_optimize_diagonal_alt -Rcpp::List nlopt_optimize_diagonal_alt(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_diagonal_alt(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_diagonal_alt(data, params, config)); - return rcpp_result_gen; -END_RCPP -} // nlopt_optimize_vestep_diagonal Rcpp::List nlopt_optimize_vestep_diagonal(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -242,19 +229,6 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// nlopt_optimize_fixed_alt -Rcpp::List nlopt_optimize_fixed_alt(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_fixed_alt(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_fixed_alt(data, params, config)); - return rcpp_result_gen; -END_RCPP -} // nlopt_optimize_full Rcpp::List nlopt_optimize_full(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); RcppExport SEXP _PLNmodels_nlopt_optimize_full(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { @@ -268,19 +242,6 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// nlopt_optimize_full_alt -Rcpp::List nlopt_optimize_full_alt(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_full_alt(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_full_alt(data, params, config)); - return rcpp_result_gen; -END_RCPP -} // nlopt_optimize_vestep_full Rcpp::List nlopt_optimize_vestep_full(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_full(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -337,19 +298,6 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// nlopt_optimize_spherical_alt -Rcpp::List nlopt_optimize_spherical_alt(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_nlopt_optimize_spherical_alt(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(nlopt_optimize_spherical_alt(data, params, config)); - return rcpp_result_gen; -END_RCPP -} // nlopt_optimize_vestep_spherical Rcpp::List nlopt_optimize_vestep_spherical(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_nlopt_optimize_vestep_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -677,17 +625,13 @@ static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_newton_optimize_spherical_alt", (DL_FUNC) &_PLNmodels_newton_optimize_spherical_alt, 3}, {"_PLNmodels_newton_optimize_vestep_spherical", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_spherical, 5}, {"_PLNmodels_nlopt_optimize_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_diagonal, 3}, - {"_PLNmodels_nlopt_optimize_diagonal_alt", (DL_FUNC) &_PLNmodels_nlopt_optimize_diagonal_alt, 3}, {"_PLNmodels_nlopt_optimize_vestep_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_diagonal, 5}, {"_PLNmodels_nlopt_optimize_fixed", (DL_FUNC) &_PLNmodels_nlopt_optimize_fixed, 3}, - {"_PLNmodels_nlopt_optimize_fixed_alt", (DL_FUNC) &_PLNmodels_nlopt_optimize_fixed_alt, 3}, {"_PLNmodels_nlopt_optimize_full", (DL_FUNC) &_PLNmodels_nlopt_optimize_full, 3}, - {"_PLNmodels_nlopt_optimize_full_alt", (DL_FUNC) &_PLNmodels_nlopt_optimize_full_alt, 3}, {"_PLNmodels_nlopt_optimize_vestep_full", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_full, 5}, {"_PLNmodels_nlopt_optimize_rank", (DL_FUNC) &_PLNmodels_nlopt_optimize_rank, 3}, {"_PLNmodels_nlopt_optimize_vestep_rank", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_rank, 5}, {"_PLNmodels_nlopt_optimize_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_spherical, 3}, - {"_PLNmodels_nlopt_optimize_spherical_alt", (DL_FUNC) &_PLNmodels_nlopt_optimize_spherical_alt, 3}, {"_PLNmodels_nlopt_optimize_vestep_spherical", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_spherical, 5}, {"_PLNmodels_cpp_test_nlopt", (DL_FUNC) &_PLNmodels_cpp_test_nlopt, 0}, {"_PLNmodels_nlopt_optimize_genetic_modeling", (DL_FUNC) &_PLNmodels_nlopt_optimize_genetic_modeling, 7}, diff --git a/src/nlopt_diag_cov.cpp b/src/nlopt_diag_cov.cpp index 284fb97c..9f649906 100644 --- a/src/nlopt_diag_cov.cpp +++ b/src/nlopt_diag_cov.cpp @@ -8,10 +8,9 @@ #include "utils.h" // --------------------------------------------------------------------------------------- -// Diagonal covariance PLN — nlopt/CCSAQ optimizer +// Diagonal covariance PLN — nlopt/CCSAQ optimizer (archived: B in parameter vector) -// [[Rcpp::export]] -Rcpp::List nlopt_optimize_diagonal( +Rcpp::List nlopt_optimize_diagonal_old( const Rcpp::List & data , // List(Y, X, O, w) const Rcpp::List & params, // List(B, M, S) const Rcpp::List & config // List of config values @@ -105,10 +104,10 @@ Rcpp::List nlopt_optimize_diagonal( } // --------------------------------------------------------------------------------------- -// Diagonal covariance PLN — profiled-B nlopt: B removed from parameter vector, closed-form per eval +// Diagonal covariance PLN — nlopt/CCSAQ optimizer: B profiled via closed form, reduced parameter vector // [[Rcpp::export]] -Rcpp::List nlopt_optimize_diagonal_alt( +Rcpp::List nlopt_optimize_diagonal( const Rcpp::List & data , const Rcpp::List & params, const Rcpp::List & config @@ -183,7 +182,7 @@ Rcpp::List nlopt_optimize_diagonal_alt( Rcpp::Named("Ji", Ji), Rcpp::Named("monitoring", Rcpp::List::create( Rcpp::Named("status", static_cast(result.status)), - Rcpp::Named("backend", "nlopt_alt"), + Rcpp::Named("backend", "nlopt"), Rcpp::Named("objective", objective_vec), Rcpp::Named("iterations", result.nb_iterations) )) diff --git a/src/nlopt_fixed_cov.cpp b/src/nlopt_fixed_cov.cpp index bc9c6099..c0be7551 100644 --- a/src/nlopt_fixed_cov.cpp +++ b/src/nlopt_fixed_cov.cpp @@ -8,10 +8,9 @@ #include "utils.h" // --------------------------------------------------------------------------------------- -// Fixed inverse covariance (Omega) PLN — nlopt/CCSAQ optimizer +// Fixed inverse covariance (Omega) PLN — nlopt/CCSAQ optimizer (archived: B in parameter vector) -// [[Rcpp::export]] -Rcpp::List nlopt_optimize_fixed( +Rcpp::List nlopt_optimize_fixed_old( const Rcpp::List & data , // List(Y, X, O, w) const Rcpp::List & params, // List(B, M, S) const Rcpp::List & config // List of config values @@ -98,10 +97,10 @@ Rcpp::List nlopt_optimize_fixed( } // --------------------------------------------------------------------------------------- -// Fixed covariance PLN — profiled-B nlopt: B removed from parameter vector, closed-form per eval +// Fixed covariance PLN — nlopt/CCSAQ optimizer: B profiled via closed form, reduced parameter vector // [[Rcpp::export]] -Rcpp::List nlopt_optimize_fixed_alt( +Rcpp::List nlopt_optimize_fixed( const Rcpp::List & data , const Rcpp::List & params, const Rcpp::List & config @@ -172,7 +171,7 @@ Rcpp::List nlopt_optimize_fixed_alt( Rcpp::Named("Ji", Ji), Rcpp::Named("monitoring", Rcpp::List::create( Rcpp::Named("status", static_cast(result.status)), - Rcpp::Named("backend", "nlopt_alt"), + Rcpp::Named("backend", "nlopt"), Rcpp::Named("objective", objective_vec), Rcpp::Named("iterations", result.nb_iterations) )) diff --git a/src/nlopt_full_cov.cpp b/src/nlopt_full_cov.cpp index 620a01d5..8edf5c66 100644 --- a/src/nlopt_full_cov.cpp +++ b/src/nlopt_full_cov.cpp @@ -8,10 +8,9 @@ #include "utils.h" // --------------------------------------------------------------------------------------- -// Full covariance PLN — nlopt/CCSAQ optimizer +// Full covariance PLN — nlopt/CCSAQ optimizer (archived: B in parameter vector) -// [[Rcpp::export]] -Rcpp::List nlopt_optimize_full( +Rcpp::List nlopt_optimize_full_old( const Rcpp::List & data , // List(Y, X, O, w) const Rcpp::List & params, // List(B, M, S) const Rcpp::List & config // List of config values @@ -137,10 +136,10 @@ Rcpp::List nlopt_optimize_full( } // --------------------------------------------------------------------------------------- -// Full covariance PLN — profiled-B nlopt: B removed from parameter vector, closed-form per eval +// Full covariance PLN — nlopt/CCSAQ optimizer: B profiled via closed form, reduced parameter vector // [[Rcpp::export]] -Rcpp::List nlopt_optimize_full_alt( +Rcpp::List nlopt_optimize_full( const Rcpp::List & data , // List(Y, X, O, w) const Rcpp::List & params, // List(B, M, S) const Rcpp::List & config // List of config values @@ -251,7 +250,7 @@ Rcpp::List nlopt_optimize_full_alt( Rcpp::Named("Ji", Ji), Rcpp::Named("monitoring", Rcpp::List::create( Rcpp::Named("status", last_status), - Rcpp::Named("backend", "nlopt_alt"), + Rcpp::Named("backend", "nlopt"), Rcpp::Named("objective", objective_vec), Rcpp::Named("iterations", total_iterations) )) diff --git a/src/nlopt_spherical.cpp b/src/nlopt_spherical.cpp index 218be6dd..26dafba9 100644 --- a/src/nlopt_spherical.cpp +++ b/src/nlopt_spherical.cpp @@ -8,10 +8,9 @@ #include "utils.h" // --------------------------------------------------------------------------------------- -// Spherical covariance PLN — nlopt/CCSAQ optimizer +// Spherical covariance PLN — nlopt/CCSAQ optimizer (archived: B in parameter vector) -// [[Rcpp::export]] -Rcpp::List nlopt_optimize_spherical( +Rcpp::List nlopt_optimize_spherical_old( const Rcpp::List & data , // List(Y, X, O, w) const Rcpp::List & params, // List(B, M, S) const Rcpp::List & config // List of config values @@ -103,10 +102,10 @@ Rcpp::List nlopt_optimize_spherical( } // --------------------------------------------------------------------------------------- -// Spherical covariance PLN — profiled-B nlopt: B removed from parameter vector, closed-form per eval +// Spherical covariance PLN — nlopt/CCSAQ optimizer: B profiled via closed form, reduced parameter vector // [[Rcpp::export]] -Rcpp::List nlopt_optimize_spherical_alt( +Rcpp::List nlopt_optimize_spherical( const Rcpp::List & data , const Rcpp::List & params, const Rcpp::List & config @@ -179,7 +178,7 @@ Rcpp::List nlopt_optimize_spherical_alt( Rcpp::Named("Ji", Ji), Rcpp::Named("monitoring", Rcpp::List::create( Rcpp::Named("status", static_cast(result.status)), - Rcpp::Named("backend", "nlopt_alt"), + Rcpp::Named("backend", "nlopt"), Rcpp::Named("objective", objective_vec), Rcpp::Named("iterations", result.nb_iterations) )) From b7a71495ddc3593fc1bfff35c786ce4f51c37922 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Wed, 10 Jun 2026 09:09:53 +0200 Subject: [PATCH 22/58] use alternative param in all optimizer --- R/PLN.R | 4 +- R/PLNfit-class.R | 24 ++--- R/RcppExports.R | 16 ---- R/utils.R | 21 +++-- src/RcppExports.cpp | 56 ------------ src/newton_diag_cov.cpp | 35 +------ src/newton_fixed_cov.cpp | 33 +------ src/newton_full_cov.cpp | 35 +------ src/newton_impl_alt.h | 57 +++++++----- src/newton_spherical.cpp | 35 +------ src/nlopt_diag_cov.cpp | 170 +++++++++------------------------- src/nlopt_fixed_cov.cpp | 90 +----------------- src/nlopt_full_cov.cpp | 191 +++++++-------------------------------- src/nlopt_spherical.cpp | 163 +++++++++------------------------ 14 files changed, 185 insertions(+), 745 deletions(-) diff --git a/R/PLN.R b/R/PLN.R index 0089e12e..39e81e3f 100644 --- a/R/PLN.R +++ b/R/PLN.R @@ -101,7 +101,7 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { #' #' @export PLN_param <- function( - backend = c("homemade", "nlopt", "torch", "homemade_alt", "hybrid"), + backend = c("nlopt", "homemade", "hybrid", "torch"), trace = 1, covariance = c("full", "diagonal", "spherical", "fixed"), Omega = NULL, @@ -127,7 +127,7 @@ PLN_param <- function( } else if (backend == "torch") { stopifnot(config_optim$algorithm %in% available_algorithms_torch) config_opt <- config_default_torch - } else { # "homemade", "homemade_alt", or "hybrid" + } else { # "homemade" or "hybrid" config_opt <- config_default_homemade } config_opt[names(config_optim)] <- config_optim diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index 0a0b2d7c..cb784d59 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -364,14 +364,12 @@ PLNfit <- R6Class( private$torch_optimize } else if (control$backend == "homemade") { newton_optimize_full - } else if (control$backend == "homemade_alt") { - newton_optimize_full_alt } else if (control$backend == "hybrid") { - make_hybrid_optimizer(newton_optimize_full, newton_optimize_full_alt) + make_hybrid_optimizer(nlopt_optimize_full, newton_optimize_full) } else { nlopt_optimize_full } - private$optimizer$vestep <- if (control$backend %in% c("homemade", "homemade_alt", "hybrid")) newton_optimize_vestep_full else nlopt_optimize_vestep_full + private$optimizer$vestep <- if (control$backend %in% c("homemade", "hybrid")) newton_optimize_vestep_full else nlopt_optimize_vestep_full }, ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -608,8 +606,6 @@ PLNfit <- R6Class( ) M <- tcrossprod(VE$M, A) - # S <- map(1:n_new, ~crossprod(sqrt(VE$S[., ]) * t(A)) + Sigma21) %>% - # simplify2array() S <- map(1:n_new, ~crossprod(VE$S[., ] * t(A)) + Sigma21) %>% simplify2array() ## mean latent positions in the parameter space @@ -750,14 +746,12 @@ PLNfit_diagonal <- R6Class( private$torch_optimize } else if (control$backend == "homemade") { newton_optimize_diagonal - } else if (control$backend == "homemade_alt") { - newton_optimize_diagonal_alt } else if (control$backend == "hybrid") { - make_hybrid_optimizer(newton_optimize_diagonal, newton_optimize_diagonal_alt) + make_hybrid_optimizer(nlopt_optimize_diagonal, newton_optimize_diagonal) } else { nlopt_optimize_diagonal } - private$optimizer$vestep <- if (control$backend %in% c("homemade", "homemade_alt", "hybrid")) newton_optimize_vestep_diagonal else nlopt_optimize_vestep_diagonal + private$optimizer$vestep <- if (control$backend %in% c("homemade", "hybrid")) newton_optimize_vestep_diagonal else nlopt_optimize_vestep_diagonal } ), private = list( @@ -843,14 +837,12 @@ PLNfit_spherical <- R6Class( private$torch_optimize } else if (control$backend == "homemade") { newton_optimize_spherical - } else if (control$backend == "homemade_alt") { - newton_optimize_spherical_alt } else if (control$backend == "hybrid") { - make_hybrid_optimizer(newton_optimize_spherical, newton_optimize_spherical_alt) + make_hybrid_optimizer(nlopt_optimize_spherical, newton_optimize_spherical) } else { nlopt_optimize_spherical } - private$optimizer$vestep <- if (control$backend %in% c("homemade", "homemade_alt", "hybrid")) newton_optimize_vestep_spherical else nlopt_optimize_vestep_spherical + private$optimizer$vestep <- if (control$backend %in% c("homemade", "hybrid")) newton_optimize_vestep_spherical else nlopt_optimize_vestep_spherical } ), private = list( @@ -940,10 +932,8 @@ PLNfit_fixedcov <- R6Class( private$torch_optimize } else if (control$backend == "homemade") { newton_optimize_fixed - } else if (control$backend == "homemade_alt") { - newton_optimize_fixed_alt } else if (control$backend == "hybrid") { - make_hybrid_optimizer(newton_optimize_fixed, newton_optimize_fixed_alt) + make_hybrid_optimizer(nlopt_optimize_fixed, newton_optimize_fixed) } else { nlopt_optimize_fixed } diff --git a/R/RcppExports.R b/R/RcppExports.R index 62326c62..aa20d6ac 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -5,10 +5,6 @@ newton_optimize_diagonal <- function(data, params, config) { .Call('_PLNmodels_newton_optimize_diagonal', PACKAGE = 'PLNmodels', data, params, config) } -newton_optimize_diagonal_alt <- function(data, params, config) { - .Call('_PLNmodels_newton_optimize_diagonal_alt', PACKAGE = 'PLNmodels', data, params, config) -} - newton_optimize_vestep_diagonal <- function(data, params, B, Omega, config) { .Call('_PLNmodels_newton_optimize_vestep_diagonal', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } @@ -17,18 +13,10 @@ newton_optimize_fixed <- function(data, params, config) { .Call('_PLNmodels_newton_optimize_fixed', PACKAGE = 'PLNmodels', data, params, config) } -newton_optimize_fixed_alt <- function(data, params, config) { - .Call('_PLNmodels_newton_optimize_fixed_alt', PACKAGE = 'PLNmodels', data, params, config) -} - newton_optimize_full <- function(data, params, config) { .Call('_PLNmodels_newton_optimize_full', PACKAGE = 'PLNmodels', data, params, config) } -newton_optimize_full_alt <- function(data, params, config) { - .Call('_PLNmodels_newton_optimize_full_alt', PACKAGE = 'PLNmodels', data, params, config) -} - newton_optimize_vestep_full <- function(data, params, B, Omega, config) { .Call('_PLNmodels_newton_optimize_vestep_full', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } @@ -45,10 +33,6 @@ newton_optimize_spherical <- function(data, params, config) { .Call('_PLNmodels_newton_optimize_spherical', PACKAGE = 'PLNmodels', data, params, config) } -newton_optimize_spherical_alt <- function(data, params, config) { - .Call('_PLNmodels_newton_optimize_spherical_alt', PACKAGE = 'PLNmodels', data, params, config) -} - newton_optimize_vestep_spherical <- function(data, params, B, Omega, config) { .Call('_PLNmodels_newton_optimize_vestep_spherical', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } diff --git a/R/utils.R b/R/utils.R index 925d8930..f52dce0a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -22,18 +22,21 @@ config_default_homemade <- ftol_rel = 1e-8 ) -# Hybrid backend: two-phase optimizer — homemade (phase 1) then homemade_alt (phase 2). -# Phase 1 uses looser tolerances (100× the target ftol_rel) to reach the basin quickly. -# Phase 2 refines to the full requested tolerance. +# Hybrid backend: two-phase optimizer — nlopt/CCSAQ (phase 1) then homemade Newton (phase 2). +# Phase 1 (nlopt) uses looser tolerances to reach the basin quickly with quasi-Newton search. +# Phase 2 (homemade, envelope-theorem Newton) refines to the full requested tolerance. # Returns a closure with the same (data, params, config) signature as the C++ wrappers. -make_hybrid_optimizer <- function(opt_phase1, opt_phase2) { +make_hybrid_optimizer <- function(opt_nlopt, opt_newton) { function(data, params, config) { - config1 <- config - config1$ftol_rel <- config$ftol_rel * 10 - if (!is.null(config$em_ftol)) config1$em_ftol <- config$em_ftol * 10 - res1 <- opt_phase1(data, params, config1) + # Phase 1: nlopt config with 10× looser tolerance for fast basin finding + config1 <- modifyList(config_default_nlopt, list( + maxeval = config$maxeval, + ftol_rel = config$ftol_rel * 10 + )) + res1 <- opt_nlopt(data, params, config1) params2 <- modifyList(params, list(B = res1$B, M = res1$M, S = res1$S)) - res2 <- opt_phase2(data, params2, config) + # Phase 2: homemade Newton with full tolerance + res2 <- opt_newton(data, params2, config) res2$monitoring$objective <- c(res1$monitoring$objective, res2$monitoring$objective) res2$monitoring$iterations <- res1$monitoring$iterations + res2$monitoring$iterations res2$monitoring$backend <- "hybrid" diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index d5f7c3d6..87df22b0 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -24,19 +24,6 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// newton_optimize_diagonal_alt -Rcpp::List newton_optimize_diagonal_alt(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_newton_optimize_diagonal_alt(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(newton_optimize_diagonal_alt(data, params, config)); - return rcpp_result_gen; -END_RCPP -} // newton_optimize_vestep_diagonal Rcpp::List newton_optimize_vestep_diagonal(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_newton_optimize_vestep_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -65,19 +52,6 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// newton_optimize_fixed_alt -Rcpp::List newton_optimize_fixed_alt(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_newton_optimize_fixed_alt(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(newton_optimize_fixed_alt(data, params, config)); - return rcpp_result_gen; -END_RCPP -} // newton_optimize_full Rcpp::List newton_optimize_full(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); RcppExport SEXP _PLNmodels_newton_optimize_full(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { @@ -91,19 +65,6 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// newton_optimize_full_alt -Rcpp::List newton_optimize_full_alt(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_newton_optimize_full_alt(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(newton_optimize_full_alt(data, params, config)); - return rcpp_result_gen; -END_RCPP -} // newton_optimize_vestep_full Rcpp::List newton_optimize_vestep_full(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_newton_optimize_vestep_full(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -160,19 +121,6 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// newton_optimize_spherical_alt -Rcpp::List newton_optimize_spherical_alt(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_newton_optimize_spherical_alt(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(newton_optimize_spherical_alt(data, params, config)); - return rcpp_result_gen; -END_RCPP -} // newton_optimize_vestep_spherical Rcpp::List newton_optimize_vestep_spherical(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); RcppExport SEXP _PLNmodels_newton_optimize_vestep_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { @@ -612,17 +560,13 @@ END_RCPP static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_newton_optimize_diagonal", (DL_FUNC) &_PLNmodels_newton_optimize_diagonal, 3}, - {"_PLNmodels_newton_optimize_diagonal_alt", (DL_FUNC) &_PLNmodels_newton_optimize_diagonal_alt, 3}, {"_PLNmodels_newton_optimize_vestep_diagonal", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_diagonal, 5}, {"_PLNmodels_newton_optimize_fixed", (DL_FUNC) &_PLNmodels_newton_optimize_fixed, 3}, - {"_PLNmodels_newton_optimize_fixed_alt", (DL_FUNC) &_PLNmodels_newton_optimize_fixed_alt, 3}, {"_PLNmodels_newton_optimize_full", (DL_FUNC) &_PLNmodels_newton_optimize_full, 3}, - {"_PLNmodels_newton_optimize_full_alt", (DL_FUNC) &_PLNmodels_newton_optimize_full_alt, 3}, {"_PLNmodels_newton_optimize_vestep_full", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_full, 5}, {"_PLNmodels_newton_optimize_rank", (DL_FUNC) &_PLNmodels_newton_optimize_rank, 3}, {"_PLNmodels_newton_optimize_vestep_rank", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_rank, 5}, {"_PLNmodels_newton_optimize_spherical", (DL_FUNC) &_PLNmodels_newton_optimize_spherical, 3}, - {"_PLNmodels_newton_optimize_spherical_alt", (DL_FUNC) &_PLNmodels_newton_optimize_spherical_alt, 3}, {"_PLNmodels_newton_optimize_vestep_spherical", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_spherical, 5}, {"_PLNmodels_nlopt_optimize_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_diagonal, 3}, {"_PLNmodels_nlopt_optimize_vestep_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_diagonal, 5}, diff --git a/src/newton_diag_cov.cpp b/src/newton_diag_cov.cpp index 06135298..12879baf 100644 --- a/src/newton_diag_cov.cpp +++ b/src/newton_diag_cov.cpp @@ -3,11 +3,11 @@ // [[Rcpp::depends(RcppArmadillo)]] #include "utils.h" -#include "newton_impl.h" -#include "newton_impl_alt.h" +#include "newton_impl.h" // newton_vestep_impl +#include "newton_impl_alt.h" // newton_optimize_alt_impl — the homemade E-step // --------------------------------------------------------------------------------------- -// Diagonal covariance PLN — coordinate-Newton optimizer +// Diagonal covariance PLN — homemade Newton optimizer (profiled B via envelope theorem) // [[Rcpp::export]] Rcpp::List newton_optimize_diagonal( @@ -32,35 +32,6 @@ Rcpp::List newton_optimize_diagonal( arma::mat S2 = S % S; DiagonalCovTraits::State state(M, S2, w, w_bar); - return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); -} - -// --------------------------------------------------------------------------------------- -// Diagonal covariance PLN — alternative EM: closed-form B in M-step - -// [[Rcpp::export]] -Rcpp::List newton_optimize_diagonal_alt( - const Rcpp::List & data , - const Rcpp::List & params, - const Rcpp::List & config -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); - - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; - const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; - - const double w_bar = arma::accu(w); - arma::mat S2 = S % S; - DiagonalCovTraits::State state(M, S2, w, w_bar); - return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); } diff --git a/src/newton_fixed_cov.cpp b/src/newton_fixed_cov.cpp index 3f25bebf..c2632618 100644 --- a/src/newton_fixed_cov.cpp +++ b/src/newton_fixed_cov.cpp @@ -3,11 +3,10 @@ // [[Rcpp::depends(RcppArmadillo)]] #include "utils.h" -#include "newton_impl.h" -#include "newton_impl_alt.h" +#include "newton_impl_alt.h" // newton_optimize_alt_impl — the homemade E-step // --------------------------------------------------------------------------------------- -// Fixed inverse covariance (Omega provided externally) PLN — coordinate-Newton optimizer +// Fixed inverse covariance (Omega provided externally) PLN — homemade Newton optimizer // [[Rcpp::export]] Rcpp::List newton_optimize_fixed( @@ -24,34 +23,6 @@ Rcpp::List newton_optimize_fixed( arma::mat S = Rcpp::as(params["S"]); arma::mat Omega = Rcpp::as(params["Omega"]); - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - - arma::mat S2 = S % S; - FixedCovTraits::State state(Omega); - - // Fixed covariance has no EM loop (has_em = false); pass max_em=1, em_tol=0 - return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, 1, 0.0); -} - -// --------------------------------------------------------------------------------------- -// Fixed inverse covariance PLN — alternative EM: closed-form B, iterated until convergence - -// [[Rcpp::export]] -Rcpp::List newton_optimize_fixed_alt( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(B, M, S, Omega) - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); - arma::mat Omega = Rcpp::as(params["Omega"]); - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; diff --git a/src/newton_full_cov.cpp b/src/newton_full_cov.cpp index e9366712..49f4d058 100644 --- a/src/newton_full_cov.cpp +++ b/src/newton_full_cov.cpp @@ -3,11 +3,11 @@ // [[Rcpp::depends(RcppArmadillo)]] #include "utils.h" -#include "newton_impl.h" -#include "newton_impl_alt.h" +#include "newton_impl.h" // newton_vestep_impl +#include "newton_impl_alt.h" // newton_optimize_alt_impl — the homemade E-step // --------------------------------------------------------------------------------------- -// Full covariance PLN — coordinate-Newton optimizer +// Full covariance PLN — homemade Newton optimizer (profiled B via envelope theorem) // [[Rcpp::export]] Rcpp::List newton_optimize_full( @@ -32,35 +32,6 @@ Rcpp::List newton_optimize_full( arma::mat S2 = S % S; FullCovTraits::State state(M, S2, w, w_bar); - return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); -} - -// --------------------------------------------------------------------------------------- -// Full covariance PLN — alternative EM: closed-form B in M-step, no newton_step_B in inner loop - -// [[Rcpp::export]] -Rcpp::List newton_optimize_full_alt( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(B, M, S) - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); - - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; - const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; - - const double w_bar = arma::accu(w); - arma::mat S2 = S % S; - FullCovTraits::State state(M, S2, w, w_bar); - return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); } diff --git a/src/newton_impl_alt.h b/src/newton_impl_alt.h index e81c3f05..1481c0bb 100644 --- a/src/newton_impl_alt.h +++ b/src/newton_impl_alt.h @@ -6,11 +6,13 @@ // Alternative parameterization: M stores M_full (the full variational mean on Z_i, // not the residual M_res = M_full - XB used in newton_impl.h). // -// Key difference from the standard implementation: -// - B is NOT updated in the inner loop; it gets an exact closed-form EM M-step: -// B = (X'WX)^{-1} X'W M_full -// - The inner loop updates only M_full and S, with gradient using M_res = M_full - XB. -// - Sigma/Omega M-step uses M_res = M_full - XB (same formula as before). +// B is profiled at every Newton step via the envelope theorem (same as nlopt E-step): +// B = P_X * M_full = (X'WX)^{-1} X'W M_full (closed-form optimum for current M_full) +// M_res = M_full - X*B (projection orthogonal to col(X)) +// The gradient of J_profiled w.r.t. M_full equals the gradient w.r.t. M_res +// (envelope theorem), so no formula change is needed. Within each Armijo line search +// B is held fixed at the value computed at the start of the Newton step, consistent +// with how nlopt evaluates the gradient once per quasi-Newton iteration. // // At input/output: M is in the "residual" format (M_res = M_full - XB) to stay // compatible with the rest of the R package. The conversion is done internally. @@ -28,9 +30,10 @@ Rcpp::List newton_optimize_alt_impl( const double c1 = 1e-4; const arma::mat ones_row = arma::ones(n, 1); - // Precompute X'WX once: used for closed-form B = (X'WX)^{-1} X'W M_full + // Precompute X'WX and P_X once: P_X = (X'WX)^{-1}X'W (d×n) for live B = P_X * M_full const arma::mat Xw = X.each_col() % w; // n×d const arma::mat XtWX = X.t() * Xw; // d×d, symmetric PD + const arma::mat P_X = arma::solve(XtWX, Xw.t()); // d×n, precomputed once // Convert input M from residual format to M_full = XB + M_res M = X * B + M; @@ -43,13 +46,15 @@ Rcpp::List newton_optimize_alt_impl( int total_iter = 0; int last_status = 5; - // Inner loop: B is fixed; only M_full and S are updated. + // Inner loop: B profiled at each Newton step via envelope theorem. auto inner_loop = [&]() { - const arma::mat XB = X * B; // constant within this inner loop double obj_prev = arma::datum::inf; for (int it = 0; it < maxiter; it++) { S2 = arma::exp(psi); + // Envelope theorem: update B to closed-form optimum for current M_full + B = P_X * M; + const arma::mat XB = X * B; // frozen during the Armijo line search below arma::mat M_res = M - XB; arma::mat Z = O + M; // Z = O + M_full arma::mat A = arma::exp(Z + 0.5 * S2); @@ -60,31 +65,37 @@ Rcpp::List newton_optimize_alt_impl( hess_M.clamp(1e-10, arma::datum::inf); arma::mat step_M = grad_M / hess_M; - arma::mat MresO = Traits::times_Omega(M_res, state); - arma::mat dMO = Traits::times_Omega(step_M, state); + // Q_step = (I - X*P_X)*step_M: change in M_res per unit alpha (correct projected step) + // With live B: M_res_t = M_res - alpha*Q_step, slope = -grad_M . Q_step + const arma::mat Q_step = step_M - X * (P_X * step_M); + arma::mat MresO = Traits::times_Omega(M_res, state); + arma::mat QstepO = Traits::times_Omega(Q_step, state); double f0_M = arma::accu(w.t() * (A - Y % Z)) + Traits::penalty_M(MresO, M_res, w); - double slope_M = -arma::accu(grad_M % step_M); + double slope_M = -arma::accu(grad_M % Q_step); + // Fall back if step is not a descent direction (degenerate case) + if (slope_M >= 0) slope_M = -arma::accu(grad_M % step_M); double alpha_M = 1.0; for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; // M_full candidate - arma::mat MresOt = MresO - alpha_M * dMO; - arma::mat Zt = Z - alpha_M * step_M; // = O + Mt + arma::mat MresOt = MresO - alpha_M * QstepO; + arma::mat MresT = M_res - alpha_M * Q_step; + arma::mat Zt = Z - alpha_M * step_M; // = O + Mt arma::mat At = arma::exp(Zt + 0.5 * S2); - // penalty uses M_res_t = Mt - XB - if (arma::accu(w.t() * (At - Y % Zt)) + Traits::penalty_M(MresOt, Mt - XB, w) + if (arma::accu(w.t() * (At - Y % Zt)) + Traits::penalty_M(MresOt, MresT, w) <= f0_M + c1 * alpha_M * slope_M) break; alpha_M *= 0.5; } M -= alpha_M * step_M; + // Keep B current after accepting the M step + B = P_X * M; Z = O + M; // S step: exact fixed-point ψ = −log(A + diag_Ω) fixed_point_psi(psi, S2, Z, A, Traits::cov_diag(state, ones_row)); A = arma::exp(Z + 0.5 * S2); - M_res = M - XB; + arma::mat M_res_new = M - X * B; // updated M_res with live B double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * psi)) - + Traits::objective_cov(M_res, S2, state, w); + + Traits::objective_cov(M_res_new, S2, state, w); objective_vec.push_back(obj); total_iter++; @@ -99,10 +110,8 @@ Rcpp::List newton_optimize_alt_impl( S2 = arma::exp(psi); - // Closed-form B M-step: B = (X'WX)^{-1} X'W M_full - B = arma::solve(XtWX, Xw.t() * M); - - // Sigma/Omega M-step: uses M_res = M_full - XB (same as current mstep) + // B is already at its optimum (live-updated in inner_loop); only Omega needs updating. + // Recompute M_res for the Sigma/Omega M-step. arma::mat M_res = M - X * B; Traits::mstep(state, M_res, S2, w, w_bar, p); @@ -114,12 +123,12 @@ Rcpp::List newton_optimize_alt_impl( elbo_prev = elbo; } } else { - // Fixed covariance: Omega is fixed; iterate (E-step + B M-step) until convergence + // Fixed covariance: Omega is fixed; B is live-updated in inner_loop. double elbo_prev_fix = -arma::datum::inf; for (int em = 0; em < max_em; em++) { inner_loop(); S2 = arma::exp(psi); - B = arma::solve(XtWX, Xw.t() * M); + // B already optimal after inner_loop; recompute M_res for ELBO check. arma::mat M_res = M - X * B; arma::mat Z = O + M; arma::mat A = arma::exp(Z + 0.5 * S2); diff --git a/src/newton_spherical.cpp b/src/newton_spherical.cpp index 6fd096ad..63ce8ef0 100644 --- a/src/newton_spherical.cpp +++ b/src/newton_spherical.cpp @@ -3,11 +3,11 @@ // [[Rcpp::depends(RcppArmadillo)]] #include "utils.h" -#include "newton_impl.h" -#include "newton_impl_alt.h" +#include "newton_impl.h" // newton_vestep_impl +#include "newton_impl_alt.h" // newton_optimize_alt_impl — the homemade E-step // --------------------------------------------------------------------------------------- -// Spherical covariance PLN — coordinate-Newton optimizer +// Spherical covariance PLN — homemade Newton optimizer (profiled B via envelope theorem) // [[Rcpp::export]] Rcpp::List newton_optimize_spherical( @@ -32,35 +32,6 @@ Rcpp::List newton_optimize_spherical( arma::mat S2 = S % S; SphericalCovTraits::State state(M, S2, w, w_bar); - return newton_optimize_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); -} - -// --------------------------------------------------------------------------------------- -// Spherical covariance PLN — alternative EM: closed-form B in M-step - -// [[Rcpp::export]] -Rcpp::List newton_optimize_spherical_alt( - const Rcpp::List & data , - const Rcpp::List & params, - const Rcpp::List & config -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); - - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; - const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; - - const double w_bar = arma::accu(w); - arma::mat S2 = S % S; - SphericalCovTraits::State state(M, S2, w, w_bar); - return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); } diff --git a/src/nlopt_diag_cov.cpp b/src/nlopt_diag_cov.cpp index 9f649906..267fe3c3 100644 --- a/src/nlopt_diag_cov.cpp +++ b/src/nlopt_diag_cov.cpp @@ -8,99 +8,21 @@ #include "utils.h" // --------------------------------------------------------------------------------------- -// Diagonal covariance PLN — nlopt/CCSAQ optimizer (archived: B in parameter vector) - -Rcpp::List nlopt_optimize_diagonal_old( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(B, M, S) - const Rcpp::List & config // List of config values +// Shared inner computation for diagonal-covariance NLOPT objective and gradients. +// Z = O + X*B + M_res and S2 = exp(logS2) must be pre-computed by the caller. +// inv_sigma2: row vector of element-wise precisions (profiled 1/diag_sigma or fixed omega2). +// penalty: KL variance term (log-det for profiled E-step; quadratic for fixed-omega vestep). +static double diag_cov_obj_grad_impl( + const arma::mat & M_res, const arma::mat & Z, + const arma::mat & S2, const arma::mat & logS2, + const arma::rowvec & inv_sigma2, double penalty, + const arma::mat & Y, const arma::vec & w, + arma::mat & grad_M, arma::mat & grad_S ) { - // Conversion from R, prepare optimization - const arma::mat & Y = Rcpp::as(data["Y"]); // responses (n,p) - const arma::mat & X = Rcpp::as(data["X"]); // covariates (n,d) - const arma::mat & O = Rcpp::as(data["O"]); // offsets (n,p) - const arma::vec & w = Rcpp::as(data["w"]); // weights (n) - const auto init_B = Rcpp::as(params["B"]); // (d,p) - const auto init_M = Rcpp::as(params["M"]); // (n,p) - const auto init_S = Rcpp::as(params["S"]); // (n,p) - - const auto metadata = tuple_metadata(init_B, init_M, init_S); - enum { B_ID, M_ID, S_ID }; // Names for metadata indexes - - auto parameters = std::vector(metadata.packed_size); - metadata.map(parameters.data()) = init_B; - metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = arma::log(init_S % init_S); // pack logS2 - - auto optimizer = new_nlopt_optimizer(config, parameters.size()); - std::vector objective_vec ; - objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); - const double w_bar = accu(w); - - const arma::mat Xw = X.each_col() % w; // fixed: precomputed once - - // Optimize - auto objective_and_grad = [&metadata, &O, &X, &Xw, &Y, &w, &w_bar, &objective_vec](const double * params, double * grad) -> double { - const arma::mat B = metadata.map(params); - const arma::mat M = metadata.map(params); - const arma::mat logS2 = metadata.map(params); - - arma::mat S2 = arma::exp(logS2); - arma::mat Z = O + X * B + M; - arma::mat A = exp(Z + 0.5 * S2); - arma::rowvec diag_sigma = w.t() * (M % M + S2) / w_bar; - // -½ log(S²) → -½ logS2 - double objective = accu(diagmat(w) * (A - Y % Z - 0.5 * logS2)) + 0.5 * w_bar * accu(log(diag_sigma)); - - metadata.map(grad) = Xw.t() * (A - Y); - metadata.map(grad) = diagmat(w) * ((M.each_row() / diag_sigma) + A - Y); - // grad_logS2 = ½ w ⊙ (S²⊙(1/σ² + A) − 1) - metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % pow(diag_sigma, -1) + S2 % A - 1.); - - objective_vec.push_back(objective) ; - - return objective; - }; - OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); - - // Variational parameters - arma::mat M = metadata.copy(parameters.data()); - arma::mat logS2 = metadata.copy(parameters.data()); - arma::mat S2 = arma::exp(logS2); - arma::mat S = arma::exp(0.5 * logS2); - // Regression parameters - arma::mat B = metadata.copy(parameters.data()); - // Variance parameters - arma::rowvec sigma2 = w.t() * (M % M + S2) / w_bar; - arma::vec omega2 = pow(sigma2.t(), -1); - arma::sp_mat Sigma(Y.n_cols, Y.n_cols); - Sigma.diag() = sigma2; - arma::sp_mat Omega(Y.n_cols, Y.n_cols); - Omega.diag() = omega2; - // Element-wise log-likelihood - arma::mat Z = O + X * B + M; - arma::mat A = exp(Z + 0.5 * S2); - arma::mat loglik = - sum(Y % Z - A + 0.5 * logS2, 1) - 0.5 * (pow(M, 2) + S2) * omega2 + 0.5 * sum(log(omega2)) + ki(Y); - - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("B", B), - Rcpp::Named("Sigma", Sigma), - Rcpp::Named("Omega", Omega), - Rcpp::Named("M", M), - Rcpp::Named("S", S), - Rcpp::Named("Z", Z), - Rcpp::Named("A", A), - Rcpp::Named("Ji", Ji), - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", static_cast(result.status)), - Rcpp::Named("backend", "nlopt"), - Rcpp::Named("objective", objective_vec), - Rcpp::Named("iterations", result.nb_iterations) - )) - ); + const arma::mat A = arma::exp(Z + 0.5 * S2); + grad_M = arma::diagmat(w) * (M_res.each_row() % inv_sigma2 + A - Y); + grad_S = 0.5 * arma::diagmat(w) * (S2.each_row() % inv_sigma2 + S2 % A - 1.); + return accu(w.t() * (A - Y % Z - 0.5 * logS2)) + penalty; } // --------------------------------------------------------------------------------------- @@ -135,22 +57,23 @@ Rcpp::List nlopt_optimize_diagonal( const arma::mat Xw = X.each_col() % w; const arma::mat P_X = arma::solve(X.t() * Xw, Xw.t()); + // E-step: M_full is the NLOPT parameter; B and diag_sigma profiled at each eval auto objective_and_grad = [&](const double * par, double * grad) -> double { - const arma::mat M_full = metadata.map(par); - const arma::mat logS2 = metadata.map(par); - arma::mat S2 = arma::exp(logS2); - arma::mat B = P_X * M_full; - arma::mat M_res = M_full - X * B; - arma::mat Z = O + M_full; - arma::mat A = exp(Z + 0.5 * S2); - arma::rowvec diag_sigma = w.t() * (M_res % M_res + S2) / w_bar; - double objective = accu(diagmat(w) * (A - Y % Z - 0.5 * logS2)) - + 0.5 * w_bar * accu(log(diag_sigma)); - // gradient for M_full = gradient for M_res (envelope theorem for B and sigma2) - metadata.map(grad) = diagmat(w) * ((M_res.each_row() / diag_sigma) + A - Y); - metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % pow(diag_sigma, -1) + S2 % A - 1.); - objective_vec.push_back(objective); - return objective; + const arma::mat M_full = metadata.map(par); + const arma::mat logS2 = metadata.map(par); + const arma::mat S2 = arma::exp(logS2); + const arma::mat B = P_X * M_full; + const arma::mat M_res = M_full - X * B; + const arma::rowvec diag_sigma = w.t() * (M_res % M_res + S2) / w_bar; + const arma::rowvec inv_sigma2 = arma::pow(diag_sigma, -1); + arma::mat gM, gS; + const double obj = diag_cov_obj_grad_impl(M_res, O + M_full, S2, logS2, + inv_sigma2, 0.5 * w_bar * accu(arma::log(diag_sigma)), + Y, w, gM, gS); + metadata.map(grad) = gM; + metadata.map(grad) = gS; + objective_vec.push_back(obj); + return obj; }; OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); @@ -218,26 +141,21 @@ Rcpp::List nlopt_optimize_vestep_diagonal( std::vector objective_vec ; objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); - const arma::mat XB_diag = X * B; - const arma::vec omega2_v = arma::diagvec(Omega); // fixed: Omega not optimized in vestep + const arma::mat OXB = O + X * B; // fixed offset, precomputed once + const arma::rowvec omega2_v = arma::diagvec(Omega).t(); // fixed precision, as row vector - // Optimize - auto objective_and_grad = [&metadata, &O, &XB_diag, &Y, &w, &omega2_v, &objective_vec](const double * params, double * grad) -> double { + // Vestep: M_res is the NLOPT parameter; B and Omega fixed by the caller + auto objective_and_grad = [&](const double * params, double * grad) -> double { const arma::mat M = metadata.map(params); const arma::mat logS2 = metadata.map(params); - - arma::mat S2 = arma::exp(logS2); - arma::mat Z = O + XB_diag + M; - arma::mat A = exp(Z + 0.5 * S2); - double objective = - accu(w.t() * (A - Y % Z - 0.5 * logS2)) + 0.5 * as_scalar(w.t() * (pow(M, 2) + S2) * omega2_v) ; - - metadata.map(grad) = diagmat(w) * (M * arma::diagmat(omega2_v) + A - Y); - metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % omega2_v.t() + S2 % A - 1.); - - objective_vec.push_back(objective) ; - - return objective; + const arma::mat S2 = arma::exp(logS2); + const double penalty = 0.5 * as_scalar(w.t() * (arma::pow(M, 2) + S2) * omega2_v.t()); + arma::mat gM, gS; + const double obj = diag_cov_obj_grad_impl(M, OXB + M, S2, logS2, omega2_v, penalty, Y, w, gM, gS); + metadata.map(grad) = gM; + metadata.map(grad) = gS; + objective_vec.push_back(obj); + return obj; }; OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); @@ -246,10 +164,10 @@ Rcpp::List nlopt_optimize_vestep_diagonal( arma::mat logS2 = metadata.copy(parameters.data()); arma::mat S2 = arma::exp(logS2); arma::mat S = arma::exp(0.5 * logS2); - arma::vec omega2 = Omega.diag(); // Element-wise log-likelihood - arma::mat Z = O + X * B + M; + arma::mat Z = OXB + M; arma::mat A = exp(Z + 0.5 * S2); + arma::vec omega2 = Omega.diag(); arma::mat loglik = sum(Y % Z - A + 0.5 * logS2, 1) - 0.5 * (pow(M, 2) + S2) * omega2 + 0.5 * sum(log(omega2)) + ki(Y); diff --git a/src/nlopt_fixed_cov.cpp b/src/nlopt_fixed_cov.cpp index c0be7551..90a08f08 100644 --- a/src/nlopt_fixed_cov.cpp +++ b/src/nlopt_fixed_cov.cpp @@ -7,95 +7,6 @@ #include "packing.h" #include "utils.h" -// --------------------------------------------------------------------------------------- -// Fixed inverse covariance (Omega) PLN — nlopt/CCSAQ optimizer (archived: B in parameter vector) - -Rcpp::List nlopt_optimize_fixed_old( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(B, M, S) - const Rcpp::List & config // List of config values -) { - // Conversion from R, prepare optimization - const arma::mat & Y = Rcpp::as(data["Y"]); // responses (n,p) - const arma::mat & X = Rcpp::as(data["X"]); // covariates (n,d) - const arma::mat & O = Rcpp::as(data["O"]); // offsets (n,p) - const arma::vec & w = Rcpp::as(data["w"]); // weights (n) - const auto init_B = Rcpp::as(params["B"]); // (d,p) - const auto init_M = Rcpp::as(params["M"]); // (n,p) - const auto init_S = Rcpp::as(params["S"]); // (n,p) - const auto Omega = Rcpp::as(params["Omega"]); // covinv (p,p) - - const auto metadata = tuple_metadata(init_B, init_M, init_S); - enum { B_ID, M_ID, S_ID }; // Names for metadata indexes - - auto parameters = std::vector(metadata.packed_size); - metadata.map(parameters.data()) = init_B; - metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = arma::log(init_S % init_S); // pack logS2 - - // Optimize - auto optimizer = new_nlopt_optimizer(config, parameters.size()); - std::vector objective_vec ; - - const arma::mat Xw = X.each_col() % w; // fixed: precomputed once - const arma::vec Omega_diag = diagvec(Omega); - - auto objective_and_grad = [&metadata, &O, &X, &Xw, &Y, &w, &Omega, &Omega_diag, &objective_vec](const double * params, double * grad) -> double { - const arma::mat B = metadata.map(params); - const arma::mat M = metadata.map(params); - const arma::mat logS2 = metadata.map(params); - - arma::mat S2 = arma::exp(logS2); - arma::mat Z = O + X * B + M; - arma::mat A = exp(Z + 0.5 * S2); - arma::mat nSigma = M.t() * (M.each_col() % w) + diagmat(w.t() * S2); - // -½ log(S²) → -½ logS2 - double objective = accu(w.t() * (A - Y % Z - 0.5 * logS2)) + 0.5 * trace(Omega * nSigma); - - metadata.map(grad) = Xw.t() * (A - Y); - metadata.map(grad) = diagmat(w) * (M * Omega + A - Y); - // grad_logS2 = ½ w ⊙ (S²⊙(Ω_diag + A) − 1) - metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % Omega_diag.t() + S2 % A - 1.) ; - - objective_vec.push_back(objective) ; - - return objective; - }; - OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); - - // Model and variational parameters - arma::mat B = metadata.copy(parameters.data()); - arma::mat M = metadata.copy(parameters.data()); - arma::mat logS2 = metadata.copy(parameters.data()); - arma::mat S2 = arma::exp(logS2); - arma::mat S = arma::exp(0.5 * logS2); - arma::mat Sigma = (M.t() * (M.each_col() % w) + diagmat(w.t() * S2)) / accu(w); - // Element-wise log-likelihood - arma::mat Z = O + X * B + M; - arma::mat A = exp(Z + 0.5 * S2); - arma::mat loglik = sum(Y % Z - A - 0.5 * ((M * Omega) % M - logS2 + S2 * diagmat(Omega)), 1) + - 0.5 * real(log_det(Omega)) + ki(Y); - - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("B", B), - Rcpp::Named("M", M), - Rcpp::Named("S", S), - Rcpp::Named("Z", Z), - Rcpp::Named("A", A), - Rcpp::Named("Sigma", Sigma), - Rcpp::Named("Omega", Omega), - Rcpp::Named("Ji", Ji), - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", static_cast(result.status)), - Rcpp::Named("backend", "nlopt"), - Rcpp::Named("objective", objective_vec), - Rcpp::Named("iterations", result.nb_iterations) - )) - ); -} - // --------------------------------------------------------------------------------------- // Fixed covariance PLN — nlopt/CCSAQ optimizer: B profiled via closed form, reduced parameter vector @@ -140,6 +51,7 @@ Rcpp::List nlopt_optimize_fixed( + 0.5 * trace(Omega * (M_res.t() * (M_res.each_col() % w) + diagmat(w.t() * S2))); // gradient for M_full = gradient for M_res (envelope theorem for B) metadata.map(grad) = diagmat(w) * (M_res * Omega + A - Y); + // grad_logS2 = ½ w ⊙ (S²⊙(Ω_diag + A) − 1) metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % Omega_diag.t() + S2 % A - 1.); objective_vec.push_back(objective); return objective; diff --git a/src/nlopt_full_cov.cpp b/src/nlopt_full_cov.cpp index 8edf5c66..848656ac 100644 --- a/src/nlopt_full_cov.cpp +++ b/src/nlopt_full_cov.cpp @@ -8,131 +8,21 @@ #include "utils.h" // --------------------------------------------------------------------------------------- -// Full covariance PLN — nlopt/CCSAQ optimizer (archived: B in parameter vector) - -Rcpp::List nlopt_optimize_full_old( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(B, M, S) - const Rcpp::List & config // List of config values +// Shared inner computation: full-covariance NLOPT objective and gradients. +// Z = O + X*B + M_res must be computed by the caller (varies between E-step and vestep). +static double full_cov_obj_grad_impl( + const arma::mat & M_res, const arma::mat & Z, const arma::mat & logS2, + const arma::mat & Omega, const arma::vec & Omega_diag, + const arma::mat & Y, const arma::vec & w, + arma::mat & grad_M, arma::mat & grad_S ) { - // Conversion from R, prepare optimization - const arma::mat & Y = Rcpp::as(data["Y"]); // responses (n,p) - const arma::mat & X = Rcpp::as(data["X"]); // covariates (n,d) - const arma::mat & O = Rcpp::as(data["O"]); // offsets (n,p) - const arma::vec & w = Rcpp::as(data["w"]); // weights (n) - const auto init_B = Rcpp::as(params["B"]); // (d,p) - const auto init_M = Rcpp::as(params["M"]); // (n,p) - const auto init_S = Rcpp::as(params["S"]); // (n,p) - - const auto metadata = tuple_metadata(init_B, init_M, init_S); - enum { B_ID, M_ID, S_ID }; // Names for metadata indexes - - auto parameters = std::vector(metadata.packed_size); - metadata.map(parameters.data()) = init_B; - metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = arma::log(init_S % init_S); // pack logS2 - - const double w_bar = accu(w); - // VEM config — sensible defaults if not supplied by R - const int max_em_iter = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; - const double em_ftol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; - - // Initial Omega: closed-form from initial M, S (one inv_sympd, outside the loop) - arma::mat Omega; - { - const arma::mat S2_init = init_S % init_S; - arma::mat Sigma_init = (1. / w_bar) * (init_M.t() * (init_M.each_col() % w) + diagmat(w.t() * S2_init)); - Omega = inv_sympd(Sigma_init); - } - - std::vector objective_vec; - double elbo_prev = -arma::datum::inf; - int total_iterations = 0; - int last_status = 0; - const arma::mat Xw = X.each_col() % w; // fixed: precomputed once for all EM iterations - - for (int em_iter = 0; em_iter < std::max(1, max_em_iter); em_iter++) { - // E-step: optimize B, M, S with Omega fixed — no inv_sympd inside gradient - auto optimizer = new_nlopt_optimizer(config, parameters.size()); - objective_vec.reserve(objective_vec.size() + nlopt_get_maxeval(optimizer.get())); - const arma::vec Omega_diag = diagvec(Omega); // fixed per EM iteration - - auto objective_and_grad = [&metadata, &Y, &X, &Xw, &O, &w, &Omega, &Omega_diag, &objective_vec](const double * params, double * grad) -> double { - const arma::mat B = metadata.map(params); - const arma::mat M = metadata.map(params); - const arma::mat logS2 = metadata.map(params); // logS2 = log(S²) - arma::mat S2 = arma::exp(logS2); - arma::mat Z = O + X * B + M; - arma::mat A = exp(Z + 0.5 * S2); - arma::mat MO = M * Omega; // cached: reused in objective and M-gradient - const arma::rowvec wS2 = w.t() * S2; - - // -½ log(S²) → -½ logS2 (no log call needed) - double objective = accu(w.t() * (A - Y % Z - 0.5 * logS2)) - + 0.5 * (accu(MO % (M.each_col() % w)) + dot(Omega_diag, wS2.t())); - - metadata.map(grad) = Xw.t() * (A - Y); - metadata.map(grad) = diagmat(w) * (MO + A - Y); - // grad_logS2 = ½ w ⊙ (S²⊙(Ω_diag + A) − 1) - metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % Omega_diag.t() + S2 % A - 1.); - - objective_vec.push_back(objective); - return objective; - }; - - OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); - total_iterations += result.nb_iterations; - last_status = static_cast(result.status); - - // M-step: update Omega analytically (one inv_sympd per EM iteration) - arma::mat M = metadata.copy(parameters.data()); - arma::mat logS2 = metadata.copy(parameters.data()); - arma::mat S2 = arma::exp(logS2); - arma::mat Sigma = (1. / w_bar) * (M.t() * (M.each_col() % w) + diagmat(w.t() * S2)); - Omega = inv_sympd(Sigma); - - // ELBO after M-step: trace(Omega*nSigma) = w_bar*p, log_det(Omega) = -log_det(Sigma) - arma::mat B = metadata.copy(parameters.data()); - arma::mat Z = O + X * B + M; - arma::mat A = exp(Z + 0.5 * S2); - double elbo = accu(w.t() * (Y % Z - A + 0.5 * logS2)) - - 0.5 * w_bar * real(log_det(Sigma)); - - if (em_iter > 0 && converged(elbo, elbo_prev, em_ftol)) break; - elbo_prev = elbo; - } - - // Final extraction - arma::mat M = metadata.copy(parameters.data()); - arma::mat logS2 = metadata.copy(parameters.data()); - arma::mat S2 = arma::exp(logS2); - arma::mat S = arma::exp(0.5 * logS2); - arma::mat B = metadata.copy(parameters.data()); - arma::mat Sigma = (1. / w_bar) * (M.t() * (M.each_col() % w) + diagmat(w.t() * S2)); - // Omega already updated from the last M-step - arma::mat Z = O + X * B + M; - arma::mat A = exp(Z + 0.5 * S2); - arma::vec loglik = sum(Y % Z - A + 0.5 * logS2 - 0.5 * ((M * Omega) % M + S2 * diagmat(Omega)), 1) + - 0.5 * real(log_det(Omega)) + ki(Y); - - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("B", B), - Rcpp::Named("M", M), - Rcpp::Named("S", S), - Rcpp::Named("Z", Z), - Rcpp::Named("A", A), - Rcpp::Named("Sigma", Sigma), - Rcpp::Named("Omega", Omega), - Rcpp::Named("Ji", Ji), - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", last_status), - Rcpp::Named("backend", "nlopt"), - Rcpp::Named("objective", objective_vec), - Rcpp::Named("iterations", total_iterations) - )) - ); + const arma::mat S2 = arma::exp(logS2); + const arma::mat A = arma::exp(Z + 0.5 * S2); + const arma::mat MO = M_res * Omega; + grad_M = arma::diagmat(w) * (MO + A - Y); + grad_S = 0.5 * arma::diagmat(w) * (S2.each_row() % Omega_diag.t() + S2 % A - 1.); + return accu(w.t() * (A - Y % Z - 0.5 * logS2)) + + 0.5 * (accu(MO % (M_res.each_col() % w)) + dot(Omega_diag, (w.t() * S2).t())); } // --------------------------------------------------------------------------------------- @@ -186,23 +76,18 @@ Rcpp::List nlopt_optimize_full( objective_vec.reserve(objective_vec.size() + nlopt_get_maxeval(optimizer.get())); const arma::vec Omega_diag = diagvec(Omega); + // E-step: M_full is the NLOPT parameter; B profiled at each eval (envelope theorem) auto objective_and_grad = [&](const double * par, double * grad) -> double { const arma::mat M_full = metadata.map(par); const arma::mat logS2 = metadata.map(par); - arma::mat S2 = arma::exp(logS2); - arma::mat B = P_X * M_full; - arma::mat M_res = M_full - X * B; - arma::mat Z = O + M_full; - arma::mat A = exp(Z + 0.5 * S2); - arma::mat MO = M_res * Omega; - const arma::rowvec wS2 = w.t() * S2; - double objective = accu(w.t() * (A - Y % Z - 0.5 * logS2)) - + 0.5 * (accu(MO % (M_res.each_col() % w)) + dot(Omega_diag, wS2.t())); - // gradient for M_full = gradient for M_res (envelope theorem for B) - metadata.map(grad) = diagmat(w) * (MO + A - Y); - metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % Omega_diag.t() + S2 % A - 1.); - objective_vec.push_back(objective); - return objective; + const arma::mat B = P_X * M_full; + const arma::mat M_res = M_full - X * B; + arma::mat gM, gS; + const double obj = full_cov_obj_grad_impl(M_res, O + M_full, logS2, Omega, Omega_diag, Y, w, gM, gS); + metadata.map(grad) = gM; + metadata.map(grad) = gS; + objective_vec.push_back(obj); + return obj; }; OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); @@ -288,27 +173,19 @@ Rcpp::List nlopt_optimize_vestep_full( std::vector objective_vec ; objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); - const arma::mat XB_vestep = X * B; - const arma::vec Omega_diag_v = diagvec(Omega); + const arma::mat OXB = O + X * B; // fixed offset: O + XB, precomputed once + const arma::vec Omega_diag = diagvec(Omega); - auto objective_and_grad = [&metadata, &O, &XB_vestep, &Y, &w, &Omega, &Omega_diag_v, &objective_vec](const double * params, double * grad) -> double { + // Vestep: M_res is the NLOPT parameter; B and Omega fixed by the caller + auto objective_and_grad = [&](const double * params, double * grad) -> double { const arma::mat M = metadata.map(params); const arma::mat logS2 = metadata.map(params); - - arma::mat S2 = arma::exp(logS2); - arma::mat Z = O + XB_vestep + M; - arma::mat A = exp(Z + 0.5 * S2); - arma::mat MO = M * Omega; - const arma::rowvec wS2 = w.t() * S2; - double objective = accu(w.t() * (A - Y % Z - 0.5 * logS2)) - + 0.5 * (accu(MO % (M.each_col() % w)) + dot(Omega_diag_v, wS2.t())); - - metadata.map(grad) = diagmat(w) * (MO + A - Y); - metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % Omega_diag_v.t() + S2 % A - 1.); - - objective_vec.push_back(objective) ; - - return objective; + arma::mat gM, gS; + const double obj = full_cov_obj_grad_impl(M, OXB + M, logS2, Omega, Omega_diag, Y, w, gM, gS); + metadata.map(grad) = gM; + metadata.map(grad) = gS; + objective_vec.push_back(obj); + return obj; }; OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); @@ -318,7 +195,7 @@ Rcpp::List nlopt_optimize_vestep_full( arma::mat S2 = arma::exp(logS2); arma::mat S = arma::exp(0.5 * logS2); // Element-wise log-likelihood - arma::mat Z = O + X * B + M; + arma::mat Z = OXB + M; arma::mat A = exp(Z + 0.5 * S2); arma::vec loglik = sum(Y % Z - A + 0.5 * logS2 - 0.5 * ((M * Omega) % M + S2 * diagmat(Omega)), 1) + 0.5 * real(log_det(Omega)) + ki(Y); diff --git a/src/nlopt_spherical.cpp b/src/nlopt_spherical.cpp index 26dafba9..60446927 100644 --- a/src/nlopt_spherical.cpp +++ b/src/nlopt_spherical.cpp @@ -8,97 +8,21 @@ #include "utils.h" // --------------------------------------------------------------------------------------- -// Spherical covariance PLN — nlopt/CCSAQ optimizer (archived: B in parameter vector) - -Rcpp::List nlopt_optimize_spherical_old( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(B, M, S) - const Rcpp::List & config // List of config values +// Shared inner computation for spherical-covariance NLOPT objective and gradients. +// Z = O + X*B + M_res and S2 = exp(logS2) must be pre-computed by the caller. +// inv_sigma2: scalar precision (profiled 1/sigma2 or fixed omega2 = Omega(0,0)). +// penalty: KL variance term (log for profiled E-step; quadratic for fixed-omega vestep). +static double spherical_cov_obj_grad_impl( + const arma::mat & M_res, const arma::mat & Z, + const arma::mat & S2, const arma::mat & logS2, + double inv_sigma2, double penalty, + const arma::mat & Y, const arma::vec & w, + arma::mat & grad_M, arma::mat & grad_S ) { - // Conversion from R, prepare optimization - const arma::mat & Y = Rcpp::as(data["Y"]); // responses (n,p) - const arma::mat & X = Rcpp::as(data["X"]); // covariates (n,d) - const arma::mat & O = Rcpp::as(data["O"]); // offsets (n,p) - const arma::vec & w = Rcpp::as(data["w"]); // weights (n) - const auto init_B = Rcpp::as(params["B"]); // (d,p) - const auto init_M = Rcpp::as(params["M"]); // (n,p) - const auto init_S = Rcpp::as(params["S"]); // (n,p) - - const auto metadata = tuple_metadata(init_B, init_M, init_S); - enum { B_ID, M_ID, S_ID }; // Names for metadata indexes - - auto parameters = std::vector(metadata.packed_size); - metadata.map(parameters.data()) = init_B; - metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = arma::log(init_S % init_S); // pack logS2 - - // Optimize - auto optimizer = new_nlopt_optimizer(config, parameters.size()); - const double w_bar = accu(w); - std::vector objective_vec ; - objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); - - const arma::mat Xw = X.each_col() % w; // fixed: precomputed once - - auto objective_and_grad = [&metadata, &O, &X, &Xw, &Y, &w, &w_bar, &objective_vec](const double * params, double * grad) -> double { - const arma::mat B = metadata.map(params); - const arma::mat M = metadata.map(params); - const arma::mat logS2 = metadata.map(params); - - arma::mat S2 = arma::exp(logS2); - const arma::uword p = Y.n_cols; - arma::mat Z = O + X * B + M; - arma::mat A = exp(Z + 0.5 * S2); - double sigma2 = accu(diagmat(w) * (pow(M, 2) + S2)) / (double(p) * w_bar) ; - // -½ log(S²) → -½ logS2 - double objective = accu(w.t() * (A - Y % Z - 0.5 * logS2)) + 0.5 * (double(p) * w_bar) * log(sigma2) ; - - metadata.map(grad) = Xw.t() * (A - Y); - metadata.map(grad) = diagmat(w) * (M / sigma2 + A - Y); - // grad_logS2 = ½ w ⊙ (S²/σ² + S²⊙A − 1) - metadata.map(grad) = 0.5 * diagmat(w) * (S2 / sigma2 + S2 % A - 1.); - - objective_vec.push_back(objective) ; - - return objective; - }; - OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); - - // Variational parameters - arma::mat M = metadata.copy(parameters.data()); - arma::mat logS2 = metadata.copy(parameters.data()); - arma::mat S2 = arma::exp(logS2); - arma::mat S = arma::exp(0.5 * logS2); - // Regression parameters - arma::mat B = metadata.copy(parameters.data()); - // Variance parameters - const arma::uword p = Y.n_cols; - const double sigma2 = accu(diagmat(w) * (pow(M, 2) + S2)) / (double(p) * w_bar) ; - arma::sp_mat Sigma(p,p); Sigma.diag() = arma::ones(p) * sigma2; - arma::sp_mat Omega(p,p); Omega.diag() = arma::ones(p) * pow(sigma2, -1); - // Element-wise log-likelihood [log(S²/σ²) = logS2 - log(σ²)] - arma::mat Z = O + X * B + M; - arma::mat A = exp(Z + 0.5 * S2); - arma::mat loglik = sum(Y % Z - A - 0.5 * (pow(M, 2) + S2) / sigma2 + 0.5 * (logS2 - log(sigma2)), 1) + ki(Y); - - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("B", B), - Rcpp::Named("Sigma", Sigma), - Rcpp::Named("Omega", Omega), - Rcpp::Named("M", M), - Rcpp::Named("S", S), - Rcpp::Named("Z", Z), - Rcpp::Named("A", A), - Rcpp::Named("Ji", Ji), - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", static_cast(result.status)), - Rcpp::Named("backend", "nlopt"), - Rcpp::Named("objective", objective_vec), - Rcpp::Named("iterations", result.nb_iterations) - )) - ); + const arma::mat A = arma::exp(Z + 0.5 * S2); + grad_M = arma::diagmat(w) * (M_res * inv_sigma2 + A - Y); + grad_S = 0.5 * arma::diagmat(w) * (S2 * inv_sigma2 + S2 % A - 1.); + return accu(w.t() * (A - Y % Z - 0.5 * logS2)) + penalty; } // --------------------------------------------------------------------------------------- @@ -134,21 +58,22 @@ Rcpp::List nlopt_optimize_spherical( const arma::mat Xw = X.each_col() % w; const arma::mat P_X = arma::solve(X.t() * Xw, Xw.t()); + // E-step: M_full is the NLOPT parameter; B and sigma2 profiled at each eval auto objective_and_grad = [&](const double * par, double * grad) -> double { const arma::mat M_full = metadata.map(par); const arma::mat logS2 = metadata.map(par); - arma::mat S2 = arma::exp(logS2); - arma::mat B = P_X * M_full; - arma::mat M_res = M_full - X * B; - arma::mat Z = O + M_full; - arma::mat A = exp(Z + 0.5 * S2); - double sigma2 = accu(diagmat(w) * (pow(M_res, 2) + S2)) / (double(p) * w_bar); - double objective = accu(w.t() * (A - Y % Z - 0.5 * logS2)) + 0.5 * double(p) * w_bar * log(sigma2); - // gradient for M_full = gradient for M_res (envelope theorem for B and sigma2) - metadata.map(grad) = diagmat(w) * (M_res / sigma2 + A - Y); - metadata.map(grad) = 0.5 * diagmat(w) * (S2 / sigma2 + S2 % A - 1.); - objective_vec.push_back(objective); - return objective; + const arma::mat S2 = arma::exp(logS2); + const arma::mat B = P_X * M_full; + const arma::mat M_res = M_full - X * B; + const double sigma2 = accu(arma::diagmat(w) * (arma::pow(M_res, 2) + S2)) / (double(p) * w_bar); + arma::mat gM, gS; + const double obj = spherical_cov_obj_grad_impl(M_res, O + M_full, S2, logS2, + 1./sigma2, 0.5 * double(p) * w_bar * std::log(sigma2), + Y, w, gM, gS); + metadata.map(grad) = gM; + metadata.map(grad) = gS; + objective_vec.push_back(obj); + return obj; }; OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); @@ -216,27 +141,22 @@ Rcpp::List nlopt_optimize_vestep_spherical( std::vector objective_vec ; objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); - const arma::mat XB_sph = X * B; // fixed: B not optimized in vestep + const arma::mat OXB = O + X * B; // fixed offset, precomputed once + const double omega2 = Omega(0, 0); // fixed precision = 1/sigma2 - auto objective_and_grad = [&metadata, &O, &XB_sph, &Y, &w, &Omega, &objective_vec](const double * params, double * grad) -> double { + // Vestep: M_res is the NLOPT parameter; B and Omega fixed by the caller + auto objective_and_grad = [&](const double * params, double * grad) -> double { const arma::mat M = metadata.map(params); const arma::mat logS2 = metadata.map(params); - - arma::mat S2 = arma::exp(logS2); - arma::mat Z = O + XB_sph + M; - arma::mat A = exp(Z + 0.5 * S2); - double n_sigma2 = accu(diagmat(w) * (pow(M, 2) + S2)) ; - double omega2 = Omega(0, 0); - // -½ log(S²) → -½ logS2 - double objective = accu(w.t() * (A - Y % Z - 0.5 * logS2)) + 0.5 * n_sigma2 * omega2; - - metadata.map(grad) = diagmat(w) * (M / omega2 + A - Y); - // grad_logS2 = ½ w ⊙ (S²/ω² + S²⊙A − 1) - metadata.map(grad) = 0.5 * diagmat(w) * (S2 / omega2 + S2 % A - 1.); - - objective_vec.push_back(objective) ; - - return objective; + const arma::mat S2 = arma::exp(logS2); + const double penalty = 0.5 * omega2 * accu(arma::diagmat(w) * (arma::pow(M, 2) + S2)); + arma::mat gM, gS; + const double obj = spherical_cov_obj_grad_impl(M, OXB + M, S2, logS2, + omega2, penalty, Y, w, gM, gS); + metadata.map(grad) = gM; + metadata.map(grad) = gS; + objective_vec.push_back(obj); + return obj; }; OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); @@ -245,9 +165,8 @@ Rcpp::List nlopt_optimize_vestep_spherical( arma::mat logS2 = metadata.copy(parameters.data()); arma::mat S2 = arma::exp(logS2); arma::mat S = arma::exp(0.5 * logS2); - double omega2 = Omega(0, 0); // Element-wise log-likelihood [log(S²·ω²) = logS2 + log(ω²)] - arma::mat Z = O + X * B + M; + arma::mat Z = OXB + M; arma::mat A = exp(Z + 0.5 * S2); arma::mat loglik = sum(Y % Z - A - 0.5 * (pow(M, 2) + S2) * omega2 + 0.5 * (logS2 + log(omega2)), 1) + ki(Y); From 0fdfb0d18c7dc545bef448bc0a9e0df6847ef331 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Wed, 10 Jun 2026 10:33:04 +0200 Subject: [PATCH 23/58] reparing some tests that failed after factorisation --- R/PLN.R | 2 +- R/PLNLDA.R | 11 ++++++----- R/PLNLDAfit-class.R | 24 ++++++++++++++++++++---- R/PLNmixture.R | 12 ++++++------ R/PLNnetwork.R | 11 ++++++----- R/utils.R | 2 +- inst/case_studies/oaks_tree.R | 8 ++++---- src/newton_impl_alt.h | 3 ++- tests/testthat/test-pln.R | 4 ++-- tests/testthat/test-plnfit.R | 4 ++-- 10 files changed, 50 insertions(+), 31 deletions(-) diff --git a/R/PLN.R b/R/PLN.R index 39e81e3f..71d2a1cf 100644 --- a/R/PLN.R +++ b/R/PLN.R @@ -101,7 +101,7 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { #' #' @export PLN_param <- function( - backend = c("nlopt", "homemade", "hybrid", "torch"), + backend = c("homemade", "nlopt", "hybrid", "torch"), trace = 1, covariance = c("full", "diagonal", "spherical", "fixed"), Omega = NULL, diff --git a/R/PLNLDA.R b/R/PLNLDA.R index 80549d8c..52f258aa 100644 --- a/R/PLNLDA.R +++ b/R/PLNLDA.R @@ -45,7 +45,7 @@ PLNLDA <- function(formula, data, subset, weights, grouping, control = PLN_param } grouping <- as.factor(grouping) - # force the intercept term if excluded (prevent interferences with group means when coding discrete variables) + # force the intercept term if excluded (prevent interference with group means when coding discrete variables) the_call <- match.call(expand.dots = FALSE) the_call$formula <- update.formula(formula(the_call), ~ . +1) @@ -87,7 +87,7 @@ PLNLDA <- function(formula, data, subset, weights, grouping, control = PLN_param #' @inherit PLN_param details #' @export PLNLDA_param <- function( - backend = c("nlopt", "torch"), + backend = c("homemade", "nlopt", "hybrid", "torch"), trace = 1, covariance = c("full", "diagonal", "spherical"), config_post = list(), @@ -104,14 +104,15 @@ PLNLDA_param <- function( config_pst$trace <- trace ## optimization config - stopifnot(backend %in% c("nlopt", "torch")) + backend <- match.arg(backend) if (backend == "nlopt") { stopifnot(config_optim$algorithm %in% available_algorithms_nlopt) config_opt <- config_default_nlopt - } - if (backend == "torch") { + } else if (backend == "torch") { stopifnot(config_optim$algorithm %in% available_algorithms_torch) config_opt <- config_default_torch + } else { # "homemade" or "hybrid" + config_opt <- config_default_homemade } config_opt[names(config_optim)] <- config_optim config_opt$trace <- trace diff --git a/R/PLNLDAfit-class.R b/R/PLNLDAfit-class.R index 9649f9b6..650adb3d 100644 --- a/R/PLNLDAfit-class.R +++ b/R/PLNLDAfit-class.R @@ -406,8 +406,16 @@ PLNLDAfit_diagonal <- R6Class( #' @description Initialize a [`PLNfit`] model initialize = function(grouping, responses, covariates, offsets, weights, formula, control) { super$initialize(grouping, responses, covariates, offsets, weights, formula, control) - private$optimizer$main <- ifelse(control$backend == "nlopt", nlopt_optimize_diagonal, private$torch_optimize) - private$optimizer$vestep <- nlopt_optimize_vestep_diagonal + private$optimizer$main <- if (control$backend == "torch") { + private$torch_optimize + } else if (control$backend == "homemade") { + newton_optimize_diagonal + } else if (control$backend == "hybrid") { + make_hybrid_optimizer(nlopt_optimize_diagonal, newton_optimize_diagonal) + } else { + nlopt_optimize_diagonal + } + private$optimizer$vestep <- if (control$backend %in% c("homemade", "hybrid")) newton_optimize_vestep_diagonal else nlopt_optimize_vestep_diagonal } ), private = list( @@ -496,8 +504,16 @@ PLNLDAfit_spherical <- R6Class( #' @description Initialize a [`PLNfit`] model initialize = function(grouping, responses, covariates, offsets, weights, formula, control) { super$initialize(grouping, responses, covariates, offsets, weights, formula, control) - private$optimizer$main <- ifelse(control$backend == "nlopt", nlopt_optimize_spherical, private$torch_optimize) - private$optimizer$vestep <- nlopt_optimize_vestep_spherical + private$optimizer$main <- if (control$backend == "torch") { + private$torch_optimize + } else if (control$backend == "homemade") { + newton_optimize_spherical + } else if (control$backend == "hybrid") { + make_hybrid_optimizer(nlopt_optimize_spherical, newton_optimize_spherical) + } else { + nlopt_optimize_spherical + } + private$optimizer$vestep <- if (control$backend %in% c("homemade", "hybrid")) newton_optimize_vestep_spherical else nlopt_optimize_vestep_spherical } ), private = list( diff --git a/R/PLNmixture.R b/R/PLNmixture.R index aebc68f6..04b86a9c 100644 --- a/R/PLNmixture.R +++ b/R/PLNmixture.R @@ -69,7 +69,7 @@ PLNmixture <- function(formula, data, subset, clusters = 1:5, control = PLNmixt #' #' Helper to define list of parameters to control the PLNmixture fit. All arguments have defaults. #' -#' @param backend optimization back used, either "nlopt" or "torch". Default is "nlopt" +#' @param backend optimization back used, either "homemade", "nlopt", "hybrid" or "torch". Default is "homemade". #' @param covariance character setting the model for the covariance matrices of the mixture components. Either "full", "diagonal" or "spherical". Default is "spherical". #' @param smoothing The smoothing to apply. Either, 'none', forward', 'backward' or 'both'. Default is 'both'. #' @param init_cl The initial clustering to apply. Either, 'kmeans', CAH' or a user defined clustering given as a list of clusterings, the size of which is equal to the number of clusters considered. Default is 'kmeans'. @@ -89,7 +89,7 @@ PLNmixture <- function(formula, data, subset, clusters = 1:5, control = PLNmixt #' @seealso [PLN_param()] #' @export PLNmixture_param <- function( - backend = "nlopt" , + backend = c("homemade", "nlopt", "hybrid", "torch"), trace = 1 , covariance = "spherical", init_cl = "kmeans" , @@ -107,14 +107,14 @@ PLNmixture_param <- function( ## optimization config backend <- match.arg(backend) - stopifnot(backend %in% c("nlopt", "torch")) if (backend == "nlopt") { stopifnot(config_optim$algorithm %in% available_algorithms_nlopt) - config_opt <- config_default_nlopt_pln - } - if (backend == "torch") { + config_opt <- config_default_nlopt + } else if (backend == "torch") { stopifnot(config_optim$algorithm %in% available_algorithms_torch) config_opt <- config_default_torch + } else { # "homemade" or "hybrid" + config_opt <- config_default_homemade } config_opt$ftol_out <- 1e-3 config_opt$maxit_out <- 50 diff --git a/R/PLNnetwork.R b/R/PLNnetwork.R index 372357be..d44814f3 100644 --- a/R/PLNnetwork.R +++ b/R/PLNnetwork.R @@ -52,7 +52,8 @@ PLNnetwork <- function(formula, data, subset, weights, penalties = NULL, control #' #' Helper to define list of parameters to control the PLN fit. All arguments have defaults. #' -#' @param backend optimization back used, either "nlopt" or "torch". Default is "nlopt" +#' @param backend optimization back used, either "nlopt", "homemade", "hybrid" or "torch". Default is "nlopt". +#' Note: the "nlopt" backend converges better in PLNnetwork's outer glasso alternation than "homemade". #' @param inception_cov Covariance structure used for the inception model used to initialize the PLNfamily. Defaults to "full" and can be constrained to "diagonal" and "spherical". #' @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-treatment (optional bootstrap, jackknife, R2, etc). @@ -74,7 +75,7 @@ PLNnetwork <- function(formula, data, subset, weights, penalties = NULL, control #' @seealso [PLN_param()] #' @export PLNnetwork_param <- function( - backend = c("nlopt", "torch"), + backend = c("nlopt", "homemade", "hybrid", "torch"), inception_cov = c("full", "spherical", "diagonal"), trace = 1 , n_penalties = 30 , @@ -95,14 +96,14 @@ PLNnetwork_param <- function( ## optimization config backend <- match.arg(backend) - stopifnot(backend %in% c("nlopt", "torch")) if (backend == "nlopt") { stopifnot(config_optim$algorithm %in% available_algorithms_nlopt) config_opt <- config_default_nlopt - } - if (backend == "torch") { + } else if (backend == "torch") { stopifnot(config_optim$algorithm %in% available_algorithms_torch) config_opt <- config_default_torch + } else { # "homemade" or "hybrid" + config_opt <- config_default_homemade } inception_cov <- match.arg(inception_cov) config_opt$trace <- trace diff --git a/R/utils.R b/R/utils.R index f52dce0a..d6adccac 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,4 +1,4 @@ -available_algorithms_nlopt <- c("MMA", "CCSAQ", "LBFGS", "VAR1", "VAR2") +available_algorithms_nlopt <- c("CCSAQ", "MMA", "LBFGS", "VAR1", "VAR2") available_algorithms_torch <- c("RPROP", "RMSPROP", "ADAM", "ADAGRAD") config_default_nlopt <- diff --git a/inst/case_studies/oaks_tree.R b/inst/case_studies/oaks_tree.R index e77f866d..5dc093bc 100644 --- a/inst/case_studies/oaks_tree.R +++ b/inst/case_studies/oaks_tree.R @@ -2,9 +2,9 @@ library(PLNmodels) library(factoextra) ## setting up future for parallelism -nb_cores <- 10 -options(future.fork.enable = TRUE) -future::plan("multicore", workers = nb_cores) +# nb_cores <- 10 +# options(future.fork.enable = TRUE) +# future::plan("multicore", workers = nb_cores) ## get oaks data set data(oaks) @@ -140,4 +140,4 @@ p <- myPLN$plot_clustering_data() aricode::ARI(myPLN$memberships, oaks$tree) -future::plan("sequential") +# future::plan("sequential") diff --git a/src/newton_impl_alt.h b/src/newton_impl_alt.h index 1481c0bb..4cc0bd35 100644 --- a/src/newton_impl_alt.h +++ b/src/newton_impl_alt.h @@ -33,7 +33,8 @@ Rcpp::List newton_optimize_alt_impl( // Precompute X'WX and P_X once: P_X = (X'WX)^{-1}X'W (d×n) for live B = P_X * M_full const arma::mat Xw = X.each_col() % w; // n×d const arma::mat XtWX = X.t() * Xw; // d×d, symmetric PD - const arma::mat P_X = arma::solve(XtWX, Xw.t()); // d×n, precomputed once + // When d=0 (no covariates), X'WX is 0×0: skip solve to avoid spurious singularity warning + const arma::mat P_X = (X.n_cols > 0) ? arma::solve(XtWX, Xw.t()) : arma::mat(0, n); // Convert input M from residual format to M_full = XB + M_res M = X * B + M; diff --git a/tests/testthat/test-pln.R b/tests/testthat/test-pln.R index a4afbe2a..d83c9e2e 100644 --- a/tests/testthat/test-pln.R +++ b/tests/testthat/test-pln.R @@ -58,7 +58,7 @@ test_that("PLN: Check consistency of observation weights - fully parameterized c ## equivalent weigths expect_output(model2 <- PLN(Abundance ~ 1, data = trichoptera, weights = rep(1.0, nrow(trichoptera))), paste("\n Initialization...", - "Adjusting a full covariance PLN model with nlopt optimizer", + "Adjusting a full covariance PLN model with homemade optimizer", "Post-treatments...", "DONE!", sep = "\n "), fixed = TRUE) @@ -125,7 +125,7 @@ test_that("PLN is working with unnamed data matrix", { expect_equal(MMA$loglik, CCSAQ$loglik, tolerance = 1e-1) ## Almost equivalent, CCSAQ faster expect_equal(MMA$loglik, LBFGS$loglik, tolerance = 1e-1) - expect_error(PLN(Abundance ~ 1, data = trichoptera, control = PLN_param(config_optim = list(algorithm = "nawak")))) + expect_error(PLN(Abundance ~ 1, data = trichoptera, control = PLN_param(backend = "nlopt", config_optim = list(algorithm = "nawak")))) }) test_that("PLN: Check that univariate PLN models works, with matrix of numeric format", { diff --git a/tests/testthat/test-plnfit.R b/tests/testthat/test-plnfit.R index b646f608..b4be97ca 100644 --- a/tests/testthat/test-plnfit.R +++ b/tests/testthat/test-plnfit.R @@ -9,7 +9,7 @@ test_that("PLN fit: check classes, getters and field access", { control = PLN_param(trace = 1)), " Initialization... - Adjusting a full covariance PLN model with nlopt optimizer + Adjusting a full covariance PLN model with homemade optimizer Post-treatments... DONE!" ) @@ -18,7 +18,7 @@ test_that("PLN fit: check classes, getters and field access", { control = PLN_param(trace = 1, inception = model)), " Initialization... - Adjusting a full covariance PLN model with nlopt optimizer + Adjusting a full covariance PLN model with homemade optimizer Post-treatments... DONE!" ) From 325bdef7f015216d44d265d8663ee3536d5225d8 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Wed, 10 Jun 2026 10:46:10 +0200 Subject: [PATCH 24/58] cleaning doc and dead code --- DEVLOG_2026-06-08-09.md | 316 ++++++++++++++++++++++++++++++ NAMESPACE | 1 - R/PLN.R | 7 +- R/PLNfit-class.R | 104 ---------- R/PLNnetwork.R | 1 - R/plot_utils.R | 47 +---- R/utils.R | 32 +-- man/PLNLDA_param.Rd | 2 +- man/PLNPCA_param.Rd | 15 +- man/PLNPCAfit.Rd | 23 +++ man/PLN_param.Rd | 6 +- man/PLNmixture_param.Rd | 4 +- man/PLNnetwork_param.Rd | 5 +- man/ZIPLN_param.Rd | 4 +- man/ZIPLNnetwork_param.Rd | 3 +- man/compute_PLN_starting_point.Rd | 2 +- src/nlopt_wrapper.cpp | 36 ---- src/nlopt_wrapper.h | 10 - 18 files changed, 372 insertions(+), 246 deletions(-) create mode 100644 DEVLOG_2026-06-08-09.md diff --git a/DEVLOG_2026-06-08-09.md b/DEVLOG_2026-06-08-09.md new file mode 100644 index 00000000..fbce29c8 --- /dev/null +++ b/DEVLOG_2026-06-08-09.md @@ -0,0 +1,316 @@ +# Journal de développement — 8-9 juin 2026 + +Branche : `code-enhancement` + +## Contexte + +Refonte complète des optimiseurs pour le modèle PLN (Poisson Log-Normal, variational EM) et ses variantes de covariance (full, diagonal, sphérique, fixed). L'objectif est d'améliorer la qualité des optima trouvés et la vitesse de convergence. + +--- + +## 1. Backend `homemade` — coordonnée-Newton maison (08/06) + +**Fichiers** : `src/newton_impl.h`, `src/CovarianceTraits.h`, `src/newton_*.cpp`, `R/PLNfit-class.R` + +### Ce qui a été fait + +Implémentation d'un optimiseur coordonnée-Newton template (`newton_optimize_impl`) remplaçant NLOPT comme backend principal pour les quatre variantes de covariance (full, diagonal, sphérique, fixed). + +**Architecture** : +- `CovarianceTraits.h` : traits template (`FullCovTraits`, `DiagonalCovTraits`, `SphericalCovTraits`, `FixedCovTraits`) encapsulant les spécificités de chaque covariance (gradient/hessien de M, mise à jour de Σ, ELBO). +- `newton_impl.h` : template générique de l'algorithme, instancié par covariance. +- Paramétrage `log(S²)` pour S (évite les contraintes de positivité, meilleur conditionnement). + +**Algorithme** (boucle EM externe + boucle interne Newton) : +- **Boucle interne** : step Newton diagonal pour M (avec Armijo), point fixe exact pour S² = `−1/(A + diag(Ω))`. +- **Boucle externe EM** : M-step analytique pour Σ (full/diag/sphérique) ; B mis à jour par Newton avec Hessien diagonal Poisson. +- **VE step** (`newton_vestep_impl`) : variante pour M et S seuls (B, Ω fixes), utilisée en validation croisée. + +**Ajout** : `backend = "homemade"` dans `PLN_param()`, compatible avec tous les appels existants. + +--- + +## 2. Backend spectral pour PLNPCA (09/06 matin) + +**Fichiers** : `src/spectral_rank_cov.cpp`, `src/newton_rank_cov.cpp` + +Implémentation d'un gradient spectral (méthode de Barzilai-Borwein avec acceptation GLL non-monotone) pour l'optimisation de PLNPCA (`homemade` backend). Compétitif avec NLOPT/CCSAQ, tolérance par défaut `1e-9` pour contrer les oscillations de l'acceptation non-monotone. + +--- + +## 3. Paramétrisations alternatives et backend `homemade_alt` (09/06 après-midi) + +**Fichiers** : `src/newton_impl_alt.h`, `src/newton_*_cov.cpp`, `R/PLNfit-class.R`, `R/PLN.R` + +### Motivation + +Dans la paramétrisation standard, M stocke le résidu `M_res = M_full − XB`, et B est mis à jour par Newton approché à chaque itération interne. La paramétrisation alternative stocke `M_full` et dispose d'une **forme close exacte pour B** dans le M-step : + +``` +B̂ = (X'WX)⁻¹ X'W M_full +``` + +### Ce qui a été fait + +Nouveau template `newton_optimize_alt_impl` dans `newton_impl_alt.h` : +- Boucle interne : M_full et S mis à jour (B gelé), gradient utilise `M_res = M_full − XB`. +- M-step : B par forme close, puis Σ/Ω analytique. +- Entrée/sortie en format résiduel (compatible avec le reste du package). +- Cas `fixed_cov` : itère (boucle interne + mise à jour B) jusqu'à convergence de l'ELBO. + +**Nouvelles fonctions exportées** : `newton_optimize_full_alt`, `newton_optimize_diagonal_alt`, `newton_optimize_spherical_alt`, `newton_optimize_fixed_alt`. + +**Ajout** : `backend = "homemade_alt"` dans `PLN_param()`. + +### Problème cold-start + +La variante `homemade_alt` seule souffre d'un problème de démarrage à froid pour les covariances full/diagonal : B est gelé pendant la boucle interne, puis fait un grand saut au M-step, désalignant M_full et XB_new. + +--- + +## 4. Backend `hybrid` (09/06 après-midi) + +**Fichiers** : `R/utils.R`, `R/PLNfit-class.R` + +### Solution au cold-start + +Fonction `make_hybrid_optimizer(opt1, opt2)` dans `utils.R` : chaîne deux optimiseurs. +- **Phase 1** (`homemade`, tolérance ×10) : converge rapidement vers le bon bassin. +- **Phase 2** (`homemade_alt`, tolérance cible) : raffine depuis ce bon point de départ. + +Correction importante : `params2 <- modifyList(params, list(B=..., M=..., S=...))` pour passer Omega à travers dans le cas `fixed_cov`. + +**Ajout** : `backend = "hybrid"` dans `PLN_param()`. + +### Résultats sur `oaks` (n=116, p=114) + +| Backend | ELBO full | Temps | ELBO diag | Temps | +|---|---|---|---|---| +| `homemade` | −32043 | 5.5s | −38411 | 4.1s | +| `homemade_alt` | froid | — | −38408 | 1.3s | +| **`hybrid`** | **−32033** | **3.0s** | **−38408** | **2.0s** | + +`hybrid` est universellement meilleur que `homemade` seul : +4 à +15 ELBO selon la config, 1.3–2.7× plus rapide. + +--- + +## 5. Paramétrisation alternative pour `fixed_cov` (09/06) + +Extension naturelle de `homemade_alt` / `hybrid` à `PLNfit_fixedcov` (Ω fourni en entrée, non estimé). La boucle externe itère (boucle interne + B forme close) jusqu'à convergence de l'ELBO partiel. Correction de `make_hybrid_optimizer` pour transmettre Ω via `modifyList`. + +--- + +## 6. Backend `nlopt` amélioré — B profilé analytiquement (09/06 soir) + +**Fichiers** : `src/nlopt_full_cov.cpp`, `src/nlopt_diag_cov.cpp`, `src/nlopt_spherical.cpp`, `src/nlopt_fixed_cov.cpp` + +### Idée + +Plutôt qu'inclure B dans le vecteur de paramètres NLOPT, on le profil analytiquement à chaque évaluation du gradient : + +```cpp +// Préconvergence une fois : P_X = solve(X'WX, X'W) [d×n] +// À chaque eval NLOPT : +B = P_X * M_full // forme close O(d·n·p) +M_res = M_full - X * B +// gradient pour M_full = gradient pour M_res (théorème de l'enveloppe) +``` + +Le vecteur de paramètres passe de `(B, M, S)` taille `n(d+2p)` à `(M_full, S)` taille `2np`. Le paysage de l'objectif est plus lisse (B toujours à son optimum conditionnel). + +**Implémentations** : +- `nlopt_optimize_full` : boucle EM conservée (inv_sympd coûteux), B profilé dans le E-step. +- `nlopt_optimize_diagonal` / `nlopt_optimize_spherical` : pas de boucle EM, B **et** σ² profilés à chaque eval. +- `nlopt_optimize_fixed` : pas de M-step Σ, B profilé à chaque eval. + +Les anciennes implémentations (B dans le vecteur NLOPT) sont archivées sous le suffixe `_old` dans le code C++, non exportées vers R. + +### Résultats sur `oaks` + +| Backend | ELBO full | ELBO diag | ELBO sphér. | Temps diag | +|---|---|---|---|---| +| `nlopt` (ancien) | −32183 | −38439 | −39456 | 2.9s | +| **`nlopt` (nouveau)** | **−32060** | **−38408** | **−39450** | **0.7s** | +| `hybrid` | −32033 | −38408 | −39450 | 2.0s–3.0s | + +Gains : +122 ELBO (full), +31 ELBO (diagonal), **4× plus rapide** (diagonal), **3× plus rapide** (sphérique et fixed). + +--- + +--- + +## 7. Corrections et factorisation des helpers nlopt (10/06) + +**Fichiers** : `src/nlopt_full_cov.cpp`, `src/nlopt_diag_cov.cpp`, `src/nlopt_spherical.cpp` + +### Factorisation du calcul objectif/gradient + +Les fonctions `nlopt_optimize_*` et `nlopt_optimize_vestep_*` partageaient un calcul objectif/gradient identique à un terme de pénalité et un Z près. On a factorisé ce code dans des helpers statiques : + +- `full_cov_obj_grad_impl(M_res, Z, logS2, Omega, ...)` : commun à E-step et vestep full. +- `diag_cov_obj_grad_impl(M_res, Z, S2, logS2, inv_sigma2, penalty, ...)` : commun diagonal. +- `spherical_cov_obj_grad_impl(M_res, Z, S2, logS2, inv_sigma2, penalty, ...)` : commun sphérique. + +Le `penalty` et le `Z` sont pré-calculés par l'appelant, qui seul connaît si on est en E-step profilé ou en vestep (B fixe). + +### Correction de bug : vestep sphérique + +**Bug pré-existant** dans `nlopt_optimize_vestep_spherical` : le gradient utilisait `M / omega2` au lieu de `M * omega2` (division par la précision = multiplication par la variance, direction opposée). La pénalité dans l'objectif (`omega2 * accu(...)`) était correcte, seul le gradient était faux. Corrigé en passant par le helper qui utilise `M_res * inv_sigma2 = M * omega2`. + +--- + +## 8. Piste explorée (abandonnée) : Hessienne complète pour le step Newton (10/06) + +**Question initiale** : `homemade_alt` avec B gelé converge vers des optima moins bons que `homemade` (écart de 120 unités ELBO sur `oaks`). Peut-on améliorer le step Newton en utilisant la Hessienne complète plutôt que la diagonale ? + +### Analyse théorique + +La Hessienne exacte par échantillon est (Eq. 19 du document `alter_param.pdf`) : + +``` +H_M_i = −w_i · (diag(A_i) + Ω) [p×p] +``` + +Pour les covariances diagonale et sphérique, Ω est diagonal : la Hessienne complète se réduit à la diagonale déjà utilisée — **aucun gain possible**. + +Pour la covariance full, les éléments hors-diagonale de Ω sont ignorés par l'approximation diagonale. Utiliser la Hessienne exacte nécessiterait un solve p×p par échantillon : coût O(np³) ≈ 170M flops par itération sur `oaks` (n=116, p=114), contre O(np) actuellement. + +**Estimation du rapport coût/bénéfice** (sur `oaks`) : +- Coût step exact : ~1000× plus cher par itération +- Gain en itérations : ~10× (Newton quadratique vs linéaire) +- Bilan : ~100× plus lent. **Non rentable.** + +### Mesures effectuées + +Comptage des itérations sur `oaks` (n=116, p=114) avec budget=50 EM × 50 inner : + +| Backend | Itérations internes | ELBO | +|---|---|---| +| `homemade_alt` | 657 (~13/EM step) | −31 522 | +| `homemade` | 3 136 (~63/EM step) | −31 402 | +| `hybrid` | 1 076 | −31 402 | + +La vrai cause du mauvais ELBO de `homemade_alt` n'est pas le step Newton mais le **B gelé** : l'optimum trouvé est sous-optimal parce que la boucle interne converge vite vers le meilleur M_full *pour le B courant*, puis B saute au M-step, désalignant tout. + +--- + +## 9. Théorème de l'enveloppe dans la boucle interne (10/06) + +**Fichier** : `src/newton_impl_alt.h` + +### Idée + +Dans `nlopt_optimize_full`, B est mis à jour à **chaque évaluation de gradient** : +```cpp +B = P_X * M_full // P_X = (X'WX)⁻¹X'W, précomputé +M_res = M_full − X * B +// gradient pour M_full ≡ gradient pour M_res (théorème de l'enveloppe) +``` + +Ce profil continu de B élimine le cold-start. On applique la même idée dans la boucle interne de `homemade_alt`. + +### Implémentation + +`P_X = solve(XtWX, Xw')` précomputée une fois. À chaque pas Newton : + +1. `B = P_X * M_full` — B mis à jour au début de l'itération +2. `XB = X * B` — gelé pendant la recherche de ligne (cohérent avec nlopt qui évalue le gradient une fois par pas quasi-Newton) +3. `M_res = M_full − XB` +4. Gradient/Hessien calculés sur `M_res` (formule inchangée par théorème de l'enveloppe) +5. Step Newton `step_M = grad_M / hess_M` + +### Première tentative : Armijo avec XB gelé + +Résultats initiaux sur `oaks` (budget=300) : ELBO = −32 029 (vs −32 031 pour `homemade`). Amélioration sur `oaks`. Mais sur `trichoptera` (d≈15, n=49) : ELBO = −897 vs −841 pour `homemade`. **Régression sévère sur les datasets avec beaucoup de covariables.** + +**Cause** : avec XB gelé, l'Armijo évalue l'objectif en `M_res − α·step_M` (le pas complet). Mais avec B live, le vrai `M_res` après le pas est `M_res − α·Q_step` où `Q_step = (I − X·P_X)·step_M`. Quand d/n est grand (trichoptera : d≈15, n=49), la composante X·P_X·step_M est importante : l'Armijo acceptait des pas bien trop larges, menant à une convergence oscillante et de mauvaise qualité. + +### Correction : pente projetée Q_step dans l'Armijo + +Le changement réel de `M_res` pour un pas `−α·step_M` sur M_full est : + +``` +ΔM_res = −α · Q_step = −α · (I − X·P_X) · step_M +``` + +On corrige l'Armijo pour évaluer l'objectif au bon point : + +```cpp +const arma::mat Q_step = step_M - X * (P_X * step_M); // changement réel de M_res +arma::mat QstepO = Traits::times_Omega(Q_step, state); // précomputé une fois +double slope_M = -arma::accu(grad_M % Q_step); // pente projetée correcte +// fallback si non-descente (cas dégénéré d/n grand) : +if (slope_M >= 0) slope_M = -arma::accu(grad_M % step_M); + +// Armijo loop : MresOt = MresO - α * QstepO (O(np), sans recalculer B) +// MresT = M_res - α * Q_step +``` + +### Résultats après correction (budget maxit=max_em=100) + +| Dataset | homemade (ancien) | homemade_alt corrigé | hybrid | +|---|---|---|---| +| oaks (d=1, n=116, p=114) | −32 034, 2 077 it | −32 030, 1 077 it | −32 029, 1 001 it | +| trichoptera (d≈15, n=49, p=17) | −844, 3 538 it | **−840**, 8 256 it | **−840**, 8 691 it | +| barents (d=5, n=89, p=30) | −4 379, 3 438 it | **−4 304**, 5 594 it | **−4 304**, 5 764 it | + +Avec la correction Q_step, `homemade_alt` est maintenant **équivalent ou supérieur** à l'ancien `homemade` sur tous les datasets. L'Armijo correct empêche les pas surdimensionnés : plus d'itérations par pas EM (82 vs 10 sur trichoptera), mais chaque itération est productive. + +--- + +## 10. Refactorisation finale : suppression de `homemade`, renommage (10/06) + +**Fichiers** : `src/newton_{full,diag,spherical,fixed}_cov.cpp`, `R/PLNfit-class.R`, `R/PLN.R`, `R/utils.R` + +### Décision + +Le benchmark sur trois datasets (oaks, trichoptera, barents) montre que `homemade_alt` corrigé **domine l'ancien `homemade`** en qualité ELBO et en nombre d'itérations, à budget égal : + +- meilleur ELBO sur barents et trichoptera +- equivalent ou légèrement meilleur sur oaks +- 2–4× moins d'itérations totales + +L'ancien `homemade` est supprimé. `homemade_alt` devient le nouveau `homemade`. + +### Changements C++ + +Les quatre fichiers `newton_*_cov.cpp` suppriment la fonction basée sur `newton_optimize_impl` et renomment `newton_optimize_*_alt` → `newton_optimize_*`. `newton_impl.h` est conservé (utilisé par `newton_vestep_impl` pour les vesteps). `RcppExports.{R,cpp}` régénérés par `Rcpp::compileAttributes()`. + +### Nouveau `hybrid` : nlopt → new homemade + +L'ancien `hybrid` chaînait `homemade → homemade_alt`, les deux ayant le même type de config. Le nouveau `hybrid` chaîne : + +- **Phase 1** : `nlopt_optimize_*` (CCSAQ, tolérance 10× relâchée) — exploration globale rapide +- **Phase 2** : `newton_optimize_*` (nouveau homemade, tolérance cible) — raffinement local Newton + +`make_hybrid_optimizer` construit explicitement un config nlopt pour la phase 1 (depuis `config_default_nlopt`), plutôt que de passer le config homemade. Cela évite l'erreur `algorithm="NEWTON" non reconnu par nlopt`. + +En pratique, `hybrid` et `homemade` convergent désormais au même ELBO (à ±0.1 unité) sur tous les datasets testés. `hybrid` reste utile comme filet de sécurité pour les paysages difficiles où le point d'initialisation importe. + +--- + +## Récapitulatif des backends disponibles + +| `backend` | Algorithme | Remarque | +|---|---|---| +| `"nlopt"` | CCSAQ/NLOPT, B profilé (enveloppe) | Défaut | +| `"homemade"` | Newton diagonal, B profilé (enveloppe), Armijo Q_step | Rapide, haute qualité | +| `"hybrid"` | nlopt (exploration) → homemade (raffinement) | Filet de sécurité | +| `"torch"` | RPROP/ADAM/... | GPU-compatible | + +--- + +## Fichiers créés ou significativement modifiés + +| Fichier | Nature | +|---|---| +| `src/CovarianceTraits.h` | Traits template pour les 4 covariances | +| `src/newton_impl.h` | Template coordonnée-Newton (vestep uniquement désormais) | +| `src/newton_impl_alt.h` | Template Newton diagonal avec B profilé (→ nouveau `homemade`) | +| `src/newton_{full,diag,spherical,fixed}_cov.cpp` | Instances + fonctions exportées (sans variantes `_alt`) | +| `src/nlopt_{full,diag,spherical,fixed}_cov.cpp` | B profilé + helpers statiques + bug fix vestep sphérique | +| `src/spectral_rank_cov.cpp` | Gradient spectral BB+GLL pour PLNPCA | +| `src/newton_rank_cov.cpp` | Coordonnée-Newton pour PLNPCA | +| `R/PLNfit-class.R` | Branchement backends dans les 4 classes PLNfit | +| `R/PLN.R` | `PLN_param()` — `homemade_alt` supprimé | +| `R/utils.R` | `make_hybrid_optimizer()` revu (phase 1 nlopt) | diff --git a/NAMESPACE b/NAMESPACE index b27ef1e0..252b77dc 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -107,7 +107,6 @@ importFrom(purrr,map_dbl) importFrom(purrr,map_int) importFrom(purrr,reduce) importFrom(rlang,.data) -importFrom(scales,alpha) importFrom(stats,.getXlevels) importFrom(stats,.lm.fit) importFrom(stats,as.formula) diff --git a/R/PLN.R b/R/PLN.R index 71d2a1cf..accb50a9 100644 --- a/R/PLN.R +++ b/R/PLN.R @@ -36,7 +36,6 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { "diagonal" = PLNfit_diagonal$new(args$Y, args$X, args$O, args$w, args$formula, control), "spherical" = PLNfit_spherical$new(args$Y, args$X, args$O, args$w, args$formula, control), "fixed" = PLNfit_fixedcov$new(args$Y, args$X, args$O, args$w, args$formula, control), - # "genet" = PLNfit_$new(args$Y, args$X, args$O, args$w, args$formula, control), PLNfit$new(args$Y, args$X, args$O, args$w, args$formula, control)) # default: full covariance ## optimization @@ -55,9 +54,9 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { #' #' Helper to define list of parameters to control the PLN fit. All arguments have defaults. #' -#' @param backend optimization back used, either "nlopt", "torch", or "homemade". Default is "nlopt". -#' Use "homemade" for the built-in coordinate-Newton optimizer (exact diagonal Newton steps), -#' which does not depend on NLOPT. +#' @param backend optimization back used, either "homemade" (default), "nlopt", "hybrid" or "torch". +#' "homemade" is the built-in envelope-theorem Newton optimizer (does not depend on NLOPT). +#' "hybrid" runs nlopt first for basin finding, then switches to homemade for refinement. #' @param covariance character setting the model for the covariance matrix. Either "full", "diagonal", "spherical" or "fixed". Default is "full". #' @param Omega precision matrix of the latent variables. Inverse of Sigma. Must be specified if `covariance` is "fixed" #' @param config_optim a list for controlling the optimizer (either "nlopt" or "torch" backend). See details diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index cb784d59..1210debe 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -1011,107 +1011,3 @@ PLNfit_fixedcov <- R6Class( ) ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -## CLASS PLNfit_genetprior ############################ -# ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# -# #' An R6 Class to represent a PLNfit in a standard, general framework, with residual covariance modelling -# #' motivatived by population genetics -# #' -# #' @inherit PLNfit -# #' @rdname PLNfit_genetprior -# #' @importFrom R6 R6Class -# #' -# #' @examples -# #' \dontrun{ -# #' data(trichoptera) -# #' trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) -# #' myPLN <- PLN(Abundance ~ 1, data = trichoptera) -# #' class(myPLN) -# #' print(myPLN) -# #' } -# PLNfit_genetprior <- R6Class( -# classname = "PLNfit_genetprior", -# inherit = PLNfit, -# ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# ## PUBLIC MEMBERS ---- -# ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# public = list( -# #' @description Call to the NLopt or TORCH optimizer and update of the relevant fields -# optimize = function(responses, covariates, offsets, weights, control) { -# args <- list(Y = responses, -# X = covariates, -# O = offsets, -# w = weights, -# params = list(B = private$B, M = private$M, S = private$S)) -# -# if (self$vcov_model == "genetic") { -# args$params$rho = 0.25 -# args$C <- control$corr_matrix -# } -# if (self$vcov_model == "fixed") { -# args$Omega <- private$Omega -# } -# -# if (control$backend == "nlopt") -# optim_out <- do.call(nlopt_optimizexxx, c(args, list(config = control$options_nlopt))) -# else { -# ## initialize torch with nlopt -# optim_out <- self$optimize_nlopt(c(args, list(config = control$options_nlopt))) -# args$params = list(B = optim_out$B, M = optim_out$M, S = optim_out$S) -# optim_out <- self$optimize_torch(c(args, list(config = control$options_torch))) -# } -# -# private$B <- optim_out$B -# private$M <- optim_out$M -# private$S <- optim_out$S -# private$Z <- optim_out$Z -# private$A <- optim_out$A -# private$monitoring <- list(iterations = optim_out$iterations, message = status_to_message(optim_out$status)) -# self$update_Sigma(args$w) -# self$update_loglik(args$w, args$Y) -# }, -# update_Sigma = function(weights) { -# w_bar <- sum(weights) -# private$Sigma <- switch(self$vcov_model, -# "spherical" = Matrix::Diagonal(self$p, sum(crossprod(weights, private$M^2 + private$S^2)) / (self$p * w_bar)), -# "diagonal" = Matrix::Diagonal(self$p, crossprod(weights, private$M^2 + private$S^2)/ w_bar), -# "full" = (crossprod(private$M, weights * private$M) + diag(as.numeric(crossprod(weights, private$S^2)))) / w_bar, -# "fixed" = solve(private$Omega) -# ) -# private$Omega <- switch(self$vcov_model, -# "fixed" = private$Omega, solve(private$Sigma) -# # "genetic = private$Omega, solve(private$Sigma) -# ) -# -# # if (self$vcov_model == "genetic") -# # private$psi <- list(sigma2 = optim_out$sigma2, rho = optim_out$rho) -# -# }, -# -# update_loglik = function(weights, Y) { -# KY <- .5 * self$p - rowSums(.logfactorial(Y)) -# S2 <- private$S**2 -# Ji <- as.numeric( -# .5 * determinant(private$Omega, logarithm = TRUE)$modulus + KY + -# rowSums(Y * private$Z - private$A + .5 * log(private$S^2) - -# .5 * ( (private$M %*% private$Omega) * private$M + sweep(private$S^2, 2, diag(private$Omega), '*'))) -# ) -# attr(Ji, "weights") <- weights -# private$Ji <- Ji -# }, -# ), -# active = list( -# #' @field nb_param number of parameters in the current PLN model -# nb_param = function() {as.integer(self$p * self$d + 2)}, -# #' @field vcov_model character: the model used for the residual covariance -# vcov_model = function() {"genetic"}, -# #' @field gen_par a list with two parameters, sigma2 and rho, only used with the genetic covariance model -# gen_par = function() {private$psi}, -# ), -# private = list( -# psi = NA, # parameters for genetic model of covariance -# ) -# ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# ## END OF THE CLASS PLNfit_genetprior -# ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -# ) diff --git a/R/PLNnetwork.R b/R/PLNnetwork.R index d44814f3..6e97ed9c 100644 --- a/R/PLNnetwork.R +++ b/R/PLNnetwork.R @@ -121,7 +121,6 @@ PLNnetwork_param <- function( penalty_weights = penalty_weights , jackknife = FALSE , bootstrap = 0 , - variance = TRUE , config_post = config_pst , config_optim = config_opt , inception = inception ), class = "PLNmodels_param") diff --git a/R/plot_utils.R b/R/plot_utils.R index f1aa1a0e..4b980291 100644 --- a/R/plot_utils.R +++ b/R/plot_utils.R @@ -82,55 +82,10 @@ circle <- function(center = c(0, 0), radius = 1, npoints = 100) { r = radius tt = seq(0, 2 * pi, length = npoints) xx = center[1] + r * cos(tt) - yy = center[1] + r * sin(tt) + yy = center[2] + r * sin(tt) return(data.frame(x = xx, y = yy)) } -#' @importFrom scales alpha -GeomCircle <- ggplot2::ggproto("GeomCircle", - ggplot2::Geom, - required_aes = c("x", "y", "radius"), - default_aes = ggplot2::aes( - colour = "grey30", fill=NA, alpha=NA, linewidth=1, linetype="solid"), - draw_key = function (data, params, size) - { - grid::circleGrob( - 0.5, 0.5, - r=0.35, - gp = grid::gpar( - col = scales::alpha(data$colour, data$alpha), - fill = scales::alpha(data$fill, data$alpha), - lty = data$linetype, - lwd = data$linewidth - ) - ) - }, - - draw_panel = function(data, panel_scales, coord, na.rm = TRUE) { - coords <- coord$transform(data, panel_scales) - grid::circleGrob( - x=coords$x, y=coords$y, - r=coords$radius, - gp = grid::gpar( - col = alpha(coords$colour, coords$alpha), - fill = alpha(coords$fill, coords$alpha), - lty = coords$linetype, - lwd = coords$linewidth - ) - ) - } -) - -geom_circle <- function(mapping = NULL, data = NULL, stat = "identity", - position = "identity", na.rm = FALSE, show.legend = NA, - inherit.aes = TRUE, ...) { - ggplot2::layer( - geom = GeomCircle, mapping = mapping, data = data, stat = stat, - position = position, show.legend = show.legend, inherit.aes = inherit.aes, - params = list(na.rm = na.rm, ...) - ) -} - g_legend <- function(a.gplot){ tmp <- ggplot_gtable(ggplot_build(a.gplot)) leg <- which(sapply(tmp$grobs, function(x) x$name) == "guide-box") diff --git a/R/utils.R b/R/utils.R index d6adccac..69150301 100644 --- a/R/utils.R +++ b/R/utils.R @@ -122,26 +122,6 @@ config_post_default_PLNmixture <- sandwich_var = FALSE ) -status_to_message <- function(status) { - message <- switch(as.character(status), - "1" = "success", - "2" = "success, stopval was reached", - "3" = "success, ftol_rel or ftol_abs was reached", - "4" = "success, xtol_rel or xtol_abs was reached", - "5" = "success, maxeval was reached", - "6" = "success, maxtime was reached", - "-1" = "failure", - "-2" = "invalid arguments", - "-3" = "out of memory.", - "-4" = "roundoff errors led to a breakdown of the optimization algorithm", - "-5" = "forced termination:", - "Return status not recognized" - ) - message -} - -trace <- function(x) sum(diag(x)) - .xlogx <- function(x) ifelse(x < .Machine$double.eps, 0, x*log(x)) .softmax <- function(x) { @@ -229,16 +209,6 @@ edge_to_node <- function(x, n = max(x)) { return(data.frame(node1 = i + 1, node2 = j + 1)) } -node_pair_to_egde <- function(x, y, node.set = union(x, y)) { - ## Convert node labels to integers (starting from 0) - x <- match(x, node.set) - 1 - y <- match(y, node.set) - 1 - ## For each pair (x,y) return, corresponding edge number - n <- length(node.set) - j.grid <- cumsum(0:(n - 1)) - x + j.grid[y] + 1 -} - #' @title PLN RNG #' #' @description Random generation for the PLN model with latent mean equal to mu, latent covariance matrix @@ -329,7 +299,7 @@ create_parameters <- function( #' Y <- barents$Abundance #' X <- model.matrix(Abundance ~ Latitude + Longitude + Depth + Temperature, data = barents) #' O <- log(barents$Offset) -#' w <-- rep(1, nrow(Y)) +#' w <- rep(1, nrow(Y)) #' compute_PLN_starting_point(Y, X, O, w) #' } #' diff --git a/man/PLNLDA_param.Rd b/man/PLNLDA_param.Rd index 8ab56640..03c81dc8 100644 --- a/man/PLNLDA_param.Rd +++ b/man/PLNLDA_param.Rd @@ -5,7 +5,7 @@ \title{Control of a PLNLDA fit} \usage{ PLNLDA_param( - backend = c("nlopt", "torch"), + backend = c("homemade", "nlopt", "hybrid", "torch"), trace = 1, covariance = c("full", "diagonal", "spherical"), config_post = list(), diff --git a/man/PLNPCA_param.Rd b/man/PLNPCA_param.Rd index b5c23c7d..9299d0cf 100644 --- a/man/PLNPCA_param.Rd +++ b/man/PLNPCA_param.Rd @@ -5,15 +5,18 @@ \title{Control of PLNPCA fit} \usage{ PLNPCA_param( - backend = c("nlopt", "torch"), + backend = c("nlopt", "torch", "homemade"), trace = 1, config_optim = list(), config_post = list(), - inception = NULL + inception = NULL, + sequential = FALSE ) } \arguments{ -\item{backend}{optimization back used, either "nlopt" or "torch". Default is "nlopt"} +\item{backend}{optimization back used, either "nlopt", "torch", or "homemade". Default is "nlopt". +Use "homemade" for the built-in coordinate-Newton optimizer (exact diagonal Newton steps for +B, M, C, and closed-form update for S in log(S²) space), which does not depend on NLOPT.} \item{trace}{a integer for verbosity.} @@ -24,6 +27,12 @@ PLNPCA_param( \item{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.} + +\item{sequential}{logical. If \code{TRUE}, ranks are fitted in ascending order and each model is +warm-started from the converged solution of the previous rank: loadings C are augmented +with new columns from the inception SVD, while latent scores M and variances S are +padded with zeros / 0.1 respectively. Disables parallel fitting across ranks. +Default is \code{FALSE}.} } \value{ list of parameters configuring the fit. diff --git a/man/PLNPCAfit.Rd b/man/PLNPCAfit.Rd index e1383708..9d5b5ecb 100644 --- a/man/PLNPCAfit.Rd +++ b/man/PLNPCAfit.Rd @@ -59,6 +59,7 @@ The function \code{\link{PLNPCA}}, the class \code{\link[=PLNPCAfamily]{PLNPCAfa \subsection{Public methods}{ \itemize{ \item \href{#method-PLNPCAfit-initialize}{\code{PLNPCAfit$new()}} + \item \href{#method-PLNPCAfit-warm_start_from}{\code{PLNPCAfit$warm_start_from()}} \item \href{#method-PLNPCAfit-update}{\code{PLNPCAfit$update()}} \item \href{#method-PLNPCAfit-optimize}{\code{PLNPCAfit$optimize()}} \item \href{#method-PLNPCAfit-optimize_vestep}{\code{PLNPCAfit$optimize_vestep()}} @@ -104,6 +105,28 @@ The function \code{\link{PLNPCA}}, the class \code{\link[=PLNPCAfamily]{PLNPCAfa } } +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-PLNPCAfit-warm_start_from}{}}} +\subsection{\code{PLNPCAfit$warm_start_from()}}{ + Reinitialize parameters for sequential warm-starting from a lower-rank fit. +Fitted loadings C, scores M, variances S, and regression coefficients B from \code{prev_fit} +are carried over; new columns are padded using the inception SVD (C) or zeros/0.1 (M/S). + \subsection{Usage}{ + \if{html}{\out{
}} + \preformatted{PLNPCAfit$warm_start_from(prev_fit, svdM)} + \if{html}{\out{
}} + } + \subsection{Arguments}{ + \if{html}{\out{
}} + \describe{ + \item{\code{prev_fit}}{a converged \code{\link{PLNPCAfit}} of rank \code{self$rank - k} (k >= 1)} + \item{\code{svdM}}{the inception SVD (from \code{PLNPCAfamily})} + } + \if{html}{\out{
}} + } +} + \if{html}{\out{
}} \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfit-update}{}}} diff --git a/man/PLN_param.Rd b/man/PLN_param.Rd index a5142d85..8a9671a4 100644 --- a/man/PLN_param.Rd +++ b/man/PLN_param.Rd @@ -5,7 +5,7 @@ \title{Control of a PLN fit} \usage{ PLN_param( - backend = c("nlopt", "torch"), + backend = c("homemade", "nlopt", "hybrid", "torch"), trace = 1, covariance = c("full", "diagonal", "spherical", "fixed"), Omega = NULL, @@ -15,7 +15,9 @@ PLN_param( ) } \arguments{ -\item{backend}{optimization back used, either "nlopt" or "torch". Default is "nlopt"} +\item{backend}{optimization back used, either "homemade" (default), "nlopt", "hybrid" or "torch". +"homemade" is the built-in envelope-theorem Newton optimizer (does not depend on NLOPT). +"hybrid" runs nlopt first for basin finding, then switches to homemade for refinement.} \item{trace}{a integer for verbosity.} diff --git a/man/PLNmixture_param.Rd b/man/PLNmixture_param.Rd index 81ec96c7..a72bd1c9 100644 --- a/man/PLNmixture_param.Rd +++ b/man/PLNmixture_param.Rd @@ -5,7 +5,7 @@ \title{Control of a PLNmixture fit} \usage{ PLNmixture_param( - backend = "nlopt", + backend = c("homemade", "nlopt", "hybrid", "torch"), trace = 1, covariance = "spherical", init_cl = "kmeans", @@ -16,7 +16,7 @@ PLNmixture_param( ) } \arguments{ -\item{backend}{optimization back used, either "nlopt" or "torch". Default is "nlopt"} +\item{backend}{optimization back used, either "homemade", "nlopt", "hybrid" or "torch". Default is "homemade".} \item{trace}{a integer for verbosity.} diff --git a/man/PLNnetwork_param.Rd b/man/PLNnetwork_param.Rd index c40c1350..546e6e2c 100644 --- a/man/PLNnetwork_param.Rd +++ b/man/PLNnetwork_param.Rd @@ -5,7 +5,7 @@ \title{Control of PLNnetwork fit} \usage{ PLNnetwork_param( - backend = c("nlopt", "torch"), + backend = c("nlopt", "homemade", "hybrid", "torch"), inception_cov = c("full", "spherical", "diagonal"), trace = 1, n_penalties = 30, @@ -18,7 +18,8 @@ PLNnetwork_param( ) } \arguments{ -\item{backend}{optimization back used, either "nlopt" or "torch". Default is "nlopt"} +\item{backend}{optimization back used, either "nlopt", "homemade", "hybrid" or "torch". Default is "nlopt". +Note: the "nlopt" backend converges better in PLNnetwork's outer glasso alternation than "homemade".} \item{inception_cov}{Covariance structure used for the inception model used to initialize the PLNfamily. Defaults to "full" and can be constrained to "diagonal" and "spherical".} diff --git a/man/ZIPLN_param.Rd b/man/ZIPLN_param.Rd index fb0786c7..6c2f46da 100644 --- a/man/ZIPLN_param.Rd +++ b/man/ZIPLN_param.Rd @@ -18,7 +18,9 @@ ZIPLN_param( ) } \arguments{ -\item{backend}{optimization back used, either "nlopt" or "torch". Default is "nlopt"} +\item{backend}{optimization back used, either "homemade" (default), "nlopt", "hybrid" or "torch". +"homemade" is the built-in envelope-theorem Newton optimizer (does not depend on NLOPT). +"hybrid" runs nlopt first for basin finding, then switches to homemade for refinement.} \item{trace}{a integer for verbosity.} diff --git a/man/ZIPLNnetwork_param.Rd b/man/ZIPLNnetwork_param.Rd index fe3d4daa..f81166c4 100644 --- a/man/ZIPLNnetwork_param.Rd +++ b/man/ZIPLNnetwork_param.Rd @@ -18,7 +18,8 @@ ZIPLNnetwork_param( ) } \arguments{ -\item{backend}{optimization back used, either "nlopt" or "torch". Default is "nlopt"} +\item{backend}{optimization back used, either "nlopt", "homemade", "hybrid" or "torch". Default is "nlopt". +Note: the "nlopt" backend converges better in PLNnetwork's outer glasso alternation than "homemade".} \item{inception_cov}{Covariance structure used for the inception model used to initialize the PLNfamily. Defaults to "full" and can be constrained to "diagonal" and "spherical".} diff --git a/man/compute_PLN_starting_point.Rd b/man/compute_PLN_starting_point.Rd index 0390059b..6c9427f0 100644 --- a/man/compute_PLN_starting_point.Rd +++ b/man/compute_PLN_starting_point.Rd @@ -32,7 +32,7 @@ data(barents) Y <- barents$Abundance X <- model.matrix(Abundance ~ Latitude + Longitude + Depth + Temperature, data = barents) O <- log(barents$Offset) -w <-- rep(1, nrow(Y)) +w <- rep(1, nrow(Y)) compute_PLN_starting_point(Y, X, O, w) } diff --git a/src/nlopt_wrapper.cpp b/src/nlopt_wrapper.cpp index 85c3bd5a..6b680a8b 100644 --- a/src/nlopt_wrapper.cpp +++ b/src/nlopt_wrapper.cpp @@ -85,35 +85,6 @@ std::unique_ptr new_nlopt_optimizer(const Rcpp::List return opt; } -// void set_uniform_x_weights(NloptStruct * opt, double value) { -// if(nlopt_set_x_weights1(opt, value) != NLOPT_SUCCESS) { -// throw Rcpp::exception("nlopt_set_x_weights1"); -// } -// } -// -// void set_per_value_x_weights(NloptStruct * opt, const std::vector & x_weights) { -// if(x_weights.size() != nlopt_get_dimension(opt)) { -// throw Rcpp::exception("set_per_value_xtol_weights: parameter size mismatch"); -// } -// if(nlopt_set_x_weights(opt, x_weights.data()) != NLOPT_SUCCESS) { -// throw Rcpp::exception("nlopt_set_x_weights"); -// } -// } -// -// void set_uniform_xtol_abs(NloptStruct * opt, double value) { -// if(nlopt_set_xtol_abs1(opt, value) != NLOPT_SUCCESS) { -// throw Rcpp::exception("nlopt_set_xtol_abs1"); -// } -// } -// void set_per_value_xtol_abs(NloptStruct * opt, const std::vector & xtol_abs) { -// if(xtol_abs.size() != nlopt_get_dimension(opt)) { -// throw Rcpp::exception("set_per_value_xtol_abs: parameter size mismatch"); -// } -// if(nlopt_set_xtol_abs(opt, xtol_abs.data()) != NLOPT_SUCCESS) { -// throw Rcpp::exception("nlopt_set_xtol_abs"); -// } -// } - // --------------------------------------------------------------------------------------- // sanity test and example @@ -143,18 +114,12 @@ bool cpp_test_nlopt() { auto optimizer = new_nlopt_optimizer(config, x.size()); - // set_uniform_xtol_abs(optimizer.get(), 0); - // set_uniform_x_weights(optimizer.get(), 1.); - check(nlopt_get_algorithm(optimizer.get()) == NLOPT_LD_LBFGS, "optim algorithm"); check(nlopt_get_ftol_abs(optimizer.get()) == 0.0, "optim ftol_abs"); check(nlopt_get_ftol_rel(optimizer.get()) == 0.0, "optim ftol_rel"); check(nlopt_get_xtol_rel(optimizer.get()) == 1e-12, "optim xtol_rel"); auto f_and_grad = [check](const double * x, double * grad) -> double { - // double v = x[0]; - // grad[0] = 2. * v; - // return v * v; double x1sq = x[0] * x[0] ; double obj = 100*std::pow(x[1] - x1sq,2) + std::pow(1-x[0],2); @@ -169,7 +134,6 @@ bool cpp_test_nlopt() { check(r.status != NLOPT_FAILURE, "optim status"); x = std::vector{1.5, -2}; - // set_uniform_x_weights(optimizer.get(), 1.0); r = minimize_objective_on_parameters(optimizer.get(), f_and_grad, x); return success; diff --git a/src/nlopt_wrapper.h b/src/nlopt_wrapper.h index 857e6529..e97e43cd 100644 --- a/src/nlopt_wrapper.h +++ b/src/nlopt_wrapper.h @@ -23,16 +23,6 @@ struct NloptDeleter { // xtol_rel, ftol_abs, ftol_rel, maxeval, maxtime. std::unique_ptr new_nlopt_optimizer(const Rcpp::List & config, std::size_t size); -// Helpers to set xtol_abs (uniform or per-parameter packed array). -// This is not done by new_nlopt_optimizer as it may require packing values, which must be user specified. -// void set_uniform_xtol_abs(NloptStruct * opt, double value); -// void set_per_value_xtol_abs(NloptStruct * opt, const std::vector & xtol_abs); - -// Helpers to set x_weights (uniform or per-parameter packed array). -// This is not done by new_nlopt_optimizer as it may require packing values, which must be user specified. -// void set_uniform_x_weights(NloptStruct * opt, double value); -// void set_per_value_x_weights(NloptStruct * opt, const std::vector & x_weigths); - struct OptimizerResult { nlopt_result status; double objective; From 28939a0fedd6dfb10f822cdd58b30bfe09a64b8f Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Wed, 10 Jun 2026 10:53:04 +0200 Subject: [PATCH 25/58] fix use of PLNLDA_param --- R/PLNLDA.R | 21 ++++++--------------- man/PLNLDA.Rd | 19 ++++--------------- tests/testthat/test-plnlda-fit.R | 4 ++-- 3 files changed, 12 insertions(+), 32 deletions(-) diff --git a/R/PLNLDA.R b/R/PLNLDA.R index 52f258aa..facc4a31 100644 --- a/R/PLNLDA.R +++ b/R/PLNLDA.R @@ -7,21 +7,12 @@ #' @param subset an optional vector specifying a subset of observations to be used in the fitting process. #' @param weights an optional vector of observation weights to be used in the fitting process. #' @param grouping a factor specifying the class of each observation used for discriminant analysis. -#' @param control a list-like structure for controlling the optimization, with default generated by [PLN_param()]. See the associated documentation +#' @param control a list-like structure for controlling the optimization, with default generated by [PLNLDA_param()]. See the associated documentation. #' #' @return an R6 object with class [PLNLDAfit()] #' -#' @details The parameter `control` is a list controlling the optimization with the following entries: -#' * "covariance" character setting the model for the covariance matrix. Either "full" or "spherical". Default is "full". -#' * "trace" integer for verbosity. -#' * "inception" Set up the initialization. By default, the model is initialized with a multivariate linear model applied on log-transformed data. However, the user can provide a PLNfit (typically obtained from a previous fit), which often speed up the inference. -#' * "ftol_rel" stop when an optimization step changes the objective function by less than ftol multiplied by the absolute value of the parameter. Default is 1e-8 -#' * "ftol_abs" stop when an optimization step changes the objective function by less than ftol multiplied by the absolute value of the parameter. Default is 0 -#' * "xtol_rel" stop when an optimization step changes every parameters by less than xtol multiplied by the absolute value of the parameter. Default is 1e-6 -#' * "xtol_abs" stop when an optimization step changes every parameters by less than xtol multiplied by the absolute value of the parameter. Default is 0 -#' * "maxeval" stop when the number of iteration exceeds maxeval. Default is 10000 -#' * "maxtime" stop when the optimization time (in seconds) exceeds maxtime. Default is -1 (no restriction) -#' * "algorithm" the optimization method used by NLOPT among LD type, i.e. "CCSAQ", "MMA", "LBFGS", "VAR1", "VAR2". See NLOPT documentation for further details. Default is "CCSAQ". +#' @details See [PLNLDA_param()] for a full description of the optimization parameters. +#' Note that unlike [PLN_param()], [PLNLDA_param()] does not expose the `"fixed"` covariance option or the `Omega` parameter, which are not meaningful in the LDA context. #' #' @rdname PLNLDA #' @examples @@ -31,12 +22,12 @@ #' @seealso The class [`PLNLDAfit`] #' @importFrom stats model.frame model.matrix model.response model.offset #' @export -PLNLDA <- function(formula, data, subset, weights, grouping, control = PLN_param()) { +PLNLDA <- function(formula, data, subset, weights, grouping, control = PLNLDA_param()) { ## Temporary test for deprecated use of list() if (!inherits(control, "PLNmodels_param")) - stop("We now use the function PLN_param() to generate the list of parameters that controls the fit: - replace 'list(my_arg = xx)' by PLN_param(my_arg = xx) and see the documentation of PLN_param().") + stop("We now use the function PLNLDA_param() to generate the list of parameters that controls the fit: + replace 'list(my_arg = xx)' by PLNLDA_param(my_arg = xx) and see the documentation of PLNLDA_param().") ## look for grouping in the data or the parent frame if (inherits(try(eval(grouping), silent = TRUE), "try-error")) { diff --git a/man/PLNLDA.Rd b/man/PLNLDA.Rd index 4d42c46e..f0263971 100644 --- a/man/PLNLDA.Rd +++ b/man/PLNLDA.Rd @@ -4,7 +4,7 @@ \alias{PLNLDA} \title{Poisson lognormal model towards Linear Discriminant Analysis} \usage{ -PLNLDA(formula, data, subset, weights, grouping, control = PLN_param()) +PLNLDA(formula, data, subset, weights, grouping, control = PLNLDA_param()) } \arguments{ \item{formula}{an object of class "formula": a symbolic description of the model to be fitted.} @@ -17,7 +17,7 @@ PLNLDA(formula, data, subset, weights, grouping, control = PLN_param()) \item{grouping}{a factor specifying the class of each observation used for discriminant analysis.} -\item{control}{a list-like structure for controlling the optimization, with default generated by \code{\link[=PLN_param]{PLN_param()}}. See the associated documentation} +\item{control}{a list-like structure for controlling the optimization, with default generated by \code{\link[=PLNLDA_param]{PLNLDA_param()}}. See the associated documentation.} } \value{ an R6 object with class \code{\link[=PLNLDAfit]{PLNLDAfit()}} @@ -26,19 +26,8 @@ an R6 object with class \code{\link[=PLNLDAfit]{PLNLDAfit()}} Fit the Poisson lognormal for LDA with a variational algorithm. Use the (g)lm syntax for model specification (covariates, offsets). } \details{ -The parameter \code{control} is a list controlling the optimization with the following entries: -\itemize{ -\item "covariance" character setting the model for the covariance matrix. Either "full" or "spherical". Default is "full". -\item "trace" integer for verbosity. -\item "inception" Set up the initialization. By default, the model is initialized with a multivariate linear model applied on log-transformed data. However, the user can provide a PLNfit (typically obtained from a previous fit), which often speed up the inference. -\item "ftol_rel" stop when an optimization step changes the objective function by less than ftol multiplied by the absolute value of the parameter. Default is 1e-8 -\item "ftol_abs" stop when an optimization step changes the objective function by less than ftol multiplied by the absolute value of the parameter. Default is 0 -\item "xtol_rel" stop when an optimization step changes every parameters by less than xtol multiplied by the absolute value of the parameter. Default is 1e-6 -\item "xtol_abs" stop when an optimization step changes every parameters by less than xtol multiplied by the absolute value of the parameter. Default is 0 -\item "maxeval" stop when the number of iteration exceeds maxeval. Default is 10000 -\item "maxtime" stop when the optimization time (in seconds) exceeds maxtime. Default is -1 (no restriction) -\item "algorithm" the optimization method used by NLOPT among LD type, i.e. "CCSAQ", "MMA", "LBFGS", "VAR1", "VAR2". See NLOPT documentation for further details. Default is "CCSAQ". -} +See \code{\link[=PLNLDA_param]{PLNLDA_param()}} for a full description of the optimization parameters. +Note that unlike \code{\link[=PLN_param]{PLN_param()}}, \code{\link[=PLNLDA_param]{PLNLDA_param()}} does not expose the \code{"fixed"} covariance option or the \code{Omega} parameter, which are not meaningful in the LDA context. } \examples{ data(trichoptera) diff --git a/tests/testthat/test-plnlda-fit.R b/tests/testthat/test-plnlda-fit.R index 0d8e7932..b7630106 100644 --- a/tests/testthat/test-plnlda-fit.R +++ b/tests/testthat/test-plnlda-fit.R @@ -113,10 +113,10 @@ test_that("PLNLDA fit: Check number of parameters", { mdl <- PLN(Abundance ~ Group + 0 , data = trichoptera) expect_equal(mdl$nb_param, p*(p+1)/2 + p * nlevels(trichoptera$Group)) - mdl <- PLN(Abundance ~ 1, data = trichoptera, control = PLNLDA_param(covariance = "diagonal")) + mdl <- PLN(Abundance ~ 1, data = trichoptera, control = PLN_param(covariance = "diagonal")) expect_equal(mdl$nb_param, p + p * 1) - mdl <- PLN(Abundance ~ 1, data = trichoptera, control = PLNLDA_param(covariance = "spherical")) + mdl <- PLN(Abundance ~ 1, data = trichoptera, control = PLN_param(covariance = "spherical")) expect_equal(mdl$nb_param, 1 + p * 1) }) From 56f7bfae9448537f4a060af9e6fcfe8846f4db1f Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Wed, 10 Jun 2026 10:55:18 +0200 Subject: [PATCH 26/58] updating devlog --- .Rbuildignore | 1 + DEVLOG_2026-06-08-09.md | 160 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 153 insertions(+), 8 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index d70d1c95..77442722 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -36,3 +36,4 @@ ^AUTHORS$ ^dev$ ^\.claude$ +^DEVLOG.*\.md$ diff --git a/DEVLOG_2026-06-08-09.md b/DEVLOG_2026-06-08-09.md index fbce29c8..25d4c59f 100644 --- a/DEVLOG_2026-06-08-09.md +++ b/DEVLOG_2026-06-08-09.md @@ -289,14 +289,151 @@ En pratique, `hybrid` et `homemade` convergent désormais au même ELBO (à ±0. --- +## 11. Correction des bugs `ifelse()` dans PLNLDAfit (10/06) + +**Fichier** : `R/PLNLDAfit-class.R` + +### Bug + +`PLNLDAfit_diagonal$initialize` et `PLNLDAfit_spherical$initialize` utilisaient `ifelse()` au lieu de `if/else` pour sélectionner l'optimiseur : + +```r +# Code bugué +private$optimizer$main <- ifelse(control$backend == "nlopt", + nlopt_optimize_diagonal, + private$torch_optimize) +``` + +`ifelse()` évalue les **deux branches** et retourne un scalaire. Avec `backend = "homemade"` (désormais défaut), la condition est `FALSE` → retourne `private$torch_optimize`. Le torch optimizer échoue avec `double(length = config$num_epoch + 1)` car `config_default_homemade` n'a pas de champ `num_epoch`. + +### Correction + +Remplacement par un bloc `if/else if/else` complet dans les deux classes, avec dispatch correct pour les quatre backends (`torch`, `homemade`, `hybrid`, `nlopt`) et mise à jour du vestep pour les backends Newton : + +```r +private$optimizer$main <- if (control$backend == "torch") { + private$torch_optimize +} else if (control$backend == "homemade") { + newton_optimize_diagonal # ou _spherical +} else if (control$backend == "hybrid") { + make_hybrid_optimizer(nlopt_optimize_diagonal, newton_optimize_diagonal) +} else { + nlopt_optimize_diagonal +} +private$optimizer$vestep <- if (control$backend %in% c("homemade", "hybrid")) + newton_optimize_vestep_diagonal else nlopt_optimize_vestep_diagonal +``` + +--- + +## 12. Alignement des backends pour PLNnetwork et PLNmixture (10/06) + +**Fichiers** : `R/PLNnetwork.R`, `R/PLNmixture.R` + +### Constats + +- `PLNnetwork_param()` et `PLNmixture_param()` proposaient uniquement `"nlopt"` et `"torch"`, bloquant `"homemade"` et `"hybrid"` par un `stopifnot()` redondant. +- `PLNmixture_param()` référençait `config_default_nlopt_pln` (objet inexistant) → crash immédiat à l'appel. + +### Corrections apportées + +Les deux `_param()` acceptent maintenant `c("homemade", "nlopt", "hybrid", "torch")` avec suppression du `stopifnot` redondant et ajout de la branche `else { config_opt <- config_default_homemade }`. + +### Choix du défaut : analyse de la boucle externe de PLNnetwork + +La question clé : faut-il choisir `"homemade"` comme défaut pour PLNnetwork (comme pour PLN) ? + +**Test expérimental** (trichoptera, 3 pénalités) : + +| Backend | Itérations outer | Temps | +|---|---|---| +| `nlopt` | 17 + 6 + 9 = **32** | 0.85 s | +| `homemade` | 20 + 18 + 20 = **58** (hits maxit_out) | 1.06 s | + +Avec `homemade`, beaucoup de pénalités atteignent `maxit_out=20` sans converger. Cause : le Newton avec enveloppe optimise très à fond à chaque appel (M, S, B jusqu'à ftol=1e-8), ce qui provoque des changements importants de Σ = M'M/n + diag(S²) à chaque étape, rendant le schéma d'alternance glasso ↔ PLN lent à converger globalement. En revanche, sur `PLN(covariance="fixed")` seul, `homemade` est plus rapide que `nlopt` (0.76s vs 1.01s sur oaks). C'est un **problème d'articulation**, pas de performance intrinsèque. + +**Décision** : PLNnetwork conserve `"nlopt"` comme défaut. PLNmixture utilise `"homemade"` (ses composantes sont des PLNfit standards, l'alternance EM–Mixture est différente). + +--- + +## 13. Correction : warning `solve()` sur formule sans covariable (10/06) + +**Fichier** : `src/newton_impl_alt.h` + +### Bug + +`PLN(Abundance ~ 0, data = ...)` (ou toute formule sans covariable) déclenche : + +``` +warning: solve(): system is singular; attempting approx solution +``` + +Cause : avec `d = 0`, `X` est une matrice n×0, `XtWX = X'WX` est une matrice 0×0, et `arma::solve(0×0, ...)` émet ce warning. + +### Correction + +Garde sur la taille de X avant l'appel à `solve` : + +```cpp +const arma::mat P_X = (X.n_cols > 0) + ? arma::solve(XtWX, Xw.t()) + : arma::mat(0, n); // d=0 : P_X vide, toutes les opérations avec B sont des no-ops +``` + +Toutes les opérations matricielles suivantes (produits avec X, B, P_X) produisent les bonnes valeurs nulles quand d=0 grâce à l'arithmétique Armadillo sur matrices vides. + +**Note** : le touch des `.cpp` incluant `newton_impl_alt.h` est nécessaire pour forcer la recompilation du header. + +--- + +## 14. Nettoyage : code mort (10/06) + +**Fichiers** : `R/utils.R`, `R/PLNfit-class.R`, `R/PLN.R`, `R/plot_utils.R`, `R/PLNnetwork.R`, `src/nlopt_wrapper.h`, `src/nlopt_wrapper.cpp` + +Audit complet du code mort côté R et C++. Suppressions : + +**R :** +- `utils.R` : `status_to_message()` (jamais appelée ; seul usage dans un commentaire de `PLNfit-class.R`), `trace()` (shadow du `base::trace`, aucun appel actif), `node_pair_to_egde()` (typo + jamais appelée, contrairement à `edge_to_node`) +- `PLNfit-class.R` : classe `PLNfit_genetprior` entière (~100 lignes commentées) — modèle à covariance génétique abandonné +- `PLN.R` : branche `# "genet" = PLNfit_$new(...)` (classe inexistante) +- `plot_utils.R` : `GeomCircle` + `geom_circle()` (~45 lignes, jamais appelées) +- `PLNnetwork.R` : champ orphelin `variance = TRUE` dans la liste retournée par `PLNnetwork_param()` + +**C++ :** +- `nlopt_wrapper.h` + `nlopt_wrapper.cpp` : déclarations et corps des 4 fonctions helper commentées (`set_uniform_x_weights`, `set_per_value_x_weights`, `set_uniform_xtol_abs`, `set_per_value_xtol_abs`) + leurs appels commentés dans le test + +**Corrections mineures :** +- `utils.R` : typo `w <-- rep(...)` → `w <- rep(...)` dans l'exemple `compute_PLN_starting_point` +- `PLN.R` : `@param backend` mis à jour (défaut `"homemade"`, `"hybrid"` ajouté) +- `plot_utils.R` : bug `center[1]` → `center[2]` dans la coordonnée y de `circle()` (inoffensif car toujours appelée avec `c(0,0)`) + +--- + +## 15. Activation de `PLNLDA_param()` (10/06) + +**Fichiers** : `R/PLNLDA.R`, `tests/testthat/test-plnlda-fit.R` + +### Situation initiale + +`PLNLDA_param()` était définie, exportée et documentée, mais `PLNLDA()` utilisait `PLN_param()` comme défaut. Les deux fonctions retournent un `PLNmodels_param` compatible, avec une différence : `PLNLDA_param()` n'expose pas l'option `"fixed"` ni le paramètre `Omega`, non pertinents en LDA. + +De plus, `test-plnlda-fit.R` passait `PLNLDA_param(covariance = "diagonal/spherical")` à `PLN()` (bug de test). + +### Corrections + +- `PLNLDA()` : signature changée en `control = PLNLDA_param()`; documentation et message d'erreur mis à jour. +- `test-plnlda-fit.R` : `PLNLDA_param` → `PLN_param` dans les deux lignes qui testaient `PLN()`. + +--- + ## Récapitulatif des backends disponibles -| `backend` | Algorithme | Remarque | +| `backend` | Algorithme | Défaut pour | |---|---|---| -| `"nlopt"` | CCSAQ/NLOPT, B profilé (enveloppe) | Défaut | -| `"homemade"` | Newton diagonal, B profilé (enveloppe), Armijo Q_step | Rapide, haute qualité | -| `"hybrid"` | nlopt (exploration) → homemade (raffinement) | Filet de sécurité | -| `"torch"` | RPROP/ADAM/... | GPU-compatible | +| `"homemade"` | Newton diagonal, B profilé (enveloppe), Armijo Q_step | PLN, PLNLDA, PLNmixture | +| `"nlopt"` | CCSAQ/NLOPT, B profilé (enveloppe) | PLNnetwork | +| `"hybrid"` | nlopt (exploration) → homemade (raffinement) | — | +| `"torch"` | RPROP/ADAM/... | — | --- @@ -311,6 +448,13 @@ En pratique, `hybrid` et `homemade` convergent désormais au même ELBO (à ±0. | `src/nlopt_{full,diag,spherical,fixed}_cov.cpp` | B profilé + helpers statiques + bug fix vestep sphérique | | `src/spectral_rank_cov.cpp` | Gradient spectral BB+GLL pour PLNPCA | | `src/newton_rank_cov.cpp` | Coordonnée-Newton pour PLNPCA | -| `R/PLNfit-class.R` | Branchement backends dans les 4 classes PLNfit | -| `R/PLN.R` | `PLN_param()` — `homemade_alt` supprimé | -| `R/utils.R` | `make_hybrid_optimizer()` revu (phase 1 nlopt) | +| `R/PLNfit-class.R` | Branchement backends dans les 4 classes PLNfit ; `PLNfit_genetprior` supprimée | +| `R/PLNLDAfit-class.R` | Correction `ifelse()` → `if/else` dans diagonal et sphérique | +| `R/PLN.R` | `PLN_param()` — `homemade_alt` supprimé ; doc backend mise à jour | +| `R/PLNLDA.R` | `PLNLDA()` utilise désormais `PLNLDA_param()` comme défaut | +| `R/PLNnetwork.R` | `"homemade"`/`"hybrid"` ajoutés ; défaut conservé à `"nlopt"` | +| `R/PLNmixture.R` | `"homemade"`/`"hybrid"` ajoutés ; défaut `"homemade"` ; bug `config_default_nlopt_pln` corrigé | +| `R/utils.R` | `make_hybrid_optimizer()` revu ; code mort supprimé | +| `R/plot_utils.R` | `GeomCircle`/`geom_circle` supprimés ; bug `center[1]` corrigé | +| `src/nlopt_wrapper.h` | Déclarations commentées supprimées | +| `src/nlopt_wrapper.cpp` | Corps commentés + appels orphelins supprimés | From c74f4317fdaa8c9887988faabdc59537ca292d7f Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Wed, 10 Jun 2026 11:04:40 +0200 Subject: [PATCH 27/58] updating doc and optim param homogeneisation --- R/PLN.R | 6 ++++++ R/PLNmixture.R | 2 +- R/utils.R | 4 +++- man/PLNLDA_param.Rd | 8 ++++++++ man/PLNPCA_param.Rd | 8 ++++++++ man/PLN_param.Rd | 8 ++++++++ man/PLNmixture_param.Rd | 2 +- src/newton_diag_cov.cpp | 4 ++-- src/newton_fixed_cov.cpp | 4 ++-- src/newton_full_cov.cpp | 4 ++-- src/newton_spherical.cpp | 4 ++-- src/nlopt_full_cov.cpp | 8 ++++---- 12 files changed, 47 insertions(+), 15 deletions(-) diff --git a/R/PLN.R b/R/PLN.R index accb50a9..6f59d366 100644 --- a/R/PLN.R +++ b/R/PLN.R @@ -91,6 +91,12 @@ 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 #' +#' When "homemade" or "hybrid" backend is used, the following entries are relevant +#' * "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 +#' * "ftol_rel" stop the inner loop when the objective changes by less than ftol_rel (relative). Default is 1e-8 +#' * "maxit_em" stop the EM outer loop when the number of EM iterations exceeds maxit_em. Default is 50 +#' * "ftol_em" stop the EM outer loop when the ELBO changes by less than ftol_em (relative). Default is 1e-8 +#' #' 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). diff --git a/R/PLNmixture.R b/R/PLNmixture.R index 04b86a9c..6af56156 100644 --- a/R/PLNmixture.R +++ b/R/PLNmixture.R @@ -84,7 +84,7 @@ PLNmixture <- function(formula, data, subset, clusters = 1:5, control = PLNmixt #' @details See [PLN_param()] for a full description of the generic optimization parameters. PLNmixture_param() also has additional parameters controlling the optimization due the inner-outer loop structure of the optimizer: #' * "ftol_out" outer solver stops when an optimization step changes the objective function by less than xtol multiplied by the absolute value of the parameter. Default is 1e-6 #' * "maxit_out" outer solver stops when the number of iteration exceeds maxit_out. Default is 50 -#' * "it_smoothing" number of the iterations of the smoothing procedure. Default is 1. +#' * "it_smooth" number of the iterations of the smoothing procedure. Default is 1. #' #' @seealso [PLN_param()] #' @export diff --git a/R/utils.R b/R/utils.R index 69150301..89b958f7 100644 --- a/R/utils.R +++ b/R/utils.R @@ -19,7 +19,9 @@ config_default_homemade <- algorithm = "NEWTON", backend = "homemade", maxeval = 10000, - ftol_rel = 1e-8 + ftol_rel = 1e-8, + maxit_em = 50, + ftol_em = 1e-8 ) # Hybrid backend: two-phase optimizer — nlopt/CCSAQ (phase 1) then homemade Newton (phase 2). diff --git a/man/PLNLDA_param.Rd b/man/PLNLDA_param.Rd index 03c81dc8..29325e0d 100644 --- a/man/PLNLDA_param.Rd +++ b/man/PLNLDA_param.Rd @@ -62,6 +62,14 @@ When "torch" backend is used (only for PLN and PLNLDA for now), the following en \item "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 } +When "homemade" or "hybrid" backend is used, the following entries are relevant +\itemize{ +\item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 +\item "ftol_rel" stop the inner loop when the objective changes by less than ftol_rel (relative). Default is 1e-8 +\item "maxit_em" stop the EM outer loop when the number of EM iterations exceeds maxit_em. Default is 50 +\item "ftol_em" stop the EM outer loop when the ELBO changes by less than ftol_em (relative). Default is 1e-8 +} + The list of parameters \code{config_post} controls the post-treatment processing (for most \verb{PLN*()} functions), with the following entries (defaults may vary depending on the specific function, check \verb{config_post_default_*} for defaults values): \itemize{ \item jackknife boolean indicating whether jackknife should be performed to evaluate bias and variance of the model parameters. Default is FALSE. diff --git a/man/PLNPCA_param.Rd b/man/PLNPCA_param.Rd index 9299d0cf..19d9b053 100644 --- a/man/PLNPCA_param.Rd +++ b/man/PLNPCA_param.Rd @@ -68,6 +68,14 @@ When "torch" backend is used (only for PLN and PLNLDA for now), the following en \item "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 } +When "homemade" or "hybrid" backend is used, the following entries are relevant +\itemize{ +\item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 +\item "ftol_rel" stop the inner loop when the objective changes by less than ftol_rel (relative). Default is 1e-8 +\item "maxit_em" stop the EM outer loop when the number of EM iterations exceeds maxit_em. Default is 50 +\item "ftol_em" stop the EM outer loop when the ELBO changes by less than ftol_em (relative). Default is 1e-8 +} + The list of parameters \code{config_post} controls the post-treatment processing (for most \verb{PLN*()} functions), with the following entries (defaults may vary depending on the specific function, check \verb{config_post_default_*} for defaults values): \itemize{ \item jackknife boolean indicating whether jackknife should be performed to evaluate bias and variance of the model parameters. Default is FALSE. diff --git a/man/PLN_param.Rd b/man/PLN_param.Rd index 8a9671a4..1b429e11 100644 --- a/man/PLN_param.Rd +++ b/man/PLN_param.Rd @@ -67,6 +67,14 @@ When "torch" backend is used (only for PLN and PLNLDA for now), the following en \item "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 } +When "homemade" or "hybrid" backend is used, the following entries are relevant +\itemize{ +\item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 +\item "ftol_rel" stop the inner loop when the objective changes by less than ftol_rel (relative). Default is 1e-8 +\item "maxit_em" stop the EM outer loop when the number of EM iterations exceeds maxit_em. Default is 50 +\item "ftol_em" stop the EM outer loop when the ELBO changes by less than ftol_em (relative). Default is 1e-8 +} + The list of parameters \code{config_post} controls the post-treatment processing (for most \verb{PLN*()} functions), with the following entries (defaults may vary depending on the specific function, check \verb{config_post_default_*} for defaults values): \itemize{ \item jackknife boolean indicating whether jackknife should be performed to evaluate bias and variance of the model parameters. Default is FALSE. diff --git a/man/PLNmixture_param.Rd b/man/PLNmixture_param.Rd index a72bd1c9..a2637b98 100644 --- a/man/PLNmixture_param.Rd +++ b/man/PLNmixture_param.Rd @@ -45,7 +45,7 @@ See \code{\link[=PLN_param]{PLN_param()}} for a full description of the generic \itemize{ \item "ftol_out" outer solver stops when an optimization step changes the objective function by less than xtol multiplied by the absolute value of the parameter. Default is 1e-6 \item "maxit_out" outer solver stops when the number of iteration exceeds maxit_out. Default is 50 -\item "it_smoothing" number of the iterations of the smoothing procedure. Default is 1. +\item "it_smooth" number of the iterations of the smoothing procedure. Default is 1. } } \seealso{ diff --git a/src/newton_diag_cov.cpp b/src/newton_diag_cov.cpp index 12879baf..817804d3 100644 --- a/src/newton_diag_cov.cpp +++ b/src/newton_diag_cov.cpp @@ -25,8 +25,8 @@ Rcpp::List newton_optimize_diagonal( const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; - const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + const int max_em = config.containsElementNamed("maxit_em") ? Rcpp::as(config["maxit_em"]) : 50; + const double em_tol = config.containsElementNamed("ftol_em") ? Rcpp::as(config["ftol_em"]) : 1e-8; const double w_bar = arma::accu(w); arma::mat S2 = S % S; diff --git a/src/newton_fixed_cov.cpp b/src/newton_fixed_cov.cpp index c2632618..3e0827c2 100644 --- a/src/newton_fixed_cov.cpp +++ b/src/newton_fixed_cov.cpp @@ -25,8 +25,8 @@ Rcpp::List newton_optimize_fixed( const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; - const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + const int max_em = config.containsElementNamed("maxit_em") ? Rcpp::as(config["maxit_em"]) : 50; + const double em_tol = config.containsElementNamed("ftol_em") ? Rcpp::as(config["ftol_em"]) : 1e-8; FixedCovTraits::State state(Omega); return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); diff --git a/src/newton_full_cov.cpp b/src/newton_full_cov.cpp index 49f4d058..df0f7f5f 100644 --- a/src/newton_full_cov.cpp +++ b/src/newton_full_cov.cpp @@ -25,8 +25,8 @@ Rcpp::List newton_optimize_full( const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; - const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + const int max_em = config.containsElementNamed("maxit_em") ? Rcpp::as(config["maxit_em"]) : 50; + const double em_tol = config.containsElementNamed("ftol_em") ? Rcpp::as(config["ftol_em"]) : 1e-8; const double w_bar = arma::accu(w); arma::mat S2 = S % S; diff --git a/src/newton_spherical.cpp b/src/newton_spherical.cpp index 63ce8ef0..1c13e469 100644 --- a/src/newton_spherical.cpp +++ b/src/newton_spherical.cpp @@ -25,8 +25,8 @@ Rcpp::List newton_optimize_spherical( const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; - const int max_em = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; - const double em_tol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + const int max_em = config.containsElementNamed("maxit_em") ? Rcpp::as(config["maxit_em"]) : 50; + const double em_tol = config.containsElementNamed("ftol_em") ? Rcpp::as(config["ftol_em"]) : 1e-8; const double w_bar = arma::accu(w); arma::mat S2 = S % S; diff --git a/src/nlopt_full_cov.cpp b/src/nlopt_full_cov.cpp index 848656ac..637e989b 100644 --- a/src/nlopt_full_cov.cpp +++ b/src/nlopt_full_cov.cpp @@ -51,8 +51,8 @@ Rcpp::List nlopt_optimize_full( metadata.map(parameters.data()) = arma::log(init_S % init_S); const double w_bar = accu(w); - const int max_em_iter = config.containsElementNamed("max_em_iter") ? Rcpp::as(config["max_em_iter"]) : 50; - const double em_ftol = config.containsElementNamed("em_ftol") ? Rcpp::as(config["em_ftol"]) : 1e-8; + const int maxit_em = config.containsElementNamed("maxit_em") ? Rcpp::as(config["maxit_em"]) : 50; + const double ftol_em = config.containsElementNamed("ftol_em") ? Rcpp::as(config["ftol_em"]) : 1e-8; // P_X = (X'WX)^{-1} X'W : d×n, precomputed once; B = P_X * M_full at each eval const arma::mat Xw = X.each_col() % w; @@ -71,7 +71,7 @@ Rcpp::List nlopt_optimize_full( int total_iterations = 0; int last_status = 0; - for (int em_iter = 0; em_iter < std::max(1, max_em_iter); em_iter++) { + for (int em_iter = 0; em_iter < std::max(1, maxit_em); em_iter++) { auto optimizer = new_nlopt_optimizer(config, parameters.size()); objective_vec.reserve(objective_vec.size() + nlopt_get_maxeval(optimizer.get())); const arma::vec Omega_diag = diagvec(Omega); @@ -106,7 +106,7 @@ Rcpp::List nlopt_optimize_full( arma::mat A = exp(Z + 0.5 * S2); double elbo = accu(w.t() * (Y % Z - A + 0.5 * logS2)) - 0.5 * w_bar * real(log_det(Sigma)); - if (em_iter > 0 && converged(elbo, elbo_prev, em_ftol)) break; + if (em_iter > 0 && converged(elbo, elbo_prev, ftol_em)) break; elbo_prev = elbo; } From cade6b2450e838a947b7be1c13ab65933e04e4b3 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Wed, 10 Jun 2026 11:10:02 +0200 Subject: [PATCH 28/58] more fusion in param optim --- R/PLNmixture.R | 8 ++++---- R/PLNmixturefit-class.R | 12 ++++++------ R/PLNnetwork.R | 8 ++++---- R/PLNnetworkfit-class.R | 6 +++--- man/PLNmixture_param.Rd | 4 ++-- man/PLNnetwork_param.Rd | 4 ++-- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/R/PLNmixture.R b/R/PLNmixture.R index 6af56156..5a5c4214 100644 --- a/R/PLNmixture.R +++ b/R/PLNmixture.R @@ -82,8 +82,8 @@ PLNmixture <- function(formula, data, subset, clusters = 1:5, control = PLNmixt #' #' @return list of parameters configuring the fit. #' @details See [PLN_param()] for a full description of the generic optimization parameters. PLNmixture_param() also has additional parameters controlling the optimization due the inner-outer loop structure of the optimizer: -#' * "ftol_out" outer solver stops when an optimization step changes the objective function by less than xtol multiplied by the absolute value of the parameter. Default is 1e-6 -#' * "maxit_out" outer solver stops when the number of iteration exceeds maxit_out. Default is 50 +#' * "ftol_em" outer EM solver stops when the objective changes by less than ftol_em (relative). Default is 1e-3 +#' * "maxit_em" outer EM solver stops when the number of iterations exceeds maxit_em. Default is 50 #' * "it_smooth" number of the iterations of the smoothing procedure. Default is 1. #' #' @seealso [PLN_param()] @@ -116,8 +116,8 @@ PLNmixture_param <- function( } else { # "homemade" or "hybrid" config_opt <- config_default_homemade } - config_opt$ftol_out <- 1e-3 - config_opt$maxit_out <- 50 + config_opt$ftol_em <- 1e-3 + config_opt$maxit_em <- 50 config_opt$it_smooth <- 1 config_opt[names(config_optim)] <- config_optim config_opt$trace <- trace diff --git a/R/PLNmixturefit-class.R b/R/PLNmixturefit-class.R index ca6c2149..c1b4e293 100644 --- a/R/PLNmixturefit-class.R +++ b/R/PLNmixturefit-class.R @@ -105,8 +105,8 @@ PLNmixturefit <- ## =========================================== ## INITIALISATION cond <- FALSE; iter <- 1 - objective <- numeric(config$maxit_out); objective[iter] <- Inf - convergence <- numeric(config$maxit_out); convergence[iter] <- NA + objective <- numeric(config$maxit_em); objective[iter] <- Inf + convergence <- numeric(config$maxit_em); convergence[iter] <- NA ## =========================================== ## OPTIMISATION while (!cond) { @@ -138,7 +138,7 @@ PLNmixturefit <- ## Assess convergence objective[iter] <- -self$loglik convergence[iter] <- abs(objective[iter-1] - objective[iter]) /abs(objective[iter]) - if ((convergence[iter] < config$ftol_out) | (iter >= config$maxit_out)) cond <- TRUE + if ((convergence[iter] < config$ftol_em) | (iter >= config$maxit_em)) cond <- TRUE } @@ -189,8 +189,8 @@ PLNmixturefit <- ## =========================================== ## INITIALISATION cond <- FALSE; iter <- 1 - objective <- numeric(control$config_optim$maxit_out); objective[iter] <- Inf - convergence <- numeric(control$config_optim$maxit_out); convergence[iter] <- NA + objective <- numeric(control$config_optim$maxit_em); objective[iter] <- Inf + convergence <- numeric(control$config_optim$maxit_em); convergence[iter] <- NA ## =========================================== ## OPTIMISATION @@ -221,7 +221,7 @@ PLNmixturefit <- rowSums(tau * J_ik) - rowSums(.xlogx(tau)) + tau %*% log(colMeans(tau)) objective[iter] <- -sum(J_ik) convergence[iter] <- abs(objective[iter-1] - objective[iter]) /abs(objective[iter]) - if ((convergence[iter] < control$config_optim$ftol_out) | (iter >= control$config_optim$maxit_out)) cond <- TRUE + if ((convergence[iter] < control$config_optim$ftol_em) | (iter >= control$config_optim$maxit_em)) cond <- TRUE } diff --git a/R/PLNnetwork.R b/R/PLNnetwork.R index 6e97ed9c..1e08b159 100644 --- a/R/PLNnetwork.R +++ b/R/PLNnetwork.R @@ -69,8 +69,8 @@ PLNnetwork <- function(formula, data, subset, weights, penalties = NULL, control #' @return list of parameters configuring the fit. #' @inherit PLN_param details #' @details See [PLN_param()] for a full description of the generic optimization parameters. PLNnetwork_param() also has two additional parameters controlling the optimization due the inner-outer loop structure of the optimizer: -#' * "ftol_out" outer solver stops when an optimization step changes the objective function by less than ftol multiplied by the absolute value of the parameter. Default is 1e-6 -#' * "maxit_out" outer solver stops when the number of iteration exceeds maxit_out. Default is 50 +#' * "ftol_em" outer alternating solver stops when the objective changes by less than ftol_em (relative). Default is 1e-5 +#' * "maxit_em" outer alternating solver stops when the number of iterations exceeds maxit_em. Default is 20 #' #' @seealso [PLN_param()] #' @export @@ -107,8 +107,8 @@ PLNnetwork_param <- function( } inception_cov <- match.arg(inception_cov) config_opt$trace <- trace - config_opt$ftol_out <- 1e-5 - config_opt$maxit_out <- 20 + config_opt$ftol_em <- 1e-5 + config_opt$maxit_em <- 20 config_opt[names(config_optim)] <- config_optim structure(list( diff --git a/R/PLNnetworkfit-class.R b/R/PLNnetworkfit-class.R index 87538587..78f283a9 100644 --- a/R/PLNnetworkfit-class.R +++ b/R/PLNnetworkfit-class.R @@ -53,8 +53,8 @@ PLNnetworkfit <- R6Class( #' @param config a list for controlling the optimization optimize = function(data, config) { cond <- FALSE; iter <- 0 - objective <- numeric(config$maxit_out) - convergence <- numeric(config$maxit_out) + objective <- numeric(config$maxit_em) + convergence <- numeric(config$maxit_em) ## start from the standard PLN at initialization objective.old <- -self$loglik args <- list(data = list(Y = data$Y, X = data$X, O = data$O, w = data$w), @@ -76,7 +76,7 @@ PLNnetworkfit <- R6Class( ## Check convergence objective[iter] <- -self$loglik # + self$penalty * sum(abs(private$Omega)) convergence[iter] <- abs(objective[iter] - objective.old)/abs(objective[iter]) - if ((convergence[iter] < config$ftol_out) | (iter >= config$maxit_out)) cond <- TRUE + if ((convergence[iter] < config$ftol_em) | (iter >= config$maxit_em)) cond <- TRUE ## Prepare next iterate args$params <- list(B = private$B, M = private$M, S = private$S) diff --git a/man/PLNmixture_param.Rd b/man/PLNmixture_param.Rd index a2637b98..766e16d4 100644 --- a/man/PLNmixture_param.Rd +++ b/man/PLNmixture_param.Rd @@ -43,8 +43,8 @@ Helper to define list of parameters to control the PLNmixture fit. All arguments \details{ See \code{\link[=PLN_param]{PLN_param()}} for a full description of the generic optimization parameters. PLNmixture_param() also has additional parameters controlling the optimization due the inner-outer loop structure of the optimizer: \itemize{ -\item "ftol_out" outer solver stops when an optimization step changes the objective function by less than xtol multiplied by the absolute value of the parameter. Default is 1e-6 -\item "maxit_out" outer solver stops when the number of iteration exceeds maxit_out. Default is 50 +\item "ftol_em" outer EM solver stops when the objective changes by less than ftol_em (relative). Default is 1e-3 +\item "maxit_em" outer EM solver stops when the number of iterations exceeds maxit_em. Default is 50 \item "it_smooth" number of the iterations of the smoothing procedure. Default is 1. } } diff --git a/man/PLNnetwork_param.Rd b/man/PLNnetwork_param.Rd index 546e6e2c..4faae29d 100644 --- a/man/PLNnetwork_param.Rd +++ b/man/PLNnetwork_param.Rd @@ -50,8 +50,8 @@ Helper to define list of parameters to control the PLN fit. All arguments have d \details{ See \code{\link[=PLN_param]{PLN_param()}} for a full description of the generic optimization parameters. PLNnetwork_param() also has two additional parameters controlling the optimization due the inner-outer loop structure of the optimizer: \itemize{ -\item "ftol_out" outer solver stops when an optimization step changes the objective function by less than ftol multiplied by the absolute value of the parameter. Default is 1e-6 -\item "maxit_out" outer solver stops when the number of iteration exceeds maxit_out. Default is 50 +\item "ftol_em" outer alternating solver stops when the objective changes by less than ftol_em (relative). Default is 1e-5 +\item "maxit_em" outer alternating solver stops when the number of iterations exceeds maxit_em. Default is 20 } } \seealso{ From 897869feb68ecd125889e4fbb9b04fc91148b4ee Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Wed, 10 Jun 2026 14:57:33 +0200 Subject: [PATCH 29/58] added S3 methods for logLik, AIC, BIC, ICL --- NAMESPACE | 12 +++++ R/PLN.R | 2 +- R/PLNfit-S3methods.R | 94 ++++++++++++++++++++++++++++++++++ R/ZIPLNfit-S3methods.R | 82 +++++++++++++++++++++++++++++ R/utils.R | 6 +-- inst/case_studies/oaks_tree.R | 2 +- man/AIC.PLNfit.Rd | 28 ++++++++++ man/AIC.ZIPLNfit.Rd | 28 ++++++++++ man/BIC.PLNfit.Rd | 26 ++++++++++ man/BIC.ZIPLNfit.Rd | 26 ++++++++++ man/ICL.Rd | 40 +++++++++++++++ man/PLNLDA_param.Rd | 2 +- man/PLNPCA_param.Rd | 2 +- man/PLN_param.Rd | 2 +- man/logLik.PLNfit.Rd | 27 ++++++++++ man/logLik.ZIPLNfit.Rd | 27 ++++++++++ src/newton_diag_cov.cpp | 4 +- src/newton_fixed_cov.cpp | 2 +- src/newton_full_cov.cpp | 4 +- src/newton_rank_cov.cpp | 4 +- src/newton_spherical.cpp | 4 +- src/spectral_rank_cov.cpp | 4 +- tests/testthat/test-plnfit.R | 39 ++++++++++++++ tests/testthat/test-ziplnfit.R | 39 ++++++++++++++ 24 files changed, 487 insertions(+), 19 deletions(-) create mode 100644 man/AIC.PLNfit.Rd create mode 100644 man/AIC.ZIPLNfit.Rd create mode 100644 man/BIC.PLNfit.Rd create mode 100644 man/BIC.ZIPLNfit.Rd create mode 100644 man/ICL.Rd create mode 100644 man/logLik.PLNfit.Rd create mode 100644 man/logLik.ZIPLNfit.Rd diff --git a/NAMESPACE b/NAMESPACE index 252b77dc..de3ca7c0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,11 @@ # Generated by roxygen2: do not edit by hand +S3method(AIC,PLNfit) +S3method(AIC,ZIPLNfit) +S3method(BIC,PLNfit) +S3method(BIC,ZIPLNfit) +S3method(ICL,PLNfit) +S3method(ICL,ZIPLNfit) S3method(coef,PLNLDAfit) S3method(coef,PLNfit) S3method(coef,PLNmixturefit) @@ -17,6 +23,8 @@ S3method(getModel,PLNPCAfamily) S3method(getModel,PLNmixturefamily) S3method(getModel,PLNnetworkfamily) S3method(getModel,ZIPLNnetworkfamily) +S3method(logLik,PLNfit) +S3method(logLik,ZIPLNfit) S3method(plot,Networkfamily) S3method(plot,PLNLDAfit) S3method(plot,PLNPCAfamily) @@ -43,6 +51,7 @@ S3method(standard_error,PLNmixturefit) S3method(standard_error,PLNnetworkfit) S3method(vcov,PLNfit) export("%>%") +export(ICL) export(PLN) export(PLNLDA) export(PLNLDA_param) @@ -109,6 +118,8 @@ importFrom(purrr,reduce) importFrom(rlang,.data) importFrom(stats,.getXlevels) importFrom(stats,.lm.fit) +importFrom(stats,AIC) +importFrom(stats,BIC) importFrom(stats,as.formula) importFrom(stats,binomial) importFrom(stats,coef) @@ -118,6 +129,7 @@ importFrom(stats,glm.control) importFrom(stats,glm.fit) importFrom(stats,lm.fit) importFrom(stats,lm.wfit) +importFrom(stats,logLik) importFrom(stats,mad) importFrom(stats,median) importFrom(stats,model.frame) diff --git a/R/PLN.R b/R/PLN.R index 6f59d366..c7e30764 100644 --- a/R/PLN.R +++ b/R/PLN.R @@ -93,7 +93,7 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { #' #' When "homemade" or "hybrid" backend is used, the following entries are relevant #' * "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 -#' * "ftol_rel" stop the inner loop when the objective changes by less than ftol_rel (relative). Default is 1e-8 +#' * "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 #' * "maxit_em" stop the EM outer loop when the number of EM iterations exceeds maxit_em. Default is 50 #' * "ftol_em" stop the EM outer loop when the ELBO changes by less than ftol_em (relative). Default is 1e-8 #' diff --git a/R/PLNfit-S3methods.R b/R/PLNfit-S3methods.R index efc41806..3a8cabd3 100644 --- a/R/PLNfit-S3methods.R +++ b/R/PLNfit-S3methods.R @@ -189,6 +189,100 @@ standard_error.PLNfit <- function(object, type = c("sandwich", "variational", "j attr(object$model_par[[par]], paste0("variance_", type)) %>% sqrt() } +#' Extract log-likelihood of a fitted PLN model +#' +#' @name logLik.PLNfit +#' @description Returns the variational lower bound of the log-likelihood as a `"logLik"` object, +#' compatible with [stats::AIC()] and [stats::BIC()]. +#' +#' @param object an R6 object with class [`PLNfit`] +#' @param ... additional parameters for S3 compatibility. Not used +#' @return An object of class `"logLik"`. The numeric value is the variational ELBO. +#' Attributes `df` and `nobs` hold the number of parameters and observations. +#' +#' @importFrom stats logLik +#' @export +#' @examples +#' data(trichoptera) +#' trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +#' model <- PLN(Abundance ~ 1, data = trichoptera) +#' logLik(model) +logLik.PLNfit <- function(object, ...) { + stopifnot(isPLNfit(object)) + structure(object$loglik, class = "logLik", df = object$nb_param, nobs = object$n) +} + +#' Akaike Information Criterion for a fitted PLN model +#' +#' @name AIC.PLNfit +#' @description Computes the variational AIC as `loglik - nb_param` (larger is better). +#' This follows the maximization convention used throughout PLNmodels. +#' +#' @param object an R6 object with class [`PLNfit`] +#' @param k not used, present for S3 compatibility. +#' @param ... additional parameters for S3 compatibility. Not used +#' @return A scalar: the variational AIC (larger is better). +#' +#' @importFrom stats AIC +#' @export +#' @examples +#' data(trichoptera) +#' trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +#' model <- PLN(Abundance ~ 1, data = trichoptera) +#' AIC(model) +AIC.PLNfit <- function(object, ..., k = 2) { + stopifnot(isPLNfit(object)) + object$AIC +} + +#' Bayesian Information Criterion for a fitted PLN model +#' +#' @name BIC.PLNfit +#' @description Computes the variational BIC as `loglik - 0.5 * log(n) * nb_param` (larger is better). +#' This follows the maximization convention used throughout PLNmodels. +#' +#' @param object an R6 object with class [`PLNfit`] +#' @param ... additional parameters for S3 compatibility. Not used +#' @return A scalar: the variational BIC (larger is better). +#' +#' @importFrom stats BIC +#' @export +#' @examples +#' data(trichoptera) +#' trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +#' model <- PLN(Abundance ~ 1, data = trichoptera) +#' BIC(model) +BIC.PLNfit <- function(object, ...) { + stopifnot(isPLNfit(object)) + object$BIC +} + +#' Integrated Classification Likelihood +#' +#' @name ICL +#' @description Generic function to compute the Integrated Classification Likelihood (ICL) of a fitted model. +#' ICL = BIC - entropy of the variational distribution (larger is better). +#' +#' @param object a fitted model object +#' @param ... additional parameters passed to methods +#' @return A scalar: the variational ICL (larger is better). +#' @export +ICL <- function(object, ...) UseMethod("ICL") + +#' @rdname ICL +#' @description `ICL.PLNfit`: ICL for a fitted [`PLNfit`]. +#' @param object an R6 object with class [`PLNfit`] +#' @export +#' @examples +#' data(trichoptera) +#' trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +#' model <- PLN(Abundance ~ 1, data = trichoptera) +#' ICL(model) +ICL.PLNfit <- function(object, ...) { + stopifnot(isPLNfit(object)) + object$ICL +} + #' @describeIn standard_error Component-wise standard errors of B in [`PLNfit_fixedcov`] #' @export standard_error.PLNfit_fixedcov <- function(object, type = c("sandwich", "variational", "jackknife", "bootstrap"), parameter = c("B", "Omega")) { diff --git a/R/ZIPLNfit-S3methods.R b/R/ZIPLNfit-S3methods.R index d6aabb84..f7c0da78 100644 --- a/R/ZIPLNfit-S3methods.R +++ b/R/ZIPLNfit-S3methods.R @@ -95,6 +95,88 @@ sigma.ZIPLNfit <- function(object, ...) { object$model_par$Sigma } +#' Extract log-likelihood of a fitted ZIPLN model +#' +#' @name logLik.ZIPLNfit +#' @description Returns the variational lower bound of the log-likelihood as a `"logLik"` object, +#' compatible with [stats::AIC()] and [stats::BIC()]. +#' +#' @param object an R6 object with class [`ZIPLNfit`] +#' @param ... additional parameters for S3 compatibility. Not used +#' @return An object of class `"logLik"`. The numeric value is the variational ELBO. +#' Attributes `df` and `nobs` hold the number of parameters and observations. +#' +#' @importFrom stats logLik +#' @export +#' @examples +#' data(trichoptera) +#' trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +#' model <- ZIPLN(Abundance ~ 1, data = trichoptera) +#' logLik(model) +logLik.ZIPLNfit <- function(object, ...) { + stopifnot(isZIPLNfit(object)) + structure(object$loglik, class = "logLik", df = object$nb_param, nobs = object$n) +} + +#' Akaike Information Criterion for a fitted ZIPLN model +#' +#' @name AIC.ZIPLNfit +#' @description Computes the variational AIC as `loglik - nb_param` (larger is better). +#' This follows the maximization convention used throughout PLNmodels. +#' +#' @param object an R6 object with class [`ZIPLNfit`] +#' @param k not used, present for S3 compatibility. +#' @param ... additional parameters for S3 compatibility. Not used +#' @return A scalar: the variational AIC (larger is better). +#' +#' @importFrom stats AIC +#' @export +#' @examples +#' data(trichoptera) +#' trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +#' model <- ZIPLN(Abundance ~ 1, data = trichoptera) +#' AIC(model) +AIC.ZIPLNfit <- function(object, ..., k = 2) { + stopifnot(isZIPLNfit(object)) + object$AIC +} + +#' Bayesian Information Criterion for a fitted ZIPLN model +#' +#' @name BIC.ZIPLNfit +#' @description Computes the variational BIC as `loglik - 0.5 * log(n) * nb_param` (larger is better). +#' This follows the maximization convention used throughout PLNmodels. +#' +#' @param object an R6 object with class [`ZIPLNfit`] +#' @param ... additional parameters for S3 compatibility. Not used +#' @return A scalar: the variational BIC (larger is better). +#' +#' @importFrom stats BIC +#' @export +#' @examples +#' data(trichoptera) +#' trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +#' model <- ZIPLN(Abundance ~ 1, data = trichoptera) +#' BIC(model) +BIC.ZIPLNfit <- function(object, ...) { + stopifnot(isZIPLNfit(object)) + object$BIC +} + +#' @rdname ICL +#' @description `ICL.ZIPLNfit`: ICL for a fitted [`ZIPLNfit`]. +#' @param object an R6 object with class [`ZIPLNfit`] +#' @export +#' @examples +#' data(trichoptera) +#' trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +#' model <- ZIPLN(Abundance ~ 1, data = trichoptera) +#' ICL(model) +ICL.ZIPLNfit <- function(object, ...) { + stopifnot(isZIPLNfit(object)) + object$ICL +} + ## ========================================================================================= ## ## PUBLIC S3 METHODS FOR ZIPLNfit_sparse diff --git a/R/utils.R b/R/utils.R index 89b958f7..480d1b25 100644 --- a/R/utils.R +++ b/R/utils.R @@ -19,7 +19,7 @@ config_default_homemade <- algorithm = "NEWTON", backend = "homemade", maxeval = 10000, - ftol_rel = 1e-8, + ftol_in = 1e-8, maxit_em = 50, ftol_em = 1e-8 ) @@ -33,7 +33,7 @@ make_hybrid_optimizer <- function(opt_nlopt, opt_newton) { # Phase 1: nlopt config with 10× looser tolerance for fast basin finding config1 <- modifyList(config_default_nlopt, list( maxeval = config$maxeval, - ftol_rel = config$ftol_rel * 10 + ftol_rel = config$ftol_in * 10 )) res1 <- opt_nlopt(data, params, config1) params2 <- modifyList(params, list(B = res1$B, M = res1$M, S = res1$S)) @@ -57,7 +57,7 @@ config_default_spectral <- algorithm = "SPECTRAL", backend = "homemade", maxeval = 10000, - ftol_rel = 1e-9 + ftol_in = 1e-9 ) config_default_torch <- diff --git a/inst/case_studies/oaks_tree.R b/inst/case_studies/oaks_tree.R index 5dc093bc..af5206b1 100644 --- a/inst/case_studies/oaks_tree.R +++ b/inst/case_studies/oaks_tree.R @@ -63,7 +63,7 @@ plot(myLDA_tree_diagonal) otu.family <- factor(rep(c("fungi", "E. aphiltoides", "bacteria"), c(47, 1, 66))) plot(myLDA_tree, "variable", var_cols = otu.family) ## TODO: add color for arrows to check -myLDA_tree_spherical <- PLNLDA(Abundance ~ 1 + offset(log(Offset)), grouping = tree, data = oaks, control = PLN_param(covariance = "spherical")) +myLDA_tree_spherical <- PLNLDA(Abundance ~ 1 + offset(log(Offset)), grouping = tree, data = oaks, control = PLNLDA_param(covariance = "spherical")) plot(myLDA_tree_spherical) ## One dimensional check of plot diff --git a/man/AIC.PLNfit.Rd b/man/AIC.PLNfit.Rd new file mode 100644 index 00000000..87978c52 --- /dev/null +++ b/man/AIC.PLNfit.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/PLNfit-S3methods.R +\name{AIC.PLNfit} +\alias{AIC.PLNfit} +\title{Akaike Information Criterion for a fitted PLN model} +\usage{ +\method{AIC}{PLNfit}(object, ..., k = 2) +} +\arguments{ +\item{object}{an R6 object with class \code{\link{PLNfit}}} + +\item{...}{additional parameters for S3 compatibility. Not used} + +\item{k}{not used, present for S3 compatibility.} +} +\value{ +A scalar: the variational AIC (larger is better). +} +\description{ +Computes the variational AIC as \code{loglik - nb_param} (larger is better). +This follows the maximization convention used throughout PLNmodels. +} +\examples{ +data(trichoptera) +trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +model <- PLN(Abundance ~ 1, data = trichoptera) +AIC(model) +} diff --git a/man/AIC.ZIPLNfit.Rd b/man/AIC.ZIPLNfit.Rd new file mode 100644 index 00000000..62eb39ab --- /dev/null +++ b/man/AIC.ZIPLNfit.Rd @@ -0,0 +1,28 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ZIPLNfit-S3methods.R +\name{AIC.ZIPLNfit} +\alias{AIC.ZIPLNfit} +\title{Akaike Information Criterion for a fitted ZIPLN model} +\usage{ +\method{AIC}{ZIPLNfit}(object, ..., k = 2) +} +\arguments{ +\item{object}{an R6 object with class \code{\link{ZIPLNfit}}} + +\item{...}{additional parameters for S3 compatibility. Not used} + +\item{k}{not used, present for S3 compatibility.} +} +\value{ +A scalar: the variational AIC (larger is better). +} +\description{ +Computes the variational AIC as \code{loglik - nb_param} (larger is better). +This follows the maximization convention used throughout PLNmodels. +} +\examples{ +data(trichoptera) +trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +model <- ZIPLN(Abundance ~ 1, data = trichoptera) +AIC(model) +} diff --git a/man/BIC.PLNfit.Rd b/man/BIC.PLNfit.Rd new file mode 100644 index 00000000..ef0be33c --- /dev/null +++ b/man/BIC.PLNfit.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/PLNfit-S3methods.R +\name{BIC.PLNfit} +\alias{BIC.PLNfit} +\title{Bayesian Information Criterion for a fitted PLN model} +\usage{ +\method{BIC}{PLNfit}(object, ...) +} +\arguments{ +\item{object}{an R6 object with class \code{\link{PLNfit}}} + +\item{...}{additional parameters for S3 compatibility. Not used} +} +\value{ +A scalar: the variational BIC (larger is better). +} +\description{ +Computes the variational BIC as \code{loglik - 0.5 * log(n) * nb_param} (larger is better). +This follows the maximization convention used throughout PLNmodels. +} +\examples{ +data(trichoptera) +trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +model <- PLN(Abundance ~ 1, data = trichoptera) +BIC(model) +} diff --git a/man/BIC.ZIPLNfit.Rd b/man/BIC.ZIPLNfit.Rd new file mode 100644 index 00000000..f508dc12 --- /dev/null +++ b/man/BIC.ZIPLNfit.Rd @@ -0,0 +1,26 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ZIPLNfit-S3methods.R +\name{BIC.ZIPLNfit} +\alias{BIC.ZIPLNfit} +\title{Bayesian Information Criterion for a fitted ZIPLN model} +\usage{ +\method{BIC}{ZIPLNfit}(object, ...) +} +\arguments{ +\item{object}{an R6 object with class \code{\link{ZIPLNfit}}} + +\item{...}{additional parameters for S3 compatibility. Not used} +} +\value{ +A scalar: the variational BIC (larger is better). +} +\description{ +Computes the variational BIC as \code{loglik - 0.5 * log(n) * nb_param} (larger is better). +This follows the maximization convention used throughout PLNmodels. +} +\examples{ +data(trichoptera) +trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +model <- ZIPLN(Abundance ~ 1, data = trichoptera) +BIC(model) +} diff --git a/man/ICL.Rd b/man/ICL.Rd new file mode 100644 index 00000000..8b5b8644 --- /dev/null +++ b/man/ICL.Rd @@ -0,0 +1,40 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/PLNfit-S3methods.R, R/ZIPLNfit-S3methods.R +\name{ICL} +\alias{ICL} +\alias{ICL.PLNfit} +\alias{ICL.ZIPLNfit} +\title{Integrated Classification Likelihood} +\usage{ +ICL(object, ...) + +\method{ICL}{PLNfit}(object, ...) + +\method{ICL}{ZIPLNfit}(object, ...) +} +\arguments{ +\item{object}{an R6 object with class \code{\link{ZIPLNfit}}} + +\item{...}{additional parameters passed to methods} +} +\value{ +A scalar: the variational ICL (larger is better). +} +\description{ +Generic function to compute the Integrated Classification Likelihood (ICL) of a fitted model. +ICL = BIC - entropy of the variational distribution (larger is better). + +\code{ICL.PLNfit}: ICL for a fitted \code{\link{PLNfit}}. + +\code{ICL.ZIPLNfit}: ICL for a fitted \code{\link{ZIPLNfit}}. +} +\examples{ +data(trichoptera) +trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +model <- PLN(Abundance ~ 1, data = trichoptera) +ICL(model) +data(trichoptera) +trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +model <- ZIPLN(Abundance ~ 1, data = trichoptera) +ICL(model) +} diff --git a/man/PLNLDA_param.Rd b/man/PLNLDA_param.Rd index 29325e0d..a19271ff 100644 --- a/man/PLNLDA_param.Rd +++ b/man/PLNLDA_param.Rd @@ -65,7 +65,7 @@ When "torch" backend is used (only for PLN and PLNLDA for now), the following en When "homemade" or "hybrid" backend is used, the following entries are relevant \itemize{ \item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 -\item "ftol_rel" stop the inner loop when the objective changes by less than ftol_rel (relative). Default is 1e-8 +\item "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 \item "maxit_em" stop the EM outer loop when the number of EM iterations exceeds maxit_em. Default is 50 \item "ftol_em" stop the EM outer loop when the ELBO changes by less than ftol_em (relative). Default is 1e-8 } diff --git a/man/PLNPCA_param.Rd b/man/PLNPCA_param.Rd index 19d9b053..7e0e9386 100644 --- a/man/PLNPCA_param.Rd +++ b/man/PLNPCA_param.Rd @@ -71,7 +71,7 @@ When "torch" backend is used (only for PLN and PLNLDA for now), the following en When "homemade" or "hybrid" backend is used, the following entries are relevant \itemize{ \item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 -\item "ftol_rel" stop the inner loop when the objective changes by less than ftol_rel (relative). Default is 1e-8 +\item "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 \item "maxit_em" stop the EM outer loop when the number of EM iterations exceeds maxit_em. Default is 50 \item "ftol_em" stop the EM outer loop when the ELBO changes by less than ftol_em (relative). Default is 1e-8 } diff --git a/man/PLN_param.Rd b/man/PLN_param.Rd index 1b429e11..3efc73a1 100644 --- a/man/PLN_param.Rd +++ b/man/PLN_param.Rd @@ -70,7 +70,7 @@ When "torch" backend is used (only for PLN and PLNLDA for now), the following en When "homemade" or "hybrid" backend is used, the following entries are relevant \itemize{ \item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 -\item "ftol_rel" stop the inner loop when the objective changes by less than ftol_rel (relative). Default is 1e-8 +\item "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 \item "maxit_em" stop the EM outer loop when the number of EM iterations exceeds maxit_em. Default is 50 \item "ftol_em" stop the EM outer loop when the ELBO changes by less than ftol_em (relative). Default is 1e-8 } diff --git a/man/logLik.PLNfit.Rd b/man/logLik.PLNfit.Rd new file mode 100644 index 00000000..2de424eb --- /dev/null +++ b/man/logLik.PLNfit.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/PLNfit-S3methods.R +\name{logLik.PLNfit} +\alias{logLik.PLNfit} +\title{Extract log-likelihood of a fitted PLN model} +\usage{ +\method{logLik}{PLNfit}(object, ...) +} +\arguments{ +\item{object}{an R6 object with class \code{\link{PLNfit}}} + +\item{...}{additional parameters for S3 compatibility. Not used} +} +\value{ +An object of class \code{"logLik"}. The numeric value is the variational ELBO. +Attributes \code{df} and \code{nobs} hold the number of parameters and observations. +} +\description{ +Returns the variational lower bound of the log-likelihood as a \code{"logLik"} object, +compatible with \code{\link[stats:AIC]{stats::AIC()}} and \code{\link[stats:BIC]{stats::BIC()}}. +} +\examples{ +data(trichoptera) +trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +model <- PLN(Abundance ~ 1, data = trichoptera) +logLik(model) +} diff --git a/man/logLik.ZIPLNfit.Rd b/man/logLik.ZIPLNfit.Rd new file mode 100644 index 00000000..ffbbe6d3 --- /dev/null +++ b/man/logLik.ZIPLNfit.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ZIPLNfit-S3methods.R +\name{logLik.ZIPLNfit} +\alias{logLik.ZIPLNfit} +\title{Extract log-likelihood of a fitted ZIPLN model} +\usage{ +\method{logLik}{ZIPLNfit}(object, ...) +} +\arguments{ +\item{object}{an R6 object with class \code{\link{ZIPLNfit}}} + +\item{...}{additional parameters for S3 compatibility. Not used} +} +\value{ +An object of class \code{"logLik"}. The numeric value is the variational ELBO. +Attributes \code{df} and \code{nobs} hold the number of parameters and observations. +} +\description{ +Returns the variational lower bound of the log-likelihood as a \code{"logLik"} object, +compatible with \code{\link[stats:AIC]{stats::AIC()}} and \code{\link[stats:BIC]{stats::BIC()}}. +} +\examples{ +data(trichoptera) +trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +model <- ZIPLN(Abundance ~ 1, data = trichoptera) +logLik(model) +} diff --git a/src/newton_diag_cov.cpp b/src/newton_diag_cov.cpp index 817804d3..277ecf99 100644 --- a/src/newton_diag_cov.cpp +++ b/src/newton_diag_cov.cpp @@ -24,7 +24,7 @@ Rcpp::List newton_optimize_diagonal( arma::mat S = Rcpp::as(params["S"]); const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; const int max_em = config.containsElementNamed("maxit_em") ? Rcpp::as(config["maxit_em"]) : 50; const double em_tol = config.containsElementNamed("ftol_em") ? Rcpp::as(config["ftol_em"]) : 1e-8; @@ -54,7 +54,7 @@ Rcpp::List newton_optimize_vestep_diagonal( arma::mat S = Rcpp::as(params["S"]); const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; DiagonalCovTraits::State state(Omega); return newton_vestep_impl(Y, X, O, w, M, S, B, state, maxiter, ftol); diff --git a/src/newton_fixed_cov.cpp b/src/newton_fixed_cov.cpp index 3e0827c2..44eea435 100644 --- a/src/newton_fixed_cov.cpp +++ b/src/newton_fixed_cov.cpp @@ -24,7 +24,7 @@ Rcpp::List newton_optimize_fixed( arma::mat Omega = Rcpp::as(params["Omega"]); const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; const int max_em = config.containsElementNamed("maxit_em") ? Rcpp::as(config["maxit_em"]) : 50; const double em_tol = config.containsElementNamed("ftol_em") ? Rcpp::as(config["ftol_em"]) : 1e-8; diff --git a/src/newton_full_cov.cpp b/src/newton_full_cov.cpp index df0f7f5f..9bced978 100644 --- a/src/newton_full_cov.cpp +++ b/src/newton_full_cov.cpp @@ -24,7 +24,7 @@ Rcpp::List newton_optimize_full( arma::mat S = Rcpp::as(params["S"]); const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; const int max_em = config.containsElementNamed("maxit_em") ? Rcpp::as(config["maxit_em"]) : 50; const double em_tol = config.containsElementNamed("ftol_em") ? Rcpp::as(config["ftol_em"]) : 1e-8; @@ -54,7 +54,7 @@ Rcpp::List newton_optimize_vestep_full( arma::mat S = Rcpp::as(params["S"]); const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; FullCovTraits::State state(Omega); return newton_vestep_impl(Y, X, O, w, M, S, B, state, maxiter, ftol); diff --git a/src/newton_rank_cov.cpp b/src/newton_rank_cov.cpp index fecd1587..31b51e89 100644 --- a/src/newton_rank_cov.cpp +++ b/src/newton_rank_cov.cpp @@ -32,7 +32,7 @@ Rcpp::List newton_optimize_rank( arma::mat S = Rcpp::as(params["S"]); const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; const arma::uword n = Y.n_rows; const arma::uword q = C.n_cols; @@ -221,7 +221,7 @@ Rcpp::List newton_optimize_vestep_rank( arma::mat S = Rcpp::as(params["S"]); const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; const arma::uword n = Y.n_rows; const arma::uword q = C.n_cols; diff --git a/src/newton_spherical.cpp b/src/newton_spherical.cpp index 1c13e469..2e6ca3f9 100644 --- a/src/newton_spherical.cpp +++ b/src/newton_spherical.cpp @@ -24,7 +24,7 @@ Rcpp::List newton_optimize_spherical( arma::mat S = Rcpp::as(params["S"]); const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; const int max_em = config.containsElementNamed("maxit_em") ? Rcpp::as(config["maxit_em"]) : 50; const double em_tol = config.containsElementNamed("ftol_em") ? Rcpp::as(config["ftol_em"]) : 1e-8; @@ -54,7 +54,7 @@ Rcpp::List newton_optimize_vestep_spherical( arma::mat S = Rcpp::as(params["S"]); const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-8; + const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; SphericalCovTraits::State state(Omega); return newton_vestep_impl(Y, X, O, w, M, S, B, state, maxiter, ftol); diff --git a/src/spectral_rank_cov.cpp b/src/spectral_rank_cov.cpp index c4c291a1..0bc5a3e8 100644 --- a/src/spectral_rank_cov.cpp +++ b/src/spectral_rank_cov.cpp @@ -52,7 +52,7 @@ Rcpp::List spectral_optimize_rank( arma::mat S = Rcpp::as(params["S"]); const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 10000; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-10; + const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-10; const double c_armijo = 1e-4; const int nm_window = 10; // GLL nonmonotone window size @@ -217,7 +217,7 @@ Rcpp::List spectral_optimize_vestep_rank( arma::mat S = Rcpp::as(params["S"]); const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 10000; - const double ftol = config.containsElementNamed("ftol_rel") ? Rcpp::as(config["ftol_rel"]) : 1e-10; + const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-10; const double c_armijo = 1e-4; const int nm_window = 10; diff --git a/tests/testthat/test-plnfit.R b/tests/testthat/test-plnfit.R index b4be97ca..f95d3986 100644 --- a/tests/testthat/test-plnfit.R +++ b/tests/testthat/test-plnfit.R @@ -197,6 +197,45 @@ test_that("PLN fit: Check conditional prediction with sparse covariance models", } }) +test_that("PLN fit: S3 methods logLik, AIC, BIC, ICL", { + + model <- PLN(Abundance ~ 1, data = trichoptera) + + ## logLik returns a proper "logLik" S3 object + ll <- logLik(model) + expect_s3_class(ll, "logLik") + expect_equal(as.numeric(ll), model$loglik) + expect_equal(attr(ll, "df"), model$nb_param) + expect_equal(attr(ll, "nobs"), model$n) + + ## AIC and BIC match the active bindings (maximization convention: larger is better) + expect_equal(AIC(model), model$AIC) + expect_equal(BIC(model), model$BIC) + expect_equal(ICL(model), model$ICL) + + ## Numeric scalars + expect_true(is.numeric(AIC(model)) && length(AIC(model)) == 1L) + expect_true(is.numeric(BIC(model)) && length(BIC(model)) == 1L) + expect_true(is.numeric(ICL(model)) && length(ICL(model)) == 1L) + + ## BIC ≤ AIC (stronger penalty) and ICL ≤ BIC (additional entropy term) + expect_lte(BIC(model), AIC(model)) + expect_lte(ICL(model), BIC(model)) + + ## Consistency across covariance structures + for (cov in c("diagonal", "spherical")) { + m <- PLN(Abundance ~ 1, data = trichoptera, + control = PLN_param(covariance = cov, trace = 0)) + ll_m <- logLik(m) + expect_s3_class(ll_m, "logLik") + expect_equal(as.numeric(ll_m), m$loglik) + expect_equal(attr(ll_m, "df"), m$nb_param) + expect_equal(AIC(m), m$AIC) + expect_equal(BIC(m), m$BIC) + expect_equal(ICL(m), m$ICL) + } +}) + test_that("PLN fit: Check number of parameters", { p <- ncol(trichoptera$Abundance) diff --git a/tests/testthat/test-ziplnfit.R b/tests/testthat/test-ziplnfit.R index 135a3032..db3663a7 100644 --- a/tests/testthat/test-ziplnfit.R +++ b/tests/testthat/test-ziplnfit.R @@ -91,6 +91,45 @@ test_that("PLN fit: Check prediction", { expect_length(predict(model, newdata = toy_data[3:4, ], type = "r"), 2L) }) +test_that("ZIPLN fit: S3 methods logLik, AIC, BIC, ICL", { + + model <- ZIPLN(Abundance ~ 1, data = trichoptera) + + ## logLik returns a proper "logLik" S3 object + ll <- logLik(model) + expect_s3_class(ll, "logLik") + expect_equal(as.numeric(ll), model$loglik) + expect_equal(attr(ll, "df"), model$nb_param) + expect_equal(attr(ll, "nobs"), model$n) + + ## AIC and BIC match the active bindings (maximization convention: larger is better) + expect_equal(AIC(model), model$AIC) + expect_equal(BIC(model), model$BIC) + expect_equal(ICL(model), model$ICL) + + ## Numeric scalars + expect_true(is.numeric(AIC(model)) && length(AIC(model)) == 1L) + expect_true(is.numeric(BIC(model)) && length(BIC(model)) == 1L) + expect_true(is.numeric(ICL(model)) && length(ICL(model)) == 1L) + + ## BIC ≤ AIC (stronger penalty) and ICL ≤ BIC (additional entropy term) + expect_lte(BIC(model), AIC(model)) + expect_lte(ICL(model), BIC(model)) + + ## Consistency across covariance structures + for (cov in c("diagonal", "spherical")) { + m <- ZIPLN(Abundance ~ 1, data = trichoptera, + control = ZIPLN_param(covariance = cov, trace = 0)) + ll_m <- logLik(m) + expect_s3_class(ll_m, "logLik") + expect_equal(as.numeric(ll_m), m$loglik) + expect_equal(attr(ll_m, "df"), m$nb_param) + expect_equal(AIC(m), m$AIC) + expect_equal(BIC(m), m$BIC) + expect_equal(ICL(m), m$ICL) + } +}) + test_that("ZIPLN fit: Check number of parameters", { p <- ncol(trichoptera$Abundance) From d1e7fa902baf1946a36a3106366a09e5ac637072 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Wed, 10 Jun 2026 15:11:45 +0200 Subject: [PATCH 30/58] pkgdown ref --- _pkgdown.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/_pkgdown.yml b/_pkgdown.yml index 7deb44d4..3b75a9fd 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -60,6 +60,9 @@ reference: - '`predict_cond.PLNfit`' - '`fitted.PLNfit`' - '`standard_error.PLNfit`' + - '`logLik.PLNfit`' + - '`AIC.PLNfit`' + - '`BIC.PLNfit`' - title: 'Zero Inflated Poisson lognormal fit' desc: > Description of the ZIPLNfit object and methods for its manipulation. @@ -71,6 +74,9 @@ reference: - '`predict.ZIPLNfit`' - '`fitted.ZIPLNfit`' - '`plot.ZIPLNfit_sparse`' + - '`logLik.ZIPLNfit`' + - '`AIC.ZIPLNfit`' + - '`BIC.ZIPLNfit`' - title: 'Linear discriminant analysis via a Poisson lognormal fit' desc: > Description of the PLNLDAfit object and methods for its manipulation. @@ -132,6 +138,7 @@ reference: - '`PLNfamily`' - '`plot.PLNfamily`' - '`rPLN`' + - '`ICL`' - '`compute_PLN_starting_point`' - title: Data sets desc: ~ @@ -142,4 +149,3 @@ reference: - '`barents`' - '`mollusk`' - '`scRNA`' - From ff8c9c7c968e349c59ec7b8e16fd581ad8f47e9e Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Wed, 10 Jun 2026 15:40:32 +0200 Subject: [PATCH 31/58] improvements and consistency of R code --- R/PLN.R | 12 +--- R/PLNLDA.R | 15 +---- R/PLNLDAfit-class.R | 42 +++++------- R/PLNPCA.R | 13 +--- R/PLNPCAfit-class.R | 2 +- R/PLNfit-class.R | 100 +++++++++++++--------------- R/PLNmixture.R | 16 +---- R/PLNnetwork.R | 15 +---- R/utils.R | 23 +++++++ man/PLNLDAfit.Rd | 10 +-- man/PLNPCAfit.Rd | 4 +- tests/testthat/test-plnnetworkfit.R | 2 +- 12 files changed, 105 insertions(+), 149 deletions(-) diff --git a/R/PLN.R b/R/PLN.R index c7e30764..68a2e7eb 100644 --- a/R/PLN.R +++ b/R/PLN.R @@ -126,17 +126,7 @@ PLN_param <- function( ## optimization config backend <- match.arg(backend) - if (backend == "nlopt") { - stopifnot(config_optim$algorithm %in% available_algorithms_nlopt) - config_opt <- config_default_nlopt - } else if (backend == "torch") { - stopifnot(config_optim$algorithm %in% available_algorithms_torch) - config_opt <- config_default_torch - } else { # "homemade" or "hybrid" - config_opt <- config_default_homemade - } - config_opt[names(config_optim)] <- config_optim - config_opt$trace <- trace + config_opt <- make_config_optim(backend, config_optim, trace) structure(list( backend = backend , diff --git a/R/PLNLDA.R b/R/PLNLDA.R index facc4a31..8d745ad9 100644 --- a/R/PLNLDA.R +++ b/R/PLNLDA.R @@ -55,7 +55,7 @@ PLNLDA <- function(formula, data, subset, weights, grouping, control = PLNLDA_pa 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, control$config_optim) + myLDA$postTreatment(grouping, args$Y, args$X, args$O, args$w, control$config_post, control$config_optim) if (control$trace > 0) cat("\n DONE!\n") myLDA @@ -95,18 +95,7 @@ PLNLDA_param <- function( config_pst$trace <- trace ## optimization config - backend <- match.arg(backend) - if (backend == "nlopt") { - stopifnot(config_optim$algorithm %in% available_algorithms_nlopt) - config_opt <- config_default_nlopt - } else if (backend == "torch") { - stopifnot(config_optim$algorithm %in% available_algorithms_torch) - config_opt <- config_default_torch - } else { # "homemade" or "hybrid" - config_opt <- config_default_homemade - } - config_opt[names(config_optim)] <- config_optim - config_opt$trace <- trace + config_opt <- make_config_optim(backend, config_optim, trace) structure(list( backend = backend , diff --git a/R/PLNLDAfit-class.R b/R/PLNLDAfit-class.R index 650adb3d..9c2c3a86 100644 --- a/R/PLNLDAfit-class.R +++ b/R/PLNLDAfit-class.R @@ -84,11 +84,16 @@ PLNLDAfit <- R6Class( ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ## Post treatment -------------------- #' @description Update R2, fisher and std_err fields and visualization + #' @param grouping a factor with group memberships + #' @param responses the matrix of responses (counts) + #' @param covariates the matrix of covariates + #' @param offsets the matrix of offsets + #' @param weights an optional vector of observation weights. Default is uniform weights. #' @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) { + postTreatment = function(grouping, responses, covariates, offsets, weights = rep(1, nrow(responses)), config_post, config_optim) { covariates <- cbind(covariates, model.matrix( ~ grouping + 0)) - super$postTreatment(responses, covariates, offsets, config_post = config_post, config_optim = config_optim) + super$postTreatment(responses, covariates, offsets, weights, config_post = config_post, config_optim = config_optim) rownames(private$C) <- colnames(private$C) <- colnames(responses) colnames(private$S) <- 1:self$q if (config_post$trace > 1) cat("\n\tCompute LD scores for visualization...") @@ -406,16 +411,9 @@ PLNLDAfit_diagonal <- R6Class( #' @description Initialize a [`PLNfit`] model initialize = function(grouping, responses, covariates, offsets, weights, formula, control) { super$initialize(grouping, responses, covariates, offsets, weights, formula, control) - private$optimizer$main <- if (control$backend == "torch") { - private$torch_optimize - } else if (control$backend == "homemade") { - newton_optimize_diagonal - } else if (control$backend == "hybrid") { - make_hybrid_optimizer(nlopt_optimize_diagonal, newton_optimize_diagonal) - } else { - nlopt_optimize_diagonal - } - private$optimizer$vestep <- if (control$backend %in% c("homemade", "hybrid")) newton_optimize_vestep_diagonal else nlopt_optimize_vestep_diagonal + private$setup_optimizer(control$backend, + nlopt_optimize_diagonal, newton_optimize_diagonal, + nlopt_optimize_vestep_diagonal, newton_optimize_vestep_diagonal) } ), private = list( @@ -440,13 +438,12 @@ PLNLDAfit_diagonal <- R6Class( }, torch_vloglik = function(data, params) { - S2 <- torch_pow(params$S, 2) + S2 <- torch_square(params$S) omega_diag <- torch_pow(private$torch_sigma_diag(data, params), -1) - Ji <- .5 * self$p - rowSums(.logfactorial(as.matrix(data$Y))) + as.numeric( .5 * sum(torch_log(omega_diag)) + - torch_sum(data$Y * params$Z - params$A + .5 * torch_log(S2), dim = 2) - - .5 * torch_matmul(torch_pow(params$M, 2) + S2, omega_diag) + torch_sum(data$Y * params$Z - params$A + .5 * torch_log(S2) - + .5 * (torch_square(params$M) + S2) * omega_diag[NULL,], dim = 2) ) attr(Ji, "weights") <- as.numeric(data$w) Ji @@ -504,16 +501,9 @@ PLNLDAfit_spherical <- R6Class( #' @description Initialize a [`PLNfit`] model initialize = function(grouping, responses, covariates, offsets, weights, formula, control) { super$initialize(grouping, responses, covariates, offsets, weights, formula, control) - private$optimizer$main <- if (control$backend == "torch") { - private$torch_optimize - } else if (control$backend == "homemade") { - newton_optimize_spherical - } else if (control$backend == "hybrid") { - make_hybrid_optimizer(nlopt_optimize_spherical, newton_optimize_spherical) - } else { - nlopt_optimize_spherical - } - private$optimizer$vestep <- if (control$backend %in% c("homemade", "hybrid")) newton_optimize_vestep_spherical else nlopt_optimize_vestep_spherical + private$setup_optimizer(control$backend, + nlopt_optimize_spherical, newton_optimize_spherical, + nlopt_optimize_vestep_spherical, newton_optimize_vestep_spherical) } ), private = list( diff --git a/R/PLNPCA.R b/R/PLNPCA.R index a67cdfe5..402d2e53 100644 --- a/R/PLNPCA.R +++ b/R/PLNPCA.R @@ -98,17 +98,8 @@ PLNPCA_param <- function( ## optimization config backend <- match.arg(backend) - if (backend == "nlopt") { - stopifnot(config_optim$algorithm %in% available_algorithms_nlopt) - config_opt <- config_default_nlopt - } else if (backend == "torch") { - stopifnot(config_optim$algorithm %in% available_algorithms_torch) - config_opt <- config_default_torch - } else { # "homemade" — spectral gradient method - config_opt <- config_default_spectral - } - config_opt[names(config_optim)] <- config_optim - config_opt$trace <- trace + config_opt <- make_config_optim(backend, config_optim, trace, + homemade_default = config_default_spectral) config_opt$sequential <- sequential structure(list( diff --git a/R/PLNPCAfit-class.R b/R/PLNPCAfit-class.R index e045df12..3df1e079 100644 --- a/R/PLNPCAfit-class.R +++ b/R/PLNPCAfit-class.R @@ -375,7 +375,7 @@ PLNPCAfit <- R6Class( #' * 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_post, config_optim, nullModel) { + postTreatment = function(responses, covariates, offsets, weights = rep(1, nrow(responses)), config_post, config_optim, nullModel = NULL) { 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) diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index 1210debe..dc388c65 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -58,6 +58,7 @@ PLNfit <- R6Class( A = NA , # matrix of expected counts (under variational approximation) Ji = NA , # element-wise approximated loglikelihood R2 = NA , # approximated goodness of fit criterion + w = NULL , # observation weights, stored at initialization optimizer = list(), # list of links to the functions doing the optimization monitoring = list(), # list with optimization monitoring quantities @@ -322,6 +323,24 @@ PLNfit <- R6Class( lmin <- logLikPoisson(responses, nullModel, weights) lmax <- logLikPoisson(responses, log(responses), weights) private$R2 <- (loglik - lmin) / (lmax - lmin) + }, + + ## Set optimizer$main and (optionally) optimizer$vestep from the four covariance-specific + ## C++ functions. Called by every subclass initialize() so the dispatch logic lives once. + setup_optimizer = function(backend, nlopt_fn, newton_fn, + nlopt_vestep_fn = NULL, newton_vestep_fn = NULL) { + private$optimizer$main <- if (backend == "torch") { + private$torch_optimize + } else if (backend == "homemade") { + newton_fn + } else if (backend == "hybrid") { + make_hybrid_optimizer(nlopt_fn, newton_fn) + } else { + nlopt_fn + } + if (!is.null(nlopt_vestep_fn)) + private$optimizer$vestep <- + if (backend %in% c("homemade", "hybrid")) newton_vestep_fn else nlopt_vestep_fn } ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -345,6 +364,7 @@ PLNfit <- R6Class( n <- nrow(responses); p <- ncol(responses); d <- ncol(covariates) ## set up various quantities private$formula <- formula # user formula call + private$w <- weights ## initialize the variational parameters if (isPLNfit(control$inception)) { if (control$trace > 1) cat("\n User defined inceptive PLN model") @@ -360,16 +380,9 @@ PLNfit <- R6Class( private$M <- start_point$M private$S <- start_point$S } - private$optimizer$main <- if (control$backend == "torch") { - private$torch_optimize - } else if (control$backend == "homemade") { - newton_optimize_full - } else if (control$backend == "hybrid") { - make_hybrid_optimizer(nlopt_optimize_full, newton_optimize_full) - } else { - nlopt_optimize_full - } - private$optimizer$vestep <- if (control$backend %in% c("homemade", "hybrid")) newton_optimize_vestep_full else nlopt_optimize_vestep_full + private$setup_optimizer(control$backend, + nlopt_optimize_full, newton_optimize_full, + nlopt_optimize_vestep_full, newton_optimize_vestep_full) }, ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -387,16 +400,16 @@ PLNfit <- R6Class( #' @param monitoring a list with optimization monitoring quantities #' @return Update the current [`PLNfit`] object update = function(B=NA, Sigma=NA, Omega=NA, M=NA, S=NA, Ji=NA, R2=NA, Z=NA, A=NA, monitoring=NA) { - if (!anyNA(B)) private$B <- B - if (!anyNA(Sigma)) private$Sigma <- Sigma - if (!anyNA(Omega)) private$Omega <- Omega - if (!anyNA(M)) private$M <- M - if (!anyNA(S)) private$S <- S - if (!anyNA(Z)) private$Z <- Z - if (!anyNA(A)) private$A <- A - if (!anyNA(Ji)) private$Ji <- Ji - if (!anyNA(R2)) private$R2 <- R2 - if (!anyNA(monitoring)) private$monitoring <- monitoring + if (!identical(B, NA)) private$B <- B + if (!identical(Sigma, NA)) private$Sigma <- Sigma + if (!identical(Omega, NA)) private$Omega <- Omega + if (!identical(M, NA)) private$M <- M + if (!identical(S, NA)) private$S <- S + if (!identical(Z, NA)) private$Z <- Z + if (!identical(A, NA)) private$A <- A + if (!identical(Ji, NA)) private$Ji <- Ji + if (!identical(R2, NA)) private$R2 <- R2 + if (!identical(monitoring, NA)) private$monitoring <- monitoring }, ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -672,7 +685,7 @@ PLNfit <- R6Class( #' @field var_par a list with the matrices of the variational parameters: M (means) and S2 (variances) var_par = function() {list(M = private$M, S2 = private$S**2, S = private$S)}, #' @field optim_par a list with parameters useful for monitoring the optimization - optim_par = function() {c(private$monitoring, backend = private$backend)}, + optim_par = function() {private$monitoring}, #' @field latent a matrix: values of the latent vector (Z in the model) latent = function() {private$Z}, #' @field latent_pos a matrix: values of the latent position vector (Z) without covariates effects or offset @@ -684,9 +697,13 @@ PLNfit <- R6Class( #' @field vcov_model character: the model used for the residual covariance vcov_model = function() {"full"}, #' @field weights observational weights - weights = function() {as.numeric(attr(private$Ji, "weights"))}, + weights = function() {private$w}, #' @field loglik (weighted) variational lower bound of the loglikelihood - loglik = function() {sum(self$weights[self$weights > .Machine$double.eps] * private$Ji[self$weights > .Machine$double.eps]) }, + loglik = function() { + if (!is.numeric(private$Ji)) return(0) + w <- self$weights + sum(w[w > .Machine$double.eps] * private$Ji[w > .Machine$double.eps]) + }, #' @field loglik_vec element-wise variational lower bound of the loglikelihood loglik_vec = function() {private$Ji}, #' @field AIC variational lower bound of the AIC @@ -742,16 +759,9 @@ PLNfit_diagonal <- R6Class( #' @description Initialize a [`PLNfit`] model initialize = function(responses, covariates, offsets, weights, formula, control) { super$initialize(responses, covariates, offsets, weights, formula, control) - private$optimizer$main <- if (control$backend == "torch") { - private$torch_optimize - } else if (control$backend == "homemade") { - newton_optimize_diagonal - } else if (control$backend == "hybrid") { - make_hybrid_optimizer(nlopt_optimize_diagonal, newton_optimize_diagonal) - } else { - nlopt_optimize_diagonal - } - private$optimizer$vestep <- if (control$backend %in% c("homemade", "hybrid")) newton_optimize_vestep_diagonal else nlopt_optimize_vestep_diagonal + private$setup_optimizer(control$backend, + nlopt_optimize_diagonal, newton_optimize_diagonal, + nlopt_optimize_vestep_diagonal, newton_optimize_vestep_diagonal) } ), private = list( @@ -833,16 +843,9 @@ PLNfit_spherical <- R6Class( #' @description Initialize a [`PLNfit`] model initialize = function(responses, covariates, offsets, weights, formula, control) { super$initialize(responses, covariates, offsets, weights, formula, control) - private$optimizer$main <- if (control$backend == "torch") { - private$torch_optimize - } else if (control$backend == "homemade") { - newton_optimize_spherical - } else if (control$backend == "hybrid") { - make_hybrid_optimizer(nlopt_optimize_spherical, newton_optimize_spherical) - } else { - nlopt_optimize_spherical - } - private$optimizer$vestep <- if (control$backend %in% c("homemade", "hybrid")) newton_optimize_vestep_spherical else nlopt_optimize_vestep_spherical + private$setup_optimizer(control$backend, + nlopt_optimize_spherical, newton_optimize_spherical, + nlopt_optimize_vestep_spherical, newton_optimize_vestep_spherical) } ), private = list( @@ -928,16 +931,7 @@ PLNfit_fixedcov <- R6Class( #' @description Initialize a [`PLNfit`] model initialize = function(responses, covariates, offsets, weights, formula, control) { super$initialize(responses, covariates, offsets, weights, formula, control) - private$optimizer$main <- if (control$backend == "torch") { - private$torch_optimize - } else if (control$backend == "homemade") { - newton_optimize_fixed - } else if (control$backend == "hybrid") { - make_hybrid_optimizer(nlopt_optimize_fixed, newton_optimize_fixed) - } else { - nlopt_optimize_fixed - } - ## ve step is the same as in the fully parameterized covariance + private$setup_optimizer(control$backend, nlopt_optimize_fixed, newton_optimize_fixed) private$Omega <- control$Omega }, #' @description Call to the NLopt or TORCH optimizer and update of the relevant fields diff --git a/R/PLNmixture.R b/R/PLNmixture.R index 5a5c4214..c90eda8b 100644 --- a/R/PLNmixture.R +++ b/R/PLNmixture.R @@ -107,20 +107,8 @@ PLNmixture_param <- function( ## optimization config backend <- match.arg(backend) - if (backend == "nlopt") { - stopifnot(config_optim$algorithm %in% available_algorithms_nlopt) - config_opt <- config_default_nlopt - } else if (backend == "torch") { - stopifnot(config_optim$algorithm %in% available_algorithms_torch) - config_opt <- config_default_torch - } else { # "homemade" or "hybrid" - config_opt <- config_default_homemade - } - config_opt$ftol_em <- 1e-3 - config_opt$maxit_em <- 50 - config_opt$it_smooth <- 1 - config_opt[names(config_optim)] <- config_optim - config_opt$trace <- trace + config_opt <- make_config_optim(backend, config_optim, trace, + extra = list(ftol_em = 1e-3, maxit_em = 50, it_smooth = 1)) structure(list( backend = backend , diff --git a/R/PLNnetwork.R b/R/PLNnetwork.R index 1e08b159..34945ec9 100644 --- a/R/PLNnetwork.R +++ b/R/PLNnetwork.R @@ -96,20 +96,9 @@ PLNnetwork_param <- function( ## optimization config backend <- match.arg(backend) - if (backend == "nlopt") { - stopifnot(config_optim$algorithm %in% available_algorithms_nlopt) - config_opt <- config_default_nlopt - } else if (backend == "torch") { - stopifnot(config_optim$algorithm %in% available_algorithms_torch) - config_opt <- config_default_torch - } else { # "homemade" or "hybrid" - config_opt <- config_default_homemade - } inception_cov <- match.arg(inception_cov) - config_opt$trace <- trace - config_opt$ftol_em <- 1e-5 - config_opt$maxit_em <- 20 - config_opt[names(config_optim)] <- config_optim + config_opt <- make_config_optim(backend, config_optim, trace, + extra = list(ftol_em = 1e-5, maxit_em = 20)) structure(list( backend = backend , diff --git a/R/utils.R b/R/utils.R index 480d1b25..30c42b20 100644 --- a/R/utils.R +++ b/R/utils.R @@ -79,6 +79,29 @@ config_default_torch <- device = "cpu" ) +## Build the optimizer config list from a backend name and user overrides. +## `homemade_default` lets PLNPCA pass config_default_spectral instead of config_default_homemade. +## `extra` is a named list of additional defaults applied BEFORE user overrides (so the user can +## still override them), used for outer-loop parameters like ftol_em/maxit_em in PLNnetwork and +## PLNmixture. +make_config_optim <- function(backend, config_optim, trace, + homemade_default = config_default_homemade, + extra = list()) { + config_opt <- if (backend == "nlopt") { + stopifnot(config_optim$algorithm %in% available_algorithms_nlopt) + config_default_nlopt + } else if (backend == "torch") { + stopifnot(config_optim$algorithm %in% available_algorithms_torch) + config_default_torch + } else { + homemade_default + } + config_opt$trace <- trace + config_opt[names(extra)] <- extra + config_opt[names(config_optim)] <- config_optim + config_opt +} + config_post_default_PLN <- list( jackknife = FALSE, diff --git a/man/PLNLDAfit.Rd b/man/PLNLDAfit.Rd index a58d2a2c..2740381b 100644 --- a/man/PLNLDAfit.Rd +++ b/man/PLNLDAfit.Rd @@ -138,6 +138,7 @@ latent space, update corresponding fields responses, covariates, offsets, + weights = rep(1, nrow(responses)), config_post, config_optim )} @@ -146,10 +147,11 @@ latent space, update corresponding fields \subsection{Arguments}{ \if{html}{\out{
}} \describe{ - \item{\code{grouping}}{a factor specifying the class of each observation used for discriminant analysis.} - \item{\code{responses}}{the matrix of responses (called Y in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - \item{\code{covariates}}{design matrix (called X in the model). Will usually be extracted from the corresponding field in PLNfamily-class} - \item{\code{offsets}}{offset matrix (called O in the model). Will usually be extracted from the corresponding field in PLNfamily-class} + \item{\code{grouping}}{a factor with group memberships} + \item{\code{responses}}{the matrix of responses (counts)} + \item{\code{covariates}}{the matrix of covariates} + \item{\code{offsets}}{the matrix of offsets} + \item{\code{weights}}{an optional vector of observation weights. Default is uniform weights.} \item{\code{config_post}}{a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.).} \item{\code{config_optim}}{list controlling the optimization parameters} } diff --git a/man/PLNPCAfit.Rd b/man/PLNPCAfit.Rd index 9d5b5ecb..fc47e2d0 100644 --- a/man/PLNPCAfit.Rd +++ b/man/PLNPCAfit.Rd @@ -287,10 +287,10 @@ are carried over; new columns are padded using the inception SVD (C) or zeros/0. responses, covariates, offsets, - weights, + weights = rep(1, nrow(responses)), config_post, config_optim, - nullModel + nullModel = NULL )} \if{html}{\out{
}} } diff --git a/tests/testthat/test-plnnetworkfit.R b/tests/testthat/test-plnnetworkfit.R index 412a2017..5a731325 100644 --- a/tests/testthat/test-plnnetworkfit.R +++ b/tests/testthat/test-plnnetworkfit.R @@ -65,7 +65,7 @@ test_that("PLNnetwork fit accepts torch backend", { lr = 0.01, num_epoch = 5, num_batch = 1, - maxit_out = 2 + maxit_em = 2 ) ) From cf3d960ba3796ebd90a954b5c23ba24d24701981 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Wed, 10 Jun 2026 22:14:26 +0200 Subject: [PATCH 32/58] factorizing roxygen doc --- R/PLN.R | 24 +++++++------ R/PLNLDA.R | 12 ++----- R/PLNLDAfit-class.R | 16 +++++---- R/PLNPCA.R | 12 ++----- R/PLNfit-class.R | 56 +++++++++++++++++-------------- R/PLNmixture.R | 15 +++------ R/PLNmixturefamily-class.R | 2 +- R/PLNmixturefit-class.R | 14 +++----- R/PLNnetwork.R | 15 +++------ R/PLNnetworkfit-class.R | 3 +- R/utils.R | 50 ++++++++++++++++++++------- man/PLN.Rd | 2 +- man/PLNLDA.Rd | 2 +- man/PLNPCA.Rd | 2 +- man/PLN_param.Rd | 5 ++- man/PLNmixture.Rd | 2 +- man/PLNmixture_param.Rd | 51 ++++++++++++++++++++++++++-- man/PLNnetwork.Rd | 2 +- man/PLNnetwork_param.Rd | 51 ++++++++++++++++++++++++++-- man/ZIPLN.Rd | 2 +- man/ZIPLNnetwork.Rd | 2 +- man/ZIPLNnetwork_param.Rd | 2 +- man/compute_PLN_starting_point.Rd | 17 ++++++++-- src/newton_diag_cov.cpp | 3 +- src/newton_full_cov.cpp | 3 +- src/newton_impl.h | 31 +++++++++-------- src/newton_impl_alt.h | 23 +++++-------- src/newton_spherical.cpp | 3 +- src/nlopt_diag_cov.cpp | 32 +++++++++--------- src/nlopt_fixed_cov.cpp | 14 ++++---- src/nlopt_full_cov.cpp | 36 ++++++++++---------- src/nlopt_spherical.cpp | 32 +++++++++--------- tests/testthat/test-pln.R | 14 ++++---- 33 files changed, 337 insertions(+), 213 deletions(-) diff --git a/R/PLN.R b/R/PLN.R index 68a2e7eb..7e96822a 100644 --- a/R/PLN.R +++ b/R/PLN.R @@ -3,7 +3,7 @@ #' Fit the multivariate Poisson lognormal model with a variational algorithm. Use the (g)lm syntax for model specification (covariates, offsets, weights). #' #' @param formula an object of class "formula": a symbolic description of the model to be fitted. -#' @param data an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which PLN is called. +#' @param data an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which the model is called. #' @param subset an optional vector specifying a subset of observations to be used in the fitting process. #' @param weights an optional vector of observation weights to be used in the fitting process. #' @param control a list-like structure for controlling the optimization, with default generated by [PLN_param()]. See the associated documentation @@ -65,6 +65,7 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { #' @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. +#' @param init_method character: strategy for the starting-point computation (ignored when `inception` is a PLNfit). Either `"LM"` (default) or `"GLM"` (p independent Poisson GLMs, better for complex or unbalanced designs). See [compute_PLN_starting_point()]. #' #' @return list of parameters configuring the fit. #' @@ -112,10 +113,12 @@ PLN_param <- function( Omega = NULL, config_post = list(), config_optim = list(), - inception = NULL # pretrained PLNfit used as initialization + inception = NULL, + init_method = c("LM", "GLM") ) { - covariance <- match.arg(covariance) + covariance <- match.arg(covariance) + init_method <- match.arg(init_method) if (covariance == "fixed") stopifnot(inherits(Omega, "matrix") | inherits(Omega, "Matrix")) if (!is.null(inception)) stopifnot(isPLNfit(inception)) @@ -129,11 +132,12 @@ PLN_param <- function( config_opt <- make_config_optim(backend, config_optim, trace) structure(list( - backend = backend , - trace = trace , - covariance = covariance, - Omega = Omega , - config_post = config_pst, - config_optim = config_opt, - inception = inception), class = "PLNmodels_param") + backend = backend , + trace = trace , + covariance = covariance , + Omega = Omega , + config_post = config_pst , + config_optim = config_opt , + init_method = init_method, + inception = inception ), class = "PLNmodels_param") } diff --git a/R/PLNLDA.R b/R/PLNLDA.R index 8d745ad9..1decd50f 100644 --- a/R/PLNLDA.R +++ b/R/PLNLDA.R @@ -2,10 +2,7 @@ #' #' Fit the Poisson lognormal for LDA with a variational algorithm. Use the (g)lm syntax for model specification (covariates, offsets). #' -#' @param formula an object of class "formula": a symbolic description of the model to be fitted. -#' @param data an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which lm is called. -#' @param subset an optional vector specifying a subset of observations to be used in the fitting process. -#' @param weights an optional vector of observation weights to be used in the fitting process. +#' @inheritParams PLN formula data subset weights #' @param grouping a factor specifying the class of each observation used for discriminant analysis. #' @param control a list-like structure for controlling the optimization, with default generated by [PLNLDA_param()]. See the associated documentation. #' @@ -67,12 +64,7 @@ PLNLDA <- function(formula, data, subset, weights, grouping, control = PLNLDA_pa #' #' @param backend optimization back used, either "nlopt" or "torch". Default is "nlopt" #' @param covariance character setting the model for the covariance matrix. Either "full", "diagonal" or "spherical". Default is "full". -#' @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 trace a integer for verbosity. -#' @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. +#' @inheritParams PLN_param trace config_optim config_post inception #' #' @return list of parameters configuring the fit. #' @inherit PLN_param details diff --git a/R/PLNLDAfit-class.R b/R/PLNLDAfit-class.R index 9c2c3a86..967f9c9e 100644 --- a/R/PLNLDAfit-class.R +++ b/R/PLNLDAfit-class.R @@ -423,14 +423,15 @@ PLNLDAfit_diagonal <- R6Class( torch_elbo = function(data, params, index=torch_tensor(1:self$n)) { S2 <- torch_square(params$S[index]) - Z <- data$O[index] + params$M[index] + torch_matmul(data$X[index], params$B) + Z <- data$O[index] + params$M[index] # Z = O + M_full res <- .5 * sum(data$w[index]) * sum(torch_log(private$torch_sigma_diag(data, params, index))) + sum(data$w[index,NULL] * (torch_exp(Z + .5 * S2) - data$Y[index] * Z - .5 * torch_log(S2))) res }, torch_sigma_diag = function(data, params, index=torch_tensor(1:self$n)) { - torch_sum(data$w[index,NULL] * (torch_square(params$M[index]) + torch_square(params$S[index])), 1) / sum(data$w[index]) + M_res <- params$M[index] - torch_mm(data$X[index], params$B) # M_res for covariance + torch_sum(data$w[index,NULL] * (torch_square(M_res) + torch_square(params$S[index])), 1) / sum(data$w[index]) }, torch_Sigma = function(data, params, index=torch_tensor(1:self$n)) { @@ -439,11 +440,12 @@ PLNLDAfit_diagonal <- R6Class( torch_vloglik = function(data, params) { S2 <- torch_square(params$S) + M_res <- params$M - torch_mm(data$X, params$B) # M_res for KL terms omega_diag <- torch_pow(private$torch_sigma_diag(data, params), -1) Ji <- .5 * self$p - rowSums(.logfactorial(as.matrix(data$Y))) + as.numeric( .5 * sum(torch_log(omega_diag)) + torch_sum(data$Y * params$Z - params$A + .5 * torch_log(S2) - - .5 * (torch_square(params$M) + S2) * omega_diag[NULL,], dim = 2) + .5 * (torch_square(M_res) + S2) * omega_diag[NULL,], dim = 2) ) attr(Ji, "weights") <- as.numeric(data$w) Ji @@ -513,14 +515,15 @@ PLNLDAfit_spherical <- R6Class( ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% torch_elbo = function(data, params, index=torch_tensor(1:self$n)) { S2 <- torch_square(params$S[index]) - Z <- data$O[index] + params$M[index] + torch_mm(data$X[index], params$B) + Z <- data$O[index] + params$M[index] # Z = O + M_full res <- .5 * sum(data$w[index]) * self$p * torch_log(private$torch_sigma2(data, params, index)) - sum(data$w[index,NULL] * (data$Y[index] * Z - torch_exp(Z + .5 * S2) + .5 * torch_log(S2))) res }, torch_sigma2 = function(data, params, index=torch_tensor(1:self$n)) { - sum(data$w[index, NULL] * (torch_square(params$M) + torch_square(params$S))) / (sum(data$w) * self$p) + M_res <- params$M[index] - torch_mm(data$X[index], params$B) # M_res for covariance + sum(data$w[index, NULL] * (torch_square(M_res) + torch_square(params$S[index]))) / (sum(data$w[index]) * self$p) }, torch_Sigma = function(data, params, index=torch_tensor(1:self$n)) { @@ -529,9 +532,10 @@ PLNLDAfit_spherical <- R6Class( torch_vloglik = function(data, params) { S2 <- torch_pow(params$S, 2) + M_res <- params$M - torch_mm(data$X, params$B) # M_res for KL terms sigma2 <- private$torch_sigma2(data, params) Ji <- .5 * self$p - rowSums(.logfactorial(as.matrix(data$Y))) + as.numeric( - torch_sum(data$Y * params$Z - params$A + .5 * torch_log(S2/sigma2) - .5 * (torch_pow(params$M, 2) + S2)/sigma2, dim = 2) + torch_sum(data$Y * params$Z - params$A + .5 * torch_log(S2/sigma2) - .5 * (torch_pow(M_res, 2) + S2)/sigma2, dim = 2) ) attr(Ji, "weights") <- as.numeric(data$w) Ji diff --git a/R/PLNPCA.R b/R/PLNPCA.R index 402d2e53..943e3d3a 100644 --- a/R/PLNPCA.R +++ b/R/PLNPCA.R @@ -2,10 +2,7 @@ #' #' Fit the PCA variants of the Poisson lognormal with a variational algorithm. Use the (g)lm syntax for model specification (covariates, offsets). #' -#' @param formula an object of class "formula": a symbolic description of the model to be fitted. -#' @param data an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which lm is called. -#' @param subset an optional vector specifying a subset of observations to be used in the fitting process. -#' @param weights an optional vector of observation weights to be used in the fitting process. +#' @inheritParams PLN formula data subset weights #' @param ranks a vector of integer containing the successive ranks (or number of axes to be considered) #' @param control a list-like structure for controlling the optimization, with default generated by [PLNPCA_param()]. See the associated documentation. #' for details. @@ -64,12 +61,7 @@ PLNPCA <- function(formula, data, subset, weights, ranks = 1:5, control = PLNPCA #' @param backend optimization back used, either "nlopt", "torch", or "homemade". Default is "nlopt". #' Use "homemade" for the built-in coordinate-Newton optimizer (exact diagonal Newton steps for #' B, M, C, and closed-form update for S in log(S²) space), which does not depend on 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. +#' @inheritParams PLN_param trace config_optim config_post inception #' @param sequential logical. If `TRUE`, ranks are fitted in ascending order and each model is #' warm-started from the converged solution of the previous rank: loadings C are augmented #' with new columns from the inception SVD, while latent scores M and variances S are diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index dc388c65..a40c8173 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -59,6 +59,7 @@ PLNfit <- R6Class( Ji = NA , # element-wise approximated loglikelihood R2 = NA , # approximated goodness of fit criterion w = NULL , # observation weights, stored at initialization + X = NULL , # design matrix, stored at initialization for latent_pos optimizer = list(), # list of links to the functions doing the optimization monitoring = list(), # list with optimization monitoring quantities @@ -67,7 +68,7 @@ PLNfit <- R6Class( ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% torch_elbo = function(data, params, index=torch_tensor(1:self$n)) { S2 <- torch_square(params$S[index]) - Z <- data$O[index] + params$M[index] + torch_mm(data$X[index], params$B) + Z <- data$O[index] + params$M[index] # Z = O + M_full A <- torch_exp(Z + .5 * S2) res <- .5 * sum(data$w[index]) * torch_logdet(private$torch_Sigma(data, params, index)) + sum(data$w[index,NULL] * (A - data$Y[index] * Z - .5 * torch_log(S2))) @@ -76,8 +77,9 @@ PLNfit <- R6Class( torch_Sigma = function(data, params, index=torch_tensor(1:self$n)) { ws <- torch_sqrt(data$w[index, NULL]) + M_res <- params$M[index] - torch_mm(data$X[index], params$B) # M_res for covariance S2_bar <- torch_sum(torch_square(ws * params$S[index]), 1) - MtM <- torch_mm(torch_t(ws * params$M[index]), ws * params$M[index]) + MtM <- torch_mm(torch_t(ws * M_res), ws * M_res) (MtM + torch_diag(S2_bar)) / sum(ws*ws) }, @@ -87,10 +89,11 @@ PLNfit <- R6Class( torch_vloglik = function(data, params) { S2 <- torch_square(params$S) + M_res <- params$M - torch_mm(data$X, params$B) # M_res for KL terms Ji_tmp = .5 * torch_logdet(params$Omega) + torch_sum(data$Y * params$Z - params$A + .5 * torch_log(S2), dim = 2) - - .5 * torch_sum(torch_mm(params$M, params$Omega) * params$M + S2 * torch_diag(params$Omega), dim = 2) + .5 * torch_sum(torch_mm(M_res, params$Omega) * M_res + S2 * torch_diag(params$Omega), dim = 2) Ji <- - torch_sum(.logfactorial_torch(data$Y), dim = 2) + Ji_tmp Ji <- .5 * self$p + as.numeric(Ji$cpu()) @@ -168,7 +171,7 @@ PLNfit <- R6Class( params$Sigma <- private$torch_Sigma(data, params) params$Omega <- private$torch_Omega(data, params) - params$Z <- data$O + params$M + torch_matmul(data$X, params$B) + params$Z <- data$O + params$M # Z = O + M_full params$A <- torch_exp(params$Z + torch_pow(params$S, 2)/2) out <- lapply(params, function(x) { @@ -365,6 +368,7 @@ PLNfit <- R6Class( ## set up various quantities private$formula <- formula # user formula call private$w <- weights + private$X <- covariates ## initialize the variational parameters if (isPLNfit(control$inception)) { if (control$trace > 1) cat("\n User defined inceptive PLN model") @@ -375,7 +379,8 @@ PLNfit <- R6Class( private$S <- control$inception$var_par$S } else { if (control$trace > 1) cat("\n Use LM after log transformation to define the inceptive model") - start_point <- compute_PLN_starting_point(Y = responses, X = covariates, O = offsets, w = weights) + start_point <- compute_PLN_starting_point(Y = responses, X = covariates, O = offsets, w = weights, + method = if (is.null(control$init_method)) "LM" else control$init_method) private$B <- start_point$B private$M <- start_point$M private$S <- start_point$S @@ -439,7 +444,7 @@ PLNfit <- R6Class( n <- nrow(responses); p <- ncol(responses) ## initialize variational parameters with current value if dimension is the same if ((p != self$p) || (n != self$n)) { - params0 <- list(M = matrix(0, n, p), S = matrix(.1, n, p)) + params0 <- list(M = covariates %*% B, S = matrix(.1, n, p)) } else { params0 <- list(M = self$var_par$M, S = self$var_par$S) } @@ -537,11 +542,6 @@ PLNfit <- R6Class( O <- model.offset(model.frame(formula(private$formula)[-2], newdata)) if (is.null(O)) O <- matrix(0, n_new, self$p) - ## mean latent positions in the parameter space (covariates/offset only) - EZ <- X %*% private$B + O - rownames(EZ) <- rownames(newdata) - colnames(EZ) <- colnames(private$Sigma) - ## Optimize M and S if responses are provided, if (level == 1) { VE <- self$optimize_vestep( @@ -552,19 +552,20 @@ PLNfit <- R6Class( B = private$B, Omega = private$Omega ) - M <- VE$M + M <- VE$M # M_full S2 <- (VE$S)**2 } else { - # otherwise set M = 0 and S2 = diag(Sigma) - M <- matrix(0, nrow = n_new, ncol = self$p) + # population prediction: M_full = X*B (M_res = 0) + M <- X %*% private$B S2 <- matrix(diag(private$Sigma), nrow = n_new, ncol = self$p, byrow = TRUE) } + rownames(M) <- rownames(newdata) type <- match.arg(type) results <- switch( type, - link = EZ + M, - response = exp(EZ + M + 0.5 * S2) + link = O + M, + response = exp(O + M + 0.5 * S2) ) attr(results, "type") <- type results @@ -618,7 +619,8 @@ PLNfit <- R6Class( Omega = prec11 ) - M <- tcrossprod(VE$M, A) + M_res_VE <- VE$M - X %*% self$model_par$B[, cond, drop = FALSE] + M <- tcrossprod(M_res_VE, A) S <- map(1:n_new, ~crossprod(VE$S[., ] * t(A)) + Sigma21) %>% simplify2array() ## mean latent positions in the parameter space @@ -689,7 +691,7 @@ PLNfit <- R6Class( #' @field latent a matrix: values of the latent vector (Z in the model) latent = function() {private$Z}, #' @field latent_pos a matrix: values of the latent position vector (Z) without covariates effects or offset - latent_pos = function() {private$M}, + latent_pos = function() {private$M - private$X %*% private$B}, #' @field fitted a matrix: fitted values of the observations (A in the model) fitted = function() {private$A}, #' @field vcov_coef matrix of sandwich estimator of the variance-covariance of B (need fixed -ie known- covariance at the moment) @@ -771,14 +773,15 @@ PLNfit_diagonal <- R6Class( torch_elbo = function(data, params, index=torch_tensor(1:self$n)) { S2 <- torch_square(params$S[index]) - Z <- data$O[index] + params$M[index] + torch_matmul(data$X[index], params$B) + Z <- data$O[index] + params$M[index] # Z = O + M_full res <- .5 * sum(data$w[index]) * sum(torch_log(private$torch_sigma_diag(data, params, index))) + sum(data$w[index,NULL] * (torch_exp(Z + .5 * S2) - data$Y[index] * Z - .5 * torch_log(S2))) res }, torch_sigma_diag = function(data, params, index=torch_tensor(1:self$n)) { - torch_sum(data$w[index,NULL] * (torch_square(params$M[index]) + torch_square(params$S[index])), 1) / sum(data$w[index]) + M_res <- params$M[index] - torch_mm(data$X[index], params$B) # M_res for covariance + torch_sum(data$w[index,NULL] * (torch_square(M_res) + torch_square(params$S[index])), 1) / sum(data$w[index]) }, torch_Sigma = function(data, params, index=torch_tensor(1:self$n)) { @@ -787,11 +790,12 @@ PLNfit_diagonal <- R6Class( torch_vloglik = function(data, params) { S2 <- torch_square(params$S) + M_res <- params$M - torch_mm(data$X, params$B) # M_res for KL terms omega_diag <- torch_pow(private$torch_sigma_diag(data, params), -1) Ji <- .5 * self$p - rowSums(.logfactorial(as.matrix(data$Y))) + as.numeric( .5 * sum(torch_log(omega_diag)) + torch_sum(data$Y * params$Z - params$A + .5 * torch_log(S2) - - .5 * (torch_square(params$M) + S2) * omega_diag[NULL,], dim = 2) + .5 * (torch_square(M_res) + S2) * omega_diag[NULL,], dim = 2) ) attr(Ji, "weights") <- as.numeric(data$w) Ji @@ -855,14 +859,15 @@ PLNfit_spherical <- R6Class( ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% torch_elbo = function(data, params, index=torch_tensor(1:self$n)) { S2 <- torch_square(params$S[index]) - Z <- data$O[index] + params$M[index] + torch_mm(data$X[index], params$B) + Z <- data$O[index] + params$M[index] # Z = O + M_full res <- .5 * sum(data$w[index]) * self$p * torch_log(private$torch_sigma2(data, params, index)) - sum(data$w[index,NULL] * (data$Y[index] * Z - torch_exp(Z + .5 * S2) + .5 * torch_log(S2))) res }, torch_sigma2 = function(data, params, index=torch_tensor(1:self$n)) { - sum(data$w[index, NULL] * (torch_square(params$M) + torch_square(params$S))) / (sum(data$w) * self$p) + M_res <- params$M[index] - torch_mm(data$X[index], params$B) # M_res for covariance + sum(data$w[index, NULL] * (torch_square(M_res) + torch_square(params$S[index]))) / (sum(data$w[index]) * self$p) }, torch_Sigma = function(data, params, index=torch_tensor(1:self$n)) { @@ -871,9 +876,10 @@ PLNfit_spherical <- R6Class( torch_vloglik = function(data, params) { S2 <- torch_pow(params$S, 2) + M_res <- params$M - torch_mm(data$X, params$B) # M_res for KL terms sigma2 <- private$torch_sigma2(data, params) Ji <- .5 * self$p - rowSums(.logfactorial(as.matrix(data$Y))) + as.numeric( - torch_sum(data$Y * params$Z - params$A + .5 * torch_log(S2/sigma2) - .5 * (torch_pow(params$M, 2) + S2)/sigma2, dim = 2) + torch_sum(data$Y * params$Z - params$A + .5 * torch_log(S2/sigma2) - .5 * (torch_pow(M_res, 2) + S2)/sigma2, dim = 2) ) attr(Ji, "weights") <- as.numeric(data$w) Ji @@ -951,7 +957,7 @@ PLNfit_fixedcov <- R6Class( ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% torch_elbo = function(data, params, index=torch_tensor(1:self$n)) { S2 <- torch_square(params$S[index]) - Z <- data$O[index] + params$M[index] + torch_mm(data$X[index], params$B) + Z <- data$O[index] + params$M[index] # Z = O + M_full res <- sum(data$w) * torch_trace(torch_mm(private$torch_Sigma(data, params, index), private$torch_Omega(data, params))) + sum(data$w[index,NULL] * (torch_exp(Z + .5 * S2) - data$Y[index] * Z - .5 * torch_log(S2))) res diff --git a/R/PLNmixture.R b/R/PLNmixture.R index c90eda8b..e2bcb964 100644 --- a/R/PLNmixture.R +++ b/R/PLNmixture.R @@ -2,9 +2,7 @@ #' #' Fit the mixture variants of the Poisson lognormal with a variational algorithm. Use the (g)lm syntax for model specification (covariates, offsets). #' -#' @param formula an object of class "formula": a symbolic description of the model to be fitted. -#' @param data an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which lm is called. -#' @param subset an optional vector specifying a subset of observations to be used in the fitting process. +#' @inheritParams PLN formula data subset #' @param clusters a vector of integer containing the successive number of clusters (or components) to be considered #' @param control a list-like structure for controlling the optimization, with default generated by [PLNmixture_param()]. See the associated documentation #' for details. @@ -73,15 +71,12 @@ PLNmixture <- function(formula, data, subset, clusters = 1:5, control = PLNmixt #' @param covariance character setting the model for the covariance matrices of the mixture components. Either "full", "diagonal" or "spherical". Default is "spherical". #' @param smoothing The smoothing to apply. Either, 'none', forward', 'backward' or 'both'. Default is 'both'. #' @param init_cl The initial clustering to apply. Either, 'kmeans', CAH' or a user defined clustering given as a list of clusterings, the size of which is equal to the number of clusters considered. Default is 'kmeans'. -#' @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.). -#' @param trace a integer for verbosity. -#' @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. +#' @inheritParams PLN_param trace config_optim config_post inception #' #' @return list of parameters configuring the fit. -#' @details See [PLN_param()] for a full description of the generic optimization parameters. PLNmixture_param() also has additional parameters controlling the optimization due the inner-outer loop structure of the optimizer: +#' @inherit PLN_param details +#' @section Outer-loop optimization parameters: +#' `PLNmixture_param()` adds parameters controlling the EM and smoothing outer loops: #' * "ftol_em" outer EM solver stops when the objective changes by less than ftol_em (relative). Default is 1e-3 #' * "maxit_em" outer EM solver stops when the number of iterations exceeds maxit_em. Default is 50 #' * "it_smooth" number of the iterations of the smoothing procedure. Default is 1. diff --git a/R/PLNmixturefamily-class.R b/R/PLNmixturefamily-class.R index 598bca88..55f38d75 100644 --- a/R/PLNmixturefamily-class.R +++ b/R/PLNmixturefamily-class.R @@ -171,7 +171,7 @@ PLNmixturefamily <- myPLN <- PLNfit$new(responses, covariates, offsets, rep(1, nrow(responses)), formula, control) myPLN$optimize(responses, covariates, offsets, rep(1, nrow(responses)), control$config_optim) Sbar <- rowSums(myPLN$var_par$S2) - D <- sqrt(as.matrix(dist(myPLN$var_par$M)^2) + outer(Sbar,rep(1,myPLN$n)) + outer(rep(1, myPLN$n), Sbar)) + D <- sqrt(as.matrix(dist(myPLN$latent_pos)^2) + outer(Sbar,rep(1,myPLN$n)) + outer(rep(1, myPLN$n), Sbar)) clusterings <-switch(control$init_cl, "kmeans" = lapply(clusters, function(k) kmeans(D, centers = k, nstart = 30)$cl), "ward.D2" = D %>% as.dist() %>% hclust(method = "ward.D2") %>% cutree(clusters) %>% as.data.frame() %>% as.list() diff --git a/R/PLNmixturefit-class.R b/R/PLNmixturefit-class.R index c1b4e293..73adbe09 100644 --- a/R/PLNmixturefit-class.R +++ b/R/PLNmixturefit-class.R @@ -45,10 +45,7 @@ PLNmixturefit <- M <- private$comp %>% map("var_par") %>% map("M") S2 <- private$comp %>% map("var_par") %>% map("S2") - mu <- private$comp %>% map(coef) %>% map(~outer(rep(1, self$n), as.numeric(.x))) - - Ak_tilde <- list(M, S2, mu) %>% - purrr::pmap(function(M_k, S2_k, mu_k) exp(O + mu_k + M_k + .5 * S2_k)) + Ak_tilde <- map2(M, S2, function(M_k, S2_k) exp(O + M_k + .5 * S2_k)) Tk <- asplit(private$tau, 2) @@ -231,7 +228,7 @@ PLNmixturefit <- "position" = { latent_pos <- array(0, dim = c(nrow(args$X), self$k, self$p)) for (k in seq.int(self$k)) { - latent_pos[ , k, ] <- ve_step[[k]]$M + rep(1, nrow(args$X)) %o% self$group_means[, k] + latent_pos[ , k, ] <- ve_step[[k]]$M } res <- apply(latent_pos * tau %o% rep(1, self$p), c(1, 3), sum) rownames(res) <- rownames(newdata) @@ -250,8 +247,7 @@ PLNmixturefit <- plot_clustering_data = function(main = "Expected counts reorder by clustering", plot = TRUE, log_scale = TRUE) { M <- private$mix_up('var_par$M') S2 <- private$mix_up('var_par$S2') - mu <- self$posteriorProb %*% t(self$group_means) - A <- exp(mu + M + .5 * S2) + A <- exp(M + .5 * S2) p <- plot_matrix(A, 'samples', 'variables', self$memberships, log_scale) if (plot) print(p) invisible(p) @@ -263,7 +259,7 @@ PLNmixturefit <- #' @param main character. A title for the plot. An hopefully appropriate title will be used by default. #' @return a [`ggplot2::ggplot`] graphic plot_clustering_pca = function(main = "Clustering labels in Individual Factor Map", plot = TRUE) { - mu <- self$posteriorProb %*% t(self$group_means) + private$mix_up('var_par$M') + mu <- private$mix_up('var_par$M') svdM <- svd(scale(mu, TRUE, FALSE), nv = 2) .scores <- data.frame(t(t(svdM$u[, 1:2]) * svdM$d[1:2])) colnames(.scores) <- paste("a",1:2,sep = "") @@ -328,7 +324,7 @@ PLNmixturefit <- #' @field latent a matrix: values of the latent vector (Z in the model) latent = function() {private$mix_up('latent')}, #' @field latent_pos a matrix: values of the latent position vector (Z) without covariates effects or offset - latent_pos = function() {private$mix_up('var_par$M') + self$posteriorProb %*% t(self$group_means)}, + latent_pos = function() {private$mix_up('var_par$M')}, #' @field posteriorProb matrix ofposterior probability for cluster belonging posteriorProb = function(value) {if (missing(value)) return(private$tau) else private$tau <- value}, #' @field memberships vector for cluster index diff --git a/R/PLNnetwork.R b/R/PLNnetwork.R index 34945ec9..7223e20e 100644 --- a/R/PLNnetwork.R +++ b/R/PLNnetwork.R @@ -4,10 +4,7 @@ #' using a variational algorithm. Iterate over a range of logarithmically spaced sparsity parameter values. #' Use the (g)lm syntax to specify the model (including covariates and offsets). #' -#' @param formula an object of class "formula": a symbolic description of the model to be fitted. -#' @param data an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which lm is called. -#' @param subset an optional vector specifying a subset of observations to be used in the fitting process. -#' @param weights an optional vector of observation weights to be used in the fitting process. +#' @inheritParams PLN formula data subset weights #' @param penalties an optional vector of positive real number controlling the level of sparsity of the underlying network. if NULL (the default), will be set internally. See `PLNnetwork_param()` for additional tuning of the penalty. #' @param control a list-like structure for controlling the optimization, with default generated by [PLNnetwork_param()]. See the corresponding documentation for details; #' @@ -55,20 +52,16 @@ PLNnetwork <- function(formula, data, subset, weights, penalties = NULL, control #' @param backend optimization back used, either "nlopt", "homemade", "hybrid" or "torch". Default is "nlopt". #' Note: the "nlopt" backend converges better in PLNnetwork's outer glasso alternation than "homemade". #' @param inception_cov Covariance structure used for the inception model used to initialize the PLNfamily. Defaults to "full" and can be constrained to "diagonal" and "spherical". -#' @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-treatment (optional bootstrap, jackknife, R2, etc). -#' @param trace a integer for verbosity. #' @param n_penalties an integer that specifies the number of values for the penalty grid when internally generated. Ignored when penalties is non `NULL` #' @param min_ratio the penalty grid ranges from the minimal value that produces a sparse to this value multiplied by `min_ratio`. Default is 0.1. #' @param penalize_diagonal boolean: should the diagonal terms be penalized in the graphical-Lasso? Default is \code{TRUE} #' @param penalty_weights either a single or a list of p x p matrix of weights (default: all weights equal to 1) to adapt the amount of shrinkage to each pairs of node. Must be symmetric with positive values. -#' @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. +#' @inheritParams PLN_param trace config_optim config_post inception #' #' @return list of parameters configuring the fit. #' @inherit PLN_param details -#' @details See [PLN_param()] for a full description of the generic optimization parameters. PLNnetwork_param() also has two additional parameters controlling the optimization due the inner-outer loop structure of the optimizer: +#' @section Outer-loop optimization parameters: +#' `PLNnetwork_param()` adds two parameters controlling the alternating GLASSO/VEM loop: #' * "ftol_em" outer alternating solver stops when the objective changes by less than ftol_em (relative). Default is 1e-5 #' * "maxit_em" outer alternating solver stops when the number of iterations exceeds maxit_em. Default is 20 #' diff --git a/R/PLNnetworkfit-class.R b/R/PLNnetworkfit-class.R index 78f283a9..f01fd1f0 100644 --- a/R/PLNnetworkfit-class.R +++ b/R/PLNnetworkfit-class.R @@ -60,7 +60,8 @@ PLNnetworkfit <- R6Class( args <- list(data = list(Y = data$Y, X = data$X, O = data$O, w = data$w), params = list(B = private$B, M = private$M, S = private$S), config = config) - private$Sigma <- crossprod(private$M)/self$n + diag(colMeans(private$S**2), self$p, self$p) + M_res_init <- private$M - private$X %*% private$B + private$Sigma <- crossprod(M_res_init)/self$n + diag(colMeans(private$S**2), self$p, self$p) while (!cond) { iter <- iter + 1 if (config$trace > 1) cat("", iter) diff --git a/R/utils.R b/R/utils.R index 30c42b20..e32dad4d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -219,9 +219,17 @@ extract_model <- function(call, envir) { } else { stopifnot(all(w > 0) && length(w) == nrow(Y)) } - ## Save encountered levels for predict methods as attribute of the formula - attr(call$formula, "xlevels") <- .getXlevels(terms(frame), frame) - list(Y = Y, X = X, O = O, miss = is.na(Y), w = w, formula = call$formula) + ## Save encountered levels for predict methods as attribute of the formula. + ## Evaluate the formula expression to get the formula object before setting + ## attributes — avoids "cannot set an attribute on a 'symbol'" when the + ## formula was passed as a variable (e.g. PLN(my_formula, data = d)). + formula_obj <- if (is.symbol(call$formula)) { + eval(call$formula, envir = envir) + } else { + call$formula + } + attr(formula_obj, "xlevels") <- .getXlevels(terms(frame), frame) + list(Y = Y, X = X, O = O, miss = is.na(Y), w = w, formula = formula_obj) } edge_to_node <- function(x, n = max(x)) { @@ -312,10 +320,19 @@ create_parameters <- function( #' @param X Covariate matrix. Note that initialization will fail if the model matrix is singular. #' @param O Offset matrix (in log-scale) #' @param w Weight vector (defaults to 1) -#' @param s Scale parameter for S (defaults to 0.1) +#' @param method character: strategy used to initialize B. Either `"LM"` (default, fast weighted +#' log-linear regression) or `"GLM"` (p independent Poisson GLMs, more accurate for complex +#' or unbalanced designs but slower). #' @return a named list of starting values for model parameter B and variational parameters M and S used in the iterative optimization algorithm of [PLN()] #' -#' @details The default strategy to estimate B and M is to fit a linear model with covariates `X` to the response count matrix (after adding a pseudocount of 1, scaling by the offset and taking the log). The regression matrix is used to initialize `B` and the residuals to initialize `M`. `S` is initialized as a constant conformable matrix with value `s`. +#' @details +#' * **B**: estimated by weighted LM (`method = "LM"`, default) or p independent Poisson GLMs +#' (`method = "GLM"`). The GLM option gives better B estimates for factorial or unbalanced +#' designs at the cost of p IRLS fits. +#' * **M**: initialized to `log((1 + Y) / exp(O))` (M_full in the X*B + M_res parameterization). +#' * **S**: initialized element-wise to `1 / sqrt(2 + Y)`, the approximate VE-step optimum at +#' Omega = I. This adapts automatically to count levels: high S for zero counts (high +#' uncertainty), low S for large counts. #' #' @rdname compute_PLN_starting_point #' @examples @@ -326,15 +343,24 @@ create_parameters <- function( #' O <- log(barents$Offset) #' w <- rep(1, nrow(Y)) #' compute_PLN_starting_point(Y, X, O, w) +#' compute_PLN_starting_point(Y, X, O, w, method = "GLM") #' } #' -#' @importFrom stats lm.fit +#' @importFrom stats lm.fit glm.fit poisson #' @export -compute_PLN_starting_point <- function(Y, X, O, w, s = 0.1) { - # Y = responses, X = covariates, O = offsets (in log scale), w = weights +compute_PLN_starting_point <- function(Y, X, O, w, method = c("LM", "GLM")) { + method <- match.arg(method) n <- nrow(Y); p <- ncol(Y); d <- ncol(X) - fits <- lm.fit(w * X, w * log((1 + Y)/exp(O)), singular.ok = FALSE) - list(B = matrix(fits$coefficients, d, p), - M = matrix(fits$residuals, n, p), - S = matrix(s, n, p)) + if (method == "GLM") { + B <- vapply(seq_len(p), function(j) + glm.fit(X, Y[, j], offset = O[, j], weights = w, family = poisson())$coefficients, + FUN.VALUE = numeric(d) + ) + } else { + B <- lm.fit(w * X, w * log((1 + Y)/exp(O)), singular.ok = FALSE)$coefficients + B[is.na(B)] <- 0 + } + list(B = matrix(B, d, p), + M = matrix(log((1 + Y)/exp(O)), n, p), + S = 1 / sqrt(2 + Y)) } diff --git a/man/PLN.Rd b/man/PLN.Rd index c5452397..f8d18e87 100644 --- a/man/PLN.Rd +++ b/man/PLN.Rd @@ -9,7 +9,7 @@ PLN(formula, data, subset, weights, control = PLN_param()) \arguments{ \item{formula}{an object of class "formula": a symbolic description of the model to be fitted.} -\item{data}{an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which PLN is called.} +\item{data}{an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which the model is called.} \item{subset}{an optional vector specifying a subset of observations to be used in the fitting process.} diff --git a/man/PLNLDA.Rd b/man/PLNLDA.Rd index f0263971..32c005da 100644 --- a/man/PLNLDA.Rd +++ b/man/PLNLDA.Rd @@ -9,7 +9,7 @@ PLNLDA(formula, data, subset, weights, grouping, control = PLNLDA_param()) \arguments{ \item{formula}{an object of class "formula": a symbolic description of the model to be fitted.} -\item{data}{an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which lm is called.} +\item{data}{an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which the model is called.} \item{subset}{an optional vector specifying a subset of observations to be used in the fitting process.} diff --git a/man/PLNPCA.Rd b/man/PLNPCA.Rd index 39450ae1..558a486d 100644 --- a/man/PLNPCA.Rd +++ b/man/PLNPCA.Rd @@ -9,7 +9,7 @@ PLNPCA(formula, data, subset, weights, ranks = 1:5, control = PLNPCA_param()) \arguments{ \item{formula}{an object of class "formula": a symbolic description of the model to be fitted.} -\item{data}{an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which lm is called.} +\item{data}{an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which the model is called.} \item{subset}{an optional vector specifying a subset of observations to be used in the fitting process.} diff --git a/man/PLN_param.Rd b/man/PLN_param.Rd index 3efc73a1..4a2ecee0 100644 --- a/man/PLN_param.Rd +++ b/man/PLN_param.Rd @@ -11,7 +11,8 @@ PLN_param( Omega = NULL, config_post = list(), config_optim = list(), - inception = NULL + inception = NULL, + init_method = c("LM", "GLM") ) } \arguments{ @@ -32,6 +33,8 @@ PLN_param( \item{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.} + +\item{init_method}{character: strategy for the starting-point computation (ignored when \code{inception} is a PLNfit). Either \code{"LM"} (default) or \code{"GLM"} (p independent Poisson GLMs, better for complex or unbalanced designs). See \code{\link[=compute_PLN_starting_point]{compute_PLN_starting_point()}}.} } \value{ list of parameters configuring the fit. diff --git a/man/PLNmixture.Rd b/man/PLNmixture.Rd index e96ff721..d7c60f69 100644 --- a/man/PLNmixture.Rd +++ b/man/PLNmixture.Rd @@ -9,7 +9,7 @@ PLNmixture(formula, data, subset, clusters = 1:5, control = PLNmixture_param()) \arguments{ \item{formula}{an object of class "formula": a symbolic description of the model to be fitted.} -\item{data}{an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which lm is called.} +\item{data}{an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which the model is called.} \item{subset}{an optional vector specifying a subset of observations to be used in the fitting process.} diff --git a/man/PLNmixture_param.Rd b/man/PLNmixture_param.Rd index 766e16d4..1e6d4842 100644 --- a/man/PLNmixture_param.Rd +++ b/man/PLNmixture_param.Rd @@ -28,7 +28,7 @@ PLNmixture_param( \item{config_optim}{a list for controlling the optimizer (either "nlopt" or "torch" backend). See details} -\item{config_post}{a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.).} +\item{config_post}{a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.). See details} \item{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), @@ -41,13 +41,60 @@ list of parameters configuring the fit. Helper to define list of parameters to control the PLNmixture fit. All arguments have defaults. } \details{ -See \code{\link[=PLN_param]{PLN_param()}} for a full description of the generic optimization parameters. PLNmixture_param() also has additional parameters controlling the optimization due the inner-outer loop structure of the optimizer: +The list of parameters \code{config_optim} controls the optimizers. When "nlopt" is chosen the following entries are relevant +\itemize{ +\item "algorithm" the optimization method used by NLOPT among LD type, e.g. "CCSAQ", "MMA", "LBFGS". See NLOPT documentation for further details. Default is "CCSAQ". +\item "maxeval" stop when the number of iteration exceeds maxeval. Default is 10000 +\item "ftol_rel" stop when an optimization step changes the objective function by less than ftol multiplied by the absolute value of the parameter. Default is 1e-8 +\item "xtol_rel" stop when an optimization step changes every parameters by less than xtol multiplied by the absolute value of the parameter. Default is 1e-6 +\item "ftol_abs" stop when an optimization step changes the objective function by less than ftol_abs. Default is 0.0 (disabled) +\item "xtol_abs" stop when an optimization step changes every parameters by less than xtol_abs. Default is 0.0 (disabled) +\item "maxtime" stop when the optimization time (in seconds) exceeds maxtime. Default is -1 (disabled) +} + +When "torch" backend is used (only for PLN and PLNLDA for now), the following entries are relevant: +\itemize{ +\item "algorithm" the optimizer used by torch among RPROP (default), RMSPROP, ADAM and ADAGRAD +\item "maxeval" stop when the number of iteration exceeds maxeval. Default is 10 000 +\item "numepoch" stop training once this number of epochs exceeds numepoch. Set to -1 to enable infinite training. Default is 1 000 +\item "num_batch" number of batches to use during training. Defaults to 1 (use full dataset at each epoch) +\item "ftol_rel" stop when an optimization step changes the objective function by less than ftol multiplied by the absolute value of the parameter. Default is 1e-8 +\item "xtol_rel" stop when an optimization step changes every parameters by less than xtol multiplied by the absolute value of the parameter. Default is 1e-6 +\item "lr" learning rate. Default is 0.1. +\item "momentum" momentum factor. Default is 0 (no momentum). Only used in RMSPROP +\item "weight_decay" Weight decay penalty. Default is 0 (no decay). Not used in RPROP +\item "step_sizes" pair of minimal (default: 1e-6) and maximal (default: 50) allowed step sizes. Only used in RPROP +\item "etas" pair of multiplicative increase and decrease factors. Default is (0.5, 1.2). Only used in RPROP +\item "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 +} + +When "homemade" or "hybrid" backend is used, the following entries are relevant +\itemize{ +\item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 +\item "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 +\item "maxit_em" stop the EM outer loop when the number of EM iterations exceeds maxit_em. Default is 50 +\item "ftol_em" stop the EM outer loop when the ELBO changes by less than ftol_em (relative). Default is 1e-8 +} + +The list of parameters \code{config_post} controls the post-treatment processing (for most \verb{PLN*()} functions), with the following entries (defaults may vary depending on the specific function, check \verb{config_post_default_*} for defaults values): +\itemize{ +\item jackknife boolean indicating whether jackknife should be performed to evaluate bias and variance of the model parameters. Default is FALSE. +\item bootstrap integer indicating the number of bootstrap resamples generated to evaluate the variance of the model parameters. Default is 0 (inactivated). +\item 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. +\item sandwich_var boolean indicating whether sandwich estimation should be used to estimate the variance of the model parameters (highly underestimated). Default is FALSE. +\item rsquared boolean indicating whether approximation of R2 based on deviance should be computed. Default is TRUE +} +} +\section{Outer-loop optimization parameters}{ + +\code{PLNmixture_param()} adds parameters controlling the EM and smoothing outer loops: \itemize{ \item "ftol_em" outer EM solver stops when the objective changes by less than ftol_em (relative). Default is 1e-3 \item "maxit_em" outer EM solver stops when the number of iterations exceeds maxit_em. Default is 50 \item "it_smooth" number of the iterations of the smoothing procedure. Default is 1. } } + \seealso{ \code{\link[=PLN_param]{PLN_param()}} } diff --git a/man/PLNnetwork.Rd b/man/PLNnetwork.Rd index 51589dfe..cb077714 100644 --- a/man/PLNnetwork.Rd +++ b/man/PLNnetwork.Rd @@ -16,7 +16,7 @@ PLNnetwork( \arguments{ \item{formula}{an object of class "formula": a symbolic description of the model to be fitted.} -\item{data}{an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which lm is called.} +\item{data}{an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which the model is called.} \item{subset}{an optional vector specifying a subset of observations to be used in the fitting process.} diff --git a/man/PLNnetwork_param.Rd b/man/PLNnetwork_param.Rd index 4faae29d..7c12d380 100644 --- a/man/PLNnetwork_param.Rd +++ b/man/PLNnetwork_param.Rd @@ -33,7 +33,7 @@ Note: the "nlopt" backend converges better in PLNnetwork's outer glasso alternat \item{penalty_weights}{either a single or a list of p x p matrix of weights (default: all weights equal to 1) to adapt the amount of shrinkage to each pairs of node. Must be symmetric with positive values.} -\item{config_post}{a list for controlling the post-treatment (optional bootstrap, jackknife, R2, etc).} +\item{config_post}{a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.). See details} \item{config_optim}{a list for controlling the optimizer (either "nlopt" or "torch" backend). See details} @@ -48,12 +48,59 @@ list of parameters configuring the fit. Helper to define list of parameters to control the PLN fit. All arguments have defaults. } \details{ -See \code{\link[=PLN_param]{PLN_param()}} for a full description of the generic optimization parameters. PLNnetwork_param() also has two additional parameters controlling the optimization due the inner-outer loop structure of the optimizer: +The list of parameters \code{config_optim} controls the optimizers. When "nlopt" is chosen the following entries are relevant +\itemize{ +\item "algorithm" the optimization method used by NLOPT among LD type, e.g. "CCSAQ", "MMA", "LBFGS". See NLOPT documentation for further details. Default is "CCSAQ". +\item "maxeval" stop when the number of iteration exceeds maxeval. Default is 10000 +\item "ftol_rel" stop when an optimization step changes the objective function by less than ftol multiplied by the absolute value of the parameter. Default is 1e-8 +\item "xtol_rel" stop when an optimization step changes every parameters by less than xtol multiplied by the absolute value of the parameter. Default is 1e-6 +\item "ftol_abs" stop when an optimization step changes the objective function by less than ftol_abs. Default is 0.0 (disabled) +\item "xtol_abs" stop when an optimization step changes every parameters by less than xtol_abs. Default is 0.0 (disabled) +\item "maxtime" stop when the optimization time (in seconds) exceeds maxtime. Default is -1 (disabled) +} + +When "torch" backend is used (only for PLN and PLNLDA for now), the following entries are relevant: +\itemize{ +\item "algorithm" the optimizer used by torch among RPROP (default), RMSPROP, ADAM and ADAGRAD +\item "maxeval" stop when the number of iteration exceeds maxeval. Default is 10 000 +\item "numepoch" stop training once this number of epochs exceeds numepoch. Set to -1 to enable infinite training. Default is 1 000 +\item "num_batch" number of batches to use during training. Defaults to 1 (use full dataset at each epoch) +\item "ftol_rel" stop when an optimization step changes the objective function by less than ftol multiplied by the absolute value of the parameter. Default is 1e-8 +\item "xtol_rel" stop when an optimization step changes every parameters by less than xtol multiplied by the absolute value of the parameter. Default is 1e-6 +\item "lr" learning rate. Default is 0.1. +\item "momentum" momentum factor. Default is 0 (no momentum). Only used in RMSPROP +\item "weight_decay" Weight decay penalty. Default is 0 (no decay). Not used in RPROP +\item "step_sizes" pair of minimal (default: 1e-6) and maximal (default: 50) allowed step sizes. Only used in RPROP +\item "etas" pair of multiplicative increase and decrease factors. Default is (0.5, 1.2). Only used in RPROP +\item "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 +} + +When "homemade" or "hybrid" backend is used, the following entries are relevant +\itemize{ +\item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 +\item "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 +\item "maxit_em" stop the EM outer loop when the number of EM iterations exceeds maxit_em. Default is 50 +\item "ftol_em" stop the EM outer loop when the ELBO changes by less than ftol_em (relative). Default is 1e-8 +} + +The list of parameters \code{config_post} controls the post-treatment processing (for most \verb{PLN*()} functions), with the following entries (defaults may vary depending on the specific function, check \verb{config_post_default_*} for defaults values): +\itemize{ +\item jackknife boolean indicating whether jackknife should be performed to evaluate bias and variance of the model parameters. Default is FALSE. +\item bootstrap integer indicating the number of bootstrap resamples generated to evaluate the variance of the model parameters. Default is 0 (inactivated). +\item 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. +\item sandwich_var boolean indicating whether sandwich estimation should be used to estimate the variance of the model parameters (highly underestimated). Default is FALSE. +\item rsquared boolean indicating whether approximation of R2 based on deviance should be computed. Default is TRUE +} +} +\section{Outer-loop optimization parameters}{ + +\code{PLNnetwork_param()} adds two parameters controlling the alternating GLASSO/VEM loop: \itemize{ \item "ftol_em" outer alternating solver stops when the objective changes by less than ftol_em (relative). Default is 1e-5 \item "maxit_em" outer alternating solver stops when the number of iterations exceeds maxit_em. Default is 20 } } + \seealso{ \code{\link[=PLN_param]{PLN_param()}} } diff --git a/man/ZIPLN.Rd b/man/ZIPLN.Rd index b5bbe650..5bf37310 100644 --- a/man/ZIPLN.Rd +++ b/man/ZIPLN.Rd @@ -15,7 +15,7 @@ ZIPLN( \arguments{ \item{formula}{an object of class "formula": a symbolic description of the model to be fitted.} -\item{data}{an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which PLN is called.} +\item{data}{an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which the model is called.} \item{subset}{an optional vector specifying a subset of observations to be used in the fitting process.} diff --git a/man/ZIPLNnetwork.Rd b/man/ZIPLNnetwork.Rd index aef11b01..29cec29a 100644 --- a/man/ZIPLNnetwork.Rd +++ b/man/ZIPLNnetwork.Rd @@ -17,7 +17,7 @@ ZIPLNnetwork( \arguments{ \item{formula}{an object of class "formula": a symbolic description of the model to be fitted.} -\item{data}{an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which lm is called.} +\item{data}{an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model. If not found in data, the variables are taken from environment(formula), typically the environment from which the model is called.} \item{subset}{an optional vector specifying a subset of observations to be used in the fitting process.} diff --git a/man/ZIPLNnetwork_param.Rd b/man/ZIPLNnetwork_param.Rd index f81166c4..0705812e 100644 --- a/man/ZIPLNnetwork_param.Rd +++ b/man/ZIPLNnetwork_param.Rd @@ -33,7 +33,7 @@ Note: the "nlopt" backend converges better in PLNnetwork's outer glasso alternat \item{penalty_weights}{either a single or a list of p x p matrix of weights (default: all weights equal to 1) to adapt the amount of shrinkage to each pairs of node. Must be symmetric with positive values.} -\item{config_post}{a list for controlling the post-treatment (optional bootstrap, jackknife, R2, etc).} +\item{config_post}{a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.). See details} \item{config_optim}{a list for controlling the optimizer (either "nlopt" or "torch" backend). See details} diff --git a/man/compute_PLN_starting_point.Rd b/man/compute_PLN_starting_point.Rd index 6c9427f0..61a83f5e 100644 --- a/man/compute_PLN_starting_point.Rd +++ b/man/compute_PLN_starting_point.Rd @@ -4,7 +4,7 @@ \alias{compute_PLN_starting_point} \title{Helper function for PLN initialization.} \usage{ -compute_PLN_starting_point(Y, X, O, w, s = 0.1) +compute_PLN_starting_point(Y, X, O, w, method = c("LM", "GLM")) } \arguments{ \item{Y}{Response count matrix} @@ -15,7 +15,9 @@ compute_PLN_starting_point(Y, X, O, w, s = 0.1) \item{w}{Weight vector (defaults to 1)} -\item{s}{Scale parameter for S (defaults to 0.1)} +\item{method}{character: strategy used to initialize B. Either \code{"LM"} (default, fast weighted +log-linear regression) or \code{"GLM"} (p independent Poisson GLMs, more accurate for complex +or unbalanced designs but slower).} } \value{ a named list of starting values for model parameter B and variational parameters M and S used in the iterative optimization algorithm of \code{\link[=PLN]{PLN()}} @@ -24,7 +26,15 @@ a named list of starting values for model parameter B and variational parameters Barebone function to compute starting points for B, M and S when fitting a PLN. Mostly intended for internal use. } \details{ -The default strategy to estimate B and M is to fit a linear model with covariates \code{X} to the response count matrix (after adding a pseudocount of 1, scaling by the offset and taking the log). The regression matrix is used to initialize \code{B} and the residuals to initialize \code{M}. \code{S} is initialized as a constant conformable matrix with value \code{s}. +\itemize{ +\item \strong{B}: estimated by weighted LM (\code{method = "LM"}, default) or p independent Poisson GLMs +(\code{method = "GLM"}). The GLM option gives better B estimates for factorial or unbalanced +designs at the cost of p IRLS fits. +\item \strong{M}: initialized to \code{log((1 + Y) / exp(O))} (M_full in the X*B + M_res parameterization). +\item \strong{S}: initialized element-wise to \code{1 / sqrt(2 + Y)}, the approximate VE-step optimum at +Omega = I. This adapts automatically to count levels: high S for zero counts (high +uncertainty), low S for large counts. +} } \examples{ \dontrun{ @@ -34,6 +44,7 @@ X <- model.matrix(Abundance ~ Latitude + Longitude + Depth + Temperature, data = O <- log(barents$Offset) w <- rep(1, nrow(Y)) compute_PLN_starting_point(Y, X, O, w) +compute_PLN_starting_point(Y, X, O, w, method = "GLM") } } diff --git a/src/newton_diag_cov.cpp b/src/newton_diag_cov.cpp index 277ecf99..58448d25 100644 --- a/src/newton_diag_cov.cpp +++ b/src/newton_diag_cov.cpp @@ -30,7 +30,8 @@ Rcpp::List newton_optimize_diagonal( const double w_bar = arma::accu(w); arma::mat S2 = S % S; - DiagonalCovTraits::State state(M, S2, w, w_bar); + const arma::mat M_res_init = M - X * B; + DiagonalCovTraits::State state(M_res_init, S2, w, w_bar); return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); } diff --git a/src/newton_full_cov.cpp b/src/newton_full_cov.cpp index 9bced978..43fe8938 100644 --- a/src/newton_full_cov.cpp +++ b/src/newton_full_cov.cpp @@ -30,7 +30,8 @@ Rcpp::List newton_optimize_full( const double w_bar = arma::accu(w); arma::mat S2 = S % S; - FullCovTraits::State state(M, S2, w, w_bar); + const arma::mat M_res_init = M - X * B; + FullCovTraits::State state(M_res_init, S2, w, w_bar); return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); } diff --git a/src/newton_impl.h b/src/newton_impl.h index 3c8133e2..956f0978 100644 --- a/src/newton_impl.h +++ b/src/newton_impl.h @@ -145,38 +145,40 @@ Rcpp::List newton_vestep_impl( for (int it = 0; it < maxiter; it++) { S2 = arma::exp(psi); - arma::mat Z = O + XB + M; + arma::mat M_res = M - XB; // M_res for KL terms (B is fixed) + arma::mat Z = O + M; // Z = O + M_full arma::mat A = arma::exp(Z + 0.5 * S2); - // ---- Diagonal Newton step for M ---- + // ---- Diagonal Newton step for M (gradient == gradient w.r.t. M_res, B fixed) ---- arma::mat grad_M, hess_M; - Traits::grad_hess_M(M, state, A, Y, w, ones_row, grad_M, hess_M); + Traits::grad_hess_M(M_res, state, A, Y, w, ones_row, grad_M, hess_M); hess_M.clamp(1e-10, arma::datum::inf); arma::mat step_M = grad_M / hess_M; - arma::mat MO = Traits::times_Omega(M, state); + arma::mat MO = Traits::times_Omega(M_res, state); arma::mat dMO = Traits::times_Omega(step_M, state); - double f0_M = arma::accu(w.t() * (A - Y % Z)) + Traits::penalty_M(MO, M, w); + double f0_M = arma::accu(w.t() * (A - Y % Z)) + Traits::penalty_M(MO, M_res, w); double slope_M = -arma::accu(grad_M % step_M); double alpha_M = 1.0; for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; - arma::mat MOt = MO - alpha_M * dMO; - arma::mat Zt = Z - alpha_M * step_M; - arma::mat At = arma::exp(Zt + 0.5 * S2); - if (arma::accu(w.t() * (At - Y % Zt)) + Traits::penalty_M(MOt, Mt, w) + arma::mat MresT = M_res - alpha_M * step_M; + arma::mat MOt = MO - alpha_M * dMO; + arma::mat Zt = Z - alpha_M * step_M; + arma::mat At = arma::exp(Zt + 0.5 * S2); + if (arma::accu(w.t() * (At - Y % Zt)) + Traits::penalty_M(MOt, MresT, w) <= f0_M + c1 * alpha_M * slope_M) break; alpha_M *= 0.5; } M -= alpha_M * step_M; - Z = O + XB + M; + Z = O + M; // ---- S step: ψ = −log(A + ω²) — exact minimiser for fixed A ---- fixed_point_psi(psi, S2, Z, A, Traits::cov_diag(state, ones_row)); // ---- Objective for convergence ---- A = arma::exp(Z + 0.5 * S2); + arma::mat M_res_new = M - XB; double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * psi)) - + Traits::objective_cov(M, S2, state, w); + + Traits::objective_cov(M_res_new, S2, state, w); objective_vec.push_back(obj); total_iter++; @@ -187,9 +189,10 @@ Rcpp::List newton_vestep_impl( // ---- Final output ---- S2 = arma::exp(psi); S = arma::exp(0.5 * psi); - arma::mat Z = O + XB + M; + arma::mat Z = O + M; // Z = O + M_full arma::mat A = arma::exp(Z + 0.5 * S2); - arma::vec loglik = Traits::final_loglik(Y, Z, A, M, psi, state); + arma::mat M_res = M - XB; // for loglik KL terms + arma::vec loglik = Traits::final_loglik(Y, Z, A, M_res, psi, state); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; diff --git a/src/newton_impl_alt.h b/src/newton_impl_alt.h index 4cc0bd35..e47ab9bf 100644 --- a/src/newton_impl_alt.h +++ b/src/newton_impl_alt.h @@ -3,19 +3,15 @@ #include "utils.h" #include "CovarianceTraits.h" -// Alternative parameterization: M stores M_full (the full variational mean on Z_i, -// not the residual M_res = M_full - XB used in newton_impl.h). +// M_full parameterization: M is the full variational mean of Z_i (= X_i*B + M_res), +// consistent with the ZIPLN convention. M_res = M - X*B is computed locally for KL. // -// B is profiled at every Newton step via the envelope theorem (same as nlopt E-step): -// B = P_X * M_full = (X'WX)^{-1} X'W M_full (closed-form optimum for current M_full) -// M_res = M_full - X*B (projection orthogonal to col(X)) -// The gradient of J_profiled w.r.t. M_full equals the gradient w.r.t. M_res -// (envelope theorem), so no formula change is needed. Within each Armijo line search -// B is held fixed at the value computed at the start of the Newton step, consistent -// with how nlopt evaluates the gradient once per quasi-Newton iteration. +// B is profiled at every Newton step via the envelope theorem: +// B = P_X * M = (X'WX)^{-1} X'W M (closed-form optimum for current M) +// M_res = M - X*B (projection orthogonal to col(X)) +// The gradient of J_profiled w.r.t. M equals the gradient w.r.t. M_res (envelope theorem). // -// At input/output: M is in the "residual" format (M_res = M_full - XB) to stay -// compatible with the rest of the R package. The conversion is done internally. +// Input/output: M is in M_full format throughout. template Rcpp::List newton_optimize_alt_impl( @@ -36,9 +32,6 @@ Rcpp::List newton_optimize_alt_impl( // When d=0 (no covariates), X'WX is 0×0: skip solve to avoid spurious singularity warning const arma::mat P_X = (X.n_cols > 0) ? arma::solve(XtWX, Xw.t()) : arma::mat(0, n); - // Convert input M from residual format to M_full = XB + M_res - M = X * B + M; - arma::mat psi = arma::log(S % S); arma::mat S2 = arma::exp(psi); @@ -154,7 +147,7 @@ Rcpp::List newton_optimize_alt_impl( Rcpp::List cov_out = Traits::output_cov(M_res, S2, w, w_bar, state); return Rcpp::List::create( Rcpp::Named("B", B ), - Rcpp::Named("M", M_res ), // return residual format for R compatibility + Rcpp::Named("M", M ), // M_full Rcpp::Named("S", S ), Rcpp::Named("Z", Z ), Rcpp::Named("A", A ), diff --git a/src/newton_spherical.cpp b/src/newton_spherical.cpp index 2e6ca3f9..a1aca677 100644 --- a/src/newton_spherical.cpp +++ b/src/newton_spherical.cpp @@ -30,7 +30,8 @@ Rcpp::List newton_optimize_spherical( const double w_bar = arma::accu(w); arma::mat S2 = S % S; - SphericalCovTraits::State state(M, S2, w, w_bar); + const arma::mat M_res_init = M - X * B; + SphericalCovTraits::State state(M_res_init, S2, w, w_bar); return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); } diff --git a/src/nlopt_diag_cov.cpp b/src/nlopt_diag_cov.cpp index 267fe3c3..dbbcabaa 100644 --- a/src/nlopt_diag_cov.cpp +++ b/src/nlopt_diag_cov.cpp @@ -46,7 +46,7 @@ Rcpp::List nlopt_optimize_diagonal( enum { M_ID, S_ID }; auto parameters = std::vector(metadata.packed_size); - metadata.map(parameters.data()) = X * init_B + init_M; + metadata.map(parameters.data()) = init_M; metadata.map(parameters.data()) = arma::log(init_S % init_S); auto optimizer = new_nlopt_optimizer(config, parameters.size()); @@ -77,26 +77,26 @@ Rcpp::List nlopt_optimize_diagonal( }; OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); - arma::mat M_full = metadata.copy(parameters.data()); + arma::mat M = metadata.copy(parameters.data()); // M_full arma::mat logS2 = metadata.copy(parameters.data()); arma::mat S2 = arma::exp(logS2); arma::mat S = arma::exp(0.5 * logS2); - arma::mat B = P_X * M_full; - arma::mat M = M_full - X * B; - arma::rowvec sigma2 = w.t() * (M % M + S2) / w_bar; + arma::mat B = P_X * M; + arma::mat M_res = M - X * B; + arma::rowvec sigma2 = w.t() * (M_res % M_res + S2) / w_bar; arma::vec omega2 = pow(sigma2.t(), -1); arma::sp_mat Sigma(Y.n_cols, Y.n_cols); Sigma.diag() = sigma2.t(); arma::sp_mat Omega(Y.n_cols, Y.n_cols); Omega.diag() = omega2; - arma::mat Z = O + M_full; + arma::mat Z = O + M; arma::mat A = exp(Z + 0.5 * S2); - arma::mat loglik = sum(Y % Z - A + 0.5 * logS2, 1) - 0.5 * (pow(M, 2) + S2) * omega2 + arma::mat loglik = sum(Y % Z - A + 0.5 * logS2, 1) - 0.5 * (pow(M_res, 2) + S2) * omega2 + 0.5 * sum(log(omega2)) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; return Rcpp::List::create( Rcpp::Named("B", B), - Rcpp::Named("M", M), + Rcpp::Named("M", M), // M_full Rcpp::Named("S", S), Rcpp::Named("Z", Z), Rcpp::Named("A", A), @@ -141,17 +141,18 @@ Rcpp::List nlopt_optimize_vestep_diagonal( std::vector objective_vec ; objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); - const arma::mat OXB = O + X * B; // fixed offset, precomputed once + const arma::mat XB = X * B; // B is fixed; precompute XB for M_res = M - XB const arma::rowvec omega2_v = arma::diagvec(Omega).t(); // fixed precision, as row vector - // Vestep: M_res is the NLOPT parameter; B and Omega fixed by the caller + // Vestep: M_full is the NLOPT parameter; B and Omega fixed by the caller auto objective_and_grad = [&](const double * params, double * grad) -> double { const arma::mat M = metadata.map(params); const arma::mat logS2 = metadata.map(params); const arma::mat S2 = arma::exp(logS2); - const double penalty = 0.5 * as_scalar(w.t() * (arma::pow(M, 2) + S2) * omega2_v.t()); + const arma::mat M_res = M - XB; + const double penalty = 0.5 * as_scalar(w.t() * (arma::pow(M_res, 2) + S2) * omega2_v.t()); arma::mat gM, gS; - const double obj = diag_cov_obj_grad_impl(M, OXB + M, S2, logS2, omega2_v, penalty, Y, w, gM, gS); + const double obj = diag_cov_obj_grad_impl(M_res, O + M, S2, logS2, omega2_v, penalty, Y, w, gM, gS); metadata.map(grad) = gM; metadata.map(grad) = gS; objective_vec.push_back(obj); @@ -160,16 +161,17 @@ Rcpp::List nlopt_optimize_vestep_diagonal( OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); // Model and variational parameters - arma::mat M = metadata.copy(parameters.data()); + arma::mat M = metadata.copy(parameters.data()); // M_full arma::mat logS2 = metadata.copy(parameters.data()); arma::mat S2 = arma::exp(logS2); arma::mat S = arma::exp(0.5 * logS2); + arma::mat M_res = M - XB; // Element-wise log-likelihood - arma::mat Z = OXB + M; + arma::mat Z = O + M; arma::mat A = exp(Z + 0.5 * S2); arma::vec omega2 = Omega.diag(); arma::mat loglik = - sum(Y % Z - A + 0.5 * logS2, 1) - 0.5 * (pow(M, 2) + S2) * omega2 + 0.5 * sum(log(omega2)) + ki(Y); + sum(Y % Z - A + 0.5 * logS2, 1) - 0.5 * (pow(M_res, 2) + S2) * omega2 + 0.5 * sum(log(omega2)) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; diff --git a/src/nlopt_fixed_cov.cpp b/src/nlopt_fixed_cov.cpp index 90a08f08..89de508c 100644 --- a/src/nlopt_fixed_cov.cpp +++ b/src/nlopt_fixed_cov.cpp @@ -29,7 +29,7 @@ Rcpp::List nlopt_optimize_fixed( enum { M_ID, S_ID }; auto parameters = std::vector(metadata.packed_size); - metadata.map(parameters.data()) = X * init_B + init_M; + metadata.map(parameters.data()) = init_M; metadata.map(parameters.data()) = arma::log(init_S % init_S); auto optimizer = new_nlopt_optimizer(config, parameters.size()); @@ -58,16 +58,16 @@ Rcpp::List nlopt_optimize_fixed( }; OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); - arma::mat M_full = metadata.copy(parameters.data()); + arma::mat M = metadata.copy(parameters.data()); // M_full arma::mat logS2 = metadata.copy(parameters.data()); arma::mat S2 = arma::exp(logS2); arma::mat S = arma::exp(0.5 * logS2); - arma::mat B = P_X * M_full; - arma::mat M = M_full - X * B; - arma::mat Sigma = (M.t() * (M.each_col() % w) + diagmat(w.t() * S2)) / accu(w); - arma::mat Z = O + M_full; + arma::mat B = P_X * M; + arma::mat M_res = M - X * B; + arma::mat Sigma = (M_res.t() * (M_res.each_col() % w) + diagmat(w.t() * S2)) / accu(w); + arma::mat Z = O + M; arma::mat A = exp(Z + 0.5 * S2); - arma::mat loglik = sum(Y % Z - A - 0.5 * ((M * Omega) % M - logS2 + S2 * diagmat(Omega)), 1) + arma::mat loglik = sum(Y % Z - A - 0.5 * ((M_res * Omega) % M_res - logS2 + S2 * diagmat(Omega)), 1) + 0.5 * real(log_det(Omega)) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); diff --git a/src/nlopt_full_cov.cpp b/src/nlopt_full_cov.cpp index 637e989b..61351f89 100644 --- a/src/nlopt_full_cov.cpp +++ b/src/nlopt_full_cov.cpp @@ -39,7 +39,7 @@ Rcpp::List nlopt_optimize_full( const arma::mat & O = Rcpp::as(data["O"]); const arma::vec & w = Rcpp::as(data["w"]); const auto init_B = Rcpp::as(params["B"]); - const auto init_M = Rcpp::as(params["M"]); // residual format + const auto init_M = Rcpp::as(params["M"]); const auto init_S = Rcpp::as(params["S"]); // Parameters: (M_full, logS2) — B is profiled out via closed form @@ -47,7 +47,7 @@ Rcpp::List nlopt_optimize_full( enum { M_ID, S_ID }; auto parameters = std::vector(metadata.packed_size); - metadata.map(parameters.data()) = X * init_B + init_M; // M_full = XB + M_res + metadata.map(parameters.data()) = init_M; metadata.map(parameters.data()) = arma::log(init_S % init_S); const double w_bar = accu(w); @@ -58,11 +58,12 @@ Rcpp::List nlopt_optimize_full( const arma::mat Xw = X.each_col() % w; const arma::mat P_X = arma::solve(X.t() * Xw, Xw.t()); - // Initial Omega from residual init_M + // Initial Omega: M_res = M_full - X*B arma::mat Omega; { - const arma::mat S2_init = init_S % init_S; - arma::mat Sigma_init = (1./w_bar) * (init_M.t() * (init_M.each_col() % w) + diagmat(w.t() * S2_init)); + const arma::mat S2_init = init_S % init_S; + const arma::mat M_res_init = init_M - X * init_B; + arma::mat Sigma_init = (1./w_bar) * (M_res_init.t() * (M_res_init.each_col() % w) + diagmat(w.t() * S2_init)); Omega = inv_sympd(Sigma_init); } @@ -110,16 +111,16 @@ Rcpp::List nlopt_optimize_full( elbo_prev = elbo; } - arma::mat M_full = metadata.copy(parameters.data()); + arma::mat M = metadata.copy(parameters.data()); // M_full arma::mat logS2 = metadata.copy(parameters.data()); arma::mat S2 = arma::exp(logS2); arma::mat S = arma::exp(0.5 * logS2); - arma::mat B = P_X * M_full; - arma::mat M = M_full - X * B; // M_res — residual format - arma::mat Sigma = (1./w_bar) * (M.t() * (M.each_col() % w) + diagmat(w.t() * S2)); - arma::mat Z = O + M_full; + arma::mat B = P_X * M; + arma::mat M_res = M - X * B; + arma::mat Sigma = (1./w_bar) * (M_res.t() * (M_res.each_col() % w) + diagmat(w.t() * S2)); + arma::mat Z = O + M; arma::mat A = exp(Z + 0.5 * S2); - arma::vec loglik = sum(Y % Z - A + 0.5 * logS2 - 0.5 * ((M * Omega) % M + S2 * diagmat(Omega)), 1) + arma::vec loglik = sum(Y % Z - A + 0.5 * logS2 - 0.5 * ((M_res * Omega) % M_res + S2 * diagmat(Omega)), 1) + 0.5 * real(log_det(Omega)) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); @@ -173,15 +174,15 @@ Rcpp::List nlopt_optimize_vestep_full( std::vector objective_vec ; objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); - const arma::mat OXB = O + X * B; // fixed offset: O + XB, precomputed once + const arma::mat XB = X * B; // B is fixed; precompute XB for M_res = M - XB const arma::vec Omega_diag = diagvec(Omega); - // Vestep: M_res is the NLOPT parameter; B and Omega fixed by the caller + // Vestep: M_full is the NLOPT parameter; B and Omega fixed by the caller auto objective_and_grad = [&](const double * params, double * grad) -> double { const arma::mat M = metadata.map(params); const arma::mat logS2 = metadata.map(params); arma::mat gM, gS; - const double obj = full_cov_obj_grad_impl(M, OXB + M, logS2, Omega, Omega_diag, Y, w, gM, gS); + const double obj = full_cov_obj_grad_impl(M - XB, O + M, logS2, Omega, Omega_diag, Y, w, gM, gS); metadata.map(grad) = gM; metadata.map(grad) = gS; objective_vec.push_back(obj); @@ -190,14 +191,15 @@ Rcpp::List nlopt_optimize_vestep_full( OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); // Model and variational parameters - arma::mat M = metadata.copy(parameters.data()); + arma::mat M = metadata.copy(parameters.data()); // M_full arma::mat logS2 = metadata.copy(parameters.data()); arma::mat S2 = arma::exp(logS2); arma::mat S = arma::exp(0.5 * logS2); + arma::mat M_res = M - XB; // Element-wise log-likelihood - arma::mat Z = OXB + M; + arma::mat Z = O + M; arma::mat A = exp(Z + 0.5 * S2); - arma::vec loglik = sum(Y % Z - A + 0.5 * logS2 - 0.5 * ((M * Omega) % M + S2 * diagmat(Omega)), 1) + + arma::vec loglik = sum(Y % Z - A + 0.5 * logS2 - 0.5 * ((M_res * Omega) % M_res + S2 * diagmat(Omega)), 1) + 0.5 * real(log_det(Omega)) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); diff --git a/src/nlopt_spherical.cpp b/src/nlopt_spherical.cpp index 60446927..453715b9 100644 --- a/src/nlopt_spherical.cpp +++ b/src/nlopt_spherical.cpp @@ -46,7 +46,7 @@ Rcpp::List nlopt_optimize_spherical( enum { M_ID, S_ID }; auto parameters = std::vector(metadata.packed_size); - metadata.map(parameters.data()) = X * init_B + init_M; + metadata.map(parameters.data()) = init_M; metadata.map(parameters.data()) = arma::log(init_S % init_S); auto optimizer = new_nlopt_optimizer(config, parameters.size()); @@ -77,18 +77,18 @@ Rcpp::List nlopt_optimize_spherical( }; OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); - arma::mat M_full = metadata.copy(parameters.data()); + arma::mat M = metadata.copy(parameters.data()); // M_full arma::mat logS2 = metadata.copy(parameters.data()); arma::mat S2 = arma::exp(logS2); arma::mat S = arma::exp(0.5 * logS2); - arma::mat B = P_X * M_full; - arma::mat M = M_full - X * B; - const double sigma2 = accu(diagmat(w) * (pow(M, 2) + S2)) / (double(p) * w_bar); + arma::mat B = P_X * M; + arma::mat M_res = M - X * B; + const double sigma2 = accu(diagmat(w) * (pow(M_res, 2) + S2)) / (double(p) * w_bar); arma::sp_mat Sigma(p, p); Sigma.diag() = arma::ones(p) * sigma2; arma::sp_mat Omega(p, p); Omega.diag() = arma::ones(p) * pow(sigma2, -1); - arma::mat Z = O + M_full; + arma::mat Z = O + M; arma::mat A = exp(Z + 0.5 * S2); - arma::mat loglik = sum(Y % Z - A - 0.5 * (pow(M, 2) + S2) / sigma2 + 0.5 * (logS2 - log(sigma2)), 1) + ki(Y); + arma::mat loglik = sum(Y % Z - A - 0.5 * (pow(M_res, 2) + S2) / sigma2 + 0.5 * (logS2 - log(sigma2)), 1) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; @@ -141,17 +141,18 @@ Rcpp::List nlopt_optimize_vestep_spherical( std::vector objective_vec ; objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); - const arma::mat OXB = O + X * B; // fixed offset, precomputed once + const arma::mat XB = X * B; // B is fixed; precompute XB for M_res = M - XB const double omega2 = Omega(0, 0); // fixed precision = 1/sigma2 - // Vestep: M_res is the NLOPT parameter; B and Omega fixed by the caller + // Vestep: M_full is the NLOPT parameter; B and Omega fixed by the caller auto objective_and_grad = [&](const double * params, double * grad) -> double { const arma::mat M = metadata.map(params); const arma::mat logS2 = metadata.map(params); const arma::mat S2 = arma::exp(logS2); - const double penalty = 0.5 * omega2 * accu(arma::diagmat(w) * (arma::pow(M, 2) + S2)); + const arma::mat M_res = M - XB; + const double penalty = 0.5 * omega2 * accu(arma::diagmat(w) * (arma::pow(M_res, 2) + S2)); arma::mat gM, gS; - const double obj = spherical_cov_obj_grad_impl(M, OXB + M, S2, logS2, + const double obj = spherical_cov_obj_grad_impl(M_res, O + M, S2, logS2, omega2, penalty, Y, w, gM, gS); metadata.map(grad) = gM; metadata.map(grad) = gS; @@ -161,14 +162,15 @@ Rcpp::List nlopt_optimize_vestep_spherical( OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); // Model and variational parameters - arma::mat M = metadata.copy(parameters.data()); + arma::mat M = metadata.copy(parameters.data()); // M_full arma::mat logS2 = metadata.copy(parameters.data()); arma::mat S2 = arma::exp(logS2); arma::mat S = arma::exp(0.5 * logS2); - // Element-wise log-likelihood [log(S²·ω²) = logS2 + log(ω²)] - arma::mat Z = OXB + M; + arma::mat M_res = M - XB; + // Element-wise log-likelihood + arma::mat Z = O + M; arma::mat A = exp(Z + 0.5 * S2); - arma::mat loglik = sum(Y % Z - A - 0.5 * (pow(M, 2) + S2) * omega2 + 0.5 * (logS2 + log(omega2)), 1) + ki(Y); + arma::mat loglik = sum(Y % Z - A - 0.5 * (pow(M_res, 2) + S2) * omega2 + 0.5 * (logS2 + log(omega2)), 1) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; diff --git a/tests/testthat/test-pln.R b/tests/testthat/test-pln.R index d83c9e2e..4ca85e3f 100644 --- a/tests/testthat/test-pln.R +++ b/tests/testthat/test-pln.R @@ -18,10 +18,11 @@ test_that("PLN: Check that PLN is running and robust", { test_that("PLN: Check consistency of initialization - fully parametrized covariance", { - ## use default initialization (LM) - model1 <- PLN(Abundance ~ 1, data = trichoptera, control = PLN_param(trace = 0)) + ## use default initialization (LM), run enough EM iters to ensure convergence + ctrl_cv <- PLN_param(trace = 0, config_optim = list(maxit_em = 500)) + model1 <- PLN(Abundance ~ 1, data = trichoptera, control = ctrl_cv) - ## initialization with the previous fit + ## initialization with the previous fit: should converge to the same point model2 <- PLN(Abundance ~ 1, data = trichoptera, control = PLN_param(inception = model1, trace = 0)) expect_equal(model2$loglik , model1$loglik , tolerance = 0.1) @@ -35,10 +36,11 @@ test_that("PLN: Check consistency of initialization - fully parametrized covaria test_that("PLN: Check consistency of initialization - diagonal covariance", { - ## use default initialization (GLM) - model1 <- PLN(Abundance ~ 1, data = trichoptera, control = PLN_param(trace = 0, covariance = "diagonal")) + ## use default initialization, run enough EM iters to ensure convergence + ctrl_cv <- PLN_param(trace = 0, covariance = "diagonal", config_optim = list(maxit_em = 500)) + model1 <- PLN(Abundance ~ 1, data = trichoptera, control = ctrl_cv) - ## initialization with the previous fit + ## initialization with the previous fit: should converge to the same point model2 <- PLN(Abundance ~ 1, data = trichoptera, control = PLN_param(inception = model1, trace = 0, covariance = "diagonal")) expect_equal(model2$loglik , model1$loglik , tolerance = 0.1) From 7943242ea1f1f62ef3c70798b863b00d151a8b09 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Wed, 10 Jun 2026 22:31:55 +0200 Subject: [PATCH 33/58] some fix in doc and dependencies --- .Rbuildignore | 1 + DESCRIPTION | 14 +++++++------- NAMESPACE | 1 + R/utils.R | 1 + 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 77442722..d703a3f2 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -37,3 +37,4 @@ ^dev$ ^\.claude$ ^DEVLOG.*\.md$ +snowflake.log diff --git a/DESCRIPTION b/DESCRIPTION index 8a87636b..e45da547 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,7 +25,7 @@ URL: https://pln-team.github.io/PLNmodels/ BugReports: https://github.com/pln-team/PLNmodels/issues License: GPL (>= 3) Depends: R (>= 4.1.0) -Imports: +Imports: cli, corrplot, dplyr, @@ -48,28 +48,28 @@ Imports: R6, Rcpp, rlang, - scales, stats, tidyr, - torch -Suggests: + torch, + utils +Suggests: factoextra, knitr, rmarkdown, spelling, testthat -LinkingTo: +LinkingTo: nloptr, Rcpp, RcppArmadillo -VignetteBuilder: +VignetteBuilder: knitr biocViews: Encoding: UTF-8 Language: en-US LazyData: true Roxygen: list(markdown = TRUE) -Collate: +Collate: 'PLNfit-class.R' 'PLN.R' 'PLNLDA.R' diff --git a/NAMESPACE b/NAMESPACE index de3ca7c0..eb38d30e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -150,4 +150,5 @@ importFrom(stats,update.formula) importFrom(stats,var) importFrom(tidyr,gather) importFrom(tidyr,replace_na) +importFrom(utils,modifyList) useDynLib(PLNmodels) diff --git a/R/utils.R b/R/utils.R index e32dad4d..345a81e3 100644 --- a/R/utils.R +++ b/R/utils.R @@ -28,6 +28,7 @@ config_default_homemade <- # Phase 1 (nlopt) uses looser tolerances to reach the basin quickly with quasi-Newton search. # Phase 2 (homemade, envelope-theorem Newton) refines to the full requested tolerance. # Returns a closure with the same (data, params, config) signature as the C++ wrappers. +#' @importFrom utils modifyList make_hybrid_optimizer <- function(opt_nlopt, opt_newton) { function(data, params, config) { # Phase 1: nlopt config with 10× looser tolerance for fast basin finding From c0146c03ca774d768f27ece09ddfdd6eb0a6cf77 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Wed, 10 Jun 2026 22:57:58 +0200 Subject: [PATCH 34/58] fixes consecutive to PR changes --- R/PLNfit-class.R | 11 ++++++----- R/PLNmixturefamily-class.R | 4 ++-- R/PLNmixturefit-class.R | 2 +- R/utils.R | 13 ++++++++----- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index a40c8173..11dff1e9 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -258,7 +258,7 @@ PLNfit <- R6Class( O = O[-i, , drop = FALSE], w = w[-i]) args <- list(data = data, - params = do.call(compute_PLN_starting_point, data), + params = compute_PLN_starting_point(data$Y, data$X, data$O, data$w), config = config) optim_out <- do.call(private$optimizer$main, args) optim_out[c("B", "Omega")] @@ -293,7 +293,7 @@ PLNfit <- R6Class( data <- lapply(data, torch_tensor, device = config$device) args <- list(data = data, - params = do.call(compute_PLN_starting_point, data), + params = compute_PLN_starting_point(data$Y, data$X, data$O, data$w), config = config) if (config$backend == "torch") # Convert data to torch tensors args$params <- lapply(args$params, torch_tensor, requires_grad = TRUE, device = config$device) # list with B, M, S @@ -553,6 +553,7 @@ PLNfit <- R6Class( Omega = private$Omega ) M <- VE$M # M_full + colnames(M) <- colnames(private$B) S2 <- (VE$S)**2 } else { # population prediction: M_full = X*B (M_res = 0) @@ -937,7 +938,8 @@ PLNfit_fixedcov <- R6Class( #' @description Initialize a [`PLNfit`] model initialize = function(responses, covariates, offsets, weights, formula, control) { super$initialize(responses, covariates, offsets, weights, formula, control) - private$setup_optimizer(control$backend, nlopt_optimize_fixed, newton_optimize_fixed) + private$setup_optimizer(control$backend, nlopt_optimize_fixed, newton_optimize_fixed, + nlopt_optimize_vestep_full, newton_optimize_vestep_full) private$Omega <- control$Omega }, #' @description Call to the NLopt or TORCH optimizer and update of the relevant fields @@ -982,8 +984,7 @@ PLNfit_fixedcov <- R6Class( O = O[-i, , drop = FALSE], w = w[-i]) args <- list(data = data, - # params = list(B = private$B, Omega = private$Omega, M = private$M[-i, ], S = private$S[-i, ]), - params = do.call(compute_PLN_starting_point, data), + params = compute_PLN_starting_point(data$Y, data$X, data$O, data$w), config = config) optim_out <- do.call(private$optimizer$main, args) optim_out[c("B", "Omega")] diff --git a/R/PLNmixturefamily-class.R b/R/PLNmixturefamily-class.R index 55f38d75..bf43dec6 100644 --- a/R/PLNmixturefamily-class.R +++ b/R/PLNmixturefamily-class.R @@ -31,7 +31,7 @@ PLNmixturefamily <- ## Control options control$trace <- FALSE config_fast <- control$config_optim - config_fast$maxit_out <- 2 + config_fast$maxit_em <- 2 ## Effective number of clusters (remove empty classes) and current clustering with clusters numbered in 1:k (with no gaps) cl <- model$memberships @@ -98,7 +98,7 @@ PLNmixturefamily <- ## Control options control$trace <- FALSE config_fast <- control$config_optim - config_fast$maxit_out <- 2 + config_fast$maxit_em <- 2 ## number of clusters if (is.null(k)) k <- length(model$components) diff --git a/R/PLNmixturefit-class.R b/R/PLNmixturefit-class.R index 73adbe09..d4b5b545 100644 --- a/R/PLNmixturefit-class.R +++ b/R/PLNmixturefit-class.R @@ -324,7 +324,7 @@ PLNmixturefit <- #' @field latent a matrix: values of the latent vector (Z in the model) latent = function() {private$mix_up('latent')}, #' @field latent_pos a matrix: values of the latent position vector (Z) without covariates effects or offset - latent_pos = function() {private$mix_up('var_par$M')}, + latent_pos = function() {private$mix_up('latent_pos')}, #' @field posteriorProb matrix ofposterior probability for cluster belonging posteriorProb = function(value) {if (missing(value)) return(private$tau) else private$tau <- value}, #' @field memberships vector for cluster index diff --git a/R/utils.R b/R/utils.R index 345a81e3..b20c2c12 100644 --- a/R/utils.R +++ b/R/utils.R @@ -224,7 +224,7 @@ extract_model <- function(call, envir) { ## Evaluate the formula expression to get the formula object before setting ## attributes — avoids "cannot set an attribute on a 'symbol'" when the ## formula was passed as a variable (e.g. PLN(my_formula, data = d)). - formula_obj <- if (is.symbol(call$formula)) { + formula_obj <- if (!inherits(call$formula, "formula")) { eval(call$formula, envir = envir) } else { call$formula @@ -352,16 +352,19 @@ create_parameters <- function( compute_PLN_starting_point <- function(Y, X, O, w, method = c("LM", "GLM")) { method <- match.arg(method) n <- nrow(Y); p <- ncol(Y); d <- ncol(X) + Y0 <- replace(Y, is.na(Y), 0) # treat missing counts as 0 for initialization only + expO <- exp(O) if (method == "GLM") { + pois_fam <- poisson() B <- vapply(seq_len(p), function(j) - glm.fit(X, Y[, j], offset = O[, j], weights = w, family = poisson())$coefficients, + glm.fit(X, Y0[, j], offset = O[, j], weights = w, family = pois_fam)$coefficients, FUN.VALUE = numeric(d) ) } else { - B <- lm.fit(w * X, w * log((1 + Y)/exp(O)), singular.ok = FALSE)$coefficients + B <- lm.fit(w * X, w * log((1 + Y0) / expO), singular.ok = TRUE)$coefficients B[is.na(B)] <- 0 } list(B = matrix(B, d, p), - M = matrix(log((1 + Y)/exp(O)), n, p), - S = 1 / sqrt(2 + Y)) + M = matrix(log((1 + Y0) / expO), n, p), + S = 1 / sqrt(2 + Y0)) } From 85b8c4732f0cd1054b6ef6905f4acd6ddba07f1f Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Wed, 10 Jun 2026 23:05:45 +0200 Subject: [PATCH 35/58] fix in tests --- tests/testthat/test-pln.R | 17 ++++++++--------- tests/testthat/test-plnlda-fit.R | 20 +++++++------------- tests/testthat/test-standard-error.R | 2 +- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/tests/testthat/test-pln.R b/tests/testthat/test-pln.R index 4ca85e3f..8af0d072 100644 --- a/tests/testthat/test-pln.R +++ b/tests/testthat/test-pln.R @@ -73,10 +73,10 @@ test_that("PLN: Check consistency of observation weights - diagonal covariance", tol <- 1e-2 ## no weights - model1 <- PLN(Abundance ~ 1, data = trichoptera, control = PLN_param(covariance = "spherical", trace = 0)) + model1 <- PLN(Abundance ~ 1, data = trichoptera, control = PLN_param(covariance = "diagonal", trace = 0)) - ## equivalent weigths - model2 <- PLN(Abundance ~ 1, data = trichoptera, weights = rep(1.0, nrow(trichoptera)), control = PLN_param(covariance = "spherical", trace = 0)) + ## equivalent weights + model2 <- PLN(Abundance ~ 1, data = trichoptera, weights = rep(1.0, nrow(trichoptera)), control = PLN_param(covariance = "diagonal", trace = 0)) expect_equal(model2$loglik , model1$loglik , tolerance = tol) }) @@ -87,9 +87,8 @@ test_that("PLN: Check consistency of observation weights - spherical covariance" ## no weights model1 <- PLN(Abundance ~ 1, data = trichoptera, control = PLN_param(covariance = "spherical", trace = 0)) - ## equivalent weigths + ## equivalent weights model2 <- PLN(Abundance ~ 1, data = trichoptera, weights = rep(1.0, nrow(trichoptera)), control = PLN_param(covariance = "spherical", trace = 0)) - model3 <- PLN(Abundance ~ 1, data = trichoptera, weights = runif(nrow(trichoptera)), control = PLN_param(covariance = "spherical", trace = 0)) expect_equal(model2$loglik , model1$loglik , tolerance = tol) }) @@ -206,7 +205,7 @@ test_that("PLN: Check that all univariate PLN models are equivalent with the mul }) -test_that("PLN: check initialization fails when the covariate model matrix is singular", { +test_that("PLN: singular covariate model matrix is handled gracefully", { n = 10; d = 1; p = 10 Y <- matrix(rpois(n*p, 1), n, p) @@ -218,8 +217,8 @@ test_that("PLN: check initialization fails when the covariate model matrix is si f1 <- gl(2, n/2, labels = c("1.1", "1.2")) f2 <- gl(2, n/2, labels = c("2.1", "2.2")) - # In both cases, model.matrix(formula) is singular - expect_error(PLN(Y ~ X_singular)) - expect_error(PLN(Y ~ f1 + f2)) + # singular.ok = TRUE: dropped coefficients are zeroed, PLN does not throw + expect_no_error(PLN(Y ~ X_singular)) + expect_no_error(PLN(Y ~ f1 + f2)) }) diff --git a/tests/testthat/test-plnlda-fit.R b/tests/testthat/test-plnlda-fit.R index b7630106..fd4d57d1 100644 --- a/tests/testthat/test-plnlda-fit.R +++ b/tests/testthat/test-plnlda-fit.R @@ -103,21 +103,15 @@ test_that("plot_LDA works for 4 or more axes:", { test_that("PLNLDA fit: Check number of parameters", { p <- ncol(trichoptera$Abundance) + g <- nlevels(trichoptera$Group) - mdl <- PLN(Abundance ~ 1, data = trichoptera) - expect_equal(mdl$nb_param, p*(p+1)/2 + p * 1) + ## no extra covariate: Sigma (p*(p+1)/2) + group means (p*g) + mdl0 <- PLNLDA(Abundance ~ 0 + offset(log(Offset)), grouping = Group, data = trichoptera) + expect_equal(mdl0$nb_param, p * (p + 1) / 2 + p * g) - mdl <- PLN(Abundance ~ 1 + Wind, data = trichoptera) - expect_equal(mdl$nb_param, p*(p+1)/2 + p * 2) - - mdl <- PLN(Abundance ~ Group + 0 , data = trichoptera) - expect_equal(mdl$nb_param, p*(p+1)/2 + p * nlevels(trichoptera$Group)) - - mdl <- PLN(Abundance ~ 1, data = trichoptera, control = PLN_param(covariance = "diagonal")) - expect_equal(mdl$nb_param, p + p * 1) - - mdl <- PLN(Abundance ~ 1, data = trichoptera, control = PLN_param(covariance = "spherical")) - expect_equal(mdl$nb_param, 1 + p * 1) + ## one extra covariate: adds p regression coefficients + mdl1 <- PLNLDA(Abundance ~ Wind + offset(log(Offset)), grouping = Group, data = trichoptera) + expect_equal(mdl1$nb_param, p * (p + 1) / 2 + p * g + p * 1) }) diff --git a/tests/testthat/test-standard-error.R b/tests/testthat/test-standard-error.R index 4f7903a0..2b275f4c 100644 --- a/tests/testthat/test-standard-error.R +++ b/tests/testthat/test-standard-error.R @@ -148,7 +148,7 @@ test_that("Check that variance estimation are coherent in PLNfit", { expect_gt(tr_sandwich , 0) }) -test_that("Check that variance estimation are coherent in PLNnetwork", { +test_that("Check that variance estimation are coherent in PLNPCA", { myPCAs <- PLNPCA(Abundance ~ Var_1 + 0 + offset(log(Offset)), data = data, ranks = 1:3) myPCA <- myPCAs$models[[2]] B <- coef(myPCA); B[ , ] <- NA From f02aa55e9751f27b34c33498bad69e7891463bb2 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Wed, 10 Jun 2026 23:37:28 +0200 Subject: [PATCH 36/58] fixes C++ + factorisation --- DEVLOG_2026-06-08-09.md | 135 +++++++++++++++++++++++++++++++++++ memory/feedback_cpp_audit.md | 30 ++++++++ src/CovarianceTraits.h | 134 +++++++++++++++------------------- src/newton_diag_cov.cpp | 7 +- src/newton_fixed_cov.cpp | 7 +- src/newton_full_cov.cpp | 7 +- src/newton_spherical.cpp | 7 +- src/nlopt_diag_cov.cpp | 21 +----- src/nlopt_fixed_cov.cpp | 26 +++---- src/nlopt_full_cov.cpp | 30 ++------ src/nlopt_impl.h | 52 ++++++++++++++ src/nlopt_spherical.cpp | 21 +----- src/utils.h | 15 ++++ 13 files changed, 317 insertions(+), 175 deletions(-) create mode 100644 memory/feedback_cpp_audit.md create mode 100644 src/nlopt_impl.h diff --git a/DEVLOG_2026-06-08-09.md b/DEVLOG_2026-06-08-09.md index 25d4c59f..8fe590b4 100644 --- a/DEVLOG_2026-06-08-09.md +++ b/DEVLOG_2026-06-08-09.md @@ -426,6 +426,102 @@ De plus, `test-plnlda-fit.R` passait `PLNLDA_param(covariance = "diagonal/spheri --- +## 16. Audit global du code — branche `code-enhancement` vs `master` (10/06) + +Audit multi-angles (7 finders indépendants + 10 verifiers) sur le diff complet de la branche. Méthodologie : line-by-line, removed-behavior, cross-file, reuse, simplification, efficiency, altitude — chaque finding soumis à un verifier avant confirmation. + +8 findings confirmés ou plausibles, classés par sévérité : + +| # | Sévérité | Fichier | Résumé | +|---|---|---|---| +| 1 | Critique | `PLNfit-class.R` | `PLNfit_fixedcov$initialize` appelle `setup_optimizer` sans les args vestep → `optimizer$vestep = NULL` → crash dans `predict(level=1)` et `predict_cond()` | +| 2 | Critique | `PLNmixturefamily-class.R` | `config_fast$maxit_out <- 2` mais `optimize()` lit `config$maxit_em` → smoothing tourne 50 EM iters au lieu de 2 (~25× plus lent) | +| 3 | Haute | `PLNfit-class.R` | `do.call(compute_PLN_starting_point, data)` dans jackknife/bootstrap → sensitive aux noms des éléments de `data`, échoue si `method` est dans la liste | +| 4 | Haute | `PLNfit-class.R` | `predict(level=1)` : M retourné par C++ sans colnames → noms d'espèces perdus dans la prédiction | +| 5 | Haute | `PLNmixturefit-class.R` | `latent_pos` active binding retourne `mix_up('var_par$M')` (M_full) au lieu de `mix_up('latent_pos')` (M_res) → k-means de clustering sur les mauvaises coordonnées | +| 6 | Moyenne | `utils.R` | `compute_PLN_starting_point` : `Y` non protégé contre les NA → crash si Y contient des NA | +| 7 | Moyenne | `utils.R` | `compute_PLN_starting_point` : `singular.ok = FALSE` rend le guard `B[is.na(B)] <- 0` inaccessible | +| 8 | Faible | `utils.R` | `extract_model` : `is.symbol(call$formula)` ne couvre pas les expressions de type call (ex. `formula(paste(...))`) | + +Deux findings refutés (P6, P8 dans la numérotation interne) : `PLNLDAfit$predict` double-comptage — infirmé par la sémantique M_res + group_means ; `PLNmixturefit$predict` position — infirmé, le VE optimizer retourne déjà M_full. + +--- + +## 17. Application des 8 corrections (10/06) + +**Fix 1 — `PLNfit_fixedcov` vestep manquant** (`R/PLNfit-class.R`) + +`setup_optimizer` appelé avec seulement 3 args au lieu de 5 : les fonctions vestep (`nlopt_optimize_vestep_full`, `newton_optimize_vestep_full`) n'étaient pas passées, laissant `optimizer$vestep = NULL`. `predict(level=1)` et `predict_cond()` crashaient via `do.call(NULL, args)`. + +```r +# Avant +private$setup_optimizer(control$backend, nlopt_optimize_fixed, newton_optimize_fixed) +# Après +private$setup_optimizer(control$backend, nlopt_optimize_fixed, newton_optimize_fixed, + nlopt_optimize_vestep_full, newton_optimize_vestep_full) +``` + +**Fix 2 — smoothing PLNmixture : clé `maxit_em` au lieu de `maxit_out`** (`R/PLNmixturefamily-class.R`) + +Dans `add_one_cluster()` et `remove_one_cluster()`, `config_fast$maxit_out <- 2` n'avait aucun effet car `optimize()` lit `config$maxit_em`. Le screening rapide des candidats tournait donc à plein régime (50 EM iters par candidat). + +```r +# Avant (dans les deux fonctions) +config_fast$maxit_out <- 2 +# Après +config_fast$maxit_em <- 2 +``` + +**Fix 3 — jackknife/bootstrap : `do.call` supprimé** (`R/PLNfit-class.R`) + +`do.call(compute_PLN_starting_point, data)` — `data` est une liste nommée `(Y, X, O, miss, w, formula)` dont les noms ne correspondent pas aux paramètres de `compute_PLN_starting_point(Y, X, O, w, method)`. Remplacé par un appel positionnel direct qui passe correctement `w` et permet de spécifier `method`. + +**Fix 4 — colnames M dans `predict(level=1)`** (`R/PLNfit-class.R`) + +L'optimiseur C++ retourne M sans attributs de noms. `colnames(M) <- colnames(private$B)` ajouté après récupération du résultat VE. + +**Fix 5 — `latent_pos` de `PLNmixturefit`** (`R/PLNmixturefit-class.R`) + +`mix_up('var_par$M')` accédait au champ brut `private$M` de chaque composante (M_full = μ_k + M_res). Le k-means dans `add_one_cluster()` opérait donc sur les coordonnées incluant les effets de groupe, biaisant la séparation. Corrigé en `mix_up('latent_pos')` qui appelle le binding actif de chaque `PLNfit` (M − X*B = M_res). + +**Fix 6+7 — `compute_PLN_starting_point` : NA, singular.ok, pois_fam** (`R/utils.R`) + +- `Y0 <- replace(Y, is.na(Y), 0)` : protection NA pour `lm.fit` et `glm.fit` +- `expO <- exp(O)` : calculé une seule fois (était calculé deux fois) +- `singular.ok = TRUE` : active la garde `B[is.na(B)] <- 0` (auparavant inaccessible car `lm.fit` plantait avant de retourner NA) +- `pois_fam <- poisson()` : famille créée une fois hors du `vapply` (évite p réallocations) + +**Fix 8 — `extract_model` : `!inherits` au lieu de `is.symbol`** (`R/utils.R`) + +`is.symbol(call$formula)` ne couvrait pas les expressions de type `call` (ex. `formula(paste(...))`), laissant l'attribut `xlevels` être assigné à un objet non-formula. Remplacé par `!inherits(call$formula, "formula")` qui couvre tous les cas non-formula. + +--- + +## 18. Nettoyage de la suite de tests (10/06) + +**Fichiers** : `tests/testthat/test-pln.R`, `tests/testthat/test-plnlda-fit.R`, `tests/testthat/test-standard-error.R` + +### Test cassé par Fix 7 (`singular.ok = TRUE`) + +`test-pln.R` lignes 209–225 attendait `expect_error(PLN(Y ~ X_singular))`. Après Fix 7, PLN gère silencieusement les designs singuliers (coefficients à 0 via `B[is.na(B)] <- 0`) au lieu de planter. Le test est mis à jour : + +- Description : `"PLN: singular covariate model matrix is handled gracefully"` +- `expect_error` → `expect_no_error` pour les deux cas (covariables continues dupliquées, facteurs corrélés) + +### Faux label + doublon (`test-pln.R` lignes 72–95) + +Les deux blocs "diagonal" et "spherical" utilisaient `covariance = "spherical"` : code identique, couverture identique. Le bloc "diagonal" est corrigé pour utiliser réellement `covariance = "diagonal"` (ajout d'une couverture manquante). La variable `model3` (poids aléatoires sans `expect_*`) dans le bloc spherical est supprimée. + +### Duplicate cross-fichier (`test-plnlda-fit.R` lignes 103–122) + +Le test "PLNLDA fit: Check number of parameters" testait `PLN()` (copie quasi-identique de `test-plnfit.R:239`). Remplacé par un vrai test de `PLNLDA$nb_param` : Σ (`p*(p+1)/2`) + group means (`p*g`) + éventuels régresseurs. + +### Noms de tests dupliqués (`test-standard-error.R` lignes 151, 159) + +Deux blocs portaient le nom identique `"Check that variance estimation are coherent in PLNnetwork"`. Le premier testait en réalité PLNPCA. Renommé en `"Check that variance estimation are coherent in PLNPCA"`. + +--- + ## Récapitulatif des backends disponibles | `backend` | Algorithme | Défaut pour | @@ -458,3 +554,42 @@ De plus, `test-plnlda-fit.R` passait `PLNLDA_param(covariance = "diagonal/spheri | `R/plot_utils.R` | `GeomCircle`/`geom_circle` supprimés ; bug `center[1]` corrigé | | `src/nlopt_wrapper.h` | Déclarations commentées supprimées | | `src/nlopt_wrapper.cpp` | Corps commentés + appels orphelins supprimés | + +--- + +## 19. Audit C++ — corrections appliquées (10/06) + +Audit complet du code C++ : 8 améliorations identifiées (★★★ bugs/efficacité, ★★ factorisation, ★ style) et intégralement appliquées. + +### Corrections ★★★ + +**Fix 1 — Guard P_X pour d=0 (`nlopt_*.cpp`)** : quand la formule est `~ 0` (sans covariables), `X` est une matrice (n×0) et `arma::solve(X.t() * Xw, Xw.t())` déclenchait un avertissement Armadillo. Corrigé dans les 4 fichiers : +```cpp +// Avant (tous les fichiers nlopt) : +const arma::mat P_X = arma::solve(X.t() * Xw, Xw.t()); +// Après : +const arma::mat P_X = (X.n_cols > 0) ? arma::solve(X.t() * Xw, Xw.t()) : arma::mat(0, Y.n_rows); +``` + +**Fix 2 — O(p³) → O(np) dans `nlopt_fixed_cov.cpp`** : l'objectif utilisait `trace(Omega * (...))` coûtant O(p³), remplacé par le calcul élément-par-élément d'O(np) via `full_cov_obj_grad_impl` (déjà utilisée dans `nlopt_full_cov.cpp`). Gain asymptotique pour grand p. + +**Fix 3 — Factorisation `FullCovTraits`/`FixedCovTraits`** : ces deux traits partageaient 6 méthodes statiques identiques (~35 lignes de duplication). Nouveau `DenseOmegaImpl` base struct avec les 6 méthodes ; `FullCovTraits` et `FixedCovTraits` en héritent. Seuls `mstep`, `elbo_cov`, `output_cov`, et `has_em` restent spécialisés. + +### Corrections ★★ + +**Fix 4 — `NewtonConfig` dans `utils.h`** : struct centralisant l'extraction de config depuis `Rcpp::List` (pattern `containsElementNamed` répété 4 fois × 4 fichiers → 1 struct). + +**Fix 5 — Adoption de `NewtonConfig`** : les 4 fichiers `newton_*.cpp` + `nlopt_full_cov.cpp` utilisent désormais `const NewtonConfig cfg(config);` au lieu du bloc 4-lignes dupliqué. + +**Fix 6 — `nlopt_impl.h`** : nouveau header partagé exposant les 3 helpers `inline` (`full_cov_obj_grad_impl`, `diag_cov_obj_grad_impl`, `spherical_cov_obj_grad_impl`). Les copies `static` locales ont été supprimées des 3 fichiers `nlopt_*.cpp` qui les dupliquaient. + +**Fix 7 — Méthode `update()` dans chaque `State`** : les constructeurs et `mstep` des 3 traits à covariance estimée (Full, Diagonal, Sphérique) contenaient un code identique. Ajout d'une méthode `update(M, S2, w, w_bar)` à chaque `State` ; le constructeur et `mstep` délèguent vers elle. + +### Correction ★ + +**Fix 8 — `SphericalCovTraits::output_cov`** : `Sigma_out.diag() = arma::ones(p) * s.sigma2` remplacé par `Sigma_out.diag().fill(s.sigma2)` (supprime la construction inutile d'un vecteur temporaire de 1s). + +### Résultat + +- Compilation propre (0 erreur, 0 nouveau warning) +- 72 tests PLN passent (FAIL 0) diff --git a/memory/feedback_cpp_audit.md b/memory/feedback_cpp_audit.md new file mode 100644 index 00000000..f741b820 --- /dev/null +++ b/memory/feedback_cpp_audit.md @@ -0,0 +1,30 @@ +--- +name: feedback-cpp-audit +description: Corrections C++ appliquées sur la branche code-enhancement en juin 2026 — 8 fixes, compilation propre, 72 tests passent +metadata: + type: feedback +--- + +8 améliorations C++ appliquées intégralement le 10/06/2026. Toutes les corrections sont sur la branche `code-enhancement`. + +**Fixes appliqués :** + +1. **Guard P_X (d=0)** — 4 fichiers `nlopt_*.cpp` : `(X.n_cols > 0) ? arma::solve(...) : arma::mat(0, Y.n_rows)` évite le crash quand la formule est `~ 0`. + +2. **O(p³)→O(np) dans `nlopt_fixed_cov.cpp`** : `trace(Omega * (...))` remplacé par `full_cov_obj_grad_impl` (accu elementwise). + +3. **`DenseOmegaImpl` base struct** dans `CovarianceTraits.h` : `FullCovTraits` et `FixedCovTraits` héritent désormais de `DenseOmegaImpl` qui contient les 6 méthodes statiques identiques (`cov_diag`, `grad_hess_M`, `times_Omega`, `penalty_M`, `objective_cov`, `final_loglik`). + +4. **`NewtonConfig` struct** dans `utils.h` : centralise les 4 `containsElementNamed` parsings. + +5. **Adoption `NewtonConfig`** : `newton_{full,diag,spherical,fixed}_cov.cpp` + `nlopt_full_cov.cpp`. + +6. **`nlopt_impl.h`** : nouveau header partagé avec les 3 helpers `inline` ; copies `static` supprimées des `.cpp`. + +7. **Méthode `update()`** dans chaque `State` de `CovarianceTraits.h` : constructeur et `mstep` délèguent vers `s.update(M, S2, w, w_bar)`. + +8. **Style `SphericalCovTraits::output_cov`** : `.fill(s.sigma2)` à la place de `= arma::ones(p) * s.sigma2`. + +**Why:** factorisation, efficacité (O(p³)→O(np)), et robustesse (guard d=0). + +**How to apply:** avant toute modification C++ future, relire `CovarianceTraits.h` pour comprendre la hiérarchie `DenseOmegaImpl → FullCovTraits/FixedCovTraits` et vérifier que les nouvelles méthodes communes sont ajoutées à la base, pas dupliquées. diff --git a/src/CovarianceTraits.h b/src/CovarianceTraits.h index 1da04400..e3fda3b3 100644 --- a/src/CovarianceTraits.h +++ b/src/CovarianceTraits.h @@ -3,22 +3,14 @@ #include "utils.h" // ───────────────────────────────────────────────────────────────────────────── -// Full (dense p×p) covariance +// Shared base for dense (full p×p) Omega variants (FullCovTraits and FixedCovTraits). +// Contains the 6 static methods that are identical in both. Derived traits use +// struct inheritance to expose these methods without repetition. // ───────────────────────────────────────────────────────────────────────────── -struct FullCovTraits { +struct DenseOmegaImpl { struct State { arma::mat Omega; - arma::mat Sigma; arma::vec diag_Omega; - - State(const arma::mat & M, const arma::mat & S2, const arma::vec & w, double w_bar) { - Sigma = (1./w_bar) * (M.t() * (M.each_col() % w) + arma::diagmat(w.t() * S2)); - Omega = arma::inv_sympd(Sigma); - diag_Omega = arma::diagvec(Omega); - } - // vestep: Omega known and fixed - explicit State(const arma::mat & omega) - : Omega(omega), diag_Omega(arma::diagvec(omega)) {} }; static arma::mat cov_diag(const State & s, const arma::mat & ones_row) { @@ -37,7 +29,6 @@ struct FullCovTraits { static arma::mat times_Omega(const arma::mat & M, const State & s) { return M * s.Omega; } - // Takes precomputed MO = M * Omega to avoid redundant matrix multiplies in Armijo static double penalty_M(const arma::mat & MO, const arma::mat & M, const arma::vec & w) { return 0.5 * arma::as_scalar(w.t() * arma::sum(MO % M, 1)); } @@ -48,17 +39,6 @@ struct FullCovTraits { + arma::dot(s.diag_Omega, (w.t() * S2).t())); } - static void mstep(State & s, const arma::mat & M, const arma::mat & S2, - const arma::vec & w, double w_bar, arma::uword /*p*/) { - s.Sigma = (1./w_bar) * (M.t() * (M.each_col() % w) + arma::diagmat(w.t() * S2)); - s.Omega = arma::inv_sympd(s.Sigma); - s.diag_Omega = arma::diagvec(s.Omega); - } - - static double elbo_cov(const State & s, double w_bar, arma::uword /*p*/) { - return -0.5 * w_bar * std::real(arma::log_det(s.Sigma)); - } - static arma::vec final_loglik(const arma::mat & Y, const arma::mat & Z, const arma::mat & A, const arma::mat & M, const arma::mat & psi, const State & s) { const arma::mat S2 = arma::exp(psi); @@ -66,6 +46,37 @@ struct FullCovTraits { - 0.5 * ((M * s.Omega) % M + S2 * arma::diagmat(s.Omega)), 1) + 0.5 * std::real(arma::log_det(s.Omega)) + ki(Y); } +}; + +// ───────────────────────────────────────────────────────────────────────────── +// Full (dense p×p) covariance +// ───────────────────────────────────────────────────────────────────────────── +struct FullCovTraits : DenseOmegaImpl { + struct State : DenseOmegaImpl::State { + arma::mat Sigma; + + State(const arma::mat & M, const arma::mat & S2, const arma::vec & w, double w_bar) { + update(M, S2, w, w_bar); + } + explicit State(const arma::mat & omega) { + Omega = omega; + diag_Omega = arma::diagvec(omega); + } + void update(const arma::mat & M, const arma::mat & S2, const arma::vec & w, double w_bar) { + Sigma = (1./w_bar) * (M.t() * (M.each_col() % w) + arma::diagmat(w.t() * S2)); + Omega = arma::inv_sympd(Sigma); + diag_Omega = arma::diagvec(Omega); + } + }; + + static void mstep(State & s, const arma::mat & M, const arma::mat & S2, + const arma::vec & w, double w_bar, arma::uword /*p*/) { + s.update(M, S2, w, w_bar); + } + + static double elbo_cov(const State & s, double w_bar, arma::uword /*p*/) { + return -0.5 * w_bar * std::real(arma::log_det(s.Sigma)); + } static Rcpp::List output_cov(const arma::mat & /*M*/, const arma::mat & /*S2*/, const arma::vec & /*w*/, double /*w_bar*/, const State & s) { @@ -84,14 +95,16 @@ struct DiagonalCovTraits { arma::rowvec sigma2; State(const arma::mat & M, const arma::mat & S2, const arma::vec & w, double w_bar) { - sigma2 = (w.t() * (M % M + S2)) / w_bar; - omega2 = arma::pow(sigma2, -1); + update(M, S2, w, w_bar); } - // vestep: Omega known and fixed (diagonal matrix passed as dense mat) explicit State(const arma::mat & omega_mat) { omega2 = arma::diagvec(omega_mat).t(); sigma2 = arma::pow(omega2, -1); } + void update(const arma::mat & M, const arma::mat & S2, const arma::vec & w, double w_bar) { + sigma2 = (w.t() * (M % M + S2)) / w_bar; + omega2 = arma::pow(sigma2, -1); + } }; static arma::mat cov_diag(const State & s, const arma::mat & ones_row) { @@ -119,8 +132,7 @@ struct DiagonalCovTraits { static void mstep(State & s, const arma::mat & M, const arma::mat & S2, const arma::vec & w, double w_bar, arma::uword /*p*/) { - s.sigma2 = (w.t() * (M % M + S2)) / w_bar; - s.omega2 = arma::pow(s.sigma2, -1); + s.update(M, S2, w, w_bar); } static double elbo_cov(const State & s, double w_bar, arma::uword /*p*/) { @@ -156,13 +168,15 @@ struct SphericalCovTraits { double sigma2; State(const arma::mat & M, const arma::mat & S2, const arma::vec & w, double w_bar) { + update(M, S2, w, w_bar); + } + explicit State(const arma::mat & omega_mat) + : omega2(omega_mat(0, 0)), sigma2(1.0 / omega_mat(0, 0)) {} + void update(const arma::mat & M, const arma::mat & S2, const arma::vec & w, double w_bar) { arma::uword p = M.n_cols; sigma2 = arma::accu(arma::diagmat(w) * (M % M + S2)) / (double(p) * w_bar); omega2 = 1.0 / sigma2; } - // vestep: Omega known and fixed (scalar diagonal matrix) - explicit State(const arma::mat & omega_mat) - : omega2(omega_mat(0, 0)), sigma2(1.0 / omega_mat(0, 0)) {} }; // returns double: fixed_point_psi handles scalar broadcast @@ -190,9 +204,8 @@ struct SphericalCovTraits { } static void mstep(State & s, const arma::mat & M, const arma::mat & S2, - const arma::vec & w, double w_bar, arma::uword p) { - s.sigma2 = arma::accu(arma::diagmat(w) * (M % M + S2)) / (double(p) * w_bar); - s.omega2 = 1.0 / s.sigma2; + const arma::vec & w, double w_bar, arma::uword /*p*/) { + s.update(M, S2, w, w_bar); } static double elbo_cov(const State & s, double w_bar, arma::uword p) { @@ -209,8 +222,8 @@ struct SphericalCovTraits { static Rcpp::List output_cov(const arma::mat & M, const arma::mat & /*S2*/, const arma::vec & /*w*/, double /*w_bar*/, const State & s) { arma::uword p = M.n_cols; - arma::sp_mat Sigma_out(p, p); Sigma_out.diag() = arma::ones(p) * s.sigma2; - arma::sp_mat Omega_out(p, p); Omega_out.diag() = arma::ones(p) * s.omega2; + arma::sp_mat Sigma_out(p, p); Sigma_out.diag().fill(s.sigma2); + arma::sp_mat Omega_out(p, p); Omega_out.diag().fill(s.omega2); return Rcpp::List::create(Rcpp::Named("Sigma", Sigma_out), Rcpp::Named("Omega", Omega_out)); } @@ -220,41 +233,14 @@ struct SphericalCovTraits { // ───────────────────────────────────────────────────────────────────────────── // Fixed covariance (Omega provided externally, not estimated) // ───────────────────────────────────────────────────────────────────────────── -struct FixedCovTraits { - struct State { - arma::mat Omega; - arma::vec diag_Omega; - - explicit State(const arma::mat & omega) - : Omega(omega), diag_Omega(arma::diagvec(omega)) {} +struct FixedCovTraits : DenseOmegaImpl { + struct State : DenseOmegaImpl::State { + explicit State(const arma::mat & omega) { + Omega = omega; + diag_Omega = arma::diagvec(omega); + } }; - static arma::mat cov_diag(const State & s, const arma::mat & ones_row) { - return ones_row * s.diag_Omega.t(); - } - - static void grad_hess_M( - const arma::mat & M, const State & s, - const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & ones_row, - arma::mat & grad_M, arma::mat & hess_M) - { - arma::mat MO = M * s.Omega; - grad_M = MO + A - Y; grad_M.each_col() %= w; - hess_M = A + ones_row * s.diag_Omega.t(); hess_M.each_col() %= w; - } - - static arma::mat times_Omega(const arma::mat & M, const State & s) { return M * s.Omega; } - - static double penalty_M(const arma::mat & MO, const arma::mat & M, const arma::vec & w) { - return 0.5 * arma::as_scalar(w.t() * arma::sum(MO % M, 1)); - } - - static double objective_cov(const arma::mat & M, const arma::mat & S2, const State & s, const arma::vec & w) { - arma::mat MO = M * s.Omega; - return 0.5 * (arma::as_scalar(w.t() * arma::sum(MO % M, 1)) - + arma::dot(s.diag_Omega, (w.t() * S2).t())); - } - static void mstep(State & /*s*/, const arma::mat & /*M*/, const arma::mat & /*S2*/, const arma::vec & /*w*/, double /*w_bar*/, arma::uword /*p*/) {} @@ -262,14 +248,6 @@ struct FixedCovTraits { return 0.0; } - static arma::vec final_loglik(const arma::mat & Y, const arma::mat & Z, const arma::mat & A, - const arma::mat & M, const arma::mat & psi, const State & s) { - const arma::mat S2 = arma::exp(psi); - return arma::sum(Y % Z - A + 0.5 * psi - - 0.5 * ((M * s.Omega) % M + S2 * arma::diagmat(s.Omega)), 1) - + 0.5 * std::real(arma::log_det(s.Omega)) + ki(Y); - } - static Rcpp::List output_cov(const arma::mat & M, const arma::mat & S2, const arma::vec & w, double w_bar, const State & s) { arma::mat Sigma = (M.t() * (M.each_col() % w) + arma::diagmat(w.t() * S2)) / w_bar; diff --git a/src/newton_diag_cov.cpp b/src/newton_diag_cov.cpp index 58448d25..89eaf23c 100644 --- a/src/newton_diag_cov.cpp +++ b/src/newton_diag_cov.cpp @@ -23,17 +23,14 @@ Rcpp::List newton_optimize_diagonal( arma::mat M = Rcpp::as(params["M"]); arma::mat S = Rcpp::as(params["S"]); - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; - const int max_em = config.containsElementNamed("maxit_em") ? Rcpp::as(config["maxit_em"]) : 50; - const double em_tol = config.containsElementNamed("ftol_em") ? Rcpp::as(config["ftol_em"]) : 1e-8; + const NewtonConfig cfg(config); const double w_bar = arma::accu(w); arma::mat S2 = S % S; const arma::mat M_res_init = M - X * B; DiagonalCovTraits::State state(M_res_init, S2, w, w_bar); - return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); + return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); } // --------------------------------------------------------------------------------------- diff --git a/src/newton_fixed_cov.cpp b/src/newton_fixed_cov.cpp index 44eea435..055ca440 100644 --- a/src/newton_fixed_cov.cpp +++ b/src/newton_fixed_cov.cpp @@ -23,11 +23,8 @@ Rcpp::List newton_optimize_fixed( arma::mat S = Rcpp::as(params["S"]); arma::mat Omega = Rcpp::as(params["Omega"]); - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; - const int max_em = config.containsElementNamed("maxit_em") ? Rcpp::as(config["maxit_em"]) : 50; - const double em_tol = config.containsElementNamed("ftol_em") ? Rcpp::as(config["ftol_em"]) : 1e-8; + const NewtonConfig cfg(config); FixedCovTraits::State state(Omega); - return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); + return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); } diff --git a/src/newton_full_cov.cpp b/src/newton_full_cov.cpp index 43fe8938..7b297033 100644 --- a/src/newton_full_cov.cpp +++ b/src/newton_full_cov.cpp @@ -23,17 +23,14 @@ Rcpp::List newton_optimize_full( arma::mat M = Rcpp::as(params["M"]); arma::mat S = Rcpp::as(params["S"]); - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; - const int max_em = config.containsElementNamed("maxit_em") ? Rcpp::as(config["maxit_em"]) : 50; - const double em_tol = config.containsElementNamed("ftol_em") ? Rcpp::as(config["ftol_em"]) : 1e-8; + const NewtonConfig cfg(config); const double w_bar = arma::accu(w); arma::mat S2 = S % S; const arma::mat M_res_init = M - X * B; FullCovTraits::State state(M_res_init, S2, w, w_bar); - return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); + return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); } // --------------------------------------------------------------------------------------- diff --git a/src/newton_spherical.cpp b/src/newton_spherical.cpp index a1aca677..aad91790 100644 --- a/src/newton_spherical.cpp +++ b/src/newton_spherical.cpp @@ -23,17 +23,14 @@ Rcpp::List newton_optimize_spherical( arma::mat M = Rcpp::as(params["M"]); arma::mat S = Rcpp::as(params["S"]); - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; - const int max_em = config.containsElementNamed("maxit_em") ? Rcpp::as(config["maxit_em"]) : 50; - const double em_tol = config.containsElementNamed("ftol_em") ? Rcpp::as(config["ftol_em"]) : 1e-8; + const NewtonConfig cfg(config); const double w_bar = arma::accu(w); arma::mat S2 = S % S; const arma::mat M_res_init = M - X * B; SphericalCovTraits::State state(M_res_init, S2, w, w_bar); - return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, maxiter, ftol, max_em, em_tol); + return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); } // --------------------------------------------------------------------------------------- diff --git a/src/nlopt_diag_cov.cpp b/src/nlopt_diag_cov.cpp index dbbcabaa..97cfcaae 100644 --- a/src/nlopt_diag_cov.cpp +++ b/src/nlopt_diag_cov.cpp @@ -6,24 +6,7 @@ #include "nlopt_wrapper.h" #include "packing.h" #include "utils.h" - -// --------------------------------------------------------------------------------------- -// Shared inner computation for diagonal-covariance NLOPT objective and gradients. -// Z = O + X*B + M_res and S2 = exp(logS2) must be pre-computed by the caller. -// inv_sigma2: row vector of element-wise precisions (profiled 1/diag_sigma or fixed omega2). -// penalty: KL variance term (log-det for profiled E-step; quadratic for fixed-omega vestep). -static double diag_cov_obj_grad_impl( - const arma::mat & M_res, const arma::mat & Z, - const arma::mat & S2, const arma::mat & logS2, - const arma::rowvec & inv_sigma2, double penalty, - const arma::mat & Y, const arma::vec & w, - arma::mat & grad_M, arma::mat & grad_S -) { - const arma::mat A = arma::exp(Z + 0.5 * S2); - grad_M = arma::diagmat(w) * (M_res.each_row() % inv_sigma2 + A - Y); - grad_S = 0.5 * arma::diagmat(w) * (S2.each_row() % inv_sigma2 + S2 % A - 1.); - return accu(w.t() * (A - Y % Z - 0.5 * logS2)) + penalty; -} +#include "nlopt_impl.h" // --------------------------------------------------------------------------------------- // Diagonal covariance PLN — nlopt/CCSAQ optimizer: B profiled via closed form, reduced parameter vector @@ -55,7 +38,7 @@ Rcpp::List nlopt_optimize_diagonal( const double w_bar = accu(w); const arma::mat Xw = X.each_col() % w; - const arma::mat P_X = arma::solve(X.t() * Xw, Xw.t()); + const arma::mat P_X = (X.n_cols > 0) ? arma::solve(X.t() * Xw, Xw.t()) : arma::mat(0, Y.n_rows); // E-step: M_full is the NLOPT parameter; B and diag_sigma profiled at each eval auto objective_and_grad = [&](const double * par, double * grad) -> double { diff --git a/src/nlopt_fixed_cov.cpp b/src/nlopt_fixed_cov.cpp index 89de508c..b4fec9d8 100644 --- a/src/nlopt_fixed_cov.cpp +++ b/src/nlopt_fixed_cov.cpp @@ -6,6 +6,7 @@ #include "nlopt_wrapper.h" #include "packing.h" #include "utils.h" +#include "nlopt_impl.h" // --------------------------------------------------------------------------------------- // Fixed covariance PLN — nlopt/CCSAQ optimizer: B profiled via closed form, reduced parameter vector @@ -35,26 +36,21 @@ Rcpp::List nlopt_optimize_fixed( auto optimizer = new_nlopt_optimizer(config, parameters.size()); std::vector objective_vec; - const arma::mat Xw = X.each_col() % w; - const arma::mat P_X = arma::solve(X.t() * Xw, Xw.t()); + const arma::mat Xw = X.each_col() % w; + const arma::mat P_X = (X.n_cols > 0) ? arma::solve(X.t() * Xw, Xw.t()) : arma::mat(0, Y.n_rows); const arma::vec Omega_diag = diagvec(Omega); auto objective_and_grad = [&](const double * par, double * grad) -> double { const arma::mat M_full = metadata.map(par); const arma::mat logS2 = metadata.map(par); - arma::mat S2 = arma::exp(logS2); - arma::mat B = P_X * M_full; - arma::mat M_res = M_full - X * B; - arma::mat Z = O + M_full; - arma::mat A = exp(Z + 0.5 * S2); - double objective = accu(w.t() * (A - Y % Z - 0.5 * logS2)) - + 0.5 * trace(Omega * (M_res.t() * (M_res.each_col() % w) + diagmat(w.t() * S2))); - // gradient for M_full = gradient for M_res (envelope theorem for B) - metadata.map(grad) = diagmat(w) * (M_res * Omega + A - Y); - // grad_logS2 = ½ w ⊙ (S²⊙(Ω_diag + A) − 1) - metadata.map(grad) = 0.5 * diagmat(w) * (S2.each_row() % Omega_diag.t() + S2 % A - 1.); - objective_vec.push_back(objective); - return objective; + const arma::mat B = P_X * M_full; + const arma::mat M_res = M_full - X * B; + arma::mat gM, gS; + const double obj = full_cov_obj_grad_impl(M_res, O + M_full, logS2, Omega, Omega_diag, Y, w, gM, gS); + metadata.map(grad) = gM; + metadata.map(grad) = gS; + objective_vec.push_back(obj); + return obj; }; OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); diff --git a/src/nlopt_full_cov.cpp b/src/nlopt_full_cov.cpp index 61351f89..f9437288 100644 --- a/src/nlopt_full_cov.cpp +++ b/src/nlopt_full_cov.cpp @@ -6,24 +6,7 @@ #include "nlopt_wrapper.h" #include "packing.h" #include "utils.h" - -// --------------------------------------------------------------------------------------- -// Shared inner computation: full-covariance NLOPT objective and gradients. -// Z = O + X*B + M_res must be computed by the caller (varies between E-step and vestep). -static double full_cov_obj_grad_impl( - const arma::mat & M_res, const arma::mat & Z, const arma::mat & logS2, - const arma::mat & Omega, const arma::vec & Omega_diag, - const arma::mat & Y, const arma::vec & w, - arma::mat & grad_M, arma::mat & grad_S -) { - const arma::mat S2 = arma::exp(logS2); - const arma::mat A = arma::exp(Z + 0.5 * S2); - const arma::mat MO = M_res * Omega; - grad_M = arma::diagmat(w) * (MO + A - Y); - grad_S = 0.5 * arma::diagmat(w) * (S2.each_row() % Omega_diag.t() + S2 % A - 1.); - return accu(w.t() * (A - Y % Z - 0.5 * logS2)) - + 0.5 * (accu(MO % (M_res.each_col() % w)) + dot(Omega_diag, (w.t() * S2).t())); -} +#include "nlopt_impl.h" // --------------------------------------------------------------------------------------- // Full covariance PLN — nlopt/CCSAQ optimizer: B profiled via closed form, reduced parameter vector @@ -50,13 +33,12 @@ Rcpp::List nlopt_optimize_full( metadata.map(parameters.data()) = init_M; metadata.map(parameters.data()) = arma::log(init_S % init_S); - const double w_bar = accu(w); - const int maxit_em = config.containsElementNamed("maxit_em") ? Rcpp::as(config["maxit_em"]) : 50; - const double ftol_em = config.containsElementNamed("ftol_em") ? Rcpp::as(config["ftol_em"]) : 1e-8; + const double w_bar = accu(w); + const NewtonConfig cfg(config); // P_X = (X'WX)^{-1} X'W : d×n, precomputed once; B = P_X * M_full at each eval const arma::mat Xw = X.each_col() % w; - const arma::mat P_X = arma::solve(X.t() * Xw, Xw.t()); + const arma::mat P_X = (X.n_cols > 0) ? arma::solve(X.t() * Xw, Xw.t()) : arma::mat(0, Y.n_rows); // Initial Omega: M_res = M_full - X*B arma::mat Omega; @@ -72,7 +54,7 @@ Rcpp::List nlopt_optimize_full( int total_iterations = 0; int last_status = 0; - for (int em_iter = 0; em_iter < std::max(1, maxit_em); em_iter++) { + for (int em_iter = 0; em_iter < std::max(1, cfg.max_em); em_iter++) { auto optimizer = new_nlopt_optimizer(config, parameters.size()); objective_vec.reserve(objective_vec.size() + nlopt_get_maxeval(optimizer.get())); const arma::vec Omega_diag = diagvec(Omega); @@ -107,7 +89,7 @@ Rcpp::List nlopt_optimize_full( arma::mat A = exp(Z + 0.5 * S2); double elbo = accu(w.t() * (Y % Z - A + 0.5 * logS2)) - 0.5 * w_bar * real(log_det(Sigma)); - if (em_iter > 0 && converged(elbo, elbo_prev, ftol_em)) break; + if (em_iter > 0 && converged(elbo, elbo_prev, cfg.em_tol)) break; elbo_prev = elbo; } diff --git a/src/nlopt_impl.h b/src/nlopt_impl.h new file mode 100644 index 00000000..501d4fdb --- /dev/null +++ b/src/nlopt_impl.h @@ -0,0 +1,52 @@ +#pragma once +#include + +// Shared objective/gradient implementations for the three NLOPT covariance variants. +// Defined inline here so nlopt_full_cov.cpp, nlopt_diag_cov.cpp, nlopt_spherical.cpp and +// nlopt_fixed_cov.cpp can all include this header instead of each defining a private static copy. + +// Full covariance: Z = O + M_full supplied by caller. +// Returns the ELBO objective (negated); fills grad_M and grad_S. +inline double full_cov_obj_grad_impl( + const arma::mat & M_res, const arma::mat & Z, const arma::mat & logS2, + const arma::mat & Omega, const arma::vec & Omega_diag, + const arma::mat & Y, const arma::vec & w, + arma::mat & grad_M, arma::mat & grad_S +) { + const arma::mat S2 = arma::exp(logS2); + const arma::mat A = arma::exp(Z + 0.5 * S2); + const arma::mat MO = M_res * Omega; + grad_M = arma::diagmat(w) * (MO + A - Y); + grad_S = 0.5 * arma::diagmat(w) * (S2.each_row() % Omega_diag.t() + S2 % A - 1.); + return accu(w.t() * (A - Y % Z - 0.5 * logS2)) + + 0.5 * (accu(MO % (M_res.each_col() % w)) + dot(Omega_diag, (w.t() * S2).t())); +} + +// Diagonal covariance: inv_sigma2 = row vector of precisions (profiled or fixed); +// penalty = KL covariance term pre-computed by the caller (differs between E-step and vestep). +inline double diag_cov_obj_grad_impl( + const arma::mat & M_res, const arma::mat & Z, + const arma::mat & S2, const arma::mat & logS2, + const arma::rowvec & inv_sigma2, double penalty, + const arma::mat & Y, const arma::vec & w, + arma::mat & grad_M, arma::mat & grad_S +) { + const arma::mat A = arma::exp(Z + 0.5 * S2); + grad_M = arma::diagmat(w) * (M_res.each_row() % inv_sigma2 + A - Y); + grad_S = 0.5 * arma::diagmat(w) * (S2.each_row() % inv_sigma2 + S2 % A - 1.); + return accu(w.t() * (A - Y % Z - 0.5 * logS2)) + penalty; +} + +// Spherical covariance: inv_sigma2 = scalar precision; penalty pre-computed by caller. +inline double spherical_cov_obj_grad_impl( + const arma::mat & M_res, const arma::mat & Z, + const arma::mat & S2, const arma::mat & logS2, + double inv_sigma2, double penalty, + const arma::mat & Y, const arma::vec & w, + arma::mat & grad_M, arma::mat & grad_S +) { + const arma::mat A = arma::exp(Z + 0.5 * S2); + grad_M = arma::diagmat(w) * (M_res * inv_sigma2 + A - Y); + grad_S = 0.5 * arma::diagmat(w) * (S2 * inv_sigma2 + S2 % A - 1.); + return accu(w.t() * (A - Y % Z - 0.5 * logS2)) + penalty; +} diff --git a/src/nlopt_spherical.cpp b/src/nlopt_spherical.cpp index 453715b9..4434bd33 100644 --- a/src/nlopt_spherical.cpp +++ b/src/nlopt_spherical.cpp @@ -6,24 +6,7 @@ #include "nlopt_wrapper.h" #include "packing.h" #include "utils.h" - -// --------------------------------------------------------------------------------------- -// Shared inner computation for spherical-covariance NLOPT objective and gradients. -// Z = O + X*B + M_res and S2 = exp(logS2) must be pre-computed by the caller. -// inv_sigma2: scalar precision (profiled 1/sigma2 or fixed omega2 = Omega(0,0)). -// penalty: KL variance term (log for profiled E-step; quadratic for fixed-omega vestep). -static double spherical_cov_obj_grad_impl( - const arma::mat & M_res, const arma::mat & Z, - const arma::mat & S2, const arma::mat & logS2, - double inv_sigma2, double penalty, - const arma::mat & Y, const arma::vec & w, - arma::mat & grad_M, arma::mat & grad_S -) { - const arma::mat A = arma::exp(Z + 0.5 * S2); - grad_M = arma::diagmat(w) * (M_res * inv_sigma2 + A - Y); - grad_S = 0.5 * arma::diagmat(w) * (S2 * inv_sigma2 + S2 % A - 1.); - return accu(w.t() * (A - Y % Z - 0.5 * logS2)) + penalty; -} +#include "nlopt_impl.h" // --------------------------------------------------------------------------------------- // Spherical covariance PLN — nlopt/CCSAQ optimizer: B profiled via closed form, reduced parameter vector @@ -56,7 +39,7 @@ Rcpp::List nlopt_optimize_spherical( objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); const arma::mat Xw = X.each_col() % w; - const arma::mat P_X = arma::solve(X.t() * Xw, Xw.t()); + const arma::mat P_X = (X.n_cols > 0) ? arma::solve(X.t() * Xw, Xw.t()) : arma::mat(0, Y.n_rows); // E-step: M_full is the NLOPT parameter; B and sigma2 profiled at each eval auto objective_and_grad = [&](const double * par, double * grad) -> double { diff --git a/src/utils.h b/src/utils.h index 495978af..1f4a9f98 100644 --- a/src/utils.h +++ b/src/utils.h @@ -77,3 +77,18 @@ inline void fixed_point_psi( inline bool converged(double val, double prev, double tol) { return std::abs(val - prev) < tol * (1.0 + std::abs(prev)); } + +// ---- Config extraction for homemade Newton optimizers ---- +// Centralises the containsElementNamed pattern replicated across all newton_*.cpp files. +struct NewtonConfig { + int maxiter = 200; + double ftol = 1e-8; + int max_em = 50; + double em_tol = 1e-8; + explicit NewtonConfig(const Rcpp::List & cfg) { + if (cfg.containsElementNamed("maxeval")) maxiter = Rcpp::as(cfg["maxeval"]); + if (cfg.containsElementNamed("ftol_in")) ftol = Rcpp::as(cfg["ftol_in"]); + if (cfg.containsElementNamed("maxit_em")) max_em = Rcpp::as(cfg["maxit_em"]); + if (cfg.containsElementNamed("ftol_em")) em_tol = Rcpp::as(cfg["ftol_em"]); + } +}; From 16a79a3d1ff956fbb140ed2858fe9e7ddb957940 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Thu, 11 Jun 2026 11:59:00 +0200 Subject: [PATCH 37/58] avoid redundancies with exp in Newton optim --- src/newton_impl.h | 26 ++++++++++++++------------ src/newton_impl_alt.h | 27 ++++++++++++++------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/newton_impl.h b/src/newton_impl.h index 956f0978..39e17d3c 100644 --- a/src/newton_impl.h +++ b/src/newton_impl.h @@ -32,11 +32,13 @@ Rcpp::List newton_optimize_impl( auto inner_loop = [&]() { double obj_prev = arma::datum::inf; - for (int it = 0; it < maxiter; it++) { - S2 = arma::exp(psi); - arma::mat Z = O + X * B + M; - arma::mat A = arma::exp(Z + 0.5 * S2); + // S2 is current (fixed_point_psi updated it in previous round, or initialized above). + // Z and A are kept current at the end of each iteration; compute them once here. + arma::mat Z = O + X * B + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + for (int it = 0; it < maxiter; it++) { + // S2, Z, A are current; newton_step_B will update B, Z, A. newton_step_B(Xw, Xw2, X, Y, O, w, M, S2, B, Z, A); arma::mat grad_M, hess_M; @@ -80,7 +82,7 @@ Rcpp::List newton_optimize_impl( for (int em = 0; em < max_em; em++) { inner_loop(); - S2 = arma::exp(psi); + // S2 is current: fixed_point_psi updated it inside inner_loop. Traits::mstep(state, M, S2, w, w_bar, p); arma::mat Z = O + X * B + M; @@ -143,11 +145,13 @@ Rcpp::List newton_vestep_impl( double obj_prev = arma::datum::inf; int total_iter = 0; + // Z and A are kept current at the end of each iteration; compute them once here. + arma::mat Z = O + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + for (int it = 0; it < maxiter; it++) { - S2 = arma::exp(psi); + // S2, Z, A are current. arma::mat M_res = M - XB; // M_res for KL terms (B is fixed) - arma::mat Z = O + M; // Z = O + M_full - arma::mat A = arma::exp(Z + 0.5 * S2); // ---- Diagonal Newton step for M (gradient == gradient w.r.t. M_res, B fixed) ---- arma::mat grad_M, hess_M; @@ -187,11 +191,9 @@ Rcpp::List newton_vestep_impl( } // ---- Final output ---- - S2 = arma::exp(psi); + // S2, Z, A are current from the last iteration (fixed_point_psi + exp update). S = arma::exp(0.5 * psi); - arma::mat Z = O + M; // Z = O + M_full - arma::mat A = arma::exp(Z + 0.5 * S2); - arma::mat M_res = M - XB; // for loglik KL terms + const arma::mat M_res = M - XB; // for loglik KL terms arma::vec loglik = Traits::final_loglik(Y, Z, A, M_res, psi, state); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); diff --git a/src/newton_impl_alt.h b/src/newton_impl_alt.h index e47ab9bf..05cb729f 100644 --- a/src/newton_impl_alt.h +++ b/src/newton_impl_alt.h @@ -43,15 +43,17 @@ Rcpp::List newton_optimize_alt_impl( // Inner loop: B profiled at each Newton step via envelope theorem. auto inner_loop = [&]() { double obj_prev = arma::datum::inf; + // S2 is current (fixed_point_psi updated it in the previous round, or initialized above). + // Sync B, Z, A once per EM round; they are kept current at the end of each Newton step + // so subsequent iterations reuse them directly without recomputation. + B = P_X * M; + arma::mat Z = O + M; + arma::mat A = arma::exp(Z + 0.5 * S2); for (int it = 0; it < maxiter; it++) { - S2 = arma::exp(psi); - // Envelope theorem: update B to closed-form optimum for current M_full - B = P_X * M; - const arma::mat XB = X * B; // frozen during the Armijo line search below - arma::mat M_res = M - XB; - arma::mat Z = O + M; // Z = O + M_full - arma::mat A = arma::exp(Z + 0.5 * S2); + // S2, B, Z, A are all current here. + const arma::mat XB = X * B; // frozen during the Armijo line search below + const arma::mat M_res = M - XB; // Newton step for M_full: gradient/Hessian are functions of M_res arma::mat grad_M, hess_M; @@ -79,15 +81,15 @@ Rcpp::List newton_optimize_alt_impl( alpha_M *= 0.5; } M -= alpha_M * step_M; - // Keep B current after accepting the M step - B = P_X * M; + B = P_X * M; Z = O + M; // S step: exact fixed-point ψ = −log(A + diag_Ω) fixed_point_psi(psi, S2, Z, A, Traits::cov_diag(state, ones_row)); + // A with new S2 — needed for obj computation and for next iteration A = arma::exp(Z + 0.5 * S2); - arma::mat M_res_new = M - X * B; // updated M_res with live B + const arma::mat M_res_new = M - X * B; double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * psi)) + Traits::objective_cov(M_res_new, S2, state, w); objective_vec.push_back(obj); @@ -102,8 +104,7 @@ Rcpp::List newton_optimize_alt_impl( for (int em = 0; em < max_em; em++) { inner_loop(); - S2 = arma::exp(psi); - + // S2 is current: fixed_point_psi updated it inside inner_loop. // B is already at its optimum (live-updated in inner_loop); only Omega needs updating. // Recompute M_res for the Sigma/Omega M-step. arma::mat M_res = M - X * B; @@ -121,7 +122,7 @@ Rcpp::List newton_optimize_alt_impl( double elbo_prev_fix = -arma::datum::inf; for (int em = 0; em < max_em; em++) { inner_loop(); - S2 = arma::exp(psi); + // S2 is current: fixed_point_psi updated it inside inner_loop. // B already optimal after inner_loop; recompute M_res for ELBO check. arma::mat M_res = M - X * B; arma::mat Z = O + M; From 14a57972829f30dbaf694792b883065244c3973c Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Thu, 11 Jun 2026 13:53:42 +0200 Subject: [PATCH 38/58] exact block newton for small dataset + removing dead code --- R/PLN.R | 1 + R/utils.R | 13 +-- src/CovarianceTraits.h | 50 ++++++++++++ src/newton_diag_cov.cpp | 11 +-- src/newton_fixed_cov.cpp | 4 +- src/newton_full_cov.cpp | 11 +-- src/newton_impl.h | 137 +++++++++++++++++++++----------- src/newton_impl_alt.h | 165 --------------------------------------- src/newton_spherical.cpp | 11 +-- src/utils.h | 18 +++-- 10 files changed, 172 insertions(+), 249 deletions(-) delete mode 100644 src/newton_impl_alt.h diff --git a/R/PLN.R b/R/PLN.R index 7e96822a..36e2582b 100644 --- a/R/PLN.R +++ b/R/PLN.R @@ -97,6 +97,7 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { #' * "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 #' * "maxit_em" stop the EM outer loop when the number of EM iterations exceeds maxit_em. Default is 50 #' * "ftol_em" stop the EM outer loop when the ELBO changes by less than ftol_em (relative). Default is 1e-8 +#' * "block_newton_thresh" for full/fixed covariance: use exact per-observation block Newton (p×p solve) when p ≤ this threshold, diagonal approximation otherwise. Default is 30. Set to 0 to always use the diagonal approximation. #' #' 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. diff --git a/R/utils.R b/R/utils.R index b20c2c12..18b52e95 100644 --- a/R/utils.R +++ b/R/utils.R @@ -16,12 +16,13 @@ config_default_nlopt <- config_default_homemade <- list( - algorithm = "NEWTON", - backend = "homemade", - maxeval = 10000, - ftol_in = 1e-8, - maxit_em = 50, - ftol_em = 1e-8 + algorithm = "NEWTON", + backend = "homemade", + maxeval = 10000, + ftol_in = 1e-8, + maxit_em = 50, + ftol_em = 1e-8, + block_newton_thresh = 30L ) # Hybrid backend: two-phase optimizer — nlopt/CCSAQ (phase 1) then homemade Newton (phase 2). diff --git a/src/CovarianceTraits.h b/src/CovarianceTraits.h index e3fda3b3..b90f87d2 100644 --- a/src/CovarianceTraits.h +++ b/src/CovarianceTraits.h @@ -29,6 +29,32 @@ struct DenseOmegaImpl { static arma::mat times_Omega(const arma::mat & M, const State & s) { return M * s.Omega; } + // Newton step for M. + // p ≤ block_thresh: exact per-observation block Newton — n p×p Cholesky solves, O(np³). + // Captures full Omega correlation; converges in far fewer inner iterations. + // p > block_thresh: diagonal approximation — O(np), same as the original grad_hess_M + divide. + static void compute_step_M( + const arma::mat & M, const State & s, + const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & ones_row, + arma::mat & grad_M, arma::mat & step_M, + arma::uword block_thresh = 30) + { + const arma::uword n = M.n_rows, p = M.n_cols; + const arma::mat MO = M * s.Omega; + grad_M = MO + A - Y; grad_M.each_col() %= w; + step_M.set_size(n, p); + if (p <= block_thresh) { + for (arma::uword i = 0; i < n; i++) { + const arma::mat H_i = w(i) * (arma::diagmat(A.row(i).t()) + s.Omega); + step_M.row(i) = arma::solve(arma::symmatu(H_i), grad_M.row(i).t()).t(); + } + } else { + arma::mat hess = A + ones_row * s.diag_Omega.t(); hess.each_col() %= w; + hess.clamp(1e-10, arma::datum::inf); + step_M = grad_M / hess; + } + } + static double penalty_M(const arma::mat & MO, const arma::mat & M, const arma::vec & w) { return 0.5 * arma::as_scalar(w.t() * arma::sum(MO % M, 1)); } @@ -122,6 +148,18 @@ struct DiagonalCovTraits { static arma::mat times_Omega(const arma::mat & M, const State & s) { return M.each_row() % s.omega2; } + static void compute_step_M( + const arma::mat & M, const State & s, + const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & ones_row, + arma::mat & grad_M, arma::mat & step_M, + arma::uword /*block_thresh*/ = 0) + { + grad_M = M.each_row() % s.omega2 + A - Y; grad_M.each_col() %= w; + arma::mat hess = ones_row * s.omega2 + A; hess.each_col() %= w; + hess.clamp(1e-10, arma::datum::inf); + step_M = grad_M / hess; + } + static double penalty_M(const arma::mat & MO, const arma::mat & M, const arma::vec & w) { return 0.5 * arma::as_scalar(w.t() * arma::sum(MO % M, 1)); } @@ -195,6 +233,18 @@ struct SphericalCovTraits { static arma::mat times_Omega(const arma::mat & M, const State & s) { return s.omega2 * M; } + static void compute_step_M( + const arma::mat & M, const State & s, + const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & /*ones_row*/, + arma::mat & grad_M, arma::mat & step_M, + arma::uword /*block_thresh*/ = 0) + { + grad_M = s.omega2 * M + A - Y; grad_M.each_col() %= w; + arma::mat hess = s.omega2 + A; hess.each_col() %= w; + hess.clamp(1e-10, arma::datum::inf); + step_M = grad_M / hess; + } + static double penalty_M(const arma::mat & MO, const arma::mat & M, const arma::vec & w) { return 0.5 * arma::as_scalar(w.t() * arma::sum(MO % M, 1)); } diff --git a/src/newton_diag_cov.cpp b/src/newton_diag_cov.cpp index 89eaf23c..21ba076e 100644 --- a/src/newton_diag_cov.cpp +++ b/src/newton_diag_cov.cpp @@ -3,8 +3,7 @@ // [[Rcpp::depends(RcppArmadillo)]] #include "utils.h" -#include "newton_impl.h" // newton_vestep_impl -#include "newton_impl_alt.h" // newton_optimize_alt_impl — the homemade E-step +#include "newton_impl.h" // newton_optimize_impl + newton_vestep_impl // --------------------------------------------------------------------------------------- // Diagonal covariance PLN — homemade Newton optimizer (profiled B via envelope theorem) @@ -30,7 +29,7 @@ Rcpp::List newton_optimize_diagonal( const arma::mat M_res_init = M - X * B; DiagonalCovTraits::State state(M_res_init, S2, w, w_bar); - return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); + return newton_optimize_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol, cfg.block_newton_thresh); } // --------------------------------------------------------------------------------------- @@ -51,9 +50,7 @@ Rcpp::List newton_optimize_vestep_diagonal( arma::mat M = Rcpp::as(params["M"]); arma::mat S = Rcpp::as(params["S"]); - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; - + const NewtonConfig cfg(config); DiagonalCovTraits::State state(Omega); - return newton_vestep_impl(Y, X, O, w, M, S, B, state, maxiter, ftol); + return newton_vestep_impl(Y, X, O, w, M, S, B, state, cfg.maxiter, cfg.ftol, cfg.block_newton_thresh); } diff --git a/src/newton_fixed_cov.cpp b/src/newton_fixed_cov.cpp index 055ca440..da670003 100644 --- a/src/newton_fixed_cov.cpp +++ b/src/newton_fixed_cov.cpp @@ -3,7 +3,7 @@ // [[Rcpp::depends(RcppArmadillo)]] #include "utils.h" -#include "newton_impl_alt.h" // newton_optimize_alt_impl — the homemade E-step +#include "newton_impl.h" // newton_optimize_impl — the homemade E-step // --------------------------------------------------------------------------------------- // Fixed inverse covariance (Omega provided externally) PLN — homemade Newton optimizer @@ -26,5 +26,5 @@ Rcpp::List newton_optimize_fixed( const NewtonConfig cfg(config); FixedCovTraits::State state(Omega); - return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); + return newton_optimize_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol, cfg.block_newton_thresh); } diff --git a/src/newton_full_cov.cpp b/src/newton_full_cov.cpp index 7b297033..a94e1706 100644 --- a/src/newton_full_cov.cpp +++ b/src/newton_full_cov.cpp @@ -3,8 +3,7 @@ // [[Rcpp::depends(RcppArmadillo)]] #include "utils.h" -#include "newton_impl.h" // newton_vestep_impl -#include "newton_impl_alt.h" // newton_optimize_alt_impl — the homemade E-step +#include "newton_impl.h" // newton_optimize_impl + newton_vestep_impl // --------------------------------------------------------------------------------------- // Full covariance PLN — homemade Newton optimizer (profiled B via envelope theorem) @@ -30,7 +29,7 @@ Rcpp::List newton_optimize_full( const arma::mat M_res_init = M - X * B; FullCovTraits::State state(M_res_init, S2, w, w_bar); - return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); + return newton_optimize_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol, cfg.block_newton_thresh); } // --------------------------------------------------------------------------------------- @@ -51,9 +50,7 @@ Rcpp::List newton_optimize_vestep_full( arma::mat M = Rcpp::as(params["M"]); arma::mat S = Rcpp::as(params["S"]); - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; - + const NewtonConfig cfg(config); FullCovTraits::State state(Omega); - return newton_vestep_impl(Y, X, O, w, M, S, B, state, maxiter, ftol); + return newton_vestep_impl(Y, X, O, w, M, S, B, state, cfg.maxiter, cfg.ftol, cfg.block_newton_thresh); } diff --git a/src/newton_impl.h b/src/newton_impl.h index 39e17d3c..fc0dce95 100644 --- a/src/newton_impl.h +++ b/src/newton_impl.h @@ -3,26 +3,37 @@ #include "utils.h" #include "CovarianceTraits.h" -// Generic coordinate-Newton EM optimizer for PLN covariance variants. -// Traits encodes the variant-specific math (M grad/hess, M-step, ELBO, loglik). -// has_em=true → double EM+inner loop; has_em=false → single inner loop (fixed cov). +// M_full parameterization: M is the full variational mean of Z_i (= X_i*B + M_res), +// consistent with the ZIPLN convention. M_res = M - X*B is computed locally for KL. +// +// B is profiled at every Newton step via the envelope theorem: +// B = P_X * M = (X'WX)^{-1} X'W M (closed-form optimum for current M) +// M_res = M - X*B (projection orthogonal to col(X)) +// The gradient of J_profiled w.r.t. M equals the gradient w.r.t. M_res (envelope theorem). +// +// Input/output: M is in M_full format throughout. + template Rcpp::List newton_optimize_impl( const arma::mat & Y, const arma::mat & X, const arma::mat & O, const arma::vec & w, arma::mat B, arma::mat M, arma::mat S, typename Traits::State state, - int maxiter, double ftol, int max_em, double em_tol + int maxiter, double ftol, int max_em, double em_tol, + int block_newton_thresh = 30 ) { const int n = Y.n_rows; const arma::uword p = Y.n_cols; const double w_bar = arma::accu(w); const double c1 = 1e-4; - - const arma::mat Xw = X.each_col() % w; - arma::mat Xw2 = X % X; Xw2.each_col() %= w; const arma::mat ones_row = arma::ones(n, 1); - arma::mat psi = arma::log(S % S); // ψ = log(S²), work in logS² space throughout + // Precompute X'WX and P_X once: P_X = (X'WX)^{-1}X'W (d×n) for live B = P_X * M_full + const arma::mat Xw = X.each_col() % w; // n×d + const arma::mat XtWX = X.t() * Xw; // d×d, symmetric PD + // When d=0 (no covariates), X'WX is 0×0: skip solve to avoid spurious singularity warning + const arma::mat P_X = (X.n_cols > 0) ? arma::solve(XtWX, Xw.t()) : arma::mat(0, n); + + arma::mat psi = arma::log(S % S); arma::mat S2 = arma::exp(psi); std::vector objective_vec; @@ -30,46 +41,59 @@ Rcpp::List newton_optimize_impl( int total_iter = 0; int last_status = 5; + // Inner loop: B profiled at each Newton step via envelope theorem. auto inner_loop = [&]() { double obj_prev = arma::datum::inf; - // S2 is current (fixed_point_psi updated it in previous round, or initialized above). - // Z and A are kept current at the end of each iteration; compute them once here. - arma::mat Z = O + X * B + M; - arma::mat A = arma::exp(Z + 0.5 * S2); + // S2 is current (fixed_point_psi updated it in the previous round, or initialized above). + // Sync B, Z, A once per EM round; they are kept current at the end of each Newton step + // so subsequent iterations reuse them directly without recomputation. + B = P_X * M; + arma::mat Z = O + M; + arma::mat A = arma::exp(Z + 0.5 * S2); for (int it = 0; it < maxiter; it++) { - // S2, Z, A are current; newton_step_B will update B, Z, A. - newton_step_B(Xw, Xw2, X, Y, O, w, M, S2, B, Z, A); - - arma::mat grad_M, hess_M; - Traits::grad_hess_M(M, state, A, Y, w, ones_row, grad_M, hess_M); - hess_M.clamp(1e-10, arma::datum::inf); - arma::mat step_M = grad_M / hess_M; - // Precompute MO and dMO once — avoids O(n*p²) multiply at each Armijo backtrack - arma::mat MO = Traits::times_Omega(M, state); - arma::mat dMO = Traits::times_Omega(step_M, state); - double f0_M = arma::accu(w.t() * (A - Y % Z)) + Traits::penalty_M(MO, M, w); - double slope_M = -arma::accu(grad_M % step_M); + // S2, B, Z, A are all current here. + const arma::mat XB = X * B; // frozen during the Armijo line search below + const arma::mat M_res = M - XB; + + // Newton step for M_full using Trait-specific preconditioner. + // DenseOmegaImpl: shared p×p preconditioner (diag(wA_mean)+Omega), one Cholesky per call. + // Diagonal/Spherical: diagonal step (unchanged). + arma::mat grad_M, step_M; + Traits::compute_step_M(M_res, state, A, Y, w, ones_row, grad_M, step_M, + static_cast(block_newton_thresh)); + + // Q_step = (I - X*P_X)*step_M: change in M_res per unit alpha (correct projected step) + // With live B: M_res_t = M_res - alpha*Q_step, slope = -grad_M . Q_step + const arma::mat Q_step = step_M - X * (P_X * step_M); + arma::mat MresO = Traits::times_Omega(M_res, state); + arma::mat QstepO = Traits::times_Omega(Q_step, state); + double f0_M = arma::accu(w.t() * (A - Y % Z)) + Traits::penalty_M(MresO, M_res, w); + double slope_M = -arma::accu(grad_M % Q_step); + // Fall back if step is not a descent direction (degenerate case) + if (slope_M >= 0) slope_M = -arma::accu(grad_M % step_M); double alpha_M = 1.0; for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; - arma::mat MOt = MO - alpha_M * dMO; // linear update, no matrix multiply - arma::mat Zt = Z - alpha_M * step_M; - arma::mat At = arma::exp(Zt + 0.5 * S2); - if (arma::accu(w.t() * (At - Y % Zt)) + Traits::penalty_M(MOt, Mt, w) + arma::mat MresOt = MresO - alpha_M * QstepO; + arma::mat MresT = M_res - alpha_M * Q_step; + arma::mat Zt = Z - alpha_M * step_M; // = O + Mt + arma::mat At = arma::exp(Zt + 0.5 * S2); + if (arma::accu(w.t() * (At - Y % Zt)) + Traits::penalty_M(MresOt, MresT, w) <= f0_M + c1 * alpha_M * slope_M) break; alpha_M *= 0.5; } M -= alpha_M * step_M; - Z = O + X * B + M; + B = P_X * M; + Z = O + M; - // S step: ψ = −log(A + ω²) — exact minimiser for fixed A + // S step: exact fixed-point ψ = −log(A + diag_Ω) fixed_point_psi(psi, S2, Z, A, Traits::cov_diag(state, ones_row)); + // A with new S2 — needed for obj computation and for next iteration A = arma::exp(Z + 0.5 * S2); - // KL entropy: S² − log(S²) − 1 = exp(ψ) − ψ − 1 + const arma::mat M_res_new = M - X * B; double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * psi)) - + Traits::objective_cov(M, S2, state, w); + + Traits::objective_cov(M_res_new, S2, state, w); objective_vec.push_back(obj); total_iter++; @@ -83,9 +107,12 @@ Rcpp::List newton_optimize_impl( inner_loop(); // S2 is current: fixed_point_psi updated it inside inner_loop. - Traits::mstep(state, M, S2, w, w_bar, p); + // B is already at its optimum (live-updated in inner_loop); only Omega needs updating. + // Recompute M_res for the Sigma/Omega M-step. + arma::mat M_res = M - X * B; + Traits::mstep(state, M_res, S2, w, w_bar, p); - arma::mat Z = O + X * B + M; + arma::mat Z = O + M; arma::mat A = arma::exp(Z + 0.5 * S2); double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * psi)) + Traits::elbo_cov(state, w_bar, p); @@ -93,21 +120,37 @@ Rcpp::List newton_optimize_impl( elbo_prev = elbo; } } else { - inner_loop(); + // Fixed covariance: Omega is fixed; B is live-updated in inner_loop. + double elbo_prev_fix = -arma::datum::inf; + for (int em = 0; em < max_em; em++) { + inner_loop(); + // S2 is current: fixed_point_psi updated it inside inner_loop. + // B already optimal after inner_loop; recompute M_res for ELBO check. + arma::mat M_res = M - X * B; + arma::mat Z = O + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * psi)) + - Traits::objective_cov(M_res, S2, state, w); + if (em > 0 && converged(elbo, elbo_prev_fix, em_tol)) { last_status = 3; break; } + elbo_prev_fix = elbo; + } } S2 = arma::exp(psi); S = arma::exp(0.5 * psi); - arma::mat Z = O + X * B + M; + arma::mat M_res = M - X * B; + arma::mat Z = O + M; arma::mat A = arma::exp(Z + 0.5 * S2); - arma::vec loglik = Traits::final_loglik(Y, Z, A, M, psi, state); + + // final_loglik uses M_res for the KL terms (same convention as newton_impl.h) + arma::vec loglik = Traits::final_loglik(Y, Z, A, M_res, psi, state); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; - Rcpp::List cov_out = Traits::output_cov(M, S2, w, w_bar, state); + Rcpp::List cov_out = Traits::output_cov(M_res, S2, w, w_bar, state); return Rcpp::List::create( Rcpp::Named("B", B ), - Rcpp::Named("M", M ), + Rcpp::Named("M", M ), // M_full Rcpp::Named("S", S ), Rcpp::Named("Z", Z ), Rcpp::Named("A", A ), @@ -116,7 +159,7 @@ Rcpp::List newton_optimize_impl( Rcpp::Named("Ji", Ji ), Rcpp::Named("monitoring", Rcpp::List::create( Rcpp::Named("status", last_status ), - Rcpp::Named("backend", "newton" ), + Rcpp::Named("backend", "newton" ), Rcpp::Named("objective", objective_vec ), Rcpp::Named("iterations", total_iter ) )) @@ -131,7 +174,8 @@ Rcpp::List newton_vestep_impl( const arma::mat & Y, const arma::mat & X, const arma::mat & O, const arma::vec & w, arma::mat M, arma::mat S, const arma::mat & B, const typename Traits::State & state, - int maxiter, double ftol + int maxiter, double ftol, + int block_newton_thresh = 30 ) { const int n = Y.n_rows; const double c1 = 1e-4; @@ -153,11 +197,10 @@ Rcpp::List newton_vestep_impl( // S2, Z, A are current. arma::mat M_res = M - XB; // M_res for KL terms (B is fixed) - // ---- Diagonal Newton step for M (gradient == gradient w.r.t. M_res, B fixed) ---- - arma::mat grad_M, hess_M; - Traits::grad_hess_M(M_res, state, A, Y, w, ones_row, grad_M, hess_M); - hess_M.clamp(1e-10, arma::datum::inf); - arma::mat step_M = grad_M / hess_M; + // ---- Newton step for M (gradient and preconditioned step via Trait method) ---- + arma::mat grad_M, step_M; + Traits::compute_step_M(M_res, state, A, Y, w, ones_row, grad_M, step_M, + static_cast(block_newton_thresh)); arma::mat MO = Traits::times_Omega(M_res, state); arma::mat dMO = Traits::times_Omega(step_M, state); double f0_M = arma::accu(w.t() * (A - Y % Z)) + Traits::penalty_M(MO, M_res, w); diff --git a/src/newton_impl_alt.h b/src/newton_impl_alt.h deleted file mode 100644 index 05cb729f..00000000 --- a/src/newton_impl_alt.h +++ /dev/null @@ -1,165 +0,0 @@ -#pragma once -#include -#include "utils.h" -#include "CovarianceTraits.h" - -// M_full parameterization: M is the full variational mean of Z_i (= X_i*B + M_res), -// consistent with the ZIPLN convention. M_res = M - X*B is computed locally for KL. -// -// B is profiled at every Newton step via the envelope theorem: -// B = P_X * M = (X'WX)^{-1} X'W M (closed-form optimum for current M) -// M_res = M - X*B (projection orthogonal to col(X)) -// The gradient of J_profiled w.r.t. M equals the gradient w.r.t. M_res (envelope theorem). -// -// Input/output: M is in M_full format throughout. - -template -Rcpp::List newton_optimize_alt_impl( - const arma::mat & Y, const arma::mat & X, const arma::mat & O, const arma::vec & w, - arma::mat B, arma::mat M, arma::mat S, - typename Traits::State state, - int maxiter, double ftol, int max_em, double em_tol -) { - const int n = Y.n_rows; - const arma::uword p = Y.n_cols; - const double w_bar = arma::accu(w); - const double c1 = 1e-4; - const arma::mat ones_row = arma::ones(n, 1); - - // Precompute X'WX and P_X once: P_X = (X'WX)^{-1}X'W (d×n) for live B = P_X * M_full - const arma::mat Xw = X.each_col() % w; // n×d - const arma::mat XtWX = X.t() * Xw; // d×d, symmetric PD - // When d=0 (no covariates), X'WX is 0×0: skip solve to avoid spurious singularity warning - const arma::mat P_X = (X.n_cols > 0) ? arma::solve(XtWX, Xw.t()) : arma::mat(0, n); - - arma::mat psi = arma::log(S % S); - arma::mat S2 = arma::exp(psi); - - std::vector objective_vec; - double elbo_prev = -arma::datum::inf; - int total_iter = 0; - int last_status = 5; - - // Inner loop: B profiled at each Newton step via envelope theorem. - auto inner_loop = [&]() { - double obj_prev = arma::datum::inf; - // S2 is current (fixed_point_psi updated it in the previous round, or initialized above). - // Sync B, Z, A once per EM round; they are kept current at the end of each Newton step - // so subsequent iterations reuse them directly without recomputation. - B = P_X * M; - arma::mat Z = O + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - - for (int it = 0; it < maxiter; it++) { - // S2, B, Z, A are all current here. - const arma::mat XB = X * B; // frozen during the Armijo line search below - const arma::mat M_res = M - XB; - - // Newton step for M_full: gradient/Hessian are functions of M_res - arma::mat grad_M, hess_M; - Traits::grad_hess_M(M_res, state, A, Y, w, ones_row, grad_M, hess_M); - hess_M.clamp(1e-10, arma::datum::inf); - arma::mat step_M = grad_M / hess_M; - - // Q_step = (I - X*P_X)*step_M: change in M_res per unit alpha (correct projected step) - // With live B: M_res_t = M_res - alpha*Q_step, slope = -grad_M . Q_step - const arma::mat Q_step = step_M - X * (P_X * step_M); - arma::mat MresO = Traits::times_Omega(M_res, state); - arma::mat QstepO = Traits::times_Omega(Q_step, state); - double f0_M = arma::accu(w.t() * (A - Y % Z)) + Traits::penalty_M(MresO, M_res, w); - double slope_M = -arma::accu(grad_M % Q_step); - // Fall back if step is not a descent direction (degenerate case) - if (slope_M >= 0) slope_M = -arma::accu(grad_M % step_M); - double alpha_M = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat MresOt = MresO - alpha_M * QstepO; - arma::mat MresT = M_res - alpha_M * Q_step; - arma::mat Zt = Z - alpha_M * step_M; // = O + Mt - arma::mat At = arma::exp(Zt + 0.5 * S2); - if (arma::accu(w.t() * (At - Y % Zt)) + Traits::penalty_M(MresOt, MresT, w) - <= f0_M + c1 * alpha_M * slope_M) break; - alpha_M *= 0.5; - } - M -= alpha_M * step_M; - B = P_X * M; - Z = O + M; - - // S step: exact fixed-point ψ = −log(A + diag_Ω) - fixed_point_psi(psi, S2, Z, A, Traits::cov_diag(state, ones_row)); - - // A with new S2 — needed for obj computation and for next iteration - A = arma::exp(Z + 0.5 * S2); - const arma::mat M_res_new = M - X * B; - double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * psi)) - + Traits::objective_cov(M_res_new, S2, state, w); - objective_vec.push_back(obj); - total_iter++; - - if (it > 0 && converged(obj, obj_prev, ftol)) { last_status = 3; break; } - obj_prev = obj; - } - }; - - if (Traits::has_em) { - for (int em = 0; em < max_em; em++) { - inner_loop(); - - // S2 is current: fixed_point_psi updated it inside inner_loop. - // B is already at its optimum (live-updated in inner_loop); only Omega needs updating. - // Recompute M_res for the Sigma/Omega M-step. - arma::mat M_res = M - X * B; - Traits::mstep(state, M_res, S2, w, w_bar, p); - - arma::mat Z = O + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * psi)) - + Traits::elbo_cov(state, w_bar, p); - if (em > 0 && converged(elbo, elbo_prev, em_tol)) { last_status = 3; break; } - elbo_prev = elbo; - } - } else { - // Fixed covariance: Omega is fixed; B is live-updated in inner_loop. - double elbo_prev_fix = -arma::datum::inf; - for (int em = 0; em < max_em; em++) { - inner_loop(); - // S2 is current: fixed_point_psi updated it inside inner_loop. - // B already optimal after inner_loop; recompute M_res for ELBO check. - arma::mat M_res = M - X * B; - arma::mat Z = O + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * psi)) - - Traits::objective_cov(M_res, S2, state, w); - if (em > 0 && converged(elbo, elbo_prev_fix, em_tol)) { last_status = 3; break; } - elbo_prev_fix = elbo; - } - } - - S2 = arma::exp(psi); - S = arma::exp(0.5 * psi); - arma::mat M_res = M - X * B; - arma::mat Z = O + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - - // final_loglik uses M_res for the KL terms (same convention as newton_impl.h) - arma::vec loglik = Traits::final_loglik(Y, Z, A, M_res, psi, state); - - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - Rcpp::List cov_out = Traits::output_cov(M_res, S2, w, w_bar, state); - return Rcpp::List::create( - Rcpp::Named("B", B ), - Rcpp::Named("M", M ), // M_full - Rcpp::Named("S", S ), - Rcpp::Named("Z", Z ), - Rcpp::Named("A", A ), - Rcpp::Named("Sigma", cov_out["Sigma"]), - Rcpp::Named("Omega", cov_out["Omega"]), - Rcpp::Named("Ji", Ji ), - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", last_status ), - Rcpp::Named("backend", "newton_alt" ), - Rcpp::Named("objective", objective_vec ), - Rcpp::Named("iterations", total_iter ) - )) - ); -} diff --git a/src/newton_spherical.cpp b/src/newton_spherical.cpp index aad91790..516841ce 100644 --- a/src/newton_spherical.cpp +++ b/src/newton_spherical.cpp @@ -3,8 +3,7 @@ // [[Rcpp::depends(RcppArmadillo)]] #include "utils.h" -#include "newton_impl.h" // newton_vestep_impl -#include "newton_impl_alt.h" // newton_optimize_alt_impl — the homemade E-step +#include "newton_impl.h" // newton_optimize_impl + newton_vestep_impl // --------------------------------------------------------------------------------------- // Spherical covariance PLN — homemade Newton optimizer (profiled B via envelope theorem) @@ -30,7 +29,7 @@ Rcpp::List newton_optimize_spherical( const arma::mat M_res_init = M - X * B; SphericalCovTraits::State state(M_res_init, S2, w, w_bar); - return newton_optimize_alt_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); + return newton_optimize_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol, cfg.block_newton_thresh); } // --------------------------------------------------------------------------------------- @@ -51,9 +50,7 @@ Rcpp::List newton_optimize_vestep_spherical( arma::mat M = Rcpp::as(params["M"]); arma::mat S = Rcpp::as(params["S"]); - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; - + const NewtonConfig cfg(config); SphericalCovTraits::State state(Omega); - return newton_vestep_impl(Y, X, O, w, M, S, B, state, maxiter, ftol); + return newton_vestep_impl(Y, X, O, w, M, S, B, state, cfg.maxiter, cfg.ftol, cfg.block_newton_thresh); } diff --git a/src/utils.h b/src/utils.h index 1f4a9f98..d1be039a 100644 --- a/src/utils.h +++ b/src/utils.h @@ -81,14 +81,16 @@ inline bool converged(double val, double prev, double tol) { // ---- Config extraction for homemade Newton optimizers ---- // Centralises the containsElementNamed pattern replicated across all newton_*.cpp files. struct NewtonConfig { - int maxiter = 200; - double ftol = 1e-8; - int max_em = 50; - double em_tol = 1e-8; + int maxiter = 200; + double ftol = 1e-8; + int max_em = 50; + double em_tol = 1e-8; + int block_newton_thresh = 30; explicit NewtonConfig(const Rcpp::List & cfg) { - if (cfg.containsElementNamed("maxeval")) maxiter = Rcpp::as(cfg["maxeval"]); - if (cfg.containsElementNamed("ftol_in")) ftol = Rcpp::as(cfg["ftol_in"]); - if (cfg.containsElementNamed("maxit_em")) max_em = Rcpp::as(cfg["maxit_em"]); - if (cfg.containsElementNamed("ftol_em")) em_tol = Rcpp::as(cfg["ftol_em"]); + if (cfg.containsElementNamed("maxeval")) maxiter = Rcpp::as(cfg["maxeval"]); + if (cfg.containsElementNamed("ftol_in")) ftol = Rcpp::as(cfg["ftol_in"]); + if (cfg.containsElementNamed("maxit_em")) max_em = Rcpp::as(cfg["maxit_em"]); + if (cfg.containsElementNamed("ftol_em")) em_tol = Rcpp::as(cfg["ftol_em"]); + if (cfg.containsElementNamed("block_newton_thresh")) block_newton_thresh = Rcpp::as(cfg["block_newton_thresh"]); } }; From 6cc41d3b215ef8a54aa371d56d8b96504e088a9c Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Thu, 11 Jun 2026 22:02:19 +0200 Subject: [PATCH 39/58] more robust Newton algorithm --- R/PLN.R | 1 - R/utils.R | 5 +- src/CovarianceTraits.h | 108 ++++++++++++++++---- src/newton_diag_cov.cpp | 4 +- src/newton_fixed_cov.cpp | 2 +- src/newton_full_cov.cpp | 4 +- src/newton_impl.h | 212 ++++++++++++++++----------------------- src/newton_spherical.cpp | 4 +- src/utils.h | 10 +- 9 files changed, 188 insertions(+), 162 deletions(-) diff --git a/R/PLN.R b/R/PLN.R index 36e2582b..7e96822a 100644 --- a/R/PLN.R +++ b/R/PLN.R @@ -97,7 +97,6 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { #' * "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 #' * "maxit_em" stop the EM outer loop when the number of EM iterations exceeds maxit_em. Default is 50 #' * "ftol_em" stop the EM outer loop when the ELBO changes by less than ftol_em (relative). Default is 1e-8 -#' * "block_newton_thresh" for full/fixed covariance: use exact per-observation block Newton (p×p solve) when p ≤ this threshold, diagonal approximation otherwise. Default is 30. Set to 0 to always use the diagonal approximation. #' #' 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. diff --git a/R/utils.R b/R/utils.R index 18b52e95..487b5252 100644 --- a/R/utils.R +++ b/R/utils.R @@ -20,9 +20,8 @@ config_default_homemade <- backend = "homemade", maxeval = 10000, ftol_in = 1e-8, - maxit_em = 50, - ftol_em = 1e-8, - block_newton_thresh = 30L + maxit_em = 200, + ftol_em = 1e-8 ) # Hybrid backend: two-phase optimizer — nlopt/CCSAQ (phase 1) then homemade Newton (phase 2). diff --git a/src/CovarianceTraits.h b/src/CovarianceTraits.h index b90f87d2..c25e9dab 100644 --- a/src/CovarianceTraits.h +++ b/src/CovarianceTraits.h @@ -29,36 +29,51 @@ struct DenseOmegaImpl { static arma::mat times_Omega(const arma::mat & M, const State & s) { return M * s.Omega; } - // Newton step for M. - // p ≤ block_thresh: exact per-observation block Newton — n p×p Cholesky solves, O(np³). - // Captures full Omega correlation; converges in far fewer inner iterations. - // p > block_thresh: diagonal approximation — O(np), same as the original grad_hess_M + divide. static void compute_step_M( const arma::mat & M, const State & s, const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & ones_row, - arma::mat & grad_M, arma::mat & step_M, - arma::uword block_thresh = 30) + arma::mat & grad_M, arma::mat & step_M) { - const arma::uword n = M.n_rows, p = M.n_cols; const arma::mat MO = M * s.Omega; grad_M = MO + A - Y; grad_M.each_col() %= w; - step_M.set_size(n, p); - if (p <= block_thresh) { - for (arma::uword i = 0; i < n; i++) { - const arma::mat H_i = w(i) * (arma::diagmat(A.row(i).t()) + s.Omega); - step_M.row(i) = arma::solve(arma::symmatu(H_i), grad_M.row(i).t()).t(); - } - } else { - arma::mat hess = A + ones_row * s.diag_Omega.t(); hess.each_col() %= w; - hess.clamp(1e-10, arma::datum::inf); - step_M = grad_M / hess; - } + arma::mat hess = A + ones_row * s.diag_Omega.t(); hess.each_col() %= w; + hess.clamp(1e-10, arma::datum::inf); + step_M = grad_M / hess; } static double penalty_M(const arma::mat & MO, const arma::mat & M, const arma::vec & w) { return 0.5 * arma::as_scalar(w.t() * arma::sum(MO % M, 1)); } + static double penalty_S(const arma::mat & S2, const State & s, const arma::vec & w) { + return 0.5 * arma::dot(s.diag_Omega, (w.t() * S2).t()); + } + + // Joint Newton step for (M, ψ) where ψ = log(S²): diagonal 2×2 per (i,j). + static void compute_joint_step_MS( + const arma::mat & M, const State & s, + const arma::mat & A, const arma::mat & S2, + const arma::mat & Y, const arma::vec & w, const arma::mat & ones_row, + arma::mat & grad_M, arma::mat & step_M, + arma::mat & grad_psi, arma::mat & step_psi) + { + const arma::mat MO = M * s.Omega; + const arma::mat omega_d = ones_row * s.diag_Omega.t(); + const arma::mat AS2 = A % S2; + + grad_M = MO + A - Y; grad_M.each_col() %= w; + grad_psi = 0.5 * (AS2 + omega_d % S2 - 1.0); grad_psi.each_col() %= w; + + arma::mat h_pp = 0.5 * (S2 % (A % (1.0 + 0.5*S2) + omega_d)); h_pp.each_col() %= w; + arma::mat h_mp = 0.5 * AS2; h_mp.each_col() %= w; + arma::mat h_mm = A + omega_d; h_mm.each_col() %= w; + + arma::mat det = h_mm % h_pp - h_mp % h_mp; + det.clamp(1e-20, arma::datum::inf); + step_M = (h_pp % grad_M - h_mp % grad_psi) / det; + step_psi = (h_mm % grad_psi - h_mp % grad_M ) / det; + } + static double objective_cov(const arma::mat & M, const arma::mat & S2, const State & s, const arma::vec & w) { arma::mat MO = M * s.Omega; return 0.5 * (arma::as_scalar(w.t() * arma::sum(MO % M, 1)) @@ -151,8 +166,7 @@ struct DiagonalCovTraits { static void compute_step_M( const arma::mat & M, const State & s, const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & ones_row, - arma::mat & grad_M, arma::mat & step_M, - arma::uword /*block_thresh*/ = 0) + arma::mat & grad_M, arma::mat & step_M) { grad_M = M.each_row() % s.omega2 + A - Y; grad_M.each_col() %= w; arma::mat hess = ones_row * s.omega2 + A; hess.each_col() %= w; @@ -164,6 +178,32 @@ struct DiagonalCovTraits { return 0.5 * arma::as_scalar(w.t() * arma::sum(MO % M, 1)); } + static double penalty_S(const arma::mat & S2, const State & s, const arma::vec & w) { + return 0.5 * arma::as_scalar((w.t() * S2) * s.omega2.t()); + } + + static void compute_joint_step_MS( + const arma::mat & M, const State & s, + const arma::mat & A, const arma::mat & S2, + const arma::mat & Y, const arma::vec & w, const arma::mat & ones_row, + arma::mat & grad_M, arma::mat & step_M, + arma::mat & grad_psi, arma::mat & step_psi) + { + const arma::mat omega_d = ones_row * s.omega2; + const arma::mat AS2 = A % S2; + grad_M = M.each_row() % s.omega2 + A - Y; grad_M.each_col() %= w; + grad_psi = 0.5 * (AS2 + omega_d % S2 - 1.0); grad_psi.each_col() %= w; + + arma::mat h_pp = 0.5 * (S2 % (A % (1.0 + 0.5*S2) + omega_d)); h_pp.each_col() %= w; + arma::mat h_mp = 0.5 * AS2; h_mp.each_col() %= w; + arma::mat h_mm = A + omega_d; h_mm.each_col() %= w; + + arma::mat det = h_mm % h_pp - h_mp % h_mp; + det.clamp(1e-20, arma::datum::inf); + step_M = (h_pp % grad_M - h_mp % grad_psi) / det; + step_psi = (h_mm % grad_psi - h_mp % grad_M ) / det; + } + static double objective_cov(const arma::mat & M, const arma::mat & S2, const State & s, const arma::vec & w) { return 0.5 * arma::as_scalar((w.t() * (M % M + S2)) * s.omega2.t()); } @@ -233,11 +273,35 @@ struct SphericalCovTraits { static arma::mat times_Omega(const arma::mat & M, const State & s) { return s.omega2 * M; } + static double penalty_S(const arma::mat & S2, const State & s, const arma::vec & w) { + return 0.5 * s.omega2 * arma::dot(w, arma::sum(S2, 1)); + } + + static void compute_joint_step_MS( + const arma::mat & M, const State & s, + const arma::mat & A, const arma::mat & S2, + const arma::mat & Y, const arma::vec & w, const arma::mat & /*ones_row*/, + arma::mat & grad_M, arma::mat & step_M, + arma::mat & grad_psi, arma::mat & step_psi) + { + const arma::mat AS2 = A % S2; + grad_M = s.omega2 * M + A - Y; grad_M.each_col() %= w; + grad_psi = 0.5 * (AS2 + s.omega2 * S2 - 1.0); grad_psi.each_col() %= w; + + arma::mat h_pp = 0.5 * (S2 % (A % (1.0 + 0.5*S2) + s.omega2)); h_pp.each_col() %= w; + arma::mat h_mp = 0.5 * AS2; h_mp.each_col() %= w; + arma::mat h_mm = A + s.omega2; h_mm.each_col() %= w; + + arma::mat det = h_mm % h_pp - h_mp % h_mp; + det.clamp(1e-20, arma::datum::inf); + step_M = (h_pp % grad_M - h_mp % grad_psi) / det; + step_psi = (h_mm % grad_psi - h_mp % grad_M ) / det; + } + static void compute_step_M( const arma::mat & M, const State & s, const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & /*ones_row*/, - arma::mat & grad_M, arma::mat & step_M, - arma::uword /*block_thresh*/ = 0) + arma::mat & grad_M, arma::mat & step_M) { grad_M = s.omega2 * M + A - Y; grad_M.each_col() %= w; arma::mat hess = s.omega2 + A; hess.each_col() %= w; diff --git a/src/newton_diag_cov.cpp b/src/newton_diag_cov.cpp index 21ba076e..67614b65 100644 --- a/src/newton_diag_cov.cpp +++ b/src/newton_diag_cov.cpp @@ -29,7 +29,7 @@ Rcpp::List newton_optimize_diagonal( const arma::mat M_res_init = M - X * B; DiagonalCovTraits::State state(M_res_init, S2, w, w_bar); - return newton_optimize_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol, cfg.block_newton_thresh); + return newton_optimize_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); } // --------------------------------------------------------------------------------------- @@ -52,5 +52,5 @@ Rcpp::List newton_optimize_vestep_diagonal( const NewtonConfig cfg(config); DiagonalCovTraits::State state(Omega); - return newton_vestep_impl(Y, X, O, w, M, S, B, state, cfg.maxiter, cfg.ftol, cfg.block_newton_thresh); + return newton_vestep_impl(Y, X, O, w, M, S, B, state, cfg.maxiter, cfg.ftol); } diff --git a/src/newton_fixed_cov.cpp b/src/newton_fixed_cov.cpp index da670003..806ed0a2 100644 --- a/src/newton_fixed_cov.cpp +++ b/src/newton_fixed_cov.cpp @@ -26,5 +26,5 @@ Rcpp::List newton_optimize_fixed( const NewtonConfig cfg(config); FixedCovTraits::State state(Omega); - return newton_optimize_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol, cfg.block_newton_thresh); + return newton_optimize_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); } diff --git a/src/newton_full_cov.cpp b/src/newton_full_cov.cpp index a94e1706..dc1cf35a 100644 --- a/src/newton_full_cov.cpp +++ b/src/newton_full_cov.cpp @@ -29,7 +29,7 @@ Rcpp::List newton_optimize_full( const arma::mat M_res_init = M - X * B; FullCovTraits::State state(M_res_init, S2, w, w_bar); - return newton_optimize_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol, cfg.block_newton_thresh); + return newton_optimize_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); } // --------------------------------------------------------------------------------------- @@ -52,5 +52,5 @@ Rcpp::List newton_optimize_vestep_full( const NewtonConfig cfg(config); FullCovTraits::State state(Omega); - return newton_vestep_impl(Y, X, O, w, M, S, B, state, cfg.maxiter, cfg.ftol, cfg.block_newton_thresh); + return newton_vestep_impl(Y, X, O, w, M, S, B, state, cfg.maxiter, cfg.ftol); } diff --git a/src/newton_impl.h b/src/newton_impl.h index fc0dce95..095a2b0b 100644 --- a/src/newton_impl.h +++ b/src/newton_impl.h @@ -13,13 +13,15 @@ // // Input/output: M is in M_full format throughout. +// Mirror of nlopt_full_cov structure: outer EM loop (max_em) over an inner VE-step that +// optimizes (M, ψ) jointly for fixed Omega until convergence (ftol), then one Omega M-step. +// Joint Newton step per inner iteration: diagonal 2×2 per (i,j) with cross-term H_Mψ. template Rcpp::List newton_optimize_impl( const arma::mat & Y, const arma::mat & X, const arma::mat & O, const arma::vec & w, arma::mat B, arma::mat M, arma::mat S, typename Traits::State state, - int maxiter, double ftol, int max_em, double em_tol, - int block_newton_thresh = 30 + int maxiter, double ftol, int max_em, double em_tol ) { const int n = Y.n_rows; const arma::uword p = Y.n_cols; @@ -27,10 +29,8 @@ Rcpp::List newton_optimize_impl( const double c1 = 1e-4; const arma::mat ones_row = arma::ones(n, 1); - // Precompute X'WX and P_X once: P_X = (X'WX)^{-1}X'W (d×n) for live B = P_X * M_full - const arma::mat Xw = X.each_col() % w; // n×d - const arma::mat XtWX = X.t() * Xw; // d×d, symmetric PD - // When d=0 (no covariates), X'WX is 0×0: skip solve to avoid spurious singularity warning + const arma::mat Xw = X.each_col() % w; + const arma::mat XtWX = X.t() * Xw; const arma::mat P_X = (X.n_cols > 0) ? arma::solve(XtWX, Xw.t()) : arma::mat(0, n); arma::mat psi = arma::log(S % S); @@ -38,119 +38,83 @@ Rcpp::List newton_optimize_impl( std::vector objective_vec; double elbo_prev = -arma::datum::inf; - int total_iter = 0; int last_status = 5; - // Inner loop: B profiled at each Newton step via envelope theorem. - auto inner_loop = [&]() { - double obj_prev = arma::datum::inf; - // S2 is current (fixed_point_psi updated it in the previous round, or initialized above). - // Sync B, Z, A once per EM round; they are kept current at the end of each Newton step - // so subsequent iterations reuse them directly without recomputation. - B = P_X * M; - arma::mat Z = O + M; - arma::mat A = arma::exp(Z + 0.5 * S2); + B = P_X * M; + arma::mat Z = O + M; + arma::mat A = arma::exp(Z + 0.5 * S2); + for (int em_iter = 0; em_iter < std::max(1, max_em); em_iter++) { + // ── Inner VE-step: optimize (M, ψ) to convergence for the current Omega/state ── + double inner_prev = arma::datum::inf; for (int it = 0; it < maxiter; it++) { - // S2, B, Z, A are all current here. - const arma::mat XB = X * B; // frozen during the Armijo line search below + const arma::mat XB = X * B; const arma::mat M_res = M - XB; - // Newton step for M_full using Trait-specific preconditioner. - // DenseOmegaImpl: shared p×p preconditioner (diag(wA_mean)+Omega), one Cholesky per call. - // Diagonal/Spherical: diagonal step (unchanged). - arma::mat grad_M, step_M; - Traits::compute_step_M(M_res, state, A, Y, w, ones_row, grad_M, step_M, - static_cast(block_newton_thresh)); - - // Q_step = (I - X*P_X)*step_M: change in M_res per unit alpha (correct projected step) - // With live B: M_res_t = M_res - alpha*Q_step, slope = -grad_M . Q_step + // Joint Newton step for (M, ψ): gradient + 2×2 Newton per (i,j) + arma::mat grad_M, step_M, grad_psi, step_psi; + Traits::compute_joint_step_MS(M_res, state, A, S2, Y, w, ones_row, + grad_M, step_M, grad_psi, step_psi); const arma::mat Q_step = step_M - X * (P_X * step_M); - arma::mat MresO = Traits::times_Omega(M_res, state); - arma::mat QstepO = Traits::times_Omega(Q_step, state); - double f0_M = arma::accu(w.t() * (A - Y % Z)) + Traits::penalty_M(MresO, M_res, w); - double slope_M = -arma::accu(grad_M % Q_step); - // Fall back if step is not a descent direction (degenerate case) - if (slope_M >= 0) slope_M = -arma::accu(grad_M % step_M); - double alpha_M = 1.0; + const arma::mat MresO = Traits::times_Omega(M_res, state); + const arma::mat QstepO = Traits::times_Omega(Q_step, state); + double f0 = arma::accu(w.t() * (A - Y % Z - 0.5 * psi)) + + Traits::penalty_M(MresO, M_res, w) + Traits::penalty_S(S2, state, w); + double slope = -arma::accu(grad_M % Q_step) - arma::accu(grad_psi % step_psi); + if (slope >= 0) slope = -arma::accu(grad_M % step_M) - arma::accu(grad_psi % step_psi); + double alpha = 1.0; for (int ls = 0; ls < 20; ls++) { - arma::mat MresOt = MresO - alpha_M * QstepO; - arma::mat MresT = M_res - alpha_M * Q_step; - arma::mat Zt = Z - alpha_M * step_M; // = O + Mt - arma::mat At = arma::exp(Zt + 0.5 * S2); - if (arma::accu(w.t() * (At - Y % Zt)) + Traits::penalty_M(MresOt, MresT, w) - <= f0_M + c1 * alpha_M * slope_M) break; - alpha_M *= 0.5; + const arma::mat MresT = M_res - alpha * Q_step; + const arma::mat MresOt = MresO - alpha * QstepO; + const arma::mat psit = psi - alpha * step_psi; + const arma::mat S2t = arma::exp(psit); + const arma::mat Zt = Z - alpha * step_M; + const arma::mat At = arma::exp(Zt + 0.5 * S2t); + if (arma::accu(w.t() * (At - Y % Zt - 0.5 * psit)) + + Traits::penalty_M(MresOt, MresT, w) + Traits::penalty_S(S2t, state, w) + <= f0 + c1 * alpha * slope) break; + alpha *= 0.5; } - M -= alpha_M * step_M; - B = P_X * M; - Z = O + M; - - // S step: exact fixed-point ψ = −log(A + diag_Ω) - fixed_point_psi(psi, S2, Z, A, Traits::cov_diag(state, ones_row)); - - // A with new S2 — needed for obj computation and for next iteration - A = arma::exp(Z + 0.5 * S2); - const arma::mat M_res_new = M - X * B; - double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * psi)) - + Traits::objective_cov(M_res_new, S2, state, w); - objective_vec.push_back(obj); - total_iter++; - - if (it > 0 && converged(obj, obj_prev, ftol)) { last_status = 3; break; } - obj_prev = obj; + M -= alpha * step_M; + psi -= alpha * step_psi; + S2 = arma::exp(psi); + B = P_X * M; + Z = O + M; + A = arma::exp(Z + 0.5 * S2); + + objective_vec.push_back(f0); + if (it > 0 && converged(f0, inner_prev, ftol)) break; + inner_prev = f0; } - }; - - if (Traits::has_em) { - for (int em = 0; em < max_em; em++) { - inner_loop(); - - // S2 is current: fixed_point_psi updated it inside inner_loop. - // B is already at its optimum (live-updated in inner_loop); only Omega needs updating. - // Recompute M_res for the Sigma/Omega M-step. - arma::mat M_res = M - X * B; - Traits::mstep(state, M_res, S2, w, w_bar, p); - - arma::mat Z = O + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * psi)) - + Traits::elbo_cov(state, w_bar, p); - if (em > 0 && converged(elbo, elbo_prev, em_tol)) { last_status = 3; break; } - elbo_prev = elbo; - } - } else { - // Fixed covariance: Omega is fixed; B is live-updated in inner_loop. - double elbo_prev_fix = -arma::datum::inf; - for (int em = 0; em < max_em; em++) { - inner_loop(); - // S2 is current: fixed_point_psi updated it inside inner_loop. - // B already optimal after inner_loop; recompute M_res for ELBO check. - arma::mat M_res = M - X * B; - arma::mat Z = O + M; - arma::mat A = arma::exp(Z + 0.5 * S2); - double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * psi)) - - Traits::objective_cov(M_res, S2, state, w); - if (em > 0 && converged(elbo, elbo_prev_fix, em_tol)) { last_status = 3; break; } - elbo_prev_fix = elbo; + + // ── VM-step: update Omega/Sigma (skipped for fixed covariance) ── + const arma::mat M_res_cur = M - X * B; + if (Traits::has_em) { + Traits::mstep(state, M_res_cur, S2, w, w_bar, p); + } else { + last_status = 3; break; // fixed covariance: inner loop already converged } + + // ── Outer ELBO for convergence ── + double elbo = arma::accu(w.t() * (Y % Z - A + 0.5 * psi)) + + Traits::elbo_cov(state, w_bar, p); + if (em_iter > 0 && converged(elbo, elbo_prev, em_tol)) { last_status = 3; break; } + elbo_prev = elbo; } S2 = arma::exp(psi); S = arma::exp(0.5 * psi); arma::mat M_res = M - X * B; - arma::mat Z = O + M; - arma::mat A = arma::exp(Z + 0.5 * S2); + Z = O + M; + A = arma::exp(Z + 0.5 * S2); - // final_loglik uses M_res for the KL terms (same convention as newton_impl.h) arma::vec loglik = Traits::final_loglik(Y, Z, A, M_res, psi, state); - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; Rcpp::List cov_out = Traits::output_cov(M_res, S2, w, w_bar, state); return Rcpp::List::create( Rcpp::Named("B", B ), - Rcpp::Named("M", M ), // M_full + Rcpp::Named("M", M ), Rcpp::Named("S", S ), Rcpp::Named("Z", Z ), Rcpp::Named("A", A ), @@ -158,10 +122,10 @@ Rcpp::List newton_optimize_impl( Rcpp::Named("Omega", cov_out["Omega"]), Rcpp::Named("Ji", Ji ), Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", last_status ), - Rcpp::Named("backend", "newton" ), - Rcpp::Named("objective", objective_vec ), - Rcpp::Named("iterations", total_iter ) + Rcpp::Named("status", last_status ), + Rcpp::Named("backend", "newton" ), + Rcpp::Named("objective", objective_vec ), + Rcpp::Named("iterations", (int)objective_vec.size() ) )) ); } @@ -174,8 +138,7 @@ Rcpp::List newton_vestep_impl( const arma::mat & Y, const arma::mat & X, const arma::mat & O, const arma::vec & w, arma::mat M, arma::mat S, const arma::mat & B, const typename Traits::State & state, - int maxiter, double ftol, - int block_newton_thresh = 30 + int maxiter, double ftol ) { const int n = Y.n_rows; const double c1 = 1e-4; @@ -197,29 +160,32 @@ Rcpp::List newton_vestep_impl( // S2, Z, A are current. arma::mat M_res = M - XB; // M_res for KL terms (B is fixed) - // ---- Newton step for M (gradient and preconditioned step via Trait method) ---- - arma::mat grad_M, step_M; - Traits::compute_step_M(M_res, state, A, Y, w, ones_row, grad_M, step_M, - static_cast(block_newton_thresh)); - arma::mat MO = Traits::times_Omega(M_res, state); - arma::mat dMO = Traits::times_Omega(step_M, state); - double f0_M = arma::accu(w.t() * (A - Y % Z)) + Traits::penalty_M(MO, M_res, w); - double slope_M = -arma::accu(grad_M % step_M); - double alpha_M = 1.0; + // ---- Joint Newton step for (M, ψ) ---- + arma::mat grad_M, step_M, grad_psi, step_psi; + Traits::compute_joint_step_MS(M_res, state, A, S2, Y, w, ones_row, + grad_M, step_M, grad_psi, step_psi); + const arma::mat MO = Traits::times_Omega(M_res, state); + const arma::mat dMO = Traits::times_Omega(step_M, state); + double f0 = arma::accu(w.t() * (A - Y % Z - 0.5 * psi)) + + Traits::penalty_M(MO, M_res, w) + Traits::penalty_S(S2, state, w); + double slope = -arma::accu(grad_M % step_M) - arma::accu(grad_psi % step_psi); + double alpha = 1.0; for (int ls = 0; ls < 20; ls++) { - arma::mat MresT = M_res - alpha_M * step_M; - arma::mat MOt = MO - alpha_M * dMO; - arma::mat Zt = Z - alpha_M * step_M; - arma::mat At = arma::exp(Zt + 0.5 * S2); - if (arma::accu(w.t() * (At - Y % Zt)) + Traits::penalty_M(MOt, MresT, w) - <= f0_M + c1 * alpha_M * slope_M) break; - alpha_M *= 0.5; + const arma::mat MresT = M_res - alpha * step_M; + const arma::mat MOt = MO - alpha * dMO; + const arma::mat psit = psi - alpha * step_psi; + const arma::mat S2t = arma::exp(psit); + const arma::mat Zt = Z - alpha * step_M; + const arma::mat At = arma::exp(Zt + 0.5 * S2t); + if (arma::accu(w.t() * (At - Y % Zt - 0.5 * psit)) + + Traits::penalty_M(MOt, MresT, w) + Traits::penalty_S(S2t, state, w) + <= f0 + c1 * alpha * slope) break; + alpha *= 0.5; } - M -= alpha_M * step_M; - Z = O + M; - - // ---- S step: ψ = −log(A + ω²) — exact minimiser for fixed A ---- - fixed_point_psi(psi, S2, Z, A, Traits::cov_diag(state, ones_row)); + M -= alpha * step_M; + psi -= alpha * step_psi; + S2 = arma::exp(psi); + Z = O + M; // ---- Objective for convergence ---- A = arma::exp(Z + 0.5 * S2); diff --git a/src/newton_spherical.cpp b/src/newton_spherical.cpp index 516841ce..c73902b9 100644 --- a/src/newton_spherical.cpp +++ b/src/newton_spherical.cpp @@ -29,7 +29,7 @@ Rcpp::List newton_optimize_spherical( const arma::mat M_res_init = M - X * B; SphericalCovTraits::State state(M_res_init, S2, w, w_bar); - return newton_optimize_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol, cfg.block_newton_thresh); + return newton_optimize_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); } // --------------------------------------------------------------------------------------- @@ -52,5 +52,5 @@ Rcpp::List newton_optimize_vestep_spherical( const NewtonConfig cfg(config); SphericalCovTraits::State state(Omega); - return newton_vestep_impl(Y, X, O, w, M, S, B, state, cfg.maxiter, cfg.ftol, cfg.block_newton_thresh); + return newton_vestep_impl(Y, X, O, w, M, S, B, state, cfg.maxiter, cfg.ftol); } diff --git a/src/utils.h b/src/utils.h index d1be039a..415cde20 100644 --- a/src/utils.h +++ b/src/utils.h @@ -85,12 +85,10 @@ struct NewtonConfig { double ftol = 1e-8; int max_em = 50; double em_tol = 1e-8; - int block_newton_thresh = 30; explicit NewtonConfig(const Rcpp::List & cfg) { - if (cfg.containsElementNamed("maxeval")) maxiter = Rcpp::as(cfg["maxeval"]); - if (cfg.containsElementNamed("ftol_in")) ftol = Rcpp::as(cfg["ftol_in"]); - if (cfg.containsElementNamed("maxit_em")) max_em = Rcpp::as(cfg["maxit_em"]); - if (cfg.containsElementNamed("ftol_em")) em_tol = Rcpp::as(cfg["ftol_em"]); - if (cfg.containsElementNamed("block_newton_thresh")) block_newton_thresh = Rcpp::as(cfg["block_newton_thresh"]); + if (cfg.containsElementNamed("maxeval")) maxiter = Rcpp::as(cfg["maxeval"]); + if (cfg.containsElementNamed("ftol_in")) ftol = Rcpp::as(cfg["ftol_in"]); + if (cfg.containsElementNamed("maxit_em")) max_em = Rcpp::as(cfg["maxit_em"]); + if (cfg.containsElementNamed("ftol_em")) em_tol = Rcpp::as(cfg["ftol_em"]); } }; From 4a3336c4919788959fa819c6d21973d2a7294a7d Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Thu, 11 Jun 2026 22:02:32 +0200 Subject: [PATCH 40/58] script for backend and convergence analysis --- inst/backend_comparison.R | 183 +++++++++++++++++++++++++++++ inst/convergence_analysis.R | 227 ++++++++++++++++++++++++++++++++++++ 2 files changed, 410 insertions(+) create mode 100644 inst/backend_comparison.R create mode 100644 inst/convergence_analysis.R diff --git a/inst/backend_comparison.R b/inst/backend_comparison.R new file mode 100644 index 00000000..1a964f0b --- /dev/null +++ b/inst/backend_comparison.R @@ -0,0 +1,183 @@ +## ============================================================ +## Backend comparison: homemade Newton vs nlopt/CCSAQ +## Metrics: computation time, iterations, final loglik +## Datasets: trichoptera, barents, mollusk, oaks, microcosm, scRNA +## Covariances: full, diagonal, spherical +## Note: full covariance skipped for scRNA (p=500, prohibitive) +## ============================================================ + +suppressPackageStartupMessages({ + devtools::load_all(".", quiet = TRUE) + library(ggplot2) + library(dplyr) + library(tidyr) +}) + +ctrl_newton <- function(cov) PLN_param(backend = "homemade", covariance = cov, trace = 0) +ctrl_nlopt <- function(cov) PLN_param(backend = "nlopt", covariance = cov, trace = 0) + +## ---- Helper: fit one model with timing, return summary row ---- +fit_timed <- function(formula, data, cov, backend_ctrl, backend_name, label) { + t0 <- proc.time() + m <- tryCatch( + PLN(formula, data = data, control = backend_ctrl(cov)), + error = function(e) NULL + ) + elapsed <- (proc.time() - t0)[["elapsed"]] + if (is.null(m)) { + return(data.frame( + label = label, backend = backend_name, covariance = cov, + time_s = elapsed, n_iter = NA_integer_, loglik = NA_real_, + converged = FALSE, stringsAsFactors = FALSE + )) + } + data.frame( + label = label, + backend = backend_name, + covariance = cov, + time_s = elapsed, + n_iter = m$optim_par$iterations, + loglik = m$loglik, + converged = (m$optim_par$status == 3), + stringsAsFactors = FALSE + ) +} + +## ---- Helper: run both backends for a given (formula, data, cov) ---- +compare_both <- function(formula, data, cov, label) { + cat(sprintf(" %s [%s]...\n", label, cov)) + rbind( + fit_timed(formula, data, cov, ctrl_newton, "newton", label), + fit_timed(formula, data, cov, ctrl_nlopt, "nlopt", label) + ) +} + +## ---- Data preparation ---- +tri <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +mol <- prepare_data(mollusk$Abundance, mollusk$Covariate) + +## ---- Run all comparisons ---- +results <- list() + +cat("=== trichoptera (n=49, p=17) ===\n") +for (cov in c("full", "diagonal", "spherical")) { + results[[length(results)+1]] <- compare_both(Abundance ~ 1, tri, cov, "tri_nocov") + results[[length(results)+1]] <- compare_both(Abundance ~ Wind + Temperature, tri, cov, "tri_cov") +} + +cat("=== barents (n=89, p=30) ===\n") +for (cov in c("full", "diagonal", "spherical")) { + results[[length(results)+1]] <- compare_both(Abundance ~ 1, barents, cov, "bar_nocov") + results[[length(results)+1]] <- compare_both(Abundance ~ Depth + Temperature, barents, cov, "bar_cov") +} + +cat("=== mollusk (n=163, p=32) ===\n") +for (cov in c("full", "diagonal", "spherical")) { + results[[length(results)+1]] <- compare_both(Abundance ~ 1, mol, cov, "mol_nocov") + results[[length(results)+1]] <- compare_both(Abundance ~ site + season, mol, cov, "mol_cov") +} + +cat("=== oaks (n=116, p=114) ===\n") +for (cov in c("full", "diagonal", "spherical")) { + results[[length(results)+1]] <- compare_both(Abundance ~ 1 + offset(log(Offset)), oaks, cov, "oak_nocov") + results[[length(results)+1]] <- compare_both(Abundance ~ tree + offset(log(Offset)), oaks, cov, "oak_cov") +} + +cat("=== microcosm (n=880, p=259) ===\n") +for (cov in c("diagonal", "spherical")) { + results[[length(results)+1]] <- compare_both(Abundance ~ 1 + offset(log(Offset)), microcosm, cov, "mic_nocov") + results[[length(results)+1]] <- compare_both(Abundance ~ site + offset(log(Offset)), microcosm, cov, "mic_cov") +} +cat(" microcosm full (slow)...\n") +for (lbl in c("mic_nocov", "mic_cov")) { + form <- if (lbl == "mic_nocov") Abundance ~ 1 + offset(log(Offset)) else Abundance ~ site + offset(log(Offset)) + results[[length(results)+1]] <- compare_both(form, microcosm, "full", lbl) +} + +cat("=== scRNA (n=3918, p=500) — full skipped ===\n") +for (cov in c("diagonal", "spherical")) { + results[[length(results)+1]] <- compare_both(counts ~ 1 + offset(log(total_counts)), scRNA, cov, "scr_nocov") + results[[length(results)+1]] <- compare_both(counts ~ cell_line + offset(log(total_counts)), scRNA, cov, "scr_cov") +} + +cat("All fits done.\n\n") + +## ---- Combine results ---- +df <- do.call(rbind, results) +df$dataset <- sub("_.*", "", df$label) +df$covariates <- sub(".*_", "", df$label) + +## ---- Summary table (wide format) ---- +cat("========== COMPARISON SUMMARY ==========\n") +wide <- df %>% + select(label, covariance, backend, time_s, n_iter, loglik, converged) %>% + tidyr::pivot_wider( + names_from = backend, + values_from = c(time_s, n_iter, loglik, converged) + ) %>% + mutate( + loglik_diff = loglik_newton - loglik_nlopt, + speedup = time_s_nlopt / time_s_newton + ) %>% + arrange(label, covariance) + +print(wide %>% select(label, covariance, + time_newton = time_s_newton, time_nlopt = time_s_nlopt, speedup, + iter_newton = n_iter_newton, iter_nlopt = n_iter_nlopt, + ll_newton = loglik_newton, ll_nlopt = loglik_nlopt, + ll_diff = loglik_diff, + conv_newton = converged_newton, conv_nlopt = converged_nlopt + ) %>% + mutate(across(where(is.numeric), ~ signif(., 4))), + row.names = FALSE, width = 200) + +## ---- Plot 1: time comparison ---- +p1 <- ggplot(df, aes(x = paste(label, covariance, sep="\n"), y = time_s, fill = backend)) + + geom_col(position = "dodge", width = 0.7) + + facet_wrap(~ dataset, scales = "free", nrow = 2) + + scale_fill_manual(values = c(newton = "#E69F00", nlopt = "#56B4E9")) + + labs(title = "Computation time: Newton vs nlopt", + x = NULL, y = "Elapsed time (s)", fill = "Backend") + + theme_bw(base_size = 10) + + theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 7)) + +ggsave("backend_time.pdf", p1, width = 18, height = 10) +cat("\nSaved: backend_time.pdf\n") + +## ---- Plot 2: loglik difference (newton - nlopt) ---- +df_wide <- df %>% + pivot_wider(names_from = backend, values_from = c(time_s, n_iter, loglik, converged)) %>% + mutate(ll_diff = loglik_newton - loglik_nlopt, + fit = paste(label, covariance, sep=" / ")) + +p2 <- ggplot(df_wide, aes(x = fit, y = ll_diff, + fill = ifelse(ll_diff > 0, "Newton better", "nlopt better"))) + + geom_col(width = 0.7) + + facet_wrap(~ dataset, scales = "free", nrow = 2) + + geom_hline(yintercept = 0, linetype = "dashed") + + scale_fill_manual(values = c("Newton better" = "#009E73", "nlopt better" = "#D55E00"), + name = NULL) + + labs(title = "loglik difference: Newton minus nlopt", + subtitle = "Positive = Newton finds better solution", + x = NULL, y = "loglik(Newton) - loglik(nlopt)") + + theme_bw(base_size = 10) + + theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 7)) + +ggsave("backend_loglik.pdf", p2, width = 18, height = 10) +cat("Saved: backend_loglik.pdf\n") + +## ---- Plot 3: speedup (nlopt_time / newton_time) ---- +p3 <- ggplot(df_wide, aes(x = fit, y = time_s_nlopt / time_s_newton, + fill = dataset)) + + geom_col(width = 0.7) + + facet_wrap(~ dataset, scales = "free", nrow = 2) + + geom_hline(yintercept = 1, linetype = "dashed", colour = "grey40") + + labs(title = "Speedup: nlopt_time / newton_time", + subtitle = "> 1 means Newton is faster", + x = NULL, y = "Speedup ratio") + + theme_bw(base_size = 10) + + theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 7), + legend.position = "none") + +ggsave("backend_speedup.pdf", p3, width = 18, height = 10) +cat("Saved: backend_speedup.pdf\n") diff --git a/inst/convergence_analysis.R b/inst/convergence_analysis.R new file mode 100644 index 00000000..11e44c12 --- /dev/null +++ b/inst/convergence_analysis.R @@ -0,0 +1,227 @@ +## ============================================================ +## Convergence analysis of the homemade Newton backend +## Datasets: trichoptera (n=49, p=17), barents (n=89, p=30), +## mollusk (n=163, p=32), oaks (n=116, p=114), +## microcosm (n=880, p=259), scRNA (n=3918, p=500) +## Covariances: full, diagonal, spherical +## With / without covariates +## Note: full covariance skipped for scRNA (p=500, O(n·p²) M-step prohibitive) +## full covariance for microcosm is slow (~30–60s per fit) +## ============================================================ + +suppressPackageStartupMessages({ + devtools::load_all(".", quiet = TRUE) + library(ggplot2) + library(tidyr) +}) + +ctrl <- function(cov) PLN_param(backend = "homemade", covariance = cov, trace = 0) + +## ---- trichoptera (n=49, p=17) ---- +cat("Fitting trichoptera...\n") +tri <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +fits <- list( + tri_full_nocov = PLN(Abundance ~ 1, data = tri, control = ctrl("full")), + tri_diag_nocov = PLN(Abundance ~ 1, data = tri, control = ctrl("diagonal")), + tri_sph_nocov = PLN(Abundance ~ 1, data = tri, control = ctrl("spherical")), + tri_full_cov = PLN(Abundance ~ Wind + Temperature, data = tri, control = ctrl("full")), + tri_diag_cov = PLN(Abundance ~ Wind + Temperature, data = tri, control = ctrl("diagonal")), + tri_sph_cov = PLN(Abundance ~ Wind + Temperature, data = tri, control = ctrl("spherical")) +) + +## ---- barents (n=89, p=30) ---- +cat("Fitting barents...\n") +fits <- c(fits, list( + bar_full_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = barents, control = ctrl("full")), + bar_diag_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = barents, control = ctrl("diagonal")), + bar_sph_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = barents, control = ctrl("spherical")), + bar_full_cov = PLN(Abundance ~ Depth + Temperature + offset(log(Offset)), data = barents, control = ctrl("full")), + bar_diag_cov = PLN(Abundance ~ Depth + Temperature + offset(log(Offset)), data = barents, control = ctrl("diagonal")), + bar_sph_cov = PLN(Abundance ~ Depth + Temperature + offset(log(Offset)), data = barents, control = ctrl("spherical")) +)) + +## ---- mollusk (n=163, p=32) ---- +cat("Fitting mollusk...\n") +mol <- prepare_data(mollusk$Abundance, mollusk$Covariate) +fits <- c(fits, list( + mol_full_nocov = PLN(Abundance ~ 1, data = mol, control = ctrl("full")), + mol_diag_nocov = PLN(Abundance ~ 1, data = mol, control = ctrl("diagonal")), + mol_sph_nocov = PLN(Abundance ~ 1, data = mol, control = ctrl("spherical")), + mol_full_cov = PLN(Abundance ~ site + season, data = mol, control = ctrl("full")), + mol_diag_cov = PLN(Abundance ~ site + season, data = mol, control = ctrl("diagonal")), + mol_sph_cov = PLN(Abundance ~ site + season, data = mol, control = ctrl("spherical")) +)) + +## ---- oaks (n=116, p=114) ---- +cat("Fitting oaks...\n") +fits <- c(fits, list( + oak_full_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = oaks, control = ctrl("full")), + oak_diag_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = oaks, control = ctrl("diagonal")), + oak_sph_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = oaks, control = ctrl("spherical")), + oak_full_cov = PLN(Abundance ~ tree + offset(log(Offset)), data = oaks, control = ctrl("full")), + oak_diag_cov = PLN(Abundance ~ tree + offset(log(Offset)), data = oaks, control = ctrl("diagonal")), + oak_sph_cov = PLN(Abundance ~ tree + offset(log(Offset)), data = oaks, control = ctrl("spherical")) +)) + +## ---- microcosm (n=880, p=259) ---- +cat("Fitting microcosm (diagonal + spherical)...\n") +fits <- c(fits, list( + mic_diag_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = microcosm, control = ctrl("diagonal")), + mic_sph_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = microcosm, control = ctrl("spherical")), + mic_diag_cov = PLN(Abundance ~ site + offset(log(Offset)), data = microcosm, control = ctrl("diagonal")), + mic_sph_cov = PLN(Abundance ~ site + offset(log(Offset)), data = microcosm, control = ctrl("spherical")) +)) +cat("Fitting microcosm full covariance (slow — O(n·p²) M-step with n=880, p=259)...\n") +fits <- c(fits, list( + mic_full_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = microcosm, control = ctrl("full")), + mic_full_cov = PLN(Abundance ~ site + offset(log(Offset)), data = microcosm, control = ctrl("full")) +)) + +## ---- scRNA (n=3918, p=500) — full covariance skipped ---- +cat("Fitting scRNA (diagonal + spherical only — full covariance prohibitive at p=500)...\n") +fits <- c(fits, list( + scr_diag_nocov = PLN(counts ~ 1 + offset(log(total_counts)), data = scRNA, control = ctrl("diagonal")), + scr_sph_nocov = PLN(counts ~ 1 + offset(log(total_counts)), data = scRNA, control = ctrl("spherical")), + scr_diag_cov = PLN(counts ~ cell_line + offset(log(total_counts)), data = scRNA, control = ctrl("diagonal")), + scr_sph_cov = PLN(counts ~ cell_line + offset(log(total_counts)), data = scRNA, control = ctrl("spherical")) +)) + +cat("All fits done.\n") + +## ---- Extract monitoring ---- +mon <- lapply(names(fits), function(nm) { + m <- fits[[nm]]$optim_par + obj <- m$objective + obj_norm <- (obj - min(obj)) / (max(obj) - min(obj) + .Machine$double.eps) + rel_change <- abs(diff(obj)) / (abs(obj[-length(obj)]) + 1e-30) + tail_n <- max(5L, as.integer(0.2 * length(rel_change))) + tail_slope <- if (all(tail(rel_change, tail_n) > 0)) + mean(log10(tail(rel_change, tail_n) + 1e-30)) + else NA_real_ + parts <- strsplit(nm, "_")[[1]] + list( + name = nm, + dataset = parts[1], + covariance = parts[2], + covariates = parts[3], + n_iter = m$iterations, + status = m$status, + converged = (m$status == 3), + obj_init = obj[1], + obj_final = obj[length(obj)], + rel_drop = (obj[1] - obj[length(obj)]) / abs(obj[1]), + last_delta = rel_change[length(rel_change)], + tail_slope = tail_slope, + obj_seq = obj, + rel_seq = rel_change, + obj_norm_seq = obj_norm + ) +}) + +## ---- Summary table ---- +cat("\n========== CONVERGENCE SUMMARY ==========\n") +sumtab <- do.call(rbind, lapply(mon, function(x) { + data.frame( + fit = x$name, + n_iter = x$n_iter, + converged = x$converged, + rel_drop = signif(x$rel_drop, 3), + last_delta = signif(x$last_delta, 3), + tail_slope = signif(x$tail_slope, 3), + stringsAsFactors = FALSE + ) +})) +print(sumtab, row.names = FALSE) + +## ---- Plateau detection ---- +cat("\n========== PLATEAU DETECTION (fraction of steps with delta < 1e-6) ==========\n") +for (x in mon) { + r <- x$rel_seq + frac_flat <- mean(r < 1e-6) + cat(sprintf(" %-25s %5.1f%% flat steps | %d total\n", + x$name, 100*frac_flat, x$n_iter)) +} + +## ---- EM kink detection ---- +cat("\n========== EM KINK DETECTION (local minima in rel-change = EM M-step boundaries) ==========\n") +for (x in mon) { + r <- x$rel_seq + kinks <- which(diff(sign(diff(log(r + 1e-30)))) == 2) + cat(sprintf(" %-25s ~%d EM kinks in %d inner steps (%.1f steps/EM)\n", + x$name, length(kinks), x$n_iter, + if (length(kinks) > 0) x$n_iter / length(kinks) else NaN)) +} + +## ---- Convergence speed ---- +cat("\n========== CONVERGENCE RATE (mean log10 rel-change in last 20% of steps) ==========\n") +for (x in mon) { + cat(sprintf(" %-25s tail log10(delta) = %.2f (higher = slower)\n", + x$name, x$tail_slope)) +} + +## ---- Build tidy data frames for plots ---- +df_traj <- do.call(rbind, lapply(mon, function(x) { + data.frame(name = x$name, dataset = x$dataset, covariance = x$covariance, + covariates = x$covariates, + step = seq_along(x$obj_norm_seq), obj_norm = x$obj_norm_seq, + stringsAsFactors = FALSE) +})) + +df_rel <- do.call(rbind, lapply(mon, function(x) { + data.frame(name = x$name, dataset = x$dataset, covariance = x$covariance, + covariates = x$covariates, + step = seq_along(x$rel_seq), rel_change = pmax(x$rel_seq, 1e-16), + stringsAsFactors = FALSE) +})) + +## ---- Plot 1: normalised objective (log1p) ---- +dataset_labels <- c(tri = "trichoptera (n=49, p=17)", + bar = "barents (n=89, p=30)", + mol = "mollusk (n=163, p=32)", + oak = "oaks (n=116, p=114)", + mic = "microcosm (n=880, p=259)", + scr = "scRNA (n=3918, p=500)") + +p1 <- ggplot(df_traj, aes(step, obj_norm + 1e-6, colour = covariance, linetype = covariates)) + + geom_line(linewidth = 0.6) + + facet_wrap(~ dataset, scales = "free_x", + labeller = labeller(dataset = dataset_labels)) + + scale_y_log10() + + labs(title = "Normalised inner objective (log10 scale)", + subtitle = "(obj - obj_min) / range -- 0 = fully converged", + x = "Newton step (cumulated over EM)", y = "Normalised obj", + colour = "Covariance", linetype = "Covariates") + + theme_bw(base_size = 11) + +ggsave("convergence_trajectory.pdf", p1, width = 15, height = 8) +cat("\nSaved: convergence_trajectory.pdf\n") + +## ---- Plot 2: per-step relative change ---- +p2 <- ggplot(df_rel, aes(step, rel_change, colour = covariance, linetype = covariates)) + + geom_line(linewidth = 0.5, alpha = 0.8) + + facet_wrap(~ dataset, scales = "free", + labeller = labeller(dataset = dataset_labels)) + + scale_y_log10() + + geom_hline(yintercept = 1e-8, linetype = "dotted", colour = "grey50") + + labs(title = "Per-step relative change |dobj|/|obj| (log10)", + subtitle = "Dotted = ftol_in = 1e-8 | Bumps = EM M-step boundary", + x = "Newton step", y = "Relative change", + colour = "Covariance", linetype = "Covariates") + + theme_bw(base_size = 11) + +ggsave("convergence_rel_change.pdf", p2, width = 15, height = 8) +cat("Saved: convergence_rel_change.pdf\n") + +## ---- Plot 3: distribution of step sizes ---- +p3 <- ggplot(df_rel, aes(rel_change, fill = covariance)) + + geom_histogram(bins = 50, alpha = 0.65, position = "identity") + + facet_grid(dataset ~ covariates, scales = "free_y", + labeller = labeller(dataset = dataset_labels)) + + scale_x_log10() + + geom_vline(xintercept = 1e-8, linetype = "dotted") + + labs(title = "Distribution of per-step relative changes", + x = "Relative change (log10)", fill = "Covariance") + + theme_bw(base_size = 10) + +ggsave("convergence_step_dist.pdf", p3, width = 12, height = 14) +cat("Saved: convergence_step_dist.pdf\n") From bd56a24e3e692206aefd1dafc7741fe10ce01e07 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 06:46:27 +0200 Subject: [PATCH 41/58] res benchmark --- .Rbuildignore | 3 +- inst/backend_comparison.R | 20 ++++++++---- inst/benchmark/backend_comparison.csv | 37 ++++++++++++++++++++++ inst/benchmark/backend_loglik.pdf | Bin 0 -> 7022 bytes inst/benchmark/backend_speedup.pdf | Bin 0 -> 6964 bytes inst/benchmark/backend_time.pdf | Bin 0 -> 7446 bytes inst/benchmark/convergence_rel_change.pdf | Bin 0 -> 314291 bytes inst/benchmark/convergence_step_dist.pdf | Bin 0 -> 14414 bytes inst/benchmark/convergence_trajectory.pdf | Bin 0 -> 189591 bytes inst/convergence_analysis.R | 17 ++++++---- inst/missing_data/call_optim_PCA.R | 26 --------------- 11 files changed, 64 insertions(+), 39 deletions(-) create mode 100644 inst/benchmark/backend_comparison.csv create mode 100644 inst/benchmark/backend_loglik.pdf create mode 100644 inst/benchmark/backend_speedup.pdf create mode 100644 inst/benchmark/backend_time.pdf create mode 100644 inst/benchmark/convergence_rel_change.pdf create mode 100644 inst/benchmark/convergence_step_dist.pdf create mode 100644 inst/benchmark/convergence_trajectory.pdf delete mode 100644 inst/missing_data/call_optim_PCA.R diff --git a/.Rbuildignore b/.Rbuildignore index d703a3f2..e274c348 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -26,10 +26,11 @@ ^inst/check$ ^inst/torch_for_r$ ^inst/case_studies$ -^inst/test/ ^inst/missing_data$ ^inst/simus_PLNnetwork$ ^inst/simus_ZIPLN$ +^inst/benchmark$ +^inst/binom$ ^\.github$ ^data-raw$ ^CRAN-SUBMISSION$ diff --git a/inst/backend_comparison.R b/inst/backend_comparison.R index 1a964f0b..df169a8c 100644 --- a/inst/backend_comparison.R +++ b/inst/backend_comparison.R @@ -2,8 +2,8 @@ ## Backend comparison: homemade Newton vs nlopt/CCSAQ ## Metrics: computation time, iterations, final loglik ## Datasets: trichoptera, barents, mollusk, oaks, microcosm, scRNA -## Covariances: full, diagonal, spherical -## Note: full covariance skipped for scRNA (p=500, prohibitive) +## Covariances: full, diagonal, spherical (including scRNA full) +## Output: inst/benchmark/ ## ============================================================ suppressPackageStartupMessages({ @@ -94,11 +94,16 @@ for (lbl in c("mic_nocov", "mic_cov")) { results[[length(results)+1]] <- compare_both(form, microcosm, "full", lbl) } -cat("=== scRNA (n=3918, p=500) — full skipped ===\n") +cat("=== scRNA (n=3918, p=500) ===\n") for (cov in c("diagonal", "spherical")) { results[[length(results)+1]] <- compare_both(counts ~ 1 + offset(log(total_counts)), scRNA, cov, "scr_nocov") results[[length(results)+1]] <- compare_both(counts ~ cell_line + offset(log(total_counts)), scRNA, cov, "scr_cov") } +cat(" scRNA full covariance (very slow)...\n") +for (lbl in c("scr_nocov", "scr_cov")) { + form <- if (lbl == "scr_nocov") counts ~ 1 + offset(log(total_counts)) else counts ~ cell_line + offset(log(total_counts)) + results[[length(results)+1]] <- compare_both(form, scRNA, "full", lbl) +} cat("All fits done.\n\n") @@ -131,6 +136,9 @@ print(wide %>% select(label, covariance, mutate(across(where(is.numeric), ~ signif(., 4))), row.names = FALSE, width = 200) +write.csv(wide, "inst/benchmark/backend_comparison.csv", row.names = FALSE) +cat("Saved: backend_comparison.csv\n") + ## ---- Plot 1: time comparison ---- p1 <- ggplot(df, aes(x = paste(label, covariance, sep="\n"), y = time_s, fill = backend)) + geom_col(position = "dodge", width = 0.7) + @@ -141,7 +149,7 @@ p1 <- ggplot(df, aes(x = paste(label, covariance, sep="\n"), y = time_s, fill = theme_bw(base_size = 10) + theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 7)) -ggsave("backend_time.pdf", p1, width = 18, height = 10) +ggsave("inst/benchmark/backend_time.pdf", p1, width = 18, height = 10) cat("\nSaved: backend_time.pdf\n") ## ---- Plot 2: loglik difference (newton - nlopt) ---- @@ -163,7 +171,7 @@ p2 <- ggplot(df_wide, aes(x = fit, y = ll_diff, theme_bw(base_size = 10) + theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 7)) -ggsave("backend_loglik.pdf", p2, width = 18, height = 10) +ggsave("inst/benchmark/backend_loglik.pdf", p2, width = 18, height = 10) cat("Saved: backend_loglik.pdf\n") ## ---- Plot 3: speedup (nlopt_time / newton_time) ---- @@ -179,5 +187,5 @@ p3 <- ggplot(df_wide, aes(x = fit, y = time_s_nlopt / time_s_newton, theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 7), legend.position = "none") -ggsave("backend_speedup.pdf", p3, width = 18, height = 10) +ggsave("inst/benchmark/backend_speedup.pdf", p3, width = 18, height = 10) cat("Saved: backend_speedup.pdf\n") diff --git a/inst/benchmark/backend_comparison.csv b/inst/benchmark/backend_comparison.csv new file mode 100644 index 00000000..e85f1739 --- /dev/null +++ b/inst/benchmark/backend_comparison.csv @@ -0,0 +1,37 @@ +"label","covariance","time_s_newton","time_s_nlopt","n_iter_newton","n_iter_nlopt","loglik_newton","loglik_nlopt","converged_newton","converged_nlopt","loglik_diff","speedup" +"bar_cov","diagonal",1.05,0.539000000000001,1390,610,-4652.41317806047,-4653.99348305037,TRUE,TRUE,1.58030498990229,0.513333333333334 +"bar_cov","full",1.841,1.026,1764,1680,-4402.0859350791,-4413.41174849079,TRUE,TRUE,11.325813411695,0.557305812058663 +"bar_cov","spherical",0.811,0.469999999999999,829,256,-4760.4695205047,-4761.35301027491,TRUE,TRUE,0.883489770218148,0.579531442663377 +"bar_nocov","diagonal",0.707000000000001,0.441999999999998,635,192,-5149.60159867053,-5149.63778663945,TRUE,TRUE,0.0361879689180569,0.625176803394622 +"bar_nocov","full",1.24,0.888999999999999,984,1181,-4598.24275109682,-4612.09856510894,TRUE,TRUE,13.8558140121222,0.716935483870968 +"bar_nocov","spherical",0.495999999999999,0.43,196,129,-5328.28635148151,-5328.2894020688,TRUE,TRUE,0.00305058729372831,0.86693548387097 +"mic_cov","diagonal",51.479,15.247,639,374,-240659.939958148,-240818.143459407,TRUE,TRUE,158.203501258919,0.296179024456575 +"mic_cov","full",115.783,22.978,1309,507,-214999.32158194,-244917.899601699,TRUE,FALSE,29918.5780197598,0.198457459212492 +"mic_cov","spherical",48.234,18.277,565,351,-240957.760282918,-241060.554147804,TRUE,TRUE,102.793864886713,0.37892358087656 +"mic_nocov","diagonal",20.108,19.471,210,337,-256915.919764276,-256977.808342199,TRUE,TRUE,61.888577923557,0.968321066242292 +"mic_nocov","full",105.867,22.934,1124,462,-217552.959190675,-248119.764778727,TRUE,FALSE,30566.8055880514,0.21663030028243 +"mic_nocov","spherical",15.628,16.729,190,344,-257402.932528361,-257453.434787707,TRUE,TRUE,50.502259346249,1.07045047350908 +"mol_cov","diagonal",13.834,21.611,15396,10000,-2911.2889512502,-2919.77577617919,FALSE,FALSE,8.4868249289816,1.56216567876247 +"mol_cov","full",17.49,11.069,15061,14772,-2846.76911940346,-2852.36858140965,FALSE,TRUE,5.59946200618424,0.632875929102344 +"mol_cov","spherical",10.278,3.16200000000001,11631,3618,-2953.18152203507,-2954.28459024873,FALSE,TRUE,1.1030682136643,0.307647402218331 +"mol_nocov","diagonal",3.68,0.679000000000002,3637,421,-4194.73378465473,-4194.53368225736,FALSE,TRUE,-0.200102397374394,0.184510869565218 +"mol_nocov","full",7.626,4.899,4930,6131,-3636.11380818712,-3643.5050447213,FALSE,TRUE,7.39123653418164,0.642407553107789 +"mol_nocov","spherical",1.708,0.545000000000002,1532,210,-4243.76351089611,-4243.76368505931,TRUE,TRUE,0.000174163194060384,0.319086651053865 +"oak_cov","diagonal",2.94999999999999,1.547,459,286,-35993.0942141486,-35995.6366421201,TRUE,TRUE,2.54242797150073,0.524406779661018 +"oak_cov","full",5.15700000000001,5.24799999999999,882,1672,-31386.5517453461,-31407.5336217167,TRUE,TRUE,20.9818763705771,1.01764591816947 +"oak_cov","spherical",2.09899999999999,0.792000000000002,294,137,-36731.9371369512,-36732.9568866259,TRUE,TRUE,1.01974967472052,0.37732253454026 +"oak_nocov","diagonal",1.09299999999999,0.854000000000013,121,141,-38407.6721221679,-38407.8643602946,TRUE,TRUE,0.192238126750453,0.781335773101575 +"oak_nocov","full",6.188,4.69499999999999,715,1750,-32028.4697547819,-32048.6173086626,TRUE,TRUE,20.1475538807026,0.758726567550096 +"oak_nocov","spherical",0.850999999999999,0.722000000000008,60,105,-39450.2375855111,-39450.2370236831,TRUE,TRUE,-0.000561827982892282,0.848413631022337 +"scr_cov","diagonal",231.829,132.426,420,268,-4047743.23620142,-4047750.81489767,TRUE,TRUE,7.57869625417516,0.57122275470282 +"scr_cov","full",285.188,739.741,527,1550,-3749669.06887884,-3750612.59354959,TRUE,TRUE,943.52467074804,2.59387141113932 +"scr_cov","spherical",134.827,67.923,266,143,-4123014.20792418,-4123019.79846823,TRUE,TRUE,5.59054405335337,0.503778916685827 +"scr_nocov","diagonal",69.731,88.533,124,181,-4619897.81674815,-4619906.54349095,TRUE,TRUE,8.72674279939383,1.26963617329452 +"scr_nocov","full",367.284,782.01,644,1676,-3781946.19168387,-3782813.28887135,TRUE,TRUE,867.097187487409,2.12916979775868 +"scr_nocov","spherical",30.346,42.8700000000001,52,93,-4796744.81980006,-4796751.50031606,TRUE,TRUE,6.68051600176841,1.41270678178343 +"tri_cov","diagonal",0.573,0.451000000000001,927,510,-1140.57830657624,-1140.60974804156,FALSE,TRUE,0.031441465318494,0.787085514834208 +"tri_cov","full",0.877,0.557,1052,975,-1080.76749574514,-1082.12577047728,FALSE,TRUE,1.35827473213976,0.635119726339795 +"tri_cov","spherical",0.465000000000002,0.427999999999999,405,190,-1172.0745796868,-1172.08077342394,TRUE,TRUE,0.00619373714448557,0.920430107526876 +"tri_nocov","diagonal",0.529999999999999,0.423,793,211,-1250.76584921142,-1250.72668131909,FALSE,TRUE,-0.0391678923338077,0.798113207547171 +"tri_nocov","full",0.897,0.661,816,1229,-1129.55914454164,-1130.2978158157,TRUE,TRUE,0.738671274052194,0.736900780379041 +"tri_nocov","spherical",0.437999999999999,0.395,234,98,-1286.04055118098,-1286.04064726557,TRUE,TRUE,9.60845829922619e-05,0.901826484018266 diff --git a/inst/benchmark/backend_loglik.pdf b/inst/benchmark/backend_loglik.pdf new file mode 100644 index 0000000000000000000000000000000000000000..95cc35a3238665cc611c4cd6c2f061ef7cb2af31 GIT binary patch literal 7022 zcmZ{pcR1T^+sCb<_NY}_v9}Ogt=fv#-c&?{iUbK_&!Se*Qd*muRg~6Vwf9z9t7x_M z-s+7$ckkzUpZk4(|Kzy7zwpG9*IL=SLTzabNLZZUrBwWFZ!ArqI!DCkLB%%Nj z0MhOeiJTk>P{kbzMmr%9s$et}z^f_?5&=nyNQ#Pr#KfgRAU+bHF4F%0eP`r^hGTab z05sgeu8vL+6ySje+SLP%-KOV`wD*8O-LKw?3rh-%V71@1kXI5PiGl(N6k&gL3eexD z0RWA>U7-M=3K$KBBVhob9vB8i0mQHY27rHWkow1ltGKIZcPIk=S2$1wi9lnQD1h|u z?LY%43hChv!R8bHuY6Ylf7+n~MZnOG05K715CEv|1V>|U091!#o1+SaAnl=7=SHEi zJ#!(!q;*(oKV_+=ZW=0Ea68J9oVO?HR#T@@Qi|cU01)*NFHiI`d3$w@yj^e3hZlY|NNMtyaEgG)>Qqy4hxMw99X0%K04beH~h{#H)c5;r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EM^&9fB3A&sfw#YCgOcS?n$naIvg2Xvm^F} z{ELlReVB(c-0hdd>b3OmuGBZ z{sUcXyWQj6aMVkh9Tw@E=qq>31<{Z>@b5XQuDX?-U-q@xZ{F`~V8jLAp4grqv1Bns z5%$e1_wTkJo4RH_{fDMoQExDL6)(6*!ui6v{8J7$_nTG1A3lB;TjuL{XyrooA^R2M zn&ph#=Vycbo3ZO$H?Me>RkY>gEk5kp{=q$@cn@d!#dDnEwZZL|O(W>OB>!|s;dhe)c zr2>cUn=-?(`c^EZ57tEuA2%nq?s8U>=)oviwf%luL@Cj4^(Wijx2?Qry$rt#KSFko z|Ius9{oRIA{xt+pM-%Sbk!Zpc;Jj`9_sRr`Rzc&Ce*{V(6zSlAAl&?)U+r4}q@;l^ zNVGc+AO``ux?}JN6v6>d36hcm+G7aA3LFjz06MzC9uRt57~K85)rBM7;O;ICD1;{f zh)1IA36cv8?uJ1FfOc+(b3=kB3=Ss@6DWc9NJ1(c5(fZ^qcM1UgaZKR_Is0XLhFx0 z!Tv*caz{JD+}vGIFn2rvh;hWA5zd5cu-}n!=bgLNe@sDs_xgVt@qdj$ev<&u(A^II zdn$4+5*XtS%!RNe0v-IW%fD>25U2+TJQ5D01pcWD;Jl*$IW_TgLpV?ppaeuI@%ICO zNJ~pf0~`QpFf{ouO-hC^$@wo$T9yDj|D{1d1aSJ_ zngkg14_^te+&?skN7y_Q1*8_ML egTVvNM^3+MgTuqz@V_eqAv~1){OWodl>Y;tRae0P literal 0 HcmV?d00001 diff --git a/inst/benchmark/backend_time.pdf b/inst/benchmark/backend_time.pdf new file mode 100644 index 0000000000000000000000000000000000000000..a81790d7da0edcf662d7ed6f6a6c387402ad44e6 GIT binary patch literal 7446 zcmZ{pbzIcj_WtRV76CyRx`ctD1tf-&jsYYEh9M*dnL(+c8{tTYbccu%Qc_aV-6dVp z$RMD82k$xOo_p`_H~;L}&u8tu)?RvFjf4SslpcVDK;lB;!onaCQArSpmjtK1iT^op6L%Bs4s%8R84d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-#*8(mgx z)gfGm7fcXzsJiv6vF50&bTp%%=#Tdny8zjTyRr|CtlER6p$qT1Uj+kqLmi=X?}J+Uitb-N$bq7 zu>;s4a^~!ZF+-)DWy(iAf5aDoJ(piisV`_m8V=td^2??AZGWdfJ3c6Wsgv!8iw-%x z`kz@_>hCd>E+VM|Y@)i=8vf z697ayI@@9-7i*|H+!X+{afjUmVoq8^p%}Y}1ZeAsNriAk0Dyw7aHK8F4ghrjT_hAU z`a3&Y|3i21aJ9E~_i%Bx_CNxFaC^8b%n6gt`uEL{uQGJbAAp(Izp{UfPeJ`aMRI$`eL5$Fgp?qln9du z{rv-oi;0Pd0qg*OYaopKck=_d{;dg%V?gLXH4#Y(44V9xCMAY}oBz~Ag~Ty@@!y&h zrnLXmgh0X=pYOjlssGW$C8Yi*hlG&WKWaw0TRS?#+%e`Q0BGRo4a2+_0DR8HK9Tk%Q1MWF&MF0Q* literal 0 HcmV?d00001 diff --git a/inst/benchmark/convergence_rel_change.pdf b/inst/benchmark/convergence_rel_change.pdf new file mode 100644 index 0000000000000000000000000000000000000000..ce6fd6eaf0ff800bbd8ba90dffda0bea18f978f4 GIT binary patch literal 314291 zcmZ^~cT`hb^e$=#L=ER4Ml1wusHj1ZUUCG>u~0046cZ7tK_e)TFqi(XeP@Gjgo0V8^^acjy&4qkcU|8l{KnPr8(^C2HO!@OKmThBy$AN0 z?=uE%|Gf*d(6no%z5Po6E0-3eF!_I^(TAUnzUr?Jcl5pC8;S|khr9X)`d`;K1p`j& z|GyI~{*MU@;}%9=^S^TAe}=;yF;{MY>UDj~|E9xF`(MX|U-JX&9r*vPw=m#;tK+2q zmB1T8`lkDh_Zyq&!;b`q-T-@m9|;BOIppt$x#Yhf`Slw>YnN9><)!6+>)7+{;Ul(u zm(uWD{$F~`U3Nhl8rv+FuDE^b`U9_x;0Z~XEu(KiZ}wW9P!SOu>#lSwco1f)Surah z;alkl#XKFM{6kVHVai_cB+QuQL>Caac$F+eHJ-s{Yuj<8^9Y=5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ar$0};K1w>E7Nhj3Z|W~D-S8hexuKa9)pj@B@|nlziY+7pt89aF#6ElO@9k|) zTC^+ro#e!dx>o_)oKGFb=Pz~w#&Y*=4ne*vSFl>FQL-dsOQXY2N&>v`o z&|aYlN57120SX%(Q{?dntj9fkp44ft&TA!gIhyzlOIbTmpLJf5Z>DV@XuaFjzOUM8 za(5bA(sL&ZY}(A5Xpeiyx}gf5;j?#ZBhoAd!9J9 zI`NpheAJ<+wl+?0QxA4uWjk|PzdSoGO;82H>-8co9{#V4 zT=3s%DCU1>YawE$rMZJRPka ztb71K4?72VE(>%tvv6~E0szh3to|~>CCw}>teiYBftGe~Q|@+fsKD;z>|tqT4FJ0R z-~AUHUf{RiFF)5*rn%@e--f~N-n=xpQcWMvPxX7-O}_rICD5$69S>i-~uea#C-i)MpYK`{{ypw=*R#7 literal 0 HcmV?d00001 diff --git a/inst/benchmark/convergence_step_dist.pdf b/inst/benchmark/convergence_step_dist.pdf new file mode 100644 index 0000000000000000000000000000000000000000..5fbccd59cfb420316f27e2094d0731e07e3427ef GIT binary patch literal 14414 zcmZ{L1yo$ivi9J?AxHv&FhC%<4=xEF+zErr;1(DH1b2cNDgsrsIIY4rT+}8ChZo z3SzK|Ilv6z7IwDchHw~|PMn{Ejf0zwo1LA5gNv7qmmY&v-p=Iz>{GLVTLWGyU?~Sf zdvgn8N3fz3+};TexG6c>gC~7{bCBFk6#{RdD=kHDFdX zS9=(kRm>1>Xl-W(W>qpYgE@jZ0Rt8Aza4n~m&1eIgS7+97XG(6tC*cF91tDBynozT zRbY;GP7cPvcwGNA-h;tE;gEybn!(M%>}(ty5HPExg*6=b3apaWKy<`m#&#yKhlM-B zfuPx7xTNmt%2$xpL^rnRvr91;L2NTxaD|H-8zSsGY&)PK(|)^1@~Y+5(c>X8=liVQ z3?Othbw^X)9Ex1$;n)o152TxW{o)AozZ6;o>c$oo?ynDuYFh4hpX5EUqnLAj8c1;G zalLZdZcnN(%kg>jo-C00?m8$Tuax3WfUD^w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oOB-zpxlTTR z=E-$irn?0e65bNxKQL(X6EL1Ddnp3DKk;nbq`Wlj^dA&Irk<7RruBHqDx!Dca`R>~ zHYu-Dgz;YIx_@oPxy9v%gN;Z4a;I~0Ggg|SpWiZlKe`9ohfkl}YLb+i>LoNPdpRyK zZ`<5ABsvpt*6o+=Gm0d7ZeBh;Io!(&Q%v_nI`==m{$G1?zJF~)G5$VIBw-62+_A6) z&J#UsTmLO-TG+m}b+q_Lfx#+nVQLBk&JaBu64C~9L0D}pY@HmzeB7+>ob2E*YnUk< zgPn_u)x-`s_T=bj0cJIGFnkZ}aSe@~9=5v177oTvHm24v7ceW_!rBB-*%%r-*x7yP+PdV>Lc@xNyH4+j?qm?;Jun4Jp)nECGy zm>UA&gn&)K|I%>)3DLs`Z2K=AJ2x=Z|Io3sLHK~I>c4c{JV0LdUpih6Am#aQ9R!Hh z|Io3qaXftg|JL#Sw~n0?0{LHaaPmF``+xYdbMmnPC)WO32V{8vrQ>2_`;Ya(9Skk3 zVGh8VKQODR#RnJ=D=_ODTT?qAEB%ufs@U1V!GGn5e=;yb2l$_;vU9OPAQ&_>5{i-- F{|^o%wxIw3 literal 0 HcmV?d00001 diff --git a/inst/benchmark/convergence_trajectory.pdf b/inst/benchmark/convergence_trajectory.pdf new file mode 100644 index 0000000000000000000000000000000000000000..4d5fafd020089db54ad4f0ae12f1bb0b4d35f0cd GIT binary patch literal 189591 zcma&O2{_d2`#*mAblOywEOm%U3KdCZ$ud5noEF=uP!p1*vS%A+m`bt~bK0mQCY++h zUPHF2EE8gK6ejzU5yKe6Fvg7k{T^D*_xt}{zu$Gayr1{`+3x3Fp5=bs&uq3a-><2? zeYe==%e|NTF4HbIoxCWfyzUR)n`fsof4DbyMfNC}uea-~Bx?Mza zcW>9-z5~9A`tm_OZ4pDG#oWBlAXM!9PR$0bqanU-8??+^0$ehSSYS#=Hndzul^hKMb)+baP#*Gyyyz;?fxI_AqBp%H#t#;bIM2PO2wG^AzkQChbR8jlPM`z}Zh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pdQRd+5*wv+1cjb(rd6@;i?<()kY3)4|pTC<=dvjWMDI|E78Pcp&XLfKnpEA^pz>A}=Q=D+jTM z{F4TgfiTZPT>nXvkq3$pBS=fK3f%7n#|0hl9 zztUtB6_sTFrw%0~$&;FTS{(leeXGU` literal 0 HcmV?d00001 diff --git a/inst/convergence_analysis.R b/inst/convergence_analysis.R index 11e44c12..8769a6f4 100644 --- a/inst/convergence_analysis.R +++ b/inst/convergence_analysis.R @@ -5,8 +5,8 @@ ## microcosm (n=880, p=259), scRNA (n=3918, p=500) ## Covariances: full, diagonal, spherical ## With / without covariates -## Note: full covariance skipped for scRNA (p=500, O(n·p²) M-step prohibitive) -## full covariance for microcosm is slow (~30–60s per fit) +## Note: full covariance for microcosm (~30-60s) and scRNA (very slow) included +## Output: inst/benchmark/ ## ============================================================ suppressPackageStartupMessages({ @@ -78,13 +78,18 @@ fits <- c(fits, list( )) ## ---- scRNA (n=3918, p=500) — full covariance skipped ---- -cat("Fitting scRNA (diagonal + spherical only — full covariance prohibitive at p=500)...\n") +cat("Fitting scRNA diagonal + spherical (n=3918, p=500)...\n") fits <- c(fits, list( scr_diag_nocov = PLN(counts ~ 1 + offset(log(total_counts)), data = scRNA, control = ctrl("diagonal")), scr_sph_nocov = PLN(counts ~ 1 + offset(log(total_counts)), data = scRNA, control = ctrl("spherical")), scr_diag_cov = PLN(counts ~ cell_line + offset(log(total_counts)), data = scRNA, control = ctrl("diagonal")), scr_sph_cov = PLN(counts ~ cell_line + offset(log(total_counts)), data = scRNA, control = ctrl("spherical")) )) +cat("Fitting scRNA full covariance (very slow — O(n·p²) M-step with n=3918, p=500)...\n") +fits <- c(fits, list( + scr_full_nocov = PLN(counts ~ 1 + offset(log(total_counts)), data = scRNA, control = ctrl("full")), + scr_full_cov = PLN(counts ~ cell_line + offset(log(total_counts)), data = scRNA, control = ctrl("full")) +)) cat("All fits done.\n") @@ -193,7 +198,7 @@ p1 <- ggplot(df_traj, aes(step, obj_norm + 1e-6, colour = covariance, linetype = colour = "Covariance", linetype = "Covariates") + theme_bw(base_size = 11) -ggsave("convergence_trajectory.pdf", p1, width = 15, height = 8) +ggsave("inst/benchmark/convergence_trajectory.pdf", p1, width = 15, height = 8) cat("\nSaved: convergence_trajectory.pdf\n") ## ---- Plot 2: per-step relative change ---- @@ -209,7 +214,7 @@ p2 <- ggplot(df_rel, aes(step, rel_change, colour = covariance, linetype = covar colour = "Covariance", linetype = "Covariates") + theme_bw(base_size = 11) -ggsave("convergence_rel_change.pdf", p2, width = 15, height = 8) +ggsave("inst/benchmark/convergence_rel_change.pdf", p2, width = 15, height = 8) cat("Saved: convergence_rel_change.pdf\n") ## ---- Plot 3: distribution of step sizes ---- @@ -223,5 +228,5 @@ p3 <- ggplot(df_rel, aes(rel_change, fill = covariance)) + x = "Relative change (log10)", fill = "Covariance") + theme_bw(base_size = 10) -ggsave("convergence_step_dist.pdf", p3, width = 12, height = 14) +ggsave("inst/benchmark/convergence_step_dist.pdf", p3, width = 12, height = 14) cat("Saved: convergence_step_dist.pdf\n") diff --git a/inst/missing_data/call_optim_PCA.R b/inst/missing_data/call_optim_PCA.R deleted file mode 100644 index 1a3993b4..00000000 --- a/inst/missing_data/call_optim_PCA.R +++ /dev/null @@ -1,26 +0,0 @@ -library(PLNmodels) -data("trichoptera") -trichoptera <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) - -Y <- as.matrix(trichoptera$Abundance) -X <- model.matrix(Abundance ~ 1, data = trichoptera) -n <- nrow(Y) -p <- ncol(Y) -d <- ncol(X) # number of covariates -q <- 5 # number of PCA components -O <- matrix(0, nrow = n, ncol = p) - -data <- list(Y = Y, - X = X, - O = O, - w = rep(1,n)) - -params <- list(B = matrix(0, d, p), - C = matrix(0, p, q), - M = matrix(0, n, q), - S = matrix(0.1, n, q) - ) -config <- PLNPCA_param()$config_optim - -out <- PLNmodels:::nlopt_optimize_rank(data, params, config) - From cd016353f500c5940938cbb4d6da6461f3c83577 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 09:40:11 +0200 Subject: [PATCH 42/58] cleaning code --- DEVLOG_2026-06-11-12.md | 195 ++++++++++++++++++++++++++++++++++++++++ src/CovarianceTraits.h | 116 ++++-------------------- src/newton_impl.h | 34 ++++--- src/nlopt_impl.h | 22 ++--- 4 files changed, 241 insertions(+), 126 deletions(-) create mode 100644 DEVLOG_2026-06-11-12.md diff --git a/DEVLOG_2026-06-11-12.md b/DEVLOG_2026-06-11-12.md new file mode 100644 index 00000000..fedc6fc1 --- /dev/null +++ b/DEVLOG_2026-06-11-12.md @@ -0,0 +1,195 @@ +# Journal de développement — 11-12 juin 2026 + +Branche : `code-enhancement` + +--- + +## 20. Pas Newton conjoint sur (M, ψ) — remplacement du point fixe (11/06) + +**Fichiers** : `src/CovarianceTraits.h`, `src/newton_impl.h` + +### Motivation + +L'ancienne boucle interne faisait : +1. Step Newton diagonal pour M (avec Armijo) +2. Point fixe exact pour S² : `S² = -1 / (A + diag(Ω))` (pas d'Armijo, convergence immédiate) + +Cette séparation ignore le couplage entre M et S (via A = exp(M + S²/2 + O)). La correction de l'un modifie A, qui invalide l'autre. On travaille alternativement sur deux sous-problèmes couplés, ce qui ralentit la convergence. + +### Nouveau pas conjoint (M, ψ) avec terme croisé + +On paramétrise ψ = log(S²) et on résout simultanément le système 2×2 **par entrée (i,j)** : + +``` +Hessienne diagonale par blocs (indépendance entre (i,j)) : + H_MM = w·(A + ω_jj) + H_ψψ = 0.5·w·S²·(A·(1 + 0.5·S²) + ω_jj) + H_Mψ = 0.5·w·A·S² ← terme croisé (nul si A≈0) + +det = H_MM·H_ψψ - H_Mψ² (clampé à 1e-20) +step_M = (H_ψψ·grad_M - H_Mψ·grad_ψ) / det +step_ψ = (H_MM·grad_ψ - H_Mψ·grad_M) / det +``` + +L'Armijo est appliqué conjointement sur `(M - α·Q_step, ψ - α·step_ψ)` avec pente : + +``` +slope = -accu(grad_M % Q_step) - accu(grad_ψ % step_ψ) +``` + +où `Q_step = step_M - X * (P_X * step_M)` est la projection hors col(X) pour le B profilé. + +### Résultat + +Convergence plus robuste sur les grands datasets (microcosm, scRNA). Le terme croisé H_Mψ est faible quand A est petit (régions creuses), fort quand A est grand (signaux forts) — l'approximation diagonale par blocs est exacte dans la limite d'observations indépendantes. + +--- + +## 21. Investigation et suppression de `block_newton_thresh` (12/06) + +**Fichiers** : `src/CovarianceTraits.h`, `src/utils.h`, `src/newton_impl.h`, `src/newton_full_cov.cpp`, `src/newton_fixed_cov.cpp`, `R/utils.R`, `R/PLN.R` + +### Origine du paramètre + +Avant le pas conjoint, `DenseOmegaImpl` offrait un mode alternatif : pour `p ≤ block_newton_thresh`, on calculait le step exact par **solveur Schur p×p par observation** (complément de Schur sur H_MM, en O(np³)). L'approximation diagonale 2×2 était le fallback pour `p > thresh`. + +### Analyse du coût — cas barents (n=89, p=30) + +Avec `block_newton_thresh = 30` (défaut), barents full activait le solveur exact : +- Coût : 89 × (920 iters) × (30³ / 6) ≈ **2G FLOPs** par EM step +- Temps observé : 3 s (contre 0.9 s pour nlopt) + +Passage à `block_newton_thresh = 0` (approx diagonale) : +- Coût : O(n·p) ≈ 90 × fois moins +- Temps observé : **0.68 s** +- Loglik : **identique** (+14 vs nlopt, inchangé) +- Itérations internes : +15% seulement + +La précision supplémentaire du solveur exact n'apporte aucun bénéfice observable, pour un coût prohibitif sur des datasets de taille courante. + +### Décision : suppression complète + +Le paramètre `block_newton_thresh` est **supprimé** de l'ensemble du code (7 fichiers modifiés) : + +| Fichier | Modification | +|---------|-------------| +| `R/utils.R` | Suppression de `block_newton_thresh = 0L` dans `config_default_homemade` | +| `R/PLN.R` | Suppression de la ligne `@param` dans la doc | +| `src/utils.h` | Suppression du champ `int block_newton_thresh = 30` dans `NewtonConfig` et du parsing | +| `src/CovarianceTraits.h` | `DenseOmegaImpl::compute_joint_step_MS` et `compute_step_M` : suppression du paramètre et du bloc `if (thresh > 0)` avec les solveurs Schur | +| `src/CovarianceTraits.h` | `DiagonalCovTraits`, `SphericalCovTraits` : suppression du paramètre commenté `/*block_thresh*/ = 0` | +| `src/newton_impl.h` | `newton_optimize_impl` et `newton_vestep_impl` : suppression du paramètre ; correction de virgule résiduelle | +| `src/newton_full_cov.cpp`, `newton_fixed_cov.cpp` | Suppression de `cfg.block_newton_thresh` dans les appels | + +--- + +## 22. Augmentation de `maxit_em` : 50 → 200 (12/06) + +**Fichier** : `R/utils.R` + +### Problème + +Trichoptera full (nocov) et oaks full convergeaient `FALSE` avec `maxit_em = 50`. L'ELBO progressait encore à la 50ème itération externe : il manquait simplement du budget, pas un défaut algorithmique. + +### Correction + +`maxit_em = 50L → 200L` dans `config_default_homemade`. Résultat : oaks full et trichoptera full (nocov) convergent désormais (`conv = TRUE`). + +**État final de `config_default_homemade`** : +```r +config_default_homemade <- + list( + algorithm = "NEWTON", + backend = "homemade", + maxeval = 10000, + ftol_in = 1e-8, + maxit_em = 200, + ftol_em = 1e-8 + ) +``` + +--- + +## 23. Benchmark complet — 6 jeux de données (12/06) + +**Fichiers** : `inst/convergence_analysis.R`, `inst/backend_comparison.R`, `inst/.gitignore` (via `.gitignore` racine), `.Rbuildignore` + +### Jeux de données couverts + +| Dataset | n | p | Covariances testées | +|---------|---|---|---------------------| +| trichoptera | 49 | 17 | full, diag, sph | +| barents | 89 | 30 | full, diag, sph | +| mollusk | 163 | 32 | full, diag, sph | +| oaks | 116 | 114 | full, diag, sph | +| microcosm | 880 | 259 | diag, sph, **full** | +| scRNA | 3918 | 500 | diag, sph, **full** | + +Toutes les configurations testées avec et sans covariables (12 labels, 3 covariances = 36 paires chacune avec Newton et nlopt). + +### Sorties + +`inst/benchmark/` (dans `.gitignore` et `.Rbuildignore`) : +- `convergence_trajectory.pdf` — ELBO vs itérations EM +- `convergence_rel_change.pdf` — changement relatif ELBO par itération +- `convergence_step_dist.pdf` — distance des pas (M, S) par itération +- `backend_time.pdf` — temps de calcul Newton vs nlopt +- `backend_loglik.pdf` — différence de loglik (Newton − nlopt) +- `backend_speedup.pdf` — speedup nlopt/Newton par configuration +- `backend_comparison.csv` — tableau complet + +### Résultats clés + +**Newton trouve toujours un loglik ≥ nlopt** (invariant robuste sur tous les datasets) : + +| Régime | Speedup Newton/nlopt | ll_diff | Conv Newton | Conv nlopt | +|--------|---------------------|---------|-------------|------------| +| **scRNA full** (n=3918, p=500) | **2.1–2.6× plus rapide** | **+867 à +944** | ✓ | ✓ | +| scRNA diag/sph nocov | 1.3–1.4× plus rapide | +7–9 | ✓ | ✓ | +| scRNA diag/sph cov | nlopt légèrement plus rapide | +1–8 | ✓ | ✓ | +| oaks full (n=116, p=114) | ~1× (égal) | +20–21 | ✓ | ✓ | +| **microcosm full** (n=880, p=259) | nlopt 4–5× plus rapide | **+30000** | ✓ | **✗ (conv=FALSE)** | +| barents full | nlopt 1.4–1.8× | +11–14 | ✓ | ✓ | +| mollusk | variable | +0–8 | ✗ | ✗/✓ | + +### Cas remarquables + +**microcosm full** : nlopt est plus rapide (23 s vs 106 s) mais **ne converge pas** — il s'arrête à un plateau bien inférieur (loglik ≈ −248 000 contre −217 000 pour Newton). Newton est le seul backend fonctionnel sur ce cas. + +**scRNA full** : Newton est à la fois plus rapide (+2.1–2.6×) et meilleur en loglik (+867/+944). La grande taille (n=3918) conditionne mieux le problème intérieur et facilite la convergence Newton. + +**mollusk** : les deux backends peinent (ELBO décroissant, rel_drop > 100%). Problème d'initialisation loin de l'optimum — hors périmètre de cette session. + +**trichoptera diagonal** : nécessite > 200 EM iterations externes — non convergé dans le budget. À investiguer séparément. + +--- + +## Récapitulatif des décisions algorithmiques finales + +### Ce qui est fixé (stable) + +| Composante | Choix retenu | Raison | +|-----------|-------------|--------| +| Paramétrage S | ψ = log(S²) | Évite les contraintes ≥ 0, meilleur conditionnement | +| Step interne | Pas conjoint Newton 2×2 (M, ψ) | Capture le couplage M-S via H_Mψ, sans coût O(p³) | +| Approximation hessienne | Diagonale par blocs (indépendance i,j) | Exacte pour Schur diagonal, O(np), identique en qualité à l'exact | +| Armijo | Conjoint sur (M, ψ), pente Q_step projetée | Correct avec B profilé (sinon pas trop longs si d/n grand) | +| B profilé | P_X = solve(X'WX, X'W), mis à jour avant chaque step | Élimine le cold-start, enveloppe valide | +| Structure EM | Boucle interne VE (ftol=1e-8) + boucle externe EM (maxit=200, em_tol=1e-8) | Convergence robuste sur grand n | +| Ω, B | M-step analytique après convergence interne | Newton pure uniquement sur (M, ψ) | + +### Ce qui est abandonné + +| Idée | Pourquoi abandonnée | +|------|---------------------| +| Block Newton (solveur Schur p×p) | O(np³) prohibitif, aucun gain en loglik vs approximation diagonale | +| Point fixe séparé pour S² | Ignore le couplage M-S, convergence plus lente | +| `homemade_alt` distinct de `homemade` | Fusionné dans `homemade` après validation (B profilé + Q_step Armijo) | +| `hybrid` comme défaut | Newton seul suffit sur tous les cas validés | + +### Cas limites connus + +- **mollusk** : mauvaise initialisation, les deux backends convergent mal +- **trichoptera diagonal** : besoin de > 200 EM iterations (budget à augmenter localement si nécessaire) +- **microcosm full** : Newton 4–5× plus lent que nlopt (mais seul à converger correctement) +- **La comparaison de temps est sensible à la charge BLAS** (multithreadé) : ne pas lancer les scripts en parallèle diff --git a/src/CovarianceTraits.h b/src/CovarianceTraits.h index c25e9dab..00209b99 100644 --- a/src/CovarianceTraits.h +++ b/src/CovarianceTraits.h @@ -4,7 +4,7 @@ // ───────────────────────────────────────────────────────────────────────────── // Shared base for dense (full p×p) Omega variants (FullCovTraits and FixedCovTraits). -// Contains the 6 static methods that are identical in both. Derived traits use +// Contains the static methods that are identical in both. Derived traits use // struct inheritance to expose these methods without repetition. // ───────────────────────────────────────────────────────────────────────────── struct DenseOmegaImpl { @@ -13,34 +13,8 @@ struct DenseOmegaImpl { arma::vec diag_Omega; }; - static arma::mat cov_diag(const State & s, const arma::mat & ones_row) { - return ones_row * s.diag_Omega.t(); - } - - static void grad_hess_M( - const arma::mat & M, const State & s, - const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & ones_row, - arma::mat & grad_M, arma::mat & hess_M) - { - arma::mat MO = M * s.Omega; - grad_M = MO + A - Y; grad_M.each_col() %= w; - hess_M = A + ones_row * s.diag_Omega.t(); hess_M.each_col() %= w; - } - static arma::mat times_Omega(const arma::mat & M, const State & s) { return M * s.Omega; } - static void compute_step_M( - const arma::mat & M, const State & s, - const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & ones_row, - arma::mat & grad_M, arma::mat & step_M) - { - const arma::mat MO = M * s.Omega; - grad_M = MO + A - Y; grad_M.each_col() %= w; - arma::mat hess = A + ones_row * s.diag_Omega.t(); hess.each_col() %= w; - hess.clamp(1e-10, arma::datum::inf); - step_M = grad_M / hess; - } - static double penalty_M(const arma::mat & MO, const arma::mat & M, const arma::vec & w) { return 0.5 * arma::as_scalar(w.t() * arma::sum(MO % M, 1)); } @@ -50,14 +24,17 @@ struct DenseOmegaImpl { } // Joint Newton step for (M, ψ) where ψ = log(S²): diagonal 2×2 per (i,j). + // MO (output) = M * Omega — returned so the caller can reuse it for penalty/Armijo + // without an extra O(n p²) matrix product. static void compute_joint_step_MS( const arma::mat & M, const State & s, const arma::mat & A, const arma::mat & S2, const arma::mat & Y, const arma::vec & w, const arma::mat & ones_row, arma::mat & grad_M, arma::mat & step_M, - arma::mat & grad_psi, arma::mat & step_psi) + arma::mat & grad_psi, arma::mat & step_psi, + arma::mat & MO) { - const arma::mat MO = M * s.Omega; + MO = M * s.Omega; const arma::mat omega_d = ones_row * s.diag_Omega.t(); const arma::mat AS2 = A % S2; @@ -74,12 +51,6 @@ struct DenseOmegaImpl { step_psi = (h_mm % grad_psi - h_mp % grad_M ) / det; } - static double objective_cov(const arma::mat & M, const arma::mat & S2, const State & s, const arma::vec & w) { - arma::mat MO = M * s.Omega; - return 0.5 * (arma::as_scalar(w.t() * arma::sum(MO % M, 1)) - + arma::dot(s.diag_Omega, (w.t() * S2).t())); - } - static arma::vec final_loglik(const arma::mat & Y, const arma::mat & Z, const arma::mat & A, const arma::mat & M, const arma::mat & psi, const State & s) { const arma::mat S2 = arma::exp(psi); @@ -148,32 +119,8 @@ struct DiagonalCovTraits { } }; - static arma::mat cov_diag(const State & s, const arma::mat & ones_row) { - return ones_row * s.omega2; - } - - static void grad_hess_M( - const arma::mat & M, const State & s, - const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & ones_row, - arma::mat & grad_M, arma::mat & hess_M) - { - grad_M = M.each_row() % s.omega2 + A - Y; grad_M.each_col() %= w; - hess_M = ones_row * s.omega2 + A; hess_M.each_col() %= w; - } - static arma::mat times_Omega(const arma::mat & M, const State & s) { return M.each_row() % s.omega2; } - static void compute_step_M( - const arma::mat & M, const State & s, - const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & ones_row, - arma::mat & grad_M, arma::mat & step_M) - { - grad_M = M.each_row() % s.omega2 + A - Y; grad_M.each_col() %= w; - arma::mat hess = ones_row * s.omega2 + A; hess.each_col() %= w; - hess.clamp(1e-10, arma::datum::inf); - step_M = grad_M / hess; - } - static double penalty_M(const arma::mat & MO, const arma::mat & M, const arma::vec & w) { return 0.5 * arma::as_scalar(w.t() * arma::sum(MO % M, 1)); } @@ -182,17 +129,20 @@ struct DiagonalCovTraits { return 0.5 * arma::as_scalar((w.t() * S2) * s.omega2.t()); } + // MO (output) = M.each_row() % omega2 — returned for caller reuse. static void compute_joint_step_MS( const arma::mat & M, const State & s, const arma::mat & A, const arma::mat & S2, const arma::mat & Y, const arma::vec & w, const arma::mat & ones_row, arma::mat & grad_M, arma::mat & step_M, - arma::mat & grad_psi, arma::mat & step_psi) + arma::mat & grad_psi, arma::mat & step_psi, + arma::mat & MO) { const arma::mat omega_d = ones_row * s.omega2; const arma::mat AS2 = A % S2; - grad_M = M.each_row() % s.omega2 + A - Y; grad_M.each_col() %= w; - grad_psi = 0.5 * (AS2 + omega_d % S2 - 1.0); grad_psi.each_col() %= w; + MO = M.each_row() % s.omega2; + grad_M = MO + A - Y; grad_M.each_col() %= w; + grad_psi = 0.5 * (AS2 + omega_d % S2 - 1.0); grad_psi.each_col() %= w; arma::mat h_pp = 0.5 * (S2 % (A % (1.0 + 0.5*S2) + omega_d)); h_pp.each_col() %= w; arma::mat h_mp = 0.5 * AS2; h_mp.each_col() %= w; @@ -204,10 +154,6 @@ struct DiagonalCovTraits { step_psi = (h_mm % grad_psi - h_mp % grad_M ) / det; } - static double objective_cov(const arma::mat & M, const arma::mat & S2, const State & s, const arma::vec & w) { - return 0.5 * arma::as_scalar((w.t() * (M % M + S2)) * s.omega2.t()); - } - static void mstep(State & s, const arma::mat & M, const arma::mat & S2, const arma::vec & w, double w_bar, arma::uword /*p*/) { s.update(M, S2, w, w_bar); @@ -257,36 +203,25 @@ struct SphericalCovTraits { } }; - // returns double: fixed_point_psi handles scalar broadcast - static double cov_diag(const State & s, const arma::mat & /*ones_row*/) { - return s.omega2; - } - - static void grad_hess_M( - const arma::mat & M, const State & s, - const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & /*ones_row*/, - arma::mat & grad_M, arma::mat & hess_M) - { - grad_M = s.omega2 * M + A - Y; grad_M.each_col() %= w; - hess_M = s.omega2 + A; hess_M.each_col() %= w; - } - static arma::mat times_Omega(const arma::mat & M, const State & s) { return s.omega2 * M; } static double penalty_S(const arma::mat & S2, const State & s, const arma::vec & w) { return 0.5 * s.omega2 * arma::dot(w, arma::sum(S2, 1)); } + // MO (output) = omega2 * M — returned for caller reuse. static void compute_joint_step_MS( const arma::mat & M, const State & s, const arma::mat & A, const arma::mat & S2, const arma::mat & Y, const arma::vec & w, const arma::mat & /*ones_row*/, arma::mat & grad_M, arma::mat & step_M, - arma::mat & grad_psi, arma::mat & step_psi) + arma::mat & grad_psi, arma::mat & step_psi, + arma::mat & MO) { const arma::mat AS2 = A % S2; - grad_M = s.omega2 * M + A - Y; grad_M.each_col() %= w; - grad_psi = 0.5 * (AS2 + s.omega2 * S2 - 1.0); grad_psi.each_col() %= w; + MO = s.omega2 * M; + grad_M = MO + A - Y; grad_M.each_col() %= w; + grad_psi = 0.5 * (AS2 + s.omega2 * S2 - 1.0); grad_psi.each_col() %= w; arma::mat h_pp = 0.5 * (S2 % (A % (1.0 + 0.5*S2) + s.omega2)); h_pp.each_col() %= w; arma::mat h_mp = 0.5 * AS2; h_mp.each_col() %= w; @@ -298,25 +233,10 @@ struct SphericalCovTraits { step_psi = (h_mm % grad_psi - h_mp % grad_M ) / det; } - static void compute_step_M( - const arma::mat & M, const State & s, - const arma::mat & A, const arma::mat & Y, const arma::vec & w, const arma::mat & /*ones_row*/, - arma::mat & grad_M, arma::mat & step_M) - { - grad_M = s.omega2 * M + A - Y; grad_M.each_col() %= w; - arma::mat hess = s.omega2 + A; hess.each_col() %= w; - hess.clamp(1e-10, arma::datum::inf); - step_M = grad_M / hess; - } - static double penalty_M(const arma::mat & MO, const arma::mat & M, const arma::vec & w) { return 0.5 * arma::as_scalar(w.t() * arma::sum(MO % M, 1)); } - static double objective_cov(const arma::mat & M, const arma::mat & S2, const State & s, const arma::vec & w) { - return 0.5 * s.omega2 * arma::accu(arma::diagmat(w) * (M % M + S2)); - } - static void mstep(State & s, const arma::mat & M, const arma::mat & S2, const arma::vec & w, double w_bar, arma::uword /*p*/) { s.update(M, S2, w, w_bar); diff --git a/src/newton_impl.h b/src/newton_impl.h index 095a2b0b..7824ca3d 100644 --- a/src/newton_impl.h +++ b/src/newton_impl.h @@ -51,12 +51,12 @@ Rcpp::List newton_optimize_impl( const arma::mat XB = X * B; const arma::mat M_res = M - XB; - // Joint Newton step for (M, ψ): gradient + 2×2 Newton per (i,j) - arma::mat grad_M, step_M, grad_psi, step_psi; + // Joint Newton step: compute_joint_step_MS also returns MO = M_res * Omega + // so we reuse it for the Armijo penalty — avoids a redundant O(n p²) product. + arma::mat grad_M, step_M, grad_psi, step_psi, MresO; Traits::compute_joint_step_MS(M_res, state, A, S2, Y, w, ones_row, - grad_M, step_M, grad_psi, step_psi); + grad_M, step_M, grad_psi, step_psi, MresO); const arma::mat Q_step = step_M - X * (P_X * step_M); - const arma::mat MresO = Traits::times_Omega(M_res, state); const arma::mat QstepO = Traits::times_Omega(Q_step, state); double f0 = arma::accu(w.t() * (A - Y % Z - 0.5 * psi)) + Traits::penalty_M(MresO, M_res, w) + Traits::penalty_S(S2, state, w); @@ -152,19 +152,17 @@ Rcpp::List newton_vestep_impl( double obj_prev = arma::datum::inf; int total_iter = 0; - // Z and A are kept current at the end of each iteration; compute them once here. arma::mat Z = O + M; arma::mat A = arma::exp(Z + 0.5 * S2); for (int it = 0; it < maxiter; it++) { - // S2, Z, A are current. - arma::mat M_res = M - XB; // M_res for KL terms (B is fixed) + arma::mat M_res = M - XB; - // ---- Joint Newton step for (M, ψ) ---- - arma::mat grad_M, step_M, grad_psi, step_psi; + // Joint Newton step: MO = M_res * Omega returned to avoid recomputing it + // for the Armijo penalty evaluation. + arma::mat grad_M, step_M, grad_psi, step_psi, MO; Traits::compute_joint_step_MS(M_res, state, A, S2, Y, w, ones_row, - grad_M, step_M, grad_psi, step_psi); - const arma::mat MO = Traits::times_Omega(M_res, state); + grad_M, step_M, grad_psi, step_psi, MO); const arma::mat dMO = Traits::times_Omega(step_M, state); double f0 = arma::accu(w.t() * (A - Y % Z - 0.5 * psi)) + Traits::penalty_M(MO, M_res, w) + Traits::penalty_S(S2, state, w); @@ -186,12 +184,14 @@ Rcpp::List newton_vestep_impl( psi -= alpha * step_psi; S2 = arma::exp(psi); Z = O + M; + A = arma::exp(Z + 0.5 * S2); - // ---- Objective for convergence ---- - A = arma::exp(Z + 0.5 * S2); - arma::mat M_res_new = M - XB; + // Post-update objective: reuse MO_new = MO - alpha*dMO = M_res_new * Omega + // (exact incremental update, avoids an extra O(n p²) product for full cov). + const arma::mat MO_new = MO - alpha * dMO; + const arma::mat M_res_new = M - XB; double obj = arma::accu(w.t() * (A - Y % Z - 0.5 * psi)) - + Traits::objective_cov(M_res_new, S2, state, w); + + Traits::penalty_M(MO_new, M_res_new, w) + Traits::penalty_S(S2, state, w); objective_vec.push_back(obj); total_iter++; @@ -199,10 +199,8 @@ Rcpp::List newton_vestep_impl( obj_prev = obj; } - // ---- Final output ---- - // S2, Z, A are current from the last iteration (fixed_point_psi + exp update). S = arma::exp(0.5 * psi); - const arma::mat M_res = M - XB; // for loglik KL terms + const arma::mat M_res = M - XB; arma::vec loglik = Traits::final_loglik(Y, Z, A, M_res, psi, state); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); diff --git a/src/nlopt_impl.h b/src/nlopt_impl.h index 501d4fdb..9477fe5b 100644 --- a/src/nlopt_impl.h +++ b/src/nlopt_impl.h @@ -4,20 +4,22 @@ // Shared objective/gradient implementations for the three NLOPT covariance variants. // Defined inline here so nlopt_full_cov.cpp, nlopt_diag_cov.cpp, nlopt_spherical.cpp and // nlopt_fixed_cov.cpp can all include this header instead of each defining a private static copy. +// +// All three functions optimize over (M_full, ψ=log(S²)) and return grad_psi = d/dψ. // Full covariance: Z = O + M_full supplied by caller. -// Returns the ELBO objective (negated); fills grad_M and grad_S. +// Returns the ELBO objective (negated); fills grad_M and grad_psi. inline double full_cov_obj_grad_impl( const arma::mat & M_res, const arma::mat & Z, const arma::mat & logS2, const arma::mat & Omega, const arma::vec & Omega_diag, const arma::mat & Y, const arma::vec & w, - arma::mat & grad_M, arma::mat & grad_S + arma::mat & grad_M, arma::mat & grad_psi ) { const arma::mat S2 = arma::exp(logS2); const arma::mat A = arma::exp(Z + 0.5 * S2); const arma::mat MO = M_res * Omega; - grad_M = arma::diagmat(w) * (MO + A - Y); - grad_S = 0.5 * arma::diagmat(w) * (S2.each_row() % Omega_diag.t() + S2 % A - 1.); + grad_M = MO + A - Y; grad_M.each_col() %= w; + grad_psi = 0.5 * (S2.each_row() % Omega_diag.t() + S2 % A - 1.0); grad_psi.each_col() %= w; return accu(w.t() * (A - Y % Z - 0.5 * logS2)) + 0.5 * (accu(MO % (M_res.each_col() % w)) + dot(Omega_diag, (w.t() * S2).t())); } @@ -29,11 +31,11 @@ inline double diag_cov_obj_grad_impl( const arma::mat & S2, const arma::mat & logS2, const arma::rowvec & inv_sigma2, double penalty, const arma::mat & Y, const arma::vec & w, - arma::mat & grad_M, arma::mat & grad_S + arma::mat & grad_M, arma::mat & grad_psi ) { const arma::mat A = arma::exp(Z + 0.5 * S2); - grad_M = arma::diagmat(w) * (M_res.each_row() % inv_sigma2 + A - Y); - grad_S = 0.5 * arma::diagmat(w) * (S2.each_row() % inv_sigma2 + S2 % A - 1.); + grad_M = M_res.each_row() % inv_sigma2 + A - Y; grad_M.each_col() %= w; + grad_psi = 0.5 * (S2.each_row() % inv_sigma2 + S2 % A - 1.0); grad_psi.each_col() %= w; return accu(w.t() * (A - Y % Z - 0.5 * logS2)) + penalty; } @@ -43,10 +45,10 @@ inline double spherical_cov_obj_grad_impl( const arma::mat & S2, const arma::mat & logS2, double inv_sigma2, double penalty, const arma::mat & Y, const arma::vec & w, - arma::mat & grad_M, arma::mat & grad_S + arma::mat & grad_M, arma::mat & grad_psi ) { const arma::mat A = arma::exp(Z + 0.5 * S2); - grad_M = arma::diagmat(w) * (M_res * inv_sigma2 + A - Y); - grad_S = 0.5 * arma::diagmat(w) * (S2 * inv_sigma2 + S2 % A - 1.); + grad_M = M_res * inv_sigma2 + A - Y; grad_M.each_col() %= w; + grad_psi = 0.5 * (S2 * inv_sigma2 + S2 % A - 1.0); grad_psi.each_col() %= w; return accu(w.t() * (A - Y % Z - 0.5 * logS2)) + penalty; } From 56900ca075ef4ef850df133f005d5f4728cdfb8a Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 10:39:33 +0200 Subject: [PATCH 43/58] =?UTF-8?q?avoid=20passing=20S=20as=20S=C2=B2=20is?= =?UTF-8?q?=20now=20the=20natural=20parameter=20in=20PLN-like=20algo=20(lo?= =?UTF-8?q?g(S=C2=B2)=20is=20used=20for=20optim)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/PLNLDAfit-class.R | 2 +- R/PLNPCAfit-class.R | 10 +++++++++- R/PLNfit-class.R | 38 +++++++++++++++++++++----------------- R/PLNnetworkfamily-class.R | 2 +- R/PLNnetworkfit-class.R | 6 +++--- R/utils.R | 8 ++++---- src/newton_diag_cov.cpp | 15 +++++++-------- src/newton_fixed_cov.cpp | 4 ++-- src/newton_full_cov.cpp | 15 +++++++-------- src/newton_impl.h | 16 ++++++---------- src/newton_spherical.cpp | 15 +++++++-------- src/nlopt_diag_cov.cpp | 26 ++++++++++++-------------- src/nlopt_fixed_cov.cpp | 15 +++++++-------- src/nlopt_full_cov.cpp | 29 +++++++++++++---------------- src/nlopt_spherical.cpp | 26 ++++++++++++-------------- 15 files changed, 112 insertions(+), 115 deletions(-) diff --git a/R/PLNLDAfit-class.R b/R/PLNLDAfit-class.R index 967f9c9e..47da2f70 100644 --- a/R/PLNLDAfit-class.R +++ b/R/PLNLDAfit-class.R @@ -95,7 +95,7 @@ PLNLDAfit <- R6Class( covariates <- cbind(covariates, model.matrix( ~ grouping + 0)) super$postTreatment(responses, covariates, offsets, weights, config_post = config_post, config_optim = config_optim) rownames(private$C) <- colnames(private$C) <- colnames(responses) - colnames(private$S) <- 1:self$q + colnames(private$S2) <- 1:self$q if (config_post$trace > 1) cat("\n\tCompute LD scores for visualization...") self$setVisualization() }, diff --git a/R/PLNPCAfit-class.R b/R/PLNPCAfit-class.R index 3df1e079..d4b97d9d 100644 --- a/R/PLNPCAfit-class.R +++ b/R/PLNPCAfit-class.R @@ -48,6 +48,7 @@ PLNPCAfit <- R6Class( private = list( C = NULL, svdCM = NULL, + S = NA , # rank-reduced variational variances (n × q), separate from PLNfit's S2 ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ## PRIVATE TORCH METHODS FOR RANK-CONSTRAINED OPTIMIZATION @@ -284,8 +285,9 @@ PLNPCAfit <- R6Class( #' @param monitoring a list with optimization monitoring quantities #' @return Update the current [`PLNPCAfit`] object update = function(B=NA, Sigma=NA, Omega=NA, C=NA, M=NA, S=NA, Z=NA, A=NA, Ji=NA, R2=NA, monitoring=NA) { - super$update(B = B, Sigma = Sigma, Omega = Omega, M = M, S = S, Z = Z, A = A, Ji = Ji, R2 = R2, monitoring = monitoring) + super$update(B = B, Sigma = Sigma, Omega = Omega, M = M, Z = Z, A = A, Ji = Ji, R2 = R2, monitoring = monitoring) if (!anyNA(C)) private$C <- C + if (!anyNA(S)) private$S <- S }, ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -379,6 +381,10 @@ PLNPCAfit <- R6Class( 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) + if (!identical(private$S, NA)) { + rownames(private$S) <- rownames(responses) + colnames(private$S) <- 1:self$q + } self$setVisualization() }, @@ -507,6 +513,8 @@ PLNPCAfit <- R6Class( ## ACTIVE BINDINGS ---- ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% active = list( + #' @field var_par variational parameters (M, S, S2) in the rank-q latent space + var_par = function() {list(M = private$M, S2 = private$S^2, S = private$S)}, #' @field rank the dimension of the current model rank = function() {self$q}, #' @field vcov_model character: the model used for the residual covariance diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index 11dff1e9..cfeae84f 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -52,7 +52,7 @@ PLNfit <- R6Class( B = NA , # regression parameters of the latent layer Sigma = NA , # covariance matrix of the latent layer Omega = NA , # precision matrix of the latent layer. Inverse of Sigma - S = NA , # variational parameters for the variances + S2 = NA , # variational parameters for the variances M = NA , # variational parameters for the means Z = NA , # matrix of latent variable A = NA , # matrix of expected counts (under variational approximation) @@ -244,7 +244,7 @@ PLNfit <- R6Class( vcov_sandwich_B = function(Y, X) { vcov_sand <- get_sandwich_variance_B(Y, X, private$A, - private$S, private$Sigma, diag(private$Omega) + sqrt(private$S2), private$Sigma, diag(private$Omega) ) attr(private$B, "vcov_sandwich") <- vcov_sand attr(private$B, "variance_sandwich") <- matrix(diag(vcov_sand), nrow = self$d, ncol = self$p, @@ -376,14 +376,14 @@ PLNfit <- R6Class( private$Sigma <- control$inception$model_par$Sigma private$B <- control$inception$model_par$B private$M <- control$inception$var_par$M - private$S <- control$inception$var_par$S + private$S2 <- control$inception$var_par$S2 } else { if (control$trace > 1) cat("\n Use LM after log transformation to define the inceptive model") start_point <- compute_PLN_starting_point(Y = responses, X = covariates, O = offsets, w = weights, method = if (is.null(control$init_method)) "LM" else control$init_method) - private$B <- start_point$B - private$M <- start_point$M - private$S <- start_point$S + private$B <- start_point$B + private$M <- start_point$M + private$S2 <- start_point$S2 } private$setup_optimizer(control$backend, nlopt_optimize_full, newton_optimize_full, @@ -404,12 +404,13 @@ PLNfit <- R6Class( #' @param A matrix of fitted values #' @param monitoring a list with optimization monitoring quantities #' @return Update the current [`PLNfit`] object - update = function(B=NA, Sigma=NA, Omega=NA, M=NA, S=NA, Ji=NA, R2=NA, Z=NA, A=NA, monitoring=NA) { + update = function(B=NA, Sigma=NA, Omega=NA, M=NA, S2=NA, S=NA, Ji=NA, R2=NA, Z=NA, A=NA, monitoring=NA) { if (!identical(B, NA)) private$B <- B if (!identical(Sigma, NA)) private$Sigma <- Sigma if (!identical(Omega, NA)) private$Omega <- Omega if (!identical(M, NA)) private$M <- M - if (!identical(S, NA)) private$S <- S + if (!identical(S2, NA)) private$S2 <- S2 + if (!identical(S, NA) && identical(S2, NA)) private$S2 <- S^2 if (!identical(Z, NA)) private$Z <- Z if (!identical(A, NA)) private$A <- A if (!identical(Ji, NA)) private$Ji <- Ji @@ -424,7 +425,7 @@ PLNfit <- R6Class( #' @description Call to the NLopt or TORCH optimizer and update of the relevant fields optimize = function(responses, covariates, offsets, weights, config) { args <- list(data = list(Y = responses, X = covariates, O = offsets, w = weights), - params = list(B = private$B, M = private$M, S = private$S), + params = list(B = private$B, M = private$M, S2 = private$S2), config = config) optim_out <- do.call(private$optimizer$main, args) do.call(self$update, optim_out) @@ -444,9 +445,9 @@ PLNfit <- R6Class( n <- nrow(responses); p <- ncol(responses) ## initialize variational parameters with current value if dimension is the same if ((p != self$p) || (n != self$n)) { - params0 <- list(M = covariates %*% B, S = matrix(.1, n, p)) + params0 <- list(M = covariates %*% B, S2 = matrix(.01, n, p)) } else { - params0 <- list(M = self$var_par$M, S = self$var_par$S) + params0 <- list(M = self$var_par$M, S2 = self$var_par$S2) } args <- list(data = list(Y = responses, X = covariates, O = offsets, w = weights), ## Initialize the variational parameters with the new dimension of the data @@ -479,8 +480,11 @@ PLNfit <- R6Class( } rownames(private$Sigma) <- colnames(private$Sigma) <- colnames(responses) rownames(private$Omega) <- colnames(private$Omega) <- colnames(responses) - rownames(private$M) <- rownames(private$S) <- rownames(responses) - colnames(private$S) <- 1:self$q + rownames(private$M) <- rownames(responses) + if (!identical(private$S2, NA) && ncol(private$S2) == self$q) { + rownames(private$S2) <- rownames(responses) + colnames(private$S2) <- 1:self$q + } ## OPTIONAL POST-TREATMENT (potentially costly) ## 1. compute and store approximated R2 with Poisson-based deviance @@ -554,7 +558,7 @@ PLNfit <- R6Class( ) M <- VE$M # M_full colnames(M) <- colnames(private$B) - S2 <- (VE$S)**2 + S2 <- VE$S2 } else { # population prediction: M_full = X*B (M_res = 0) M <- X %*% private$B @@ -622,7 +626,7 @@ PLNfit <- R6Class( M_res_VE <- VE$M - X %*% self$model_par$B[, cond, drop = FALSE] M <- tcrossprod(M_res_VE, A) - S <- map(1:n_new, ~crossprod(VE$S[., ] * t(A)) + Sigma21) %>% simplify2array() + S <- map(1:n_new, ~crossprod(sqrt(VE$S2)[., ] * t(A)) + Sigma21) %>% simplify2array() ## mean latent positions in the parameter space EZ <- X %*% private$B[, !cond, drop = FALSE] + M + O[, !cond, drop = FALSE] @@ -686,7 +690,7 @@ PLNfit <- R6Class( #' @field model_par a list with the matrices of the model parameters: B (covariates), Sigma (covariance), Omega (precision matrix), plus some others depending on the variant) model_par = function() {list(B = private$B, Sigma = private$Sigma, Omega = private$Omega, Theta = t(private$B))}, #' @field var_par a list with the matrices of the variational parameters: M (means) and S2 (variances) - var_par = function() {list(M = private$M, S2 = private$S**2, S = private$S)}, + var_par = function() {list(M = private$M, S2 = private$S2, S = sqrt(private$S2))}, #' @field optim_par a list with parameters useful for monitoring the optimization optim_par = function() {private$monitoring}, #' @field latent a matrix: values of the latent vector (Z in the model) @@ -945,7 +949,7 @@ PLNfit_fixedcov <- R6Class( #' @description Call to the NLopt or TORCH optimizer and update of the relevant fields optimize = function(responses, covariates, offsets, weights, config) { args <- list(data = list(Y = responses, X = covariates, O = offsets, w = weights), - params = list(B = private$B, M = private$M, S = private$S, Omega = private$Omega), + params = list(B = private$B, M = private$M, S2 = private$S2, Omega = private$Omega), config = config) optim_out <- do.call(private$optimizer$main, args) do.call(self$update, optim_out) diff --git a/R/PLNnetworkfamily-class.R b/R/PLNnetworkfamily-class.R index 74db828d..87c04f46 100644 --- a/R/PLNnetworkfamily-class.R +++ b/R/PLNnetworkfamily-class.R @@ -371,7 +371,7 @@ PLNnetworkfamily <- R6Class( inception_ <- self$getModel(self$penalties[1]) inception_$update( M = inception_$var_par$M[subsample, ], - S = inception_$var_par$S[subsample, ] + S2 = inception_$var_par$S2[subsample, ] ) ## force some control parameters diff --git a/R/PLNnetworkfit-class.R b/R/PLNnetworkfit-class.R index f01fd1f0..b9eb733f 100644 --- a/R/PLNnetworkfit-class.R +++ b/R/PLNnetworkfit-class.R @@ -58,10 +58,10 @@ PLNnetworkfit <- R6Class( ## start from the standard PLN at initialization objective.old <- -self$loglik args <- list(data = list(Y = data$Y, X = data$X, O = data$O, w = data$w), - params = list(B = private$B, M = private$M, S = private$S), + params = list(B = private$B, M = private$M, S2 = private$S2), config = config) M_res_init <- private$M - private$X %*% private$B - private$Sigma <- crossprod(M_res_init)/self$n + diag(colMeans(private$S**2), self$p, self$p) + private$Sigma <- crossprod(M_res_init)/self$n + diag(colMeans(private$S2), self$p, self$p) while (!cond) { iter <- iter + 1 if (config$trace > 1) cat("", iter) @@ -80,7 +80,7 @@ PLNnetworkfit <- R6Class( if ((convergence[iter] < config$ftol_em) | (iter >= config$maxit_em)) cond <- TRUE ## Prepare next iterate - args$params <- list(B = private$B, M = private$M, S = private$S) + args$params <- list(B = private$B, M = private$M, S2 = private$S2) objective.old <- objective[iter] } diff --git a/R/utils.R b/R/utils.R index 487b5252..6c17bc59 100644 --- a/R/utils.R +++ b/R/utils.R @@ -37,7 +37,7 @@ make_hybrid_optimizer <- function(opt_nlopt, opt_newton) { ftol_rel = config$ftol_in * 10 )) res1 <- opt_nlopt(data, params, config1) - params2 <- modifyList(params, list(B = res1$B, M = res1$M, S = res1$S)) + params2 <- modifyList(params, list(B = res1$B, M = res1$M, S2 = res1$S2)) # Phase 2: homemade Newton with full tolerance res2 <- opt_newton(data, params2, config) res2$monitoring$objective <- c(res1$monitoring$objective, res2$monitoring$objective) @@ -364,7 +364,7 @@ compute_PLN_starting_point <- function(Y, X, O, w, method = c("LM", "GLM")) { B <- lm.fit(w * X, w * log((1 + Y0) / expO), singular.ok = TRUE)$coefficients B[is.na(B)] <- 0 } - list(B = matrix(B, d, p), - M = matrix(log((1 + Y0) / expO), n, p), - S = 1 / sqrt(2 + Y0)) + list(B = matrix(B, d, p), + M = matrix(log((1 + Y0) / expO), n, p), + S2 = 1 / (2 + Y0)) } diff --git a/src/newton_diag_cov.cpp b/src/newton_diag_cov.cpp index 67614b65..a2ea1818 100644 --- a/src/newton_diag_cov.cpp +++ b/src/newton_diag_cov.cpp @@ -18,18 +18,17 @@ Rcpp::List newton_optimize_diagonal( const arma::mat & X = Rcpp::as(data["X"]); const arma::mat & O = Rcpp::as(data["O"]); const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); const NewtonConfig cfg(config); const double w_bar = arma::accu(w); - arma::mat S2 = S % S; const arma::mat M_res_init = M - X * B; DiagonalCovTraits::State state(M_res_init, S2, w, w_bar); - return newton_optimize_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); + return newton_optimize_impl(Y, X, O, w, B, M, S2, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); } // --------------------------------------------------------------------------------------- @@ -47,10 +46,10 @@ Rcpp::List newton_optimize_vestep_diagonal( const arma::mat & X = Rcpp::as(data["X"]); const arma::mat & O = Rcpp::as(data["O"]); const arma::vec & w = Rcpp::as(data["w"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); const NewtonConfig cfg(config); DiagonalCovTraits::State state(Omega); - return newton_vestep_impl(Y, X, O, w, M, S, B, state, cfg.maxiter, cfg.ftol); + return newton_vestep_impl(Y, X, O, w, M, S2, B, state, cfg.maxiter, cfg.ftol); } diff --git a/src/newton_fixed_cov.cpp b/src/newton_fixed_cov.cpp index 806ed0a2..821a519c 100644 --- a/src/newton_fixed_cov.cpp +++ b/src/newton_fixed_cov.cpp @@ -20,11 +20,11 @@ Rcpp::List newton_optimize_fixed( const arma::vec & w = Rcpp::as(data["w"]); arma::mat B = Rcpp::as(params["B"]); arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); + arma::mat S2 = Rcpp::as(params["S2"]); arma::mat Omega = Rcpp::as(params["Omega"]); const NewtonConfig cfg(config); FixedCovTraits::State state(Omega); - return newton_optimize_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); + return newton_optimize_impl(Y, X, O, w, B, M, S2, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); } diff --git a/src/newton_full_cov.cpp b/src/newton_full_cov.cpp index dc1cf35a..16948398 100644 --- a/src/newton_full_cov.cpp +++ b/src/newton_full_cov.cpp @@ -18,18 +18,17 @@ Rcpp::List newton_optimize_full( const arma::mat & X = Rcpp::as(data["X"]); const arma::mat & O = Rcpp::as(data["O"]); const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); const NewtonConfig cfg(config); const double w_bar = arma::accu(w); - arma::mat S2 = S % S; const arma::mat M_res_init = M - X * B; FullCovTraits::State state(M_res_init, S2, w, w_bar); - return newton_optimize_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); + return newton_optimize_impl(Y, X, O, w, B, M, S2, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); } // --------------------------------------------------------------------------------------- @@ -47,10 +46,10 @@ Rcpp::List newton_optimize_vestep_full( const arma::mat & X = Rcpp::as(data["X"]); const arma::mat & O = Rcpp::as(data["O"]); const arma::vec & w = Rcpp::as(data["w"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); const NewtonConfig cfg(config); FullCovTraits::State state(Omega); - return newton_vestep_impl(Y, X, O, w, M, S, B, state, cfg.maxiter, cfg.ftol); + return newton_vestep_impl(Y, X, O, w, M, S2, B, state, cfg.maxiter, cfg.ftol); } diff --git a/src/newton_impl.h b/src/newton_impl.h index 7824ca3d..1edc4df8 100644 --- a/src/newton_impl.h +++ b/src/newton_impl.h @@ -19,7 +19,7 @@ template Rcpp::List newton_optimize_impl( const arma::mat & Y, const arma::mat & X, const arma::mat & O, const arma::vec & w, - arma::mat B, arma::mat M, arma::mat S, + arma::mat B, arma::mat M, arma::mat S2, typename Traits::State state, int maxiter, double ftol, int max_em, double em_tol ) { @@ -33,8 +33,7 @@ Rcpp::List newton_optimize_impl( const arma::mat XtWX = X.t() * Xw; const arma::mat P_X = (X.n_cols > 0) ? arma::solve(XtWX, Xw.t()) : arma::mat(0, n); - arma::mat psi = arma::log(S % S); - arma::mat S2 = arma::exp(psi); + arma::mat psi = arma::log(S2); std::vector objective_vec; double elbo_prev = -arma::datum::inf; @@ -103,7 +102,6 @@ Rcpp::List newton_optimize_impl( } S2 = arma::exp(psi); - S = arma::exp(0.5 * psi); arma::mat M_res = M - X * B; Z = O + M; A = arma::exp(Z + 0.5 * S2); @@ -115,7 +113,7 @@ Rcpp::List newton_optimize_impl( return Rcpp::List::create( Rcpp::Named("B", B ), Rcpp::Named("M", M ), - Rcpp::Named("S", S ), + Rcpp::Named("S2", S2 ), Rcpp::Named("Z", Z ), Rcpp::Named("A", A ), Rcpp::Named("Sigma", cov_out["Sigma"]), @@ -136,7 +134,7 @@ Rcpp::List newton_optimize_impl( template Rcpp::List newton_vestep_impl( const arma::mat & Y, const arma::mat & X, const arma::mat & O, const arma::vec & w, - arma::mat M, arma::mat S, + arma::mat M, arma::mat S2, const arma::mat & B, const typename Traits::State & state, int maxiter, double ftol ) { @@ -145,8 +143,7 @@ Rcpp::List newton_vestep_impl( const arma::mat ones_row = arma::ones(n, 1); const arma::mat XB = X * B; - arma::mat psi = arma::log(S % S); // ψ = log(S²) - arma::mat S2 = arma::exp(psi); + arma::mat psi = arma::log(S2); std::vector objective_vec; double obj_prev = arma::datum::inf; @@ -199,7 +196,6 @@ Rcpp::List newton_vestep_impl( obj_prev = obj; } - S = arma::exp(0.5 * psi); const arma::mat M_res = M - XB; arma::vec loglik = Traits::final_loglik(Y, Z, A, M_res, psi, state); @@ -207,7 +203,7 @@ Rcpp::List newton_vestep_impl( Ji.attr("weights") = w; return Rcpp::List::create( Rcpp::Named("M") = M, - Rcpp::Named("S") = S, + Rcpp::Named("S2") = S2, Rcpp::Named("Ji") = Ji, Rcpp::Named("monitoring", Rcpp::List::create( Rcpp::Named("status", 3 ), diff --git a/src/newton_spherical.cpp b/src/newton_spherical.cpp index c73902b9..10814c0b 100644 --- a/src/newton_spherical.cpp +++ b/src/newton_spherical.cpp @@ -18,18 +18,17 @@ Rcpp::List newton_optimize_spherical( const arma::mat & X = Rcpp::as(data["X"]); const arma::mat & O = Rcpp::as(data["O"]); const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); const NewtonConfig cfg(config); const double w_bar = arma::accu(w); - arma::mat S2 = S % S; const arma::mat M_res_init = M - X * B; SphericalCovTraits::State state(M_res_init, S2, w, w_bar); - return newton_optimize_impl(Y, X, O, w, B, M, S, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); + return newton_optimize_impl(Y, X, O, w, B, M, S2, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); } // --------------------------------------------------------------------------------------- @@ -47,10 +46,10 @@ Rcpp::List newton_optimize_vestep_spherical( const arma::mat & X = Rcpp::as(data["X"]); const arma::mat & O = Rcpp::as(data["O"]); const arma::vec & w = Rcpp::as(data["w"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); const NewtonConfig cfg(config); SphericalCovTraits::State state(Omega); - return newton_vestep_impl(Y, X, O, w, M, S, B, state, cfg.maxiter, cfg.ftol); + return newton_vestep_impl(Y, X, O, w, M, S2, B, state, cfg.maxiter, cfg.ftol); } diff --git a/src/nlopt_diag_cov.cpp b/src/nlopt_diag_cov.cpp index 97cfcaae..db17ff07 100644 --- a/src/nlopt_diag_cov.cpp +++ b/src/nlopt_diag_cov.cpp @@ -21,16 +21,16 @@ Rcpp::List nlopt_optimize_diagonal( const arma::mat & X = Rcpp::as(data["X"]); const arma::mat & O = Rcpp::as(data["O"]); const arma::vec & w = Rcpp::as(data["w"]); - const auto init_B = Rcpp::as(params["B"]); - const auto init_M = Rcpp::as(params["M"]); - const auto init_S = Rcpp::as(params["S"]); + const auto init_B = Rcpp::as(params["B"]); + const auto init_M = Rcpp::as(params["M"]); + const auto init_S2 = Rcpp::as(params["S2"]); - const auto metadata = tuple_metadata(init_M, init_S); + const auto metadata = tuple_metadata(init_M, init_S2); enum { M_ID, S_ID }; auto parameters = std::vector(metadata.packed_size); metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = arma::log(init_S % init_S); + metadata.map(parameters.data()) = arma::log(init_S2); auto optimizer = new_nlopt_optimizer(config, parameters.size()); std::vector objective_vec; @@ -63,7 +63,6 @@ Rcpp::List nlopt_optimize_diagonal( arma::mat M = metadata.copy(parameters.data()); // M_full arma::mat logS2 = metadata.copy(parameters.data()); arma::mat S2 = arma::exp(logS2); - arma::mat S = arma::exp(0.5 * logS2); arma::mat B = P_X * M; arma::mat M_res = M - X * B; arma::rowvec sigma2 = w.t() * (M_res % M_res + S2) / w_bar; @@ -80,7 +79,7 @@ Rcpp::List nlopt_optimize_diagonal( return Rcpp::List::create( Rcpp::Named("B", B), Rcpp::Named("M", M), // M_full - Rcpp::Named("S", S), + Rcpp::Named("S2", S2), Rcpp::Named("Z", Z), Rcpp::Named("A", A), Rcpp::Named("Sigma", Sigma), @@ -110,15 +109,15 @@ Rcpp::List nlopt_optimize_vestep_diagonal( const arma::mat & X = Rcpp::as(data["X"]); // covariates (n,d) const arma::mat & O = Rcpp::as(data["O"]); // offsets (n,p) const arma::vec & w = Rcpp::as(data["w"]); // weights (n) - const auto init_M = Rcpp::as(params["M"]); // (n,p) - const auto init_S = Rcpp::as(params["S"]); // (n,p) + const auto init_M = Rcpp::as(params["M"]); // (n,p) + const auto init_S2 = Rcpp::as(params["S2"]); // (n,p) - const auto metadata = tuple_metadata(init_M, init_S); + const auto metadata = tuple_metadata(init_M, init_S2); enum { M_ID, S_ID }; // Names for metadata indexes auto parameters = std::vector(metadata.packed_size); metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = arma::log(init_S % init_S); // pack logS2 + metadata.map(parameters.data()) = arma::log(init_S2); // pack logS2 auto optimizer = new_nlopt_optimizer(config, parameters.size()); std::vector objective_vec ; @@ -147,7 +146,6 @@ Rcpp::List nlopt_optimize_vestep_diagonal( arma::mat M = metadata.copy(parameters.data()); // M_full arma::mat logS2 = metadata.copy(parameters.data()); arma::mat S2 = arma::exp(logS2); - arma::mat S = arma::exp(0.5 * logS2); arma::mat M_res = M - XB; // Element-wise log-likelihood arma::mat Z = O + M; @@ -159,8 +157,8 @@ Rcpp::List nlopt_optimize_vestep_diagonal( Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; return Rcpp::List::create( - Rcpp::Named("M") = M, - Rcpp::Named("S") = S, + Rcpp::Named("M") = M, + Rcpp::Named("S2") = S2, Rcpp::Named("Ji") = Ji, Rcpp::Named("monitoring", Rcpp::List::create( Rcpp::Named("status", static_cast(result.status)), diff --git a/src/nlopt_fixed_cov.cpp b/src/nlopt_fixed_cov.cpp index b4fec9d8..baa8a144 100644 --- a/src/nlopt_fixed_cov.cpp +++ b/src/nlopt_fixed_cov.cpp @@ -21,17 +21,17 @@ Rcpp::List nlopt_optimize_fixed( const arma::mat & X = Rcpp::as(data["X"]); const arma::mat & O = Rcpp::as(data["O"]); const arma::vec & w = Rcpp::as(data["w"]); - const auto init_B = Rcpp::as(params["B"]); - const auto init_M = Rcpp::as(params["M"]); - const auto Omega = Rcpp::as(params["Omega"]); - const auto init_S = Rcpp::as(params["S"]); + const auto init_B = Rcpp::as(params["B"]); + const auto init_M = Rcpp::as(params["M"]); + const auto Omega = Rcpp::as(params["Omega"]); + const auto init_S2 = Rcpp::as(params["S2"]); - const auto metadata = tuple_metadata(init_M, init_S); + const auto metadata = tuple_metadata(init_M, init_S2); enum { M_ID, S_ID }; auto parameters = std::vector(metadata.packed_size); metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = arma::log(init_S % init_S); + metadata.map(parameters.data()) = arma::log(init_S2); auto optimizer = new_nlopt_optimizer(config, parameters.size()); std::vector objective_vec; @@ -57,7 +57,6 @@ Rcpp::List nlopt_optimize_fixed( arma::mat M = metadata.copy(parameters.data()); // M_full arma::mat logS2 = metadata.copy(parameters.data()); arma::mat S2 = arma::exp(logS2); - arma::mat S = arma::exp(0.5 * logS2); arma::mat B = P_X * M; arma::mat M_res = M - X * B; arma::mat Sigma = (M_res.t() * (M_res.each_col() % w) + diagmat(w.t() * S2)) / accu(w); @@ -71,7 +70,7 @@ Rcpp::List nlopt_optimize_fixed( return Rcpp::List::create( Rcpp::Named("B", B), Rcpp::Named("M", M), - Rcpp::Named("S", S), + Rcpp::Named("S2", S2), Rcpp::Named("Z", Z), Rcpp::Named("A", A), Rcpp::Named("Sigma", Sigma), diff --git a/src/nlopt_full_cov.cpp b/src/nlopt_full_cov.cpp index f9437288..0ab28b7d 100644 --- a/src/nlopt_full_cov.cpp +++ b/src/nlopt_full_cov.cpp @@ -21,17 +21,17 @@ Rcpp::List nlopt_optimize_full( const arma::mat & X = Rcpp::as(data["X"]); const arma::mat & O = Rcpp::as(data["O"]); const arma::vec & w = Rcpp::as(data["w"]); - const auto init_B = Rcpp::as(params["B"]); - const auto init_M = Rcpp::as(params["M"]); - const auto init_S = Rcpp::as(params["S"]); + const auto init_B = Rcpp::as(params["B"]); + const auto init_M = Rcpp::as(params["M"]); + const auto init_S2 = Rcpp::as(params["S2"]); // Parameters: (M_full, logS2) — B is profiled out via closed form - const auto metadata = tuple_metadata(init_M, init_S); + const auto metadata = tuple_metadata(init_M, init_S2); enum { M_ID, S_ID }; auto parameters = std::vector(metadata.packed_size); metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = arma::log(init_S % init_S); + metadata.map(parameters.data()) = arma::log(init_S2); const double w_bar = accu(w); const NewtonConfig cfg(config); @@ -43,9 +43,8 @@ Rcpp::List nlopt_optimize_full( // Initial Omega: M_res = M_full - X*B arma::mat Omega; { - const arma::mat S2_init = init_S % init_S; const arma::mat M_res_init = init_M - X * init_B; - arma::mat Sigma_init = (1./w_bar) * (M_res_init.t() * (M_res_init.each_col() % w) + diagmat(w.t() * S2_init)); + arma::mat Sigma_init = (1./w_bar) * (M_res_init.t() * (M_res_init.each_col() % w) + diagmat(w.t() * init_S2)); Omega = inv_sympd(Sigma_init); } @@ -96,7 +95,6 @@ Rcpp::List nlopt_optimize_full( arma::mat M = metadata.copy(parameters.data()); // M_full arma::mat logS2 = metadata.copy(parameters.data()); arma::mat S2 = arma::exp(logS2); - arma::mat S = arma::exp(0.5 * logS2); arma::mat B = P_X * M; arma::mat M_res = M - X * B; arma::mat Sigma = (1./w_bar) * (M_res.t() * (M_res.each_col() % w) + diagmat(w.t() * S2)); @@ -110,7 +108,7 @@ Rcpp::List nlopt_optimize_full( return Rcpp::List::create( Rcpp::Named("B", B), Rcpp::Named("M", M), - Rcpp::Named("S", S), + Rcpp::Named("S2", S2), Rcpp::Named("Z", Z), Rcpp::Named("A", A), Rcpp::Named("Sigma", Sigma), @@ -141,15 +139,15 @@ Rcpp::List nlopt_optimize_vestep_full( const arma::mat & X = Rcpp::as(data["X"]); // covariates (n,d) const arma::mat & O = Rcpp::as(data["O"]); // offsets (n,p) const arma::vec & w = Rcpp::as(data["w"]); // weights (n) - const auto init_M = Rcpp::as(params["M"]); // (n,p) - const auto init_S = Rcpp::as(params["S"]); // (n,p) + const auto init_M = Rcpp::as(params["M"]); // (n,p) + const auto init_S2 = Rcpp::as(params["S2"]); // (n,p) - const auto metadata = tuple_metadata(init_M, init_S); + const auto metadata = tuple_metadata(init_M, init_S2); enum { M_ID, S_ID }; // Names for metadata indexes auto parameters = std::vector(metadata.packed_size); metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = arma::log(init_S % init_S); // pack logS2 + metadata.map(parameters.data()) = arma::log(init_S2); // pack logS2 // Optimize auto optimizer = new_nlopt_optimizer(config, parameters.size()); @@ -176,7 +174,6 @@ Rcpp::List nlopt_optimize_vestep_full( arma::mat M = metadata.copy(parameters.data()); // M_full arma::mat logS2 = metadata.copy(parameters.data()); arma::mat S2 = arma::exp(logS2); - arma::mat S = arma::exp(0.5 * logS2); arma::mat M_res = M - XB; // Element-wise log-likelihood arma::mat Z = O + M; @@ -187,8 +184,8 @@ Rcpp::List nlopt_optimize_vestep_full( Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; return Rcpp::List::create( - Rcpp::Named("M") = M, - Rcpp::Named("S") = S, + Rcpp::Named("M") = M, + Rcpp::Named("S2") = S2, Rcpp::Named("Ji") = Ji, Rcpp::Named("monitoring", Rcpp::List::create( Rcpp::Named("status", static_cast(result.status)), diff --git a/src/nlopt_spherical.cpp b/src/nlopt_spherical.cpp index 4434bd33..60a82e76 100644 --- a/src/nlopt_spherical.cpp +++ b/src/nlopt_spherical.cpp @@ -21,16 +21,16 @@ Rcpp::List nlopt_optimize_spherical( const arma::mat & X = Rcpp::as(data["X"]); const arma::mat & O = Rcpp::as(data["O"]); const arma::vec & w = Rcpp::as(data["w"]); - const auto init_B = Rcpp::as(params["B"]); - const auto init_M = Rcpp::as(params["M"]); - const auto init_S = Rcpp::as(params["S"]); + const auto init_B = Rcpp::as(params["B"]); + const auto init_M = Rcpp::as(params["M"]); + const auto init_S2 = Rcpp::as(params["S2"]); - const auto metadata = tuple_metadata(init_M, init_S); + const auto metadata = tuple_metadata(init_M, init_S2); enum { M_ID, S_ID }; auto parameters = std::vector(metadata.packed_size); metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = arma::log(init_S % init_S); + metadata.map(parameters.data()) = arma::log(init_S2); auto optimizer = new_nlopt_optimizer(config, parameters.size()); const double w_bar = accu(w); @@ -63,7 +63,6 @@ Rcpp::List nlopt_optimize_spherical( arma::mat M = metadata.copy(parameters.data()); // M_full arma::mat logS2 = metadata.copy(parameters.data()); arma::mat S2 = arma::exp(logS2); - arma::mat S = arma::exp(0.5 * logS2); arma::mat B = P_X * M; arma::mat M_res = M - X * B; const double sigma2 = accu(diagmat(w) * (pow(M_res, 2) + S2)) / (double(p) * w_bar); @@ -78,7 +77,7 @@ Rcpp::List nlopt_optimize_spherical( return Rcpp::List::create( Rcpp::Named("B", B), Rcpp::Named("M", M), - Rcpp::Named("S", S), + Rcpp::Named("S2", S2), Rcpp::Named("Z", Z), Rcpp::Named("A", A), Rcpp::Named("Sigma", Sigma), @@ -109,15 +108,15 @@ Rcpp::List nlopt_optimize_vestep_spherical( const arma::mat & X = Rcpp::as(data["X"]); // covariates (n,d) const arma::mat & O = Rcpp::as(data["O"]); // offsets (n,p) const arma::vec & w = Rcpp::as(data["w"]); // weights (n) - const auto init_M = Rcpp::as(params["M"]); // (n,p) - const auto init_S = Rcpp::as(params["S"]); // (n) + const auto init_M = Rcpp::as(params["M"]); // (n,p) + const auto init_S2 = Rcpp::as(params["S2"]); // (n,p) - const auto metadata = tuple_metadata(init_M, init_S); + const auto metadata = tuple_metadata(init_M, init_S2); enum { M_ID, S_ID }; // Names for metadata indexes auto parameters = std::vector(metadata.packed_size); metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = arma::log(init_S % init_S); // pack logS2 + metadata.map(parameters.data()) = arma::log(init_S2); // pack logS2 // Optimize auto optimizer = new_nlopt_optimizer(config, parameters.size()); @@ -148,7 +147,6 @@ Rcpp::List nlopt_optimize_vestep_spherical( arma::mat M = metadata.copy(parameters.data()); // M_full arma::mat logS2 = metadata.copy(parameters.data()); arma::mat S2 = arma::exp(logS2); - arma::mat S = arma::exp(0.5 * logS2); arma::mat M_res = M - XB; // Element-wise log-likelihood arma::mat Z = O + M; @@ -158,8 +156,8 @@ Rcpp::List nlopt_optimize_vestep_spherical( Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; return Rcpp::List::create( - Rcpp::Named("M") = M, - Rcpp::Named("S") = S, + Rcpp::Named("M") = M, + Rcpp::Named("S2") = S2, Rcpp::Named("Ji") = Ji, Rcpp::Named("monitoring", Rcpp::List::create( Rcpp::Named("status", static_cast(result.status)), From 1de7e6561b042c460291104460128fa23dc51c76 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 11:10:44 +0200 Subject: [PATCH 44/58] use S2 instead of S including in doc for PLN, ZIPLN and variantes --- R/PLNfit-class.R | 7 +- R/PLNnetworkfamily-class.R | 8 +- R/RcppExports.R | 44 ++--- R/ZIPLN.R | 2 +- R/ZIPLNfit-class.R | 103 +++++----- R/utils.R | 4 +- man/PLNPCAfit.Rd | 2 + man/PLNfit.Rd | 6 +- man/ZIPLNfit.Rd | 8 +- man/compute_PLN_starting_point.Rd | 4 +- src/RcppExports.cpp | 112 +++++------ src/optim_zi-pln.cpp | 299 ++++++++++++------------------ 12 files changed, 260 insertions(+), 339 deletions(-) diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index cfeae84f..3cd4b37e 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -397,20 +397,19 @@ PLNfit <- R6Class( #' @description #' Update a [`PLNfit`] object #' @param M matrix of variational parameters for the mean - #' @param S matrix of variational parameters for the variance + #' @param S2 matrix of variational parameters for the variance #' @param Ji vector of variational lower bounds of the log-likelihoods (one value per sample) #' @param R2 approximate R^2 goodness-of-fit criterion #' @param Z matrix of latent vectors (includes covariates and offset effects) #' @param A matrix of fitted values #' @param monitoring a list with optimization monitoring quantities #' @return Update the current [`PLNfit`] object - update = function(B=NA, Sigma=NA, Omega=NA, M=NA, S2=NA, S=NA, Ji=NA, R2=NA, Z=NA, A=NA, monitoring=NA) { + update = function(B=NA, Sigma=NA, Omega=NA, M=NA, S2=NA, Ji=NA, R2=NA, Z=NA, A=NA, monitoring=NA) { if (!identical(B, NA)) private$B <- B if (!identical(Sigma, NA)) private$Sigma <- Sigma if (!identical(Omega, NA)) private$Omega <- Omega if (!identical(M, NA)) private$M <- M if (!identical(S2, NA)) private$S2 <- S2 - if (!identical(S, NA) && identical(S2, NA)) private$S2 <- S^2 if (!identical(Z, NA)) private$Z <- Z if (!identical(A, NA)) private$A <- A if (!identical(Ji, NA)) private$Ji <- Ji @@ -431,7 +430,7 @@ PLNfit <- R6Class( do.call(self$update, optim_out) }, - #' @description Result of one call to the VE step of the optimization procedure: optimal variational parameters (M, S) and corresponding log likelihood values for fixed model parameters (Sigma, B). Intended to position new data in the latent space. + #' @description Result of one call to the VE step of the optimization procedure: optimal variational parameters (M, S2) and corresponding log likelihood values for fixed model parameters (Sigma, B). Intended to position new data in the latent space. #' @param B Optional fixed value of the regression parameters #' @param Sigma variance-covariance matrix of the latent variables #' @return A list with three components: diff --git a/R/PLNnetworkfamily-class.R b/R/PLNnetworkfamily-class.R index 87c04f46..85ae75a9 100644 --- a/R/PLNnetworkfamily-class.R +++ b/R/PLNnetworkfamily-class.R @@ -97,9 +97,9 @@ Networkfamily <- R6Class( ## Save time by starting the optimization of model m + 1 with optimal parameters of model m if (m < length(self$penalties)) self$models[[m + 1]]$update( - B = self$models[[m]]$model_par$B, - M = self$models[[m]]$var_par$M, - S = self$models[[m]]$var_par$S + B = self$models[[m]]$model_par$B, + M = self$models[[m]]$var_par$M, + S2 = self$models[[m]]$var_par$S2 ) if (config$trace > 1) { @@ -507,7 +507,7 @@ ZIPLNnetworkfamily <- R6Class( inception_$update( R = inception_$var_par$R[subsample, ], M = inception_$var_par$M[subsample, ], - S = inception_$var_par$S[subsample, ] + S2 = inception_$var_par$S2[subsample, ] ) ## force some control parameters diff --git a/R/RcppExports.R b/R/RcppExports.R index aa20d6ac..af78a57c 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -81,20 +81,20 @@ nlopt_optimize_genetic_modeling <- function(init_parameters, Y, X, O, w, C, conf .Call('_PLNmodels_nlopt_optimize_genetic_modeling', PACKAGE = 'PLNmodels', init_parameters, Y, X, O, w, C, configuration) } -zipln_vloglik <- function(Y, X, O, Pi, Omega, B, R, M, S) { - .Call('_PLNmodels_zipln_vloglik', PACKAGE = 'PLNmodels', Y, X, O, Pi, Omega, B, R, M, S) +zipln_vloglik <- function(Y, X, O, Pi, Omega, B, R, M, S2) { + .Call('_PLNmodels_zipln_vloglik', PACKAGE = 'PLNmodels', Y, X, O, Pi, Omega, B, R, M, S2) } -optim_zipln_Omega_full <- function(M, X, B, S) { - .Call('_PLNmodels_optim_zipln_Omega_full', PACKAGE = 'PLNmodels', M, X, B, S) +optim_zipln_Omega_full <- function(M, X, B, S2) { + .Call('_PLNmodels_optim_zipln_Omega_full', PACKAGE = 'PLNmodels', M, X, B, S2) } -optim_zipln_Omega_spherical <- function(M, X, B, S) { - .Call('_PLNmodels_optim_zipln_Omega_spherical', PACKAGE = 'PLNmodels', M, X, B, S) +optim_zipln_Omega_spherical <- function(M, X, B, S2) { + .Call('_PLNmodels_optim_zipln_Omega_spherical', PACKAGE = 'PLNmodels', M, X, B, S2) } -optim_zipln_Omega_diagonal <- function(M, X, B, S) { - .Call('_PLNmodels_optim_zipln_Omega_diagonal', PACKAGE = 'PLNmodels', M, X, B, S) +optim_zipln_Omega_diagonal <- function(M, X, B, S2) { + .Call('_PLNmodels_optim_zipln_Omega_diagonal', PACKAGE = 'PLNmodels', M, X, B, S2) } optim_zipln_B_dense <- function(M, X) { @@ -105,32 +105,28 @@ optim_zipln_zipar_covar <- function(R, init_B0, X0, configuration) { .Call('_PLNmodels_optim_zipln_zipar_covar', PACKAGE = 'PLNmodels', R, init_B0, X0, configuration) } -optim_zipln_R_var <- function(Y, X, O, M, S, Pi, B) { - .Call('_PLNmodels_optim_zipln_R_var', PACKAGE = 'PLNmodels', Y, X, O, M, S, Pi, B) +optim_zipln_R_var <- function(Y, X, O, M, S2, Pi, B) { + .Call('_PLNmodels_optim_zipln_R_var', PACKAGE = 'PLNmodels', Y, X, O, M, S2, Pi, B) } -optim_zipln_R_exact <- function(Y, X, O, M, S, Pi, B) { - .Call('_PLNmodels_optim_zipln_R_exact', PACKAGE = 'PLNmodels', Y, X, O, M, S, Pi, B) +optim_zipln_R_exact <- function(Y, X, O, M, S2, Pi, B) { + .Call('_PLNmodels_optim_zipln_R_exact', PACKAGE = 'PLNmodels', Y, X, O, M, S2, Pi, B) } -optim_zipln_M <- function(init_M, Y, X, O, R, S, B, Omega, configuration) { - .Call('_PLNmodels_optim_zipln_M', PACKAGE = 'PLNmodels', init_M, Y, X, O, R, S, B, Omega, configuration) +optim_zipln_M <- function(init_M, Y, X, O, R, S2, B, Omega, configuration) { + .Call('_PLNmodels_optim_zipln_M', PACKAGE = 'PLNmodels', init_M, Y, X, O, R, S2, B, Omega, configuration) } -optim_zipln_S <- function(init_S, O, M, R, B, diag_Omega, configuration) { - .Call('_PLNmodels_optim_zipln_S', PACKAGE = 'PLNmodels', init_S, O, M, R, B, diag_Omega, configuration) +optim_zipln_psi <- function(init_S2, O, M, R, B, diag_Omega, configuration) { + .Call('_PLNmodels_optim_zipln_psi', PACKAGE = 'PLNmodels', init_S2, O, M, R, B, diag_Omega, configuration) } -optim_zipln_M_S <- function(init_M, init_S, Y, X, O, R, B, Omega, configuration) { - .Call('_PLNmodels_optim_zipln_M_S', PACKAGE = 'PLNmodels', init_M, init_S, Y, X, O, R, B, Omega, configuration) +optim_zipln_M_psi <- function(init_M, init_S2, Y, X, O, R, B, Omega, configuration) { + .Call('_PLNmodels_optim_zipln_M_psi', PACKAGE = 'PLNmodels', init_M, init_S2, Y, X, O, R, B, Omega, configuration) } -optim_zipln_M_logS <- function(init_M, init_S, Y, X, O, R, B, Omega, configuration) { - .Call('_PLNmodels_optim_zipln_M_logS', PACKAGE = 'PLNmodels', init_M, init_S, Y, X, O, R, B, Omega, configuration) -} - -optim_zipln_M_S_newton <- function(init_M, init_S, Y, X, O, R, B, Omega, maxiter, ftol_rel) { - .Call('_PLNmodels_optim_zipln_M_S_newton', PACKAGE = 'PLNmodels', init_M, init_S, Y, X, O, R, B, Omega, maxiter, ftol_rel) +optim_zipln_M_psi_newton <- function(init_M, init_S2, Y, X, O, R, B, Omega, maxiter, ftol_rel) { + .Call('_PLNmodels_optim_zipln_M_psi_newton', PACKAGE = 'PLNmodels', init_M, init_S2, Y, X, O, R, B, Omega, maxiter, ftol_rel) } cpp_test_packing <- function() { diff --git a/R/ZIPLN.R b/R/ZIPLN.R index d7027f0f..a2900402 100644 --- a/R/ZIPLN.R +++ b/R/ZIPLN.R @@ -107,7 +107,7 @@ ZIPLN_param <- function( ## optimization config stopifnot(backend %in% c("nlopt")) algo_req <- if (!is.null(config_optim$algorithm)) config_optim$algorithm else "CCSAQ" - stopifnot(algo_req %in% available_algorithms_nlopt) + stopifnot(algo_req %in% c(available_algorithms_nlopt, "NEWTON", "SPLIT")) config_opt <- config_default_nlopt config_opt$algorithm <- algo_req config_opt$trace <- trace diff --git a/R/ZIPLNfit-class.R b/R/ZIPLNfit-class.R index 6721ccde..b0224da8 100644 --- a/R/ZIPLNfit-class.R +++ b/R/ZIPLNfit-class.R @@ -44,25 +44,25 @@ ZIPLNfit <- R6Class( #' @param Omega precision matrix of the latent variables #' @param Sigma covariance matrix of the latent variables #' @param M matrix of mean vectors for the variational approximation - #' @param S matrix of standard deviation parameters for the variational approximation + #' @param S2 matrix of variance parameters for the variational approximation #' @param R matrix of probabilities for the variational approximation #' @param Ji vector of variational lower bounds of the log-likelihoods (one value per sample) #' @param Z matrix of latent vectors (includes covariates and offset effects) #' @param A matrix of fitted values #' @param monitoring a list with optimization monitoring quantities #' @return Update the current [`ZIPLNfit`] object - update = function(B=NA, B0=NA, Pi=NA, Omega=NA, Sigma=NA, M=NA, S=NA, R=NA, Ji=NA, Z=NA, A=NA, monitoring=NA) { - if (!anyNA(B)) private$B <- B - if (!anyNA(B0)) private$B0 <- B0 - if (!anyNA(Pi)) private$Pi <- Pi - if (!anyNA(Omega)) private$Omega <- Omega - if (!anyNA(Sigma)) private$Sigma <- Sigma - if (!anyNA(M)) private$M <- M - if (!anyNA(S)) private$S <- S - if (!anyNA(R)) private$R <- R - if (!anyNA(Z)) private$Z <- Z - if (!anyNA(A)) private$A <- A - if (!anyNA(Ji)) private$Ji <- Ji + update = function(B=NA, B0=NA, Pi=NA, Omega=NA, Sigma=NA, M=NA, S2=NA, R=NA, Ji=NA, Z=NA, A=NA, monitoring=NA) { + if (!anyNA(B)) private$B <- B + if (!anyNA(B0)) private$B0 <- B0 + if (!anyNA(Pi)) private$Pi <- Pi + if (!anyNA(Omega)) private$Omega <- Omega + if (!anyNA(Sigma)) private$Sigma <- Sigma + if (!anyNA(M)) private$M <- M + if (!identical(S2, NA)) private$S2 <- S2 + if (!anyNA(R)) private$R <- R + if (!anyNA(Z)) private$Z <- Z + if (!anyNA(A)) private$A <- A + if (!anyNA(Ji)) private$Ji <- Ji if (!anyNA(monitoring)) private$monitoring <- monitoring }, @@ -84,7 +84,7 @@ ZIPLNfit <- R6Class( if (isZIPLNfit(control$inception)) { private$R <- control$inception$var_par$R private$M <- control$inception$var_par$M - private$S <- control$inception$var_par$S + private$S2 <- control$inception$var_par$S2 private$B <- control$inception$model_par$B private$B0 <- control$inception$model_par$B0 } else { @@ -122,7 +122,7 @@ ZIPLNfit <- R6Class( ## Initialization of the PLN component private$B <- B private$M <- M - private$S <- matrix(.1, n, p) + private$S2 <- matrix(.01, n, p) } private$Pi <- switch(control$ziparam, "single" = matrix( mean(private$R), n, p) , @@ -148,10 +148,18 @@ ZIPLNfit <- R6Class( private$optimizer$MS <- if (identical(control$config_optim$algorithm, "NEWTON")) { ftol <- if (!is.null(control$config_optim$ftol_rel)) control$config_optim$ftol_rel else 1e-8 maxiter <- as.integer(if (!is.null(control$config_optim$maxeval)) control$config_optim$maxeval else 200L) - function(init_M, init_S, Y, X, O, R, B, Omega, configuration) - optim_zipln_M_S_newton(init_M, init_S, Y, X, O, R, B, Omega, maxiter, ftol) + function(init_M, init_S2, Y, X, O, R, B, Omega, configuration) + optim_zipln_M_psi_newton(init_M, init_S2, Y, X, O, R, B, Omega, maxiter, ftol) + } else if (identical(control$config_optim$algorithm, "SPLIT")) { + # Separate M then ψ=log(S²) optimization via nlopt/CCSAQ + function(init_M, init_S2, Y, X, O, R, B, Omega, configuration) { + config_sub <- modifyList(configuration, list(algorithm = "CCSAQ")) + out_M <- optim_zipln_M(init_M, Y, X, O, R, init_S2, B, Omega, config_sub) + out_psi <- optim_zipln_psi(init_S2, O, out_M$M, R, B, diag(Omega), config_sub) + list(M = out_M$M, S2 = out_psi$S2) + } } else { - optim_zipln_M_S + optim_zipln_M_psi } }, @@ -162,7 +170,7 @@ ZIPLNfit <- R6Class( parameters <- list(Omega = NA, B0 = private$B0, B = private$B, Pi = private$Pi, - M = private$M, S = private$S, R = private$R) + M = private$M, S2 = private$S2, R = private$R) # Outer loop nb_iter <- 0 @@ -182,7 +190,7 @@ ZIPLNfit <- R6Class( ### M Step # PLN part new_Omega <- private$optimizer$Omega( - M = parameters$M, X = data$X, B = parameters$B, S = parameters$S + M = parameters$M, X = data$X, B = parameters$B, S2 = parameters$S2 ) new_B <- private$optimizer$B( M = parameters$M, X = data$X @@ -197,26 +205,26 @@ ZIPLNfit <- R6Class( ### VE Step # ZI part - new_R <- private$optimizer$R(Y = data$Y, X = data$X, O = data$O, M = parameters$M, S = parameters$S, Pi = new_Pi, B = new_B) + new_R <- private$optimizer$R(Y = data$Y, X = data$X, O = data$O, M = parameters$M, S2 = parameters$S2, Pi = new_Pi, B = new_B) - # PLN part: joint optimization of M and S + # PLN part: joint optimization of M and ψ=log(S²) MS_out <- private$optimizer$MS( - init_M = parameters$M, init_S = parameters$S, + init_M = parameters$M, init_S2 = parameters$S2, Y = data$Y, X = data$X, O = data$O, R = new_R, B = new_B, Omega = new_Omega, configuration = control ) - new_M <- MS_out$M - new_S <- MS_out$S + new_M <- MS_out$M + new_S2 <- MS_out$S2 # Check convergence new_parameters <- list( Omega = new_Omega, B = new_B, B0 = new_B0, Pi = new_Pi, - R = new_R, M = new_M, S = new_S + R = new_R, M = new_M, S2 = new_S2 ) nb_iter <- nb_iter + 1 vloglik <- zipln_vloglik( - data$Y, data$X, data$O, new_Pi, new_Omega, new_B, new_R, new_M, new_S + data$Y, data$X, data$O, new_Pi, new_Omega, new_B, new_R, new_M, new_S2 ) criterion[nb_iter] <- new_objective <- -sum(vloglik) @@ -250,10 +258,10 @@ ZIPLNfit <- R6Class( Omega = parameters$Omega, Sigma = tryCatch(Matrix::solve(symmpart(parameters$Omega)), error = function(e) {e}), M = parameters$M, - S = parameters$S, + S2 = parameters$S2, R = parameters$R, Z = data$O + parameters$M, - A = exp(data$O + parameters$M + .5 * parameters$S^2), + A = exp(data$O + parameters$M + .5 * parameters$S2), Ji = vloglik, monitoring = list( iterations = nb_iter, @@ -270,17 +278,17 @@ ZIPLNfit <- R6Class( rownames(private$B0) <- colnames(data$X0) rownames(private$Omega) <- colnames(private$Omega) <- colnames(private$Pi) <- colnames_Y dimnames(private$Sigma) <- dimnames(private$Omega) - rownames(private$M) <- rownames(private$S) <- rownames(private$R) <- rownames(private$Pi) <- rownames(data$Y) + rownames(private$M) <- rownames(private$S2) <- rownames(private$R) <- rownames(private$Pi) <- rownames(data$Y) }, - #' @description Result of one call to the VE step of the optimization procedure: optimal variational parameters (M, S, R) and corresponding log likelihood values for fixed model parameters (Sigma, B, B0). Intended to position new data in the latent space. + #' @description Result of one call to the VE step of the optimization procedure: optimal variational parameters (M, S2, R) and corresponding log likelihood values for fixed model parameters (Sigma, B, B0). Intended to position new data in the latent space. #' @param B Optional fixed value of the regression parameters in the PLN component #' @param B0 Optional fixed value of the regression parameters in the ZI component #' @param Omega inverse variance-covariance matrix of the latent variables #' @return A list with three components: #' * the matrix `M` of variational means, - #' * the matrix `S` of variational standard deviations + #' * the matrix `S2` of variational variances #' * the matrix `R` of variational ZI probabilities #' * the vector `Ji` of (variational) log-likelihood of each new observation #' * a list `monitoring` with information about convergence status @@ -291,7 +299,7 @@ ZIPLNfit <- R6Class( control = ZIPLN_param(backend = "nlopt")$config_optim) { n <- nrow(data$Y) parameters <- - list(M = matrix(0, n, self$p), S = matrix(0.1, n, self$p), R = matrix(0, n, self$p)) + list(M = matrix(0, n, self$p), S2 = matrix(.01, n, self$p), R = matrix(0, n, self$p)) # Outer loop nb_iter <- 0 @@ -316,21 +324,21 @@ ZIPLNfit <- R6Class( # VE Step new_R <- private$optimizer$R( - Y = data$Y, X = data$X, O = data$O, M = parameters$M, S = parameters$S, Pi = Pi, B = B + Y = data$Y, X = data$X, O = data$O, M = parameters$M, S2 = parameters$S2, Pi = Pi, B = B ) MS_out <- private$optimizer$MS( - init_M = parameters$M, init_S = parameters$S, + init_M = parameters$M, init_S2 = parameters$S2, Y = data$Y, X = data$X, O = data$O, R = new_R, B = B, Omega = Omega, configuration = control ) - new_M <- MS_out$M - new_S <- MS_out$S + new_M <- MS_out$M + new_S2 <- MS_out$S2 # Check convergence - new_parameters <- list(R = new_R, M = new_M, S = new_S) + new_parameters <- list(R = new_R, M = new_M, S2 = new_S2) nb_iter <- nb_iter + 1 vloglik <- zipln_vloglik( - data$Y, data$X, data$O, Pi, Omega, B, new_R, new_M, new_S + data$Y, data$X, data$O, Pi, Omega, B, new_R, new_M, new_S2 ) criterion[nb_iter] <- new_objective <- -sum(vloglik) @@ -361,7 +369,8 @@ ZIPLNfit <- R6Class( list( M = parameters$M, - S = parameters$S, + S2 = parameters$S2, + S = sqrt(parameters$S2), R = parameters$R, Ji = vloglik, monitoring = list( @@ -436,7 +445,7 @@ ZIPLNfit <- R6Class( ) R <- VE$R M <- VE$M - S2 <- VE$S^2 + S2 <- VE$S2 } else { # otherwise set R to Pi, M to XB and S2 to diag(Sigma) R <- private$Pi[1:nrow(newdata), ] @@ -495,7 +504,7 @@ ZIPLNfit <- R6Class( Pi = NA, # the probability parameters for the ZI part Omega = NA, # the precision matrix Sigma = NA, # the covariance matrix - S = NA, # the variational parameters for the standard deviations + S2 = NA, # the variational parameters for the variance M = NA, # the variational parameters for the means Z = NA, # the matrix of latent variable P = NA, # the matrix of latent variable without covariates effect @@ -541,7 +550,7 @@ ZIPLNfit <- R6Class( #' @field model_par a list with the matrices of parameters found in the model (B, Sigma, plus some others depending on the variant) model_par = function() {list(B = private$B, B0 = private$B0, Pi = private$Pi, Omega = private$Omega, Sigma = private$Sigma)}, #' @field var_par a list with two matrices, M and S2, which are the estimated parameters in the variational approximation - var_par = function() {list(M = private$M, S2 = private$S^2, S = private$S, R = private$R)}, + var_par = function() {list(M = private$M, S2 = private$S2, S = sqrt(private$S2), R = private$R)}, #' @field optim_par a list with parameters useful for monitoring the optimization optim_par = function() {private$monitoring}, #' @field latent a matrix: values of the latent vector (Z in the model) @@ -567,7 +576,7 @@ ZIPLNfit <- R6Class( #' @field entropy_ZI Entropy of the variational distribution entropy_ZI = function() {-sum(.xlogx(1 - private$R)) - sum(.xlogx(private$R))}, #' @field entropy_PLN Entropy of the Gaussian variational distribution in the PLN component - entropy_PLN = function() {.5 * (self$n * self$p * log(2*pi*exp(1)) + sum(log(private$S^2)))}, + entropy_PLN = function() {.5 * (self$n * self$p * log(2*pi*exp(1)) + sum(log(private$S2)))}, #' @field ICL variational lower bound of the ICL ICL = function() {self$BIC - self$entropy}, #' @field criteria a vector with loglik, BIC, ICL and number of parameters @@ -702,7 +711,7 @@ ZIPLNfit_fixed <- R6Class( initialize = function(data, control) { super$initialize(data, control) private$Omega <- control$Omega - private$optimizer$Omega <- function(M, X, B, S) {private$Omega} + private$optimizer$Omega <- function(M, X, B, S2) {private$Omega} } ), active = list( @@ -766,8 +775,8 @@ ZIPLNfit_sparse <- R6Class( private$lambda <- control$penalty private$rho <- control$penalty_weights private$optimizer$Omega <- - function(M, X, B, S) { - glassoFast( crossprod(M - X %*% B)/self$n + diag(colMeans(S * S), self$p, self$p), + function(M, X, B, S2) { + glassoFast( crossprod(M - X %*% B)/self$n + diag(colMeans(S2), self$p, self$p), rho = private$lambda * private$rho )$wi } }, diff --git a/R/utils.R b/R/utils.R index 6c17bc59..a23fe504 100644 --- a/R/utils.R +++ b/R/utils.R @@ -315,7 +315,7 @@ create_parameters <- function( #' Helper function for PLN initialization. #' #' @description -#' Barebone function to compute starting points for B, M and S when fitting a PLN. Mostly intended for internal use. +#' Barebone function to compute starting points for B, M and S2 when fitting a PLN. Mostly intended for internal use. #' #' @param Y Response count matrix #' @param X Covariate matrix. Note that initialization will fail if the model matrix is singular. @@ -324,7 +324,7 @@ create_parameters <- function( #' @param method character: strategy used to initialize B. Either `"LM"` (default, fast weighted #' log-linear regression) or `"GLM"` (p independent Poisson GLMs, more accurate for complex #' or unbalanced designs but slower). -#' @return a named list of starting values for model parameter B and variational parameters M and S used in the iterative optimization algorithm of [PLN()] +#' @return a named list of starting values for model parameter B and variational parameters M and S2 used in the iterative optimization algorithm of [PLN()] #' #' @details #' * **B**: estimated by weighted LM (`method = "LM"`, default) or p independent Poisson GLMs diff --git a/man/PLNPCAfit.Rd b/man/PLNPCAfit.Rd index fc47e2d0..8e433ff8 100644 --- a/man/PLNPCAfit.Rd +++ b/man/PLNPCAfit.Rd @@ -25,6 +25,8 @@ The function \code{\link{PLNPCA}}, the class \code{\link[=PLNPCAfamily]{PLNPCAfa \section{Active bindings}{ \if{html}{\out{

}} \describe{ + \item{\code{var_par}}{variational parameters (M, S, S2) in the rank-q latent space} + \item{\code{rank}}{the dimension of the current model} \item{\code{vcov_model}}{character: the model used for the residual covariance} diff --git a/man/PLNfit.Rd b/man/PLNfit.Rd index 2deff67d..c2c1d1e4 100644 --- a/man/PLNfit.Rd +++ b/man/PLNfit.Rd @@ -121,7 +121,7 @@ print(myPLN) Sigma = NA, Omega = NA, M = NA, - S = NA, + S2 = NA, Ji = NA, R2 = NA, Z = NA, @@ -137,7 +137,7 @@ print(myPLN) \item{\code{Sigma}}{variance-covariance matrix of the latent variables} \item{\code{Omega}}{precision matrix of the latent variables. Inverse of Sigma.} \item{\code{M}}{matrix of variational parameters for the mean} - \item{\code{S}}{matrix of variational parameters for the variance} + \item{\code{S2}}{matrix of variational parameters for the variance} \item{\code{Ji}}{vector of variational lower bounds of the log-likelihoods (one value per sample)} \item{\code{R2}}{approximate R^2 goodness-of-fit criterion} \item{\code{Z}}{matrix of latent vectors (includes covariates and offset effects)} @@ -178,7 +178,7 @@ print(myPLN) \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNfit-optimize_vestep}{}}} \subsection{\code{PLNfit$optimize_vestep()}}{ - Result of one call to the VE step of the optimization procedure: optimal variational parameters (M, S) and corresponding log likelihood values for fixed model parameters (Sigma, B). Intended to position new data in the latent space. + Result of one call to the VE step of the optimization procedure: optimal variational parameters (M, S2) and corresponding log likelihood values for fixed model parameters (Sigma, B). Intended to position new data in the latent space. \subsection{Usage}{ \if{html}{\out{
}} \preformatted{PLNfit$optimize_vestep( diff --git a/man/ZIPLNfit.Rd b/man/ZIPLNfit.Rd index 6556fec0..dafc7b8b 100644 --- a/man/ZIPLNfit.Rd +++ b/man/ZIPLNfit.Rd @@ -109,7 +109,7 @@ print(myPLN) Omega = NA, Sigma = NA, M = NA, - S = NA, + S2 = NA, R = NA, Ji = NA, Z = NA, @@ -127,7 +127,7 @@ print(myPLN) \item{\code{Omega}}{precision matrix of the latent variables} \item{\code{Sigma}}{covariance matrix of the latent variables} \item{\code{M}}{matrix of mean vectors for the variational approximation} - \item{\code{S}}{matrix of standard deviation parameters for the variational approximation} + \item{\code{S2}}{matrix of variance parameters for the variational approximation} \item{\code{R}}{matrix of probabilities for the variational approximation} \item{\code{Ji}}{vector of variational lower bounds of the log-likelihoods (one value per sample)} \item{\code{Z}}{matrix of latent vectors (includes covariates and offset effects)} @@ -185,7 +185,7 @@ print(myPLN) \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-ZIPLNfit-optimize_vestep}{}}} \subsection{\code{ZIPLNfit$optimize_vestep()}}{ - Result of one call to the VE step of the optimization procedure: optimal variational parameters (M, S, R) and corresponding log likelihood values for fixed model parameters (Sigma, B, B0). Intended to position new data in the latent space. + Result of one call to the VE step of the optimization procedure: optimal variational parameters (M, S2, R) and corresponding log likelihood values for fixed model parameters (Sigma, B, B0). Intended to position new data in the latent space. \subsection{Usage}{ \if{html}{\out{
}} \preformatted{ZIPLNfit$optimize_vestep( @@ -212,7 +212,7 @@ print(myPLN) A list with three components: \itemize{ \item the matrix \code{M} of variational means, -\item the matrix \code{S} of variational standard deviations +\item the matrix \code{S2} of variational variances \item the matrix \code{R} of variational ZI probabilities \item the vector \code{Ji} of (variational) log-likelihood of each new observation \item a list \code{monitoring} with information about convergence status diff --git a/man/compute_PLN_starting_point.Rd b/man/compute_PLN_starting_point.Rd index 61a83f5e..1b047a7e 100644 --- a/man/compute_PLN_starting_point.Rd +++ b/man/compute_PLN_starting_point.Rd @@ -20,10 +20,10 @@ log-linear regression) or \code{"GLM"} (p independent Poisson GLMs, more accurat or unbalanced designs but slower).} } \value{ -a named list of starting values for model parameter B and variational parameters M and S used in the iterative optimization algorithm of \code{\link[=PLN]{PLN()}} +a named list of starting values for model parameter B and variational parameters M and S2 used in the iterative optimization algorithm of \code{\link[=PLN]{PLN()}} } \description{ -Barebone function to compute starting points for B, M and S when fitting a PLN. Mostly intended for internal use. +Barebone function to compute starting points for B, M and S2 when fitting a PLN. Mostly intended for internal use. } \details{ \itemize{ diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 87df22b0..6916c65d 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -289,8 +289,8 @@ BEGIN_RCPP END_RCPP } // zipln_vloglik -arma::vec zipln_vloglik(const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& Pi, const arma::mat& Omega, const arma::mat& B, const arma::mat& R, const arma::mat& M, const arma::mat& S); -RcppExport SEXP _PLNmodels_zipln_vloglik(SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP PiSEXP, SEXP OmegaSEXP, SEXP BSEXP, SEXP RSEXP, SEXP MSEXP, SEXP SSEXP) { +arma::vec zipln_vloglik(const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& Pi, const arma::mat& Omega, const arma::mat& B, const arma::mat& R, const arma::mat& M, const arma::mat& S2); +RcppExport SEXP _PLNmodels_zipln_vloglik(SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP PiSEXP, SEXP OmegaSEXP, SEXP BSEXP, SEXP RSEXP, SEXP MSEXP, SEXP S2SEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; @@ -302,50 +302,50 @@ BEGIN_RCPP Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type R(RSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type M(MSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type S(SSEXP); - rcpp_result_gen = Rcpp::wrap(zipln_vloglik(Y, X, O, Pi, Omega, B, R, M, S)); + Rcpp::traits::input_parameter< const arma::mat& >::type S2(S2SEXP); + rcpp_result_gen = Rcpp::wrap(zipln_vloglik(Y, X, O, Pi, Omega, B, R, M, S2)); return rcpp_result_gen; END_RCPP } // optim_zipln_Omega_full -arma::mat optim_zipln_Omega_full(const arma::mat& M, const arma::mat& X, const arma::mat& B, const arma::mat& S); -RcppExport SEXP _PLNmodels_optim_zipln_Omega_full(SEXP MSEXP, SEXP XSEXP, SEXP BSEXP, SEXP SSEXP) { +arma::mat optim_zipln_Omega_full(const arma::mat& M, const arma::mat& X, const arma::mat& B, const arma::mat& S2); +RcppExport SEXP _PLNmodels_optim_zipln_Omega_full(SEXP MSEXP, SEXP XSEXP, SEXP BSEXP, SEXP S2SEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::mat& >::type M(MSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type S(SSEXP); - rcpp_result_gen = Rcpp::wrap(optim_zipln_Omega_full(M, X, B, S)); + Rcpp::traits::input_parameter< const arma::mat& >::type S2(S2SEXP); + rcpp_result_gen = Rcpp::wrap(optim_zipln_Omega_full(M, X, B, S2)); return rcpp_result_gen; END_RCPP } // optim_zipln_Omega_spherical -arma::mat optim_zipln_Omega_spherical(const arma::mat& M, const arma::mat& X, const arma::mat& B, const arma::mat& S); -RcppExport SEXP _PLNmodels_optim_zipln_Omega_spherical(SEXP MSEXP, SEXP XSEXP, SEXP BSEXP, SEXP SSEXP) { +arma::mat optim_zipln_Omega_spherical(const arma::mat& M, const arma::mat& X, const arma::mat& B, const arma::mat& S2); +RcppExport SEXP _PLNmodels_optim_zipln_Omega_spherical(SEXP MSEXP, SEXP XSEXP, SEXP BSEXP, SEXP S2SEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::mat& >::type M(MSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type S(SSEXP); - rcpp_result_gen = Rcpp::wrap(optim_zipln_Omega_spherical(M, X, B, S)); + Rcpp::traits::input_parameter< const arma::mat& >::type S2(S2SEXP); + rcpp_result_gen = Rcpp::wrap(optim_zipln_Omega_spherical(M, X, B, S2)); return rcpp_result_gen; END_RCPP } // optim_zipln_Omega_diagonal -arma::mat optim_zipln_Omega_diagonal(const arma::mat& M, const arma::mat& X, const arma::mat& B, const arma::mat& S); -RcppExport SEXP _PLNmodels_optim_zipln_Omega_diagonal(SEXP MSEXP, SEXP XSEXP, SEXP BSEXP, SEXP SSEXP) { +arma::mat optim_zipln_Omega_diagonal(const arma::mat& M, const arma::mat& X, const arma::mat& B, const arma::mat& S2); +RcppExport SEXP _PLNmodels_optim_zipln_Omega_diagonal(SEXP MSEXP, SEXP XSEXP, SEXP BSEXP, SEXP S2SEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::mat& >::type M(MSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type S(SSEXP); - rcpp_result_gen = Rcpp::wrap(optim_zipln_Omega_diagonal(M, X, B, S)); + Rcpp::traits::input_parameter< const arma::mat& >::type S2(S2SEXP); + rcpp_result_gen = Rcpp::wrap(optim_zipln_Omega_diagonal(M, X, B, S2)); return rcpp_result_gen; END_RCPP } @@ -376,8 +376,8 @@ BEGIN_RCPP END_RCPP } // optim_zipln_R_var -arma::mat optim_zipln_R_var(const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& M, const arma::mat& S, const arma::mat& Pi, const arma::mat& B); -RcppExport SEXP _PLNmodels_optim_zipln_R_var(SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP MSEXP, SEXP SSEXP, SEXP PiSEXP, SEXP BSEXP) { +arma::mat optim_zipln_R_var(const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& M, const arma::mat& S2, const arma::mat& Pi, const arma::mat& B); +RcppExport SEXP _PLNmodels_optim_zipln_R_var(SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP MSEXP, SEXP S2SEXP, SEXP PiSEXP, SEXP BSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; @@ -385,16 +385,16 @@ BEGIN_RCPP Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type O(OSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type M(MSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type S(SSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type S2(S2SEXP); Rcpp::traits::input_parameter< const arma::mat& >::type Pi(PiSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - rcpp_result_gen = Rcpp::wrap(optim_zipln_R_var(Y, X, O, M, S, Pi, B)); + rcpp_result_gen = Rcpp::wrap(optim_zipln_R_var(Y, X, O, M, S2, Pi, B)); return rcpp_result_gen; END_RCPP } // optim_zipln_R_exact -arma::mat optim_zipln_R_exact(const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& M, const arma::mat& S, const arma::mat& Pi, const arma::mat& B); -RcppExport SEXP _PLNmodels_optim_zipln_R_exact(SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP MSEXP, SEXP SSEXP, SEXP PiSEXP, SEXP BSEXP) { +arma::mat optim_zipln_R_exact(const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& M, const arma::mat& S2, const arma::mat& Pi, const arma::mat& B); +RcppExport SEXP _PLNmodels_optim_zipln_R_exact(SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP MSEXP, SEXP S2SEXP, SEXP PiSEXP, SEXP BSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; @@ -402,16 +402,16 @@ BEGIN_RCPP Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type O(OSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type M(MSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type S(SSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type S2(S2SEXP); Rcpp::traits::input_parameter< const arma::mat& >::type Pi(PiSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - rcpp_result_gen = Rcpp::wrap(optim_zipln_R_exact(Y, X, O, M, S, Pi, B)); + rcpp_result_gen = Rcpp::wrap(optim_zipln_R_exact(Y, X, O, M, S2, Pi, B)); return rcpp_result_gen; END_RCPP } // optim_zipln_M -Rcpp::List optim_zipln_M(const arma::mat& init_M, const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& R, const arma::mat& S, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& configuration); -RcppExport SEXP _PLNmodels_optim_zipln_M(SEXP init_MSEXP, SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP RSEXP, SEXP SSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configurationSEXP) { +Rcpp::List optim_zipln_M(const arma::mat& init_M, const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& R, const arma::mat& S2, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& configuration); +RcppExport SEXP _PLNmodels_optim_zipln_M(SEXP init_MSEXP, SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP RSEXP, SEXP S2SEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configurationSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; @@ -420,58 +420,39 @@ BEGIN_RCPP Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type O(OSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type R(RSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type S(SSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type S2(S2SEXP); Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type configuration(configurationSEXP); - rcpp_result_gen = Rcpp::wrap(optim_zipln_M(init_M, Y, X, O, R, S, B, Omega, configuration)); + rcpp_result_gen = Rcpp::wrap(optim_zipln_M(init_M, Y, X, O, R, S2, B, Omega, configuration)); return rcpp_result_gen; END_RCPP } -// optim_zipln_S -Rcpp::List optim_zipln_S(const arma::mat& init_S, const arma::mat& O, const arma::mat& M, const arma::mat& R, const arma::mat& B, const arma::vec& diag_Omega, const Rcpp::List& configuration); -RcppExport SEXP _PLNmodels_optim_zipln_S(SEXP init_SSEXP, SEXP OSEXP, SEXP MSEXP, SEXP RSEXP, SEXP BSEXP, SEXP diag_OmegaSEXP, SEXP configurationSEXP) { +// optim_zipln_psi +Rcpp::List optim_zipln_psi(const arma::mat& init_S2, const arma::mat& O, const arma::mat& M, const arma::mat& R, const arma::mat& B, const arma::vec& diag_Omega, const Rcpp::List& configuration); +RcppExport SEXP _PLNmodels_optim_zipln_psi(SEXP init_S2SEXP, SEXP OSEXP, SEXP MSEXP, SEXP RSEXP, SEXP BSEXP, SEXP diag_OmegaSEXP, SEXP configurationSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const arma::mat& >::type init_S(init_SSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type init_S2(init_S2SEXP); Rcpp::traits::input_parameter< const arma::mat& >::type O(OSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type M(MSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type R(RSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); Rcpp::traits::input_parameter< const arma::vec& >::type diag_Omega(diag_OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type configuration(configurationSEXP); - rcpp_result_gen = Rcpp::wrap(optim_zipln_S(init_S, O, M, R, B, diag_Omega, configuration)); - return rcpp_result_gen; -END_RCPP -} -// optim_zipln_M_S -Rcpp::List optim_zipln_M_S(const arma::mat& init_M, const arma::mat& init_S, const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& R, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& configuration); -RcppExport SEXP _PLNmodels_optim_zipln_M_S(SEXP init_MSEXP, SEXP init_SSEXP, SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP RSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configurationSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const arma::mat& >::type init_M(init_MSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type init_S(init_SSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type Y(YSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type O(OSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type R(RSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type configuration(configurationSEXP); - rcpp_result_gen = Rcpp::wrap(optim_zipln_M_S(init_M, init_S, Y, X, O, R, B, Omega, configuration)); + rcpp_result_gen = Rcpp::wrap(optim_zipln_psi(init_S2, O, M, R, B, diag_Omega, configuration)); return rcpp_result_gen; END_RCPP } -// optim_zipln_M_logS -Rcpp::List optim_zipln_M_logS(const arma::mat& init_M, const arma::mat& init_S, const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& R, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& configuration); -RcppExport SEXP _PLNmodels_optim_zipln_M_logS(SEXP init_MSEXP, SEXP init_SSEXP, SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP RSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configurationSEXP) { +// optim_zipln_M_psi +Rcpp::List optim_zipln_M_psi(const arma::mat& init_M, const arma::mat& init_S2, const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& R, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& configuration); +RcppExport SEXP _PLNmodels_optim_zipln_M_psi(SEXP init_MSEXP, SEXP init_S2SEXP, SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP RSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configurationSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::mat& >::type init_M(init_MSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type init_S(init_SSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type init_S2(init_S2SEXP); Rcpp::traits::input_parameter< const arma::mat& >::type Y(YSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type O(OSEXP); @@ -479,18 +460,18 @@ BEGIN_RCPP Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type configuration(configurationSEXP); - rcpp_result_gen = Rcpp::wrap(optim_zipln_M_logS(init_M, init_S, Y, X, O, R, B, Omega, configuration)); + rcpp_result_gen = Rcpp::wrap(optim_zipln_M_psi(init_M, init_S2, Y, X, O, R, B, Omega, configuration)); return rcpp_result_gen; END_RCPP } -// optim_zipln_M_S_newton -Rcpp::List optim_zipln_M_S_newton(const arma::mat& init_M, const arma::mat& init_S, const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& R, const arma::mat& B, const arma::mat& Omega, const int maxiter, const double ftol_rel); -RcppExport SEXP _PLNmodels_optim_zipln_M_S_newton(SEXP init_MSEXP, SEXP init_SSEXP, SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP RSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP maxiterSEXP, SEXP ftol_relSEXP) { +// optim_zipln_M_psi_newton +Rcpp::List optim_zipln_M_psi_newton(const arma::mat& init_M, const arma::mat& init_S2, const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& R, const arma::mat& B, const arma::mat& Omega, const int maxiter, const double ftol_rel); +RcppExport SEXP _PLNmodels_optim_zipln_M_psi_newton(SEXP init_MSEXP, SEXP init_S2SEXP, SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP RSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP maxiterSEXP, SEXP ftol_relSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const arma::mat& >::type init_M(init_MSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type init_S(init_SSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type init_S2(init_S2SEXP); Rcpp::traits::input_parameter< const arma::mat& >::type Y(YSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type O(OSEXP); @@ -499,7 +480,7 @@ BEGIN_RCPP Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const double >::type ftol_rel(ftol_relSEXP); - rcpp_result_gen = Rcpp::wrap(optim_zipln_M_S_newton(init_M, init_S, Y, X, O, R, B, Omega, maxiter, ftol_rel)); + rcpp_result_gen = Rcpp::wrap(optim_zipln_M_psi_newton(init_M, init_S2, Y, X, O, R, B, Omega, maxiter, ftol_rel)); return rcpp_result_gen; END_RCPP } @@ -588,10 +569,9 @@ static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_optim_zipln_R_var", (DL_FUNC) &_PLNmodels_optim_zipln_R_var, 7}, {"_PLNmodels_optim_zipln_R_exact", (DL_FUNC) &_PLNmodels_optim_zipln_R_exact, 7}, {"_PLNmodels_optim_zipln_M", (DL_FUNC) &_PLNmodels_optim_zipln_M, 9}, - {"_PLNmodels_optim_zipln_S", (DL_FUNC) &_PLNmodels_optim_zipln_S, 7}, - {"_PLNmodels_optim_zipln_M_S", (DL_FUNC) &_PLNmodels_optim_zipln_M_S, 9}, - {"_PLNmodels_optim_zipln_M_logS", (DL_FUNC) &_PLNmodels_optim_zipln_M_logS, 9}, - {"_PLNmodels_optim_zipln_M_S_newton", (DL_FUNC) &_PLNmodels_optim_zipln_M_S_newton, 10}, + {"_PLNmodels_optim_zipln_psi", (DL_FUNC) &_PLNmodels_optim_zipln_psi, 7}, + {"_PLNmodels_optim_zipln_M_psi", (DL_FUNC) &_PLNmodels_optim_zipln_M_psi, 9}, + {"_PLNmodels_optim_zipln_M_psi_newton", (DL_FUNC) &_PLNmodels_optim_zipln_M_psi_newton, 10}, {"_PLNmodels_cpp_test_packing", (DL_FUNC) &_PLNmodels_cpp_test_packing, 0}, {"_PLNmodels_spectral_optimize_rank", (DL_FUNC) &_PLNmodels_spectral_optimize_rank, 3}, {"_PLNmodels_spectral_optimize_vestep_rank", (DL_FUNC) &_PLNmodels_spectral_optimize_vestep_rank, 5}, diff --git a/src/optim_zi-pln.cpp b/src/optim_zi-pln.cpp index 73dd1312..658961b4 100644 --- a/src/optim_zi-pln.cpp +++ b/src/optim_zi-pln.cpp @@ -11,6 +11,9 @@ #include "utils.h" #include "lambertW.h" +// All optimizers use the reparameterization ψ = log(S²) so the variance S² is +// always positive. The R/C++ interface passes S2 (variance) rather than S (std dev). + // [[Rcpp::export]] arma::vec zipln_vloglik( const arma::mat & Y, // responses (n,p) @@ -21,12 +24,11 @@ arma::vec zipln_vloglik( const arma::mat & B, // (d,p) const arma::mat & R, // (n,p) const arma::mat & M, // (n,p) - const arma::mat & S // (n,p) + const arma::mat & S2 // (n,p) variational variance ) { const arma::uword p = Y.n_cols; - const arma::mat S2 = S % S ; - const arma::mat A = trunc_exp(O + M + .5 * S2) ; + const arma::mat A = trunc_exp(O + M + .5 * S2) ; const arma::mat M_mu = M - X * B ; const arma::mat mu0 = logit(Pi) ; return ( @@ -41,38 +43,38 @@ arma::vec zipln_vloglik( // [[Rcpp::export]] arma::mat optim_zipln_Omega_full( - const arma::mat & M, // (n,p) - const arma::mat & X, // (n,d) - const arma::mat & B, // (d,p) - const arma::mat & S // (n,p) + const arma::mat & M, // (n,p) + const arma::mat & X, // (n,d) + const arma::mat & B, // (d,p) + const arma::mat & S2 // (n,p) variational variance ) { const arma::uword n = M.n_rows; arma::mat M_mu = M - X * B; - return (double(n) * inv_sympd(M_mu.t() * M_mu + diagmat(sum(S % S, 0)))); + return (double(n) * inv_sympd(M_mu.t() * M_mu + diagmat(sum(S2, 0)))); } // [[Rcpp::export]] arma::mat optim_zipln_Omega_spherical( - const arma::mat & M, // (n,p) - const arma::mat & X, // (n,d) - const arma::mat & B, // (d,p) - const arma::mat & S // (n,p) + const arma::mat & M, // (n,p) + const arma::mat & X, // (n,d) + const arma::mat & B, // (d,p) + const arma::mat & S2 // (n,p) variational variance ) { const arma::uword n = M.n_rows; const arma::uword p = M.n_cols; - double sigma2 = accu( pow(M - X * B, 2) + S % S ) / double(n * p) ; + double sigma2 = accu( pow(M - X * B, 2) + S2 ) / double(n * p) ; return arma::diagmat(arma::ones(p)/sigma2) ; } // [[Rcpp::export]] arma::mat optim_zipln_Omega_diagonal( - const arma::mat & M, // (n,p) - const arma::mat & X, // (n,d) - const arma::mat & B, // (d,p) - const arma::mat & S // (n,p) + const arma::mat & M, // (n,p) + const arma::mat & X, // (n,d) + const arma::mat & B, // (d,p) + const arma::mat & S2 // (n,p) variational variance ) { const arma::uword n = M.n_rows; - return arma::diagmat(double(n) / sum( pow(M - X * B, 2) + S % S, 0)) ; + return arma::diagmat(double(n) / sum( pow(M - X * B, 2) + S2, 0)) ; } // [[Rcpp::export]] @@ -123,19 +125,16 @@ Rcpp::List optim_zipln_zipar_covar( // [[Rcpp::export]] arma::mat optim_zipln_R_var( - const arma::mat & Y, // responses (n,p) - const arma::mat & X, // covariates (n,d) - const arma::mat & O, // offsets (n,p) - const arma::mat & M, // (n,p) - const arma::mat & S, // (n,p) + const arma::mat & Y, // responses (n,p) + const arma::mat & X, // covariates (n,d) + const arma::mat & O, // offsets (n,p) + const arma::mat & M, // (n,p) + const arma::mat & S2, // (n,p) variational variance const arma::mat & Pi, // (d,p) - const arma::mat & B // covariates (n,d) + const arma::mat & B // covariates (n,d) ) { - arma::mat A = exp(O + M + 0.5 * S % S); + arma::mat A = exp(O + M + 0.5 * S2); arma::mat R = 1. / (1. + exp(-(A + logit(Pi)))); - // Zero R_{i,j} if Y_{i,j} > 0 - // multiplication with f(sign(Y)) could work to zero stuff as there should not be any +inf - // using a loop as it is more explicit and should have ok performance in C++ R.elem(arma::find(Y > 0.)).zeros(); return R; } @@ -147,20 +146,20 @@ double phi (double mu, double sigma2) { // [[Rcpp::export]] arma::mat optim_zipln_R_exact ( - const arma::mat & Y, // covariates (n,d) - const arma::mat & X, // covariates (n,d) - const arma::mat & O, // offsets (n,p) - const arma::mat & M, // (n,p) - const arma::mat & S, // (n,p) + const arma::mat & Y, // covariates (n,d) + const arma::mat & X, // covariates (n,d) + const arma::mat & O, // offsets (n,p) + const arma::mat & M, // (n,p) + const arma::mat & S2, // (n,p) variational variance const arma::mat & Pi, // (n,p) - const arma::mat & B // covariates (n,d) + const arma::mat & B // covariates (n,d) ) { arma::mat XB = X * B; arma::mat M_mu = M - XB; const int n = (int)M.n_rows; const int p = (int)M.n_cols; - arma::vec diag_Sigma = (sum(M_mu % M_mu, 0) + sum(S % S, 0)).t() / double(n); + arma::vec diag_Sigma = (sum(M_mu % M_mu, 0) + sum(S2, 0)).t() / double(n); arma::mat R = arma::zeros(n, p); // lambertW0_CS is pure (no global state) — safe to parallelize #ifdef _OPENMP @@ -184,7 +183,7 @@ Rcpp::List optim_zipln_M( const arma::mat & X, // covariates (n,d) const arma::mat & O, // offsets (n, p) const arma::mat & R, // (n,p) - const arma::mat & S, // (n,p) + const arma::mat & S2, // (n,p) variational variance (fixed) const arma::mat & B, // (d,p) const arma::mat & Omega, // (p,p) const Rcpp::List & configuration // List of config values ; xtol_abs is M only (double or mat) @@ -196,8 +195,8 @@ Rcpp::List optim_zipln_M( metadata.map(parameters.data()) = init_M; auto optimizer = new_nlopt_optimizer(configuration, parameters.size()); - const arma::mat X_B = X * B; // (n,p) - const arma::mat O_S2 = O + 0.5 * S % S; // (n,p) + const arma::mat X_B = X * B; // (n,p) + const arma::mat O_S2 = O + 0.5 * S2; // (n,p) // Optimize auto objective_and_grad = @@ -220,188 +219,126 @@ Rcpp::List optim_zipln_M( Rcpp::Named("M") = M); } +// --------------------------------------------------------------------------------------- +// Optimize ψ = log(S²) only, M fixed — nlopt/CCSAQ +// Interface: takes S2 (variance), returns S2. + // [[Rcpp::export]] -Rcpp::List optim_zipln_S( - const arma::mat & init_S, // (n,p) +Rcpp::List optim_zipln_psi( + const arma::mat & init_S2, // (n,p) variational variance (initialization) const arma::mat & O, // offsets (n, p) - const arma::mat & M, // (n,p) + const arma::mat & M, // (n,p) fixed const arma::mat & R, // (n,p) const arma::mat & B, // (d,p) - const arma::vec & diag_Omega,// (p,1) - const Rcpp::List & configuration // List of config values ; xtol_abs is S2 only (double or mat) + const arma::vec & diag_Omega,// (p) + const Rcpp::List & configuration ) { - const auto metadata = tuple_metadata(init_S); - enum { S_ID }; // Names for metadata indexes + const arma::mat psi_init = arma::log(init_S2); + const auto metadata = tuple_metadata(psi_init); + enum { PSI_ID }; auto parameters = std::vector(metadata.packed_size); - metadata.map(parameters.data()) = init_S; + metadata.map(parameters.data()) = psi_init; auto optimizer = new_nlopt_optimizer(configuration, parameters.size()); const arma::mat O_M = O + M; - // Optimize auto objective_and_grad = [&metadata, &O_M, &R, &diag_Omega](const double * params, double * grad) -> double { - const arma::mat S = metadata.map(params); - - const arma::mat S2 = S % S; - arma::mat A = exp(O_M + 0.5 * S2); // (n,p) - - // trace(1^T log(S)) == accu(log(S)). - // S_bar = diag(sum(S, 0)). trace(Omega * S_bar) = dot(diagvec(Omega), sum(S2, 0)) - double objective = accu((1. - R) % A) + 0.5 * dot(diag_Omega, sum(S2, 0)) - 0.5 * accu(log(S2)); - // S2^\emptyset interpreted as pow(S2, -1.) as that makes the most sense (gradient component for log(S2)) - // 1_n Diag(Omega)^T is n rows of diag(omega) values - metadata.map(grad) = S.each_row() % diag_Omega.t() + (1. - R) % S % A - 1. / S ; - return objective; - }; - OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); - - arma::mat S = metadata.copy(parameters.data()); - return Rcpp::List::create( - Rcpp::Named("status") = static_cast(result.status), - Rcpp::Named("iterations") = result.nb_iterations, - Rcpp::Named("S") = S); -} - -// [[Rcpp::export]] -Rcpp::List optim_zipln_M_S( - const arma::mat & init_M, // (n,p) - const arma::mat & init_S, // (n,p) - const arma::mat & Y, // responses (n,p) - const arma::mat & X, // covariates (n,d) - const arma::mat & O, // offsets (n,p) - const arma::mat & R, // (n,p) - const arma::mat & B, // (d,p) - const arma::mat & Omega, // (p,p) - const Rcpp::List & configuration -) { - const auto metadata = tuple_metadata(init_M, init_S); - enum { M_ID, S_ID }; - - auto parameters = std::vector(metadata.packed_size); - metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = init_S; - - auto optimizer = new_nlopt_optimizer(configuration, parameters.size()); - const arma::mat X_B = X * B; - const arma::vec diag_Omega = diagvec(Omega); + const arma::mat psi = metadata.map(params); + const arma::mat S2 = arma::exp(psi); + const arma::mat A = exp(O_M + 0.5 * S2); - auto objective_and_grad = [&metadata, &Y, &O, &R, &X_B, &Omega, &diag_Omega]( - const double * params, double * grad) -> double { - const arma::mat M = metadata.map(params); - const arma::mat S = metadata.map(params); - const arma::mat S2 = S % S; - const arma::mat A = exp(O + M + 0.5 * S2); - const arma::mat M_mu = M - X_B; - const arma::mat M_mu_Omega = M_mu * Omega; - - double objective = - accu((1. - R) % (Y % M - A)) - + 0.5 * accu(M_mu_Omega % M_mu) - + 0.5 * dot(diag_Omega, sum(S2, 0)) - - 0.5 * accu(log(S2)); - - metadata.map(grad) = M_mu_Omega + (1. - R) % (A - Y); - metadata.map(grad) = S.each_row() % diag_Omega.t() + (1. - R) % S % A - 1. / S; + // f = accu((1-R)%A) + 0.5*dot(diag_Omega, sum(S2,0)) - 0.5*accu(psi) + double objective = accu((1. - R) % A) + 0.5 * dot(diag_Omega, sum(S2, 0)) - 0.5 * accu(psi); + // grad_ψ_ij = 0.5 * S2_ij * (diag_Omega_j + (1-R_ij)*A_ij) - 0.5 + metadata.map(grad) = 0.5 * (S2.each_row() % diag_Omega.t() + (1. - R) % S2 % A - 1.); return objective; }; - OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); - arma::mat M = metadata.copy(parameters.data()); - arma::mat S = metadata.copy(parameters.data()); + arma::mat psi = metadata.copy(parameters.data()); + arma::mat S2 = arma::exp(psi); return Rcpp::List::create( Rcpp::Named("status") = static_cast(result.status), Rcpp::Named("iterations") = result.nb_iterations, - Rcpp::Named("M") = M, - Rcpp::Named("S") = S - ); + Rcpp::Named("S2") = S2); } // --------------------------------------------------------------------------------------- -// Joint optimization of (M, logS) — reparametrize S = exp(logS) to make the problem -// unconstrained, enabling quasi-Newton methods (LBFGS) that diverge in the S domain. -// -// Gradient w.r.t. logS_ij = S_ij * grad_S_ij -// = S²_ij * (diag_Omega_j + (1-R_ij)*A_ij) - 1 -// Hessian diagonal (exact, S decoupled): -// = 2*S²_ij * (diag_Omega_j + (1-R_ij)*A_ij*(1 + S²_ij)) > 0 -// This makes the problem globally unconstrained with positive-definite diagonal Hessian in logS. +// Joint optimization of (M, ψ=log(S²)) — nlopt/CCSAQ +// Interface: takes M, S2 (variance), returns M, S2. // [[Rcpp::export]] -Rcpp::List optim_zipln_M_logS( - const arma::mat & init_M, // (n,p) - const arma::mat & init_S, // (n,p) — converted to logS internally - const arma::mat & Y, // (n,p) - const arma::mat & X, // (n,d) - const arma::mat & O, // (n,p) - const arma::mat & R, // (n,p) - const arma::mat & B, // (d,p) - const arma::mat & Omega, // (p,p) +Rcpp::List optim_zipln_M_psi( + const arma::mat & init_M, // (n,p) + const arma::mat & init_S2, // (n,p) variational variance + const arma::mat & Y, // responses (n,p) + const arma::mat & X, // covariates (n,d) + const arma::mat & O, // offsets (n,p) + const arma::mat & R, // (n,p) + const arma::mat & B, // (d,p) + const arma::mat & Omega, // (p,p) const Rcpp::List & configuration ) { - const arma::mat logS_init = arma::log(init_S); - - const auto metadata = tuple_metadata(init_M, logS_init); - enum { M_ID, logS_ID }; + const arma::mat psi_init = arma::log(init_S2); + const auto metadata = tuple_metadata(init_M, psi_init); + enum { M_ID, PSI_ID }; auto parameters = std::vector(metadata.packed_size); metadata.map (parameters.data()) = init_M; - metadata.map(parameters.data()) = logS_init; + metadata.map(parameters.data()) = psi_init; auto optimizer = new_nlopt_optimizer(configuration, parameters.size()); - const arma::mat X_B = X * B; + const arma::mat X_B = X * B; const arma::vec diag_Omega = diagvec(Omega); auto objective_and_grad = [&metadata, &Y, &O, &R, &X_B, &Omega, &diag_Omega]( const double * params, double * grad) -> double { - const arma::mat M = metadata.map (params); - const arma::mat logS = metadata.map(params); - const arma::mat S2 = arma::exp(2. * logS); - const arma::mat A = arma::exp(O + M + 0.5 * S2); + const arma::mat M = metadata.map (params); + const arma::mat psi = metadata.map(params); + const arma::mat S2 = arma::exp(psi); + const arma::mat A = exp(O + M + 0.5 * S2); const arma::mat M_mu = M - X_B; const arma::mat M_mu_Omega = M_mu * Omega; double objective = - accu((1. - R) % (Y % M - A)) + 0.5 * accu(M_mu_Omega % M_mu) + 0.5 * dot(diag_Omega, sum(S2, 0)) - - accu(logS); // = -0.5*accu(log(S²)) + - 0.5 * accu(psi); metadata.map (grad) = M_mu_Omega + (1. - R) % (A - Y); - // grad_logS_ij = S²_ij * (diag_Omega_j + (1-R_ij)*A_ij) - 1 - metadata.map(grad) = S2 % ((1. - R) % A + arma::ones(A.n_rows, 1) * diag_Omega.t()) - 1.; + metadata.map(grad) = 0.5 * (S2.each_row() % diag_Omega.t() + (1. - R) % S2 % A - 1.); return objective; }; OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); - arma::mat M = metadata.copy (parameters.data()); - arma::mat logS = metadata.copy(parameters.data()); + arma::mat M = metadata.copy (parameters.data()); + arma::mat psi = metadata.copy(parameters.data()); return Rcpp::List::create( Rcpp::Named("status") = static_cast(result.status), Rcpp::Named("iterations") = result.nb_iterations, - Rcpp::Named("M") = M, - Rcpp::Named("S") = arma::exp(logS) + Rcpp::Named("M") = M, + Rcpp::Named("S2") = arma::exp(psi) ); } // --------------------------------------------------------------------------------------- -// Custom coordinate-Newton optimizer for (M, logS) — no NLopt dependency. +// Custom coordinate-Newton optimizer for (M, ψ=log(S²)) — no NLopt dependency. // // Per iteration: -// 1. Diagonal Newton step for M with Armijo backtracking (one M*Omega product) -// 2. Exact closed-form update for logS: logS* = -0.5*log(diag_Omega + (1-R)*A) -// This is the exact minimiser of f w.r.t. S for fixed M and A (before S feeds back -// into A). Stable by construction; no step-size issue. +// 1. Diagonal Newton step for M with Armijo backtracking +// 2. Exact closed-form update for ψ: ψ* = -log(diag_Omega + (1-R)*A) +// (exact minimiser of f w.r.t. S² for fixed M and A) // -// Cost per iteration ≈ 2 × O(n*p²) gradient evaluations — same arithmetic as CCSAQ -// but with much better step quality: typically 5-15 iterations vs 50-100 for CCSAQ. +// Upper bound on ψ prevents exp(O+M+0.5*S²) overflow: keep O+M+0.5*S² ≤ 700. // [[Rcpp::export]] -Rcpp::List optim_zipln_M_S_newton( +Rcpp::List optim_zipln_M_psi_newton( const arma::mat & init_M, // (n,p) - const arma::mat & init_S, // (n,p) + const arma::mat & init_S2, // (n,p) variational variance const arma::mat & Y, // (n,p) const arma::mat & X, // (n,d) const arma::mat & O, // (n,p) @@ -415,21 +352,21 @@ Rcpp::List optim_zipln_M_S_newton( const arma::vec diag_Omega = diagvec(Omega); const arma::mat ones_col = arma::ones(init_M.n_rows, 1); - arma::mat M = init_M; - arma::mat logS = arma::log(init_S); + arma::mat M = init_M; + arma::mat psi = arma::log(init_S2); - // Helper: full objective value (for convergence check and Armijo) - auto objective = [&](const arma::mat & M_, const arma::mat & logS_) -> double { - const arma::mat S2_ = arma::exp(2. * logS_); + // Full objective value f(M, ψ) + auto objective = [&](const arma::mat & M_, const arma::mat & psi_) -> double { + const arma::mat S2_ = arma::exp(psi_); const arma::mat A_ = arma::exp(O + M_ + 0.5 * S2_); const arma::mat M_mu_ = M_ - X_B; return - accu((1. - R) % (Y % M_ - A_)) + 0.5 * accu((M_mu_ * Omega) % M_mu_) + 0.5 * dot(diag_Omega, sum(S2_, 0)) - - accu(logS_); + - 0.5 * accu(psi_); }; - double obj_prev = objective(M, logS); + double obj_prev = objective(M, psi); int iter = 0; for (iter = 0; iter < maxiter; iter++) { @@ -437,19 +374,18 @@ Rcpp::List optim_zipln_M_S_newton( // Step 1 — diagonal Newton on M with Armijo backtracking // ---------------------------------------------------------------- { - const arma::mat S2 = arma::exp(2. * logS); + const arma::mat S2 = arma::exp(psi); const arma::mat A = arma::exp(O + M + 0.5 * S2); const arma::mat M_mu_Omega = (M - X_B) * Omega; const arma::mat grad_M = M_mu_Omega + (1. - R) % (A - Y); const arma::mat hess_M = (1. - R) % A + ones_col * diag_Omega.t(); - const arma::mat step_M = grad_M / hess_M; // Newton direction (descent) + const arma::mat step_M = grad_M / hess_M; - // Armijo backtracking: f(M - alpha*step) <= f(M) - c1*alpha*||step||²_H double alpha = 1.0; const double c1 = 1e-4; - const double slope = - accu(grad_M % step_M); // ≤ 0 + const double slope = - accu(grad_M % step_M); for (int ls = 0; ls < 20; ++ls) { - if (objective(M - alpha * step_M, logS) <= obj_prev + c1 * alpha * slope) + if (objective(M - alpha * step_M, psi) <= obj_prev + c1 * alpha * slope) break; alpha *= 0.5; } @@ -457,26 +393,25 @@ Rcpp::List optim_zipln_M_S_newton( } // ---------------------------------------------------------------- - // Step 2 — exact closed-form update for logS (fixed-point step) - // logS* = -0.5 * log( diag_Omega + (1-R)*A ) - // Per-element upper bound prevents exp(Z + 0.5*S²) from overflowing: - // keep Z + 0.5*S² ≤ 700 => logS ≤ 0.5*log(max(1, 700-Z)) + // Step 2 — exact closed-form update for ψ (fixed-point in S² space) + // S²* = 1 / (diag_Omega + (1-R)*A) ⟹ ψ* = -log(diag_Omega + (1-R)*A) + // Upper bound: keep O + M + 0.5*S² ≤ 700 ⟹ ψ ≤ log(max(1, 700-(O+M))) // ---------------------------------------------------------------- { - const arma::mat S2 = arma::exp(2. * logS); - const arma::mat Z_cur = O + X_B + M; - const arma::mat A = arma::exp(Z_cur + 0.5 * S2); - const arma::mat base = (1. - R) % A + ones_col * diag_Omega.t(); - const arma::mat logS_cand = -0.5 * arma::log(base); - const arma::mat logS_ub = 0.5 * arma::log( + const arma::mat S2 = arma::exp(psi); + const arma::mat Z_cur = O + M; + const arma::mat A = arma::exp(Z_cur + 0.5 * S2); + const arma::mat base = (1. - R) % A + ones_col * diag_Omega.t(); + const arma::mat psi_opt = - arma::log(base); + const arma::mat psi_ub = arma::log( arma::clamp(700. - Z_cur, 1., arma::datum::inf)); - logS = arma::clamp(arma::min(logS_cand, logS_ub), -20., arma::datum::inf); + psi = arma::clamp(arma::min(psi_opt, psi_ub), -40., arma::datum::inf); } // ---------------------------------------------------------------- // Convergence check // ---------------------------------------------------------------- - const double obj = objective(M, logS); + const double obj = objective(M, psi); if (iter > 0 && std::abs(obj - obj_prev) < ftol_rel * (1. + std::abs(obj_prev))) break; obj_prev = obj; } @@ -484,7 +419,7 @@ Rcpp::List optim_zipln_M_S_newton( return Rcpp::List::create( Rcpp::Named("status") = 3, Rcpp::Named("iterations") = iter, - Rcpp::Named("M") = M, - Rcpp::Named("S") = arma::exp(logS) + Rcpp::Named("M") = M, + Rcpp::Named("S2") = arma::exp(psi) ); } From 62ecfaff8e41307f4b0c040d162f72706fed63c3 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 12:36:08 +0200 Subject: [PATCH 45/58] cleaning optim for zipln --- R/RcppExports.R | 8 +- R/ZIPLN.R | 23 +++-- R/ZIPLNfit-class.R | 47 ++++------ src/RcppExports.cpp | 24 +++--- src/optim_zi-pln.cpp | 198 ++++++++++++++++++++++++++----------------- 5 files changed, 166 insertions(+), 134 deletions(-) diff --git a/R/RcppExports.R b/R/RcppExports.R index af78a57c..aff36801 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -121,12 +121,12 @@ optim_zipln_psi <- function(init_S2, O, M, R, B, diag_Omega, configuration) { .Call('_PLNmodels_optim_zipln_psi', PACKAGE = 'PLNmodels', init_S2, O, M, R, B, diag_Omega, configuration) } -optim_zipln_M_psi <- function(init_M, init_S2, Y, X, O, R, B, Omega, configuration) { - .Call('_PLNmodels_optim_zipln_M_psi', PACKAGE = 'PLNmodels', init_M, init_S2, Y, X, O, R, B, Omega, configuration) +ve_step_zipln_nlopt <- function(init_M, init_S2, Y, X, O, Pi, B, Omega, configuration) { + .Call('_PLNmodels_ve_step_zipln_nlopt', PACKAGE = 'PLNmodels', init_M, init_S2, Y, X, O, Pi, B, Omega, configuration) } -optim_zipln_M_psi_newton <- function(init_M, init_S2, Y, X, O, R, B, Omega, maxiter, ftol_rel) { - .Call('_PLNmodels_optim_zipln_M_psi_newton', PACKAGE = 'PLNmodels', init_M, init_S2, Y, X, O, R, B, Omega, maxiter, ftol_rel) +ve_step_zipln_newton <- function(init_M, init_S2, Y, X, O, Pi, B, Omega, maxiter, ftol_rel) { + .Call('_PLNmodels_ve_step_zipln_newton', PACKAGE = 'PLNmodels', init_M, init_S2, Y, X, O, Pi, B, Omega, maxiter, ftol_rel) } cpp_test_packing <- function() { diff --git a/R/ZIPLN.R b/R/ZIPLN.R index a2900402..75ecec39 100644 --- a/R/ZIPLN.R +++ b/R/ZIPLN.R @@ -74,13 +74,13 @@ ZIPLN <- function(formula, data, subset, zi = c("single", "row", "col"), control #' @inherit PLN_param details #' @details See [PLN_param()] and [PLNnetwork_param()] for a full description of the generic optimization parameters. Like [PLNnetwork_param()], ZIPLN_param() has two parameters controlling the optimization due the inner-outer loop structure of the optimizer: #' * "ftol_out" outer solver stops when an optimization step changes the objective function by less than `ftol_out` multiplied by the absolute value of the parameter. Default is 1e-6 -#' * "maxit_out" outer solver stops when the number of iteration exceeds `maxit_out`. Default is 100 (200 for NEWTON) +#' * "maxit_out" outer solver stops when the number of iteration exceeds `maxit_out`. Default is 200 for "homemade", 100 for "nlopt" #' and one additional parameter controlling the form of the variational approximation of the zero inflation: #' * "approx_ZI" either uses an exact or approximated conditional distribution for the zero inflation. Default is FALSE #' #' @export ZIPLN_param <- function( - backend = c("nlopt"), + backend = c("homemade", "nlopt"), trace = 1, covariance = c("full", "diagonal", "spherical", "fixed", "sparse"), Omega = NULL, @@ -104,17 +104,14 @@ ZIPLN_param <- function( config_pst[names(config_post)] <- config_post config_pst$trace <- trace - ## optimization config - stopifnot(backend %in% c("nlopt")) - algo_req <- if (!is.null(config_optim$algorithm)) config_optim$algorithm else "CCSAQ" - stopifnot(algo_req %in% c(available_algorithms_nlopt, "NEWTON", "SPLIT")) - config_opt <- config_default_nlopt - config_opt$algorithm <- algo_req - config_opt$trace <- trace - config_opt$ftol_out <- 1e-6 - config_opt$approx_ZI <- TRUE - config_opt$maxit_out <- if (algo_req == "NEWTON") 200L else 100L - config_opt[names(config_optim)] <- config_optim + ## optimization config — mirrors PLN_param: "homemade" = Newton, "nlopt" = CCSAQ/etc. + backend <- match.arg(backend) + config_opt <- make_config_optim(backend, config_optim, trace, + extra = list( + ftol_out = 1e-6, + approx_ZI = TRUE, + maxit_out = if (backend == "homemade") 200L else 100L + )) structure(list( backend = backend , diff --git a/R/ZIPLNfit-class.R b/R/ZIPLNfit-class.R index b0224da8..4a05f58d 100644 --- a/R/ZIPLNfit-class.R +++ b/R/ZIPLNfit-class.R @@ -139,27 +139,21 @@ ZIPLNfit <- R6Class( "row" = function(R, ...) list(Pi = matrix(rowMeans(R), nrow(R), p) , B0 = matrix(NA, d0, p)), "col" = function(R, ...) list(Pi = matrix(colMeans(R), nrow(R), p, byrow = TRUE), B0 = matrix(NA, d0, p)), "covar" = function(R, init_B0, X0, config) { - if (identical(config$algorithm, "NEWTON")) config$algorithm <- "CCSAQ" + # optim_zipln_zipar_covar is always nlopt-based + if (control$backend == "homemade") config <- config_default_nlopt optim_zipln_zipar_covar(R, init_B0, X0, config) } ) - private$optimizer$R <- ifelse(control$config_optim$approx_ZI, optim_zipln_R_var, optim_zipln_R_exact) private$optimizer$Omega <- optim_zipln_Omega_full - private$optimizer$MS <- if (identical(control$config_optim$algorithm, "NEWTON")) { - ftol <- if (!is.null(control$config_optim$ftol_rel)) control$config_optim$ftol_rel else 1e-8 - maxiter <- as.integer(if (!is.null(control$config_optim$maxeval)) control$config_optim$maxeval else 200L) - function(init_M, init_S2, Y, X, O, R, B, Omega, configuration) - optim_zipln_M_psi_newton(init_M, init_S2, Y, X, O, R, B, Omega, maxiter, ftol) - } else if (identical(control$config_optim$algorithm, "SPLIT")) { - # Separate M then ψ=log(S²) optimization via nlopt/CCSAQ - function(init_M, init_S2, Y, X, O, R, B, Omega, configuration) { - config_sub <- modifyList(configuration, list(algorithm = "CCSAQ")) - out_M <- optim_zipln_M(init_M, Y, X, O, R, init_S2, B, Omega, config_sub) - out_psi <- optim_zipln_psi(init_S2, O, out_M$M, R, B, diag(Omega), config_sub) - list(M = out_M$M, S2 = out_psi$S2) - } + # Dispatch VE step on backend: "homemade" = Newton, "nlopt" = CCSAQ/etc. + private$optimizer$MS <- if (control$backend == "homemade") { + ftol <- if (!is.null(control$config_optim$ftol_in)) control$config_optim$ftol_in else 1e-8 + maxiter <- as.integer(if (!is.null(control$config_optim$maxeval)) control$config_optim$maxeval else 10000L) + function(init_M, init_S2, Y, X, O, Pi, B, Omega, configuration) + ve_step_zipln_newton(init_M, init_S2, Y, X, O, Pi, B, Omega, maxiter, ftol) } else { - optim_zipln_M_psi + function(init_M, init_S2, Y, X, O, Pi, B, Omega, configuration) + ve_step_zipln_nlopt(init_M, init_S2, Y, X, O, Pi, B, Omega, configuration) } }, @@ -203,18 +197,15 @@ ZIPLNfit <- R6Class( new_B0 <- optim_new_zipar$B0 new_Pi <- optim_new_zipar$Pi - ### VE Step - # ZI part - new_R <- private$optimizer$R(Y = data$Y, X = data$X, O = data$O, M = parameters$M, S2 = parameters$S2, Pi = new_Pi, B = new_B) - - # PLN part: joint optimization of M and ψ=log(S²) + ### VE Step — joint (M, ψ, R): both CCSAQ and NEWTON handle R internally MS_out <- private$optimizer$MS( init_M = parameters$M, init_S2 = parameters$S2, - Y = data$Y, X = data$X, O = data$O, R = new_R, B = new_B, Omega = new_Omega, - configuration = control + Y = data$Y, X = data$X, O = data$O, + Pi = new_Pi, B = new_B, Omega = new_Omega, configuration = control ) new_M <- MS_out$M new_S2 <- MS_out$S2 + new_R <- MS_out$R # Check convergence new_parameters <- list( @@ -322,17 +313,15 @@ ZIPLNfit <- R6Class( R = parameters$R, init_B0 = B0, X0 = data$X0, config = config_default_nlopt )$Pi - # VE Step - new_R <- private$optimizer$R( - Y = data$Y, X = data$X, O = data$O, M = parameters$M, S2 = parameters$S2, Pi = Pi, B = B - ) + # VE Step — joint (M, ψ, R): R handled internally by optimizer MS_out <- private$optimizer$MS( init_M = parameters$M, init_S2 = parameters$S2, - Y = data$Y, X = data$X, O = data$O, R = new_R, B = B, Omega = Omega, - configuration = control + Y = data$Y, X = data$X, O = data$O, + Pi = Pi, B = B, Omega = Omega, configuration = control ) new_M <- MS_out$M new_S2 <- MS_out$S2 + new_R <- MS_out$R # Check convergence new_parameters <- list(R = new_R, M = new_M, S2 = new_S2) nb_iter <- nb_iter + 1 diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 6916c65d..f681a27b 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -445,9 +445,9 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// optim_zipln_M_psi -Rcpp::List optim_zipln_M_psi(const arma::mat& init_M, const arma::mat& init_S2, const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& R, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& configuration); -RcppExport SEXP _PLNmodels_optim_zipln_M_psi(SEXP init_MSEXP, SEXP init_S2SEXP, SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP RSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configurationSEXP) { +// ve_step_zipln_nlopt +Rcpp::List ve_step_zipln_nlopt(const arma::mat& init_M, const arma::mat& init_S2, const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& Pi, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& configuration); +RcppExport SEXP _PLNmodels_ve_step_zipln_nlopt(SEXP init_MSEXP, SEXP init_S2SEXP, SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP PiSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configurationSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; @@ -456,17 +456,17 @@ BEGIN_RCPP Rcpp::traits::input_parameter< const arma::mat& >::type Y(YSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type O(OSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type R(RSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Pi(PiSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type configuration(configurationSEXP); - rcpp_result_gen = Rcpp::wrap(optim_zipln_M_psi(init_M, init_S2, Y, X, O, R, B, Omega, configuration)); + rcpp_result_gen = Rcpp::wrap(ve_step_zipln_nlopt(init_M, init_S2, Y, X, O, Pi, B, Omega, configuration)); return rcpp_result_gen; END_RCPP } -// optim_zipln_M_psi_newton -Rcpp::List optim_zipln_M_psi_newton(const arma::mat& init_M, const arma::mat& init_S2, const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& R, const arma::mat& B, const arma::mat& Omega, const int maxiter, const double ftol_rel); -RcppExport SEXP _PLNmodels_optim_zipln_M_psi_newton(SEXP init_MSEXP, SEXP init_S2SEXP, SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP RSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP maxiterSEXP, SEXP ftol_relSEXP) { +// ve_step_zipln_newton +Rcpp::List ve_step_zipln_newton(const arma::mat& init_M, const arma::mat& init_S2, const arma::mat& Y, const arma::mat& X, const arma::mat& O, const arma::mat& Pi, const arma::mat& B, const arma::mat& Omega, const int maxiter, const double ftol_rel); +RcppExport SEXP _PLNmodels_ve_step_zipln_newton(SEXP init_MSEXP, SEXP init_S2SEXP, SEXP YSEXP, SEXP XSEXP, SEXP OSEXP, SEXP PiSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP maxiterSEXP, SEXP ftol_relSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; @@ -475,12 +475,12 @@ BEGIN_RCPP Rcpp::traits::input_parameter< const arma::mat& >::type Y(YSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type X(XSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type O(OSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type R(RSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Pi(PiSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const int >::type maxiter(maxiterSEXP); Rcpp::traits::input_parameter< const double >::type ftol_rel(ftol_relSEXP); - rcpp_result_gen = Rcpp::wrap(optim_zipln_M_psi_newton(init_M, init_S2, Y, X, O, R, B, Omega, maxiter, ftol_rel)); + rcpp_result_gen = Rcpp::wrap(ve_step_zipln_newton(init_M, init_S2, Y, X, O, Pi, B, Omega, maxiter, ftol_rel)); return rcpp_result_gen; END_RCPP } @@ -570,8 +570,8 @@ static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_optim_zipln_R_exact", (DL_FUNC) &_PLNmodels_optim_zipln_R_exact, 7}, {"_PLNmodels_optim_zipln_M", (DL_FUNC) &_PLNmodels_optim_zipln_M, 9}, {"_PLNmodels_optim_zipln_psi", (DL_FUNC) &_PLNmodels_optim_zipln_psi, 7}, - {"_PLNmodels_optim_zipln_M_psi", (DL_FUNC) &_PLNmodels_optim_zipln_M_psi, 9}, - {"_PLNmodels_optim_zipln_M_psi_newton", (DL_FUNC) &_PLNmodels_optim_zipln_M_psi_newton, 10}, + {"_PLNmodels_ve_step_zipln_nlopt", (DL_FUNC) &_PLNmodels_ve_step_zipln_nlopt, 9}, + {"_PLNmodels_ve_step_zipln_newton", (DL_FUNC) &_PLNmodels_ve_step_zipln_newton, 10}, {"_PLNmodels_cpp_test_packing", (DL_FUNC) &_PLNmodels_cpp_test_packing, 0}, {"_PLNmodels_spectral_optimize_rank", (DL_FUNC) &_PLNmodels_spectral_optimize_rank, 3}, {"_PLNmodels_spectral_optimize_vestep_rank", (DL_FUNC) &_PLNmodels_spectral_optimize_vestep_rank, 5}, diff --git a/src/optim_zi-pln.cpp b/src/optim_zi-pln.cpp index 658961b4..21c2a9d4 100644 --- a/src/optim_zi-pln.cpp +++ b/src/optim_zi-pln.cpp @@ -135,7 +135,7 @@ arma::mat optim_zipln_R_var( ) { arma::mat A = exp(O + M + 0.5 * S2); arma::mat R = 1. / (1. + exp(-(A + logit(Pi)))); - R.elem(arma::find(Y > 0.)).zeros(); + R %= arma::conv_to::from(Y < 0.5); return R; } @@ -270,13 +270,13 @@ Rcpp::List optim_zipln_psi( // Interface: takes M, S2 (variance), returns M, S2. // [[Rcpp::export]] -Rcpp::List optim_zipln_M_psi( +Rcpp::List ve_step_zipln_nlopt( const arma::mat & init_M, // (n,p) const arma::mat & init_S2, // (n,p) variational variance const arma::mat & Y, // responses (n,p) const arma::mat & X, // covariates (n,d) const arma::mat & O, // offsets (n,p) - const arma::mat & R, // (n,p) + const arma::mat & Pi, // (n,p) ZI structural probability const arma::mat & B, // (d,p) const arma::mat & Omega, // (p,p) const Rcpp::List & configuration @@ -290,136 +290,182 @@ Rcpp::List optim_zipln_M_psi( metadata.map(parameters.data()) = psi_init; auto optimizer = new_nlopt_optimizer(configuration, parameters.size()); - const arma::mat X_B = X * B; + const arma::mat X_B = X * B; const arma::vec diag_Omega = diagvec(Omega); - - auto objective_and_grad = [&metadata, &Y, &O, &R, &X_B, &Omega, &diag_Omega]( + const arma::mat logit_Pi = logit(Pi); + const arma::mat Y_zero = arma::conv_to::from(Y < 0.5); + + // R is fixed at its exact conditional optimum given the initial (M, S2). + // This ensures a consistent (objective, gradient) pair for nlopt. + // After convergence the final R is recomputed from the optimised (M, S2). + const arma::mat A0 = arma::exp(O + init_M + 0.5 * init_S2); + const arma::mat R0 = (1.0 / (1.0 + arma::exp(-(A0 + logit_Pi)))) % Y_zero; + const arma::mat one_m_R = 1.0 - R0; + + auto objective_and_grad = [&metadata, &Y, &O, &X_B, &Omega, &diag_Omega, + &one_m_R]( const double * params, double * grad) -> double { const arma::mat M = metadata.map (params); const arma::mat psi = metadata.map(params); const arma::mat S2 = arma::exp(psi); - const arma::mat A = exp(O + M + 0.5 * S2); + const arma::mat A = arma::exp(O + M + 0.5 * S2); const arma::mat M_mu = M - X_B; const arma::mat M_mu_Omega = M_mu * Omega; - double objective = - accu((1. - R) % (Y % M - A)) + double objective = - accu(one_m_R % (Y % M - A)) + 0.5 * accu(M_mu_Omega % M_mu) + 0.5 * dot(diag_Omega, sum(S2, 0)) - 0.5 * accu(psi); - metadata.map (grad) = M_mu_Omega + (1. - R) % (A - Y); - metadata.map(grad) = 0.5 * (S2.each_row() % diag_Omega.t() + (1. - R) % S2 % A - 1.); + metadata.map (grad) = M_mu_Omega + one_m_R % (A - Y); + metadata.map(grad) = 0.5 * (S2.each_row() % diag_Omega.t() + one_m_R % S2 % A - 1.); return objective; }; OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); - arma::mat M = metadata.copy (parameters.data()); - arma::mat psi = metadata.copy(parameters.data()); + const arma::mat M = metadata.copy (parameters.data()); + const arma::mat psi = metadata.copy(parameters.data()); + const arma::mat S2 = arma::exp(psi); + const arma::mat A = arma::exp(O + M + 0.5 * S2); + const arma::mat Rfin = (1.0 / (1.0 + arma::exp(-(A + logit_Pi)))) % Y_zero; return Rcpp::List::create( Rcpp::Named("status") = static_cast(result.status), Rcpp::Named("iterations") = result.nb_iterations, Rcpp::Named("M") = M, - Rcpp::Named("S2") = arma::exp(psi) + Rcpp::Named("S2") = S2, + Rcpp::Named("R") = Rfin ); } // --------------------------------------------------------------------------------------- -// Custom coordinate-Newton optimizer for (M, ψ=log(S²)) — no NLopt dependency. +// Joint VE Newton optimizer for (M, ψ=log(S²), R) — no NLopt dependency. +// +// R is the exact conditional optimum given (M, ψ): R_ij* = σ(A_ij + logit(π_ij)) for Y=0. +// Since ∂f/∂R = 0 at R*, updating R at each Newton iteration does not modify the gradient +// formula for (M, ψ) — only (1-R) changes, tightening the VE step. // -// Per iteration: -// 1. Diagonal Newton step for M with Armijo backtracking -// 2. Exact closed-form update for ψ: ψ* = -log(diag_Omega + (1-R)*A) -// (exact minimiser of f w.r.t. S² for fixed M and A) +// Per Newton iteration: +// 0. R ← σ(A + logit(Pi)), zeroed where Y > 0 [exact VE for R, O(np)] +// 1. 2×2 Newton step for (M_res, ψ) with cross-term H_{Mψ} [joint step] +// 2. Joint Armijo on (M_res, ψ) with R fixed [line search, R frozen] // -// Upper bound on ψ prevents exp(O+M+0.5*S²) overflow: keep O+M+0.5*S² ≤ 700. +// M·Ω cached and updated incrementally inside the line search (avoids O(np²) per trial). // [[Rcpp::export]] -Rcpp::List optim_zipln_M_psi_newton( +Rcpp::List ve_step_zipln_newton( const arma::mat & init_M, // (n,p) const arma::mat & init_S2, // (n,p) variational variance const arma::mat & Y, // (n,p) const arma::mat & X, // (n,d) const arma::mat & O, // (n,p) - const arma::mat & R, // (n,p) + const arma::mat & Pi, // (n,p) ZI structural probability (model param, fixed) const arma::mat & B, // (d,p) const arma::mat & Omega, // (p,p) - const int maxiter, // max coordinate steps - const double ftol_rel // relative objective convergence threshold + const int maxiter, + const double ftol_rel ) { - const arma::mat X_B = X * B; - const arma::vec diag_Omega = diagvec(Omega); - const arma::mat ones_col = arma::ones(init_M.n_rows, 1); - - arma::mat M = init_M; - arma::mat psi = arma::log(init_S2); - - // Full objective value f(M, ψ) - auto objective = [&](const arma::mat & M_, const arma::mat & psi_) -> double { - const arma::mat S2_ = arma::exp(psi_); - const arma::mat A_ = arma::exp(O + M_ + 0.5 * S2_); - const arma::mat M_mu_ = M_ - X_B; - return - accu((1. - R) % (Y % M_ - A_)) - + 0.5 * accu((M_mu_ * Omega) % M_mu_) - + 0.5 * dot(diag_Omega, sum(S2_, 0)) - - 0.5 * accu(psi_); + const arma::mat XB = X * B; + const arma::mat OXB = O + XB; + const arma::vec diag_Omega = arma::diagvec(Omega); + const arma::mat omega_d = arma::ones(init_M.n_rows, 1) * diag_Omega.t(); // (n,p) + const arma::mat logit_Pi = logit(Pi); + const arma::mat Y_zero = arma::conv_to::from(Y < 0.5); // 1.0 where Y==0 + + arma::mat M_res = init_M - XB; + arma::mat psi = arma::log(init_S2); + arma::mat MO = M_res * Omega; + arma::mat S2 = arma::exp(psi); + arma::mat A = arma::trunc_exp(OXB + M_res + 0.5 * S2); + + // R and (1-R): updated at each Newton iteration, frozen during line search. + arma::mat R = 1.0 / (1.0 + arma::exp(-(A + logit_Pi))); + R %= Y_zero; + arma::mat one_m_R = 1.0 - R; + arma::mat one_m_R_Y = one_m_R % Y; + + // Objective for line search: uses one_m_R / one_m_R_Y captured by ref (frozen during LS). + auto obj_fun = [&](const arma::mat & Mres, const arma::mat & MO_, + const arma::mat & psi_) -> double { + const arma::mat S2_ = arma::exp(psi_); + const arma::mat A_ = arma::trunc_exp(OXB + Mres + 0.5 * S2_); + return - arma::accu(one_m_R % (Y % (Mres + XB) - A_)) + + 0.5 * arma::accu(Mres % MO_) + + 0.5 * arma::dot(diag_Omega, arma::sum(S2_, 0)) + - 0.5 * arma::accu(psi_); }; - double obj_prev = objective(M, psi); + double obj_prev = obj_fun(M_res, MO, psi); int iter = 0; for (iter = 0; iter < maxiter; iter++) { // ---------------------------------------------------------------- - // Step 1 — diagonal Newton on M with Armijo backtracking + // Step 0 — exact R update: R* = σ(A + logit(Pi)), R[Y>0] = 0 + // ∂f/∂R = 0 here, so gradient of f w.r.t. (M,ψ) is unchanged. + // Skipped when update_R=false (R held fixed at initial value). // ---------------------------------------------------------------- - { - const arma::mat S2 = arma::exp(psi); - const arma::mat A = arma::exp(O + M + 0.5 * S2); - const arma::mat M_mu_Omega = (M - X_B) * Omega; - const arma::mat grad_M = M_mu_Omega + (1. - R) % (A - Y); - const arma::mat hess_M = (1. - R) % A + ones_col * diag_Omega.t(); - const arma::mat step_M = grad_M / hess_M; - - double alpha = 1.0; - const double c1 = 1e-4; - const double slope = - accu(grad_M % step_M); - for (int ls = 0; ls < 20; ++ls) { - if (objective(M - alpha * step_M, psi) <= obj_prev + c1 * alpha * slope) - break; - alpha *= 0.5; - } - M -= alpha * step_M; - } + R = 1.0 / (1.0 + arma::exp(-(A + logit_Pi))); + R %= Y_zero; + one_m_R = 1.0 - R; + one_m_R_Y = one_m_R % Y; + obj_prev = obj_fun(M_res, MO, psi); // ---------------------------------------------------------------- - // Step 2 — exact closed-form update for ψ (fixed-point in S² space) - // S²* = 1 / (diag_Omega + (1-R)*A) ⟹ ψ* = -log(diag_Omega + (1-R)*A) - // Upper bound: keep O + M + 0.5*S² ≤ 700 ⟹ ψ ≤ log(max(1, 700-(O+M))) + // Step 1 — joint 2×2 Newton step for (M_res, ψ) // ---------------------------------------------------------------- - { - const arma::mat S2 = arma::exp(psi); - const arma::mat Z_cur = O + M; - const arma::mat A = arma::exp(Z_cur + 0.5 * S2); - const arma::mat base = (1. - R) % A + ones_col * diag_Omega.t(); - const arma::mat psi_opt = - arma::log(base); - const arma::mat psi_ub = arma::log( - arma::clamp(700. - Z_cur, 1., arma::datum::inf)); - psi = arma::clamp(arma::min(psi_opt, psi_ub), -40., arma::datum::inf); + const arma::mat one_m_R_A = one_m_R % A; + + const arma::mat grad_M = MO + one_m_R_A - one_m_R_Y; + const arma::mat grad_psi = 0.5 * (S2 % (one_m_R_A + omega_d) - 1.0); + + const arma::mat h_mm = one_m_R_A + omega_d; + const arma::mat h_pp = 0.5 * S2 % (one_m_R_A % (1.0 + 0.5 * S2) + omega_d); + const arma::mat h_mp = 0.5 * S2 % one_m_R_A; + + arma::mat det = h_mm % h_pp - h_mp % h_mp; + det.clamp(1e-20, arma::datum::inf); + + const arma::mat step_M = (h_pp % grad_M - h_mp % grad_psi) / det; + const arma::mat step_psi = (h_mm % grad_psi - h_mp % grad_M ) / det; + + // ---------------------------------------------------------------- + // Step 2 — joint Armijo on (M_res, ψ), R frozen at current value. + // dMO = step_M * Omega computed once; MO_trial = MO - α·dMO is O(np). + // ---------------------------------------------------------------- + const arma::mat dMO = step_M * Omega; + double slope = -arma::accu(grad_M % step_M) - arma::accu(grad_psi % step_psi); + if (slope >= 0.0) + slope = -(arma::accu(arma::square(grad_M)) + arma::accu(arma::square(grad_psi))); + + constexpr double c1 = 1e-4; + double alpha = 1.0; + for (int ls = 0; ls < 20; ++ls) { + if (obj_fun(M_res - alpha * step_M, + MO - alpha * dMO, + psi - alpha * step_psi) <= obj_prev + c1 * alpha * slope) break; + alpha *= 0.5; } + M_res -= alpha * step_M; + MO -= alpha * dMO; + psi -= alpha * step_psi; + S2 = arma::exp(psi); + A = arma::trunc_exp(OXB + M_res + 0.5 * S2); + // ---------------------------------------------------------------- - // Convergence check + // Convergence check (M, ψ only; R convergence implicit) // ---------------------------------------------------------------- - const double obj = objective(M, psi); - if (iter > 0 && std::abs(obj - obj_prev) < ftol_rel * (1. + std::abs(obj_prev))) break; + const double obj = obj_fun(M_res, MO, psi); + if (iter > 0 && std::abs(obj - obj_prev) < ftol_rel * (1.0 + std::abs(obj_prev))) break; obj_prev = obj; } return Rcpp::List::create( Rcpp::Named("status") = 3, Rcpp::Named("iterations") = iter, - Rcpp::Named("M") = M, - Rcpp::Named("S2") = arma::exp(psi) + Rcpp::Named("M") = M_res + XB, + Rcpp::Named("S2") = S2, + Rcpp::Named("R") = R ); } From d60f9ce73039632138611c84a8bed7f0ee390bfc Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 12:59:32 +0200 Subject: [PATCH 46/58] fix test for zipln after first batch of topitmization --- man/ZIPLN_param.Rd | 4 +-- src/optim_zi-pln.cpp | 55 ++++++++++++++++++++----------------- tests/testthat/test-zipln.R | 8 +++--- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/man/ZIPLN_param.Rd b/man/ZIPLN_param.Rd index 6c2f46da..246cddf4 100644 --- a/man/ZIPLN_param.Rd +++ b/man/ZIPLN_param.Rd @@ -5,7 +5,7 @@ \title{Control of a ZIPLN fit} \usage{ ZIPLN_param( - backend = c("nlopt"), + backend = c("homemade", "nlopt"), trace = 1, covariance = c("full", "diagonal", "spherical", "fixed", "sparse"), Omega = NULL, @@ -52,7 +52,7 @@ Helper to define list of parameters to control the PLN fit. All arguments have d See \code{\link[=PLN_param]{PLN_param()}} and \code{\link[=PLNnetwork_param]{PLNnetwork_param()}} for a full description of the generic optimization parameters. Like \code{\link[=PLNnetwork_param]{PLNnetwork_param()}}, ZIPLN_param() has two parameters controlling the optimization due the inner-outer loop structure of the optimizer: \itemize{ \item "ftol_out" outer solver stops when an optimization step changes the objective function by less than \code{ftol_out} multiplied by the absolute value of the parameter. Default is 1e-6 -\item "maxit_out" outer solver stops when the number of iteration exceeds \code{maxit_out}. Default is 100 (200 for NEWTON) +\item "maxit_out" outer solver stops when the number of iteration exceeds \code{maxit_out}. Default is 200 for "homemade", 100 for "nlopt" and one additional parameter controlling the form of the variational approximation of the zero inflation: \item "approx_ZI" either uses an exact or approximated conditional distribution for the zero inflation. Default is FALSE } diff --git a/src/optim_zi-pln.cpp b/src/optim_zi-pln.cpp index 21c2a9d4..fb01c277 100644 --- a/src/optim_zi-pln.cpp +++ b/src/optim_zi-pln.cpp @@ -62,7 +62,7 @@ arma::mat optim_zipln_Omega_spherical( ) { const arma::uword n = M.n_rows; const arma::uword p = M.n_cols; - double sigma2 = accu( pow(M - X * B, 2) + S2 ) / double(n * p) ; + double sigma2 = accu( arma::square(M - X * B) + S2 ) / double(n * p) ; return arma::diagmat(arma::ones(p)/sigma2) ; } @@ -74,7 +74,7 @@ arma::mat optim_zipln_Omega_diagonal( const arma::mat & S2 // (n,p) variational variance ) { const arma::uword n = M.n_rows; - return arma::diagmat(double(n) / sum( pow(M - X * B, 2) + S2, 0)) ; + return arma::diagmat(double(n) / sum( arma::square(M - X * B) + S2, 0)) ; } // [[Rcpp::export]] @@ -266,8 +266,15 @@ Rcpp::List optim_zipln_psi( } // --------------------------------------------------------------------------------------- -// Joint optimization of (M, ψ=log(S²)) — nlopt/CCSAQ -// Interface: takes M, S2 (variance), returns M, S2. +// Joint VE step for (M, ψ=log(S²), R) — nlopt backend. +// +// R is fixed at its exact conditional optimum R* = σ(A₀ + logit(Pi)) [Y>0 → 0] +// computed once from the initial (M, S²) before the nlopt solve. Fixing R +// during the inner solve keeps the (objective, gradient) pair consistent, which +// is required by nlopt's line-search. The final R is recomputed from the +// optimised (M, S²) before returning. +// +// Interface: takes Pi (ZI structural probability), returns M, S², R. // [[Rcpp::export]] Rcpp::List ve_step_zipln_nlopt( @@ -380,48 +387,46 @@ Rcpp::List ve_step_zipln_newton( arma::mat A = arma::trunc_exp(OXB + M_res + 0.5 * S2); // R and (1-R): updated at each Newton iteration, frozen during line search. - arma::mat R = 1.0 / (1.0 + arma::exp(-(A + logit_Pi))); - R %= Y_zero; - arma::mat one_m_R = 1.0 - R; - arma::mat one_m_R_Y = one_m_R % Y; + // one_m_R_Y = (1-R)%Y = Y always: when Y>0 R=0, when Y=0 Y=0, so just use Y. + arma::mat R = arma::zeros(arma::size(A)); + arma::mat one_m_R(arma::size(A)); - // Objective for line search: uses one_m_R / one_m_R_Y captured by ref (frozen during LS). + // Objective for line search: captures one_m_R by ref (frozen during LS). auto obj_fun = [&](const arma::mat & Mres, const arma::mat & MO_, const arma::mat & psi_) -> double { const arma::mat S2_ = arma::exp(psi_); const arma::mat A_ = arma::trunc_exp(OXB + Mres + 0.5 * S2_); - return - arma::accu(one_m_R % (Y % (Mres + XB) - A_)) + return - arma::accu(Y % (Mres + XB)) + arma::accu(one_m_R % A_) + 0.5 * arma::accu(Mres % MO_) + 0.5 * arma::dot(diag_Omega, arma::sum(S2_, 0)) - 0.5 * arma::accu(psi_); }; - double obj_prev = obj_fun(M_res, MO, psi); + double obj_prev = 0.0; int iter = 0; for (iter = 0; iter < maxiter; iter++) { // ---------------------------------------------------------------- // Step 0 — exact R update: R* = σ(A + logit(Pi)), R[Y>0] = 0 - // ∂f/∂R = 0 here, so gradient of f w.r.t. (M,ψ) is unchanged. - // Skipped when update_R=false (R held fixed at initial value). + // ∂f/∂R = 0 at R*, so the gradient w.r.t. (M,ψ) is unaffected. // ---------------------------------------------------------------- - R = 1.0 / (1.0 + arma::exp(-(A + logit_Pi))); - R %= Y_zero; - one_m_R = 1.0 - R; - one_m_R_Y = one_m_R % Y; - obj_prev = obj_fun(M_res, MO, psi); + R = 1.0 / (1.0 + arma::exp(-(A + logit_Pi))); + R %= Y_zero; + one_m_R = 1.0 - R; + obj_prev = obj_fun(M_res, MO, psi); // ---------------------------------------------------------------- // Step 1 — joint 2×2 Newton step for (M_res, ψ) // ---------------------------------------------------------------- const arma::mat one_m_R_A = one_m_R % A; - const arma::mat grad_M = MO + one_m_R_A - one_m_R_Y; - const arma::mat grad_psi = 0.5 * (S2 % (one_m_R_A + omega_d) - 1.0); - + // h_mp computed first; h_pp reuses S2 % one_m_R_A via h_mp const arma::mat h_mm = one_m_R_A + omega_d; - const arma::mat h_pp = 0.5 * S2 % (one_m_R_A % (1.0 + 0.5 * S2) + omega_d); const arma::mat h_mp = 0.5 * S2 % one_m_R_A; + const arma::mat h_pp = h_mp % (1.0 + 0.5 * S2) + 0.5 * S2 % omega_d; + + const arma::mat grad_M = MO + one_m_R_A - Y; + const arma::mat grad_psi = h_mp + 0.5 * (S2 % omega_d - 1.0); // = 0.5*(S2%(one_m_R_A+omega_d)-1) arma::mat det = h_mm % h_pp - h_mp % h_mp; det.clamp(1e-20, arma::datum::inf); @@ -454,11 +459,11 @@ Rcpp::List ve_step_zipln_newton( A = arma::trunc_exp(OXB + M_res + 0.5 * S2); // ---------------------------------------------------------------- - // Convergence check (M, ψ only; R convergence implicit) + // Convergence: compare objective before and after this Newton step + // (R is frozen during the step; obj_prev was set at top of this iter) // ---------------------------------------------------------------- const double obj = obj_fun(M_res, MO, psi); - if (iter > 0 && std::abs(obj - obj_prev) < ftol_rel * (1.0 + std::abs(obj_prev))) break; - obj_prev = obj; + if (std::abs(obj - obj_prev) < ftol_rel * (1.0 + std::abs(obj_prev))) break; } return Rcpp::List::create( diff --git a/tests/testthat/test-zipln.R b/tests/testthat/test-zipln.R index 8b954951..0389b97e 100644 --- a/tests/testthat/test-zipln.R +++ b/tests/testthat/test-zipln.R @@ -51,13 +51,13 @@ test_that("PLN is working with unnamed data matrix", { test_that("ZIPLN is working with different optimization algorithm in NLopt", { - MMA <- ZIPLN(Abundance ~ 1, data = trichoptera, control = ZIPLN_param(config_optim = list(algorithm = "MMA"))) - CCSAQ <- ZIPLN(Abundance ~ 1, data = trichoptera, control = ZIPLN_param(config_optim = list(algorithm = "CCSAQ"))) - LBFGS <- ZIPLN(Abundance ~ 1, data = trichoptera, control = ZIPLN_param(config_optim = list(algorithm = "LBFGS"))) + MMA <- ZIPLN(Abundance ~ 1, data = trichoptera, control = ZIPLN_param(backend = "nlopt", config_optim = list(algorithm = "MMA"))) + CCSAQ <- ZIPLN(Abundance ~ 1, data = trichoptera, control = ZIPLN_param(backend = "nlopt", config_optim = list(algorithm = "CCSAQ"))) + LBFGS <- ZIPLN(Abundance ~ 1, data = trichoptera, control = ZIPLN_param(backend = "nlopt", config_optim = list(algorithm = "LBFGS"))) expect_equal(MMA$loglik, CCSAQ$loglik, tolerance = 1e-1) ## Almost equivalent, CCSAQ faster - expect_error(ZIPLN(Abundance ~ 1, data = trichoptera, control = ZIPLN_param(config_optim = list(algorithm = "nawak")))) + expect_error(ZIPLN(Abundance ~ 1, data = trichoptera, control = ZIPLN_param(backend = "nlopt", config_optim = list(algorithm = "nawak")))) }) test_that("ZIPLN is working with exact and variational inference for the conditional distribution of the ZI component", { From 156b179e21869cc51e273057f49ede92dab7bf45 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 13:10:57 +0200 Subject: [PATCH 47/58] suppressing API for approx_zi which doesn't work in practice. --- R/ZIPLN.R | 7 +++---- R/ZIPLNfit-class.R | 1 - R/ZIPLNnetwork.R | 1 - man/ZIPLN_param.Rd | 9 +++------ tests/testthat/test-zipln.R | 10 ---------- 5 files changed, 6 insertions(+), 22 deletions(-) diff --git a/R/ZIPLN.R b/R/ZIPLN.R index 75ecec39..72115551 100644 --- a/R/ZIPLN.R +++ b/R/ZIPLN.R @@ -64,19 +64,19 @@ ZIPLN <- function(formula, data, subset, zi = c("single", "row", "col"), control #' Control of a ZIPLN fit #' -#' Helper to define list of parameters to control the PLN fit. All arguments have defaults. +#' Helper to define list of parameters to control the ZIPLN fit. All arguments have defaults. #' #' @inheritParams PLN_param #' @inheritParams PLNnetwork_param +#' @param backend optimization backend, either `"homemade"` (default, built-in Newton optimizer for the joint VE step) or `"nlopt"` (NLOPT-based CCSAQ). Unlike [PLN_param()], `"hybrid"` and `"torch"` are not supported. #' @param penalty a user-defined penalty to sparsify the residual covariance. Defaults to 0 (no sparsity). #' @return list of parameters used during the fit and post-processing steps #' #' @inherit PLN_param details -#' @details See [PLN_param()] and [PLNnetwork_param()] for a full description of the generic optimization parameters. Like [PLNnetwork_param()], ZIPLN_param() has two parameters controlling the optimization due the inner-outer loop structure of the optimizer: +#' @details See [PLN_param()] for a description of the generic `config_optim` entries (`ftol_rel`, `xtol_rel`, etc.). Like [PLNnetwork_param()], ZIPLN_param() has two parameters controlling the outer EM loop: #' * "ftol_out" outer solver stops when an optimization step changes the objective function by less than `ftol_out` multiplied by the absolute value of the parameter. Default is 1e-6 #' * "maxit_out" outer solver stops when the number of iteration exceeds `maxit_out`. Default is 200 for "homemade", 100 for "nlopt" #' and one additional parameter controlling the form of the variational approximation of the zero inflation: -#' * "approx_ZI" either uses an exact or approximated conditional distribution for the zero inflation. Default is FALSE #' #' @export ZIPLN_param <- function( @@ -109,7 +109,6 @@ ZIPLN_param <- function( config_opt <- make_config_optim(backend, config_optim, trace, extra = list( ftol_out = 1e-6, - approx_ZI = TRUE, maxit_out = if (backend == "homemade") 200L else 100L )) diff --git a/R/ZIPLNfit-class.R b/R/ZIPLNfit-class.R index 4a05f58d..d005dbb9 100644 --- a/R/ZIPLNfit-class.R +++ b/R/ZIPLNfit-class.R @@ -106,7 +106,6 @@ ZIPLNfit <- R6Class( B[,j] <- replace_na(coef(zip_out, "count"), 0) R[, j] <- replace_na(predict(zip_out, type = "zero"), sum(y == 0) / n) M[,j] <- pmin(replace_na(residuals(zip_out), 0) + data$X %*% coef(zip_out, "count"), 10) - if (max(M[,j]) > 10) browser() } else { p_out <- glm(y ~ 0 + data$X, family = 'poisson', offset = data$O[, j]) B0[,j] <- rep(-10, d0) diff --git a/R/ZIPLNnetwork.R b/R/ZIPLNnetwork.R index 989550ed..c3ede542 100644 --- a/R/ZIPLNnetwork.R +++ b/R/ZIPLNnetwork.R @@ -87,7 +87,6 @@ ZIPLNnetwork_param <- function( config_opt$trace <- trace config_opt$ftol_out <- 1e-6 config_opt$maxit_out <- 50 - config_opt$approx_ZI <- TRUE config_opt[names(config_optim)] <- config_optim inception_cov <- match.arg(inception_cov) diff --git a/man/ZIPLN_param.Rd b/man/ZIPLN_param.Rd index 246cddf4..54a83ac0 100644 --- a/man/ZIPLN_param.Rd +++ b/man/ZIPLN_param.Rd @@ -18,9 +18,7 @@ ZIPLN_param( ) } \arguments{ -\item{backend}{optimization back used, either "homemade" (default), "nlopt", "hybrid" or "torch". -"homemade" is the built-in envelope-theorem Newton optimizer (does not depend on NLOPT). -"hybrid" runs nlopt first for basin finding, then switches to homemade for refinement.} +\item{backend}{optimization backend, either \code{"homemade"} (default, built-in Newton optimizer for the joint VE step) or \code{"nlopt"} (NLOPT-based CCSAQ). Unlike \code{\link[=PLN_param]{PLN_param()}}, \code{"hybrid"} and \code{"torch"} are not supported.} \item{trace}{a integer for verbosity.} @@ -46,14 +44,13 @@ which sometimes speeds up the inference.} list of parameters used during the fit and post-processing steps } \description{ -Helper to define list of parameters to control the PLN fit. All arguments have defaults. +Helper to define list of parameters to control the ZIPLN fit. All arguments have defaults. } \details{ -See \code{\link[=PLN_param]{PLN_param()}} and \code{\link[=PLNnetwork_param]{PLNnetwork_param()}} for a full description of the generic optimization parameters. Like \code{\link[=PLNnetwork_param]{PLNnetwork_param()}}, ZIPLN_param() has two parameters controlling the optimization due the inner-outer loop structure of the optimizer: +See \code{\link[=PLN_param]{PLN_param()}} for a description of the generic \code{config_optim} entries (\code{ftol_rel}, \code{xtol_rel}, etc.). Like \code{\link[=PLNnetwork_param]{PLNnetwork_param()}}, ZIPLN_param() has two parameters controlling the outer EM loop: \itemize{ \item "ftol_out" outer solver stops when an optimization step changes the objective function by less than \code{ftol_out} multiplied by the absolute value of the parameter. Default is 1e-6 \item "maxit_out" outer solver stops when the number of iteration exceeds \code{maxit_out}. Default is 200 for "homemade", 100 for "nlopt" and one additional parameter controlling the form of the variational approximation of the zero inflation: -\item "approx_ZI" either uses an exact or approximated conditional distribution for the zero inflation. Default is FALSE } } diff --git a/tests/testthat/test-zipln.R b/tests/testthat/test-zipln.R index 0389b97e..1811c69a 100644 --- a/tests/testthat/test-zipln.R +++ b/tests/testthat/test-zipln.R @@ -60,16 +60,6 @@ test_that("PLN is working with unnamed data matrix", { expect_error(ZIPLN(Abundance ~ 1, data = trichoptera, control = ZIPLN_param(backend = "nlopt", config_optim = list(algorithm = "nawak")))) }) -test_that("ZIPLN is working with exact and variational inference for the conditional distribution of the ZI component", { - - approx <- ZIPLN(Abundance ~ 1, data = trichoptera, control = ZIPLN_param(config_optim = list(approx_ZI = TRUE))) - exact <- ZIPLN(Abundance ~ 1, data = trichoptera, control = ZIPLN_param(config_optim = list(approx_ZI = FALSE))) - - expect_equal(approx$loglik, exact$loglik, tolerance = 1e-1) ## Almost equivalent - expect_equal(approx$model_par$B, exact$model_par$B, tolerance = 1e-1) ## Almost equivalent - expect_equal(approx$model_par$Sigma, exact$model_par$Sigma, tolerance = 1e-1) ## Almost equivalent - -}) test_that("ZIPLN: Check that univariate ZIPLN models works, with matrix of numeric format", { expect_no_error(uniZIPLN <- ZIPLN(Abundance[,1,drop=FALSE] ~ 1, data = trichoptera)) From 81b6500a70f66103a1b49802c5e1464e1a01e6ca Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 14:13:28 +0200 Subject: [PATCH 48/58] updating DEVLOG --- DEVLOG_2026-06-11-12.md | 112 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/DEVLOG_2026-06-11-12.md b/DEVLOG_2026-06-11-12.md index fedc6fc1..fe3ce062 100644 --- a/DEVLOG_2026-06-11-12.md +++ b/DEVLOG_2026-06-11-12.md @@ -193,3 +193,115 @@ Toutes les configurations testées avec et sans covariables (12 labels, 3 covari - **trichoptera diagonal** : besoin de > 200 EM iterations (budget à augmenter localement si nécessaire) - **microcosm full** : Newton 4–5× plus lent que nlopt (mais seul à converger correctement) - **La comparaison de temps est sensible à la charge BLAS** (multithreadé) : ne pas lancer les scripts en parallèle + +--- + +## 24. ZIPLN — Étape VE conjointe (M, ψ, R) et alignement API (12/06) + +**Fichiers** : `src/optim_zi-pln.cpp`, `R/ZIPLNfit-class.R`, `R/ZIPLN.R`, `R/RcppExports.R`, `src/RcppExports.cpp` + +### Architecture finale de l'étape VE ZIPLN + +Les deux backends gèrent R **en interne** et retournent `(M, S², R)` : + +**Backend "homemade" — `ve_step_zipln_newton`** +``` +Pour chaque itération : + R = σ(A + logit(Pi)) × 1{Y=0} ← mis à jour à chaque iter depuis (M,S²) courant + one_m_R = 1 - R + Hessienne 2×2 par (i,j) : + h_mm = (1-R)·A + ω_jj + h_mp = 0.5·S²·(1-R)·A ← terme croisé (théorème de l'enveloppe) + h_pp = h_mp·(1 + 0.5·S²) + 0.5·S²·ω_jj + Pas Newton + Armijo conjoint (M, ψ) +convergence : |f(t)-f(t-1)| < ftol·(1+|f(t-1)|) +``` + +**Backend "nlopt" — `ve_step_zipln_nlopt`** +``` +R₀ = σ(A₀ + logit(Pi)) × 1{Y=0} ← calculé une fois sur (init_M, init_S²) +R₀ fixé pendant toute la solve nlopt ← garantit cohérence (objectif, gradient) +Après convergence : R = σ(A_final + logit(Pi)) × 1{Y=0} +Retourne (M, S², R) +``` + +La fixation de R₀ pendant l'optimisation nlopt est nécessaire : mettre à jour R dans chaque callback de gradient brise la cohérence (objectif, gradient) du point de vue de nlopt, dégradant l'ELBO de ~1000 unités (−36706 vs −33523 sur oaks). + +### Alignement API PLN ↔ ZIPLN + +`ZIPLN_param()` utilise désormais `make_config_optim()` avec `backend = c("homemade", "nlopt")`, comme `PLN_param()`. Les fonctions renommées : +- `optim_zipln_M_psi` → `ve_step_zipln_nlopt` +- `optim_zipln_M_psi_newton` → `ve_step_zipln_newton` + +### Benchmark (oaks, n=116, p=114, `Abundance ~ 1`) + +| Backend | ELBO | Temps | +|---------|------|-------| +| homemade (Newton) | −32 982 | 16.1 s | +| nlopt (CCSAQ) | −33 517 | 14.2 s | + +Newton trouve un ELBO meilleur (+535), à temps comparable. + +--- + +## 25. Corrections doc et code ZIPLN (12/06) + +**Fichiers** : `R/ZIPLN.R`, `R/ZIPLNfit-class.R`, `src/optim_zi-pln.cpp`, `tests/testthat/test-zipln.R` + +### En-tête `ve_step_zipln_nlopt` (optim_zi-pln.cpp) + +Mis à jour pour décrire l'implémentation réelle : +- Précise que la fonction prend Pi (pas R), fixe R₀ avant nlopt, retourne (M, S², R) +- Explication de la fixation R₀ pour la cohérence (objectif, gradient) + +### Doc ZIPLN_param (R/ZIPLN.R) + +- Titre corrigé : "PLN fit" → "ZIPLN fit" +- `@param backend` ajouté pour surcharger l'héritage de `PLN_param` (qui mentionne "hybrid" et "torch", non supportés par ZIPLN) +- `@details` reformulé pour distinguer entries communes et spécifiques à ZIPLN + +### `browser()` supprimé (R/ZIPLNfit-class.R:109) + +Résidu de debug dans `initialize()` : `if (max(M[,j]) > 10) browser()`. La condition est rendue impossible par le `pmin(..., 10)` sur la ligne précédente. + +### Test NLopt corrigé (tests/testthat/test-zipln.R) + +Le test "ZIPLN is working with different optimization algorithm in NLopt" utilisait le backend par défaut ("homemade"), rendant les noms d'algorithme nlopt sans effet. Ajout de `backend = "nlopt"` explicite. + +--- + +## 26. Investigation et suppression de `approx_ZI` (12/06) + +**Fichiers** : `R/ZIPLNfit-class.R`, `R/ZIPLN.R`, `R/ZIPLNnetwork.R`, `tests/testthat/test-zipln.R` + +### Contexte + +L'option `approx_ZI` existait depuis l'ancienne architecture (R séparé du step (M,S)) pour basculer entre deux formes de mise à jour de R : +- `approx_ZI=TRUE` → `optim_zipln_R_var` : R* = σ(A + logit(π)), maximiseur exact de l'ELBO w.r.t. R +- `approx_ZI=FALSE` → `optim_zipln_R_exact` : R = π / (Φ(O+XB, σ²)·(1-π) + π), vraie probabilité bayésienne P(C=1|Y=0) marginalisée sur Z via la fonction W de Lambert + +Dans la nouvelle architecture conjointe, `approx_ZI` n'était plus câblé — le step VE utilisait toujours la forme σ, mais le paramètre restait dans le config sans effet. + +### Benchmark de comparaison (trichoptera) + +| Backend | approx_ZI | ELBO | Itérations | +|---------|-----------|------|-----------| +| Newton | TRUE (σ formula) | **−1139.3** | 167 | +| Newton | FALSE (Lambert W) | −1216.2 | 16 | +| CCSAQ | TRUE (σ formula) | **−1140.8** | 64 | +| CCSAQ | FALSE (Lambert W) | −1226.5 | 27 | + +### Analyse + +La forme "exacte" bayésienne donne un ELBO inférieur de **77–86 points**. La raison est théoriquement claire : la formule σ(A + logit(π)) est l'**optimum exact de l'ELBO** par rapport à R (∂ELBO/∂R_ij = 0 donne exactement cette formule). La forme Lambert W maximise la vraisemblance marginale vraie, une fonctionnelle différente — convergence plus rapide mais vers un point sous-optimal au sens de l'ELBO. + +Le qualificatif "approché" pour la formule σ était trompeur : c'est la forme exacte du point de vue de la borne variationnelle. + +### Décision : suppression complète + +`approx_ZI` supprimé de : +- `R/ZIPLN.R` : doc + `make_config_optim(extra=...)` +- `R/ZIPLNnetwork.R` : ligne `config_opt$approx_ZI <- TRUE` +- `tests/testthat/test-zipln.R` : test entier supprimé (testait l'équivalence des deux formes, fausse) + +Les fonctions C++ `optim_zipln_R_var` et `optim_zipln_R_exact` sont conservées dans `src/optim_zi-pln.cpp` pour mémoire historique. From ae976cbb778da72184d051d06a479291632dee58 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 14:14:43 +0200 Subject: [PATCH 49/58] =?UTF-8?q?fixing=20and=20enhancing=20torch=20impl?= =?UTF-8?q?=20for=20PLN=20:=20bug=20xies,=20new=20param=20for=20variationa?= =?UTF-8?q?l=20variance=20->=20optimize=20log(S=C2=B2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/PLNfit-class.R | 74 +++++++++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index 3cd4b37e..859cdf57 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -67,18 +67,18 @@ PLNfit <- R6Class( ## PRIVATE TORCH METHODS FOR OPTIMIZATION ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% torch_elbo = function(data, params, index=torch_tensor(1:self$n)) { - S2 <- torch_square(params$S[index]) - Z <- data$O[index] + params$M[index] # Z = O + M_full - A <- torch_exp(Z + .5 * S2) + S2 <- torch_exp(params$psi[index]) + Z <- data$O[index] + params$M[index] + A <- torch_exp(Z + .5 * S2) res <- .5 * sum(data$w[index]) * torch_logdet(private$torch_Sigma(data, params, index)) + - sum(data$w[index,NULL] * (A - data$Y[index] * Z - .5 * torch_log(S2))) + sum(data$w[index,NULL] * (A - data$Y[index] * Z - .5 * params$psi[index])) res }, torch_Sigma = function(data, params, index=torch_tensor(1:self$n)) { ws <- torch_sqrt(data$w[index, NULL]) - M_res <- params$M[index] - torch_mm(data$X[index], params$B) # M_res for covariance - S2_bar <- torch_sum(torch_square(ws * params$S[index]), 1) + M_res <- params$M[index] - torch_mm(data$X[index], params$B) + S2_bar <- torch_sum(data$w[index, NULL] * torch_exp(params$psi[index]), 1) MtM <- torch_mm(torch_t(ws * M_res), ws * M_res) (MtM + torch_diag(S2_bar)) / sum(ws*ws) }, @@ -88,11 +88,11 @@ PLNfit <- R6Class( }, torch_vloglik = function(data, params) { - S2 <- torch_square(params$S) - M_res <- params$M - torch_mm(data$X, params$B) # M_res for KL terms + S2 <- torch_exp(params$psi) + M_res <- params$M - torch_mm(data$X, params$B) Ji_tmp = .5 * torch_logdet(params$Omega) + - torch_sum(data$Y * params$Z - params$A + .5 * torch_log(S2), dim = 2) - + torch_sum(data$Y * params$Z - params$A + .5 * params$psi, dim = 2) - .5 * torch_sum(torch_mm(M_res, params$Omega) * M_res + S2 * torch_diag(params$Omega), dim = 2) Ji <- - torch_sum(.logfactorial_torch(data$Y), dim = 2) + Ji_tmp Ji <- .5 * self$p + as.numeric(Ji$cpu()) @@ -107,8 +107,12 @@ PLNfit <- R6Class( if (config$trace > 1) message (paste("optimizing with device: ", config$device)) ## Conversion of data and parameters to torch tensors (pointers) - data <- lapply(data, torch_tensor, dtype = torch_float32(), device = config$device) # list with Y, X, O, w - params <- lapply(params, torch_tensor, dtype = torch_float32(), requires_grad = TRUE, device = config$device) # list with B, M, S + data <- lapply(data, torch_tensor, dtype = torch_float32(), device = config$device) # Y, X, O, w + S2_init <- params$S2 # extract S2 as plain R matrix before torch conversion + params$S2 <- NULL # remove it: psi (leaf tensor) replaces it + params <- lapply(params, torch_tensor, dtype = torch_float32(), requires_grad = TRUE, device = config$device) + ## ψ = log(S²) — created as a fresh leaf tensor, unconstrained (same reparameterisation as Newton/nlopt) + params$psi <- torch_tensor(log(S2_init), dtype = torch_float32(), requires_grad = TRUE, device = config$device) ## Initialize optimizer optimizer <- switch(config$algorithm, @@ -171,13 +175,15 @@ PLNfit <- R6Class( params$Sigma <- private$torch_Sigma(data, params) params$Omega <- private$torch_Omega(data, params) - params$Z <- data$O + params$M # Z = O + M_full - params$A <- torch_exp(params$Z + torch_pow(params$S, 2)/2) + params$Z <- data$O + params$M + params$A <- torch_exp(params$Z + torch_exp(params$psi)/2) out <- lapply(params, function(x) { x = x$cpu() as.matrix(x)} ) + out$S2 <- exp(out$psi) # convert ψ back to S² for the rest of the package + out$psi <- NULL out$Ji <- private$torch_vloglik(data, params) out$monitoring <- list( objective = objective, @@ -776,16 +782,16 @@ PLNfit_diagonal <- R6Class( ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% torch_elbo = function(data, params, index=torch_tensor(1:self$n)) { - S2 <- torch_square(params$S[index]) - Z <- data$O[index] + params$M[index] # Z = O + M_full + S2 <- torch_exp(params$psi[index]) + Z <- data$O[index] + params$M[index] res <- .5 * sum(data$w[index]) * sum(torch_log(private$torch_sigma_diag(data, params, index))) + - sum(data$w[index,NULL] * (torch_exp(Z + .5 * S2) - data$Y[index] * Z - .5 * torch_log(S2))) + sum(data$w[index,NULL] * (torch_exp(Z + .5 * S2) - data$Y[index] * Z - .5 * params$psi[index])) res }, torch_sigma_diag = function(data, params, index=torch_tensor(1:self$n)) { - M_res <- params$M[index] - torch_mm(data$X[index], params$B) # M_res for covariance - torch_sum(data$w[index,NULL] * (torch_square(M_res) + torch_square(params$S[index])), 1) / sum(data$w[index]) + M_res <- params$M[index] - torch_mm(data$X[index], params$B) + torch_sum(data$w[index,NULL] * (torch_square(M_res) + torch_exp(params$psi[index])), 1) / sum(data$w[index]) }, torch_Sigma = function(data, params, index=torch_tensor(1:self$n)) { @@ -793,12 +799,12 @@ PLNfit_diagonal <- R6Class( }, torch_vloglik = function(data, params) { - S2 <- torch_square(params$S) - M_res <- params$M - torch_mm(data$X, params$B) # M_res for KL terms + S2 <- torch_exp(params$psi) + M_res <- params$M - torch_mm(data$X, params$B) omega_diag <- torch_pow(private$torch_sigma_diag(data, params), -1) Ji <- .5 * self$p - rowSums(.logfactorial(as.matrix(data$Y))) + as.numeric( .5 * sum(torch_log(omega_diag)) + - torch_sum(data$Y * params$Z - params$A + .5 * torch_log(S2) - + torch_sum(data$Y * params$Z - params$A + .5 * params$psi - .5 * (torch_square(M_res) + S2) * omega_diag[NULL,], dim = 2) ) attr(Ji, "weights") <- as.numeric(data$w) @@ -862,16 +868,16 @@ PLNfit_spherical <- R6Class( ## PRIVATE TORCH METHODS FOR OPTIMIZATION ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% torch_elbo = function(data, params, index=torch_tensor(1:self$n)) { - S2 <- torch_square(params$S[index]) - Z <- data$O[index] + params$M[index] # Z = O + M_full + S2 <- torch_exp(params$psi[index]) + Z <- data$O[index] + params$M[index] res <- .5 * sum(data$w[index]) * self$p * torch_log(private$torch_sigma2(data, params, index)) - - sum(data$w[index,NULL] * (data$Y[index] * Z - torch_exp(Z + .5 * S2) + .5 * torch_log(S2))) + sum(data$w[index,NULL] * (data$Y[index] * Z - torch_exp(Z + .5 * S2) + .5 * params$psi[index])) res }, torch_sigma2 = function(data, params, index=torch_tensor(1:self$n)) { - M_res <- params$M[index] - torch_mm(data$X[index], params$B) # M_res for covariance - sum(data$w[index, NULL] * (torch_square(M_res) + torch_square(params$S[index]))) / (sum(data$w[index]) * self$p) + M_res <- params$M[index] - torch_mm(data$X[index], params$B) + sum(data$w[index, NULL] * (torch_square(M_res) + torch_exp(params$psi[index]))) / (sum(data$w[index]) * self$p) }, torch_Sigma = function(data, params, index=torch_tensor(1:self$n)) { @@ -879,11 +885,12 @@ PLNfit_spherical <- R6Class( }, torch_vloglik = function(data, params) { - S2 <- torch_pow(params$S, 2) - M_res <- params$M - torch_mm(data$X, params$B) # M_res for KL terms + S2 <- torch_exp(params$psi) + M_res <- params$M - torch_mm(data$X, params$B) sigma2 <- private$torch_sigma2(data, params) Ji <- .5 * self$p - rowSums(.logfactorial(as.matrix(data$Y))) + as.numeric( - torch_sum(data$Y * params$Z - params$A + .5 * torch_log(S2/sigma2) - .5 * (torch_pow(M_res, 2) + S2)/sigma2, dim = 2) + torch_sum(data$Y * params$Z - params$A + .5 * (params$psi - torch_log(sigma2)) - + .5 * (torch_pow(M_res, 2) + S2)/sigma2, dim = 2) ) attr(Ji, "weights") <- as.numeric(data$w) Ji @@ -961,10 +968,11 @@ PLNfit_fixedcov <- R6Class( ## PRIVATE TORCH METHODS FOR OPTIMIZATION ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% torch_elbo = function(data, params, index=torch_tensor(1:self$n)) { - S2 <- torch_square(params$S[index]) - Z <- data$O[index] + params$M[index] # Z = O + M_full - res <- sum(data$w) * torch_trace(torch_mm(private$torch_Sigma(data, params, index), private$torch_Omega(data, params))) + - sum(data$w[index,NULL] * (torch_exp(Z + .5 * S2) - data$Y[index] * Z - .5 * torch_log(S2))) + S2 <- torch_exp(params$psi[index]) + Z <- data$O[index] + params$M[index] + # 0.5 factor: KL term is (1/2)*tr(Omega * Sigma_q); Sigma here is the empirical mean cov + res <- 0.5 * sum(data$w) * torch_trace(torch_mm(private$torch_Sigma(data, params, index), private$torch_Omega(data, params))) + + sum(data$w[index,NULL] * (torch_exp(Z + .5 * S2) - data$Y[index] * Z - .5 * params$psi[index])) res }, From 910c32a5f4325ce24b3eb873e9533b25e137fb16 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 14:30:42 +0200 Subject: [PATCH 50/58] use psi in troch impl of PLNLDA --- R/PLNLDAfit-class.R | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/R/PLNLDAfit-class.R b/R/PLNLDAfit-class.R index 47da2f70..0c2c21c3 100644 --- a/R/PLNLDAfit-class.R +++ b/R/PLNLDAfit-class.R @@ -422,16 +422,16 @@ PLNLDAfit_diagonal <- R6Class( ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% torch_elbo = function(data, params, index=torch_tensor(1:self$n)) { - S2 <- torch_square(params$S[index]) - Z <- data$O[index] + params$M[index] # Z = O + M_full + S2 <- torch_exp(params$psi[index]) + Z <- data$O[index] + params$M[index] res <- .5 * sum(data$w[index]) * sum(torch_log(private$torch_sigma_diag(data, params, index))) + - sum(data$w[index,NULL] * (torch_exp(Z + .5 * S2) - data$Y[index] * Z - .5 * torch_log(S2))) + sum(data$w[index,NULL] * (torch_exp(Z + .5 * S2) - data$Y[index] * Z - .5 * params$psi[index])) res }, torch_sigma_diag = function(data, params, index=torch_tensor(1:self$n)) { - M_res <- params$M[index] - torch_mm(data$X[index], params$B) # M_res for covariance - torch_sum(data$w[index,NULL] * (torch_square(M_res) + torch_square(params$S[index])), 1) / sum(data$w[index]) + M_res <- params$M[index] - torch_mm(data$X[index], params$B) + torch_sum(data$w[index,NULL] * (torch_square(M_res) + torch_exp(params$psi[index])), 1) / sum(data$w[index]) }, torch_Sigma = function(data, params, index=torch_tensor(1:self$n)) { @@ -439,12 +439,12 @@ PLNLDAfit_diagonal <- R6Class( }, torch_vloglik = function(data, params) { - S2 <- torch_square(params$S) - M_res <- params$M - torch_mm(data$X, params$B) # M_res for KL terms + S2 <- torch_exp(params$psi) + M_res <- params$M - torch_mm(data$X, params$B) omega_diag <- torch_pow(private$torch_sigma_diag(data, params), -1) Ji <- .5 * self$p - rowSums(.logfactorial(as.matrix(data$Y))) + as.numeric( .5 * sum(torch_log(omega_diag)) + - torch_sum(data$Y * params$Z - params$A + .5 * torch_log(S2) - + torch_sum(data$Y * params$Z - params$A + .5 * params$psi - .5 * (torch_square(M_res) + S2) * omega_diag[NULL,], dim = 2) ) attr(Ji, "weights") <- as.numeric(data$w) @@ -514,16 +514,16 @@ PLNLDAfit_spherical <- R6Class( ## PRIVATE TORCH METHODS FOR OPTIMIZATION ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% torch_elbo = function(data, params, index=torch_tensor(1:self$n)) { - S2 <- torch_square(params$S[index]) - Z <- data$O[index] + params$M[index] # Z = O + M_full + S2 <- torch_exp(params$psi[index]) + Z <- data$O[index] + params$M[index] res <- .5 * sum(data$w[index]) * self$p * torch_log(private$torch_sigma2(data, params, index)) - - sum(data$w[index,NULL] * (data$Y[index] * Z - torch_exp(Z + .5 * S2) + .5 * torch_log(S2))) + sum(data$w[index,NULL] * (data$Y[index] * Z - torch_exp(Z + .5 * S2) + .5 * params$psi[index])) res }, torch_sigma2 = function(data, params, index=torch_tensor(1:self$n)) { - M_res <- params$M[index] - torch_mm(data$X[index], params$B) # M_res for covariance - sum(data$w[index, NULL] * (torch_square(M_res) + torch_square(params$S[index]))) / (sum(data$w[index]) * self$p) + M_res <- params$M[index] - torch_mm(data$X[index], params$B) + sum(data$w[index, NULL] * (torch_square(M_res) + torch_exp(params$psi[index]))) / (sum(data$w[index]) * self$p) }, torch_Sigma = function(data, params, index=torch_tensor(1:self$n)) { @@ -531,11 +531,12 @@ PLNLDAfit_spherical <- R6Class( }, torch_vloglik = function(data, params) { - S2 <- torch_pow(params$S, 2) - M_res <- params$M - torch_mm(data$X, params$B) # M_res for KL terms + S2 <- torch_exp(params$psi) + M_res <- params$M - torch_mm(data$X, params$B) sigma2 <- private$torch_sigma2(data, params) Ji <- .5 * self$p - rowSums(.logfactorial(as.matrix(data$Y))) + as.numeric( - torch_sum(data$Y * params$Z - params$A + .5 * torch_log(S2/sigma2) - .5 * (torch_pow(M_res, 2) + S2)/sigma2, dim = 2) + torch_sum(data$Y * params$Z - params$A + .5 * (params$psi - torch_log(sigma2)) - + .5 * (torch_pow(M_res, 2) + S2)/sigma2, dim = 2) ) attr(Ji, "weights") <- as.numeric(data$w) Ji From 7042e2bc58278755f2f1e644972201b97a0091c4 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 15:10:54 +0200 Subject: [PATCH 51/58] =?UTF-8?q?use=20log(S=C2=B2)=20in=20PLNPCA=20for=20?= =?UTF-8?q?all=20optimizer=20(toch,=20newton,=20CCSAQ)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- R/PLNPCAfit-class.R | 68 +++++++++------- inst/case_studies/oaks_tree.R | 14 +--- src/nlopt_rank_cov.cpp | 136 ++++++++++++++++---------------- src/spectral_rank_cov.cpp | 27 +++---- tests/testthat/test-plnpcafit.R | 2 +- 5 files changed, 124 insertions(+), 123 deletions(-) diff --git a/R/PLNPCAfit-class.R b/R/PLNPCAfit-class.R index d4b97d9d..882d0410 100644 --- a/R/PLNPCAfit-class.R +++ b/R/PLNPCAfit-class.R @@ -48,13 +48,13 @@ PLNPCAfit <- R6Class( private = list( C = NULL, svdCM = NULL, - S = NA , # rank-reduced variational variances (n × q), separate from PLNfit's S2 + S2 = NA , # rank-reduced variational variances (n × q) ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ## PRIVATE TORCH METHODS FOR RANK-CONSTRAINED OPTIMIZATION ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - torch_elbo_rank_core = function(data, M, S, B, C, index) { - S2 <- torch_square(S[index]) # (batch, q) + torch_elbo_rank_core = function(data, M, psi, B, C, index) { + S2 <- torch_exp(psi[index]) # (batch, q); ψ = log(S²) C2 <- torch_square(C) # (p, q) Z <- data$O[index] + torch_mm(M[index], torch_t(C)) + @@ -62,22 +62,22 @@ PLNPCAfit <- R6Class( A <- torch_exp(Z + 0.5 * torch_mm(S2, torch_t(C2))) lik_part <- torch_sum(data$w[index, NULL] * (A - data$Y[index] * Z)) kl_part <- 0.5 * torch_sum(data$w[index, NULL] * - (torch_square(M[index]) + S2 - torch_log(S2) - 1)) + (torch_square(M[index]) + S2 - psi[index] - 1)) lik_part + kl_part }, torch_elbo_rank = function(data, params, index = torch_tensor(1:self$n)) { - private$torch_elbo_rank_core(data, params$M, params$S, params$B, params$C, index) + private$torch_elbo_rank_core(data, params$M, params$psi, params$B, params$C, index) }, torch_vloglik_rank = function(data, params) { - S2 <- torch_square(params$S) + S2 <- torch_exp(params$psi) C2 <- torch_square(params$C) Z <- data$O + torch_mm(params$M, torch_t(params$C)) + torch_mm(data$X, params$B) A <- torch_exp(Z + 0.5 * torch_mm(S2, torch_t(C2))) Ji <- - torch_sum(.logfactorial_torch(data$Y), dim = 2) + torch_sum(data$Y * Z - A, dim = 2) - - 0.5 * torch_sum(torch_square(params$M) + S2 - torch_log(S2) - 1, dim = 2) + 0.5 * torch_sum(torch_square(params$M) + S2 - params$psi - 1, dim = 2) Ji <- .5 * self$p + as.numeric(Ji$cpu()) attr(Ji, "weights") <- as.numeric(data$w$cpu()) Ji @@ -140,9 +140,12 @@ PLNPCAfit <- R6Class( if (config$trace > 1) message(paste("optimizing with device:", config$device)) - n <- nrow(data$Y) - data <- lapply(data, torch_tensor, dtype = torch_float32(), device = config$device) + n <- nrow(data$Y) + data <- lapply(data, torch_tensor, dtype = torch_float32(), device = config$device) + S2_init <- params$S2 + params$S2 <- NULL params <- lapply(params, torch_tensor, dtype = torch_float32(), requires_grad = TRUE, device = config$device) + params$psi <- torch_tensor(log(S2_init), dtype = torch_float32(), requires_grad = TRUE, device = config$device) B <- torch_tensor(B, dtype = torch_float32(), device = config$device) C <- torch_tensor(C, dtype = torch_float32(), device = config$device) @@ -152,15 +155,17 @@ PLNPCAfit <- R6Class( config = config, n_obs = n, loss_fn = function(index) { - private$torch_elbo_rank_core(data, params$M, params$S, B, C, index) + private$torch_elbo_rank_core(data, params$M, params$psi, B, C, index) } ) params_r <- lapply(optim_out$params, function(x) as.matrix(x$cpu())) + params_r$S2 <- exp(params_r$psi) + params_r$psi <- NULL Ji_r <- private$torch_vloglik_rank(data, c(optim_out$params, list(B = B, C = C))) list( M = params_r$M, - S = params_r$S, + S2 = params_r$S2, Ji = Ji_r, monitoring = list( objective = optim_out$objective, @@ -175,8 +180,11 @@ PLNPCAfit <- R6Class( if (config$trace > 1) message(paste("optimizing with device:", config$device)) - data <- lapply(data, torch_tensor, dtype = torch_float32(), device = config$device) - params <- lapply(params, torch_tensor, dtype = torch_float32(), requires_grad = TRUE, device = config$device) + data <- lapply(data, torch_tensor, dtype = torch_float32(), device = config$device) + S2_init <- params$S2 + params$S2 <- NULL + params <- lapply(params, torch_tensor, dtype = torch_float32(), requires_grad = TRUE, device = config$device) + params$psi <- torch_tensor(log(S2_init), dtype = torch_float32(), requires_grad = TRUE, device = config$device) optim_out <- private$torch_optimize_rank_core( data = data, @@ -193,7 +201,7 @@ PLNPCAfit <- R6Class( data_r <- lapply(data, function(x) as.matrix(x$cpu())) q <- ncol(params_r$M) - S2_r <- params_r$S^2 + S2_r <- exp(params_r$psi) # ψ → S² C2_r <- params_r$C^2 Z_r <- data_r$O + params_r$M %*% t(params_r$C) + data_r$X %*% params_r$B A_r <- exp(Z_r + 0.5 * S2_r %*% t(C2_r)) @@ -206,14 +214,14 @@ PLNPCAfit <- R6Class( Ji_r <- .5 * self$p - rowSums(.logfactorial(as.matrix(data_r$Y))) + rowSums(data_r$Y * Z_r - A_r) - - 0.5 * rowSums(params_r$M^2 + S2_r - log(S2_r) - 1) + 0.5 * rowSums(params_r$M^2 + S2_r - params_r$psi - 1) attr(Ji_r, "weights") <- w_r list( B = params_r$B, C = params_r$C, M = params_r$M, - S = params_r$S, + S2 = S2_r, Z = Z_r, A = A_r, Sigma = Sigma_r, @@ -252,7 +260,7 @@ PLNPCAfit <- R6Class( } ### TODO: check that it is really better than initializing with zeros... private$M <- svdM$u[, 1:rank, drop = FALSE] %*% diag(svdM$d[1:rank], nrow = rank, ncol = rank) %*% t(svdM$v[1:rank, 1:rank, drop = FALSE]) - private$S <- matrix(0.1, self$n, rank) + private$S2 <- matrix(0.01, self$n, rank) private$C <- svdM$v[, 1:rank, drop = FALSE] %*% diag(svdM$d[1:rank], nrow = rank, ncol = rank)/sqrt(self$n) }, #' @description Reinitialize parameters for sequential warm-starting from a lower-rank fit. @@ -269,25 +277,25 @@ PLNPCAfit <- R6Class( private$C <- cbind(prev_fit$model_par$C, C_new_cols) private$M <- cbind(prev_fit$var_par$M, matrix(0, nrow = self$n, ncol = q_new - q_prev)) - private$S <- cbind(prev_fit$var_par$S, - matrix(0.1, nrow = self$n, ncol = q_new - q_prev)) + private$S2 <- cbind(prev_fit$var_par$S2, + matrix(0.01, nrow = self$n, ncol = q_new - q_prev)) private$B <- prev_fit$model_par$B }, #' @description Update a [`PLNPCAfit`] object #' @param M matrix of mean vectors for the variational approximation #' @param C matrix of PCA loadings (in the latent space) - #' @param S matrix of variance vectors for the variational approximation + #' @param S2 matrix of variational variances (n × q) #' @param Ji vector of variational lower bounds of the log-likelihoods (one value per sample) #' @param R2 approximate R^2 goodness-of-fit criterion #' @param Z matrix of latent vectors (includes covariates and offset effects) #' @param A matrix of fitted values #' @param monitoring a list with optimization monitoring quantities #' @return Update the current [`PLNPCAfit`] object - update = function(B=NA, Sigma=NA, Omega=NA, C=NA, M=NA, S=NA, Z=NA, A=NA, Ji=NA, R2=NA, monitoring=NA) { + update = function(B=NA, Sigma=NA, Omega=NA, C=NA, M=NA, S2=NA, Z=NA, A=NA, Ji=NA, R2=NA, monitoring=NA) { super$update(B = B, Sigma = Sigma, Omega = Omega, M = M, Z = Z, A = A, Ji = Ji, R2 = R2, monitoring = monitoring) - if (!anyNA(C)) private$C <- C - if (!anyNA(S)) private$S <- S + if (!anyNA(C)) private$C <- C + if (!anyNA(S2)) private$S2 <- S2 }, ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -295,7 +303,7 @@ PLNPCAfit <- R6Class( #' @description Call to the C++ optimizer and update of the relevant fields optimize = function(responses, covariates, offsets, weights, config) { args <- list(data = list(Y = responses, X = covariates, O = offsets, w = weights), - params = list(B = private$B, C = private$C, M = private$M, S = private$S), + params = list(B = private$B, C = private$C, M = private$M, S2 = private$S2), config = config) optim_out <- do.call(private$optimizer$main, args) do.call(self$update, optim_out) @@ -326,7 +334,7 @@ PLNPCAfit <- R6Class( ## Initialize the variational parameters with the appropriate new dimension of the data args <- list(data = list(Y = responses, X = covariates, O = offsets, w = weights), ## Initialize the variational parameters with the new dimension of the data - params = list(M = M_init, S = matrix(.1, n, q)), + params = list(M = M_init, S2 = matrix(.01, n, q)), B = private$B, C = private$C, config = control$config_optim) @@ -381,9 +389,9 @@ PLNPCAfit <- R6Class( 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) - if (!identical(private$S, NA)) { - rownames(private$S) <- rownames(responses) - colnames(private$S) <- 1:self$q + if (!identical(private$S2, NA)) { + rownames(private$S2) <- rownames(responses) + colnames(private$S2) <- 1:self$q } self$setVisualization() }, @@ -513,8 +521,8 @@ PLNPCAfit <- R6Class( ## ACTIVE BINDINGS ---- ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% active = list( - #' @field var_par variational parameters (M, S, S2) in the rank-q latent space - var_par = function() {list(M = private$M, S2 = private$S^2, S = private$S)}, + #' @field var_par variational parameters (M, S2) in the rank-q latent space + var_par = function() {list(M = private$M, S2 = private$S2)}, #' @field rank the dimension of the current model rank = function() {self$q}, #' @field vcov_model character: the model used for the residual covariance diff --git a/inst/case_studies/oaks_tree.R b/inst/case_studies/oaks_tree.R index af5206b1..2f1777e3 100644 --- a/inst/case_studies/oaks_tree.R +++ b/inst/case_studies/oaks_tree.R @@ -1,11 +1,6 @@ library(PLNmodels) library(factoextra) -## setting up future for parallelism -# nb_cores <- 10 -# options(future.fork.enable = TRUE) -# future::plan("multicore", workers = nb_cores) - ## get oaks data set data(oaks) @@ -71,7 +66,7 @@ myLDA_orientation <- PLNLDA(Abundance ~ 1 + offset(log(Offset)), grouping = orie plot(myLDA_orientation) ## Dimension reduction with PCA -system.time(myPLNPCAs <- PLNPCA(Abundance ~ 1 + offset(log(Offset)), data = oaks, ranks = 1:30)) # about 40 secs. +system.time(myPLNPCAs <- PLNPCA(Abundance ~ 1 + offset(log(Offset)), data = oaks, ranks = c(1, 5, 10, 20, 30))) plot(myPLNPCAs) myPLNPCA <- getBestModel(myPLNPCAs) plot(myPLNPCA, ind_cols = oaks$tree) @@ -83,7 +78,7 @@ factoextra::fviz_pca_biplot( ) + labs(col = "distance (cm)") + scale_color_viridis_d() ## Dimension reduction with PCA -system.time(myPLNPCAs_tree <- PLNPCA(Abundance ~ 0 + tree + offset(log(Offset)), data = oaks, ranks = 1:30)) # about 40 sec. with 20 cores +system.time(myPLNPCAs_tree <- PLNPCA(Abundance ~ 0 + tree + offset(log(Offset)), data = oaks, ranks = c(1, 5, 10, 20, 30))) plot(myPLNPCAs_tree) myPLNPCA_tree <- getBestModel(myPLNPCAs_tree) @@ -132,12 +127,9 @@ system.time(my_mixtures <- PLNmixture(Abundance ~ 0 + tree + distTOground + offs plot(my_mixtures, criteria = c("loglik", "ICL", "BIC"), reverse = TRUE) -myPLN <- my_mixtures %>% getBestModel("ICL") +myPLN <- my_mixtures %>% getModel(4) myPLN$plot_clustering_pca(main = 'clustering memberships in individual factor map') p <- myPLN$plot_clustering_data() aricode::ARI(myPLN$memberships, oaks$tree) - - -# future::plan("sequential") diff --git a/src/nlopt_rank_cov.cpp b/src/nlopt_rank_cov.cpp index 3dd31951..20da8c1f 100644 --- a/src/nlopt_rank_cov.cpp +++ b/src/nlopt_rank_cov.cpp @@ -9,13 +9,17 @@ // --------------------------------------------------------------------------------------- // Rank-constrained covariance +// +// Variational parameter: ψ = log(S²) (unconstrained) instead of S (bounded > 0). +// Interface: takes S2 (variance), converts to ψ = log(S²) before optimizing, returns S2. +// Gradient w.r.t. ψ: ½ · w ⊙ (S² ⊙ (1 + A·C²) − 1) [no 1/S singularity] // Rank (q) is already determined by param dimensions ; not passed anywhere // [[Rcpp::export]] Rcpp::List nlopt_optimize_rank( const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(B, C, M, S) + const Rcpp::List & params, // List(B, C, M, S2) const Rcpp::List & config // List of config values ) { // Conversion from R, prepare optimization @@ -23,62 +27,62 @@ Rcpp::List nlopt_optimize_rank( const arma::mat & X = Rcpp::as(data["X"]); // covariates (n,d) const arma::mat & O = Rcpp::as(data["O"]); // offsets (n,p) const arma::vec & w = Rcpp::as(data["w"]); // weights (n) - const auto init_B = Rcpp::as(params["B"]); // (d,p) - const auto init_C = Rcpp::as(params["C"]); // (p,q) - const auto init_M = Rcpp::as(params["M"]); // (n,q) - const auto init_S = Rcpp::as(params["S"]); // (n,q) + const auto init_B = Rcpp::as(params["B"]); // (d,p) + const auto init_C = Rcpp::as(params["C"]); // (p,q) + const auto init_M = Rcpp::as(params["M"]); // (n,q) + const arma::mat init_S2 = Rcpp::as(params["S2"]); // (n,q) variance + const arma::mat init_psi = arma::log(init_S2); // ψ = log(S²) - const auto metadata = tuple_metadata(init_B, init_C, init_M, init_S); - enum { B_ID, C_ID, M_ID, S_ID }; // Names for metadata indexes + const auto metadata = tuple_metadata(init_B, init_C, init_M, init_psi); + enum { B_ID, C_ID, M_ID, PSI_ID }; auto parameters = std::vector(metadata.packed_size); - metadata.map(parameters.data()) = init_B; - metadata.map(parameters.data()) = init_C; - metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = init_S; + metadata.map (parameters.data()) = init_B; + metadata.map (parameters.data()) = init_C; + metadata.map (parameters.data()) = init_M; + metadata.map(parameters.data()) = init_psi; // Optimize auto optimizer = new_nlopt_optimizer(config, parameters.size()); - std::vector objective_vec ; + std::vector objective_vec; objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); - const arma::mat Xw = X.each_col() % w; // fixed: precomputed once + const arma::mat Xw = X.each_col() % w; // precomputed once auto objective_and_grad = [&metadata, &O, &X, &Xw, &Y, &w, &objective_vec](const double * params, double * grad) -> double { - const arma::mat B = metadata.map(params); - const arma::mat C = metadata.map(params); - const arma::mat M = metadata.map(params); - const arma::mat S = metadata.map(params); + const arma::mat B = metadata.map (params); + const arma::mat C = metadata.map (params); + const arma::mat M = metadata.map (params); + const arma::mat psi = metadata.map(params); const arma::mat C2 = C % C; - arma::mat S2 = S % S; + const arma::mat S2 = arma::exp(psi); // S² = exp(ψ) arma::mat Z = O + X * B + M * C.t(); - arma::mat A = exp(Z + 0.5 * S2 * C2.t()); - double objective = accu(diagmat(w) * (A - Y % Z)) + 0.5 * accu(diagmat(w) * (M % M + S2 - log(S2) - 1.)); + arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); + double objective = accu(diagmat(w) * (A - Y % Z)) + + 0.5 * accu(diagmat(w) * (M % M + S2 - psi - 1.)); - metadata.map(grad) = Xw.t() * (A - Y); - metadata.map(grad) = (diagmat(w) * (A - Y)).t() * M + (A.t() * (S2.each_col() % w)) % C; - metadata.map(grad) = diagmat(w) * ((A - Y) * C + M); - metadata.map(grad) = diagmat(w) * (S - 1. / S + A * C2 % S); - - objective_vec.push_back(objective) ; + metadata.map (grad) = Xw.t() * (A - Y); + metadata.map (grad) = (diagmat(w) * (A - Y)).t() * M + (A.t() * (S2.each_col() % w)) % C; + metadata.map (grad) = diagmat(w) * ((A - Y) * C + M); + metadata.map(grad) = diagmat(w) * (0.5 * (S2 % (1. + A * C2) - 1.)); + objective_vec.push_back(objective); return objective; }; OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); // Model and variational parameters - arma::mat B = metadata.copy(parameters.data()); - arma::mat C = metadata.copy(parameters.data()); - arma::mat M = metadata.copy(parameters.data()); - arma::mat S = metadata.copy(parameters.data()); - arma::mat S2 = S % S; - arma::mat Sigma = C * (M.t() * (M.each_col() % w) + diagmat(sum(S2.each_col() % w, 0))) * C.t() / accu(w); - arma::mat Omega = C * inv_sympd((M.t() * (M.each_col() % w) + diagmat(sum(S2.each_col() % w, 0)))/accu(w)) * C.t() ; - // Element-wise log-likelihood - arma::mat Z = O + X * B + M * C.t(); - arma::mat A = exp(Z + 0.5 * S2 * (C % C).t()); - arma::mat loglik = arma::sum(Y % Z - A, 1) - 0.5 * sum(M % M + S2 - log(S2) - 1., 1) + ki(Y); + arma::mat B = metadata.copy (parameters.data()); + arma::mat C = metadata.copy (parameters.data()); + arma::mat M = metadata.copy (parameters.data()); + arma::mat psi = metadata.copy(parameters.data()); + arma::mat S2 = arma::exp(psi); + arma::mat Sigma = C * (M.t() * (M.each_col() % w) + arma::diagmat(arma::sum(S2.each_col() % w, 0))) * C.t() / accu(w); + arma::mat Omega = C * inv_sympd((M.t() * (M.each_col() % w) + arma::diagmat(arma::sum(S2.each_col() % w, 0))) / accu(w)) * C.t(); + arma::mat Z = O + X * B + M * C.t(); + arma::mat A = arma::exp(Z + 0.5 * S2 * (C % C).t()); + arma::mat loglik = arma::sum(Y % Z - A, 1) - 0.5 * arma::sum(M % M + S2 - psi - 1., 1) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; @@ -86,7 +90,7 @@ Rcpp::List nlopt_optimize_rank( Rcpp::Named("B", B), Rcpp::Named("C", C), Rcpp::Named("M", M), - Rcpp::Named("S", S), + Rcpp::Named("S2", S2), Rcpp::Named("Z", Z), Rcpp::Named("A", A), Rcpp::Named("Sigma", Sigma), @@ -108,7 +112,7 @@ Rcpp::List nlopt_optimize_rank( // [[Rcpp::export]] Rcpp::List nlopt_optimize_vestep_rank( const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(M, S) + const Rcpp::List & params, // List(M, S2) const arma::mat & B, // (d,p) const arma::mat & C, // (p,q) const Rcpp::List & config // List of config values @@ -118,55 +122,55 @@ Rcpp::List nlopt_optimize_vestep_rank( const arma::mat & X = Rcpp::as(data["X"]); // covariates (n,d) const arma::mat & O = Rcpp::as(data["O"]); // offsets (n,p) const arma::vec & w = Rcpp::as(data["w"]); // weights (n) - const auto init_M = Rcpp::as(params["M"]); // (n,q) - const auto init_S = Rcpp::as(params["S"]); // (n,q) + const auto init_M = Rcpp::as(params["M"]); // (n,q) + const arma::mat init_S2 = Rcpp::as(params["S2"]); // (n,q) variance + const arma::mat init_psi = arma::log(init_S2); // ψ = log(S²) - const auto metadata = tuple_metadata(init_M, init_S); - enum { M_ID, S_ID }; // Names for metadata indexes + const auto metadata = tuple_metadata(init_M, init_psi); + enum { M_ID, PSI_ID }; auto parameters = std::vector(metadata.packed_size); - metadata.map(parameters.data()) = init_M; - metadata.map(parameters.data()) = init_S; + metadata.map (parameters.data()) = init_M; + metadata.map(parameters.data()) = init_psi; // Optimize auto optimizer = new_nlopt_optimizer(config, parameters.size()); - std::vector objective_vec ; + std::vector objective_vec; objective_vec.reserve(nlopt_get_maxeval(optimizer.get())); const arma::mat C2 = C % C; - const arma::mat XB = X * B; // fixed: B not optimized in vestep + const arma::mat XB = X * B; auto objective_and_grad = [&metadata, &O, &XB, &Y, &w, &C, &C2, &objective_vec](const double * params, double * grad) -> double { - const arma::mat M = metadata.map(params); - const arma::mat S = metadata.map(params); - - arma::mat S2 = S % S; - arma::mat Z = O + XB + M * C.t(); - arma::mat A = exp(Z + 0.5 * S2 * C2.t()); - double objective = accu(diagmat(w) * (A - Y % Z)) + 0.5 * accu(diagmat(w) * (M % M + S2 - log(S2) - 1.)); + const arma::mat M = metadata.map (params); + const arma::mat psi = metadata.map(params); - metadata.map(grad) = diagmat(w) * ((A - Y) * C + M); - metadata.map(grad) = diagmat(w) * (S - 1. / S + A * C2 % S); + arma::mat S2 = arma::exp(psi); + arma::mat Z = O + XB + M * C.t(); + arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); + double objective = accu(diagmat(w) * (A - Y % Z)) + + 0.5 * accu(diagmat(w) * (M % M + S2 - psi - 1.)); - objective_vec.push_back(objective) ; + metadata.map (grad) = diagmat(w) * ((A - Y) * C + M); + metadata.map(grad) = diagmat(w) * (0.5 * (S2 % (1. + A * C2) - 1.)); + objective_vec.push_back(objective); return objective; }; OptimizerResult result = minimize_objective_on_parameters(optimizer.get(), objective_and_grad, parameters); // Model and variational parameters - arma::mat M = metadata.copy(parameters.data()); - arma::mat S = metadata.copy(parameters.data()); - arma::mat S2 = S % S; - // Element-wise log-likelihood - arma::mat Z = O + X * B + M * C.t(); - arma::mat A = exp(Z + 0.5 * S2 * (C % C).t()); - arma::mat loglik = arma::sum(Y % Z - A, 1) - 0.5 * sum(M % M + S2 - log(S2) - 1., 1) + ki(Y); + arma::mat M = metadata.copy (parameters.data()); + arma::mat psi = metadata.copy(parameters.data()); + arma::mat S2 = arma::exp(psi); + arma::mat Z = O + X * B + M * C.t(); + arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); + arma::mat loglik = arma::sum(Y % Z - A, 1) - 0.5 * arma::sum(M % M + S2 - psi - 1., 1) + ki(Y); Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); Ji.attr("weights") = w; return Rcpp::List::create( - Rcpp::Named("M") = M, - Rcpp::Named("S") = S, + Rcpp::Named("M") = M, + Rcpp::Named("S2") = S2, Rcpp::Named("Ji") = Ji, Rcpp::Named("monitoring", Rcpp::List::create( Rcpp::Named("status", static_cast(result.status)), diff --git a/src/spectral_rank_cov.cpp b/src/spectral_rank_cov.cpp index 0bc5a3e8..a3f2e56f 100644 --- a/src/spectral_rank_cov.cpp +++ b/src/spectral_rank_cov.cpp @@ -46,10 +46,10 @@ Rcpp::List spectral_optimize_rank( const arma::mat & X = Rcpp::as(data["X"]); const arma::mat & O = Rcpp::as(data["O"]); const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat C = Rcpp::as(params["C"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat C = Rcpp::as(params["C"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); // variational variance const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 10000; const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-10; @@ -58,10 +58,9 @@ Rcpp::List spectral_optimize_rank( const arma::mat Xw = X.each_col() % w; - // Initialise geometry with S exact + // Initialise geometry with S2 exact arma::mat C2 = C % C; - arma::mat psi = arma::log(S % S); - arma::mat S2 = arma::exp(psi); + arma::mat psi = arma::log(S2); arma::mat Z = O + X * B + M * C.t(); arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); psi = arma::clamp(-arma::log(1. + A * C2), -40., 0.); @@ -168,7 +167,6 @@ Rcpp::List spectral_optimize_rank( } // ---- Final output ---- - S = arma::exp(0.5 * psi); const double w_bar = arma::accu(w); arma::mat nSig = M.t() * (M.each_col() % w) + arma::diagmat(arma::sum(S2.each_col() % w, 0)); arma::mat Sigma = C * nSig * C.t() / w_bar; @@ -183,7 +181,7 @@ Rcpp::List spectral_optimize_rank( Rcpp::Named("B", B ), Rcpp::Named("C", C ), Rcpp::Named("M", M ), - Rcpp::Named("S", S ), + Rcpp::Named("S2", S2 ), Rcpp::Named("Z", Z ), Rcpp::Named("A", A ), Rcpp::Named("Sigma", Sigma), @@ -213,8 +211,8 @@ Rcpp::List spectral_optimize_vestep_rank( const arma::mat & X = Rcpp::as(data["X"]); const arma::mat & O = Rcpp::as(data["O"]); const arma::vec & w = Rcpp::as(data["w"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); // variational variance const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 10000; const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-10; @@ -224,8 +222,7 @@ Rcpp::List spectral_optimize_vestep_rank( const arma::mat C2 = C % C; const arma::mat XB = X * B; - arma::mat psi = arma::log(S % S); - arma::mat S2 = arma::exp(psi); + arma::mat psi = arma::log(S2); arma::mat Z = O + XB + M * C.t(); arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); psi = arma::clamp(-arma::log(1. + A * C2), -40., 0.); @@ -295,7 +292,7 @@ Rcpp::List spectral_optimize_vestep_rank( M = M_t; Z = Z_t; A = A_t; psi = psi_t; S2 = S2_t; } - S = arma::exp(0.5 * psi); + S2 = arma::exp(psi); Z = O + XB + M * C.t(); arma::vec loglik = arma::sum(Y % Z - A, 1) - 0.5 * arma::sum(M % M + S2 - psi - 1., 1) @@ -305,7 +302,7 @@ Rcpp::List spectral_optimize_vestep_rank( Ji.attr("weights") = w; return Rcpp::List::create( Rcpp::Named("M") = M, - Rcpp::Named("S") = S, + Rcpp::Named("S2") = S2, Rcpp::Named("Ji") = Ji, Rcpp::Named("monitoring", Rcpp::List::create( Rcpp::Named("status", 3 ), diff --git a/tests/testthat/test-plnpcafit.R b/tests/testthat/test-plnpcafit.R index f7fbcc1a..cfa7cda3 100644 --- a/tests/testthat/test-plnpcafit.R +++ b/tests/testthat/test-plnpcafit.R @@ -103,7 +103,7 @@ test_that("PLNPCA torch backend works for fit and project", { Y <- as.matrix(trichoptera$Abundance) expected_loglik_vec <- .5 * ncol(Y) - rowSums(PLNmodels:::.logfactorial(Y)) + rowSums(Y * torch_fit$latent - fitted(torch_fit)) - - .5 * rowSums(torch_fit$var_par$M^2 + torch_fit$var_par$S^2 - log(torch_fit$var_par$S^2) - 1) + .5 * rowSums(torch_fit$var_par$M^2 + torch_fit$var_par$S2 - log(torch_fit$var_par$S2) - 1) expect_equal(torch_fit$loglik_vec, expected_loglik_vec, tolerance = 1e-4, check.attributes = FALSE) From 6a9d34c6ddca2aa44aeaaad9c362d5ad6925b2c4 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 15:11:36 +0200 Subject: [PATCH 52/58] =?UTF-8?q?use=20log(S=C2=B2)=20in=20PLNPCA=20for=20?= =?UTF-8?q?all=20optimizer=20(toch,=20newton,=20CCSAQ)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- man/PLNPCAfit.Rd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/man/PLNPCAfit.Rd b/man/PLNPCAfit.Rd index 8e433ff8..8d3c9460 100644 --- a/man/PLNPCAfit.Rd +++ b/man/PLNPCAfit.Rd @@ -25,7 +25,7 @@ The function \code{\link{PLNPCA}}, the class \code{\link[=PLNPCAfamily]{PLNPCAfa \section{Active bindings}{ \if{html}{\out{
}} \describe{ - \item{\code{var_par}}{variational parameters (M, S, S2) in the rank-q latent space} + \item{\code{var_par}}{variational parameters (M, S2) in the rank-q latent space} \item{\code{rank}}{the dimension of the current model} @@ -142,7 +142,7 @@ are carried over; new columns are padded using the inception SVD (C) or zeros/0. Omega = NA, C = NA, M = NA, - S = NA, + S2 = NA, Z = NA, A = NA, Ji = NA, @@ -159,7 +159,7 @@ are carried over; new columns are padded using the inception SVD (C) or zeros/0. \item{\code{Omega}}{precision matrix of the latent variables. Inverse of Sigma.} \item{\code{C}}{matrix of PCA loadings (in the latent space)} \item{\code{M}}{matrix of mean vectors for the variational approximation} - \item{\code{S}}{matrix of variance vectors for the variational approximation} + \item{\code{S2}}{matrix of variational variances (n × q)} \item{\code{Z}}{matrix of latent vectors (includes covariates and offset effects)} \item{\code{A}}{matrix of fitted values} \item{\code{Ji}}{vector of variational lower bounds of the log-likelihoods (one value per sample)} From fa0345079c49944dac5a4cb5e424f8716c755483 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 18:13:21 +0200 Subject: [PATCH 53/58] renaming/reorganization --- R/PLN.R | 10 +- R/PLNLDA.R | 2 +- R/PLNLDAfit-class.R | 8 +- R/PLNPCA.R | 16 +- R/PLNPCAfit-class.R | 6 +- R/PLNfit-class.R | 20 +- R/PLNmixture.R | 4 +- R/PLNnetwork.R | 6 +- R/RcppExports.R | 44 +-- R/ZIPLN.R | 10 +- R/ZIPLNfit-class.R | 6 +- R/utils.R | 33 +- inst/backend_comparison.R | 4 +- inst/case_studies/oaks_tree.R | 4 +- inst/convergence_analysis.R | 4 +- man/PLNLDA_param.Rd | 4 +- man/PLNPCA_param.Rd | 16 +- man/PLN_param.Rd | 10 +- man/PLNmixture_param.Rd | 6 +- man/PLNnetwork_param.Rd | 8 +- man/ZIPLN_param.Rd | 6 +- man/ZIPLNnetwork_param.Rd | 4 +- src/RcppExports.cpp | 130 +++---- ...ianceTraits.h => builtin_covariance_pln.h} | 0 src/{newton_impl.h => builtin_newton_pln.h} | 6 +- src/builtin_optim_pln.cpp | 152 ++++++++ src/builtin_optim_plnpca.cpp | 362 ++++++++++++++++++ src/newton_diag_cov.cpp | 55 --- src/newton_fixed_cov.cpp | 30 -- src/newton_full_cov.cpp | 55 --- src/newton_rank_cov.cpp | 315 --------------- src/newton_spherical.cpp | 55 --- src/spectral_rank_cov.cpp | 314 --------------- src/utils.h | 2 +- tests/testthat/test-pln.R | 2 +- tests/testthat/test-plnfit.R | 4 +- 36 files changed, 682 insertions(+), 1031 deletions(-) rename src/{CovarianceTraits.h => builtin_covariance_pln.h} (100%) rename src/{newton_impl.h => builtin_newton_pln.h} (98%) create mode 100644 src/builtin_optim_pln.cpp create mode 100644 src/builtin_optim_plnpca.cpp delete mode 100644 src/newton_diag_cov.cpp delete mode 100644 src/newton_fixed_cov.cpp delete mode 100644 src/newton_full_cov.cpp delete mode 100644 src/newton_rank_cov.cpp delete mode 100644 src/newton_spherical.cpp delete mode 100644 src/spectral_rank_cov.cpp diff --git a/R/PLN.R b/R/PLN.R index 7e96822a..15cc8e43 100644 --- a/R/PLN.R +++ b/R/PLN.R @@ -54,9 +54,9 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { #' #' Helper to define list of parameters to control the PLN fit. All arguments have defaults. #' -#' @param backend optimization back used, either "homemade" (default), "nlopt", "hybrid" or "torch". -#' "homemade" is the built-in envelope-theorem Newton optimizer (does not depend on NLOPT). -#' "hybrid" runs nlopt first for basin finding, then switches to homemade for refinement. +#' @param backend optimization back used, either "builtin" (default), "nlopt", "hybrid" or "torch". +#' "builtin" is the built-in envelope-theorem Newton optimizer (does not depend on NLOPT). +#' "hybrid" runs nlopt first for basin finding, then switches to builtin for refinement. #' @param covariance character setting the model for the covariance matrix. Either "full", "diagonal", "spherical" or "fixed". Default is "full". #' @param Omega precision matrix of the latent variables. Inverse of Sigma. Must be specified if `covariance` is "fixed" #' @param config_optim a list for controlling the optimizer (either "nlopt" or "torch" backend). See details @@ -92,7 +92,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 #' -#' When "homemade" or "hybrid" backend is used, the following entries are relevant +#' When "builtin" or "hybrid" backend is used, the following entries are relevant #' * "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 #' * "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 #' * "maxit_em" stop the EM outer loop when the number of EM iterations exceeds maxit_em. Default is 50 @@ -107,7 +107,7 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { #' #' @export PLN_param <- function( - backend = c("homemade", "nlopt", "hybrid", "torch"), + backend = c("builtin", "nlopt", "hybrid", "torch"), trace = 1, covariance = c("full", "diagonal", "spherical", "fixed"), Omega = NULL, diff --git a/R/PLNLDA.R b/R/PLNLDA.R index 1decd50f..8fbfc98b 100644 --- a/R/PLNLDA.R +++ b/R/PLNLDA.R @@ -70,7 +70,7 @@ PLNLDA <- function(formula, data, subset, weights, grouping, control = PLNLDA_pa #' @inherit PLN_param details #' @export PLNLDA_param <- function( - backend = c("homemade", "nlopt", "hybrid", "torch"), + backend = c("builtin", "nlopt", "hybrid", "torch"), trace = 1, covariance = c("full", "diagonal", "spherical"), config_post = list(), diff --git a/R/PLNLDAfit-class.R b/R/PLNLDAfit-class.R index 0c2c21c3..5b94ad56 100644 --- a/R/PLNLDAfit-class.R +++ b/R/PLNLDAfit-class.R @@ -412,8 +412,8 @@ PLNLDAfit_diagonal <- R6Class( initialize = function(grouping, responses, covariates, offsets, weights, formula, control) { super$initialize(grouping, responses, covariates, offsets, weights, formula, control) private$setup_optimizer(control$backend, - nlopt_optimize_diagonal, newton_optimize_diagonal, - nlopt_optimize_vestep_diagonal, newton_optimize_vestep_diagonal) + nlopt_optimize_diagonal, builtin_optimize_diagonal, + nlopt_optimize_vestep_diagonal, builtin_optimize_vestep_diagonal) } ), private = list( @@ -504,8 +504,8 @@ PLNLDAfit_spherical <- R6Class( initialize = function(grouping, responses, covariates, offsets, weights, formula, control) { super$initialize(grouping, responses, covariates, offsets, weights, formula, control) private$setup_optimizer(control$backend, - nlopt_optimize_spherical, newton_optimize_spherical, - nlopt_optimize_vestep_spherical, newton_optimize_vestep_spherical) + nlopt_optimize_spherical, builtin_optimize_spherical, + nlopt_optimize_vestep_spherical, builtin_optimize_vestep_spherical) } ), private = list( diff --git a/R/PLNPCA.R b/R/PLNPCA.R index 943e3d3a..acea2182 100644 --- a/R/PLNPCA.R +++ b/R/PLNPCA.R @@ -58,14 +58,16 @@ PLNPCA <- function(formula, data, subset, weights, ranks = 1:5, control = PLNPCA #' #' Helper to define list of parameters to control the PLNPCA fit. All arguments have defaults. #' -#' @param backend optimization back used, either "nlopt", "torch", or "homemade". Default is "nlopt". -#' Use "homemade" for the built-in coordinate-Newton optimizer (exact diagonal Newton steps for -#' B, M, C, and closed-form update for S in log(S²) space), which does not depend on NLOPT. +#' @param backend optimization backend, either `"builtin"` (default, built-in joint L-BFGS +#' with strong Wolfe line search: all parameters B, C, M, ψ are optimised simultaneously +#' with a history of 10 curvature pairs; the Wolfe condition guarantees valid curvature +#' estimates at every step), `"nlopt"` (NLOPT/CCSAQ), +#' or `"torch"` (automatic differentiation via the torch package). #' @inheritParams PLN_param trace config_optim config_post inception #' @param sequential logical. If `TRUE`, ranks are fitted in ascending order and each model is #' warm-started from the converged solution of the previous rank: loadings C are augmented -#' with new columns from the inception SVD, while latent scores M and variances S are -#' padded with zeros / 0.1 respectively. Disables parallel fitting across ranks. +#' with new columns from the inception SVD, while latent scores M and variances S2 are +#' padded with zeros / 0.01 respectively. Disables parallel fitting across ranks. #' Default is `FALSE`. #' #' @return list of parameters configuring the fit. @@ -73,7 +75,7 @@ PLNPCA <- function(formula, data, subset, weights, ranks = 1:5, control = PLNPCA #' @inherit PLN_param details #' @export PLNPCA_param <- function( - backend = c("nlopt", "torch", "homemade"), + backend = c("builtin", "nlopt", "torch"), trace = 1 , config_optim = list() , config_post = list() , @@ -91,7 +93,7 @@ PLNPCA_param <- function( ## optimization config backend <- match.arg(backend) config_opt <- make_config_optim(backend, config_optim, trace, - homemade_default = config_default_spectral) + builtin_default = config_default_plnpca) config_opt$sequential <- sequential structure(list( diff --git a/R/PLNPCAfit-class.R b/R/PLNPCAfit-class.R index 882d0410..b9ff6963 100644 --- a/R/PLNPCAfit-class.R +++ b/R/PLNPCAfit-class.R @@ -247,12 +247,12 @@ PLNPCAfit <- R6Class( super$initialize(responses, covariates, offsets, weights, formula, control) if (control$backend == "torch") { private$optimizer$main <- private$torch_optimize_rank - } else if (control$backend == "homemade") { - private$optimizer$main <- spectral_optimize_rank + } else if (control$backend == "builtin") { + private$optimizer$main <- builtin_optimize_rank } else { private$optimizer$main <- nlopt_optimize_rank } - private$optimizer$vestep <- if (control$backend == "homemade") spectral_optimize_vestep_rank else nlopt_optimize_vestep_rank + private$optimizer$vestep <- if (control$backend == "builtin") builtin_optimize_vestep_rank else nlopt_optimize_vestep_rank if (!is.null(control$svdM)) { svdM <- control$svdM } else { diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index 859cdf57..25a7d912 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -340,7 +340,7 @@ PLNfit <- R6Class( nlopt_vestep_fn = NULL, newton_vestep_fn = NULL) { private$optimizer$main <- if (backend == "torch") { private$torch_optimize - } else if (backend == "homemade") { + } else if (backend == "builtin") { newton_fn } else if (backend == "hybrid") { make_hybrid_optimizer(nlopt_fn, newton_fn) @@ -349,7 +349,7 @@ PLNfit <- R6Class( } if (!is.null(nlopt_vestep_fn)) private$optimizer$vestep <- - if (backend %in% c("homemade", "hybrid")) newton_vestep_fn else nlopt_vestep_fn + if (backend %in% c("builtin", "hybrid")) newton_vestep_fn else nlopt_vestep_fn } ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -392,8 +392,8 @@ PLNfit <- R6Class( private$S2 <- start_point$S2 } private$setup_optimizer(control$backend, - nlopt_optimize_full, newton_optimize_full, - nlopt_optimize_vestep_full, newton_optimize_vestep_full) + nlopt_optimize_full, builtin_optimize_full, + nlopt_optimize_vestep_full, builtin_optimize_vestep_full) }, ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -772,8 +772,8 @@ PLNfit_diagonal <- R6Class( initialize = function(responses, covariates, offsets, weights, formula, control) { super$initialize(responses, covariates, offsets, weights, formula, control) private$setup_optimizer(control$backend, - nlopt_optimize_diagonal, newton_optimize_diagonal, - nlopt_optimize_vestep_diagonal, newton_optimize_vestep_diagonal) + nlopt_optimize_diagonal, builtin_optimize_diagonal, + nlopt_optimize_vestep_diagonal, builtin_optimize_vestep_diagonal) } ), private = list( @@ -858,8 +858,8 @@ PLNfit_spherical <- R6Class( initialize = function(responses, covariates, offsets, weights, formula, control) { super$initialize(responses, covariates, offsets, weights, formula, control) private$setup_optimizer(control$backend, - nlopt_optimize_spherical, newton_optimize_spherical, - nlopt_optimize_vestep_spherical, newton_optimize_vestep_spherical) + nlopt_optimize_spherical, builtin_optimize_spherical, + nlopt_optimize_vestep_spherical, builtin_optimize_vestep_spherical) } ), private = list( @@ -948,8 +948,8 @@ PLNfit_fixedcov <- R6Class( #' @description Initialize a [`PLNfit`] model initialize = function(responses, covariates, offsets, weights, formula, control) { super$initialize(responses, covariates, offsets, weights, formula, control) - private$setup_optimizer(control$backend, nlopt_optimize_fixed, newton_optimize_fixed, - nlopt_optimize_vestep_full, newton_optimize_vestep_full) + private$setup_optimizer(control$backend, nlopt_optimize_fixed, builtin_optimize_fixed, + nlopt_optimize_vestep_full, builtin_optimize_vestep_full) private$Omega <- control$Omega }, #' @description Call to the NLopt or TORCH optimizer and update of the relevant fields diff --git a/R/PLNmixture.R b/R/PLNmixture.R index e2bcb964..48251e8a 100644 --- a/R/PLNmixture.R +++ b/R/PLNmixture.R @@ -67,7 +67,7 @@ PLNmixture <- function(formula, data, subset, clusters = 1:5, control = PLNmixt #' #' Helper to define list of parameters to control the PLNmixture fit. All arguments have defaults. #' -#' @param backend optimization back used, either "homemade", "nlopt", "hybrid" or "torch". Default is "homemade". +#' @param backend optimization back used, either "builtin", "nlopt", "hybrid" or "torch". Default is "builtin". #' @param covariance character setting the model for the covariance matrices of the mixture components. Either "full", "diagonal" or "spherical". Default is "spherical". #' @param smoothing The smoothing to apply. Either, 'none', forward', 'backward' or 'both'. Default is 'both'. #' @param init_cl The initial clustering to apply. Either, 'kmeans', CAH' or a user defined clustering given as a list of clusterings, the size of which is equal to the number of clusters considered. Default is 'kmeans'. @@ -84,7 +84,7 @@ PLNmixture <- function(formula, data, subset, clusters = 1:5, control = PLNmixt #' @seealso [PLN_param()] #' @export PLNmixture_param <- function( - backend = c("homemade", "nlopt", "hybrid", "torch"), + backend = c("builtin", "nlopt", "hybrid", "torch"), trace = 1 , covariance = "spherical", init_cl = "kmeans" , diff --git a/R/PLNnetwork.R b/R/PLNnetwork.R index 7223e20e..08fb2d42 100644 --- a/R/PLNnetwork.R +++ b/R/PLNnetwork.R @@ -49,8 +49,8 @@ PLNnetwork <- function(formula, data, subset, weights, penalties = NULL, control #' #' Helper to define list of parameters to control the PLN fit. All arguments have defaults. #' -#' @param backend optimization back used, either "nlopt", "homemade", "hybrid" or "torch". Default is "nlopt". -#' Note: the "nlopt" backend converges better in PLNnetwork's outer glasso alternation than "homemade". +#' @param backend optimization back used, either "nlopt", "builtin", "hybrid" or "torch". Default is "nlopt". +#' Note: the "nlopt" backend converges better in PLNnetwork's outer glasso alternation than "builtin". #' @param inception_cov Covariance structure used for the inception model used to initialize the PLNfamily. Defaults to "full" and can be constrained to "diagonal" and "spherical". #' @param n_penalties an integer that specifies the number of values for the penalty grid when internally generated. Ignored when penalties is non `NULL` #' @param min_ratio the penalty grid ranges from the minimal value that produces a sparse to this value multiplied by `min_ratio`. Default is 0.1. @@ -68,7 +68,7 @@ PLNnetwork <- function(formula, data, subset, weights, penalties = NULL, control #' @seealso [PLN_param()] #' @export PLNnetwork_param <- function( - backend = c("nlopt", "homemade", "hybrid", "torch"), + backend = c("nlopt", "builtin", "hybrid", "torch"), inception_cov = c("full", "spherical", "diagonal"), trace = 1 , n_penalties = 30 , diff --git a/R/RcppExports.R b/R/RcppExports.R index aff36801..655492b7 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -1,40 +1,40 @@ # Generated by using Rcpp::compileAttributes() -> do not edit by hand # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 -newton_optimize_diagonal <- function(data, params, config) { - .Call('_PLNmodels_newton_optimize_diagonal', PACKAGE = 'PLNmodels', data, params, config) +builtin_optimize_full <- function(data, params, config) { + .Call('_PLNmodels_builtin_optimize_full', PACKAGE = 'PLNmodels', data, params, config) } -newton_optimize_vestep_diagonal <- function(data, params, B, Omega, config) { - .Call('_PLNmodels_newton_optimize_vestep_diagonal', PACKAGE = 'PLNmodels', data, params, B, Omega, config) +builtin_optimize_vestep_full <- function(data, params, B, Omega, config) { + .Call('_PLNmodels_builtin_optimize_vestep_full', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } -newton_optimize_fixed <- function(data, params, config) { - .Call('_PLNmodels_newton_optimize_fixed', PACKAGE = 'PLNmodels', data, params, config) +builtin_optimize_diagonal <- function(data, params, config) { + .Call('_PLNmodels_builtin_optimize_diagonal', PACKAGE = 'PLNmodels', data, params, config) } -newton_optimize_full <- function(data, params, config) { - .Call('_PLNmodels_newton_optimize_full', PACKAGE = 'PLNmodels', data, params, config) +builtin_optimize_vestep_diagonal <- function(data, params, B, Omega, config) { + .Call('_PLNmodels_builtin_optimize_vestep_diagonal', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } -newton_optimize_vestep_full <- function(data, params, B, Omega, config) { - .Call('_PLNmodels_newton_optimize_vestep_full', PACKAGE = 'PLNmodels', data, params, B, Omega, config) +builtin_optimize_spherical <- function(data, params, config) { + .Call('_PLNmodels_builtin_optimize_spherical', PACKAGE = 'PLNmodels', data, params, config) } -newton_optimize_rank <- function(data, params, config) { - .Call('_PLNmodels_newton_optimize_rank', PACKAGE = 'PLNmodels', data, params, config) +builtin_optimize_vestep_spherical <- function(data, params, B, Omega, config) { + .Call('_PLNmodels_builtin_optimize_vestep_spherical', PACKAGE = 'PLNmodels', data, params, B, Omega, config) } -newton_optimize_vestep_rank <- function(data, params, B, C, config) { - .Call('_PLNmodels_newton_optimize_vestep_rank', PACKAGE = 'PLNmodels', data, params, B, C, config) +builtin_optimize_fixed <- function(data, params, config) { + .Call('_PLNmodels_builtin_optimize_fixed', PACKAGE = 'PLNmodels', data, params, config) } -newton_optimize_spherical <- function(data, params, config) { - .Call('_PLNmodels_newton_optimize_spherical', PACKAGE = 'PLNmodels', data, params, config) +builtin_optimize_rank <- function(data, params, config) { + .Call('_PLNmodels_builtin_optimize_rank', PACKAGE = 'PLNmodels', data, params, config) } -newton_optimize_vestep_spherical <- function(data, params, B, Omega, config) { - .Call('_PLNmodels_newton_optimize_vestep_spherical', PACKAGE = 'PLNmodels', data, params, B, Omega, config) +builtin_optimize_vestep_rank <- function(data, params, B, C, config) { + .Call('_PLNmodels_builtin_optimize_vestep_rank', PACKAGE = 'PLNmodels', data, params, B, C, config) } nlopt_optimize_diagonal <- function(data, params, config) { @@ -133,14 +133,6 @@ cpp_test_packing <- function() { .Call('_PLNmodels_cpp_test_packing', PACKAGE = 'PLNmodels') } -spectral_optimize_rank <- function(data, params, config) { - .Call('_PLNmodels_spectral_optimize_rank', PACKAGE = 'PLNmodels', data, params, config) -} - -spectral_optimize_vestep_rank <- function(data, params, B, C, config) { - .Call('_PLNmodels_spectral_optimize_vestep_rank', PACKAGE = 'PLNmodels', data, params, B, C, config) -} - get_sandwich_variance_B <- function(Y, X, A, S, Sigma, Diag_Omega) { .Call('_PLNmodels_get_sandwich_variance_B', PACKAGE = 'PLNmodels', Y, X, A, S, Sigma, Diag_Omega) } diff --git a/R/ZIPLN.R b/R/ZIPLN.R index 72115551..89156703 100644 --- a/R/ZIPLN.R +++ b/R/ZIPLN.R @@ -68,19 +68,19 @@ ZIPLN <- function(formula, data, subset, zi = c("single", "row", "col"), control #' #' @inheritParams PLN_param #' @inheritParams PLNnetwork_param -#' @param backend optimization backend, either `"homemade"` (default, built-in Newton optimizer for the joint VE step) or `"nlopt"` (NLOPT-based CCSAQ). Unlike [PLN_param()], `"hybrid"` and `"torch"` are not supported. +#' @param backend optimization backend, either `"builtin"` (default, built-in Newton optimizer for the joint VE step) or `"nlopt"` (NLOPT-based CCSAQ). Unlike [PLN_param()], `"hybrid"` and `"torch"` are not supported. #' @param penalty a user-defined penalty to sparsify the residual covariance. Defaults to 0 (no sparsity). #' @return list of parameters used during the fit and post-processing steps #' #' @inherit PLN_param details #' @details See [PLN_param()] for a description of the generic `config_optim` entries (`ftol_rel`, `xtol_rel`, etc.). Like [PLNnetwork_param()], ZIPLN_param() has two parameters controlling the outer EM loop: #' * "ftol_out" outer solver stops when an optimization step changes the objective function by less than `ftol_out` multiplied by the absolute value of the parameter. Default is 1e-6 -#' * "maxit_out" outer solver stops when the number of iteration exceeds `maxit_out`. Default is 200 for "homemade", 100 for "nlopt" +#' * "maxit_out" outer solver stops when the number of iteration exceeds `maxit_out`. Default is 200 for "builtin", 100 for "nlopt" #' and one additional parameter controlling the form of the variational approximation of the zero inflation: #' #' @export ZIPLN_param <- function( - backend = c("homemade", "nlopt"), + backend = c("builtin", "nlopt"), trace = 1, covariance = c("full", "diagonal", "spherical", "fixed", "sparse"), Omega = NULL, @@ -104,12 +104,12 @@ ZIPLN_param <- function( config_pst[names(config_post)] <- config_post config_pst$trace <- trace - ## optimization config — mirrors PLN_param: "homemade" = Newton, "nlopt" = CCSAQ/etc. + ## optimization config — mirrors PLN_param: "builtin" = Newton, "nlopt" = CCSAQ/etc. backend <- match.arg(backend) config_opt <- make_config_optim(backend, config_optim, trace, extra = list( ftol_out = 1e-6, - maxit_out = if (backend == "homemade") 200L else 100L + maxit_out = if (backend == "builtin") 200L else 100L )) structure(list( diff --git a/R/ZIPLNfit-class.R b/R/ZIPLNfit-class.R index d005dbb9..9a87e529 100644 --- a/R/ZIPLNfit-class.R +++ b/R/ZIPLNfit-class.R @@ -139,13 +139,13 @@ ZIPLNfit <- R6Class( "col" = function(R, ...) list(Pi = matrix(colMeans(R), nrow(R), p, byrow = TRUE), B0 = matrix(NA, d0, p)), "covar" = function(R, init_B0, X0, config) { # optim_zipln_zipar_covar is always nlopt-based - if (control$backend == "homemade") config <- config_default_nlopt + if (control$backend == "builtin") config <- config_default_nlopt optim_zipln_zipar_covar(R, init_B0, X0, config) } ) private$optimizer$Omega <- optim_zipln_Omega_full - # Dispatch VE step on backend: "homemade" = Newton, "nlopt" = CCSAQ/etc. - private$optimizer$MS <- if (control$backend == "homemade") { + # Dispatch VE step on backend: "builtin" = Newton, "nlopt" = CCSAQ/etc. + private$optimizer$MS <- if (control$backend == "builtin") { ftol <- if (!is.null(control$config_optim$ftol_in)) control$config_optim$ftol_in else 1e-8 maxiter <- as.integer(if (!is.null(control$config_optim$maxeval)) control$config_optim$maxeval else 10000L) function(init_M, init_S2, Y, X, O, Pi, B, Omega, configuration) diff --git a/R/utils.R b/R/utils.R index a23fe504..709f1582 100644 --- a/R/utils.R +++ b/R/utils.R @@ -14,19 +14,19 @@ config_default_nlopt <- ) -config_default_homemade <- +config_default_builtin <- list( algorithm = "NEWTON", - backend = "homemade", + backend = "builtin", maxeval = 10000, ftol_in = 1e-8, maxit_em = 200, ftol_em = 1e-8 ) -# Hybrid backend: two-phase optimizer — nlopt/CCSAQ (phase 1) then homemade Newton (phase 2). +# Hybrid backend: two-phase optimizer — nlopt/CCSAQ (phase 1) then builtin Newton (phase 2). # Phase 1 (nlopt) uses looser tolerances to reach the basin quickly with quasi-Newton search. -# Phase 2 (homemade, envelope-theorem Newton) refines to the full requested tolerance. +# Phase 2 (builtin, envelope-theorem Newton) refines to the full requested tolerance. # Returns a closure with the same (data, params, config) signature as the C++ wrappers. #' @importFrom utils modifyList make_hybrid_optimizer <- function(opt_nlopt, opt_newton) { @@ -38,7 +38,7 @@ make_hybrid_optimizer <- function(opt_nlopt, opt_newton) { )) res1 <- opt_nlopt(data, params, config1) params2 <- modifyList(params, list(B = res1$B, M = res1$M, S2 = res1$S2)) - # Phase 2: homemade Newton with full tolerance + # Phase 2: builtin Newton with full tolerance res2 <- opt_newton(data, params2, config) res2$monitoring$objective <- c(res1$monitoring$objective, res2$monitoring$objective) res2$monitoring$iterations <- res1$monitoring$iterations + res2$monitoring$iterations @@ -47,18 +47,13 @@ make_hybrid_optimizer <- function(opt_nlopt, opt_newton) { } } -# Spectral gradient method (PLNPCA homemade backend): needs tighter tolerance -# than the nlopt default (1e-8) because GLL nonmonotone acceptance causes -# objective oscillations that fool consecutive convergence at 1e-8 into -# stopping prematurely at suboptimal local minima. 1e-9 balances quality and -# speed: on typical datasets spectral matches or exceeds NLOPT quality in -# comparable wall-clock time. -config_default_spectral <- +# PLNPCA builtin backend: joint L-BFGS on [vec(B); vec(C); vec(M); vec(ψ)] with strong Wolfe +# line search (m=10 pairs). Only maxeval and ftol_in are read by the C++ optimizer. +config_default_plnpca <- list( - algorithm = "SPECTRAL", - backend = "homemade", - maxeval = 10000, - ftol_in = 1e-9 + backend = "builtin", + maxeval = 10000, + ftol_in = 1e-8 ) config_default_torch <- @@ -81,12 +76,12 @@ config_default_torch <- ) ## Build the optimizer config list from a backend name and user overrides. -## `homemade_default` lets PLNPCA pass config_default_spectral instead of config_default_homemade. +## `builtin_default` lets PLNPCA pass config_default_plnpca instead of config_default_builtin. ## `extra` is a named list of additional defaults applied BEFORE user overrides (so the user can ## still override them), used for outer-loop parameters like ftol_em/maxit_em in PLNnetwork and ## PLNmixture. make_config_optim <- function(backend, config_optim, trace, - homemade_default = config_default_homemade, + builtin_default = config_default_builtin, extra = list()) { config_opt <- if (backend == "nlopt") { stopifnot(config_optim$algorithm %in% available_algorithms_nlopt) @@ -95,7 +90,7 @@ make_config_optim <- function(backend, config_optim, trace, stopifnot(config_optim$algorithm %in% available_algorithms_torch) config_default_torch } else { - homemade_default + builtin_default } config_opt$trace <- trace config_opt[names(extra)] <- extra diff --git a/inst/backend_comparison.R b/inst/backend_comparison.R index df169a8c..de4ff3a8 100644 --- a/inst/backend_comparison.R +++ b/inst/backend_comparison.R @@ -1,5 +1,5 @@ ## ============================================================ -## Backend comparison: homemade Newton vs nlopt/CCSAQ +## Backend comparison: builtin Newton vs nlopt/CCSAQ ## Metrics: computation time, iterations, final loglik ## Datasets: trichoptera, barents, mollusk, oaks, microcosm, scRNA ## Covariances: full, diagonal, spherical (including scRNA full) @@ -13,7 +13,7 @@ suppressPackageStartupMessages({ library(tidyr) }) -ctrl_newton <- function(cov) PLN_param(backend = "homemade", covariance = cov, trace = 0) +ctrl_newton <- function(cov) PLN_param(backend = "builtin", covariance = cov, trace = 0) ctrl_nlopt <- function(cov) PLN_param(backend = "nlopt", covariance = cov, trace = 0) ## ---- Helper: fit one model with timing, return summary row ---- diff --git a/inst/case_studies/oaks_tree.R b/inst/case_studies/oaks_tree.R index 2f1777e3..4f6b42a7 100644 --- a/inst/case_studies/oaks_tree.R +++ b/inst/case_studies/oaks_tree.R @@ -66,7 +66,7 @@ myLDA_orientation <- PLNLDA(Abundance ~ 1 + offset(log(Offset)), grouping = orie plot(myLDA_orientation) ## Dimension reduction with PCA -system.time(myPLNPCAs <- PLNPCA(Abundance ~ 1 + offset(log(Offset)), data = oaks, ranks = c(1, 5, 10, 20, 30))) +system.time(myPLNPCAs <- PLNPCA(Abundance ~ 1 + offset(log(Offset)), data = oaks, ranks = c(1, 5, 10, 20, 30, 35))) plot(myPLNPCAs) myPLNPCA <- getBestModel(myPLNPCAs) plot(myPLNPCA, ind_cols = oaks$tree) @@ -78,7 +78,7 @@ factoextra::fviz_pca_biplot( ) + labs(col = "distance (cm)") + scale_color_viridis_d() ## Dimension reduction with PCA -system.time(myPLNPCAs_tree <- PLNPCA(Abundance ~ 0 + tree + offset(log(Offset)), data = oaks, ranks = c(1, 5, 10, 20, 30))) +system.time(myPLNPCAs_tree <- PLNPCA(Abundance ~ 0 + tree + offset(log(Offset)), data = oaks, ranks = c(1, 5, 10, 20, 30, 35))) plot(myPLNPCAs_tree) myPLNPCA_tree <- getBestModel(myPLNPCAs_tree) diff --git a/inst/convergence_analysis.R b/inst/convergence_analysis.R index 8769a6f4..d109df59 100644 --- a/inst/convergence_analysis.R +++ b/inst/convergence_analysis.R @@ -1,5 +1,5 @@ ## ============================================================ -## Convergence analysis of the homemade Newton backend +## Convergence analysis of the builtin Newton backend ## Datasets: trichoptera (n=49, p=17), barents (n=89, p=30), ## mollusk (n=163, p=32), oaks (n=116, p=114), ## microcosm (n=880, p=259), scRNA (n=3918, p=500) @@ -15,7 +15,7 @@ suppressPackageStartupMessages({ library(tidyr) }) -ctrl <- function(cov) PLN_param(backend = "homemade", covariance = cov, trace = 0) +ctrl <- function(cov) PLN_param(backend = "builtin", covariance = cov, trace = 0) ## ---- trichoptera (n=49, p=17) ---- cat("Fitting trichoptera...\n") diff --git a/man/PLNLDA_param.Rd b/man/PLNLDA_param.Rd index a19271ff..26e65cde 100644 --- a/man/PLNLDA_param.Rd +++ b/man/PLNLDA_param.Rd @@ -5,7 +5,7 @@ \title{Control of a PLNLDA fit} \usage{ PLNLDA_param( - backend = c("homemade", "nlopt", "hybrid", "torch"), + backend = c("builtin", "nlopt", "hybrid", "torch"), trace = 1, covariance = c("full", "diagonal", "spherical"), config_post = list(), @@ -62,7 +62,7 @@ When "torch" backend is used (only for PLN and PLNLDA for now), the following en \item "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 } -When "homemade" or "hybrid" backend is used, the following entries are relevant +When "builtin" or "hybrid" backend is used, the following entries are relevant \itemize{ \item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 \item "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 diff --git a/man/PLNPCA_param.Rd b/man/PLNPCA_param.Rd index 7e0e9386..f268f543 100644 --- a/man/PLNPCA_param.Rd +++ b/man/PLNPCA_param.Rd @@ -5,7 +5,7 @@ \title{Control of PLNPCA fit} \usage{ PLNPCA_param( - backend = c("nlopt", "torch", "homemade"), + backend = c("builtin", "nlopt", "torch"), trace = 1, config_optim = list(), config_post = list(), @@ -14,9 +14,11 @@ PLNPCA_param( ) } \arguments{ -\item{backend}{optimization back used, either "nlopt", "torch", or "homemade". Default is "nlopt". -Use "homemade" for the built-in coordinate-Newton optimizer (exact diagonal Newton steps for -B, M, C, and closed-form update for S in log(S²) space), which does not depend on NLOPT.} +\item{backend}{optimization backend, either \code{"builtin"} (default, built-in joint L-BFGS +with strong Wolfe line search: all parameters B, C, M, ψ are optimised simultaneously +with a history of 10 curvature pairs; the Wolfe condition guarantees valid curvature +estimates at every step), \code{"nlopt"} (NLOPT/CCSAQ), +or \code{"torch"} (automatic differentiation via the torch package).} \item{trace}{a integer for verbosity.} @@ -30,8 +32,8 @@ which sometimes speeds up the inference.} \item{sequential}{logical. If \code{TRUE}, ranks are fitted in ascending order and each model is warm-started from the converged solution of the previous rank: loadings C are augmented -with new columns from the inception SVD, while latent scores M and variances S are -padded with zeros / 0.1 respectively. Disables parallel fitting across ranks. +with new columns from the inception SVD, while latent scores M and variances S2 are +padded with zeros / 0.01 respectively. Disables parallel fitting across ranks. Default is \code{FALSE}.} } \value{ @@ -68,7 +70,7 @@ When "torch" backend is used (only for PLN and PLNLDA for now), the following en \item "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 } -When "homemade" or "hybrid" backend is used, the following entries are relevant +When "builtin" or "hybrid" backend is used, the following entries are relevant \itemize{ \item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 \item "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 diff --git a/man/PLN_param.Rd b/man/PLN_param.Rd index 4a2ecee0..6327b261 100644 --- a/man/PLN_param.Rd +++ b/man/PLN_param.Rd @@ -5,7 +5,7 @@ \title{Control of a PLN fit} \usage{ PLN_param( - backend = c("homemade", "nlopt", "hybrid", "torch"), + backend = c("builtin", "nlopt", "hybrid", "torch"), trace = 1, covariance = c("full", "diagonal", "spherical", "fixed"), Omega = NULL, @@ -16,9 +16,9 @@ PLN_param( ) } \arguments{ -\item{backend}{optimization back used, either "homemade" (default), "nlopt", "hybrid" or "torch". -"homemade" is the built-in envelope-theorem Newton optimizer (does not depend on NLOPT). -"hybrid" runs nlopt first for basin finding, then switches to homemade for refinement.} +\item{backend}{optimization back used, either "builtin" (default), "nlopt", "hybrid" or "torch". +"builtin" is the built-in envelope-theorem Newton optimizer (does not depend on NLOPT). +"hybrid" runs nlopt first for basin finding, then switches to builtin for refinement.} \item{trace}{a integer for verbosity.} @@ -70,7 +70,7 @@ When "torch" backend is used (only for PLN and PLNLDA for now), the following en \item "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 } -When "homemade" or "hybrid" backend is used, the following entries are relevant +When "builtin" or "hybrid" backend is used, the following entries are relevant \itemize{ \item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 \item "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 diff --git a/man/PLNmixture_param.Rd b/man/PLNmixture_param.Rd index 1e6d4842..3107dee0 100644 --- a/man/PLNmixture_param.Rd +++ b/man/PLNmixture_param.Rd @@ -5,7 +5,7 @@ \title{Control of a PLNmixture fit} \usage{ PLNmixture_param( - backend = c("homemade", "nlopt", "hybrid", "torch"), + backend = c("builtin", "nlopt", "hybrid", "torch"), trace = 1, covariance = "spherical", init_cl = "kmeans", @@ -16,7 +16,7 @@ PLNmixture_param( ) } \arguments{ -\item{backend}{optimization back used, either "homemade", "nlopt", "hybrid" or "torch". Default is "homemade".} +\item{backend}{optimization back used, either "builtin", "nlopt", "hybrid" or "torch". Default is "builtin".} \item{trace}{a integer for verbosity.} @@ -68,7 +68,7 @@ When "torch" backend is used (only for PLN and PLNLDA for now), the following en \item "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 } -When "homemade" or "hybrid" backend is used, the following entries are relevant +When "builtin" or "hybrid" backend is used, the following entries are relevant \itemize{ \item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 \item "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 diff --git a/man/PLNnetwork_param.Rd b/man/PLNnetwork_param.Rd index 7c12d380..2a9e4017 100644 --- a/man/PLNnetwork_param.Rd +++ b/man/PLNnetwork_param.Rd @@ -5,7 +5,7 @@ \title{Control of PLNnetwork fit} \usage{ PLNnetwork_param( - backend = c("nlopt", "homemade", "hybrid", "torch"), + backend = c("nlopt", "builtin", "hybrid", "torch"), inception_cov = c("full", "spherical", "diagonal"), trace = 1, n_penalties = 30, @@ -18,8 +18,8 @@ PLNnetwork_param( ) } \arguments{ -\item{backend}{optimization back used, either "nlopt", "homemade", "hybrid" or "torch". Default is "nlopt". -Note: the "nlopt" backend converges better in PLNnetwork's outer glasso alternation than "homemade".} +\item{backend}{optimization back used, either "nlopt", "builtin", "hybrid" or "torch". Default is "nlopt". +Note: the "nlopt" backend converges better in PLNnetwork's outer glasso alternation than "builtin".} \item{inception_cov}{Covariance structure used for the inception model used to initialize the PLNfamily. Defaults to "full" and can be constrained to "diagonal" and "spherical".} @@ -75,7 +75,7 @@ When "torch" backend is used (only for PLN and PLNLDA for now), the following en \item "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 } -When "homemade" or "hybrid" backend is used, the following entries are relevant +When "builtin" or "hybrid" backend is used, the following entries are relevant \itemize{ \item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 \item "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 diff --git a/man/ZIPLN_param.Rd b/man/ZIPLN_param.Rd index 54a83ac0..51e675cd 100644 --- a/man/ZIPLN_param.Rd +++ b/man/ZIPLN_param.Rd @@ -5,7 +5,7 @@ \title{Control of a ZIPLN fit} \usage{ ZIPLN_param( - backend = c("homemade", "nlopt"), + backend = c("builtin", "nlopt"), trace = 1, covariance = c("full", "diagonal", "spherical", "fixed", "sparse"), Omega = NULL, @@ -18,7 +18,7 @@ ZIPLN_param( ) } \arguments{ -\item{backend}{optimization backend, either \code{"homemade"} (default, built-in Newton optimizer for the joint VE step) or \code{"nlopt"} (NLOPT-based CCSAQ). Unlike \code{\link[=PLN_param]{PLN_param()}}, \code{"hybrid"} and \code{"torch"} are not supported.} +\item{backend}{optimization backend, either \code{"builtin"} (default, built-in Newton optimizer for the joint VE step) or \code{"nlopt"} (NLOPT-based CCSAQ). Unlike \code{\link[=PLN_param]{PLN_param()}}, \code{"hybrid"} and \code{"torch"} are not supported.} \item{trace}{a integer for verbosity.} @@ -50,7 +50,7 @@ Helper to define list of parameters to control the ZIPLN fit. All arguments have See \code{\link[=PLN_param]{PLN_param()}} for a description of the generic \code{config_optim} entries (\code{ftol_rel}, \code{xtol_rel}, etc.). Like \code{\link[=PLNnetwork_param]{PLNnetwork_param()}}, ZIPLN_param() has two parameters controlling the outer EM loop: \itemize{ \item "ftol_out" outer solver stops when an optimization step changes the objective function by less than \code{ftol_out} multiplied by the absolute value of the parameter. Default is 1e-6 -\item "maxit_out" outer solver stops when the number of iteration exceeds \code{maxit_out}. Default is 200 for "homemade", 100 for "nlopt" +\item "maxit_out" outer solver stops when the number of iteration exceeds \code{maxit_out}. Default is 200 for "builtin", 100 for "nlopt" and one additional parameter controlling the form of the variational approximation of the zero inflation: } } diff --git a/man/ZIPLNnetwork_param.Rd b/man/ZIPLNnetwork_param.Rd index 0705812e..22e1ca25 100644 --- a/man/ZIPLNnetwork_param.Rd +++ b/man/ZIPLNnetwork_param.Rd @@ -18,8 +18,8 @@ ZIPLNnetwork_param( ) } \arguments{ -\item{backend}{optimization back used, either "nlopt", "homemade", "hybrid" or "torch". Default is "nlopt". -Note: the "nlopt" backend converges better in PLNnetwork's outer glasso alternation than "homemade".} +\item{backend}{optimization back used, either "nlopt", "builtin", "hybrid" or "torch". Default is "nlopt". +Note: the "nlopt" backend converges better in PLNnetwork's outer glasso alternation than "builtin".} \item{inception_cov}{Covariance structure used for the inception model used to initialize the PLNfamily. Defaults to "full" and can be constrained to "diagonal" and "spherical".} diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index f681a27b..8fbedb77 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -11,22 +11,22 @@ Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); #endif -// newton_optimize_diagonal -Rcpp::List newton_optimize_diagonal(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_newton_optimize_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +// builtin_optimize_full +Rcpp::List builtin_optimize_full(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_builtin_optimize_full(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(newton_optimize_diagonal(data, params, config)); + rcpp_result_gen = Rcpp::wrap(builtin_optimize_full(data, params, config)); return rcpp_result_gen; END_RCPP } -// newton_optimize_vestep_diagonal -Rcpp::List newton_optimize_vestep_diagonal(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_newton_optimize_vestep_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { +// builtin_optimize_vestep_full +Rcpp::List builtin_optimize_vestep_full(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_builtin_optimize_vestep_full(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; @@ -35,104 +35,104 @@ BEGIN_RCPP Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(newton_optimize_vestep_diagonal(data, params, B, Omega, config)); + rcpp_result_gen = Rcpp::wrap(builtin_optimize_vestep_full(data, params, B, Omega, config)); return rcpp_result_gen; END_RCPP } -// newton_optimize_fixed -Rcpp::List newton_optimize_fixed(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_newton_optimize_fixed(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +// builtin_optimize_diagonal +Rcpp::List builtin_optimize_diagonal(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_builtin_optimize_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(newton_optimize_fixed(data, params, config)); + rcpp_result_gen = Rcpp::wrap(builtin_optimize_diagonal(data, params, config)); return rcpp_result_gen; END_RCPP } -// newton_optimize_full -Rcpp::List newton_optimize_full(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_newton_optimize_full(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +// builtin_optimize_vestep_diagonal +Rcpp::List builtin_optimize_vestep_diagonal(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_builtin_optimize_vestep_diagonal(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(newton_optimize_full(data, params, config)); + rcpp_result_gen = Rcpp::wrap(builtin_optimize_vestep_diagonal(data, params, B, Omega, config)); return rcpp_result_gen; END_RCPP } -// newton_optimize_vestep_full -Rcpp::List newton_optimize_vestep_full(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_newton_optimize_vestep_full(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { +// builtin_optimize_spherical +Rcpp::List builtin_optimize_spherical(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_builtin_optimize_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(newton_optimize_vestep_full(data, params, B, Omega, config)); + rcpp_result_gen = Rcpp::wrap(builtin_optimize_spherical(data, params, config)); return rcpp_result_gen; END_RCPP } -// newton_optimize_rank -Rcpp::List newton_optimize_rank(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_newton_optimize_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +// builtin_optimize_vestep_spherical +Rcpp::List builtin_optimize_vestep_spherical(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_builtin_optimize_vestep_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(newton_optimize_rank(data, params, config)); + rcpp_result_gen = Rcpp::wrap(builtin_optimize_vestep_spherical(data, params, B, Omega, config)); return rcpp_result_gen; END_RCPP } -// newton_optimize_vestep_rank -Rcpp::List newton_optimize_vestep_rank(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& C, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_newton_optimize_vestep_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP CSEXP, SEXP configSEXP) { +// builtin_optimize_fixed +Rcpp::List builtin_optimize_fixed(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_builtin_optimize_fixed(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type C(CSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(newton_optimize_vestep_rank(data, params, B, C, config)); + rcpp_result_gen = Rcpp::wrap(builtin_optimize_fixed(data, params, config)); return rcpp_result_gen; END_RCPP } -// newton_optimize_spherical -Rcpp::List newton_optimize_spherical(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_newton_optimize_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { +// builtin_optimize_rank +Rcpp::List builtin_optimize_rank(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_builtin_optimize_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(newton_optimize_spherical(data, params, config)); + rcpp_result_gen = Rcpp::wrap(builtin_optimize_rank(data, params, config)); return rcpp_result_gen; END_RCPP } -// newton_optimize_vestep_spherical -Rcpp::List newton_optimize_vestep_spherical(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& Omega, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_newton_optimize_vestep_spherical(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP OmegaSEXP, SEXP configSEXP) { +// builtin_optimize_vestep_rank +Rcpp::List builtin_optimize_vestep_rank(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& C, const Rcpp::List& config); +RcppExport SEXP _PLNmodels_builtin_optimize_vestep_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP CSEXP, SEXP configSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; Rcpp::RNGScope rcpp_rngScope_gen; Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type Omega(OmegaSEXP); + Rcpp::traits::input_parameter< const arma::mat& >::type C(CSEXP); Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(newton_optimize_vestep_spherical(data, params, B, Omega, config)); + rcpp_result_gen = Rcpp::wrap(builtin_optimize_vestep_rank(data, params, B, C, config)); return rcpp_result_gen; END_RCPP } @@ -494,34 +494,6 @@ BEGIN_RCPP return rcpp_result_gen; END_RCPP } -// spectral_optimize_rank -Rcpp::List spectral_optimize_rank(const Rcpp::List& data, const Rcpp::List& params, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_spectral_optimize_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP configSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(spectral_optimize_rank(data, params, config)); - return rcpp_result_gen; -END_RCPP -} -// spectral_optimize_vestep_rank -Rcpp::List spectral_optimize_vestep_rank(const Rcpp::List& data, const Rcpp::List& params, const arma::mat& B, const arma::mat& C, const Rcpp::List& config); -RcppExport SEXP _PLNmodels_spectral_optimize_vestep_rank(SEXP dataSEXP, SEXP paramsSEXP, SEXP BSEXP, SEXP CSEXP, SEXP configSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const Rcpp::List& >::type data(dataSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type params(paramsSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type B(BSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type C(CSEXP); - Rcpp::traits::input_parameter< const Rcpp::List& >::type config(configSEXP); - rcpp_result_gen = Rcpp::wrap(spectral_optimize_vestep_rank(data, params, B, C, config)); - return rcpp_result_gen; -END_RCPP -} // get_sandwich_variance_B arma::mat get_sandwich_variance_B(const arma::mat& Y, const arma::mat& X, const arma::mat& A, const arma::mat& S, const arma::mat& Sigma, const arma::vec& Diag_Omega); RcppExport SEXP _PLNmodels_get_sandwich_variance_B(SEXP YSEXP, SEXP XSEXP, SEXP ASEXP, SEXP SSEXP, SEXP SigmaSEXP, SEXP Diag_OmegaSEXP) { @@ -540,15 +512,15 @@ END_RCPP } static const R_CallMethodDef CallEntries[] = { - {"_PLNmodels_newton_optimize_diagonal", (DL_FUNC) &_PLNmodels_newton_optimize_diagonal, 3}, - {"_PLNmodels_newton_optimize_vestep_diagonal", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_diagonal, 5}, - {"_PLNmodels_newton_optimize_fixed", (DL_FUNC) &_PLNmodels_newton_optimize_fixed, 3}, - {"_PLNmodels_newton_optimize_full", (DL_FUNC) &_PLNmodels_newton_optimize_full, 3}, - {"_PLNmodels_newton_optimize_vestep_full", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_full, 5}, - {"_PLNmodels_newton_optimize_rank", (DL_FUNC) &_PLNmodels_newton_optimize_rank, 3}, - {"_PLNmodels_newton_optimize_vestep_rank", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_rank, 5}, - {"_PLNmodels_newton_optimize_spherical", (DL_FUNC) &_PLNmodels_newton_optimize_spherical, 3}, - {"_PLNmodels_newton_optimize_vestep_spherical", (DL_FUNC) &_PLNmodels_newton_optimize_vestep_spherical, 5}, + {"_PLNmodels_builtin_optimize_full", (DL_FUNC) &_PLNmodels_builtin_optimize_full, 3}, + {"_PLNmodels_builtin_optimize_vestep_full", (DL_FUNC) &_PLNmodels_builtin_optimize_vestep_full, 5}, + {"_PLNmodels_builtin_optimize_diagonal", (DL_FUNC) &_PLNmodels_builtin_optimize_diagonal, 3}, + {"_PLNmodels_builtin_optimize_vestep_diagonal", (DL_FUNC) &_PLNmodels_builtin_optimize_vestep_diagonal, 5}, + {"_PLNmodels_builtin_optimize_spherical", (DL_FUNC) &_PLNmodels_builtin_optimize_spherical, 3}, + {"_PLNmodels_builtin_optimize_vestep_spherical", (DL_FUNC) &_PLNmodels_builtin_optimize_vestep_spherical, 5}, + {"_PLNmodels_builtin_optimize_fixed", (DL_FUNC) &_PLNmodels_builtin_optimize_fixed, 3}, + {"_PLNmodels_builtin_optimize_rank", (DL_FUNC) &_PLNmodels_builtin_optimize_rank, 3}, + {"_PLNmodels_builtin_optimize_vestep_rank", (DL_FUNC) &_PLNmodels_builtin_optimize_vestep_rank, 5}, {"_PLNmodels_nlopt_optimize_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_diagonal, 3}, {"_PLNmodels_nlopt_optimize_vestep_diagonal", (DL_FUNC) &_PLNmodels_nlopt_optimize_vestep_diagonal, 5}, {"_PLNmodels_nlopt_optimize_fixed", (DL_FUNC) &_PLNmodels_nlopt_optimize_fixed, 3}, @@ -573,8 +545,6 @@ static const R_CallMethodDef CallEntries[] = { {"_PLNmodels_ve_step_zipln_nlopt", (DL_FUNC) &_PLNmodels_ve_step_zipln_nlopt, 9}, {"_PLNmodels_ve_step_zipln_newton", (DL_FUNC) &_PLNmodels_ve_step_zipln_newton, 10}, {"_PLNmodels_cpp_test_packing", (DL_FUNC) &_PLNmodels_cpp_test_packing, 0}, - {"_PLNmodels_spectral_optimize_rank", (DL_FUNC) &_PLNmodels_spectral_optimize_rank, 3}, - {"_PLNmodels_spectral_optimize_vestep_rank", (DL_FUNC) &_PLNmodels_spectral_optimize_vestep_rank, 5}, {"_PLNmodels_get_sandwich_variance_B", (DL_FUNC) &_PLNmodels_get_sandwich_variance_B, 6}, {NULL, NULL, 0} }; diff --git a/src/CovarianceTraits.h b/src/builtin_covariance_pln.h similarity index 100% rename from src/CovarianceTraits.h rename to src/builtin_covariance_pln.h diff --git a/src/newton_impl.h b/src/builtin_newton_pln.h similarity index 98% rename from src/newton_impl.h rename to src/builtin_newton_pln.h index 1edc4df8..d1ca201e 100644 --- a/src/newton_impl.h +++ b/src/builtin_newton_pln.h @@ -1,7 +1,7 @@ #pragma once #include #include "utils.h" -#include "CovarianceTraits.h" +#include "builtin_covariance_pln.h" // M_full parameterization: M is the full variational mean of Z_i (= X_i*B + M_res), // consistent with the ZIPLN convention. M_res = M - X*B is computed locally for KL. @@ -17,7 +17,7 @@ // optimizes (M, ψ) jointly for fixed Omega until convergence (ftol), then one Omega M-step. // Joint Newton step per inner iteration: diagonal 2×2 per (i,j) with cross-term H_Mψ. template -Rcpp::List newton_optimize_impl( +Rcpp::List builtin_optimize_pln_impl( const arma::mat & Y, const arma::mat & X, const arma::mat & O, const arma::vec & w, arma::mat B, arma::mat M, arma::mat S2, typename Traits::State state, @@ -132,7 +132,7 @@ Rcpp::List newton_optimize_impl( // Generic VE-step Newton optimizer (B and Omega fixed, only M and S updated). // State must be initialized from a fixed Omega via the explicit constructor. template -Rcpp::List newton_vestep_impl( +Rcpp::List builtin_vestep_pln_impl( const arma::mat & Y, const arma::mat & X, const arma::mat & O, const arma::vec & w, arma::mat M, arma::mat S2, const arma::mat & B, const typename Traits::State & state, diff --git a/src/builtin_optim_pln.cpp b/src/builtin_optim_pln.cpp new file mode 100644 index 00000000..14d202e0 --- /dev/null +++ b/src/builtin_optim_pln.cpp @@ -0,0 +1,152 @@ +#include "RcppArmadillo.h" + +// [[Rcpp::depends(RcppArmadillo)]] + +#include "utils.h" +#include "builtin_newton_pln.h" + +// --------------------------------------------------------------------------------------- +// Builtin Newton optimizer for PLN — all covariance structures. +// Each exported function is a thin wrapper that builds the appropriate Traits::State +// and delegates to the generic builtin_optimize_pln_impl / builtin_vestep_pln_impl templates. + +// ===== FULL COVARIANCE ===== + +// [[Rcpp::export]] +Rcpp::List builtin_optimize_full( + const Rcpp::List & data , + const Rcpp::List & params, + const Rcpp::List & config +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); + const NewtonConfig cfg(config); + const double w_bar = arma::accu(w); + FullCovTraits::State state(M - X * B, S2, w, w_bar); + return builtin_optimize_pln_impl(Y, X, O, w, B, M, S2, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); +} + +// [[Rcpp::export]] +Rcpp::List builtin_optimize_vestep_full( + const Rcpp::List & data , + const Rcpp::List & params, + const arma::mat & B, + const arma::mat & Omega, + const Rcpp::List & config +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); + const NewtonConfig cfg(config); + FullCovTraits::State state(Omega); + return builtin_vestep_pln_impl(Y, X, O, w, M, S2, B, state, cfg.maxiter, cfg.ftol); +} + +// ===== DIAGONAL COVARIANCE ===== + +// [[Rcpp::export]] +Rcpp::List builtin_optimize_diagonal( + const Rcpp::List & data , + const Rcpp::List & params, + const Rcpp::List & config +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); + const NewtonConfig cfg(config); + const double w_bar = arma::accu(w); + DiagonalCovTraits::State state(M - X * B, S2, w, w_bar); + return builtin_optimize_pln_impl(Y, X, O, w, B, M, S2, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); +} + +// [[Rcpp::export]] +Rcpp::List builtin_optimize_vestep_diagonal( + const Rcpp::List & data , + const Rcpp::List & params, + const arma::mat & B, + const arma::mat & Omega, + const Rcpp::List & config +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); + const NewtonConfig cfg(config); + DiagonalCovTraits::State state(Omega); + return builtin_vestep_pln_impl(Y, X, O, w, M, S2, B, state, cfg.maxiter, cfg.ftol); +} + +// ===== SPHERICAL COVARIANCE ===== + +// [[Rcpp::export]] +Rcpp::List builtin_optimize_spherical( + const Rcpp::List & data , + const Rcpp::List & params, + const Rcpp::List & config +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); + const NewtonConfig cfg(config); + const double w_bar = arma::accu(w); + SphericalCovTraits::State state(M - X * B, S2, w, w_bar); + return builtin_optimize_pln_impl(Y, X, O, w, B, M, S2, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); +} + +// [[Rcpp::export]] +Rcpp::List builtin_optimize_vestep_spherical( + const Rcpp::List & data , + const Rcpp::List & params, + const arma::mat & B, + const arma::mat & Omega, + const Rcpp::List & config +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); + const NewtonConfig cfg(config); + SphericalCovTraits::State state(Omega); + return builtin_vestep_pln_impl(Y, X, O, w, M, S2, B, state, cfg.maxiter, cfg.ftol); +} + +// ===== FIXED COVARIANCE (Omega provided externally, no VE step exported) ===== + +// [[Rcpp::export]] +Rcpp::List builtin_optimize_fixed( + const Rcpp::List & data , + const Rcpp::List & params, + const Rcpp::List & config +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); + arma::mat Omega = Rcpp::as(params["Omega"]); + const NewtonConfig cfg(config); + FixedCovTraits::State state(Omega); + return builtin_optimize_pln_impl(Y, X, O, w, B, M, S2, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); +} diff --git a/src/builtin_optim_plnpca.cpp b/src/builtin_optim_plnpca.cpp new file mode 100644 index 00000000..0d97ce1f --- /dev/null +++ b/src/builtin_optim_plnpca.cpp @@ -0,0 +1,362 @@ +#include "RcppArmadillo.h" + +// [[Rcpp::depends(RcppArmadillo)]] + +#include "utils.h" + +// --------------------------------------------------------------------------------------- +// Rank-constrained PLN — Joint L-BFGS with strong Wolfe line search +// +// All parameters [vec(B); vec(C); vec(M); vec(ψ)] are optimised simultaneously. +// Strong Wolfe line search guarantees s^T y > 0 at every accepted step, so the +// L-BFGS history always accumulates valid curvature pairs including the bilinear +// M·Cᵀ cross-curvature that block-coordinate methods miss. + +// --------------------------------------------------------------------------------------- +// L-BFGS two-loop recursion: returns search direction p = -H_k · g +static arma::vec lbfgs_direction( + const arma::vec & g, + const std::deque & sv, + const std::deque & yv +) { + const int m = (int)sv.size(); + arma::vec q = g, alpha(m, arma::fill::zeros); + for (int i = m-1; i >= 0; i--) { + double rho = 1.0 / arma::dot(yv[i], sv[i]); + alpha(i) = rho * arma::dot(sv[i], q); + q -= alpha(i) * yv[i]; + } + arma::vec r = q; + if (m > 0) { + double sy = arma::dot(sv.back(), yv.back()); + double yy = arma::dot(yv.back(), yv.back()); + if (sy > 0 && yy > 1e-20) r *= (sy / yy); + } + for (int i = 0; i < m; i++) { + double rho = 1.0 / arma::dot(yv[i], sv[i]); + double beta = rho * arma::dot(yv[i], r); + r += sv[i] * (alpha(i) - beta); + } + return -r; +} + +// --------------------------------------------------------------------------------------- +// Strong Wolfe line search (Nocedal & Wright, Algorithm 3.5/3.6). +// Guarantees s^T y > 0 when slope0 < 0 and a descent direction is given. + +struct WolfeStep { double scale; double f; arma::vec g; }; + +template +static WolfeStep wolfe_ls( + const arma::vec & x0, const arma::vec & d, + double f0, double slope0, FG fg, + const double c1 = 1e-4, const double c2 = 0.9 +) { + auto zoom = [&](double alo, double ahi, double flo) -> WolfeStep { + for (int j = 0; j < 20; j++) { + double a = 0.5 * (alo + ahi); + auto [fa, ga] = fg(x0 + a * d); + if (fa > f0 + c1*a*slope0 || fa >= flo) { ahi = a; } + else { + double da = arma::dot(ga, d); + if (std::abs(da) <= -c2 * slope0) return {a, fa, ga}; + if (da * (ahi - alo) >= 0) ahi = alo; + alo = a; flo = fa; + } + } + double a = 0.5 * (alo + ahi); + auto [fa, ga] = fg(x0 + a * d); + return {a, fa, ga}; + }; + double a = 1.0, ap = 0, fp = f0; + for (int i = 0; i < 20; i++) { + auto [fa, ga] = fg(x0 + a * d); + if (fa > f0 + c1*a*slope0 || (i > 0 && fa >= fp)) return zoom(ap, a, fp); + double da = arma::dot(ga, d); + if (std::abs(da) <= -c2 * slope0) return {a, fa, ga}; + if (da >= 0) return zoom(a, ap, fa); + ap = a; fp = fa; + a = std::min(2.0 * a, 1e6); + } + auto [fa, ga] = fg(x0 + a * d); + return {a, fa, ga}; +} + +// --------------------------------------------------------------------------------------- +// [[Rcpp::export]] +Rcpp::List builtin_optimize_rank( + const Rcpp::List & data , + const Rcpp::List & params, + const Rcpp::List & config +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat B = Rcpp::as(params["B"]); + arma::mat C = Rcpp::as(params["C"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as (config["maxeval"]) : 10000; + const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-9; + const int m_hist = 10; + + const arma::uword n = Y.n_rows, p = Y.n_cols, q = M.n_cols, d = B.n_rows; + + // Packed-parameter offsets: x = [vec(B); vec(C); vec(M); vec(ψ)] + const arma::uword oB = 0, oC = d*p, oM = d*p + p*q, oPsi = d*p + p*q + n*q; + const arma::uword N = d*p + p*q + 2*n*q; + + // Warm-start ψ with one fixed-point step + arma::mat C2 = C % C; + arma::mat psi = arma::log(S2); + arma::mat Z = O + X * B + M * C.t(); + arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); + psi = arma::clamp(-arma::log(1. + A * C2), -40., 40.); + S2 = arma::exp(psi); + A = arma::exp(Z + 0.5 * S2 * C2.t()); + + const arma::mat Xw = X.each_col() % w; + + // Joint fg evaluator for all parameters + auto fg = [&](const arma::vec & x) -> std::pair { + arma::mat B_ = arma::reshape(x.subvec(oB, oC-1 ), d, p); + arma::mat C_ = arma::reshape(x.subvec(oC, oM-1 ), p, q); + arma::mat M_ = arma::reshape(x.subvec(oM, oPsi-1 ), n, q); + arma::mat psi_ = arma::reshape(x.subvec(oPsi, N-1 ), n, q); + arma::mat S2_ = arma::exp(psi_); + arma::mat C2_ = C_ % C_; + arma::mat Z_ = O + X * B_ + M_ * C_.t(); + arma::mat A_ = arma::exp(Z_ + 0.5 * S2_ * C2_.t()); + double f = arma::accu(w.t() * (A_ - Y % Z_)) + + 0.5 * arma::accu(w.t() * (M_ % M_ + S2_ - psi_ - 1.)); + arma::mat AmY = A_ - Y; + arma::mat AmYw = AmY; AmYw.each_col() %= w; + arma::mat gB_ = Xw.t() * AmY; + arma::mat gC_ = AmYw.t() * M_ + (A_.t() * (S2_.each_col() % w)) % C_; + arma::mat gM_ = AmY * C_ + M_; gM_.each_col() %= w; + arma::mat gPs_ = arma::diagmat(w) * (0.5 * (S2_ % (1. + A_ * C2_) - 1.)); + arma::vec g = arma::join_cols( + arma::join_cols(arma::vectorise(gB_), arma::vectorise(gC_)), + arma::join_cols(arma::vectorise(gM_), arma::vectorise(gPs_))); + return {f, g}; + }; + + // Initial packed state and evaluation + arma::vec x = arma::join_cols( + arma::join_cols(arma::vectorise(B), arma::vectorise(C)), + arma::join_cols(arma::vectorise(M), arma::vectorise(psi))); + auto [f_cur, g_cur] = fg(x); + + std::deque sv, yv; + std::vector objective_vec; + double obj_prev = arma::datum::inf; + int total_iter = 0, last_status = 5; + const int win = 100; + + for (int it = 0; it < maxiter; it++) { + objective_vec.push_back(f_cur); + total_iter++; + + if (it > 0 && converged(f_cur, obj_prev, ftol)) { last_status = 3; break; } + obj_prev = f_cur; + if (it > 0 && it % win == 0 && (int)objective_vec.size() >= 2*win) { + double m1 = *std::min_element(objective_vec.end()-win, objective_vec.end()); + double m2 = *std::min_element(objective_vec.end()-2*win, objective_vec.end()-win); + if (converged(m1, m2, ftol)) { last_status = 3; break; } + } + + // L-BFGS direction + arma::vec d_lbfgs; + if (sv.empty()) { + double gn = arma::norm(g_cur); + d_lbfgs = (gn > 1e-20) ? arma::vec(-g_cur / gn) + : arma::vec(N, arma::fill::zeros); + } else { + d_lbfgs = lbfgs_direction(g_cur, sv, yv); + if (arma::dot(d_lbfgs, g_cur) >= 0) { + sv.clear(); yv.clear(); + d_lbfgs = -g_cur / (arma::norm(g_cur) + 1e-20); + } + } + + double slope = arma::dot(d_lbfgs, g_cur); + if (std::abs(slope) < 1e-20) { last_status = 4; break; } + + WolfeStep ws = wolfe_ls(x, d_lbfgs, f_cur, slope, fg); + + // Update L-BFGS history (guarded by curvature condition) + arma::vec s_new = ws.scale * d_lbfgs; + arma::vec y_new = ws.g - g_cur; + double sy = arma::dot(s_new, y_new), ss = arma::dot(s_new, s_new); + if (sy > 1e-10 * ss && ss > 1e-20) { + sv.push_back(s_new); yv.push_back(y_new); + if ((int)sv.size() > m_hist) { sv.pop_front(); yv.pop_front(); } + } + + x = x + ws.scale * d_lbfgs; + f_cur = ws.f; + g_cur = std::move(ws.g); + } + + // Unpack final parameters + B = arma::reshape(x.subvec(oB, oC-1 ), d, p); + C = arma::reshape(x.subvec(oC, oM-1 ), p, q); + M = arma::reshape(x.subvec(oM, oPsi-1), n, q); + psi = arma::reshape(x.subvec(oPsi, N-1 ), n, q); + S2 = arma::exp(psi); + C2 = C % C; + Z = O + X * B + M * C.t(); + A = arma::exp(Z + 0.5 * S2 * C2.t()); + + const double w_bar = arma::accu(w); + arma::mat nSig = M.t() * (M.each_col() % w) + arma::diagmat(arma::sum(S2.each_col() % w, 0)); + arma::mat Sigma = C * nSig * C.t() / w_bar; + arma::mat Omega = C * arma::inv_sympd(nSig / w_bar) * C.t(); + arma::vec loglik = arma::sum(Y % Z - A, 1) + - 0.5 * arma::sum(M % M + S2 - psi - 1., 1) + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("B", B ), + Rcpp::Named("C", C ), + Rcpp::Named("M", M ), + Rcpp::Named("S2", S2 ), + Rcpp::Named("Z", Z ), + Rcpp::Named("A", A ), + Rcpp::Named("Sigma", Sigma), + Rcpp::Named("Omega", Omega), + Rcpp::Named("Ji", Ji ), + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", last_status ), + Rcpp::Named("backend", "lbfgs" ), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", total_iter ) + )) + ); +} + +// --------------------------------------------------------------------------------------- +// VE step only (project): B and C fixed, update (M, ψ). + +// [[Rcpp::export]] +Rcpp::List builtin_optimize_vestep_rank( + const Rcpp::List & data , + const Rcpp::List & params, + const arma::mat & B, + const arma::mat & C, + const Rcpp::List & config +) { + const arma::mat & Y = Rcpp::as(data["Y"]); + const arma::mat & X = Rcpp::as(data["X"]); + const arma::mat & O = Rcpp::as(data["O"]); + const arma::vec & w = Rcpp::as(data["w"]); + arma::mat M = Rcpp::as(params["M"]); + arma::mat S2 = Rcpp::as(params["S2"]); + + const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as (config["maxeval"]) : 10000; + const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-9; + const int m_hist = 10; + + const arma::uword n = Y.n_rows, q = M.n_cols; + const arma::uword oM = 0, oPsi = n*q, N = 2*n*q; + const arma::mat C2 = C % C; + const arma::mat XB = X * B; + + // Warm-start ψ + arma::mat psi = arma::log(S2); + arma::mat Z = O + XB + M * C.t(); + arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); + psi = arma::clamp(-arma::log(1. + A * C2), -40., 40.); + S2 = arma::exp(psi); + A = arma::exp(Z + 0.5 * S2 * C2.t()); + + auto fg = [&](const arma::vec & x) -> std::pair { + arma::mat M_ = arma::reshape(x.subvec(oM, oPsi-1), n, q); + arma::mat psi_ = arma::reshape(x.subvec(oPsi, N-1 ), n, q); + arma::mat S2_ = arma::exp(psi_); + arma::mat Z_ = O + XB + M_ * C.t(); + arma::mat A_ = arma::exp(Z_ + 0.5 * S2_ * C2.t()); + double f = arma::accu(w.t() * (A_ - Y % Z_)) + + 0.5 * arma::accu(w.t() * (M_ % M_ + S2_ - psi_ - 1.)); + arma::mat gM_ = (A_ - Y) * C + M_; gM_.each_col() %= w; + arma::mat gPs_ = arma::diagmat(w) * (0.5 * (S2_ % (1. + A_ * C2) - 1.)); + return {f, arma::join_cols(arma::vectorise(gM_), arma::vectorise(gPs_))}; + }; + + arma::vec x = arma::join_cols(arma::vectorise(M), arma::vectorise(psi)); + auto [f_cur, g_cur] = fg(x); + + std::deque sv, yv; + std::vector objective_vec; + double obj_prev = arma::datum::inf; + int total_iter = 0; + const int win = 100; + + for (int it = 0; it < maxiter; it++) { + objective_vec.push_back(f_cur); + total_iter++; + if (it > 0 && converged(f_cur, obj_prev, ftol)) break; + obj_prev = f_cur; + if (it > 0 && it % win == 0 && (int)objective_vec.size() >= 2*win) { + double m1 = *std::min_element(objective_vec.end()-win, objective_vec.end()); + double m2 = *std::min_element(objective_vec.end()-2*win, objective_vec.end()-win); + if (converged(m1, m2, ftol)) break; + } + + arma::vec d; + if (sv.empty()) { + double gn = arma::norm(g_cur); + d = (gn > 1e-20) ? arma::vec(-g_cur / gn) + : arma::vec(N, arma::fill::zeros); + } else { + d = lbfgs_direction(g_cur, sv, yv); + if (arma::dot(d, g_cur) >= 0) { + sv.clear(); yv.clear(); + d = -g_cur / (arma::norm(g_cur) + 1e-20); + } + } + + double slope = arma::dot(d, g_cur); + if (std::abs(slope) < 1e-20) break; + + WolfeStep ws = wolfe_ls(x, d, f_cur, slope, fg); + + arma::vec s_new = ws.scale * d; + arma::vec y_new = ws.g - g_cur; + double sy = arma::dot(s_new, y_new), ss = arma::dot(s_new, s_new); + if (sy > 1e-10 * ss && ss > 1e-20) { + sv.push_back(s_new); yv.push_back(y_new); + if ((int)sv.size() > m_hist) { sv.pop_front(); yv.pop_front(); } + } + + x = x + ws.scale * d; + f_cur = ws.f; + g_cur = std::move(ws.g); + } + + M = arma::reshape(x.subvec(oM, oPsi-1), n, q); + psi = arma::reshape(x.subvec(oPsi, N-1 ), n, q); + S2 = arma::exp(psi); + Z = O + XB + M * C.t(); + A = arma::exp(Z + 0.5 * S2 * C2.t()); + + arma::vec loglik = arma::sum(Y % Z - A, 1) + - 0.5 * arma::sum(M % M + S2 - psi - 1., 1) + ki(Y); + + Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); + Ji.attr("weights") = w; + return Rcpp::List::create( + Rcpp::Named("M") = M, + Rcpp::Named("S2") = S2, + Rcpp::Named("Ji") = Ji, + Rcpp::Named("monitoring", Rcpp::List::create( + Rcpp::Named("status", 3 ), + Rcpp::Named("backend", "lbfgs" ), + Rcpp::Named("objective", objective_vec), + Rcpp::Named("iterations", total_iter ) + )) + ); +} diff --git a/src/newton_diag_cov.cpp b/src/newton_diag_cov.cpp deleted file mode 100644 index a2ea1818..00000000 --- a/src/newton_diag_cov.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "RcppArmadillo.h" - -// [[Rcpp::depends(RcppArmadillo)]] - -#include "utils.h" -#include "newton_impl.h" // newton_optimize_impl + newton_vestep_impl - -// --------------------------------------------------------------------------------------- -// Diagonal covariance PLN — homemade Newton optimizer (profiled B via envelope theorem) - -// [[Rcpp::export]] -Rcpp::List newton_optimize_diagonal( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(B, M, S) - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S2 = Rcpp::as(params["S2"]); - - const NewtonConfig cfg(config); - - const double w_bar = arma::accu(w); - const arma::mat M_res_init = M - X * B; - DiagonalCovTraits::State state(M_res_init, S2, w, w_bar); - - return newton_optimize_impl(Y, X, O, w, B, M, S2, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); -} - -// --------------------------------------------------------------------------------------- -// VE diagonal — coordinate-Newton (M and S only, B and Omega fixed) - -// [[Rcpp::export]] -Rcpp::List newton_optimize_vestep_diagonal( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(M, S) - const arma::mat & B, // (d,p) fixed - const arma::mat & Omega, // (p,p) diagonal, fixed - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S2 = Rcpp::as(params["S2"]); - - const NewtonConfig cfg(config); - DiagonalCovTraits::State state(Omega); - return newton_vestep_impl(Y, X, O, w, M, S2, B, state, cfg.maxiter, cfg.ftol); -} diff --git a/src/newton_fixed_cov.cpp b/src/newton_fixed_cov.cpp deleted file mode 100644 index 821a519c..00000000 --- a/src/newton_fixed_cov.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "RcppArmadillo.h" - -// [[Rcpp::depends(RcppArmadillo)]] - -#include "utils.h" -#include "newton_impl.h" // newton_optimize_impl — the homemade E-step - -// --------------------------------------------------------------------------------------- -// Fixed inverse covariance (Omega provided externally) PLN — homemade Newton optimizer - -// [[Rcpp::export]] -Rcpp::List newton_optimize_fixed( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(B, M, S, Omega) - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S2 = Rcpp::as(params["S2"]); - arma::mat Omega = Rcpp::as(params["Omega"]); - - const NewtonConfig cfg(config); - - FixedCovTraits::State state(Omega); - return newton_optimize_impl(Y, X, O, w, B, M, S2, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); -} diff --git a/src/newton_full_cov.cpp b/src/newton_full_cov.cpp deleted file mode 100644 index 16948398..00000000 --- a/src/newton_full_cov.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "RcppArmadillo.h" - -// [[Rcpp::depends(RcppArmadillo)]] - -#include "utils.h" -#include "newton_impl.h" // newton_optimize_impl + newton_vestep_impl - -// --------------------------------------------------------------------------------------- -// Full covariance PLN — homemade Newton optimizer (profiled B via envelope theorem) - -// [[Rcpp::export]] -Rcpp::List newton_optimize_full( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(B, M, S) - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S2 = Rcpp::as(params["S2"]); - - const NewtonConfig cfg(config); - - const double w_bar = arma::accu(w); - const arma::mat M_res_init = M - X * B; - FullCovTraits::State state(M_res_init, S2, w, w_bar); - - return newton_optimize_impl(Y, X, O, w, B, M, S2, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); -} - -// --------------------------------------------------------------------------------------- -// VE full covariance — coordinate-Newton (M and S only, B and Omega fixed) - -// [[Rcpp::export]] -Rcpp::List newton_optimize_vestep_full( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(M, S) - const arma::mat & B, // (d,p) fixed - const arma::mat & Omega, // (p,p) fixed - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S2 = Rcpp::as(params["S2"]); - - const NewtonConfig cfg(config); - FullCovTraits::State state(Omega); - return newton_vestep_impl(Y, X, O, w, M, S2, B, state, cfg.maxiter, cfg.ftol); -} diff --git a/src/newton_rank_cov.cpp b/src/newton_rank_cov.cpp deleted file mode 100644 index 31b51e89..00000000 --- a/src/newton_rank_cov.cpp +++ /dev/null @@ -1,315 +0,0 @@ -#include "RcppArmadillo.h" - -// [[Rcpp::depends(RcppArmadillo)]] - -#include "utils.h" - -// --------------------------------------------------------------------------------------- -// Rank-constrained covariance PLN — coordinate-Newton optimizer -// -// Parameters: B (d,p), C (p,q), M (n,q), S (n,q) -// Z = O + X*B + M*C', A = exp(Z + 0.5 * S²*C²ᵀ) -// Objective: Σᵢ wᵢ (A - Y⊙Z) + ½ Σᵢ wᵢ Σₖ (Mᵢₖ² + Sᵢₖ² − log Sᵢₖ² − 1) -// -// Update order per iteration: B → C → M → S -// B, M : diagonal Newton + Armijo (standard) -// C : diagonal Newton (Gauss-Newton Hessian) + Armijo (full Z and A recomputed) -// S : closed-form exact minimiser in ψ = logS² space: ψ = −log(1 + A·C²) - -// [[Rcpp::export]] -Rcpp::List newton_optimize_rank( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(B, C, M, S) - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat C = Rcpp::as(params["C"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); - - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; - - const arma::uword n = Y.n_rows; - const arma::uword q = C.n_cols; - - const double c1 = 1e-4; - const arma::mat Xw = X.each_col() % w; - arma::mat Xw2 = X % X; Xw2.each_col() %= w; - - arma::mat C2 = C % C; - arma::mat psi = arma::log(S % S); // ψ = log(S²), work in logS² space throughout - arma::mat S2 = arma::exp(psi); - arma::mat Z = O + X * B + M * C.t(); - arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); - - std::vector objective_vec; - double obj_prev = arma::datum::inf; - int total_iter = 0; - int last_status = 5; - - for (int it = 0; it < maxiter; it++) { - - // Precompute once per iteration — reused in B and M Armijo (saves O(n*q*p) per backtrack) - arma::mat half_S2C2t = 0.5 * S2 * C2.t(); - - // ---- B step (diagonal Newton + Armijo) ---- - { - arma::mat grad_B = Xw.t() * (A - Y); - arma::mat hess_B = Xw2.t() * A; - hess_B.clamp(1e-10, arma::datum::inf); - arma::mat step_B = grad_B / hess_B; - arma::mat XstepB = X * step_B; - double f0_B = arma::accu(w.t() * (A - Y % Z)); - double slope_B = -arma::accu(grad_B % step_B); - double alpha_B = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Zt = Z - alpha_B * XstepB; - if (arma::accu(w.t() * (arma::exp(Zt + half_S2C2t) - Y % Zt)) - <= f0_B + c1 * alpha_B * slope_B) break; - alpha_B *= 0.5; - } - B -= alpha_B * step_B; - Z = O + X * B + M * C.t(); - A = arma::exp(Z + half_S2C2t); - } - - // ---- M step (block q×q Newton per observation + Armijo) ---- - // Exact Hessian per row i: Hᵢ = Cᵀ diag(Aᵢ) C + Iq (q×q, always PD) - { - arma::mat grad_M = (A - Y) * C + M; // n×q, unweighted gradient - arma::mat step_M(n, q); - for (int i = 0; i < n; i++) { - // Scale rows of C by A_{ij}: CAi_{jk} = C_{jk} * A_{ij} - arma::mat CAi = C.each_col() % A.row(i).t(); // p×q, O(p*q) - arma::mat Hi = CAi.t() * C; // q×q = C'diag(Aᵢ)C, O(p*q²) - Hi.diag() += 1.0; - step_M.row(i) = arma::solve(Hi, grad_M.row(i).t(), arma::solve_opts::fast).t(); - } - arma::mat stepMCt = step_M * C.t(); - arma::mat grad_M_w = grad_M; grad_M_w.each_col() %= w; // for slope - double f0_M = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::as_scalar(w.t() * arma::sum(M % M, 1)); - double slope_M = -arma::accu(grad_M_w % step_M); - double alpha_M = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; - arma::mat Zt = Z - alpha_M * stepMCt; - arma::mat At = arma::exp(Zt + half_S2C2t); - if (arma::accu(w.t() * (At - Y % Zt)) - + 0.5 * arma::as_scalar(w.t() * arma::sum(Mt % Mt, 1)) - <= f0_M + c1 * alpha_M * slope_M) break; - alpha_M *= 0.5; - } - M -= alpha_M * step_M; - Z = O + X * B + M * C.t(); - A = arma::exp(Z + half_S2C2t); - } - - // ---- C step (block q×q Newton per gene + Armijo) ---- - // Exact Hessian per gene j: Hⱼ = F̃ⱼᵀ diag(w⊙Aⱼ) F̃ⱼ + diag(S2ᵀ(w⊙Aⱼ)) - // where F̃ⱼ_{ik} = Mᵢₖ + S²ᵢₖ Cⱼₖ (avoids n×p temporaries of diagonal version) - { - const arma::uword p = C.n_rows; - const arma::mat WA = A.each_col() % w; // n×p - arma::mat AmY = A - Y; AmY.each_col() %= w; - arma::mat grad_C = AmY.t() * M + (WA.t() * S2) % C; // p×q - arma::mat step_C(p, q); - for (arma::uword j = 0; j < p; j++) { - // F̃ⱼ = M + S2 .* C[j,:] (broadcast C.row(j) over n rows) - arma::mat Fj = M + S2.each_row() % C.row(j); // n×q, O(n*q) - arma::mat Fj_sc = Fj.each_col() % WA.col(j); // n×q, scale by wᵢAᵢⱼ - arma::mat Hj = Fj_sc.t() * Fj; // q×q, O(n*q²) - Hj.diag() += S2.t() * WA.col(j); // + diag(S2ᵀ wA_j) - step_C.row(j) = arma::solve(Hj, grad_C.row(j).t(), arma::solve_opts::fast).t(); - } - const arma::mat Mstep_Ct = M * step_C.t(); - const arma::mat S2_CsCt = S2 * (C % step_C).t(); - const arma::mat S2_sC2t = S2 * (step_C % step_C).t(); - double f0_C = arma::accu(w.t() * (A - Y % Z)); - double slope_C = -arma::accu(grad_C % step_C); - double alpha_C = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Zt = Z - alpha_C * Mstep_Ct; - arma::mat half_t = half_S2C2t - alpha_C * S2_CsCt - + (0.5 * alpha_C * alpha_C) * S2_sC2t; - arma::mat At = arma::exp(Zt + half_t); - if (arma::accu(w.t() * (At - Y % Zt)) - <= f0_C + c1 * alpha_C * slope_C) break; - alpha_C *= 0.5; - } - C -= alpha_C * step_C; - C2 = C % C; - Z = O + X * B + M * C.t(); - half_S2C2t = 0.5 * S2 * C2.t(); - A = arma::exp(Z + half_S2C2t); - } - - // ---- S step (exact minimiser in ψ = logS² space) ---- - // ∂F/∂ψᵢₖ = 0 ⟹ ψᵢₖ = −log(1 + (A·C²)ᵢₖ) - // KL term: S² − logS² − 1 = exp(ψ) − ψ − 1 - { - psi = arma::clamp(-arma::log(1. + A * C2), -40., 0.); - S2 = arma::exp(psi); - A = arma::exp(Z + 0.5 * S2 * C2.t()); // S2 changed — full recompute - } - - // ---- Convergence check ---- - double obj = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::accu(w.t() * (M % M + S2 - psi - 1.)); - objective_vec.push_back(obj); - total_iter++; - - if (it > 0 && converged(obj, obj_prev, ftol)) { last_status = 3; break; } - obj_prev = obj; - } - - // ---- Final output ---- - S2 = arma::exp(psi); - S = arma::exp(0.5 * psi); - Z = O + X * B + M * C.t(); - A = arma::exp(Z + 0.5 * S2 * C2.t()); - const double w_bar = arma::accu(w); - arma::mat nSig = M.t() * (M.each_col() % w) + arma::diagmat(arma::sum(S2.each_col() % w, 0)); - arma::mat Sigma = C * nSig * C.t() / w_bar; - arma::mat Omega = C * arma::inv_sympd(nSig / w_bar) * C.t(); - arma::vec loglik = arma::sum(Y % Z - A, 1) - - 0.5 * arma::sum(M % M + S2 - psi - 1., 1) - + ki(Y); - - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("B", B ), - Rcpp::Named("C", C ), - Rcpp::Named("M", M ), - Rcpp::Named("S", S ), - Rcpp::Named("Z", Z ), - Rcpp::Named("A", A ), - Rcpp::Named("Sigma", Sigma), - Rcpp::Named("Omega", Omega), - Rcpp::Named("Ji", Ji ), - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", last_status ), - Rcpp::Named("backend", "newton" ), - Rcpp::Named("objective", objective_vec), - Rcpp::Named("iterations", total_iter ) - )) - ); -} - -// --------------------------------------------------------------------------------------- -// VE rank — coordinate-Newton (M and S only, B and C fixed) - -// [[Rcpp::export]] -Rcpp::List newton_optimize_vestep_rank( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(M, S) - const arma::mat & B, // (d,p) fixed - const arma::mat & C, // (p,q) fixed - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S = Rcpp::as(params["S"]); - - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 200; - const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-8; - - const arma::uword n = Y.n_rows; - const arma::uword q = C.n_cols; - - const double c1 = 1e-4; - const arma::mat C2 = C % C; - const arma::mat XB = X * B; - - arma::mat psi = arma::log(S % S); // ψ = log(S²) - arma::mat S2 = arma::exp(psi); - arma::mat Z = O + XB + M * C.t(); - arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); - - std::vector objective_vec; - double obj_prev = arma::datum::inf; - int total_iter = 0; - - for (int it = 0; it < maxiter; it++) { - - const arma::mat half_S2C2t = 0.5 * S2 * C2.t(); - - // ---- M step (block q×q Newton per observation + Armijo) ---- - { - arma::mat grad_M = (A - Y) * C + M; // n×q, unweighted - arma::mat step_M(n, q); - for (int i = 0; i < n; i++) { - arma::mat CAi = C.each_col() % A.row(i).t(); - arma::mat Hi = CAi.t() * C; - Hi.diag() += 1.0; - step_M.row(i) = arma::solve(Hi, grad_M.row(i).t(), arma::solve_opts::fast).t(); - } - arma::mat stepMCt = step_M * C.t(); - arma::mat grad_M_w = grad_M; grad_M_w.each_col() %= w; - double f0_M = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::as_scalar(w.t() * arma::sum(M % M, 1)); - double slope_M = -arma::accu(grad_M_w % step_M); - double alpha_M = 1.0; - for (int ls = 0; ls < 20; ls++) { - arma::mat Mt = M - alpha_M * step_M; - arma::mat Zt = Z - alpha_M * stepMCt; - arma::mat At = arma::exp(Zt + half_S2C2t); - if (arma::accu(w.t() * (At - Y % Zt)) - + 0.5 * arma::as_scalar(w.t() * arma::sum(Mt % Mt, 1)) - <= f0_M + c1 * alpha_M * slope_M) break; - alpha_M *= 0.5; - } - M -= alpha_M * step_M; - Z = O + XB + M * C.t(); - A = arma::exp(Z + half_S2C2t); - } - - // ---- S step (exact minimiser in ψ = logS² space) ---- - { - psi = arma::clamp(-arma::log(1. + A * C2), -40., 0.); - S2 = arma::exp(psi); - A = arma::exp(Z + 0.5 * S2 * C2.t()); // S2 changed — full recompute - } - - // ---- Convergence check ---- - double obj = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::accu(w.t() * (M % M + S2 - psi - 1.)); - objective_vec.push_back(obj); - total_iter++; - - if (it > 0 && converged(obj, obj_prev, ftol)) break; - obj_prev = obj; - } - - // ---- Final output ---- - S2 = arma::exp(psi); - S = arma::exp(0.5 * psi); - Z = O + XB + M * C.t(); - A = arma::exp(Z + 0.5 * S2 * C2.t()); - arma::vec loglik = arma::sum(Y % Z - A, 1) - - 0.5 * arma::sum(M % M + S2 - psi - 1., 1) - + ki(Y); - - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("M") = M, - Rcpp::Named("S") = S, - Rcpp::Named("Ji") = Ji, - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", 3 ), - Rcpp::Named("backend", "newton" ), - Rcpp::Named("objective", objective_vec), - Rcpp::Named("iterations", total_iter ) - )) - ); -} diff --git a/src/newton_spherical.cpp b/src/newton_spherical.cpp deleted file mode 100644 index 10814c0b..00000000 --- a/src/newton_spherical.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "RcppArmadillo.h" - -// [[Rcpp::depends(RcppArmadillo)]] - -#include "utils.h" -#include "newton_impl.h" // newton_optimize_impl + newton_vestep_impl - -// --------------------------------------------------------------------------------------- -// Spherical covariance PLN — homemade Newton optimizer (profiled B via envelope theorem) - -// [[Rcpp::export]] -Rcpp::List newton_optimize_spherical( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(B, M, S) - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S2 = Rcpp::as(params["S2"]); - - const NewtonConfig cfg(config); - - const double w_bar = arma::accu(w); - const arma::mat M_res_init = M - X * B; - SphericalCovTraits::State state(M_res_init, S2, w, w_bar); - - return newton_optimize_impl(Y, X, O, w, B, M, S2, state, cfg.maxiter, cfg.ftol, cfg.max_em, cfg.em_tol); -} - -// --------------------------------------------------------------------------------------- -// VE spherical — coordinate-Newton (M and S only, B and Omega fixed) - -// [[Rcpp::export]] -Rcpp::List newton_optimize_vestep_spherical( - const Rcpp::List & data , // List(Y, X, O, w) - const Rcpp::List & params, // List(M, S) - const arma::mat & B, // (d,p) fixed - const arma::mat & Omega, // (p,p) diagonal scalar, fixed - const Rcpp::List & config // List of config values -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S2 = Rcpp::as(params["S2"]); - - const NewtonConfig cfg(config); - SphericalCovTraits::State state(Omega); - return newton_vestep_impl(Y, X, O, w, M, S2, B, state, cfg.maxiter, cfg.ftol); -} diff --git a/src/spectral_rank_cov.cpp b/src/spectral_rank_cov.cpp deleted file mode 100644 index a3f2e56f..00000000 --- a/src/spectral_rank_cov.cpp +++ /dev/null @@ -1,314 +0,0 @@ -#include "RcppArmadillo.h" - -// [[Rcpp::depends(RcppArmadillo)]] - -#include "utils.h" - -// --------------------------------------------------------------------------------------- -// Rank-constrained PLN — Spectral Gradient Method (Barzilai-Borwein + GLL/Armijo) -// -// Parameters: B (d,p), C (p,q), M (n,q), S exact via ψ = −log(1 + A·C²) -// Z = O + X·B + M·C', A = exp(Z + ½·S²·C²ᵀ) -// -// Per-element BB step sizes (equivalent to NLOPT CCSAQ's σ): -// σᵢ = |Δgᵢ| / |sᵢ| for each element i of B, C, M -// -// Line search: GLL nonmonotone Armijo — accepts if -// f_new ≤ max_{j=0..M-1} f_{k-j} + c₁·scale·slope -// GLL reduces backtracking frequency vs monotone Armijo (the nonmonotone window -// allows temporary increases, so the BB step is accepted more often on the first try). -// -// Convergence: consecutive ftol (default 1e-9 in config_default_spectral). -// ftol=1e-8 is too loose — GLL oscillations are O(1e-8·|f|) and fool the -// criterion into stopping prematurely at suboptimal minima. 1e-9 gives -// quality matching or exceeding NLOPT CCSAQ at ≤2× wall-clock time. - -static inline double safe_ratio(double a, double b, double fallback) { - return (b > 1e-20) ? std::clamp(a / b, 1e-12, 1e12) : fallback; -} - -// Per-element σ update: σ = |y| / |s|, fall back to current value when |s| is tiny -static void update_sigma(arma::mat & sigma, - const arma::mat & y_abs, - const arma::mat & s_abs) -{ - for (arma::uword i = 0; i < sigma.n_elem; i++) - sigma(i) = safe_ratio(y_abs(i), s_abs(i), sigma(i)); -} - -// [[Rcpp::export]] -Rcpp::List spectral_optimize_rank( - const Rcpp::List & data , - const Rcpp::List & params, - const Rcpp::List & config -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat B = Rcpp::as(params["B"]); - arma::mat C = Rcpp::as(params["C"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S2 = Rcpp::as(params["S2"]); // variational variance - - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 10000; - const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-10; - const double c_armijo = 1e-4; - const int nm_window = 10; // GLL nonmonotone window size - - const arma::mat Xw = X.each_col() % w; - - // Initialise geometry with S2 exact - arma::mat C2 = C % C; - arma::mat psi = arma::log(S2); - arma::mat Z = O + X * B + M * C.t(); - arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); - psi = arma::clamp(-arma::log(1. + A * C2), -40., 0.); - S2 = arma::exp(psi); - A = arma::exp(Z + 0.5 * S2 * C2.t()); - - // Per-element BB σ (same layout as B, C, M) - arma::mat sigma_B(arma::size(B), arma::fill::ones); - arma::mat sigma_C(arma::size(C), arma::fill::ones); - arma::mat sigma_M(arma::size(M), arma::fill::ones); - arma::mat sB_prev, sC_prev, sM_prev; - arma::mat gB_prev, gC_prev, gM_prev; - bool prev_valid = false; - - // GLL nonmonotone buffer - std::deque obj_buffer; - - std::vector objective_vec; - double obj_prev = arma::datum::inf; - int total_iter = 0, last_status = 5; - const int win = 100; // window for GLL-oscillation-robust convergence check - - for (int it = 0; it < maxiter; it++) { - - // ---- Objective ---- - double obj = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::accu(w.t() * (M % M + S2 - psi - 1.)); - objective_vec.push_back(obj); - total_iter++; - // Primary: consecutive convergence (cheap, exact for monotone steps) - if (it > 0 && converged(obj, obj_prev, ftol)) { last_status = 3; break; } - obj_prev = obj; - // Secondary: window-minimum stagnation every `win` iterations. - // Compares min of last `win` evals to min of the preceding `win` evals. - // Robust to GLL oscillations, which can delay consecutive convergence. - if (it > 0 && it % win == 0 && (int)objective_vec.size() >= 2*win) { - double m1 = *std::min_element(objective_vec.end()-win, objective_vec.end()); - double m2 = *std::min_element(objective_vec.end()-2*win, objective_vec.end()-win); - if (converged(m1, m2, ftol)) { last_status = 3; break; } - } - - // Update GLL window and reference - obj_buffer.push_back(obj); - if ((int)obj_buffer.size() > nm_window) obj_buffer.pop_front(); - double f_ref = *std::max_element(obj_buffer.begin(), obj_buffer.end()); - - // ---- Joint gradient ∇(B, C, M) ---- - arma::mat AmY = A - Y; AmY.each_col() %= w; - arma::mat gB = Xw.t() * (A - Y); - arma::mat gC = AmY.t() * M + (A.t() * (S2.each_col() % w)) % C; - arma::mat gM = (A - Y) * C + M; gM.each_col() %= w; - - // ---- Per-element σ update (or initialise on first iter) ---- - if (prev_valid) { - update_sigma(sigma_B, arma::abs(gB - gB_prev), arma::abs(sB_prev)); - update_sigma(sigma_C, arma::abs(gC - gC_prev), arma::abs(sC_prev)); - update_sigma(sigma_M, arma::abs(gM - gM_prev), arma::abs(sM_prev)); - } else { - sigma_B = arma::clamp(arma::abs(gB), 1e-4, 1e12); - sigma_C = arma::clamp(arma::abs(gC), 1e-4, 1e12); - sigma_M = arma::clamp(arma::abs(gM), 1e-4, 1e12); - } - - arma::mat dB = gB / sigma_B; - arma::mat dC = gC / sigma_C; - arma::mat dM = gM / sigma_M; - double slope = -(arma::accu(dB % gB) + arma::accu(dC % gC) + arma::accu(dM % gM)); - - // ---- GLL nonmonotone Armijo with S exact update ---- - double scale = 1.0; - arma::mat B_t, C_t, M_t, C2_t, Z_t, A_t, psi_t, S2_t; - double obj_t = arma::datum::inf; - - for (int ls = 0; ls < 20; ls++) { - B_t = B - scale * dB; - C_t = C - scale * dC; - M_t = M - scale * dM; - C2_t = C_t % C_t; - Z_t = O + X * B_t + M_t * C_t.t(); - A_t = arma::exp(Z_t + 0.5 * S2 * C2_t.t()); - psi_t = arma::clamp(-arma::log(1. + A_t * C2_t), -40., 0.); - S2_t = arma::exp(psi_t); - A_t = arma::exp(Z_t + 0.5 * S2_t * C2_t.t()); - obj_t = arma::accu(w.t() * (A_t - Y % Z_t)) - + 0.5 * arma::accu(w.t() * (M_t % M_t + S2_t - psi_t - 1.)); - if (obj_t <= f_ref + c_armijo * scale * slope) break; - scale *= 0.5; - } - - // σ scale-up when Armijo backtracked heavily — prevents the next step - // from overshooting in the same direction - if (scale < 0.125) { - sigma_B /= scale; - sigma_C /= scale; - sigma_M /= scale; - } - - sB_prev = B_t - B; sC_prev = C_t - C; sM_prev = M_t - M; - gB_prev = gB; gC_prev = gC; gM_prev = gM; - prev_valid = true; - - B = B_t; C = C_t; M = M_t; - C2 = C2_t; Z = Z_t; A = A_t; psi = psi_t; S2 = S2_t; - } - - // ---- Final output ---- - const double w_bar = arma::accu(w); - arma::mat nSig = M.t() * (M.each_col() % w) + arma::diagmat(arma::sum(S2.each_col() % w, 0)); - arma::mat Sigma = C * nSig * C.t() / w_bar; - arma::mat Omega = C * arma::inv_sympd(nSig / w_bar) * C.t(); - arma::vec loglik = arma::sum(Y % Z - A, 1) - - 0.5 * arma::sum(M % M + S2 - psi - 1., 1) - + ki(Y); - - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("B", B ), - Rcpp::Named("C", C ), - Rcpp::Named("M", M ), - Rcpp::Named("S2", S2 ), - Rcpp::Named("Z", Z ), - Rcpp::Named("A", A ), - Rcpp::Named("Sigma", Sigma), - Rcpp::Named("Omega", Omega), - Rcpp::Named("Ji", Ji ), - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", last_status ), - Rcpp::Named("backend", "spectral" ), - Rcpp::Named("objective", objective_vec), - Rcpp::Named("iterations", total_iter ) - )) - ); -} - -// --------------------------------------------------------------------------------------- -// VE step: B and C fixed, update M (per-element BB + GLL) and S (exact) - -// [[Rcpp::export]] -Rcpp::List spectral_optimize_vestep_rank( - const Rcpp::List & data , - const Rcpp::List & params, - const arma::mat & B, - const arma::mat & C, - const Rcpp::List & config -) { - const arma::mat & Y = Rcpp::as(data["Y"]); - const arma::mat & X = Rcpp::as(data["X"]); - const arma::mat & O = Rcpp::as(data["O"]); - const arma::vec & w = Rcpp::as(data["w"]); - arma::mat M = Rcpp::as(params["M"]); - arma::mat S2 = Rcpp::as(params["S2"]); // variational variance - - const int maxiter = config.containsElementNamed("maxeval") ? Rcpp::as(config["maxeval"]) : 10000; - const double ftol = config.containsElementNamed("ftol_in") ? Rcpp::as(config["ftol_in"]) : 1e-10; - const double c_armijo = 1e-4; - const int nm_window = 10; - - const arma::mat C2 = C % C; - const arma::mat XB = X * B; - - arma::mat psi = arma::log(S2); - arma::mat Z = O + XB + M * C.t(); - arma::mat A = arma::exp(Z + 0.5 * S2 * C2.t()); - psi = arma::clamp(-arma::log(1. + A * C2), -40., 0.); - S2 = arma::exp(psi); - A = arma::exp(Z + 0.5 * S2 * C2.t()); - - arma::mat sigma_M(arma::size(M), arma::fill::ones); - arma::mat sM_prev, gM_prev; - bool prev_valid = false; - - std::deque obj_buffer; - std::vector objective_vec; - double obj_prev = arma::datum::inf; - int total_iter = 0; - const int win = 100; - - for (int it = 0; it < maxiter; it++) { - double obj = arma::accu(w.t() * (A - Y % Z)) - + 0.5 * arma::accu(w.t() * (M % M + S2 - psi - 1.)); - objective_vec.push_back(obj); - total_iter++; - if (it > 0 && converged(obj, obj_prev, ftol)) break; - obj_prev = obj; - if (it > 0 && it % win == 0 && (int)objective_vec.size() >= 2*win) { - double m1 = *std::min_element(objective_vec.end()-win, objective_vec.end()); - double m2 = *std::min_element(objective_vec.end()-2*win, objective_vec.end()-win); - if (converged(m1, m2, ftol)) break; - } - - obj_buffer.push_back(obj); - if ((int)obj_buffer.size() > nm_window) obj_buffer.pop_front(); - double f_ref = *std::max_element(obj_buffer.begin(), obj_buffer.end()); - - arma::mat gM = (A - Y) * C + M; gM.each_col() %= w; - - if (prev_valid) { - update_sigma(sigma_M, arma::abs(gM - gM_prev), arma::abs(sM_prev)); - } else { - sigma_M = arma::clamp(arma::abs(gM), 1e-4, 1e12); - } - - arma::mat dM = gM / sigma_M; - double slope = -arma::accu(dM % gM); - double scale = 1.0; - arma::mat M_t, Z_t, A_t, psi_t, S2_t; - double obj_t = arma::datum::inf; - - for (int ls = 0; ls < 20; ls++) { - M_t = M - scale * dM; - Z_t = O + XB + M_t * C.t(); - A_t = arma::exp(Z_t + 0.5 * S2 * C2.t()); - psi_t = arma::clamp(-arma::log(1. + A_t * C2), -40., 0.); - S2_t = arma::exp(psi_t); - A_t = arma::exp(Z_t + 0.5 * S2_t * C2.t()); - obj_t = arma::accu(w.t() * (A_t - Y % Z_t)) - + 0.5 * arma::accu(w.t() * (M_t % M_t + S2_t - psi_t - 1.)); - if (obj_t <= f_ref + c_armijo * scale * slope) break; - scale *= 0.5; - } - - if (scale < 0.125) sigma_M /= scale; - - sM_prev = M_t - M; - gM_prev = gM; - prev_valid = true; - - M = M_t; Z = Z_t; A = A_t; psi = psi_t; S2 = S2_t; - } - - S2 = arma::exp(psi); - Z = O + XB + M * C.t(); - arma::vec loglik = arma::sum(Y % Z - A, 1) - - 0.5 * arma::sum(M % M + S2 - psi - 1., 1) - + ki(Y); - - Rcpp::NumericVector Ji = Rcpp::as(Rcpp::wrap(loglik)); - Ji.attr("weights") = w; - return Rcpp::List::create( - Rcpp::Named("M") = M, - Rcpp::Named("S2") = S2, - Rcpp::Named("Ji") = Ji, - Rcpp::Named("monitoring", Rcpp::List::create( - Rcpp::Named("status", 3 ), - Rcpp::Named("backend", "spectral" ), - Rcpp::Named("objective", objective_vec), - Rcpp::Named("iterations", total_iter ) - )) - ); -} diff --git a/src/utils.h b/src/utils.h index 415cde20..d39e91b2 100644 --- a/src/utils.h +++ b/src/utils.h @@ -78,7 +78,7 @@ inline bool converged(double val, double prev, double tol) { return std::abs(val - prev) < tol * (1.0 + std::abs(prev)); } -// ---- Config extraction for homemade Newton optimizers ---- +// ---- Config extraction for builtin Newton optimizers ---- // Centralises the containsElementNamed pattern replicated across all newton_*.cpp files. struct NewtonConfig { int maxiter = 200; diff --git a/tests/testthat/test-pln.R b/tests/testthat/test-pln.R index 8af0d072..12ebb079 100644 --- a/tests/testthat/test-pln.R +++ b/tests/testthat/test-pln.R @@ -60,7 +60,7 @@ test_that("PLN: Check consistency of observation weights - fully parameterized c ## equivalent weigths expect_output(model2 <- PLN(Abundance ~ 1, data = trichoptera, weights = rep(1.0, nrow(trichoptera))), paste("\n Initialization...", - "Adjusting a full covariance PLN model with homemade optimizer", + "Adjusting a full covariance PLN model with builtin optimizer", "Post-treatments...", "DONE!", sep = "\n "), fixed = TRUE) diff --git a/tests/testthat/test-plnfit.R b/tests/testthat/test-plnfit.R index f95d3986..c71cf124 100644 --- a/tests/testthat/test-plnfit.R +++ b/tests/testthat/test-plnfit.R @@ -9,7 +9,7 @@ test_that("PLN fit: check classes, getters and field access", { control = PLN_param(trace = 1)), " Initialization... - Adjusting a full covariance PLN model with homemade optimizer + Adjusting a full covariance PLN model with builtin optimizer Post-treatments... DONE!" ) @@ -18,7 +18,7 @@ test_that("PLN fit: check classes, getters and field access", { control = PLN_param(trace = 1, inception = model)), " Initialization... - Adjusting a full covariance PLN model with homemade optimizer + Adjusting a full covariance PLN model with builtin optimizer Post-treatments... DONE!" ) From 92070c7e7691098f49745ea98205a4496817d245 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 18:40:28 +0200 Subject: [PATCH 54/58] suppressing hybrid backend (now useless) --- NAMESPACE | 1 - R/PLN.R | 7 +++---- R/PLNLDA.R | 2 +- R/PLNfit-class.R | 4 +--- R/PLNmixture.R | 4 ++-- R/PLNnetwork.R | 4 ++-- R/ZIPLN.R | 2 +- R/utils.R | 22 ---------------------- man/PLNLDA_param.Rd | 4 ++-- man/PLNPCA_param.Rd | 2 +- man/PLN_param.Rd | 9 ++++----- man/PLNmixture_param.Rd | 6 +++--- man/PLNnetwork_param.Rd | 6 +++--- man/ZIPLN_param.Rd | 2 +- man/ZIPLNnetwork_param.Rd | 2 +- 15 files changed, 25 insertions(+), 52 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index eb38d30e..de3ca7c0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -150,5 +150,4 @@ importFrom(stats,update.formula) importFrom(stats,var) importFrom(tidyr,gather) importFrom(tidyr,replace_na) -importFrom(utils,modifyList) useDynLib(PLNmodels) diff --git a/R/PLN.R b/R/PLN.R index 15cc8e43..b7c6dde7 100644 --- a/R/PLN.R +++ b/R/PLN.R @@ -54,9 +54,8 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { #' #' Helper to define list of parameters to control the PLN fit. All arguments have defaults. #' -#' @param backend optimization back used, either "builtin" (default), "nlopt", "hybrid" or "torch". +#' @param backend optimization back used, either "builtin" (default), "nlopt" or "torch". #' "builtin" is the built-in envelope-theorem Newton optimizer (does not depend on NLOPT). -#' "hybrid" runs nlopt first for basin finding, then switches to builtin for refinement. #' @param covariance character setting the model for the covariance matrix. Either "full", "diagonal", "spherical" or "fixed". Default is "full". #' @param Omega precision matrix of the latent variables. Inverse of Sigma. Must be specified if `covariance` is "fixed" #' @param config_optim a list for controlling the optimizer (either "nlopt" or "torch" backend). See details @@ -92,7 +91,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 #' -#' When "builtin" or "hybrid" backend is used, the following entries are relevant +#' When "builtin" backend is used, the following entries are relevant #' * "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 #' * "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 #' * "maxit_em" stop the EM outer loop when the number of EM iterations exceeds maxit_em. Default is 50 @@ -107,7 +106,7 @@ PLN <- function(formula, data, subset, weights, control = PLN_param()) { #' #' @export PLN_param <- function( - backend = c("builtin", "nlopt", "hybrid", "torch"), + backend = c("builtin", "nlopt", "torch"), trace = 1, covariance = c("full", "diagonal", "spherical", "fixed"), Omega = NULL, diff --git a/R/PLNLDA.R b/R/PLNLDA.R index 8fbfc98b..792a3105 100644 --- a/R/PLNLDA.R +++ b/R/PLNLDA.R @@ -70,7 +70,7 @@ PLNLDA <- function(formula, data, subset, weights, grouping, control = PLNLDA_pa #' @inherit PLN_param details #' @export PLNLDA_param <- function( - backend = c("builtin", "nlopt", "hybrid", "torch"), + backend = c("builtin", "nlopt", "torch"), trace = 1, covariance = c("full", "diagonal", "spherical"), config_post = list(), diff --git a/R/PLNfit-class.R b/R/PLNfit-class.R index 25a7d912..bca8e8aa 100644 --- a/R/PLNfit-class.R +++ b/R/PLNfit-class.R @@ -342,14 +342,12 @@ PLNfit <- R6Class( private$torch_optimize } else if (backend == "builtin") { newton_fn - } else if (backend == "hybrid") { - make_hybrid_optimizer(nlopt_fn, newton_fn) } else { nlopt_fn } if (!is.null(nlopt_vestep_fn)) private$optimizer$vestep <- - if (backend %in% c("builtin", "hybrid")) newton_vestep_fn else nlopt_vestep_fn + if (backend == "builtin") newton_vestep_fn else nlopt_vestep_fn } ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/R/PLNmixture.R b/R/PLNmixture.R index 48251e8a..a2c66208 100644 --- a/R/PLNmixture.R +++ b/R/PLNmixture.R @@ -67,7 +67,7 @@ PLNmixture <- function(formula, data, subset, clusters = 1:5, control = PLNmixt #' #' Helper to define list of parameters to control the PLNmixture fit. All arguments have defaults. #' -#' @param backend optimization back used, either "builtin", "nlopt", "hybrid" or "torch". Default is "builtin". +#' @param backend optimization back used, either "builtin", "nlopt" or "torch". Default is "builtin". #' @param covariance character setting the model for the covariance matrices of the mixture components. Either "full", "diagonal" or "spherical". Default is "spherical". #' @param smoothing The smoothing to apply. Either, 'none', forward', 'backward' or 'both'. Default is 'both'. #' @param init_cl The initial clustering to apply. Either, 'kmeans', CAH' or a user defined clustering given as a list of clusterings, the size of which is equal to the number of clusters considered. Default is 'kmeans'. @@ -84,7 +84,7 @@ PLNmixture <- function(formula, data, subset, clusters = 1:5, control = PLNmixt #' @seealso [PLN_param()] #' @export PLNmixture_param <- function( - backend = c("builtin", "nlopt", "hybrid", "torch"), + backend = c("builtin", "nlopt", "torch"), trace = 1 , covariance = "spherical", init_cl = "kmeans" , diff --git a/R/PLNnetwork.R b/R/PLNnetwork.R index 08fb2d42..020f41dc 100644 --- a/R/PLNnetwork.R +++ b/R/PLNnetwork.R @@ -49,7 +49,7 @@ PLNnetwork <- function(formula, data, subset, weights, penalties = NULL, control #' #' Helper to define list of parameters to control the PLN fit. All arguments have defaults. #' -#' @param backend optimization back used, either "nlopt", "builtin", "hybrid" or "torch". Default is "nlopt". +#' @param backend optimization back used, either "nlopt", "builtin" or "torch". Default is "nlopt". #' Note: the "nlopt" backend converges better in PLNnetwork's outer glasso alternation than "builtin". #' @param inception_cov Covariance structure used for the inception model used to initialize the PLNfamily. Defaults to "full" and can be constrained to "diagonal" and "spherical". #' @param n_penalties an integer that specifies the number of values for the penalty grid when internally generated. Ignored when penalties is non `NULL` @@ -68,7 +68,7 @@ PLNnetwork <- function(formula, data, subset, weights, penalties = NULL, control #' @seealso [PLN_param()] #' @export PLNnetwork_param <- function( - backend = c("nlopt", "builtin", "hybrid", "torch"), + backend = c("nlopt", "builtin", "torch"), inception_cov = c("full", "spherical", "diagonal"), trace = 1 , n_penalties = 30 , diff --git a/R/ZIPLN.R b/R/ZIPLN.R index 89156703..c2b28688 100644 --- a/R/ZIPLN.R +++ b/R/ZIPLN.R @@ -68,7 +68,7 @@ ZIPLN <- function(formula, data, subset, zi = c("single", "row", "col"), control #' #' @inheritParams PLN_param #' @inheritParams PLNnetwork_param -#' @param backend optimization backend, either `"builtin"` (default, built-in Newton optimizer for the joint VE step) or `"nlopt"` (NLOPT-based CCSAQ). Unlike [PLN_param()], `"hybrid"` and `"torch"` are not supported. +#' @param backend optimization backend, either `"builtin"` (default, built-in Newton optimizer for the joint VE step) or `"nlopt"` (NLOPT-based CCSAQ). #' @param penalty a user-defined penalty to sparsify the residual covariance. Defaults to 0 (no sparsity). #' @return list of parameters used during the fit and post-processing steps #' diff --git a/R/utils.R b/R/utils.R index 709f1582..20a9868b 100644 --- a/R/utils.R +++ b/R/utils.R @@ -24,28 +24,6 @@ config_default_builtin <- ftol_em = 1e-8 ) -# Hybrid backend: two-phase optimizer — nlopt/CCSAQ (phase 1) then builtin Newton (phase 2). -# Phase 1 (nlopt) uses looser tolerances to reach the basin quickly with quasi-Newton search. -# Phase 2 (builtin, envelope-theorem Newton) refines to the full requested tolerance. -# Returns a closure with the same (data, params, config) signature as the C++ wrappers. -#' @importFrom utils modifyList -make_hybrid_optimizer <- function(opt_nlopt, opt_newton) { - function(data, params, config) { - # Phase 1: nlopt config with 10× looser tolerance for fast basin finding - config1 <- modifyList(config_default_nlopt, list( - maxeval = config$maxeval, - ftol_rel = config$ftol_in * 10 - )) - res1 <- opt_nlopt(data, params, config1) - params2 <- modifyList(params, list(B = res1$B, M = res1$M, S2 = res1$S2)) - # Phase 2: builtin Newton with full tolerance - res2 <- opt_newton(data, params2, config) - res2$monitoring$objective <- c(res1$monitoring$objective, res2$monitoring$objective) - res2$monitoring$iterations <- res1$monitoring$iterations + res2$monitoring$iterations - res2$monitoring$backend <- "hybrid" - res2 - } -} # PLNPCA builtin backend: joint L-BFGS on [vec(B); vec(C); vec(M); vec(ψ)] with strong Wolfe # line search (m=10 pairs). Only maxeval and ftol_in are read by the C++ optimizer. diff --git a/man/PLNLDA_param.Rd b/man/PLNLDA_param.Rd index 26e65cde..ef746a33 100644 --- a/man/PLNLDA_param.Rd +++ b/man/PLNLDA_param.Rd @@ -5,7 +5,7 @@ \title{Control of a PLNLDA fit} \usage{ PLNLDA_param( - backend = c("builtin", "nlopt", "hybrid", "torch"), + backend = c("builtin", "nlopt", "torch"), trace = 1, covariance = c("full", "diagonal", "spherical"), config_post = list(), @@ -62,7 +62,7 @@ When "torch" backend is used (only for PLN and PLNLDA for now), the following en \item "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 } -When "builtin" or "hybrid" backend is used, the following entries are relevant +When "builtin" backend is used, the following entries are relevant \itemize{ \item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 \item "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 diff --git a/man/PLNPCA_param.Rd b/man/PLNPCA_param.Rd index f268f543..fb219f36 100644 --- a/man/PLNPCA_param.Rd +++ b/man/PLNPCA_param.Rd @@ -70,7 +70,7 @@ When "torch" backend is used (only for PLN and PLNLDA for now), the following en \item "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 } -When "builtin" or "hybrid" backend is used, the following entries are relevant +When "builtin" backend is used, the following entries are relevant \itemize{ \item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 \item "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 diff --git a/man/PLN_param.Rd b/man/PLN_param.Rd index 6327b261..9d886002 100644 --- a/man/PLN_param.Rd +++ b/man/PLN_param.Rd @@ -5,7 +5,7 @@ \title{Control of a PLN fit} \usage{ PLN_param( - backend = c("builtin", "nlopt", "hybrid", "torch"), + backend = c("builtin", "nlopt", "torch"), trace = 1, covariance = c("full", "diagonal", "spherical", "fixed"), Omega = NULL, @@ -16,9 +16,8 @@ PLN_param( ) } \arguments{ -\item{backend}{optimization back used, either "builtin" (default), "nlopt", "hybrid" or "torch". -"builtin" is the built-in envelope-theorem Newton optimizer (does not depend on NLOPT). -"hybrid" runs nlopt first for basin finding, then switches to builtin for refinement.} +\item{backend}{optimization back used, either "builtin" (default), "nlopt" or "torch". +"builtin" is the built-in envelope-theorem Newton optimizer (does not depend on NLOPT).} \item{trace}{a integer for verbosity.} @@ -70,7 +69,7 @@ When "torch" backend is used (only for PLN and PLNLDA for now), the following en \item "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 } -When "builtin" or "hybrid" backend is used, the following entries are relevant +When "builtin" backend is used, the following entries are relevant \itemize{ \item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 \item "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 diff --git a/man/PLNmixture_param.Rd b/man/PLNmixture_param.Rd index 3107dee0..fb559161 100644 --- a/man/PLNmixture_param.Rd +++ b/man/PLNmixture_param.Rd @@ -5,7 +5,7 @@ \title{Control of a PLNmixture fit} \usage{ PLNmixture_param( - backend = c("builtin", "nlopt", "hybrid", "torch"), + backend = c("builtin", "nlopt", "torch"), trace = 1, covariance = "spherical", init_cl = "kmeans", @@ -16,7 +16,7 @@ PLNmixture_param( ) } \arguments{ -\item{backend}{optimization back used, either "builtin", "nlopt", "hybrid" or "torch". Default is "builtin".} +\item{backend}{optimization back used, either "builtin", "nlopt" or "torch". Default is "builtin".} \item{trace}{a integer for verbosity.} @@ -68,7 +68,7 @@ When "torch" backend is used (only for PLN and PLNLDA for now), the following en \item "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 } -When "builtin" or "hybrid" backend is used, the following entries are relevant +When "builtin" backend is used, the following entries are relevant \itemize{ \item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 \item "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 diff --git a/man/PLNnetwork_param.Rd b/man/PLNnetwork_param.Rd index 2a9e4017..b76da47a 100644 --- a/man/PLNnetwork_param.Rd +++ b/man/PLNnetwork_param.Rd @@ -5,7 +5,7 @@ \title{Control of PLNnetwork fit} \usage{ PLNnetwork_param( - backend = c("nlopt", "builtin", "hybrid", "torch"), + backend = c("nlopt", "builtin", "torch"), inception_cov = c("full", "spherical", "diagonal"), trace = 1, n_penalties = 30, @@ -18,7 +18,7 @@ PLNnetwork_param( ) } \arguments{ -\item{backend}{optimization back used, either "nlopt", "builtin", "hybrid" or "torch". Default is "nlopt". +\item{backend}{optimization back used, either "nlopt", "builtin" or "torch". Default is "nlopt". Note: the "nlopt" backend converges better in PLNnetwork's outer glasso alternation than "builtin".} \item{inception_cov}{Covariance structure used for the inception model used to initialize the PLNfamily. Defaults to "full" and can be constrained to "diagonal" and "spherical".} @@ -75,7 +75,7 @@ When "torch" backend is used (only for PLN and PLNLDA for now), the following en \item "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 } -When "builtin" or "hybrid" backend is used, the following entries are relevant +When "builtin" backend is used, the following entries are relevant \itemize{ \item "maxeval" stop when the number of Newton steps in the inner loop exceeds maxeval. Default is 10000 \item "ftol_in" stop the inner loop when the objective changes by less than ftol_in (relative). Default is 1e-8 diff --git a/man/ZIPLN_param.Rd b/man/ZIPLN_param.Rd index 51e675cd..b36cf537 100644 --- a/man/ZIPLN_param.Rd +++ b/man/ZIPLN_param.Rd @@ -18,7 +18,7 @@ ZIPLN_param( ) } \arguments{ -\item{backend}{optimization backend, either \code{"builtin"} (default, built-in Newton optimizer for the joint VE step) or \code{"nlopt"} (NLOPT-based CCSAQ). Unlike \code{\link[=PLN_param]{PLN_param()}}, \code{"hybrid"} and \code{"torch"} are not supported.} +\item{backend}{optimization backend, either \code{"builtin"} (default, built-in Newton optimizer for the joint VE step) or \code{"nlopt"} (NLOPT-based CCSAQ).} \item{trace}{a integer for verbosity.} diff --git a/man/ZIPLNnetwork_param.Rd b/man/ZIPLNnetwork_param.Rd index 22e1ca25..cf7dcfc7 100644 --- a/man/ZIPLNnetwork_param.Rd +++ b/man/ZIPLNnetwork_param.Rd @@ -18,7 +18,7 @@ ZIPLNnetwork_param( ) } \arguments{ -\item{backend}{optimization back used, either "nlopt", "builtin", "hybrid" or "torch". Default is "nlopt". +\item{backend}{optimization back used, either "nlopt", "builtin" or "torch". Default is "nlopt". Note: the "nlopt" backend converges better in PLNnetwork's outer glasso alternation than "builtin".} \item{inception_cov}{Covariance structure used for the inception model used to initialize the PLNfamily. Defaults to "full" and can be constrained to "diagonal" and "spherical".} From 28e2fb7d1b6342f674ca945b940de848b01fb5b6 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 20:50:28 +0200 Subject: [PATCH 55/58] benchmark plnpca --- DEVLOG_2026-06-11-12.md | 197 ++++++++++++++++++++++++++ R/PLNPCA.R | 11 +- R/PLNPCAfit-class.R | 4 +- inst/backend_comparison.R | 191 ------------------------- inst/case_studies/microcosm.qmd | 4 +- inst/case_studies/mixture_iris.R | 9 +- inst/case_studies/mollusk.R | 4 +- inst/case_studies/oaks_tree.R | 2 +- inst/convergence_analysis.R | 232 ------------------------------- src/builtin_optim_plnpca.cpp | 31 +++-- 10 files changed, 233 insertions(+), 452 deletions(-) delete mode 100644 inst/backend_comparison.R delete mode 100644 inst/convergence_analysis.R diff --git a/DEVLOG_2026-06-11-12.md b/DEVLOG_2026-06-11-12.md index fe3ce062..b663762d 100644 --- a/DEVLOG_2026-06-11-12.md +++ b/DEVLOG_2026-06-11-12.md @@ -305,3 +305,200 @@ Le qualificatif "approché" pour la formule σ était trompeur : c'est la forme - `tests/testthat/test-zipln.R` : test entier supprimé (testait l'équivalence des deux formes, fausse) Les fonctions C++ `optim_zipln_R_var` et `optim_zipln_R_exact` sont conservées dans `src/optim_zi-pln.cpp` pour mémoire historique. + +--- + +## 27. PLNPCA — Remplacement du gradient spectral par L-BFGS joint + Wolfe (12/06) + +**Fichier** : `src/builtin_rank_cov.cpp` (ex `spectral_rank_cov.cpp`) + +### Historique des tentatives + +| Approche | Résultat | +|----------|---------| +| Gradient spectral BB+GLL | Converge vers un mauvais minimum local sur oaks | +| Armijo monotone (nm_window=1) | Identique — problème structural, pas ligne de recherche | +| EM alterné BB (blocs VE / M) | Même minimum — BB diagonal contaminé par couplage M·Cᵀ | +| L-BFGS alterné par blocs + Armijo | Histoire toujours vide (Armijo ne garantit pas s^T y > 0) | +| **L-BFGS joint + Wolfe fort** | **Succès — meilleur loglik que nlopt sur tous les datasets** | +| L-BFGS par blocs EM + Wolfe interne | Pas mieux que joint, 7–10× plus lent | + +### Architecture retenue + +Optimisation jointe de tous les paramètres `[vec(B); vec(C); vec(M); vec(ψ)]` avec : +- **L-BFGS** deux-boucles (m=10 paires), initialisation steepest-descent +- **Recherche de Wolfe forte** (Nocedal & Wright Algo 3.5/3.6, c₁=1e-4, c₂=0.9) + - Garantit s^T y > 0 à chaque pas accepté → historique toujours valide + - Capture la courbure croisée M·Cᵀ que les méthodes bloc-alternantes manquent +- Warm-start ψ : un pas de point fixe `ψ = −log(1 + A·C²)` avant le premier appel L-BFGS +- Convergence : ftol consécutif + fenêtre glissante de 100 itérations + +### Benchmark (séquentiel) + +| Dataset / rank | nlopt (CCSAQ) | L-BFGS joint | +|---|---|---| +| trichoptera q=3 | −766.9 / 0.68s | **−763.7** / 0.9s | +| trichoptera q=4 | −700.6 / 0.54s | **−693.6** / 2.5s | +| trichoptera q=5 | −686.2 / 0.70s | **−672.6** / 2.9s | +| oaks q=5 | −97677 / 14.6s | **−78226** / 8.6s† | +| oaks q=10 | −66399 / 15.9s | **−47238** / 17s | + +†Résultat de session précédente (joint L-BFGS pur) : −77058 / 8.6s. L-BFGS systématiquement meilleur en loglik, couplage M·Cᵀ bien capturé. + +### Pourquoi le bloc-EM L-BFGS est-il moins bon ? + +Chaque bloc (VE : M,ψ) et (M-step : B,C) est convexe isolément → L-BFGS converge vite en interne. Mais la convergence EM extérieure est linéaire et annule ce gain : 7–10× plus lent et loglik légèrement pire que joint sur oaks. + +--- + +## 28. Nettoyage et consolidation des fichiers C++ (12/06) + +### Consolidation newton_*_cov.cpp + +Les quatre fichiers thin-wrapper (full, diagonal, spherical, fixed) sont regroupés en un seul : + +| Avant | Après | +|-------|-------| +| `newton_full_cov.cpp` | → | +| `newton_diag_cov.cpp` | → `builtin_newton_pln.cpp` | +| `newton_fixed_cov.cpp` | → | +| `newton_spherical.cpp` | → | + +### Suppression du code mort + +- `newton_rank_cov.cpp` : coordinate-Newton PLNPCA développé pendant la phase BB/spectral, jamais appelé depuis R après le passage au L-BFGS. Supprimé. + +### Renommages de fichiers + +| Ancien | Nouveau | +|--------|---------| +| `spectral_rank_cov.cpp` | `builtin_rank_cov.cpp` | +| `newton_impl.h` | `builtin_newton_impl.h` | +| `CovarianceTraits.h` | `builtin_covariance_pln.h` | + +### Renommages de fonctions + +| Ancien | Nouveau | +|--------|---------| +| `spectral_optimize_rank` | `builtin_optimize_rank` | +| `spectral_optimize_vestep_rank` | `builtin_optimize_vestep_rank` | +| `newton_optimize_*` (7 fonctions) | `builtin_optimize_*` | +| `newton_optimize_impl` | `builtin_optimize_impl` | + +### Nettoyage config PLNPCA + +- `config_default_spectral` → `config_default_plnpca` +- Champ `algorithm = "LBFGS"` supprimé (jamais lu par le C++, qui ne lit que `maxeval` et `ftol_in`) + +--- + +## 29. Renommage global `"homemade"` → `"builtin"` (12/06) + +**Portée** : tous les fichiers R, C++ sources, tests, docs, scripts `inst/`. + +Motivation : "homemade" était informel et trompeur. "builtin" décrit mieux qu'il s'agit de l'optimiseur intégré au package, sans dépendance externe. + +- Chaînes `"homemade"` dans les valeurs et vecteurs de backend +- Variables `config_default_homemade` → `config_default_builtin`, paramètre `homemade_default` → `builtin_default` +- Commentaires dans les fichiers R et C++ +- Documentation `.Rd` régénérée via `devtools::document()` + +PLNPCA : `"builtin"` devient le backend **par défaut** (ex `"nlopt"`), car il donne systématiquement un meilleur loglik. + +--- + +## 30. Suppression du backend `"hybrid"` (12/06) + +### Benchmark de justification (PLN, séquentiel) + +| Dataset | Cov | nlopt | builtin | hybrid | +|---|---|---|---|---| +| trichoptera | full | −1053.0 / 0.68s | **−1051.7** / 0.93s | −1051.7 / 0.88s | +| trichoptera | diagonal | −1109.6 | −1109.7 | **−1109.6** | +| oaks | full | −32048 / 6.5s | **−32028** / 5.9s | **−32028** / 8.2s | +| oaks | diagonal | −38408 | −38408 | −38408 | + +### Verdict + +`hybrid` (nlopt phase 1 → Newton phase 2) ne dépasse jamais `builtin` seul en loglik et est systématiquement plus lent (il paie le coût nlopt inutilement). Le Newton `builtin` converge déjà bien depuis l'initialisation froide. + +### Suppressions + +- `make_hybrid_optimizer()` supprimée de `R/utils.R` +- Branche `hybrid` retirée de `setup_optimizer()` dans `R/PLNfit-class.R` +- `"hybrid"` retiré des vecteurs `backend` dans `PLN_param`, `PLNLDA_param`, `PLNmixture_param`, `PLNnetwork_param` +- Documentation `.Rd` régénérée + +--- + +## 31. Correction de l'initialisation de M pour PLNPCA (12/06) + +**Fichier** : `R/PLNPCAfit-class.R` (ligne 262) + +### Bug + +L'initialisation de `private$M` était : +```r +M <- svdM$u[, 1:q] %*% diag(d[1:q]) %*% t(svdM$v[1:q, 1:q]) +``` + +`svdM$v[1:q, 1:q]` prend les premières `q` **lignes** (espèces) de V, pas les premières `q` composantes. C'est une erreur d'index qui donne un résultat numériquement arbitraire. + +### Correction + +Dans PLNPCA, le modèle est `Z = O + X·B + M·Cᵀ` avec `M` de taille n×q. La contrainte cohérente avec `C = V[:,1:q]·D[1:q]/√n` est que `M·Cᵀ ≈ M_PLN`. En résolvant : + +M · (V[:,1:q]·D[1:q]/√n)ᵀ = U·D·Vᵀ ⟹ M = √n · U[:,1:q] + +```r +private$M <- sqrt(self$n) * svdM$u[, 1:rank, drop = FALSE] +``` + +### Impact mesuré (trichoptera) + +| q | Erreur ‖M·Cᵀ − M_PLN‖_F (ancienne) | Erreur ‖M·Cᵀ − M_PLN‖_F (nouvelle) | +|---|---|---| +| 3 | **1174** | **13.6** | +| 5 | **1176** | **8.4** | + +### Validation + +72 tests `test-plnpcafit.R` passent. Loglik post-convergence inchangés (l'optimiseur L-BFGS corrigeait de toute façon, mais le point de départ est maintenant cohérent). + +--- + +## 32. PLNPCA — Retour à nlopt comme backend par défaut (12/06) + +**Fichiers** : `R/PLNPCA.R`, `src/builtin_optim_plnpca.cpp` + +### Diagnostic + +Benchmark sur trois jeux de données (offset corrigé) avec les backends nlopt et builtin (joint L-BFGS) : + +| Dataset | nlopt loglik | nlopt t | builtin loglik | builtin t | +|---------|-------------|---------|----------------|-----------| +| trichoptera q=3 | -640.2 | 0.44s | -640.4 | 0.40s | +| barents q=5 | **-3988.2** | 0.70s | -5957.9 | 2.02s | +| oaks q=5 | **-77290.9** | 3.50s | -78015.8 | 3.04s | + +Pour barents (d[1]/√n = 474/9.4 ≈ 50), le paysage d'optimisation a deux bassins d'attraction : +- **Bon bassin** : loglik ≈ -3988, atteint uniquement par nlopt-CCSAQ +- **Mauvais bassin** : loglik ≈ -5958, où convergent joint L-BFGS, EM alterné, et toute variante gradient-based depuis l'init SVD + +Expériences effectuées sans succès : +- Gradient balancing (σ = √(‖g_M‖/‖g_C‖)) +- EM alterné (VE step strictement convexe) — améliore barents à -5156 avec maxeval=10000, -4467 avec maxeval=50000, mais n'atteint jamais -3988 +- Combinaison EM + joint polish +- Augmentation massive du budget d'itérations + +La cause fondamentale : nlopt-CCSAQ utilise des asymptotes par variable adaptatives qui maintiennent des pas très conservatifs initialement. Ces petits pas évitent de franchir la crête séparant les deux bassins depuis l'init SVD. Les méthodes gradient à pas variable (L-BFGS/EM) sautent directement dans le mauvais bassin. + +### Décision + +- `PLNPCA_param()` : default revert à `"nlopt"` (fiable, qualité garantie) +- `"builtin"` reste disponible : légèrement plus rapide sur des données simples (trichoptera), utile pour l'exploration mais sans garantie de qualité sur des données complexes +- Code C++ `builtin_optim_plnpca.cpp` : nettoyé, retour au pur joint L-BFGS sans EM (plus simple, pas moins bon) + +### Validation + +85 tests (`test-plnpcafamily.R` + `test-plnpcafit.R`) passent. diff --git a/R/PLNPCA.R b/R/PLNPCA.R index acea2182..8a0b1fdd 100644 --- a/R/PLNPCA.R +++ b/R/PLNPCA.R @@ -58,10 +58,11 @@ PLNPCA <- function(formula, data, subset, weights, ranks = 1:5, control = PLNPCA #' #' Helper to define list of parameters to control the PLNPCA fit. All arguments have defaults. #' -#' @param backend optimization backend, either `"builtin"` (default, built-in joint L-BFGS -#' with strong Wolfe line search: all parameters B, C, M, ψ are optimised simultaneously -#' with a history of 10 curvature pairs; the Wolfe condition guarantees valid curvature -#' estimates at every step), `"nlopt"` (NLOPT/CCSAQ), +#' @param backend optimization backend, either `"nlopt"` (default, NLOPT/CCSAQ — recommended +#' for PLNPCA: conservative per-variable steps reliably find the global basin even when +#' the singular-value ratio d[1]/sqrt(n) is large), `"builtin"` (joint L-BFGS with strong +#' Wolfe line search on all parameters simultaneously — faster per iteration but may +#' converge to inferior local optima on ill-conditioned datasets), #' or `"torch"` (automatic differentiation via the torch package). #' @inheritParams PLN_param trace config_optim config_post inception #' @param sequential logical. If `TRUE`, ranks are fitted in ascending order and each model is @@ -75,7 +76,7 @@ PLNPCA <- function(formula, data, subset, weights, ranks = 1:5, control = PLNPCA #' @inherit PLN_param details #' @export PLNPCA_param <- function( - backend = c("builtin", "nlopt", "torch"), + backend = c("nlopt", "builtin", "torch"), trace = 1 , config_optim = list() , config_post = list() , diff --git a/R/PLNPCAfit-class.R b/R/PLNPCAfit-class.R index b9ff6963..ff5f4f80 100644 --- a/R/PLNPCAfit-class.R +++ b/R/PLNPCAfit-class.R @@ -258,8 +258,8 @@ PLNPCAfit <- R6Class( } else { svdM <- svd(private$M, nu = rank, nv = self$p) } - ### TODO: check that it is really better than initializing with zeros... - private$M <- svdM$u[, 1:rank, drop = FALSE] %*% diag(svdM$d[1:rank], nrow = rank, ncol = rank) %*% t(svdM$v[1:rank, 1:rank, drop = FALSE]) + # M*C^T ≈ M_PLN requires M = sqrt(n)*U when C = V*D/sqrt(n) + private$M <- sqrt(self$n) * svdM$u[, 1:rank, drop = FALSE] private$S2 <- matrix(0.01, self$n, rank) private$C <- svdM$v[, 1:rank, drop = FALSE] %*% diag(svdM$d[1:rank], nrow = rank, ncol = rank)/sqrt(self$n) }, diff --git a/inst/backend_comparison.R b/inst/backend_comparison.R deleted file mode 100644 index de4ff3a8..00000000 --- a/inst/backend_comparison.R +++ /dev/null @@ -1,191 +0,0 @@ -## ============================================================ -## Backend comparison: builtin Newton vs nlopt/CCSAQ -## Metrics: computation time, iterations, final loglik -## Datasets: trichoptera, barents, mollusk, oaks, microcosm, scRNA -## Covariances: full, diagonal, spherical (including scRNA full) -## Output: inst/benchmark/ -## ============================================================ - -suppressPackageStartupMessages({ - devtools::load_all(".", quiet = TRUE) - library(ggplot2) - library(dplyr) - library(tidyr) -}) - -ctrl_newton <- function(cov) PLN_param(backend = "builtin", covariance = cov, trace = 0) -ctrl_nlopt <- function(cov) PLN_param(backend = "nlopt", covariance = cov, trace = 0) - -## ---- Helper: fit one model with timing, return summary row ---- -fit_timed <- function(formula, data, cov, backend_ctrl, backend_name, label) { - t0 <- proc.time() - m <- tryCatch( - PLN(formula, data = data, control = backend_ctrl(cov)), - error = function(e) NULL - ) - elapsed <- (proc.time() - t0)[["elapsed"]] - if (is.null(m)) { - return(data.frame( - label = label, backend = backend_name, covariance = cov, - time_s = elapsed, n_iter = NA_integer_, loglik = NA_real_, - converged = FALSE, stringsAsFactors = FALSE - )) - } - data.frame( - label = label, - backend = backend_name, - covariance = cov, - time_s = elapsed, - n_iter = m$optim_par$iterations, - loglik = m$loglik, - converged = (m$optim_par$status == 3), - stringsAsFactors = FALSE - ) -} - -## ---- Helper: run both backends for a given (formula, data, cov) ---- -compare_both <- function(formula, data, cov, label) { - cat(sprintf(" %s [%s]...\n", label, cov)) - rbind( - fit_timed(formula, data, cov, ctrl_newton, "newton", label), - fit_timed(formula, data, cov, ctrl_nlopt, "nlopt", label) - ) -} - -## ---- Data preparation ---- -tri <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) -mol <- prepare_data(mollusk$Abundance, mollusk$Covariate) - -## ---- Run all comparisons ---- -results <- list() - -cat("=== trichoptera (n=49, p=17) ===\n") -for (cov in c("full", "diagonal", "spherical")) { - results[[length(results)+1]] <- compare_both(Abundance ~ 1, tri, cov, "tri_nocov") - results[[length(results)+1]] <- compare_both(Abundance ~ Wind + Temperature, tri, cov, "tri_cov") -} - -cat("=== barents (n=89, p=30) ===\n") -for (cov in c("full", "diagonal", "spherical")) { - results[[length(results)+1]] <- compare_both(Abundance ~ 1, barents, cov, "bar_nocov") - results[[length(results)+1]] <- compare_both(Abundance ~ Depth + Temperature, barents, cov, "bar_cov") -} - -cat("=== mollusk (n=163, p=32) ===\n") -for (cov in c("full", "diagonal", "spherical")) { - results[[length(results)+1]] <- compare_both(Abundance ~ 1, mol, cov, "mol_nocov") - results[[length(results)+1]] <- compare_both(Abundance ~ site + season, mol, cov, "mol_cov") -} - -cat("=== oaks (n=116, p=114) ===\n") -for (cov in c("full", "diagonal", "spherical")) { - results[[length(results)+1]] <- compare_both(Abundance ~ 1 + offset(log(Offset)), oaks, cov, "oak_nocov") - results[[length(results)+1]] <- compare_both(Abundance ~ tree + offset(log(Offset)), oaks, cov, "oak_cov") -} - -cat("=== microcosm (n=880, p=259) ===\n") -for (cov in c("diagonal", "spherical")) { - results[[length(results)+1]] <- compare_both(Abundance ~ 1 + offset(log(Offset)), microcosm, cov, "mic_nocov") - results[[length(results)+1]] <- compare_both(Abundance ~ site + offset(log(Offset)), microcosm, cov, "mic_cov") -} -cat(" microcosm full (slow)...\n") -for (lbl in c("mic_nocov", "mic_cov")) { - form <- if (lbl == "mic_nocov") Abundance ~ 1 + offset(log(Offset)) else Abundance ~ site + offset(log(Offset)) - results[[length(results)+1]] <- compare_both(form, microcosm, "full", lbl) -} - -cat("=== scRNA (n=3918, p=500) ===\n") -for (cov in c("diagonal", "spherical")) { - results[[length(results)+1]] <- compare_both(counts ~ 1 + offset(log(total_counts)), scRNA, cov, "scr_nocov") - results[[length(results)+1]] <- compare_both(counts ~ cell_line + offset(log(total_counts)), scRNA, cov, "scr_cov") -} -cat(" scRNA full covariance (very slow)...\n") -for (lbl in c("scr_nocov", "scr_cov")) { - form <- if (lbl == "scr_nocov") counts ~ 1 + offset(log(total_counts)) else counts ~ cell_line + offset(log(total_counts)) - results[[length(results)+1]] <- compare_both(form, scRNA, "full", lbl) -} - -cat("All fits done.\n\n") - -## ---- Combine results ---- -df <- do.call(rbind, results) -df$dataset <- sub("_.*", "", df$label) -df$covariates <- sub(".*_", "", df$label) - -## ---- Summary table (wide format) ---- -cat("========== COMPARISON SUMMARY ==========\n") -wide <- df %>% - select(label, covariance, backend, time_s, n_iter, loglik, converged) %>% - tidyr::pivot_wider( - names_from = backend, - values_from = c(time_s, n_iter, loglik, converged) - ) %>% - mutate( - loglik_diff = loglik_newton - loglik_nlopt, - speedup = time_s_nlopt / time_s_newton - ) %>% - arrange(label, covariance) - -print(wide %>% select(label, covariance, - time_newton = time_s_newton, time_nlopt = time_s_nlopt, speedup, - iter_newton = n_iter_newton, iter_nlopt = n_iter_nlopt, - ll_newton = loglik_newton, ll_nlopt = loglik_nlopt, - ll_diff = loglik_diff, - conv_newton = converged_newton, conv_nlopt = converged_nlopt - ) %>% - mutate(across(where(is.numeric), ~ signif(., 4))), - row.names = FALSE, width = 200) - -write.csv(wide, "inst/benchmark/backend_comparison.csv", row.names = FALSE) -cat("Saved: backend_comparison.csv\n") - -## ---- Plot 1: time comparison ---- -p1 <- ggplot(df, aes(x = paste(label, covariance, sep="\n"), y = time_s, fill = backend)) + - geom_col(position = "dodge", width = 0.7) + - facet_wrap(~ dataset, scales = "free", nrow = 2) + - scale_fill_manual(values = c(newton = "#E69F00", nlopt = "#56B4E9")) + - labs(title = "Computation time: Newton vs nlopt", - x = NULL, y = "Elapsed time (s)", fill = "Backend") + - theme_bw(base_size = 10) + - theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 7)) - -ggsave("inst/benchmark/backend_time.pdf", p1, width = 18, height = 10) -cat("\nSaved: backend_time.pdf\n") - -## ---- Plot 2: loglik difference (newton - nlopt) ---- -df_wide <- df %>% - pivot_wider(names_from = backend, values_from = c(time_s, n_iter, loglik, converged)) %>% - mutate(ll_diff = loglik_newton - loglik_nlopt, - fit = paste(label, covariance, sep=" / ")) - -p2 <- ggplot(df_wide, aes(x = fit, y = ll_diff, - fill = ifelse(ll_diff > 0, "Newton better", "nlopt better"))) + - geom_col(width = 0.7) + - facet_wrap(~ dataset, scales = "free", nrow = 2) + - geom_hline(yintercept = 0, linetype = "dashed") + - scale_fill_manual(values = c("Newton better" = "#009E73", "nlopt better" = "#D55E00"), - name = NULL) + - labs(title = "loglik difference: Newton minus nlopt", - subtitle = "Positive = Newton finds better solution", - x = NULL, y = "loglik(Newton) - loglik(nlopt)") + - theme_bw(base_size = 10) + - theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 7)) - -ggsave("inst/benchmark/backend_loglik.pdf", p2, width = 18, height = 10) -cat("Saved: backend_loglik.pdf\n") - -## ---- Plot 3: speedup (nlopt_time / newton_time) ---- -p3 <- ggplot(df_wide, aes(x = fit, y = time_s_nlopt / time_s_newton, - fill = dataset)) + - geom_col(width = 0.7) + - facet_wrap(~ dataset, scales = "free", nrow = 2) + - geom_hline(yintercept = 1, linetype = "dashed", colour = "grey40") + - labs(title = "Speedup: nlopt_time / newton_time", - subtitle = "> 1 means Newton is faster", - x = NULL, y = "Speedup ratio") + - theme_bw(base_size = 10) + - theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 7), - legend.position = "none") - -ggsave("inst/benchmark/backend_speedup.pdf", p3, width = 18, height = 10) -cat("Saved: backend_speedup.pdf\n") diff --git a/inst/case_studies/microcosm.qmd b/inst/case_studies/microcosm.qmd index 0f2ecd0b..1e256508 100644 --- a/inst/case_studies/microcosm.qmd +++ b/inst/case_studies/microcosm.qmd @@ -143,7 +143,7 @@ model_selection %>% gt() %>% ), locations = cells_body( columns = c("AIC"), - rows = c(4, 8, 17) + rows = c(4, 8, 16) )) %>% tab_style( style = list( @@ -152,7 +152,7 @@ model_selection %>% gt() %>% ), locations = cells_body( columns = c("ICL"), - rows = c(1, 7, 17) + rows = c(2, 7, 17) )) ``` diff --git a/inst/case_studies/mixture_iris.R b/inst/case_studies/mixture_iris.R index 08185e8e..1ac7f38c 100644 --- a/inst/case_studies/mixture_iris.R +++ b/inst/case_studies/mixture_iris.R @@ -4,25 +4,24 @@ library(PLNmodels) library(tidyverse) library(viridisLite) -nb_cores <- 4 - count <- iris %>% dplyr::select(-Species) %>% exp() %>% round() %>% as.matrix() covariate <- data.frame(Species = iris$Species) iris_data <- prepare_data(count, covariate) -my_mixtures <- PLNmixture(Abundance ~ 1 + offset(log(Offset)), clusters = 1:5, data = iris_data, control_main = list(core = nb_cores)) +my_mixtures <- PLNmixture(Abundance ~ 1 + offset(log(Offset)), clusters = 1:5, data = iris_data) plot(my_mixtures) myPLN <- getBestModel(my_mixtures) +myPLN <- getModel(my_mixtures, 3) plot(myPLN, type = "pca") plot(myPLN, type = "matrix") aricode::ARI(myPLN$memberships, iris$Species) -my_mixtures_covar <- PLNmixture(Abundance ~ 0 + Species + offset(log(Offset)), clusters = 1:3, data = iris_data, control_main = list(core = nb_cores)) +my_mixtures_covar <- PLNmixture(Abundance ~ 0 + Species + offset(log(Offset)), clusters = 1:3, data = iris_data) plot(my_mixtures_covar) -myPLN_covar <- getBestModel(my_mixtures_covar) +myPLN_covar <- getModel(my_mixtures_covar, 2) plot(myPLN_covar, "pca") plot(myPLN_covar, "matrix") diff --git a/inst/case_studies/mollusk.R b/inst/case_studies/mollusk.R index cb350efa..c2498602 100644 --- a/inst/case_studies/mollusk.R +++ b/inst/case_studies/mollusk.R @@ -7,8 +7,8 @@ mollusc <- prepare_data(mollusk$Abundance, mollusk$Covariate)#> Warning: Sample( ## simple PLN system.time(myPLN_M0 <- PLN(Abundance ~ 1 + offset(log(Offset)), data = mollusc)) system.time(myPLN <- PLN(Abundance ~ 0 + site + offset(log(Offset)), data = mollusc)) -system.time(myPLN_diagonal <- PLN(Abundance ~ 0 + site + offset(log(Offset)), data = mollusc, control = list(covariance = "diagonal"))) -system.time(myPLN_spherical <- PLN(Abundance ~ 0 + site + offset(log(Offset)), data = mollusc, control = list(covariance = "spherical"))) +system.time(myPLN_diagonal <- PLN(Abundance ~ 0 + site + offset(log(Offset)), data = mollusc, control = PLN_param(covariance = "diagonal"))) +system.time(myPLN_spherical <- PLN(Abundance ~ 0 + site + offset(log(Offset)), data = mollusc, control = PLN_param(covariance = "spherical"))) rbind( myPLN_M0$criteria, diff --git a/inst/case_studies/oaks_tree.R b/inst/case_studies/oaks_tree.R index 4f6b42a7..a39acc73 100644 --- a/inst/case_studies/oaks_tree.R +++ b/inst/case_studies/oaks_tree.R @@ -89,7 +89,7 @@ factoextra::fviz_pca_biplot( labs(col = "distance (cm)") + scale_color_viridis_c() ## Network inference with sparce covariance estimation -system.time(myPLNnets <- PLNnetwork(Abundance ~ 0 + tree + offset(log(Offset)), data = oaks, control = PLNnetwork_param(min_ratio = 0.05))) +system.time(myPLNnets <- PLNnetwork(Abundance ~ 0 + tree + offset(log(Offset)), data = oaks, control = PLNnetwork_param(min_ratio = 0.01))) plot(myPLNnets) plot(getBestModel(myPLNnets, "EBIC")) # stability_selection(myPLNnets) diff --git a/inst/convergence_analysis.R b/inst/convergence_analysis.R deleted file mode 100644 index d109df59..00000000 --- a/inst/convergence_analysis.R +++ /dev/null @@ -1,232 +0,0 @@ -## ============================================================ -## Convergence analysis of the builtin Newton backend -## Datasets: trichoptera (n=49, p=17), barents (n=89, p=30), -## mollusk (n=163, p=32), oaks (n=116, p=114), -## microcosm (n=880, p=259), scRNA (n=3918, p=500) -## Covariances: full, diagonal, spherical -## With / without covariates -## Note: full covariance for microcosm (~30-60s) and scRNA (very slow) included -## Output: inst/benchmark/ -## ============================================================ - -suppressPackageStartupMessages({ - devtools::load_all(".", quiet = TRUE) - library(ggplot2) - library(tidyr) -}) - -ctrl <- function(cov) PLN_param(backend = "builtin", covariance = cov, trace = 0) - -## ---- trichoptera (n=49, p=17) ---- -cat("Fitting trichoptera...\n") -tri <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) -fits <- list( - tri_full_nocov = PLN(Abundance ~ 1, data = tri, control = ctrl("full")), - tri_diag_nocov = PLN(Abundance ~ 1, data = tri, control = ctrl("diagonal")), - tri_sph_nocov = PLN(Abundance ~ 1, data = tri, control = ctrl("spherical")), - tri_full_cov = PLN(Abundance ~ Wind + Temperature, data = tri, control = ctrl("full")), - tri_diag_cov = PLN(Abundance ~ Wind + Temperature, data = tri, control = ctrl("diagonal")), - tri_sph_cov = PLN(Abundance ~ Wind + Temperature, data = tri, control = ctrl("spherical")) -) - -## ---- barents (n=89, p=30) ---- -cat("Fitting barents...\n") -fits <- c(fits, list( - bar_full_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = barents, control = ctrl("full")), - bar_diag_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = barents, control = ctrl("diagonal")), - bar_sph_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = barents, control = ctrl("spherical")), - bar_full_cov = PLN(Abundance ~ Depth + Temperature + offset(log(Offset)), data = barents, control = ctrl("full")), - bar_diag_cov = PLN(Abundance ~ Depth + Temperature + offset(log(Offset)), data = barents, control = ctrl("diagonal")), - bar_sph_cov = PLN(Abundance ~ Depth + Temperature + offset(log(Offset)), data = barents, control = ctrl("spherical")) -)) - -## ---- mollusk (n=163, p=32) ---- -cat("Fitting mollusk...\n") -mol <- prepare_data(mollusk$Abundance, mollusk$Covariate) -fits <- c(fits, list( - mol_full_nocov = PLN(Abundance ~ 1, data = mol, control = ctrl("full")), - mol_diag_nocov = PLN(Abundance ~ 1, data = mol, control = ctrl("diagonal")), - mol_sph_nocov = PLN(Abundance ~ 1, data = mol, control = ctrl("spherical")), - mol_full_cov = PLN(Abundance ~ site + season, data = mol, control = ctrl("full")), - mol_diag_cov = PLN(Abundance ~ site + season, data = mol, control = ctrl("diagonal")), - mol_sph_cov = PLN(Abundance ~ site + season, data = mol, control = ctrl("spherical")) -)) - -## ---- oaks (n=116, p=114) ---- -cat("Fitting oaks...\n") -fits <- c(fits, list( - oak_full_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = oaks, control = ctrl("full")), - oak_diag_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = oaks, control = ctrl("diagonal")), - oak_sph_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = oaks, control = ctrl("spherical")), - oak_full_cov = PLN(Abundance ~ tree + offset(log(Offset)), data = oaks, control = ctrl("full")), - oak_diag_cov = PLN(Abundance ~ tree + offset(log(Offset)), data = oaks, control = ctrl("diagonal")), - oak_sph_cov = PLN(Abundance ~ tree + offset(log(Offset)), data = oaks, control = ctrl("spherical")) -)) - -## ---- microcosm (n=880, p=259) ---- -cat("Fitting microcosm (diagonal + spherical)...\n") -fits <- c(fits, list( - mic_diag_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = microcosm, control = ctrl("diagonal")), - mic_sph_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = microcosm, control = ctrl("spherical")), - mic_diag_cov = PLN(Abundance ~ site + offset(log(Offset)), data = microcosm, control = ctrl("diagonal")), - mic_sph_cov = PLN(Abundance ~ site + offset(log(Offset)), data = microcosm, control = ctrl("spherical")) -)) -cat("Fitting microcosm full covariance (slow — O(n·p²) M-step with n=880, p=259)...\n") -fits <- c(fits, list( - mic_full_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = microcosm, control = ctrl("full")), - mic_full_cov = PLN(Abundance ~ site + offset(log(Offset)), data = microcosm, control = ctrl("full")) -)) - -## ---- scRNA (n=3918, p=500) — full covariance skipped ---- -cat("Fitting scRNA diagonal + spherical (n=3918, p=500)...\n") -fits <- c(fits, list( - scr_diag_nocov = PLN(counts ~ 1 + offset(log(total_counts)), data = scRNA, control = ctrl("diagonal")), - scr_sph_nocov = PLN(counts ~ 1 + offset(log(total_counts)), data = scRNA, control = ctrl("spherical")), - scr_diag_cov = PLN(counts ~ cell_line + offset(log(total_counts)), data = scRNA, control = ctrl("diagonal")), - scr_sph_cov = PLN(counts ~ cell_line + offset(log(total_counts)), data = scRNA, control = ctrl("spherical")) -)) -cat("Fitting scRNA full covariance (very slow — O(n·p²) M-step with n=3918, p=500)...\n") -fits <- c(fits, list( - scr_full_nocov = PLN(counts ~ 1 + offset(log(total_counts)), data = scRNA, control = ctrl("full")), - scr_full_cov = PLN(counts ~ cell_line + offset(log(total_counts)), data = scRNA, control = ctrl("full")) -)) - -cat("All fits done.\n") - -## ---- Extract monitoring ---- -mon <- lapply(names(fits), function(nm) { - m <- fits[[nm]]$optim_par - obj <- m$objective - obj_norm <- (obj - min(obj)) / (max(obj) - min(obj) + .Machine$double.eps) - rel_change <- abs(diff(obj)) / (abs(obj[-length(obj)]) + 1e-30) - tail_n <- max(5L, as.integer(0.2 * length(rel_change))) - tail_slope <- if (all(tail(rel_change, tail_n) > 0)) - mean(log10(tail(rel_change, tail_n) + 1e-30)) - else NA_real_ - parts <- strsplit(nm, "_")[[1]] - list( - name = nm, - dataset = parts[1], - covariance = parts[2], - covariates = parts[3], - n_iter = m$iterations, - status = m$status, - converged = (m$status == 3), - obj_init = obj[1], - obj_final = obj[length(obj)], - rel_drop = (obj[1] - obj[length(obj)]) / abs(obj[1]), - last_delta = rel_change[length(rel_change)], - tail_slope = tail_slope, - obj_seq = obj, - rel_seq = rel_change, - obj_norm_seq = obj_norm - ) -}) - -## ---- Summary table ---- -cat("\n========== CONVERGENCE SUMMARY ==========\n") -sumtab <- do.call(rbind, lapply(mon, function(x) { - data.frame( - fit = x$name, - n_iter = x$n_iter, - converged = x$converged, - rel_drop = signif(x$rel_drop, 3), - last_delta = signif(x$last_delta, 3), - tail_slope = signif(x$tail_slope, 3), - stringsAsFactors = FALSE - ) -})) -print(sumtab, row.names = FALSE) - -## ---- Plateau detection ---- -cat("\n========== PLATEAU DETECTION (fraction of steps with delta < 1e-6) ==========\n") -for (x in mon) { - r <- x$rel_seq - frac_flat <- mean(r < 1e-6) - cat(sprintf(" %-25s %5.1f%% flat steps | %d total\n", - x$name, 100*frac_flat, x$n_iter)) -} - -## ---- EM kink detection ---- -cat("\n========== EM KINK DETECTION (local minima in rel-change = EM M-step boundaries) ==========\n") -for (x in mon) { - r <- x$rel_seq - kinks <- which(diff(sign(diff(log(r + 1e-30)))) == 2) - cat(sprintf(" %-25s ~%d EM kinks in %d inner steps (%.1f steps/EM)\n", - x$name, length(kinks), x$n_iter, - if (length(kinks) > 0) x$n_iter / length(kinks) else NaN)) -} - -## ---- Convergence speed ---- -cat("\n========== CONVERGENCE RATE (mean log10 rel-change in last 20% of steps) ==========\n") -for (x in mon) { - cat(sprintf(" %-25s tail log10(delta) = %.2f (higher = slower)\n", - x$name, x$tail_slope)) -} - -## ---- Build tidy data frames for plots ---- -df_traj <- do.call(rbind, lapply(mon, function(x) { - data.frame(name = x$name, dataset = x$dataset, covariance = x$covariance, - covariates = x$covariates, - step = seq_along(x$obj_norm_seq), obj_norm = x$obj_norm_seq, - stringsAsFactors = FALSE) -})) - -df_rel <- do.call(rbind, lapply(mon, function(x) { - data.frame(name = x$name, dataset = x$dataset, covariance = x$covariance, - covariates = x$covariates, - step = seq_along(x$rel_seq), rel_change = pmax(x$rel_seq, 1e-16), - stringsAsFactors = FALSE) -})) - -## ---- Plot 1: normalised objective (log1p) ---- -dataset_labels <- c(tri = "trichoptera (n=49, p=17)", - bar = "barents (n=89, p=30)", - mol = "mollusk (n=163, p=32)", - oak = "oaks (n=116, p=114)", - mic = "microcosm (n=880, p=259)", - scr = "scRNA (n=3918, p=500)") - -p1 <- ggplot(df_traj, aes(step, obj_norm + 1e-6, colour = covariance, linetype = covariates)) + - geom_line(linewidth = 0.6) + - facet_wrap(~ dataset, scales = "free_x", - labeller = labeller(dataset = dataset_labels)) + - scale_y_log10() + - labs(title = "Normalised inner objective (log10 scale)", - subtitle = "(obj - obj_min) / range -- 0 = fully converged", - x = "Newton step (cumulated over EM)", y = "Normalised obj", - colour = "Covariance", linetype = "Covariates") + - theme_bw(base_size = 11) - -ggsave("inst/benchmark/convergence_trajectory.pdf", p1, width = 15, height = 8) -cat("\nSaved: convergence_trajectory.pdf\n") - -## ---- Plot 2: per-step relative change ---- -p2 <- ggplot(df_rel, aes(step, rel_change, colour = covariance, linetype = covariates)) + - geom_line(linewidth = 0.5, alpha = 0.8) + - facet_wrap(~ dataset, scales = "free", - labeller = labeller(dataset = dataset_labels)) + - scale_y_log10() + - geom_hline(yintercept = 1e-8, linetype = "dotted", colour = "grey50") + - labs(title = "Per-step relative change |dobj|/|obj| (log10)", - subtitle = "Dotted = ftol_in = 1e-8 | Bumps = EM M-step boundary", - x = "Newton step", y = "Relative change", - colour = "Covariance", linetype = "Covariates") + - theme_bw(base_size = 11) - -ggsave("inst/benchmark/convergence_rel_change.pdf", p2, width = 15, height = 8) -cat("Saved: convergence_rel_change.pdf\n") - -## ---- Plot 3: distribution of step sizes ---- -p3 <- ggplot(df_rel, aes(rel_change, fill = covariance)) + - geom_histogram(bins = 50, alpha = 0.65, position = "identity") + - facet_grid(dataset ~ covariates, scales = "free_y", - labeller = labeller(dataset = dataset_labels)) + - scale_x_log10() + - geom_vline(xintercept = 1e-8, linetype = "dotted") + - labs(title = "Distribution of per-step relative changes", - x = "Relative change (log10)", fill = "Covariance") + - theme_bw(base_size = 10) - -ggsave("inst/benchmark/convergence_step_dist.pdf", p3, width = 12, height = 14) -cat("Saved: convergence_step_dist.pdf\n") diff --git a/src/builtin_optim_plnpca.cpp b/src/builtin_optim_plnpca.cpp index 0d97ce1f..23d3a171 100644 --- a/src/builtin_optim_plnpca.cpp +++ b/src/builtin_optim_plnpca.cpp @@ -11,9 +11,14 @@ // Strong Wolfe line search guarantees s^T y > 0 at every accepted step, so the // L-BFGS history always accumulates valid curvature pairs including the bilinear // M·Cᵀ cross-curvature that block-coordinate methods miss. +// +// Note: for datasets with large d[1]/sqrt(n) (e.g. barents), joint L-BFGS may +// converge to a local optimum inferior to nlopt-CCSAQ. The nlopt backend is +// recommended when solution quality is the priority. // --------------------------------------------------------------------------------------- // L-BFGS two-loop recursion: returns search direction p = -H_k · g + static arma::vec lbfgs_direction( const arma::vec & g, const std::deque & sv, @@ -49,13 +54,14 @@ struct WolfeStep { double scale; double f; arma::vec g; }; template static WolfeStep wolfe_ls( const arma::vec & x0, const arma::vec & d, - double f0, double slope0, FG fg, + double f0, double slope0, FG && fg, const double c1 = 1e-4, const double c2 = 0.9 ) { auto zoom = [&](double alo, double ahi, double flo) -> WolfeStep { for (int j = 0; j < 20; j++) { double a = 0.5 * (alo + ahi); - auto [fa, ga] = fg(x0 + a * d); + auto res = fg(x0 + a * d); + double fa = res.first; arma::vec ga = res.second; if (fa > f0 + c1*a*slope0 || fa >= flo) { ahi = a; } else { double da = arma::dot(ga, d); @@ -65,12 +71,13 @@ static WolfeStep wolfe_ls( } } double a = 0.5 * (alo + ahi); - auto [fa, ga] = fg(x0 + a * d); - return {a, fa, ga}; + auto res = fg(x0 + a * d); + return {a, res.first, res.second}; }; double a = 1.0, ap = 0, fp = f0; for (int i = 0; i < 20; i++) { - auto [fa, ga] = fg(x0 + a * d); + auto res = fg(x0 + a * d); + double fa = res.first; arma::vec ga = res.second; if (fa > f0 + c1*a*slope0 || (i > 0 && fa >= fp)) return zoom(ap, a, fp); double da = arma::dot(ga, d); if (std::abs(da) <= -c2 * slope0) return {a, fa, ga}; @@ -78,8 +85,8 @@ static WolfeStep wolfe_ls( ap = a; fp = fa; a = std::min(2.0 * a, 1e6); } - auto [fa, ga] = fg(x0 + a * d); - return {a, fa, ga}; + auto res = fg(x0 + a * d); + return {a, res.first, res.second}; } // --------------------------------------------------------------------------------------- @@ -132,7 +139,7 @@ Rcpp::List builtin_optimize_rank( double f = arma::accu(w.t() * (A_ - Y % Z_)) + 0.5 * arma::accu(w.t() * (M_ % M_ + S2_ - psi_ - 1.)); arma::mat AmY = A_ - Y; - arma::mat AmYw = AmY; AmYw.each_col() %= w; + arma::mat AmYw = AmY; AmYw.each_col() %= w; arma::mat gB_ = Xw.t() * AmY; arma::mat gC_ = AmYw.t() * M_ + (A_.t() * (S2_.each_col() % w)) % C_; arma::mat gM_ = AmY * C_ + M_; gM_.each_col() %= w; @@ -143,11 +150,12 @@ Rcpp::List builtin_optimize_rank( return {f, g}; }; - // Initial packed state and evaluation + // Initial packed state arma::vec x = arma::join_cols( arma::join_cols(arma::vectorise(B), arma::vectorise(C)), arma::join_cols(arma::vectorise(M), arma::vectorise(psi))); - auto [f_cur, g_cur] = fg(x); + + auto res0 = fg(x); double f_cur = res0.first; arma::vec g_cur = res0.second; std::deque sv, yv; std::vector objective_vec; @@ -186,7 +194,6 @@ Rcpp::List builtin_optimize_rank( WolfeStep ws = wolfe_ls(x, d_lbfgs, f_cur, slope, fg); - // Update L-BFGS history (guarded by curvature condition) arma::vec s_new = ws.scale * d_lbfgs; arma::vec y_new = ws.g - g_cur; double sy = arma::dot(s_new, y_new), ss = arma::dot(s_new, s_new); @@ -287,7 +294,7 @@ Rcpp::List builtin_optimize_vestep_rank( }; arma::vec x = arma::join_cols(arma::vectorise(M), arma::vectorise(psi)); - auto [f_cur, g_cur] = fg(x); + auto res0 = fg(x); double f_cur = res0.first; arma::vec g_cur = res0.second; std::deque sv, yv; std::vector objective_vec; From 7094ff70c28f5e05e1012354d2c71b604c754e7d Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 20:50:57 +0200 Subject: [PATCH 56/58] benchmark directory in inst --- inst/benchmark/backend_comparison.R | 191 +++++++++++++++++++++ inst/benchmark/benchmark_backends.R | 118 +++++++++++++ inst/benchmark/convergence_analysis.R | 232 ++++++++++++++++++++++++++ 3 files changed, 541 insertions(+) create mode 100644 inst/benchmark/backend_comparison.R create mode 100644 inst/benchmark/benchmark_backends.R create mode 100644 inst/benchmark/convergence_analysis.R diff --git a/inst/benchmark/backend_comparison.R b/inst/benchmark/backend_comparison.R new file mode 100644 index 00000000..de4ff3a8 --- /dev/null +++ b/inst/benchmark/backend_comparison.R @@ -0,0 +1,191 @@ +## ============================================================ +## Backend comparison: builtin Newton vs nlopt/CCSAQ +## Metrics: computation time, iterations, final loglik +## Datasets: trichoptera, barents, mollusk, oaks, microcosm, scRNA +## Covariances: full, diagonal, spherical (including scRNA full) +## Output: inst/benchmark/ +## ============================================================ + +suppressPackageStartupMessages({ + devtools::load_all(".", quiet = TRUE) + library(ggplot2) + library(dplyr) + library(tidyr) +}) + +ctrl_newton <- function(cov) PLN_param(backend = "builtin", covariance = cov, trace = 0) +ctrl_nlopt <- function(cov) PLN_param(backend = "nlopt", covariance = cov, trace = 0) + +## ---- Helper: fit one model with timing, return summary row ---- +fit_timed <- function(formula, data, cov, backend_ctrl, backend_name, label) { + t0 <- proc.time() + m <- tryCatch( + PLN(formula, data = data, control = backend_ctrl(cov)), + error = function(e) NULL + ) + elapsed <- (proc.time() - t0)[["elapsed"]] + if (is.null(m)) { + return(data.frame( + label = label, backend = backend_name, covariance = cov, + time_s = elapsed, n_iter = NA_integer_, loglik = NA_real_, + converged = FALSE, stringsAsFactors = FALSE + )) + } + data.frame( + label = label, + backend = backend_name, + covariance = cov, + time_s = elapsed, + n_iter = m$optim_par$iterations, + loglik = m$loglik, + converged = (m$optim_par$status == 3), + stringsAsFactors = FALSE + ) +} + +## ---- Helper: run both backends for a given (formula, data, cov) ---- +compare_both <- function(formula, data, cov, label) { + cat(sprintf(" %s [%s]...\n", label, cov)) + rbind( + fit_timed(formula, data, cov, ctrl_newton, "newton", label), + fit_timed(formula, data, cov, ctrl_nlopt, "nlopt", label) + ) +} + +## ---- Data preparation ---- +tri <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +mol <- prepare_data(mollusk$Abundance, mollusk$Covariate) + +## ---- Run all comparisons ---- +results <- list() + +cat("=== trichoptera (n=49, p=17) ===\n") +for (cov in c("full", "diagonal", "spherical")) { + results[[length(results)+1]] <- compare_both(Abundance ~ 1, tri, cov, "tri_nocov") + results[[length(results)+1]] <- compare_both(Abundance ~ Wind + Temperature, tri, cov, "tri_cov") +} + +cat("=== barents (n=89, p=30) ===\n") +for (cov in c("full", "diagonal", "spherical")) { + results[[length(results)+1]] <- compare_both(Abundance ~ 1, barents, cov, "bar_nocov") + results[[length(results)+1]] <- compare_both(Abundance ~ Depth + Temperature, barents, cov, "bar_cov") +} + +cat("=== mollusk (n=163, p=32) ===\n") +for (cov in c("full", "diagonal", "spherical")) { + results[[length(results)+1]] <- compare_both(Abundance ~ 1, mol, cov, "mol_nocov") + results[[length(results)+1]] <- compare_both(Abundance ~ site + season, mol, cov, "mol_cov") +} + +cat("=== oaks (n=116, p=114) ===\n") +for (cov in c("full", "diagonal", "spherical")) { + results[[length(results)+1]] <- compare_both(Abundance ~ 1 + offset(log(Offset)), oaks, cov, "oak_nocov") + results[[length(results)+1]] <- compare_both(Abundance ~ tree + offset(log(Offset)), oaks, cov, "oak_cov") +} + +cat("=== microcosm (n=880, p=259) ===\n") +for (cov in c("diagonal", "spherical")) { + results[[length(results)+1]] <- compare_both(Abundance ~ 1 + offset(log(Offset)), microcosm, cov, "mic_nocov") + results[[length(results)+1]] <- compare_both(Abundance ~ site + offset(log(Offset)), microcosm, cov, "mic_cov") +} +cat(" microcosm full (slow)...\n") +for (lbl in c("mic_nocov", "mic_cov")) { + form <- if (lbl == "mic_nocov") Abundance ~ 1 + offset(log(Offset)) else Abundance ~ site + offset(log(Offset)) + results[[length(results)+1]] <- compare_both(form, microcosm, "full", lbl) +} + +cat("=== scRNA (n=3918, p=500) ===\n") +for (cov in c("diagonal", "spherical")) { + results[[length(results)+1]] <- compare_both(counts ~ 1 + offset(log(total_counts)), scRNA, cov, "scr_nocov") + results[[length(results)+1]] <- compare_both(counts ~ cell_line + offset(log(total_counts)), scRNA, cov, "scr_cov") +} +cat(" scRNA full covariance (very slow)...\n") +for (lbl in c("scr_nocov", "scr_cov")) { + form <- if (lbl == "scr_nocov") counts ~ 1 + offset(log(total_counts)) else counts ~ cell_line + offset(log(total_counts)) + results[[length(results)+1]] <- compare_both(form, scRNA, "full", lbl) +} + +cat("All fits done.\n\n") + +## ---- Combine results ---- +df <- do.call(rbind, results) +df$dataset <- sub("_.*", "", df$label) +df$covariates <- sub(".*_", "", df$label) + +## ---- Summary table (wide format) ---- +cat("========== COMPARISON SUMMARY ==========\n") +wide <- df %>% + select(label, covariance, backend, time_s, n_iter, loglik, converged) %>% + tidyr::pivot_wider( + names_from = backend, + values_from = c(time_s, n_iter, loglik, converged) + ) %>% + mutate( + loglik_diff = loglik_newton - loglik_nlopt, + speedup = time_s_nlopt / time_s_newton + ) %>% + arrange(label, covariance) + +print(wide %>% select(label, covariance, + time_newton = time_s_newton, time_nlopt = time_s_nlopt, speedup, + iter_newton = n_iter_newton, iter_nlopt = n_iter_nlopt, + ll_newton = loglik_newton, ll_nlopt = loglik_nlopt, + ll_diff = loglik_diff, + conv_newton = converged_newton, conv_nlopt = converged_nlopt + ) %>% + mutate(across(where(is.numeric), ~ signif(., 4))), + row.names = FALSE, width = 200) + +write.csv(wide, "inst/benchmark/backend_comparison.csv", row.names = FALSE) +cat("Saved: backend_comparison.csv\n") + +## ---- Plot 1: time comparison ---- +p1 <- ggplot(df, aes(x = paste(label, covariance, sep="\n"), y = time_s, fill = backend)) + + geom_col(position = "dodge", width = 0.7) + + facet_wrap(~ dataset, scales = "free", nrow = 2) + + scale_fill_manual(values = c(newton = "#E69F00", nlopt = "#56B4E9")) + + labs(title = "Computation time: Newton vs nlopt", + x = NULL, y = "Elapsed time (s)", fill = "Backend") + + theme_bw(base_size = 10) + + theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 7)) + +ggsave("inst/benchmark/backend_time.pdf", p1, width = 18, height = 10) +cat("\nSaved: backend_time.pdf\n") + +## ---- Plot 2: loglik difference (newton - nlopt) ---- +df_wide <- df %>% + pivot_wider(names_from = backend, values_from = c(time_s, n_iter, loglik, converged)) %>% + mutate(ll_diff = loglik_newton - loglik_nlopt, + fit = paste(label, covariance, sep=" / ")) + +p2 <- ggplot(df_wide, aes(x = fit, y = ll_diff, + fill = ifelse(ll_diff > 0, "Newton better", "nlopt better"))) + + geom_col(width = 0.7) + + facet_wrap(~ dataset, scales = "free", nrow = 2) + + geom_hline(yintercept = 0, linetype = "dashed") + + scale_fill_manual(values = c("Newton better" = "#009E73", "nlopt better" = "#D55E00"), + name = NULL) + + labs(title = "loglik difference: Newton minus nlopt", + subtitle = "Positive = Newton finds better solution", + x = NULL, y = "loglik(Newton) - loglik(nlopt)") + + theme_bw(base_size = 10) + + theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 7)) + +ggsave("inst/benchmark/backend_loglik.pdf", p2, width = 18, height = 10) +cat("Saved: backend_loglik.pdf\n") + +## ---- Plot 3: speedup (nlopt_time / newton_time) ---- +p3 <- ggplot(df_wide, aes(x = fit, y = time_s_nlopt / time_s_newton, + fill = dataset)) + + geom_col(width = 0.7) + + facet_wrap(~ dataset, scales = "free", nrow = 2) + + geom_hline(yintercept = 1, linetype = "dashed", colour = "grey40") + + labs(title = "Speedup: nlopt_time / newton_time", + subtitle = "> 1 means Newton is faster", + x = NULL, y = "Speedup ratio") + + theme_bw(base_size = 10) + + theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 7), + legend.position = "none") + +ggsave("inst/benchmark/backend_speedup.pdf", p3, width = 18, height = 10) +cat("Saved: backend_speedup.pdf\n") diff --git a/inst/benchmark/benchmark_backends.R b/inst/benchmark/benchmark_backends.R new file mode 100644 index 00000000..dde97032 --- /dev/null +++ b/inst/benchmark/benchmark_backends.R @@ -0,0 +1,118 @@ +## Benchmark backends (nlopt / builtin / torch) sur PLN, ZIPLN, PLNPCA +## Jeux de données : trichoptera (n=49, p=17), barents (n=89, p=30), oaks (n=116, p=114) +## IMPORTANT : séquentiel uniquement (BLAS multithreadé) + +devtools::load_all(quiet = TRUE) +library(PLNmodels) + +# ── Données ────────────────────────────────────────────────────────────────── +data(trichoptera) +data(barents) +data(oaks) + +datasets <- list( + trichoptera = list( + data = prepare_data(trichoptera$Abundance, trichoptera$Covariate), + formula = Abundance ~ 1 + offset(log(Offset)), + pca_rank = 3L + ), + barents = list( + data = barents, + formula = Abundance ~ Temperature + Depth + offset(log(Offset)), + pca_rank = 5L + ), + oaks = list( + data = prepare_data(oaks$Abundance, oaks[, c("tree", "distTOtrunk", "orientation", "pmInfection")], + offset = oaks$Offset), + formula = Abundance ~ 1 + offset(log(Offset)), + pca_rank = 5L + ) +) + +backends_pln <- c("nlopt", "builtin", "torch") +backends_zipln <- c("nlopt", "builtin") # torch non supporté pour ZIPLN +backends_pca <- c("nlopt", "builtin", "torch") +cov_types <- c("full", "diagonal", "spherical") + +# ── Helper ─────────────────────────────────────────────────────────────────── +run_one <- function(expr) { + t <- system.time(m <- tryCatch(expr, error = function(e) { message(" ERROR: ", e$message); NULL })) + if (is.null(m)) return(data.frame(loglik = NA, iterations = NA, time = NA)) + # PLNPCA : récupérer le premier (seul) modèle + if (inherits(m, "PLNPCAfamily")) m <- m$models[[1]] + data.frame( + loglik = round(m$loglik, 3), + iterations = m$optim_par$iterations, + time = round(t["elapsed"], 3) + ) +} + +# ── Benchmark ───────────────────────────────────────────────────────────────── +results <- list() + +for (dname in names(datasets)) { + ds <- datasets[[dname]] + cat("\n══════════════════════════════════════════════\n") + cat(" Dataset:", dname, "\n") + cat("══════════════════════════════════════════════\n") + + # ── PLN (full / diagonal / spherical) ────────────────────────────────────── + for (cov in cov_types) { + for (bk in backends_pln) { + tag <- sprintf("PLN-%s / %s / %s", cov, bk, dname) + cat(" ", tag, "...") + res <- run_one( + PLN(ds$formula, data = ds$data, + control = PLN_param(backend = bk, covariance = cov, trace = 0)) + ) + cat(sprintf(" loglik=%.1f iter=%s t=%.2fs\n", + res$loglik, res$iterations, res$time)) + results[[tag]] <- cbind(model = "PLN", covariance = cov, + backend = bk, dataset = dname, res) + } + } + + # ── ZIPLN ────────────────────────────────────────────────────────────────── + for (bk in backends_zipln) { + tag <- sprintf("ZIPLN / %s / %s", bk, dname) + cat(" ", tag, "...") + res <- run_one( + ZIPLN(ds$formula, data = ds$data, + control = ZIPLN_param(backend = bk, trace = 0)) + ) + cat(sprintf(" loglik=%.1f iter=%s t=%.2fs\n", + res$loglik, res$iterations, res$time)) + results[[tag]] <- cbind(model = "ZIPLN", covariance = "full", + backend = bk, dataset = dname, res) + } + + # ── PLNPCA ───────────────────────────────────────────────────────────────── + for (bk in backends_pca) { + tag <- sprintf("PLNPCA(q=%d) / %s / %s", ds$pca_rank, bk, dname) + cat(" ", tag, "...") + res <- run_one( + PLNPCA(ds$formula, data = ds$data, ranks = ds$pca_rank, + control = PLNPCA_param(backend = bk, trace = 0)) + ) + cat(sprintf(" loglik=%.1f iter=%s t=%.2fs\n", + res$loglik, res$iterations, res$time)) + results[[tag]] <- cbind(model = sprintf("PLNPCA(q=%d)", ds$pca_rank), + covariance = NA, backend = bk, dataset = dname, res) + } +} + +# ── Tableau récapitulatif ───────────────────────────────────────────────────── +cat("\n\n══════════════════════════════════════════════\n") +cat(" RÉCAPITULATIF\n") +cat("══════════════════════════════════════════════\n\n") + +df <- do.call(rbind, results) +rownames(df) <- NULL + +# Affichage par dataset +for (dname in names(datasets)) { + cat(sprintf("\n--- %s ---\n", dname)) + sub <- df[df$dataset == dname, c("model", "covariance", "backend", "loglik", "iterations", "time")] + sub$covariance[is.na(sub$covariance)] <- "-" + print(sub, row.names = FALSE) +} diff --git a/inst/benchmark/convergence_analysis.R b/inst/benchmark/convergence_analysis.R new file mode 100644 index 00000000..d109df59 --- /dev/null +++ b/inst/benchmark/convergence_analysis.R @@ -0,0 +1,232 @@ +## ============================================================ +## Convergence analysis of the builtin Newton backend +## Datasets: trichoptera (n=49, p=17), barents (n=89, p=30), +## mollusk (n=163, p=32), oaks (n=116, p=114), +## microcosm (n=880, p=259), scRNA (n=3918, p=500) +## Covariances: full, diagonal, spherical +## With / without covariates +## Note: full covariance for microcosm (~30-60s) and scRNA (very slow) included +## Output: inst/benchmark/ +## ============================================================ + +suppressPackageStartupMessages({ + devtools::load_all(".", quiet = TRUE) + library(ggplot2) + library(tidyr) +}) + +ctrl <- function(cov) PLN_param(backend = "builtin", covariance = cov, trace = 0) + +## ---- trichoptera (n=49, p=17) ---- +cat("Fitting trichoptera...\n") +tri <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) +fits <- list( + tri_full_nocov = PLN(Abundance ~ 1, data = tri, control = ctrl("full")), + tri_diag_nocov = PLN(Abundance ~ 1, data = tri, control = ctrl("diagonal")), + tri_sph_nocov = PLN(Abundance ~ 1, data = tri, control = ctrl("spherical")), + tri_full_cov = PLN(Abundance ~ Wind + Temperature, data = tri, control = ctrl("full")), + tri_diag_cov = PLN(Abundance ~ Wind + Temperature, data = tri, control = ctrl("diagonal")), + tri_sph_cov = PLN(Abundance ~ Wind + Temperature, data = tri, control = ctrl("spherical")) +) + +## ---- barents (n=89, p=30) ---- +cat("Fitting barents...\n") +fits <- c(fits, list( + bar_full_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = barents, control = ctrl("full")), + bar_diag_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = barents, control = ctrl("diagonal")), + bar_sph_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = barents, control = ctrl("spherical")), + bar_full_cov = PLN(Abundance ~ Depth + Temperature + offset(log(Offset)), data = barents, control = ctrl("full")), + bar_diag_cov = PLN(Abundance ~ Depth + Temperature + offset(log(Offset)), data = barents, control = ctrl("diagonal")), + bar_sph_cov = PLN(Abundance ~ Depth + Temperature + offset(log(Offset)), data = barents, control = ctrl("spherical")) +)) + +## ---- mollusk (n=163, p=32) ---- +cat("Fitting mollusk...\n") +mol <- prepare_data(mollusk$Abundance, mollusk$Covariate) +fits <- c(fits, list( + mol_full_nocov = PLN(Abundance ~ 1, data = mol, control = ctrl("full")), + mol_diag_nocov = PLN(Abundance ~ 1, data = mol, control = ctrl("diagonal")), + mol_sph_nocov = PLN(Abundance ~ 1, data = mol, control = ctrl("spherical")), + mol_full_cov = PLN(Abundance ~ site + season, data = mol, control = ctrl("full")), + mol_diag_cov = PLN(Abundance ~ site + season, data = mol, control = ctrl("diagonal")), + mol_sph_cov = PLN(Abundance ~ site + season, data = mol, control = ctrl("spherical")) +)) + +## ---- oaks (n=116, p=114) ---- +cat("Fitting oaks...\n") +fits <- c(fits, list( + oak_full_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = oaks, control = ctrl("full")), + oak_diag_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = oaks, control = ctrl("diagonal")), + oak_sph_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = oaks, control = ctrl("spherical")), + oak_full_cov = PLN(Abundance ~ tree + offset(log(Offset)), data = oaks, control = ctrl("full")), + oak_diag_cov = PLN(Abundance ~ tree + offset(log(Offset)), data = oaks, control = ctrl("diagonal")), + oak_sph_cov = PLN(Abundance ~ tree + offset(log(Offset)), data = oaks, control = ctrl("spherical")) +)) + +## ---- microcosm (n=880, p=259) ---- +cat("Fitting microcosm (diagonal + spherical)...\n") +fits <- c(fits, list( + mic_diag_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = microcosm, control = ctrl("diagonal")), + mic_sph_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = microcosm, control = ctrl("spherical")), + mic_diag_cov = PLN(Abundance ~ site + offset(log(Offset)), data = microcosm, control = ctrl("diagonal")), + mic_sph_cov = PLN(Abundance ~ site + offset(log(Offset)), data = microcosm, control = ctrl("spherical")) +)) +cat("Fitting microcosm full covariance (slow — O(n·p²) M-step with n=880, p=259)...\n") +fits <- c(fits, list( + mic_full_nocov = PLN(Abundance ~ 1 + offset(log(Offset)), data = microcosm, control = ctrl("full")), + mic_full_cov = PLN(Abundance ~ site + offset(log(Offset)), data = microcosm, control = ctrl("full")) +)) + +## ---- scRNA (n=3918, p=500) — full covariance skipped ---- +cat("Fitting scRNA diagonal + spherical (n=3918, p=500)...\n") +fits <- c(fits, list( + scr_diag_nocov = PLN(counts ~ 1 + offset(log(total_counts)), data = scRNA, control = ctrl("diagonal")), + scr_sph_nocov = PLN(counts ~ 1 + offset(log(total_counts)), data = scRNA, control = ctrl("spherical")), + scr_diag_cov = PLN(counts ~ cell_line + offset(log(total_counts)), data = scRNA, control = ctrl("diagonal")), + scr_sph_cov = PLN(counts ~ cell_line + offset(log(total_counts)), data = scRNA, control = ctrl("spherical")) +)) +cat("Fitting scRNA full covariance (very slow — O(n·p²) M-step with n=3918, p=500)...\n") +fits <- c(fits, list( + scr_full_nocov = PLN(counts ~ 1 + offset(log(total_counts)), data = scRNA, control = ctrl("full")), + scr_full_cov = PLN(counts ~ cell_line + offset(log(total_counts)), data = scRNA, control = ctrl("full")) +)) + +cat("All fits done.\n") + +## ---- Extract monitoring ---- +mon <- lapply(names(fits), function(nm) { + m <- fits[[nm]]$optim_par + obj <- m$objective + obj_norm <- (obj - min(obj)) / (max(obj) - min(obj) + .Machine$double.eps) + rel_change <- abs(diff(obj)) / (abs(obj[-length(obj)]) + 1e-30) + tail_n <- max(5L, as.integer(0.2 * length(rel_change))) + tail_slope <- if (all(tail(rel_change, tail_n) > 0)) + mean(log10(tail(rel_change, tail_n) + 1e-30)) + else NA_real_ + parts <- strsplit(nm, "_")[[1]] + list( + name = nm, + dataset = parts[1], + covariance = parts[2], + covariates = parts[3], + n_iter = m$iterations, + status = m$status, + converged = (m$status == 3), + obj_init = obj[1], + obj_final = obj[length(obj)], + rel_drop = (obj[1] - obj[length(obj)]) / abs(obj[1]), + last_delta = rel_change[length(rel_change)], + tail_slope = tail_slope, + obj_seq = obj, + rel_seq = rel_change, + obj_norm_seq = obj_norm + ) +}) + +## ---- Summary table ---- +cat("\n========== CONVERGENCE SUMMARY ==========\n") +sumtab <- do.call(rbind, lapply(mon, function(x) { + data.frame( + fit = x$name, + n_iter = x$n_iter, + converged = x$converged, + rel_drop = signif(x$rel_drop, 3), + last_delta = signif(x$last_delta, 3), + tail_slope = signif(x$tail_slope, 3), + stringsAsFactors = FALSE + ) +})) +print(sumtab, row.names = FALSE) + +## ---- Plateau detection ---- +cat("\n========== PLATEAU DETECTION (fraction of steps with delta < 1e-6) ==========\n") +for (x in mon) { + r <- x$rel_seq + frac_flat <- mean(r < 1e-6) + cat(sprintf(" %-25s %5.1f%% flat steps | %d total\n", + x$name, 100*frac_flat, x$n_iter)) +} + +## ---- EM kink detection ---- +cat("\n========== EM KINK DETECTION (local minima in rel-change = EM M-step boundaries) ==========\n") +for (x in mon) { + r <- x$rel_seq + kinks <- which(diff(sign(diff(log(r + 1e-30)))) == 2) + cat(sprintf(" %-25s ~%d EM kinks in %d inner steps (%.1f steps/EM)\n", + x$name, length(kinks), x$n_iter, + if (length(kinks) > 0) x$n_iter / length(kinks) else NaN)) +} + +## ---- Convergence speed ---- +cat("\n========== CONVERGENCE RATE (mean log10 rel-change in last 20% of steps) ==========\n") +for (x in mon) { + cat(sprintf(" %-25s tail log10(delta) = %.2f (higher = slower)\n", + x$name, x$tail_slope)) +} + +## ---- Build tidy data frames for plots ---- +df_traj <- do.call(rbind, lapply(mon, function(x) { + data.frame(name = x$name, dataset = x$dataset, covariance = x$covariance, + covariates = x$covariates, + step = seq_along(x$obj_norm_seq), obj_norm = x$obj_norm_seq, + stringsAsFactors = FALSE) +})) + +df_rel <- do.call(rbind, lapply(mon, function(x) { + data.frame(name = x$name, dataset = x$dataset, covariance = x$covariance, + covariates = x$covariates, + step = seq_along(x$rel_seq), rel_change = pmax(x$rel_seq, 1e-16), + stringsAsFactors = FALSE) +})) + +## ---- Plot 1: normalised objective (log1p) ---- +dataset_labels <- c(tri = "trichoptera (n=49, p=17)", + bar = "barents (n=89, p=30)", + mol = "mollusk (n=163, p=32)", + oak = "oaks (n=116, p=114)", + mic = "microcosm (n=880, p=259)", + scr = "scRNA (n=3918, p=500)") + +p1 <- ggplot(df_traj, aes(step, obj_norm + 1e-6, colour = covariance, linetype = covariates)) + + geom_line(linewidth = 0.6) + + facet_wrap(~ dataset, scales = "free_x", + labeller = labeller(dataset = dataset_labels)) + + scale_y_log10() + + labs(title = "Normalised inner objective (log10 scale)", + subtitle = "(obj - obj_min) / range -- 0 = fully converged", + x = "Newton step (cumulated over EM)", y = "Normalised obj", + colour = "Covariance", linetype = "Covariates") + + theme_bw(base_size = 11) + +ggsave("inst/benchmark/convergence_trajectory.pdf", p1, width = 15, height = 8) +cat("\nSaved: convergence_trajectory.pdf\n") + +## ---- Plot 2: per-step relative change ---- +p2 <- ggplot(df_rel, aes(step, rel_change, colour = covariance, linetype = covariates)) + + geom_line(linewidth = 0.5, alpha = 0.8) + + facet_wrap(~ dataset, scales = "free", + labeller = labeller(dataset = dataset_labels)) + + scale_y_log10() + + geom_hline(yintercept = 1e-8, linetype = "dotted", colour = "grey50") + + labs(title = "Per-step relative change |dobj|/|obj| (log10)", + subtitle = "Dotted = ftol_in = 1e-8 | Bumps = EM M-step boundary", + x = "Newton step", y = "Relative change", + colour = "Covariance", linetype = "Covariates") + + theme_bw(base_size = 11) + +ggsave("inst/benchmark/convergence_rel_change.pdf", p2, width = 15, height = 8) +cat("Saved: convergence_rel_change.pdf\n") + +## ---- Plot 3: distribution of step sizes ---- +p3 <- ggplot(df_rel, aes(rel_change, fill = covariance)) + + geom_histogram(bins = 50, alpha = 0.65, position = "identity") + + facet_grid(dataset ~ covariates, scales = "free_y", + labeller = labeller(dataset = dataset_labels)) + + scale_x_log10() + + geom_vline(xintercept = 1e-8, linetype = "dotted") + + labs(title = "Distribution of per-step relative changes", + x = "Relative change (log10)", fill = "Covariance") + + theme_bw(base_size = 10) + +ggsave("inst/benchmark/convergence_step_dist.pdf", p3, width = 12, height = 14) +cat("Saved: convergence_step_dist.pdf\n") From 93bc20a35925bc89fb0355d531d5ef099ec062e6 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Fri, 12 Jun 2026 23:00:12 +0200 Subject: [PATCH 57/58] fix in init PLNPCA --- DESCRIPTION | 3 +- DEVLOG_2026-06-11-12.md | 41 +++++----- R/PLNPCA.R | 4 +- R/PLNPCAfamily-class.R | 2 +- R/PLNPCAfit-class.R | 12 ++- inst/benchmark/bench_compare.R | 105 ++++++++++++++++++++++++ inst/benchmark/bench_plnpca_fixed.R | 71 ++++++++++++++++ inst/benchmark/bench_run.R | 121 ++++++++++++++++++++++++++++ man/PLNPCA_param.Rd | 11 +-- 9 files changed, 338 insertions(+), 32 deletions(-) create mode 100644 inst/benchmark/bench_compare.R create mode 100644 inst/benchmark/bench_plnpca_fixed.R create mode 100644 inst/benchmark/bench_run.R diff --git a/DESCRIPTION b/DESCRIPTION index e45da547..6900245c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -50,8 +50,7 @@ Imports: rlang, stats, tidyr, - torch, - utils + torch Suggests: factoextra, knitr, diff --git a/DEVLOG_2026-06-11-12.md b/DEVLOG_2026-06-11-12.md index b663762d..b4c1a413 100644 --- a/DEVLOG_2026-06-11-12.md +++ b/DEVLOG_2026-06-11-12.md @@ -471,33 +471,36 @@ private$M <- sqrt(self$n) * svdM$u[, 1:rank, drop = FALSE] **Fichiers** : `R/PLNPCA.R`, `src/builtin_optim_plnpca.cpp` -### Diagnostic +### Contexte + +Cette section a d'abord été rédigée avec des chiffres issus d'une init SVD bugguée (SVD sur M_PLN complet, sans la correction SVD sur M−XB ni la normalisation X). Ces valeurs (-3988 nlopt barents q=5, -5957 builtin) étaient artefactuelles. Le **benchmark re-effectué avec le code corrigé** (fixes de la section 31 + section 33) donne un tableau très différent. + +### Benchmark re-effectué (code-enhancement, code complet avec tous les fixes) -Benchmark sur trois jeux de données (offset corrigé) avec les backends nlopt et builtin (joint L-BFGS) : +| Dataset | q | nlopt ll | nlopt t | builtin ll | builtin t | gagnant | +|---------|---|----------|---------|------------|-----------|---------| +| trichoptera | 3 | -640.5 | 0.43s | **-638.1** | 0.46s | builtin | +| trichoptera | 5 | -584.2 | 0.44s | **-578.1** | 0.56s | builtin | +| barents | 3 | -6720.4 | 0.59s | **-6699.9** | 0.80s | builtin | +| barents | 5 | **-3800.2** | 0.70s | -3836.3 | 0.88s | nlopt | +| barents | 10 | -3253.6 | 0.79s | **-3080.3** | 1.89s | builtin | +| oaks | 3 | -111741.1 | 1.15s | **-111715.3** | 1.91s | builtin | +| oaks | 5 | -77189.8 | 1.29s | **-77178.5** | 2.00s | builtin | +| oaks | 10 | **-47307.7** | 9.05s* | -47483.8 | 4.37s | nlopt | -| Dataset | nlopt loglik | nlopt t | builtin loglik | builtin t | -|---------|-------------|---------|----------------|-----------| -| trichoptera q=3 | -640.2 | 0.44s | -640.4 | 0.40s | -| barents q=5 | **-3988.2** | 0.70s | -5957.9 | 2.02s | -| oaks q=5 | **-77290.9** | 3.50s | -78015.8 | 3.04s | +*oaks q=10 nlopt : maxeval atteint (10000 iter), solution non convergée. -Pour barents (d[1]/√n = 474/9.4 ≈ 50), le paysage d'optimisation a deux bassins d'attraction : -- **Bon bassin** : loglik ≈ -3988, atteint uniquement par nlopt-CCSAQ -- **Mauvais bassin** : loglik ≈ -5958, où convergent joint L-BFGS, EM alterné, et toute variante gradient-based depuis l'init SVD +**Bilan : builtin gagne 6/9 ; nlopt gagne 2/9 (barents q=5, oaks q=10).** -Expériences effectuées sans succès : -- Gradient balancing (σ = √(‖g_M‖/‖g_C‖)) -- EM alterné (VE step strictement convexe) — améliore barents à -5156 avec maxeval=10000, -4467 avec maxeval=50000, mais n'atteint jamais -3988 -- Combinaison EM + joint polish -- Augmentation massive du budget d'itérations +La dichotomie "nlopt toujours meilleur" est donc **fausse** avec le code corrigé. Les deux backends trouvent des bassins locaux différents selon le rang et le jeu de données — sans gagnant universel. -La cause fondamentale : nlopt-CCSAQ utilise des asymptotes par variable adaptatives qui maintiennent des pas très conservatifs initialement. Ces petits pas évitent de franchir la crête séparant les deux bassins depuis l'init SVD. Les méthodes gradient à pas variable (L-BFGS/EM) sautent directement dans le mauvais bassin. +Les analyses intermédiaires (EM alterné, gradient balancing) avaient été conduites sur la base des mauvais chiffres de l'init bugguée et ne sont plus pertinentes. ### Décision -- `PLNPCA_param()` : default revert à `"nlopt"` (fiable, qualité garantie) -- `"builtin"` reste disponible : légèrement plus rapide sur des données simples (trichoptera), utile pour l'exploration mais sans garantie de qualité sur des données complexes -- Code C++ `builtin_optim_plnpca.cpp` : nettoyé, retour au pur joint L-BFGS sans EM (plus simple, pas moins bon) +- `PLNPCA_param()` : default maintenu à `"nlopt"` (comportement conservateur, prévisible) +- `"builtin"` reste disponible : souvent meilleur en loglik (6/9 cas), plus rapide sur les petits rangs +- Code C++ `builtin_optim_plnpca.cpp` : joint L-BFGS pur sans EM (plus simple) ### Validation diff --git a/R/PLNPCA.R b/R/PLNPCA.R index 8a0b1fdd..96101a17 100644 --- a/R/PLNPCA.R +++ b/R/PLNPCA.R @@ -58,9 +58,9 @@ PLNPCA <- function(formula, data, subset, weights, ranks = 1:5, control = PLNPCA #' #' Helper to define list of parameters to control the PLNPCA fit. All arguments have defaults. #' -#' @param backend optimization backend, either `"nlopt"` (default, NLOPT/CCSAQ — recommended +#' @param backend optimization backend, either `"nlopt"` (default, NLOPT/CCSAQ, recommended #' for PLNPCA: conservative per-variable steps reliably find the global basin even when -#' the singular-value ratio d[1]/sqrt(n) is large), `"builtin"` (joint L-BFGS with strong +#' the singular-value ratio d1/sqrt(n) is large), `"builtin"` (joint L-BFGS with strong #' Wolfe line search on all parameters simultaneously — faster per iteration but may #' converge to inferior local optima on ill-conditioned datasets), #' or `"torch"` (automatic differentiation via the torch package). diff --git a/R/PLNPCAfamily-class.R b/R/PLNPCAfamily-class.R index a054b0b2..a25c9116 100644 --- a/R/PLNPCAfamily-class.R +++ b/R/PLNPCAfamily-class.R @@ -52,7 +52,7 @@ PLNPCAfamily <- R6Class( private$params <- ranks ## save some time by using a common SVD to define the inceptive models control$inception <- PLNfit$new(responses, covariates, offsets, weights, formula, control) - private$svdM <- svd(control$inception$var_par$M, nu = max(ranks), nv = ncol(responses)) + private$svdM <- svd(control$inception$var_par$M - covariates %*% control$inception$model_par$B, nu = max(ranks), nv = ncol(responses)) control$svdM <- private$svdM ## instantiate as many models as ranks self$models <- lapply(ranks, function(rank){ diff --git a/R/PLNPCAfit-class.R b/R/PLNPCAfit-class.R index ff5f4f80..6a639719 100644 --- a/R/PLNPCAfit-class.R +++ b/R/PLNPCAfit-class.R @@ -256,7 +256,7 @@ PLNPCAfit <- R6Class( if (!is.null(control$svdM)) { svdM <- control$svdM } else { - svdM <- svd(private$M, nu = rank, nv = self$p) + svdM <- svd(private$M - covariates %*% private$B, nu = rank, nv = self$p) } # M*C^T ≈ M_PLN requires M = sqrt(n)*U when C = V*D/sqrt(n) private$M <- sqrt(self$n) * svdM$u[, 1:rank, drop = FALSE] @@ -302,10 +302,16 @@ PLNPCAfit <- R6Class( ## Optimization ---------------------- #' @description Call to the C++ optimizer and update of the relevant fields optimize = function(responses, covariates, offsets, weights, config) { - args <- list(data = list(Y = responses, X = covariates, O = offsets, w = weights), - params = list(B = private$B, C = private$C, M = private$M, S2 = private$S2), + ## Column-scale X to prevent first-step blowup when X has large-scale columns + ## (e.g. depth in metres). Equivalent problem; B is unscaled before storing. + scales <- pmax(sqrt(colSums(covariates^2)), 1) + X_sc <- sweep(covariates, 2, scales, "/") + B_sc <- sweep(private$B, 1, scales, "*") + args <- list(data = list(Y = responses, X = X_sc, O = offsets, w = weights), + params = list(B = B_sc, C = private$C, M = private$M, S2 = private$S2), config = config) optim_out <- do.call(private$optimizer$main, args) + optim_out$B <- sweep(optim_out$B, 1, scales, "/") do.call(self$update, optim_out) }, diff --git a/inst/benchmark/bench_compare.R b/inst/benchmark/bench_compare.R new file mode 100644 index 00000000..f8ba826b --- /dev/null +++ b/inst/benchmark/bench_compare.R @@ -0,0 +1,105 @@ +#!/usr/bin/env Rscript +## Usage: Rscript bench_compare.R + +args <- commandArgs(trailingOnly = TRUE) +if (length(args) < 2) stop("Usage: bench_compare.R ") + +df_master <- readRDS(args[1]) +df_ce <- readRDS(args[2]) +df_all <- rbind(df_master, df_ce) + +branch_m <- unique(df_master$branch) +branch_ce <- unique(df_ce$branch) + +## ── Cross-branch comparison: nlopt only (compatible baseline) ───────────────── +df_m <- df_master[df_master$backend == "nlopt", ] +df_c <- df_ce[df_ce$backend == "nlopt", ] + +## Merge on model + dataset +comp <- merge(df_m, df_c, by = c("model", "dataset"), suffixes = c(".m", ".ce")) +comp$delta_loglik <- comp$loglik.ce - comp$loglik.m +comp$speedup <- comp$time_s.m / comp$time_s.ce +comp <- comp[order(comp$model, comp$dataset), ] + +## ── Print ───────────────────────────────────────────────────────────────────── +HR <- strrep("=", 115) +hr <- strrep("-", 115) + +cat("\n", HR, "\n", sep="") +cat(sprintf(" BRANCH COMPARISON: %s (ce) vs %s (master)\n", branch_ce, branch_m)) +cat(sprintf(" Backend: nlopt (comparable defaults)\n")) +cat(HR, "\n\n", sep="") + +cat(sprintf(" %-12s %-12s | %7s %7s %8s | %10s %10s %6s | %5s %5s\n", + "Model", "Dataset", "t_master", "t_ce", "speedup", "ll_master", "ll_ce", "delta", "it_m", "it_ce")) +cat(sprintf(" %s\n", strrep("-", 100))) + +prev_model <- "" +for (i in seq_len(nrow(comp))) { + r <- comp[i, ] + if (r$model != prev_model && i > 1) cat("\n") + prev_model <- r$model + + flag <- if (!is.na(r$delta_loglik) && abs(r$delta_loglik) > 5) { + if (r$delta_loglik > 0) " ▲" else " ▼" + } else "" + + cat(sprintf(" %-12s %-12s | %7.2fs %7.2fs %8.2fx | %10.1f %10.1f %+6.1f%s | %5s %5s\n", + r$model, r$dataset, + r$time_s.m, r$time_s.ce, r$speedup, + r$loglik.m, r$loglik.ce, r$delta_loglik, flag, + ifelse(is.na(r$n_iter.m), "?", as.character(r$n_iter.m)), + ifelse(is.na(r$n_iter.ce), "?", as.character(r$n_iter.ce)) + )) +} + +cat("\n Legend: delta = ll_ce - ll_master (▲ ce better, ▼ ce worse, threshold |delta|>5)\n") +cat( " speedup = t_master / t_ce (>1 ce faster, <1 ce slower)\n\n") + +## ── Extra backends (code-enhancement only) ──────────────────────────────────── +extra <- df_ce[df_ce$backend != "nlopt", ] +if (nrow(extra) > 0) { + cat(hr, "\n", sep="") + cat(" NEW BACKENDS in code-enhancement vs its own nlopt baseline\n") + cat(hr, "\n\n", sep="") + + for (be in unique(extra$backend)) { + cat(sprintf(" Backend '%s':\n", be)) + sub_e <- extra[extra$backend == be, ] + for (i in seq_len(nrow(sub_e))) { + rx <- sub_e[i, ] + rnl <- df_c[df_c$model == rx$model & df_c$dataset == rx$dataset, ] + if (nrow(rnl) == 0) next + cat(sprintf(" %-12s %-12s | t=%.2fs vs %.2fs (nlopt) speedup=%+.2fx | ll_diff=%+.1f\n", + rx$model, rx$dataset, + rx$time_s, rnl$time_s, rnl$time_s / rx$time_s, + rx$loglik - rnl$loglik + )) + } + cat("\n") + } +} + +## ── Parameter norms ─────────────────────────────────────────────────────────── +cat(hr, "\n", sep="") +cat(" PARAMETER NORMS — B and Omega (Frobenius)\n") +cat(hr, "\n\n", sep="") +cat(sprintf(" %-12s %-12s | norm_B: %8s %8s | norm_Om: %8s %8s\n", + "Model", "Dataset", "master", "ce", "master", "ce")) +cat(sprintf(" %s\n", strrep("-", 80))) + +for (i in seq_len(nrow(comp))) { + r <- comp[i, ] + cat(sprintf(" %-12s %-12s | norm_B: %8.4f %8.4f | norm_Om: %8.4f %8.4f\n", + r$model, r$dataset, + ifelse(is.na(r$norm_B.m), 0, r$norm_B.m), + ifelse(is.na(r$norm_B.ce), 0, r$norm_B.ce), + ifelse(is.na(r$norm_Om.m), 0, r$norm_Om.m), + ifelse(is.na(r$norm_Om.ce), 0, r$norm_Om.ce) + )) +} + +## ── Save CSV ────────────────────────────────────────────────────────────────── +out_csv <- file.path(dirname(args[1]), "branch_comparison.csv") +write.csv(df_all, out_csv, row.names = FALSE) +cat(sprintf("\nFull results saved to: %s\n", out_csv)) diff --git a/inst/benchmark/bench_plnpca_fixed.R b/inst/benchmark/bench_plnpca_fixed.R new file mode 100644 index 00000000..5bfc8a0b --- /dev/null +++ b/inst/benchmark/bench_plnpca_fixed.R @@ -0,0 +1,71 @@ +#!/usr/bin/env Rscript +## Usage: Rscript bench_plnpca_fixed.R +## PLNPCA at fixed ranks (3, 5, 10) — comparable across branches. + +args <- commandArgs(trailingOnly = TRUE) +if (length(args) < 3) stop("Usage: bench_plnpca_fixed.R ") +lib_path <- args[1] +branch_name <- args[2] +out_rds <- args[3] + +.libPaths(c(lib_path, .libPaths())) +suppressPackageStartupMessages(library(PLNmodels)) +cat(sprintf("Branch: %s | PLNmodels %s\n\n", branch_name, packageVersion("PLNmodels"))) + +data(trichoptera); data(oaks); data(barents) +tri <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) + +RANKS <- c(3L, 5L, 10L) + +datasets <- list( + list(name = "trichoptera", expr_tmpl = function(q, ctrl) + PLNPCA(Abundance ~ 1, data = tri, ranks = q, control = ctrl)), + list(name = "barents", expr_tmpl = function(q, ctrl) + PLNPCA(Abundance ~ Depth + Temperature, data = barents, ranks = q, control = ctrl)), + list(name = "oaks", expr_tmpl = function(q, ctrl) + PLNPCA(Abundance ~ 1 + offset(log(Offset)), data = oaks, ranks = q, control = ctrl)) +) + +ctrl <- PLNPCA_param(trace = 0) +results <- list() + +for (ds in datasets) { + for (q in RANKS) { + cat(sprintf(" PLNPCA %-12s rank=%2d ... ", ds$name, q)) + t0 <- proc.time() + fit <- tryCatch(ds$expr_tmpl(q, ctrl), error = function(e) { + cat("ERROR:", conditionMessage(e), "\n"); NULL + }) + elapsed <- round((proc.time() - t0)[["elapsed"]], 3) + if (is.null(fit)) next + + ## Single-rank PLNPCA returns a PLNPCAfamily with one model + m <- if (inherits(fit, "PLNPCAfamily")) fit$models[[1]] else fit + + loglik <- round(m$loglik, 4) + n_iter <- if (!is.null(m$optim_par$iterations)) as.integer(m$optim_par$iterations) else NA_integer_ + norm_B <- round(norm(as.matrix(m$model_par$B), "F"), 4) + norm_Om <- tryCatch(round(norm(as.matrix(m$model_par$Omega), "F"), 4), error = function(e) NA_real_) + + cat(sprintf("done (%.2fs, ll=%.1f, iter=%s)\n", elapsed, loglik, + ifelse(is.na(n_iter), "?", n_iter))) + + results[[length(results)+1]] <- data.frame( + branch = branch_name, + model = "PLNPCA", + dataset = ds$name, + rank = q, + backend = "nlopt", + time_s = elapsed, + loglik = loglik, + n_iter = n_iter, + norm_B = norm_B, + norm_Om = norm_Om, + stringsAsFactors = FALSE + ) + } +} + +df <- do.call(rbind, results) +saveRDS(df, out_rds) +cat(sprintf("\n%d runs saved to %s\n", nrow(df), out_rds)) diff --git a/inst/benchmark/bench_run.R b/inst/benchmark/bench_run.R new file mode 100644 index 00000000..059850cf --- /dev/null +++ b/inst/benchmark/bench_run.R @@ -0,0 +1,121 @@ +#!/usr/bin/env Rscript +## Usage: Rscript bench_run.R +## Runs PLN, PLNPCA, ZIPLN, PLNnetwork on trichoptera / barents / oaks. +## Metrics: time (s), loglik (ELBO), n_iter, Frobenius norms of B and Omega. + +args <- commandArgs(trailingOnly = TRUE) +if (length(args) < 3) stop("Usage: bench_run.R ") +lib_path <- args[1] +branch_name <- args[2] +out_rds <- args[3] + +.libPaths(c(lib_path, .libPaths())) +suppressPackageStartupMessages(library(PLNmodels)) +cat(sprintf("Branch: %s | PLNmodels %s\n\n", branch_name, packageVersion("PLNmodels"))) + +## ── Detect available backends ───────────────────────────────────────────────── +pln_backends <- tryCatch(as.character(formals(PLN_param)$backend)[-1], error = function(e) "nlopt") +zipln_backends <- tryCatch(as.character(formals(ZIPLN_param)$backend)[-1], error = function(e) "nlopt") +has_homemade_pln <- "homemade" %in% pln_backends +has_homemade_zipln <- "homemade" %in% zipln_backends + +cat("PLN backends available: ", paste(pln_backends, collapse=", "), "\n") +cat("ZIPLN backends available: ", paste(zipln_backends, collapse=", "), "\n\n") + +## ── Data ───────────────────────────────────────────────────────────────────── +data(trichoptera) +data(oaks) +data(barents) +tri <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) + +## ── Helpers ────────────────────────────────────────────────────────────────── +frob <- function(x) if (is.null(x)) NA_real_ else norm(as.matrix(x), "F") + +extract_fit <- function(fit) { + list( + loglik = round(fit$loglik, 4), + n_iter = if (!is.null(fit$optim_par$iterations)) as.integer(fit$optim_par$iterations) else NA_integer_, + norm_B = round(frob(fit$model_par$B), 4), + norm_Om = round(frob(fit$model_par$Omega), 4) + ) +} + +run_timed <- function(expr, model, dataset, backend) { + cat(sprintf(" %-12s %-12s [%s] ... ", model, dataset, backend)) + t0 <- proc.time() + obj <- tryCatch(eval(expr), error = function(e) { cat("ERROR:", conditionMessage(e), "\n"); NULL }) + elapsed <- round((proc.time() - t0)[["elapsed"]], 3) + if (is.null(obj)) return(NULL) + + ## For families (PLNPCA, PLNnetwork) extract best model + fit <- tryCatch( + if (inherits(obj, c("PLNPCAfamily", "PLNnetworkfamily"))) { + crit <- if (inherits(obj, "PLNPCAfamily")) "ICL" else "BIC" + obj$getBestModel(crit) + } else { + obj + }, + error = function(e) obj + ) + + m <- extract_fit(fit) + cat(sprintf("done (%.2fs, ll=%.1f)\n", elapsed, m$loglik)) + data.frame( + branch = branch_name, + model = model, + dataset = dataset, + backend = backend, + time_s = elapsed, + loglik = m$loglik, + n_iter = m$n_iter, + norm_B = m$norm_B, + norm_Om = m$norm_Om, + stringsAsFactors = FALSE + ) +} + +results <- list() +add <- function(r) if (!is.null(r)) results[[length(results)+1]] <<- r + +## ── PLN ─────────────────────────────────────────────────────────────────────── +cat("=== PLN ===\n") + +for (be in c("nlopt", if (has_homemade_pln) "homemade")) { + ctrl <- PLN_param(backend = be, trace = 0) + add(run_timed(quote(PLN(Abundance ~ 1, data = tri, control = ctrl)), "PLN", "trichoptera", be)) + add(run_timed(quote(PLN(Abundance ~ Depth + Temperature, data = barents, control = ctrl)), "PLN", "barents", be)) + add(run_timed(quote(PLN(Abundance ~ 1 + offset(log(Offset)), data = oaks, control = ctrl)), "PLN", "oaks", be)) +} + +## ── PLNPCA ──────────────────────────────────────────────────────────────────── +cat("\n=== PLNPCA ===\n") + +ctrl_pca <- PLNPCA_param(trace = 0) +for (ds in list( + list(name="trichoptera", expr=quote(PLNPCA(Abundance ~ 1, data=tri, ranks=1:5, control=ctrl_pca))), + list(name="barents", expr=quote(PLNPCA(Abundance ~ Depth + Temperature, data=barents, ranks=1:5, control=ctrl_pca))), + list(name="oaks", expr=quote(PLNPCA(Abundance ~ 1 + offset(log(Offset)), data=oaks, ranks=1:5, control=ctrl_pca))) +)) { + add(run_timed(ds$expr, "PLNPCA", ds$name, "nlopt")) +} + +## ── ZIPLN ───────────────────────────────────────────────────────────────────── +cat("\n=== ZIPLN ===\n") + +for (be in c("nlopt", if (has_homemade_zipln) "homemade")) { + ctrl <- ZIPLN_param(backend = be, trace = 0) + add(run_timed(quote(ZIPLN(Abundance ~ 1, data=tri, control=ctrl)), "ZIPLN", "trichoptera", be)) + add(run_timed(quote(ZIPLN(Abundance ~ 1 + offset(log(Offset)), data=oaks, control=ctrl)), "ZIPLN", "oaks", be)) +} + +## ── PLNnetwork ──────────────────────────────────────────────────────────────── +cat("\n=== PLNnetwork ===\n") + +ctrl_net <- PLNnetwork_param(n_penalties = 10, trace = 0) +add(run_timed(quote(PLNnetwork(Abundance ~ 1, data=tri, control=ctrl_net)), "PLNnetwork", "trichoptera", "nlopt")) +add(run_timed(quote(PLNnetwork(Abundance ~ 1 + offset(log(Offset)), data=oaks, control=ctrl_net)), "PLNnetwork", "oaks", "nlopt")) + +## ── Save ────────────────────────────────────────────────────────────────────── +df <- do.call(rbind, results) +saveRDS(df, out_rds) +cat(sprintf("\nDone. %d runs saved to %s\n", nrow(df), out_rds)) diff --git a/man/PLNPCA_param.Rd b/man/PLNPCA_param.Rd index fb219f36..6838cfca 100644 --- a/man/PLNPCA_param.Rd +++ b/man/PLNPCA_param.Rd @@ -5,7 +5,7 @@ \title{Control of PLNPCA fit} \usage{ PLNPCA_param( - backend = c("builtin", "nlopt", "torch"), + backend = c("nlopt", "builtin", "torch"), trace = 1, config_optim = list(), config_post = list(), @@ -14,10 +14,11 @@ PLNPCA_param( ) } \arguments{ -\item{backend}{optimization backend, either \code{"builtin"} (default, built-in joint L-BFGS -with strong Wolfe line search: all parameters B, C, M, ψ are optimised simultaneously -with a history of 10 curvature pairs; the Wolfe condition guarantees valid curvature -estimates at every step), \code{"nlopt"} (NLOPT/CCSAQ), +\item{backend}{optimization backend, either \code{"nlopt"} (default, NLOPT/CCSAQ, recommended +for PLNPCA: conservative per-variable steps reliably find the global basin even when +the singular-value ratio d1/sqrt(n) is large), \code{"builtin"} (joint L-BFGS with strong +Wolfe line search on all parameters simultaneously — faster per iteration but may +converge to inferior local optima on ill-conditioned datasets), or \code{"torch"} (automatic differentiation via the torch package).} \item{trace}{a integer for verbosity.} From 58f8b1952d7bd738c95a63c340b49f10b83f9a62 Mon Sep 17 00:00:00 2001 From: Julien Chiquet Date: Sat, 13 Jun 2026 09:44:45 +0200 Subject: [PATCH 58/58] several init option for PLNPCA, LM + svd by default --- DEVLOG_2026-06-11-12.md | 62 +++++++++ R/PLNPCA.R | 29 +++- R/PLNPCAfamily-class.R | 22 ++- R/PLNPCAfit-class.R | 5 +- inst/benchmark/bench_plnpca_init.R | 138 +++++++++++++++++++ inst/benchmark/bench_plnpca_init_results.rds | Bin 0 -> 887 bytes inst/case_studies/oaks_tree.R | 2 +- man/PLNPCA_param.Rd | 17 ++- man/PLNPCAfamily.Rd | 3 + man/PLNPCAfit.Rd | 5 +- 10 files changed, 267 insertions(+), 16 deletions(-) create mode 100644 inst/benchmark/bench_plnpca_init.R create mode 100644 inst/benchmark/bench_plnpca_init_results.rds diff --git a/DEVLOG_2026-06-11-12.md b/DEVLOG_2026-06-11-12.md index b4c1a413..a63e3d87 100644 --- a/DEVLOG_2026-06-11-12.md +++ b/DEVLOG_2026-06-11-12.md @@ -505,3 +505,65 @@ Les analyses intermédiaires (EM alterné, gradient balancing) avaient été con ### Validation 85 tests (`test-plnpcafamily.R` + `test-plnpcafit.R`) passent. + +## 33. PLNPCA — Remplacement de l'init PLN-EM par LM + benchmark init_method (13/06) + +**Fichiers** : `R/PLNPCAfamily-class.R`, `R/PLNPCA.R`, `inst/benchmark/bench_plnpca_init.R` + +### Motivation + +`PLNPCAfamily$initialize` fittait systématiquement un `PLNfit` complet (EM variationnel) comme inception, uniquement pour en extraire B et M et calculer la SVD sur M−XB. Ce coût (0.6–1.8s par jeu de données) est inutile : `compute_PLN_starting_point` (lm.fit) donne directement B_lm et M_lm = log((1+Y)/exp(O)), soit exactement le résidu LM sur lequel la SVD est calculée. + +**Argument théorique :** La SVD est calculée sur les résidus de la régression de M sur X. Ces résidus sont orthogonaux à X par construction → re-estimer B pour chaque rang q donne B_q ≈ B_lm. Le B est donc universel en initialisation ; l'optimiseur affine rang par rang. + +### Changements + +**`R/PLNPCAfamily-class.R`** — `initialize()` : +- Si l'utilisateur fournit un `inception` PLNfit → comportement inchangé (SVD sur M_PLN − XB_PLN) +- Sinon → `compute_PLN_starting_point()` (un `lm.fit`), SVD sur M_lm − XB_lm. Plus de PLN EM. + +**`R/PLNPCA.R`** — `PLNPCA_param()` : +- Nouveau paramètre `init_method = c("LM", "GLM")` (cohérence avec `PLN_param`) + +### Benchmark init_method × backend (13/06/2026) + +Script : `inst/benchmark/bench_plnpca_init.R` +Conditions : `{LM, GLM, PLN-EM} × {nlopt, builtin}`, jeux trichoptera / barents / oaks. +"PLN-EM" = ancienne init master (PLNfit complet passé comme inception). + +**trichoptera** (q = 1, 3, 5) — toutes méthodes convergent au même endroit, < 10 unités de différence. + +**barents** (q = 3, 5, 10, Depth + Temperature) : + +| backend | init | q=3 | q=5 | q=10 | +|---------|------|-----|-----|------| +| nlopt | LM | **−6368.5** ✓ | −3714.5 | −3128.5 | +| nlopt | GLM | −6368.1 | −3844.5 | −3321.6 | +| nlopt | PLN-EM | −6393.0 ❌ | **−3642.5** | **−3048.6** | +| builtin | LM | −6368.0 | −3685.0 | −3131.9 | +| builtin | GLM | **−6311.5** | −3681.3 | −3062.1 | +| builtin | PLN-EM | −6415.9 ❌ | −3614.2 | −3047.5 | + +Sur q=3, LM bat PLN-EM (~25 unités). Sur q=5,10, PLN-EM aide (~70 unités). + +**oaks** (q = 5, 10, 20) : + +| backend | init | q=5 | q=10 | q=20 | +|---------|------|-----|------|------| +| nlopt | LM | −77189.8 | **−47307.7** ✓ | −30654.7 | +| nlopt | PLN-EM | −77239.0 | −47477.3 | −30537.6 | +| builtin | LM | −77178.5 | −47483.8 | −30368.8 | +| builtin | PLN-EM | **−77126.7** | −47337.4 | **−30281.9** | + +GLM systématiquement le pire sur oaks (initialisation Poisson GLM produit un M résiduel mal aligné). + +### Bilan + +- **LM est une bonne init par défaut** : aussi bon ou meilleur que PLN-EM sur barents q=3, compétitif partout, sans coût EM +- **PLN-EM aide aux grands rangs** sur datasets avec covariables fortes (barents q=5,10 : +70 ll), mais peut nuire aux petits rangs +- **GLM à éviter pour PLNPCA** : systématiquement pire que LM +- Décision : conserver `init_method = "LM"` comme défaut ; l'utilisateur peut passer `inception = PLN(...)` pour grands rangs si nécessaire + +### Validation + +85 tests passent. diff --git a/R/PLNPCA.R b/R/PLNPCA.R index 96101a17..3c55870d 100644 --- a/R/PLNPCA.R +++ b/R/PLNPCA.R @@ -38,7 +38,7 @@ PLNPCA <- function(formula, data, subset, weights, ranks = 1:5, control = PLNPCA ## extract the data matrices and weights args <- extract_model(match.call(expand.dots = FALSE), parent.frame()) - ## Instantiate the collection of PLN models, initialized by PLN with full rank + ## Instantiate the collection of PLN models; shared SVD initialisation (LM or user inception) if (control$trace > 0) cat("\n Initialization...") myPCA <- PLNPCAfamily$new(ranks, args$Y, args$X, args$O, args$w, args$formula, control) @@ -64,7 +64,19 @@ PLNPCA <- function(formula, data, subset, weights, ranks = 1:5, control = PLNPCA #' Wolfe line search on all parameters simultaneously — faster per iteration but may #' converge to inferior local optima on ill-conditioned datasets), #' or `"torch"` (automatic differentiation via the torch package). -#' @inheritParams PLN_param trace config_optim config_post inception +#' @inheritParams PLN_param trace config_optim config_post +#' @param init_method character: strategy used to compute the starting point for the shared SVD. +#' Either `"LM"` (default, fast: one multivariate `lm.fit` on log-transformed counts) or +#' `"GLM"` (p independent Poisson GLMs, more accurate for complex or highly unbalanced +#' designs). Ignored when `inception` is provided. Benchmarks show `"LM"` is as good as +#' or better than `"GLM"` for PLNPCA in most cases; `"GLM"` is not recommended. +#' See [compute_PLN_starting_point()]. +#' @param inception an optional pre-fitted [`PLNfit`] object. When provided, its variational +#' means `M` and regression coefficients `B` are used to compute the shared SVD +#' `svd(M - X*B)` that initialises all ranks simultaneously. This replaces the default +#' LM-based starting point and can improve convergence for large ranks on datasets with +#' strong covariate effects (e.g. `inception = PLN(formula, data)`). When `NULL` (default), +#' a fast LM is used. `init_method` is ignored when `inception` is set. #' @param sequential logical. If `TRUE`, ranks are fitted in ascending order and each model is #' warm-started from the converged solution of the previous rank: loadings C are augmented #' with new columns from the inception SVD, while latent scores M and variances S2 are @@ -81,10 +93,12 @@ PLNPCA_param <- function( config_optim = list() , config_post = list() , inception = NULL , # pretrained PLNfit used as initialization + init_method = c("LM", "GLM"), sequential = FALSE # fit ranks sequentially, warm-starting each from the previous ) { if (!is.null(inception)) stopifnot(isPLNfit(inception)) + init_method <- match.arg(init_method) ## post-treatment config config_pst <- config_post_default_PLNPCA @@ -98,9 +112,10 @@ PLNPCA_param <- function( config_opt$sequential <- sequential structure(list( - backend = backend , - trace = trace , - config_optim = config_opt, - config_post = config_pst, - inception = inception ), class = "PLNmodels_param") + backend = backend , + trace = trace , + config_optim = config_opt , + config_post = config_pst , + inception = inception , + init_method = init_method ), class = "PLNmodels_param") } diff --git a/R/PLNPCAfamily-class.R b/R/PLNPCAfamily-class.R index a25c9116..a1ac06df 100644 --- a/R/PLNPCAfamily-class.R +++ b/R/PLNPCAfamily-class.R @@ -46,13 +46,29 @@ PLNPCAfamily <- R6Class( ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ## Creation ----------------------- #' @description Initialize all models in the collection. + #' A single SVD of the residual matrix `M - X*B` is computed once and shared across + #' all ranks. `M` and `B` come from either a user-provided [`PLNfit`] inception or a + #' fast LM on log-transformed counts (default, controlled by `init_method`). initialize = function(ranks, responses, covariates, offsets, weights, formula, control) { ## initialize the required fields super$initialize(responses, covariates, offsets, weights, control) private$params <- ranks - ## save some time by using a common SVD to define the inceptive models - control$inception <- PLNfit$new(responses, covariates, offsets, weights, formula, control) - private$svdM <- svd(control$inception$var_par$M - covariates %*% control$inception$model_par$B, nu = max(ranks), nv = ncol(responses)) + ## compute starting point for the common SVD: + ## user-provided inception PLNfit → use its converged M and B + ## otherwise: LM on log-transformed data (fast, no EM needed) + if (isPLNfit(control$inception)) { + init_B <- control$inception$model_par$B + init_M <- control$inception$var_par$M + } else { + lm_start <- compute_PLN_starting_point( + responses, covariates, offsets, weights, + method = if (is.null(control$init_method)) "LM" else control$init_method + ) + init_B <- lm_start$B + init_M <- lm_start$M + } + ## SVD of the residual M - XB, shared across all ranks + private$svdM <- svd(init_M - covariates %*% init_B, nu = max(ranks), nv = ncol(responses)) control$svdM <- private$svdM ## instantiate as many models as ranks self$models <- lapply(ranks, function(rank){ diff --git a/R/PLNPCAfit-class.R b/R/PLNPCAfit-class.R index 6a639719..f96b4419 100644 --- a/R/PLNPCAfit-class.R +++ b/R/PLNPCAfit-class.R @@ -242,7 +242,10 @@ PLNPCAfit <- R6Class( public = list( ## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ## Creation functions ---------------- - #' @description Initialize a [`PLNPCAfit`] object + #' @description Initialize a [`PLNPCAfit`] object. + #' Uses the shared SVD from `control$svdM` (computed once in [`PLNPCAfamily`]) to set + #' the starting loadings `C` and scores `M`. The regression coefficients `B` are + #' initialised by the parent [`PLNfit`] constructor (LM or user-provided inception). initialize = function(rank, responses, covariates, offsets, weights, formula, control) { super$initialize(responses, covariates, offsets, weights, formula, control) if (control$backend == "torch") { diff --git a/inst/benchmark/bench_plnpca_init.R b/inst/benchmark/bench_plnpca_init.R new file mode 100644 index 00000000..99b67221 --- /dev/null +++ b/inst/benchmark/bench_plnpca_init.R @@ -0,0 +1,138 @@ +#!/usr/bin/env Rscript +## Benchmark : PLNPCA init_method × backend +## +## Comparaisons testées : +## init_method : "LM" — nouvelle init (lm.fit sur log(Y), défaut actuel) +## "GLM" — init Poisson GLM (p fits IRLS) +## "PLN-EM" — ancienne init master (PLNfit complet comme inception) +## backend : "nlopt" — CCSAQ (défaut PLNPCA) +## "builtin" — L-BFGS joint + Wolfe fort +## +## IMPORTANT : ne jamais lancer en parallèle (BLAS multithreadé). + +suppressPackageStartupMessages({ + devtools::load_all(quiet = TRUE) +}) +cat("PLNmodels", as.character(packageVersion("PLNmodels")), "\n\n") + +data(trichoptera); data(barents); data(oaks) +tri <- prepare_data(trichoptera$Abundance, trichoptera$Covariate) + +## -------------------------------------------------------------------------- +## Configurations testées +## -------------------------------------------------------------------------- +RANKS <- list( + trichoptera = c(1L, 3L, 5L), + barents = c(3L, 5L, 10L), + oaks = c(5L, 10L, 20L) +) + +DATASETS <- list( + list(name = "trichoptera", + formula = Abundance ~ 1, + data = tri), + list(name = "barents", + formula = Abundance ~ Depth + Temperature, + data = barents), + list(name = "oaks", + formula = Abundance ~ 1 + offset(log(Offset)), + data = oaks) +) + +BACKENDS <- c("nlopt", "builtin") + +## -------------------------------------------------------------------------- +## Helpers +## -------------------------------------------------------------------------- +run_one <- function(ds, ranks, backend, init_method, pln_inception = NULL) { + ctrl <- if (identical(init_method, "PLN-EM")) { + PLNPCA_param(backend = backend, trace = 0, inception = pln_inception) + } else { + PLNPCA_param(backend = backend, trace = 0, init_method = init_method) + } + t0 <- proc.time() + fit <- tryCatch( + PLNPCA(ds$formula, data = ds$data, ranks = ranks, control = ctrl), + error = function(e) { message(" ERROR: ", conditionMessage(e)); NULL } + ) + elapsed <- round((proc.time() - t0)[["elapsed"]], 2) + list(fit = fit, elapsed = elapsed) +} + +## -------------------------------------------------------------------------- +## Main loop (tout séquentiel) +## -------------------------------------------------------------------------- +results <- list() + +for (ds in DATASETS) { + ranks <- RANKS[[ds$name]] + cat(sprintf("=== %s (ranks: %s) ===\n", ds$name, paste(ranks, collapse = ","))) + + ## Pré-calculer le PLNfit pour l'init PLN-EM (une fois par dataset) + cat(" [PLN-EM] fitting full PLN inception ...\n") + t_pln <- proc.time() + pln_inc <- PLN(ds$formula, data = ds$data, control = PLN_param(trace = 0)) + t_pln <- round((proc.time() - t_pln)[["elapsed"]], 2) + cat(sprintf(" [PLN-EM] PLN done in %.1fs\n", t_pln)) + + for (backend in BACKENDS) { + for (init_method in c("LM", "GLM", "PLN-EM")) { + label <- sprintf("%-8s init=%-7s", backend, init_method) + cat(sprintf(" %s ...", label)) + + res <- run_one(ds, ranks, backend, init_method, pln_inception = pln_inc) + elapsed <- res$elapsed + + if (is.null(res$fit)) { + cat(" FAILED\n") + next + } + + for (m in res$fit$models) { + q <- m$rank + loglik <- round(m$loglik, 2) + n_iter <- if (!is.null(m$optim_par$iterations)) m$optim_par$iterations else NA_integer_ + results[[length(results) + 1]] <- data.frame( + dataset = ds$name, + rank = q, + backend = backend, + init_method = init_method, + loglik = loglik, + n_iter = as.integer(n_iter), + time_total_s = elapsed, + stringsAsFactors = FALSE + ) + } + ll_str <- paste(sapply(res$fit$models, function(m) round(m$loglik, 1)), collapse = " | ") + cat(sprintf(" %.1fs ll: %s\n", elapsed, ll_str)) + } + } + cat("\n") +} + +## -------------------------------------------------------------------------- +## Table de résultats +## -------------------------------------------------------------------------- +df <- do.call(rbind, results) + +cat("\n=== Résultats (loglik, plus grand = meilleur) ===\n\n") + +for (ds_name in unique(df$dataset)) { + sub <- df[df$dataset == ds_name, ] + cat(sprintf("-- %s --\n", ds_name)) + cat(sprintf(" %-8s %-8s %s\n", "backend", "init", paste(sprintf("q=%-4s", unique(sub$rank)), collapse = " "))) + for (b in BACKENDS) { + for (im in c("LM", "GLM", "PLN-EM")) { + row <- sub[sub$backend == b & sub$init_method == im, ] + if (nrow(row) == 0) next + row <- row[order(row$rank), ] + vals <- sprintf("%-6.1f", row$loglik) + cat(sprintf(" %-8s %-8s %s\n", b, im, paste(vals, collapse = " "))) + } + } + cat("\n") +} + +out_rds <- "inst/benchmark/bench_plnpca_init_results.rds" +saveRDS(df, out_rds) +cat("Résultats sauvegardés dans", out_rds, "\n") diff --git a/inst/benchmark/bench_plnpca_init_results.rds b/inst/benchmark/bench_plnpca_init_results.rds new file mode 100644 index 0000000000000000000000000000000000000000..556ab425b6abafe71aaebb7dada782c9ffb55959 GIT binary patch literal 887 zcmV--1Bm<|iwFP!000001MOFDNK;W1KklE~bEV}94YDZ6Y-k_C5K8nzWgjfk><>}c zQ>QNHwzg-621PIy1qrb)`l+&*l}UYjK_4#Gmt+M+WD)aE7$dZ_r6PgadFT10_Mil# zp!VSIcg}t1{O-B$o_o*TVGaPapfljF9!1a}DBG2thgvEsiP%!GZ3P{e5R(Lty|UKj z7Hl3q-u1h>5-WI*%_(@}s-)^%eBHk#11zCE1du?R4L8{$Wd*rK$_iQ*DSv-P=$#JC z?mw&~Ry5chg5CL-)%e{1x4HkA`0yB}q{|SQ|3ijEjP^3GIB=fq@9Jf}!##ln zS=et5g+fnRm+>pbd+UqrCr-)lI~(*ge(*WIZ5m`^{}jdB*^^B1cQl5`Uko)ejr-7PHmObV}*MPDBy-bi{Q*@s8(y4!m>7VS3@Uu3t;-?#Q2 z#T$L=Cca3{ZHhDeqK4v$_IA+w$mXVeBw*o=T;h%Pjnnsw6r7^@gooPbee~rC@{g>x z;)grQ!dFg9yfA+w(7ppOVin~wvF(?e`3x5O>$u2w08A)rt$2~RiD%ALl+j0rHwwc+ zxsYpe5!(S)Yy(KelPIkW<;&PU0jzQWB!9#M>MX$WN*of$FjwFh1IT+HZ=%Ps?-g<# zL2eNb*2gH%0AwQ1%4=x*9yuQZq~ju{k0aM5S=OCH|7GZpb1*%@rbEsh$boSg(~vVu z$;*O)cFGqO4h~bEsj!dI(4xYj5Uu-yae&gYRE4xkmSz=Bie#X|u?foiSS(EFqQF$B zk^N$^U{cBkE`FS+LjJ$_1CeJIcK=k(fNL#vCOYY3pb(2Vr)0wkI~^N(b*%LRLCCDde1L5Bj4v N^9|V|#%}Wt003Y9xL*JO literal 0 HcmV?d00001 diff --git a/inst/case_studies/oaks_tree.R b/inst/case_studies/oaks_tree.R index a39acc73..9008c3e1 100644 --- a/inst/case_studies/oaks_tree.R +++ b/inst/case_studies/oaks_tree.R @@ -89,7 +89,7 @@ factoextra::fviz_pca_biplot( labs(col = "distance (cm)") + scale_color_viridis_c() ## Network inference with sparce covariance estimation -system.time(myPLNnets <- PLNnetwork(Abundance ~ 0 + tree + offset(log(Offset)), data = oaks, control = PLNnetwork_param(min_ratio = 0.01))) +system.time(myPLNnets <- PLNnetwork(Abundance ~ 0 + tree + offset(log(Offset)), data = oaks, control = PLNnetwork_param(min_ratio = 0.02))) plot(myPLNnets) plot(getBestModel(myPLNnets, "EBIC")) # stability_selection(myPLNnets) diff --git a/man/PLNPCA_param.Rd b/man/PLNPCA_param.Rd index 6838cfca..768c5792 100644 --- a/man/PLNPCA_param.Rd +++ b/man/PLNPCA_param.Rd @@ -10,6 +10,7 @@ PLNPCA_param( config_optim = list(), config_post = list(), inception = NULL, + init_method = c("LM", "GLM"), sequential = FALSE ) } @@ -27,9 +28,19 @@ or \code{"torch"} (automatic differentiation via the torch package).} \item{config_post}{a list for controlling the post-treatments (optional bootstrap, jackknife, R2, etc.). See details} -\item{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.} +\item{inception}{an optional pre-fitted \code{\link{PLNfit}} object. When provided, its variational +means \code{M} and regression coefficients \code{B} are used to compute the shared SVD +\code{svd(M - X*B)} that initialises all ranks simultaneously. This replaces the default +LM-based starting point and can improve convergence for large ranks on datasets with +strong covariate effects (e.g. \code{inception = PLN(formula, data)}). When \code{NULL} (default), +a fast LM is used. \code{init_method} is ignored when \code{inception} is set.} + +\item{init_method}{character: strategy used to compute the starting point for the shared SVD. +Either \code{"LM"} (default, fast: one multivariate \code{lm.fit} on log-transformed counts) or +\code{"GLM"} (p independent Poisson GLMs, more accurate for complex or highly unbalanced +designs). Ignored when \code{inception} is provided. Benchmarks show \code{"LM"} is as good as +or better than \code{"GLM"} for PLNPCA in most cases; \code{"GLM"} is not recommended. +See \code{\link[=compute_PLN_starting_point]{compute_PLN_starting_point()}}.} \item{sequential}{logical. If \code{TRUE}, ranks are fitted in ascending order and each model is warm-started from the converged solution of the previous rank: loadings C are augmented diff --git a/man/PLNPCAfamily.Rd b/man/PLNPCAfamily.Rd index 085decf6..9317fd91 100644 --- a/man/PLNPCAfamily.Rd +++ b/man/PLNPCAfamily.Rd @@ -52,6 +52,9 @@ The function \code{\link[=PLNPCA]{PLNPCA()}}, the class \code{\link[=PLNPCAfit]{ \if{latex}{\out{\hypertarget{method-PLNPCAfamily-initialize}{}}} \subsection{\code{PLNPCAfamily$new()}}{ Initialize all models in the collection. +A single SVD of the residual matrix \code{M - X*B} is computed once and shared across +all ranks. \code{M} and \code{B} come from either a user-provided \code{\link{PLNfit}} inception or a +fast LM on log-transformed counts (default, controlled by \code{init_method}). \subsection{Usage}{ \if{html}{\out{
}} \preformatted{PLNPCAfamily$new( diff --git a/man/PLNPCAfit.Rd b/man/PLNPCAfit.Rd index 8d3c9460..bd598915 100644 --- a/man/PLNPCAfit.Rd +++ b/man/PLNPCAfit.Rd @@ -86,7 +86,10 @@ The function \code{\link{PLNPCA}}, the class \code{\link[=PLNPCAfamily]{PLNPCAfa \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-PLNPCAfit-initialize}{}}} \subsection{\code{PLNPCAfit$new()}}{ - Initialize a \code{\link{PLNPCAfit}} object + Initialize a \code{\link{PLNPCAfit}} object. +Uses the shared SVD from \code{control$svdM} (computed once in \code{\link{PLNPCAfamily}}) to set +the starting loadings \code{C} and scores \code{M}. The regression coefficients \code{B} are +initialised by the parent \code{\link{PLNfit}} constructor (LM or user-provided inception). \subsection{Usage}{ \if{html}{\out{
}} \preformatted{PLNPCAfit$new(rank, responses, covariates, offsets, weights, formula, control)}