fab.model.component package

Submodules

fab.model.component.bspline_predict_comp module

class fab.model.component.bspline_predict_comp.BSplineClComponent(comp_id, feature_ids, degree, knot_vecs, weights, bias)

Bases: BSplinePredictionComponent

B-spline non-linear classification component.

Parameters:
comp_idint

Component ID number.

feature_idslist[int], size = (num_features)

Feature ID number for each feature.

degreeint

Degree of B-spline function.

knot_vecsnp.ndarray, size = (num_features, num_knots)

Knot vector for each feature.

weightsnp.ndarray, size = (num_features, basis_dim)

Weight vector for each feature.

biasfloat

Bias value.

Attributes:
basis_dim

Returns ——- basis_dim : int Dimensionality of a basis function; {num_knots - degree}.

parameter_dim

Returns ——- parameter_dim : int Parameter dimensionality of this component.

relevant_feature_mask

Returns ——- relevant_feature_mask : np.array(bool), size = (num_features) Flags for each feature whether the weight value is non-zero.

Methods

calc_basis_func_matrices(X)

Calculates the basis function value matrices for all features.

calc_decision_function(X[, B_list])

Calculates the value of decision function.

calc_loglikelihood(X, Y)

Calculates the log-likelihood value for each sample.

from_dict(comp_dict)

Restores the component object from dict information.

predict(X)

Predicts the values based on the decision function and the input feature data.

to_dict()

Generates a dict of information on the component.

calc_loglikelihood(X, Y)

Calculates the log-likelihood value for each sample.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Ynp.array, size = (num_samples,)

Input target data.

Returns:
loglikelihoodnp.array, size = (num_samples)

Calculated log-likelihood values for all samples.

classmethod from_dict(comp_dict)

Restores the component object from dict information.

Parameters:
comp_dict: dict

Information on the component.

Returns:
component: BSplineClComponent

An instance of this class in which knot_vecs, weights and bias are set.

Notes

For the format of the dict (comp_dict), refer to an example for to_dict() method.

property parameter_dim
Returns:
parameter_dimint

Parameter dimensionality of this component. It is equal to {the number of nonzero elements in weights} + 1 (bias).

predict(X)

Predicts the values based on the decision function and the input feature data.

If a decision function value >= 0, the sample is classified as 1; Otherwise, -1.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Returns:
Y_estnp.array, size = (num_samples)

Predicted values, either 1 or -1.

to_dict()

Generates a dict of information on the component.

Returns:
comp_dictdict

Information on the component.

Examples

>>> component.to_dict()
{
    'comp_id': 0,
    'feature_ids': [0, 1, 3, 4],
    'degree': 1,
    'knot_vecs': np.array([[5.0, 3.5, 3.0],
                           [0.0, 1.0, 4.0],
                           [-3.5, 0.0, 1.0],
                           [0.0, -2.0, 0.0]]),
    'weights': np.array([[5.0, 3.5],
                         [0.0, 1.0],
                         [-3.5, 0.0],
                         [0.0, -2.0]]),
    'bias': 1.0
}
class fab.model.component.bspline_predict_comp.BSplinePredictionComponent(comp_id, feature_ids, degree, knot_vecs, weights, bias)

Bases: SupervisedComponent

Base class for B-spline non-linear prediction components.

Parameters:
comp_idint

Component ID number.

feature_idslist[int], size = (num_features)

Feature ID number for each feature.

degreeint

Degree of B-spline function.

knot_vecsnp.ndarray, size = (num_features, num_knots)

Knot vector for each feature.

weightsnp.ndarray, size = (num_features, basis_dim)

Weight vector for each feature.

biasfloat

Bias value.

Attributes:
basis_dim

Returns ——- basis_dim : int Dimensionality of a basis function; {num_knots - degree}.

parameter_dim

Returns the parameter dimensionality of the component.

relevant_feature_mask

Returns ——- relevant_feature_mask : np.array(bool), size = (num_features) Flags for each feature whether the weight value is non-zero.

Methods

calc_basis_func_matrices(X)

Calculates the basis function value matrices for all features.

calc_decision_function(X[, B_list])

Calculates the value of decision function.

calc_loglikelihood(X, Y)

Calculates the log-likelihood value for each sample.

from_dict(comp_dict)

Restores the component object from dict information.

predict(X)

Predicts the values based on the decision function and the input feature data.

to_dict()

Generates a dict of information on the component.

property basis_dim
Returns:
basis_dimint

Dimensionality of a basis function; {num_knots - degree}.

calc_basis_func_matrices(X)

Calculates the basis function value matrices for all features.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Returns:
B_listnp.ndarray, size = (num_features, num_samples, basis_dim)

