fab.hme.learner.opt package

Submodules

fab.hme.learner.opt.calc_hme_fic module

fab.hme.learner.opt.calc_hme_fic.calc_hme_fic(comps, lvprior, vposterior, loglikelihood_compwise, gate_fisher_coeffs=1.0, comp_fisher_coeffs=1.0)

Calculates FIC value for HME models.

This method calculates the lower bound of FIC value.

Parameters:
compslist[FABComponent]

List of component objects. Parameter dimensionalities are referred to.

lvpriorHMEBinaryTreeLVPrior

Latent variable prior object. The tree structure of lvprior and the parameter dimensionality of each gate are referred to.

vposteriorHMEVPosterior

Variational posterior used to calculate the expected number on gates and components.

loglikelihood_compwisenp.ndarray, size = (num_samples, num_comps)

Component-wise log-likelihood values for each sample.

gate_fisher_coeffsfloat or np.ndarray, size = (num_samples, num_gates)

If 1.0 [default], the number of expected samples is simply applied. For calculating scaled FIC value of lvprior complexity penalty, coefficient matrix or scalar value to vposterior must be given.

comp_fisher_coeffsfloat or np.ndarray, size = (num_samples, num_comps)

or size = (num_samples, num_targets, num_comps)

If 1.0 [default], the number of expected samples is simply applied. For calculating scaled FIC value of component complexity penalty, coefficient matrix or scalar value to vposterior must be given.

Returns:
ficfloat

The calculated FIC value.

fab.hme.learner.opt.operate_hme_shrinkage module

fab.hme.learner.opt.operate_hme_shrinkage.operate_hme_shrinkage(comps, lvprior, vposterior, threshold, is_ratio, comp_fisher_coeffs=1.0)

Executes shrinkage operation for FAB/HME having a binary tree prior.

Looking at the \(j\)-th component, if the effective number of samples is less than a threshold value:

\[N^{(t)}_{\phi_j} = \sum_{n=1}^N q^{(t)}(\zeta_{j}^{n}) \ \Gamma_{\phi_{(n, j)}}^{(t)} < \delta,\]

then the component will be shrunk.

Remaining components are normalized as \(q^{(t)}(\zeta ^{(n)} _j) = q^{(t)}(\zeta ^{(n)}) / Q^{(t)}_j\), where \(Q^{(t)}_j\) is a normalization constant for \(\sum ^E _{j=1} q^{(t)}(\zeta^{(n)} _j) = 1\).

Parameters:
compslist[FABComponent]

List of component objects to be shrunk.

lvpriorHMEBinaryTreeLVPrior

Latent variable prior object to be shrunk.

vposteriorHMEVPosterior

Variational posterior object to be shrunk.

thresholdfloat

Threshold value for shrinkage, \(\delta\).

is_ratiobool

Indicates whether threshold means absolute value or relative value.

comp_fisher_coeffsfloat or np.ndarray, size = (num_samples, num_comps)

or size = (num_samples, num_targets, num_comps)

If 1.0 [default], the number of expected samples is simply applied. For using the scaled number of expected samples, a coefficient matrix to vposterior must be given.

Returns:
shrink_comp_masknp.array(bool), size = (num_comps)

Indicates whether each component is judged to be shrunk: If shrink_comp_mask[i] is True, the i-th component is shrinkable.

Raises:
FABAllComponentsShrunkError

When not components or only one component is remained by shrinkage.

fab.hme.learner.opt.update_fisher_coeffs_context module

fab.hme.learner.opt.update_fisher_coeffs_context.calc_cl_comp_init_fisher_coeffs(Y)

Calculates initial Fisher’s coefficient values for the single classification component optimization.

It’s values are estimated by the fraction of the positive samples.

Parameters:
Ynp.array, size = (num_samples)

Target data.

Returns:
fisher_coeffsfloat or np.array, size = (num_targets)

Initial Fisher’s coefficient values for classification component.

fab.hme.learner.opt.update_fisher_coeffs_context.update_logit_gate_fisher_coeffs_context(context, with_scaled_l0_regularize, lvprior, X)

