| NormalBlockBase | R Documentation |
R6 abstract class shared by the variance-block (NormalBlockVarBase) and mean-block (NormalBlockMeanBase) model families.
dataobject of NormalBlockData class, with responses and design matrix
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 costs nu * 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 charged log(p) (the variables are
the units being clustered), parameters shared by every cell of a block
log(n * p), and the remaining ones log(n).
nb_paramnumber of free parameters in the model, sum(penalty_terms$nu)
penaltyBIC penalty, sum(nu * log(N)) over penalty_terms
BICBayesian 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), where dim is 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
NormalBlockBase$new()Create a new NormalBlockBase object.
NormalBlockBase$new(data, q, sparsity = 0, control, zero_inflation = FALSE)
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.
A new NormalBlockBase object
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.
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 )
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
Update the current object in place
NormalBlockBase$optimize()calls optimization (EM or heuristic) and updates relevant fields
NormalBlockBase$optimize( control = list(niter = 500, threshold = 1e-04, fixed_point_niter = 5), warn = TRUE )
controla list for controlling the optimization process
warnwhether to warn when the (V)EM stops at the niter cap
without reaching threshold (see private$warn_if_not_converged()).
Set to FALSE for deliberately-truncated trial fits (cheap candidate
scoring in candidates_split()/candidates_merge(), the sparsity-path
warm-start probe in NormalBlockCollectionSparsity) where stopping at
the cap is expected and not a sign of trouble.
optimizes the model and updates its parameters
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.
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) )
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 inits before fully retraining the best few
max_traininghow many of the screened candidates (best loglik
after trial_niter iterations) get fully retrained with control
controloptimize() control list (niter/threshold) used
for the final full retraining of the max_training best candidates
a new, already-optimized model. Does not mutate the current
object; reassign the result (model <- model$best_of_inits()).
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$warm_start_from(other)
othera model of the same class, already optimized
Update the current object in place with other's parameters
NormalBlockBase$candidates_split()generate and select a set of candidate models by splitting the clusters of the current model
NormalBlockBase$candidates_split(trial_niter = 5, split_rule = NULL)
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 its rule: "kmeans",
"noise", or NULL for the family's default
NormalBlockBase$candidates_merge()generate and select a set of candidate models by merging the clusters of the current model
NormalBlockBase$candidates_merge(max_candidates = 30, trial_niter = 2)
max_candidatesmerge candidates are, unlike split's, quadratic
in q (choose(q, q-2) pairs): beyond max_candidates pairs, only
the most promising ones are actually built and trial-optimized, ranked
by the family's own private$merge_score(). Set to Inf to 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.
NormalBlockBase$heldout_loglik(newdata, per_observation = FALSE)
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.
the held-out log-likelihood, or a vector of newdata$n values
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$predict(new_X)
new_Xnew set of covariates.
A n*p prediction matrix for new observations
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.
NormalBlockBase$latent_network(type = c("partial_cor", "support", "precision"))
typeedge value in the network: "support" (binary edges), "precision" (entries of the precision matrix, on the scale of the fit) or "partial_cor" (partial correlations)
a sparse square matrix, q x q (variance-block) or p x p (mean-block), with named rows and columns
NormalBlockBase$plot_loglik()plots the evolution of the objective (log-likelihood or ELBO)
across the (V)EM iterations of the last call to optimize().
NormalBlockBase$plot_loglik(show_increment = TRUE)
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).
a ggplot2::ggplot graph
NormalBlockBase$plot_network()Plot the network encoded by Omega (see
$latent_network() to extract it as a matrix).
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
)
typeedge value in the network: "partial_cor" (partial correlations) or "support" (binary edges).
outputOutput type. Either igraph (for the network) or corrplot (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$plot()
NormalBlockBase$print()User friendly print method
NormalBlockBase$print(model = paste0("A ", self$who_am_I, ".\n"))
modelFirst line of the print output
NormalBlockBase$clone()The objects of this class are cloneable with this method.
NormalBlockBase$clone(deep = FALSE)
deepWhether to make a deep clone.
# An internal abstract base class, never instantiated directly -- see
# normal_block() for how concrete models are created and fitted.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.