Basis function value matrices for all features.

calc_decision_function(X, B_list=None)

Calculates the value of decision function.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

B_listnp.ndarray or None, optional [default: None]

B-spline basis function value matrices; size = (num_features, num_samples, basis_dim). If it has already been calculated, specify it to reduce computational cost.

Returns:
Y_estnp.array, size = (num_samples)

Calculated value of the decision function for each sample.

property relevant_feature_mask
Returns:
relevant_feature_masknp.array(bool), size = (num_features)

Flags for each feature whether the weight value is non-zero.

class fab.model.component.bspline_predict_comp.BSplineRgComponent(comp_id, feature_ids, degree, knot_vecs, weights, bias, variance)

Bases: BSplinePredictionComponent

B-spline non-linear regression component.

Parameters:
comp_idint

Component ID number.

feature_idslist[int], size = (num_features)

Feature ID number for each feature.

degreeint

Degree of B-spline function.

knot_vecsnp.ndarray, size = (num_features, num_knots)

Knot vector for each feature.

weightsnp.ndarray, size = (num_features, basis_dim)

Weight vector for each feature.

biasfloat

Bias value.

variancefloat

Variance value.

Attributes:
basis_dim

Returns ——- basis_dim : int Dimensionality of a basis function; {num_knots - degree}.

parameter_dim

Returns ——- parameter_dim : int Parameter dimensionality of this component.

relevant_feature_mask

Returns ——- relevant_feature_mask : np.array(bool), size = (num_features) Flags for each feature whether the weight value is non-zero.

Methods

calc_basis_func_matrices(X)

Calculates the basis function value matrices for all features.

calc_decision_function(X[, B_list])

Calculates the value of decision function.

calc_loglikelihood(X, Y)

Calculates the log-likelihood value for each sample.

from_dict(comp_dict)

Restores the component object from dict information.

predict(X)

Predicts the values based on the decision function and the input feature data.

to_dict()

Generates a dict of information on the component.

calc_loglikelihood(X, Y)

Calculates the log-likelihood value for each sample.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Ynp.array, size = (num_samples)

Input target data.

Returns:
loglikelihoodnp.array, size = (num_samples)

Calculated log-likelihood values for all samples.

classmethod from_dict(comp_dict)

Restores the component object from dict information.

Parameters:
comp_dict: dict

Information on the component.

Returns:
component: BSplineRgComponent

An instance of this class in which knot_vecs, weights, bias and variance are set.

Notes

For the format of the dict (comp_dict), refer to an example for to_dict() method.

property parameter_dim
Returns:
parameter_dimint

Parameter dimensionality of this component. It is equal to {the number of nonzero elements in weights} + 2 (bias & variance).

predict(X)

Predicts the values based on the decision function and the input feature data.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Returns:
Y_estnp.array, size = (num_samples)

Predicted values.

to_dict()

Generates a dict of information on the component.

Returns:
comp_dictdict

Information on the component.

Examples

>>> component.to_dict()
{
    'comp_id': 0,
    'feature_ids': [0, 1, 3, 4],
    'degree': 1,
    'knot_vecs': np.array([[5.0, 3.5, 3.0],
                           [0.0, 1.0, 4.0],
                           [-3.5, 0.0, 1.0],
                           [0.0, -2.0, 0.0]]),
    'weights': np.array([[5.0, 3.5],
                         [0.0, 1.0],
                         [-3.5, 0.0],
                         [0.0, -2.0]]),
    'bias': 1.0,
    'variance': 0.5
}
fab.model.component.bspline_predict_comp.calc_bspline_basis_matrices_list(X, knot_vecs, degree)

Calculates basis function value matrices of the B-spline function for all features.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Feature data.

knot_vecsnp.ndarray, size = (num_features, num_knots)

Knot vector for each feature.

degreeint

Degree of B-spline function. Domain = [0, inf).

Returns:
B_listnp.ndarray, size = (num_features, num_samples, basis_dim)

Basis function value matrices for all features. basis_dim = num_knots - degree.

fab.model.component.bspline_predict_comp.calc_bspline_basis_matrix(X, knot_vec, degree)

Calculates a basis function values matrix of the B-spline function from a feature data.

Parameters:
Xnp.array, size = (num_samples)

Feature data for a feature.

knot_vecnp.array, size = (num_knots)

Knot vector for a feature.

degreeint

Degree of B-spline function. Domain = [0, inf).

Returns:
Bnp.ndarray, size = (num_samples, basis_dim)

Basis matrix of the feature. Each column is basis function values for each knot. basis_dim = num_knots - degree.