Calculates the Fisher coefficient of logistic-gates.

Parameters:
contextHMELearningContext

Context object in which the calculated coefficient value will be saved.

with_scaled_l0_regularizebool

Flag whether the scaled L0-regularization is applied. If False, the coefficient value is always 1.0.

lvpriorHMELogitGateLVPrior

Latent variable prior.

Xnp.ndarray, size = (num_samples, num_features)

Feature data applied to gate functions.

Returns:
None
fab.hme.learner.opt.update_fisher_coeffs_context.update_logit_rg_comp_fisher_coeffs_context(context, with_scaled_l0_regularize, comps, X, Y)

Calculates the Fisher coefficient of logistic regression components.

Parameters:
contextHMELearningContext

Context object in which the calculated coefficient value will be saved.

with_scaled_l0_regularizebool

Flag whether the scaled L0-regularization is applied. If False, the coefficient value is always 1.0.

compsList[SupervisedComponent]

List of component objects.

Xnp.ndarray, size = (num_samples, num_features)

Feature data applied to components.

Ynp.array, size = (num_samples)

Target data.

Returns:
None
fab.hme.learner.opt.update_fisher_coeffs_context.update_lsqr_rg_comp_fisher_coeffs_context(context, with_scaled_l0_regularize, comps)

Calculates the Fisher coefficient of least-squares regression components.

Parameters:
contextHMELearningContext

Context object in which the calculated coefficient value will be saved.

with_scaled_l0_regularizebool

Flag whether the scaled L0-regularization is applied. If False, the coefficient value is always 1.0.

compsList[SupervisedComponent]

List of component objects, which have attribute named variance.

Returns:
None

fab.hme.learner.opt.update_hme_vposterior module

fab.hme.learner.opt.update_hme_vposterior.update_hme_vposterior(comps, lvprior, vposterior, loglikelihood_compwise, gate_fisher_coeffs=1.0, comp_fisher_coeffs=1.0)

Updates the variational posterior as FAB E-step for HME models.

This method calculates variational posterior distribution with component-wise log-likelihood and a regularization-term.

Parameters:
compslist[FABComponent]

List of component objects. Parameter dimensionality of each component is referred to.

lvpriorHMEBinaryTreeLVPrior

Latent variable prior object. Gate-tree structure of the prior and parameter dimensionality of each gate are referred to.

vposteriorHMEVPosterior

Variational posterior distribution to be updated.

loglikelihood_compwisenp.ndarray, size = (num_samples, num_comps)

Component-wise log-likelihood values for each sample.

gate_fisher_coeffsfloat or np.ndarray, size = (num_samples, num_gates)

If 1.0 [default], the number of expected samples is simply applied to the regularize term calculation. For scaled gate complexity, a coefficient matrix to vposterior must be given.

comp_fisher_coeffsfloat or np.ndarray, size = (num_samples, num_comps)

or size = (num_samples, num_targets, num_comps)

If 1.0 [default], the number of expected samples is simply applied to the regularize term calculation. For scaled component complexity, a coefficient matrix to vposterior must be given.

Returns:
None
fab.hme.learner.opt.update_hme_vposterior.update_hme_vposterior_projection(vposterior, vposterior_updated, posterior_gate)

Updates the variational posterior distribution with projection E-step algorithm.

This method uses the variational posterior at \(t\) and \(t + 1\) (\(q(t)\) and \(q(t + 1)\)) and the posterior from the latent variable prior (\(q_{\rm gate}(t + 1)\)).

Parameters:
vposteriorHMEVPosterior

Variational posterior in the previous step, \(t\). Its matrix values are updated in this method according to projection E-step algorithm.

vposterior_updatedHMEVPosterior

Variational posterior in the current step, \(t + 1\), which was calculated with normal E-step algorithm.

posterior_gatenp.ndarray, size = (num_samples, num_comps)

Posterior distribution calculated from gating-tree structure and its gating function with input feature data. Before calculating posterior_gate, the gating-functions were optimized using vposterior_updated.

Returns:
None

Module contents