fab.learner.lvprior package¶
Submodules¶
fab.learner.lvprior.binning_info module¶
- class fab.learner.lvprior.binning_info.BinningInfo(X, max_bins)¶
Bases:
object
Binning information container class.
It holds the binning array length for each feature and sorting indices.
- Parameters:
- Xnp.ndarray, size = (num_samples, num_features)
Input feature data.
- max_binsint
Maximum number of bins for each feature.
- Attributes:
- Xnp.ndarray, size = (num_samples, num_features)
Input feature data.
- sort_idsnp.ndarray(int), size = (num_samples, num_features)
Sorting sample IDs for each feature.
- num_binsnp.array(int), size = (num_features)
Number of binning IDs for each feature. Possible values in the array are in [0, max_bins].
- binning_idsnp.ndarray(int), size = (num_samples, num_features)
Sample IDs whose sample is on the binning boundary.
Methods
calc_threshold_value
(feature_index, bin_id)Returns threshold value from feature index and binning ID.
- calc_threshold_value(feature_index, bin_id)¶
Returns threshold value from feature index and binning ID.
In this method, the threshold is set at center of two samples in the vicinity of the binning point.
If bin_id = 0 is specified for a feature on which num_bins = 0, the threshold value is the average of min(X) and max(X), this is because the sorted_id (= 0) and sorted_id - 1 (= -1) indicates the first and last samples, respectively.
- Parameters:
- feature_indexint
Feature index number, range = [0, num_features).
- bin_idint
Binning sample ID number, range = [0, num_bins(feature_index)).
- Returns:
- thresholdfloat
Threshold value of gating function.
fab.learner.lvprior.hme_binary_tree_utils module¶
- fab.learner.lvprior.hme_binary_tree_utils.construct_complete_binary_tree(tree_depth)¶
Constructs the complete binary tree in specified tree-depth.
Index number for either gate node or component node is set for all nodes in this method. Note that gating function for all gate function is None, so that should be set on the outside of this method.
- Parameters:
- tree_depthint
Depth of the gating-tree in the prior. Domain = [0, inf).
- Returns:
- root_nodeHMEBinaryTreeNode
Root node object in the tree.
- fab.learner.lvprior.hme_binary_tree_utils.cumulate_vposterior_on_binarytree_branches(lvprior, posterior_prob)¶
Cumulates posterior distribution of child branches on both sides for each gating-node.
For this method, the number of gating-nodes in the prior must be one or more, therefore, the prior having only a component node is not acceptable.
- Parameters:
- lvpriorHMEBinaryTreeLVPrior
Latent variable prior object for FAB/HME.
- posterior_probnp.ndarray, size = (num_samples, num_comps)
Variational posterior matrix.
- Returns:
- posterior_on_leftsnp.ndarray, size = (num_samples, num_gates)
Posterior on the left-child branch of each gating-node.
- posterior_on_rightsnp.ndarray, size = (num_samples, num_gates)
As with the posterior_on_lefts.
- Raises:
- ValueError
When the number of gating-nodes is zero.
- fab.learner.lvprior.hme_binary_tree_utils.prune_binarytree_nodes(lvprior, new_comp_indices)¶
Executes shrinkage operation of HME prior containing a binary tree.
- Parameters:
- lvpriorHMEBinaryTreeLVPrior
Latent variable prior object having a binary tree.
- new_comp_indicesnp.array, size = (num_comps, dtype=’O’)
Re-assigned component indices. For the i-th component, new component index is new_comp_indices[i] (= [0, num_comps)). If the i-th component is judged to be shrunk, new_comp_indices[i] is None.
- Returns:
- None
fab.learner.lvprior.init_hme_bern_gate_lvprior module¶
- fab.learner.lvprior.init_hme_bern_gate_lvprior.init_bern_gate_func_random(data)¶
Generates
BernGateFunction
objects whose parameters are initialized randomly.- Parameters:
- dataSupervisedData
Input data.
- Returns:
- gate_funcBernGateFunction
An initialized Bernoulli-gating function.
- fab.learner.lvprior.init_hme_bern_gate_lvprior.init_hme_bern_gate_lvprior_random(tree_depth, data)¶
Generates
HMEBernGateLVPrior
objects whose parameters are initialized randomly.In this method, the generated structure of the gate-tree is complete binary tree.
- Parameters:
- tree_depthint
Depth of the gating-tree in the prior. Domain = [0, inf). Depth = 0 means the prior has only one component node and there are not gating-nodes.
- dataSupervisedData
Input data.
- Returns:
- lvpriorHMEBernGateLVPrior
An initialized latent variable prior.
fab.learner.lvprior.init_hme_logit_gate_lvprior module¶
- fab.learner.lvprior.init_hme_logit_gate_lvprior.init_hme_logit_gate_lvprior_random(tree_depth, data)¶
Generates
HMELogitGateLVPrior
objects whose parameters are initialized randomly.In this method, the generated structure of the gate-tree is complete binary tree.
- Parameters:
- tree_depthint
Depth of the gating-tree in the prior. Domain = [0, inf). Depth = 0 means the prior has only one component node and there are not gating-nodes.
- dataSupervisedData
Input data.
- Returns:
- lvpriorHMELogitGateLVPrior
An initialized latent variable prior.
- fab.learner.lvprior.init_hme_logit_gate_lvprior.init_logit_gate_func_random(data)¶
Generates
LogitGateFunction
objects whose parameters are initialized randomly.Select a feature, and set a random threshold value within the value range of the feature.
- Parameters:
- dataSupervisedData
Input data.
- Returns:
- gate_funcLogitGateFunction
An initialized Logistic-gating function.
fab.learner.lvprior.opt_hme_bern_gate_lvprior module¶
- fab.learner.lvprior.opt_hme_bern_gate_lvprior.binarize_bern_gates(lvprior, opt_mode)¶
Binarizes the probability in Bernoulli-gate functions.
If the \(p > 0.5\) then the value is binarized as \(p = 1.0\), otherwise, \(p = 0.0\).
- Parameters:
- lvpriorHMEBernGateLVPrior
Latent variable prior with Bernoulli-gates.
- opt_mode{‘opt’, ‘refit’, ‘keep’}
- Mode of gate parameter optimization;
‘opt’: optimizing with all features (selecting and fitting the features), ‘refit’: only fitting with relevant features, ‘keep’: keeping all parameter values.
- Returns:
- None
- fab.learner.lvprior.opt_hme_bern_gate_lvprior.calc_bern_gate_objective_value(gate_func, X, posterior_left, posterior_right)¶
Calculates the objective value for optimizing Bernoulli-gate parameters.
- Parameters:
- gate_funcBernGateFunction
Bernoulli-gate functions object.
- Xnp.ndarray, size = (num_samples, num_features)
Input feature data for gate-optimization.
- posterior_leftnp.array, size = (num_samples)
Posterior for left-side branch on the gating-nodes.
- posterior_rightnp.array, size = (num_samples)
Posterior for right-side branch on the gating-nodes.
- Returns:
- obj_valuefloat
Objective value for optimizing Bernoulli-gate parameters.
- fab.learner.lvprior.opt_hme_bern_gate_lvprior.opt_hme_bern_gate_lvprior(lvprior, vposterior_prob, binning_info, opt_mode, num_threads_gates, num_threads_gate_features, with_validation='correct')¶
Optimizes Bernoulli-gates parameters of HME latent variable prior.
- Parameters:
- lvpriorHMEBernGateLVPrior
Latent variable prior object in which parameter values are updated.
- vposterior_probnp.ndarray, size = (num_samples, num_comps)
Variational posterior matrix.
- binning_infoBinningInfo
Binning information used to optimize parameters efficiently.
- opt_mode{‘opt’, ‘refit’, ‘keep’}
- Mode of gate parameter optimization;
‘opt’: optimizing with all features (selecting and fitting the features), ‘refit’: only fitting with relevant features, ‘keep’: keeping all parameter values.
- num_threads_gatesint
Number of OpenMP threads in gate-level for-loop.
- num_threads_gate_featuresint
Number of OpenMP threads in feature-level for-loop.
- with_validation{‘nocheck’, ‘ignore’, ‘correct’}, optional
Flag to indicate whether the following validation is enabled: If FIC of the component decreases with the optimization, previous parameter values are restored to the component.
- Returns:
- None
fab.learner.lvprior.opt_hme_logit_gate_lvprior module¶
- fab.learner.lvprior.opt_hme_logit_gate_lvprior.binarize_logit_gates(lvprior, opt_mode)¶
Binarizes the probability in logistic-gate functions.
This method set a flag to each gate function as hard-gate. If \(p > 0.5\), then the probability will be 1.0, otherwise 0.0.
- Parameters:
- lvpriorHMELogitGateLVPrior
Latent variable prior with logistic-gates.
- opt_mode{‘opt’, ‘refit’, ‘keep’}
- Mode of gate parameter optimization;
‘opt’: optimizing with all features (selecting and fitting the features), ‘refit’: only fitting with relevant features, ‘keep’: keeping all parameter values.
- Returns:
- None
- fab.learner.lvprior.opt_hme_logit_gate_lvprior.calc_const_masks(X, Y, posterior_on_gates)¶
Calculates constant masks for feature data and target data.
- Parameters:
- Xnp.ndarray, size = (num_samples, num_features)
Feature data.
- Ynp.ndarray, size = (num_samples, num_gates)
Target data.
- posterior_on_gatesnp.ndarray, size = (num_samples, num_gates)
The posterior for each sample and gate
- Returns:
- const_feature_masknp.ndarray, size = (num_features, num_gates)
The constant mask for feature data and each gate.
- const_target_masknp.ndarray, size = (num_features, num_gates)
The constant mask for target data and each gate.
- fab.learner.lvprior.opt_hme_logit_gate_lvprior.calc_gate_decision_func(lvprior, X)¶
Calculates the decision function values for each gate in a lvprior.
- Parameters:
- lvpriorHMELogitGateLVPrior
Latent variable prior in which log-likelihood values of each gate are calculated.
- Xnp.ndarray, size = (num_samples, num_features)
Feature data.
- Returns:
- decision_funcnp.ndarray, size = (num_samples, num_gates)
Log-likelihood values for all gates.
- fab.learner.lvprior.opt_hme_logit_gate_lvprior.calc_gate_loglikelihood(lvprior, X)¶
Calculates log-likelihood for each gate in a lvprior.
- Parameters:
- lvpriorHMELogitGateLVPrior
Latent variable prior in which log-likelihood values of each gate are calculated.
- Xnp.ndarray, size = (num_samples, num_features)
Feature data.
- Returns:
- loglikelihoodnp.ndarray, size = (num_samples, num_gates)
Log-likelihood values for all gates.
- fab.learner.lvprior.opt_hme_logit_gate_lvprior.calc_logit_gate_objective_value(gate_func, X, posterior_left, posterior_right, num_expect_samples)¶
Calculates the objective value for optimizing logistic-gate parameters.
- Parameters:
- gate_funcBernGateFunction
Logistic-gate function object.
- Xnp.ndarray, size = (num_samples, num_features)
Input feature data for gate-optimization.
- posterior_leftnp.array, size = (num_samples)
Posterior on left-side branch of the gating-nodes.
- posterior_rightnp.array, size = (num_samples)
Posterior on right-side branch of the gating-nodes.
- fisher_coeffsfloat or np.array, size = (num_sample) [default: 1.0]
Coefficient of the number of expected samples calculated from the empirical Fisher matrix. If 1.0, the scale is disabled.
- Returns:
- obj_valuefloat
Objective value for optimizing logistic-gate parameters.
- fab.learner.lvprior.opt_hme_logit_gate_lvprior.opt_hme_logit_gate_lvprior(lvprior, data, vposterior_prob, opt_mode, opt_type, l2_regularize, fisher_coeffs, max_relevant_features, svd_threshold, num_threads, with_validation='correct')¶
- fab.learner.lvprior.opt_hme_logit_gate_lvprior.validate_gates_fic_increase(lvprior, num_expect_samples, prev_gate_func_list, prev_num_expect_samples, data, posterior_on_gates, posterior_lefts, posterior_rights, restore=True)¶