fab.model.component.comps_loglikelihood module

fab.model.component.comps_loglikelihood.calc_supervised_comps_loglikelihood(comps, X, Y)

Calculates the log-likelihood value for the list of components.

Parameters:
compslist[SupervisedComponent]

The list of the supervised component objects.

Xnp.ndarray, size = (num_samples, num_features)

Input feature data. Note that the features applied to only component data must be given, for example, features for prior’s optimization must be excluded from X.

Ynp.array, size = (num_samples)

Input target data.

Returns:
loglikelihoodnp.ndarray, size = (num_samples, num_comps)

Calculated log-likelihood values for each sample and each component.

fab.model.component.comps_loglikelihood.calc_supervised_comps_loglikelihood_targetwise(comps, X, num_targets)

Calculates the target-wise log-likelihood value for the list of components.

Parameters:
compslist[SupervisedComponent]

The list of the supervised component objects.

Xnp.ndarray, size = (num_samples, num_features)

Input feature data. Note that the features applied to only component data must be given, for example, features for prior’s optimization must be excluded from X.

num_targetsint

The number of targets.

Returns:
loglikelihood_targetwisenp.ndarray,

size = (num_samples, num_comps, num_targets)

Calculated target-wise log-likelihood values for each sample and each component.

fab.model.component.fab_comp module

class fab.model.component.fab_comp.FABComponent(comp_id)

Bases: object

An abstract class for a component.

All components must have parameter dimensionality.

Parameters:
comp_idint

Component ID number.

Attributes:
parameter_dim

Returns the parameter dimensionality of the component.

Methods

from_dict(comp_dict)

Restores the component object from dict information.

to_dict()

Generates a dict of information on the component.

abstract classmethod from_dict(comp_dict)

Restores the component object from dict information.

Parameters:
comp_dict: dict

Information on the component.

Returns:
component: FABComponent

An instance of this class.

abstract property parameter_dim

Returns the parameter dimensionality of the component.

Returns:
parameter_dimint

Parameter dimensionality of this component.

abstract to_dict()

Generates a dict of information on the component.

Returns:
comp_dictdict

Information on the component.

class fab.model.component.fab_comp.SupervisedComponent(comp_id)

Bases: FABComponent

An abstract class for supervised components.

Component classes for supervised learning must have this interface.

Attributes:
parameter_dim

Returns the parameter dimensionality of the component.

Methods

calc_decision_function(X)

Calculates the value of decision function.

calc_loglikelihood(X, Y)

Calculates the log-likelihood value for each sample.

from_dict(comp_dict)

Restores the component object from dict information.

predict(X)

Predicts the values based on the decision function and the input feature data.

to_dict()

Generates a dict of information on the component.

abstract calc_decision_function(X)

Calculates the value of decision function.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Returns:
Y_estnp.array, size = (num_samples)

Calculated value of the decision function for each sample.

abstract calc_loglikelihood(X, Y)

Calculates the log-likelihood value for each sample.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Ynp.array, size = (num_samples)

Input target data.

Returns:
loglikelihoodnp.array, size = (num_samples)

Calculated log-likelihood values for all samples.

abstract predict(X)

Predicts the values based on the decision function and the input feature data.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Returns:
Y_estnp.array, size = (num_samples)

Predicted values.

class fab.model.component.fab_comp.UnsupervisedComponent(comp_id)

Bases: FABComponent

An abstract class for unsupervised components.

Component classes for unsupervised learning must have this interface.

Attributes:
parameter_dim

Returns the parameter dimensionality of the component.

Methods

calc_loglikelihood(X)

Calculates the log-likelihood values.

from_dict(comp_dict)

Restores the component object from dict information.

to_dict()

Generates a dict of information on the component.

abstract calc_loglikelihood(X)

Calculates the log-likelihood values.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Returns:
loglikelihoodnp.array, size = (num_samples)

Calculated log-likelihood values for all samples.

fab.model.component.linear_predict_comp module

class fab.model.component.linear_predict_comp.LeastSquaresRgComponent(comp_id, feature_ids, weights, bias, variance)

Bases: LinearPredictionComponent

Least-squares regression component class.

\[Y = XW + b.\]
Parameters:
comp_idint

Component ID number.

feature_idslist[int], size = (num_features)

Feature ID number for each feature.

weightsnp.array, size = (num_features)

Weight values: W.

biasfloat

Bias value: b.

variancefloat

Variance value assuming univariate distribution around Y.

Attributes:
parameter_dim

Returns parameter dimensionality of this component.

relevant_feature_mask

Returns relevant feature mask.

Methods

calc_decision_function(X)

