R6 abstract class shared by the variance-block (NormalBlockVarBase) and mean-block (NormalBlockMeanBase) model families.
Active bindings
inference_methodinference procedure used (heuristic or integrated with EM)
nnumber of samples
pnumber of responses per sample
dnumber of variables (dimensions in X)
d0number of zero-inflation covariates (dimensions in X0)
who_am_Ia description of the model
qnumber of blocks
n_edgesnumber of edges of the network (non null coefficient of the sparse precision matrix Omega)
objectiveevolution of the objective function during (V)EM algorithm
loglik(or its variational lower bound)
deviance(or its variational lower bound)
entropyentropy of the (variational) posterior distribution of the clustering,
-sum(tau * log(tau)): 0 when the clustering is known. Only the discrete partition is completed, as in the ICL of Biernacki, Celeux and Govaert (2000); the latent vectors W of the variance-block family are integrated out, not completed.penalty_termsdata frame with one row per group of parameters: its name (
group), its number of free parameters (nu) and the number of independent observations informing it (N), so that the group costsnu * log(N)in the BIC. As in the ICL of Daudin, Picard and Robin (2008) for SBMs and Keribin et al. (2015) for latent block models, the cluster proportions are chargedlog(p)(the variables are the units being clustered), parameters shared by every cell of a blocklog(n * p), and the remaining oneslog(n).nb_paramnumber of free parameters in the model,
sum(penalty_terms$nu)penaltyBIC penalty,
sum(nu * log(N))overpenalty_termsBICBayesian information criterion,
deviance + penalty(lower is better); built on the ELBO when the clustering is unknown and the likelihood is not available in closed form.ICLintegrated completed likelihood criterion,
BIC + 2 * entropy(lower is better); equal to the BIC when the clustering is known.EBICextended BIC of Foygel and Drton (2010) with gamma = 1/2,
BIC + 2 * n_edges * log(dim), wheredimis the dimension of the network: q for the variance-block family (network between clusters), p for the mean-block family (network between variables).criteriaa vector with loglik, BIC and number of parameters
sparsity(overall sparsity parameter)
sparsity_term(sparsity_term term in log-likelihood due to sparsity)
membershipsthe p x q matrix of cluster memberships: indicators for a known clustering, posterior probabilities (tau) otherwise
clusteringthe cluster label of each variable (MAP for an unknown clustering), named after the columns of Y
cluster_sizesgiven as a vector of cluster sizes
elements_per_clustergiven as the list of elements contained in each cluster
Methods
NormalBlockBase$new()
Create a new NormalBlockBase object.
Usage
NormalBlockBase$new(data, q, sparsity = 0, control, zero_inflation = FALSE)Arguments
dataobject of NormalBlockData class, with responses and design matrix
qnumber of block/cluster
sparsitysparsity penalty on the network density
controlstructured list of more specific parameters, to generate with NB_control
zero_inflationwhether the concrete subclass models zero-inflation; set by the ZI subclasses themselves, not meant to be set by the end user. When
FALSE, the (costly) zero-inflation probability fit (kappa/B0) is skipped entirely, since it would otherwise never be used downstream.
NormalBlockBase$update()
Update the parameters of a model in place. Each argument applies to
the families or variants named in parentheses; NA (the default)
leaves the parameter unchanged.
Usage
NormalBlockBase$update(
B = NA,
dm1 = NA,
C = NA,
Omega = NA,
gamma = NA,
mu = NA,
alpha = NA,
M = NA,
S = NA,
ll_list = NA,
warm_started = NA,
clustering_init = NA
)Arguments
Bregression coefficients (all models)
dm1inverse noise variances of the variables (variance-block)
Ccluster memberships: indicators, or posterior probabilities (all models)
Omegaprecision matrix: between clusters (variance-block) or between variables (mean-block)
gammaposterior variance of W (variance-block, known clusters)
muposterior mean of W (variance-block, known clusters)
alphacluster proportions (unknown clusters)
Mvariational means of W (variance-block, unknown clusters)
Svariational variances of W (variance-block, unknown clusters)
ll_listlist of log-lik (elbo) values
warm_startedwhether
optim_initialize()should treat the model as already initialized (reuse B/Omega/dm1/C/alpha/M/S as they stand) rather than recomputing a fresh heuristic initialization. Set by$warm_start_from()and by$split()/$merge().clustering_initinitial clustering
NormalBlockBase$optimize()
calls optimization (EM or heuristic) and updates relevant fields
Usage
NormalBlockBase$optimize(
control = list(niter = 500, threshold = 1e-04, fixed_point_niter = 5),
warn = TRUE
)Arguments
controla list for controlling the optimization process
warnwhether to warn when the (V)EM stops at the
nitercap without reachingthreshold(seeprivate$warn_if_not_converged()). Set toFALSEfor deliberately-truncated trial fits (cheap candidate scoring incandidates_split()/candidates_merge(), the sparsity-path warm-start probe in NormalBlockCollectionSparsity) where stopping at the cap is expected and not a sign of trouble.
NormalBlockBase$best_of_inits()
Try several clustering-initialization heuristics and keep
the best-ELBO converged fit (see NB_control()'s clustering_init
for the heuristics and the rationale behind the default). Every
candidate is first screened with a short trial_niter run (same idea
as candidates_split()/candidates_merge()), and only the
max_training best-screened ones are fully retrained with control.
Usage
NormalBlockBase$best_of_inits(
inits = private$default_inits,
trial_niter = 10,
max_training = 2,
control = list(niter = 500, threshold = 1e-04, fixed_point_niter = 5)
)Arguments
initsvector of clustering-heuristic names to try; defaults to the model family's own preferred order (
private$default_inits)trial_niternumber of (V)EM iterations used to cheaply screen every candidate in
initsbefore fully retraining the best fewmax_traininghow many of the screened candidates (best
loglikaftertrial_niteriterations) get fully retrained withcontrolcontroloptimize()control list (niter/threshold) used for the final full retraining of themax_trainingbest candidates
NormalBlockBase$warm_start_from()
Seed this model's starting parameters from another, already-optimized model of the same family and q, instead of a fresh heuristic clustering. Used by the sparsity paths to warm-start each penalty from the previous one's solution.
NormalBlockBase$candidates_split()
generate and select a set of candidate models by splitting the clusters of the current model
Arguments
trial_niternumber of (V)EM iterations used to cheaply score each candidate before the caller fully re-optimizes the best few – kept short on purpose.
split_rulepassed to
split()as itsrule:"kmeans","noise", orNULLfor the family's default
NormalBlockBase$candidates_merge()
generate and select a set of candidate models by merging the clusters of the current model
Arguments
max_candidatesmerge candidates are, unlike split's, quadratic in q (
choose(q, q-2)pairs): beyondmax_candidatespairs, only the most promising ones are actually built and trial-optimized, ranked by the family's ownprivate$merge_score(). Set toInfto always try every pair.trial_nitersee
$candidates_split()
NormalBlockBase$heldout_loglik()
Log-likelihood of new observations at the fitted
parameters and, for an unknown clustering, at the MAP partition (see
normal_block_cv()). It is exact, computed for variance-block models
with q x q matrices only (Woodbury identity), and given on Y's original
scale.
Arguments
newdataa NormalBlockData object with the same variables and covariates (and zero-inflation covariates) as the training data.
per_observationwhether to return one value per observation rather than their sum.
NormalBlockBase$predict()
Predicts the mean of Y for new covariates X, in Y's
original units. For the variance-block family, X B: the latent block
signals average out, so that on the training X it differs from
fitted(), which adds their posterior mean. The mean-block family
overrides it.
NormalBlockBase$latent_network()
Extract the network encoded by Omega, as a matrix rather
than a plot (see $plot_network()): between clusters for the
variance-block family, between variables for the mean-block family.
Usage
NormalBlockBase$latent_network(type = c("partial_cor", "support", "precision"))NormalBlockBase$plot_loglik()
plots the evolution of the objective (log-likelihood or ELBO)
across the (V)EM iterations of the last call to optimize().
Arguments
show_incrementwhether to add a second panel with the (log10) absolute increment between iterations and the convergence
threshold(distinguishes true convergence from a flat-looking objective trace).
Returns
a ggplot2::ggplot graph
NormalBlockBase$plot_network()
Plot the network encoded by Omega (see
$latent_network() to extract it as a matrix).
Usage
NormalBlockBase$plot_network(
type = c("partial_cor", "support"),
output = c("igraph", "corrplot"),
edge.color = c("#F8766D", "#00BFC4"),
remove.isolated = FALSE,
node.labels = NULL,
layout = igraph::layout_in_circle,
plot = TRUE
)Arguments
typeedge value in the network: "partial_cor" (partial correlations) or "support" (binary edges).
outputOutput type. Either
igraph(for the network) orcorrplot(for the adjacency matrix)edge.colorLength 2 color vector. Color for positive/negative edges. Default is
c("#F8766D", "#00BFC4"). Only relevant for igraph output.remove.isolatedif
TRUE, isolated node are remove before plotting. Only relevant for igraph output.node.labelsvector of character. The labels of the nodes. By default, the cluster names (variance-block) or the variable names (mean-block), as in
$latent_network().layoutan igraph layout function, applied to the graph without its edge weights, or a matrix of node coordinates. Only relevant for igraph output.
plotlogical. Should the final network be displayed or only sent back to the user. Default is
TRUE.
NormalBlockBase$plot()
plots the evolution of the objective during model optimization
(see plot_loglik())
NormalBlockBase$print()
User friendly print method
Usage
NormalBlockBase$print(model = paste0("A ", self$who_am_I, ".\n"))