Calculates the value of decision function according to the weight and bias values:

calc_loglikelihood(X, Y)

Calculates the log-likelihood value for each sample.

from_dict(comp_dict)

Restores the component object from dict information.

predict(X)

Predicts the values based on the decision function and the input feature data.

to_dict()

Generates a dict of information on the component.

calc_loglikelihood(X, Y)

Calculates the log-likelihood value for each sample.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Ynp.array, size = (num_samples,)

Input target data.

Returns:
loglikelihoodnp.array, size = (num_samples)

Calculated log-likelihood values for all samples.

classmethod from_dict(comp_dict)

Restores the component object from dict information.

Parameters:
comp_dict: dict

Information on the component.

Returns:
component: LeastSquaresRgComponent

An instance of this class in which weights, bias and variance are set.

Notes

For the format of the dict (comp_dict), refer to an example for to_dict() method.

property parameter_dim

Returns parameter dimensionality of this component.

Bias (= 1) and variance (= 1) terms are also included.

Returns:
parameter_dimint

Parameter dimensionality of this component. It is equal to the number of nonzero elements in weights + 2.

predict(X)

Predicts the values based on the decision function and the input feature data.

For least-squares regression, predict() is equivalent to calc_decision_function().

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Returns:
Y_estnp.array, size = (num_samples)

Predicted values.

to_dict()

Generates a dict of information on the component.

Returns:
comp_dictdict

Information on the component.

Examples

>>> component.to_dict()
{
    'comp_id': 0,
    'feature_ids': [0, 1, 3, 4],
    'weights': np.array([5.0, 0.0, -3.5, 0.0]),
    'bias': 1.0,
    'variance': 0.5
}
class fab.model.component.linear_predict_comp.LinearPredictionComponent(comp_id, feature_ids, weights, bias)

Bases: SupervisedComponent

Base class for Linear prediction components.

It handles a linear equation:

\[Y = XW + b,\]

where \(X\) is feature data (num_samples, num_features), \(Y\) is decision function for feature data (num_samples).

Parameters:
comp_idint

Component ID number.

feature_idslist[int], size = (num_features)

Feature ID number for each feature.

weightsnp.array, size = (num_features)

Weight values: W.

biasfloat

Bias value: b.

Attributes:
parameter_dim

Returns the parameter dimensionality of the component.

relevant_feature_mask

Returns relevant feature mask.

Methods

calc_decision_function(X)

Calculates the value of decision function according to the weight and bias values:

calc_loglikelihood(X, Y)

Calculates the log-likelihood value for each sample.

from_dict(comp_dict)

Restores the component object from dict information.

predict(X)

Predicts the values based on the decision function and the input feature data.

to_dict()

Generates a dict of information on the component.

calc_decision_function(X)

Calculates the value of decision function according to the weight and bias values:

\[Y = XW + b.\]
Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Returns:
Y_estnp.array, size = (num_samples)

Calculated value of the decision function for each sample.

property relevant_feature_mask

Returns relevant feature mask.

Features whose weights are nonzero are classified as relevant features. The bias terms is always relevant, therefore its flag is not included on the result.

Returns:
relevant_masknp.array(dtype=bool), size = (num_features)

List of flags for all features. If True, the feature is relevant that means the weight value for the feature is nonzero.

class fab.model.component.linear_predict_comp.LogisticRgComponent(comp_id, feature_ids, weights, bias)

Bases: LinearPredictionComponent

Logistic regression component class.

\[Y = \{ 1 + \exp (-Z)\}^{-1},\]

where \(Z = XW + b\).

Parameters:
comp_idint

Component ID number.

feature_idslist[int], size = (num_features)

Feature ID number for each feature.

weightsnp.array, size = (num_features)

Weight values: W.

biasfloat

Bias value: b.

Attributes:
parameter_dim

Returns ——- parameter_dim : int Parameter dimensionality of this component.

relevant_feature_mask

Returns relevant feature mask.

Methods

calc_decision_function(X)

Calculates the value of decision function according to the weight and bias values:

calc_loglikelihood(X, Y)

Calculates the log-likelihood value for each sample.

from_dict(comp_dict)

Restores the component object from dict information.

predict(X)

Predicts the values based on the decision function and the input feature data.

to_dict()

Generates a dict of information on the component.

calc_loglikelihood(X, Y)

Calculates the log-likelihood value for each sample.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Ynp.array, size = (num_samples)

Input target data.

Returns:
loglikelihoodnp.array, size = (num_samples)

Calculated log-likelihood values for all samples.

classmethod from_dict(comp_dict)

Restores the component object from dict information.

Parameters:
comp_dict: dict

Information on the component.

Returns:
component: LogisticRgComponent

An instance of this class in which weights and bias are set.

Notes

For the format of the dict (comp_dict), refer to an example for to_dict() method.

property parameter_dim
Returns:
parameter_dimint

Parameter dimensionality of this component. It is equal to the number of nonzero elements in weights + 1 (bias).

predict(X)

Predicts the values based on the decision function and the input feature data.

For logistic regression, prediction value is either -1.0 or 1.0.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Returns:
Y_estnp.array, size = (num_samples)

Predicted values. The value is either -1.0 or 1.0 for each sample.

to_dict()

Generates a dict of information on the component.

Returns:
comp_dictdict

Information on the component.

Examples

>>> component.to_dict()
{
    'comp_id': 0,
    'feature_ids': [0, 1, 3, 4],
    'weights': np.array([5.0, 0.0, -3.5]),
    'bias': 1.0
}

fab.model.component.softmax_cl_comp module

class fab.model.component.softmax_cl_comp.SoftmaxClComponent(comp_id, feature_ids, weights, bias)

Bases: SupervisedComponent

Softmax classification component class.

\[Y_c = \frac{\exp\{Z_c\}}{\sum_{c}\exp\{Z_c\}}\]

where \(Z_c = XW_c + b_c\) .

Parameters:
comp_idint

Component ID number.

feature_idslist[int], size = (num_features)

Feature ID number for each feature.

weightsnp.ndarray, size = (num_features, num_targets)

Weight values: W.

biasnp.array, size = (num_targets)

Bias values: b.

Attributes:
parameter_dim

Returns ——- parameter_dim : int Parameter dimensionality of this component.

relevant_feature_mask

Returns relevant feature mask.

Methods

calc_decision_function(X)

Calculates the value of decision function according to the weight and bias values:

calc_loglikelihood(X, Y)

Calculates the log-likelihood value for each sample.

calc_loglikelihood_targetwise(X)

Calculates the target-wise log-likelihood value for each sample.

from_dict(comp_dict)

Restores the component object from dict information.

predict(X)

Predicts the values based on the decision function and the input feature data.

to_dict()

Generates a dict of information on the component.

calc_decision_function(X)

Calculates the value of decision function according to the weight and bias values:

\[Y = XW + b.\]
Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Returns:
Y_estnp.ndarray, size = (num_samples, num_targets)

Calculated value of the decision function for each sample.

calc_loglikelihood(X, Y)

Calculates the log-likelihood value for each sample.

The size of (Y == 1) must be equal to Y.shape[0], that means only one element for each sample is 1.0, and others are 0.0.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Ynp.ndarray, size = (num_samples, num_targets)

Input target data.

Returns:
loglikelihoodnp.array, size = (num_samples)

Calculated log-likelihood values for all samples.

calc_loglikelihood_targetwise(X)

Calculates the target-wise log-likelihood value for each sample.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Returns:
loglikelihood_targetwisenp.ndarray,

size = (num_samples, num_targets)

Calculated target-wise log-likelihood values for all samples.

classmethod from_dict(comp_dict)

Restores the component object from dict information.

Parameters:
comp_dict: dict

Information on the component.

Returns:
component: SoftmaxClComponent

An instance of this class in which weights and bias are set.

Notes

For the format of the dict (comp_dict), refer to an example for to_dict() method.

property parameter_dim
Returns:
parameter_dimint

Parameter dimensionality of this component. It is equal to the number of nonzero elements in weights + 1 (bias).

predict(X)

Predicts the values based on the decision function and the input feature data.

For softmax classification, prediction value is either +1.0 or 0.0.

Parameters:
Xnp.ndarray, size = (num_samples, num_features)

Input feature data.

Returns:
Y_estnp.ndarray, size = (num_samples, num_targets)

Predicted values. The value is either +1.0 or 0.0 for each sample.

property relevant_feature_mask

Returns relevant feature mask.

Features whose weights are nonzero are classified as relevant features. The bias terms is always relevant, therefore its flag is not included on the result.

Returns:
relevant_masknp.array(dtype=bool), size = (num_features)

List of flags for all features. If True, the feature is relevant that means the weight value for the feature is nonzero.

to_dict()

Generates a dict of information on the component.

Returns:
comp_dictdict

Information on the component.

Examples

>>> component.to_dict()
{
    'comp_id': 0,
    'feature_ids': [0, 1, 3, 4],
    'weights': np.array([[5.0, 3.5],
                         [0.0, 1.0],
                         [-3.5, 0.0],
                         [0.0, -2.0]]),
    'bias': np.array([1.0, 2.0])
}

Module contents