fab.common package¶
Submodules¶
fab.common.basic_func module¶
- fab.common.basic_func.calc_logistic_func_loglikelihood(Y_est)¶
Calculates the log-likelihood value of the logistic function, -log{1 + exp(-Y_est)}.
For stable numerical computations, the positive and negative sides are separately calculated by the different equations, where are analytically equivalent to each other (exp(x) is applied only in x < 0).
- Parameters:
- Y_estnp.array, size = (num_samples)
The decision function values for all samples.
- Returns:
- loglikelihoodnp.array, size = (num_samples)
The log-likelihood value for each sample.
- fab.common.basic_func.calc_signs(Y)¶
Calculates the sign of Y values.
- Parameters:
- Ynp.array, size = (num_samples)
Values whose signs will be calculated.
- Returns:
- signsnp.array, size = (num_samples)
It means the signs (positive or negative) of Y values as follows: if Y >= 0 then +1; if Y < 0 then -1; otherwise (nan) 0.
- fab.common.basic_func.calc_softmax_func_loglikelihood_targetwise(Y_est)¶
Calculates the log-likelihood value of the logistic function, log{exp(Y_est) / sigm_c(exp(Y_est_c))}.
An equivalent transformed formula is calculated for stable numerical computations: the maximum value of the decision function is subtracted for each sample.
- Parameters:
- Y_estnp.ndarray, size = (num_samples, num_targets)
The target-wise decision function values for all samples.
- Returns:
- loglikelihoodnp.ndarray, size = (num_samples, num_targets)
The target-wise log-likelihood values for each sample.
- fab.common.basic_func.calc_univariate_gauss_loglikelihood(X, X_mean, variance)¶
Calculates the log-likelihood value of the univariate Gaussian distribution.
- Parameters:
- Xnp.array, size = (num_sample)
Input data on which univariate Gaussian log-likelihood values are computed.
- X_meannp.array, size = (num_sample)
Mean values of Gaussian distributions.
- variancefloat
Variance of Gaussian distribution, must be > 0.0.
- Returns:
- loglikelihoodnp.array, size = (num_samples)
The log-likelihood value for each sample.
- fab.common.basic_func.normalize_matrix_row_direction(matrix)¶
Normalizes matrix elements by row.
All elements are normalized so that the summation of elements of each row is equals to 1.0.
If the normalization constant is zero and all values are zero or all values are non-zero, each row element will be set to 1.0 / n, where n is the number of columns.
If the normalization constant is zero and there are zero and nonzero elements, each nonzero element will be set to 1.0 / n, where n is the number of nonzero columns.
- Parameters:
- matrixnp.ndarray, size = (num_rows, num_columns)
Matrix to be normalized.
- Returns:
- None
- fab.common.basic_func.replace_zero_with_epsilon(value)¶
If the value is less than machine epsilon value (minimum but non-zero value), the value is replaced with machine epsilon value.
Only the non-negative values are supported.
- Parameters:
- valuefloat
Any value.
- Returns:
- valuefloat
Equal to the input value when it is larger than machine epsilon. Otherwise, returns machine epsilon value.
Examples
>>> value = 0.0 >>> replace_zero_with_epsilon(value) 2.2204460492503131e-16 >>> value 0.0
- fab.common.basic_func.replace_zero_with_epsilon_array(values)¶
Applies replace_zero_with_epsilon() method to all elements of the array.
Only the non-negative values are supported.
- Parameters:
- valuesnp.array
Array of any value.
- Returns:
- valuesnp.array
Applied on each element; returns the input value when it is larger than machine epsilon. Otherwise, returns machine epsilon value.
Examples
>>> values = np.array([0.0, 1.0, 10.0]) >>> replace_zero_with_epsilon(values) >>> values array([2.22044605e-16, 1.0, 10.0])
- fab.common.basic_func.replace_zeroprob_with_epsilon(value)¶
If the probability is less than machine epsilon value (a very small and non-zero value) or greater than 1.0 - epsilon, the value is replaced with epsilon value or 1.0 - epsilon.
Only the non-negative values are supported.
- Parameters:
- valuefloat
Any value.
- Returns:
- valuefloat
Equal to the input value when (epsilon <= value <= 1.0 - epsilon). Otherwise returns epsilon or 1.0 - epsilon.
Examples
>>> value = 1.0 >>> replace_zeroprob_with_epsilon(value) 0.99999999999999978 >>> value 1.0
fab.common.exception module¶
- exception fab.common.exception.FABAllComponentsShrunkError¶
Bases:
Exception
Exception class for error handling when all components are shrunk.
fab.common.parse_float_value module¶
- fab.common.parse_float_value.parse_float_value(value)¶
Converts argument to float value and a flag of absolute or relative threshold value.
- Parameters:
- valuestr or float
Threshold value. The a percentage character is appended after the numerical value (ex. ‘10.0%’), the value is recognized as a ratio in percentage unit (= 0.10).
- Returns:
- thresholdfloat
Threshold value.
- is_ratiobool
Indicates whether the threshold value is ratio or not.
Examples
>>> parse_float_value(10.0) (10.0, False) >>> parse_float_value(10) (10.0, False) >>> parse_float_value('10.0') (10.0, False) >>> parse_float_value('25.0%') (0.25, True) >>> parse_float_value('50%') (0.5, True)
fab.common.validate_data module¶
- fab.common.validate_data.validate_binary_target_cl_data(Y)¶
Checks whether the binary classification target data values are either 1 or -1.
- Parameters:
- Ynp.array, size = (num_samples)
Target data whose values are checked.
- Returns:
- None
- Raises:
- ValueError
The dimensionality of target data is not 1. Target values are not binary values.
- fab.common.validate_data.validate_feature_data(X)¶
Checks the validity of feature data.
- Parameters:
- Xnp.ndarray, size = (num_samples, num_features)
The feature data whose type and number of samples are checked.
- Returns:
- None
- Raises:
- TypeError
Feature data is not np.ndarray(np.float) or num_dims != 2.
- ValueError
Feature data unexpectedly contains inf/-inf, nan.
- fab.common.validate_data.validate_feature_ids(target_name, feature_ids, accept_ids_empty=False, accept_none=False)¶
Checks the validity of a feature_ids parameter.
- Parameters:
- target_namestr
Target name to be validate.
- feature_idsNone or list[int]
Feature IDs object.
- accept_ids_emptybool, optional [default: False]
If True, no exceptions are raised if feature_ids is empty list ([]).
- accept_nonebool [default: False]
If True, no exceptions are raised if feature_ids is None.
- Returns:
- None
- Raises:
- TypeError
Type of specified feature IDs is unsupported.
- ValueError
Specified feature IDs are out of range.
- fab.common.validate_data.validate_multi_target_cl_data(Y)¶
Checks whether the multiclass classification target data values are either 1 or 0.
- Parameters:
- Ynp.ndarray, size = (num_samples, num_targets)
Target data whose values are checked.
- Returns:
- None
- Raises:
- ValueError
The dimensionality of target data is not 2. The number of targets is invalid value. Target values are not multiclass values. Not only one target which is 1 for each sample.
- fab.common.validate_data.validate_supervised_data(X, Y, num_target_dims=1)¶
Checks the validity of feature data and target data.
- Parameters:
- Xnp.ndarray, size = (num_samples, num_features)
The feature data whose type and the number of samples are checked.
- Ynp.array, size = (num_samples) or
np.ndarray, size = (num_samples, num_targets) The target data whose type and the number of samples are checked.
- num_target_dimsint
Dimensionality of target data.
- Returns:
- None
- Raises:
- TypeError
Data are not np.ndarray(np.float). The dimensionality of feature data is not 2. The dimensionality of target data is not specified value: 1 or 2.
- ValueError
Feature and target data unexpectedly contain inf/-inf, nan. The number of feature and target data samples are inconsistent.
- fab.common.validate_data.validate_target_data(Y, num_dims)¶
Checks the validity of target data.
- Parameters:
- Ynp.array, size = (num_samples) or
np.ndarray, size = (num_samples, num_targets) The target data whose type is checked.
- num_dimsint
Dimensionality of target data.
- Returns:
- None
- Raises:
- TypeError
Target data is not np.ndarray(np.float). The dimensionality of target data is not specified value: 1 or 2.
- ValueError
Target data unexpectedly contains inf/-inf, nan.
fab.common.validate_params module¶
- fab.common.validate_params.validate_bias_scale(bias_min_scale, bias_max_scale, target_name=None)¶
Checks the validity of parameters for generating a random bias value.
Domain = (-inf, inf). and bias_min_scale < bias_max_scale.
- Parameters:
- target_name{‘’, ‘gate’, ‘comp’}
Target name prefix for the error message strings.
- bias_min_scale, bias_max_scalefloat
The minimum and maximum scales for the bias.
- Returns:
- None
- Raises:
- TypeError
The parameter type is incorrect.
- ValueError
The value is out of range.
- fab.common.validate_params.validate_fab_stop_threshold(value)¶
Checks the validity of a fab-stop-threshold value.
Type = {float, str}. Domain = (0, inf) for both absolute and percentage values.
- Parameters:
- valuefloat or str
The value to be validated.
- Returns:
- None
- Raises:
- ValueError
The specified fab_stop_threshold is out of range.
- fab.common.validate_params.validate_shrink_threshold(value)¶
Checks the validity of a shrink-threshold value.
Type = {float, str}. Domain = [1, inf) for absolute values, or (0, 1) for for percentage values.
- Parameters:
- valuefloat or str
The value to be validated.
- Returns:
- None
- Raises:
- TypeError
The specified value type is not supported.
- ValueError
The specified value is out of range.
- fab.common.validate_params.validate_variance_scale(variance_min_scale, variance_max_scale, target_name=None)¶
Checks the validity of parameters for generating random variance values.
Domain = (0, inf). and variance_min_scale < variance_max_scale.
- Parameters:
- target_name{‘’, ‘comp’}
Target name prefix for the error message strings.
- variance_min_scale, variance_max_scalefloat
The minimum and maximum scales for the variance.
- Returns:
- None
- Raises:
- TypeError
The parameter type is incorrect.
- ValueError
The value is out of range.
- fab.common.validate_params.validate_weights_scale(weights_min_scale, weights_max_scale, target_name=None)¶
Checks the validity of parameters for generating random weight values.
Domain = (-inf, inf). and weights_min_scale < weights_max_scale.
- Parameters:
- target_name{‘’, ‘gate’, ‘comp’}
Target name prefix for the error message strings.
- weights_min_scale, weights_max_scalefloat
The minimum and maximum scales for the weights.
- Returns:
- None
- Raises:
- TypeError
The parameter type is incorrect.
- ValueError
The value is out of range.
fab.common.validate_utils module¶
- fab.common.validate_utils.is_integer(value)¶
Checks whether the value is integer.
- Parameters:
- valueint
The value to be checked whether it is an integer or not.
- Returns:
- is_integerbool
If True, the value is an integer. Bool values are judged to return False.
- fab.common.validate_utils.is_real(value)¶
Checks whether the value is a real number.
- Parameters:
- valuefloat or int
The value to be checked whether it is a real number or not.
- Returns:
- is_realbool
If True, the value is a real number. Bool values are judged to return False.
- fab.common.validate_utils.validate_bool(target_name, value, accept_none=False)¶
Checks whether the value is a bool value.
- Parameters:
- target_namestr
Name of the target whose value will be checked.
- valuebool
The value to be checked whether it is boolean or not.
- accept_nonebool [default: False]
If True, no exceptions are raised if value is None.
- Returns:
- None
- Raises:
- TypeError
Value type is not boolean
- fab.common.validate_utils.validate_dict(target_name, value, expected_keys=None, accept_none=False)¶
Checks whether the value is a dict value and the keys of value are same as expected keys.
- Parameters:
- target_namestr
Name of the target whose value will be checked.
- valuedict
The value to be checked whether its keys are same as the expected keys.
- expected_keyslist [default: None]
List of expected keys. If None, the value is not checked whether the keys of value are same as expected keys.
- accept_nonebool [default: False]
If True, no exceptions are raised if value is None.
- Returns:
- None
- Raises:
- TypeError
The specified value type is not supported.
- ValueError
The specified value is not in expected values.
- fab.common.validate_utils.validate_finite_real(target_name, value, start=None, start_equals=True, end=None, end_equals=True, accept_inf=False, accept_none=False)¶
Checks whether the value is a finite real value and is within the range of possible values.
The set of real numbers includes integer and float values.
- Parameters:
- target_namestr
Name of the target whose value will be checked.
- valuefloat or int
The value to be checked whether it is within the range.
- start, endfloat or None [default: None]
The lower and upper boundary of the value. If None, no boundary.
- start_equals, end_equalsbool [default: True]
If True, the bound is a closed boundary.
- accept_infbool [default: False]
If True, no exceptions are raised if value is inf/-inf.
- accept_nonebool [default: False]
If True, no exceptions are raised if value is None.
- Returns:
- None
- Raises:
- TypeError
The specified value type is not supported.
- ValueError
The specified value is out of range.
- fab.common.validate_utils.validate_float_numpy_array(target_name, value, expected_shape=None, accept_empty=False, accept_inf=False, accept_nan=False, accept_none=False)¶
Checks whether the value is a numpy array value. The value shape is same as the expected shape and it contains valid value.
- Parameters:
- target_namestr
Name of the target whose value will be checked.
- valuenp.array
The value to be checked whether its shape is same as the expected shape and it contains valid value.
- expected_shapetuple [default: None]
The expected shape. If None, the value is not checked whether the shape of value same as expected shape.
- accept_infbool [default: False]
If True, no exceptions are raised if value contain inf/-inf.
- accept_nanbool [default: False]
If True, no exceptions are raised if value contain nan.
- accept_nonebool [default: False]
If True, no exceptions are raised if value is None.
- Returns:
- None
- Raises:
- TypeError
The specified value type is not supported. The specified data type of value is not supported. The specified value shape is not supported.
- ValueError
The specified value are out of range.
- fab.common.validate_utils.validate_int(target_name, value, start=None, start_equals=True, end=None, end_equals=True, accept_none=False)¶
Checks whether the value is an integer value and is within the range of possible integer values.
- Parameters:
- target_namestr
Name of the target whose value will be checked.
- valueint
The value to be checked whether it is within the range.
- start, endint or None [default: None]
The lower and upper boundary of the value. If None, no boundary.
- start_equals, end_equalsbool [default: True]
If True, the bound is a closed boundary.
- accept_nonebool [default: False]
If True, no exceptions are raised if value is None.
- Returns:
- None
- Raises:
- ValueError
The specified value is out of range.
- fab.common.validate_utils.validate_str(target_name, value, expected_values=None, accept_none=False)¶
Checks whether the value is a string value and is within expected values.
- Parameters:
- target_namestr
Name of the target whose value will be checked.
- valuestr
The value to be checked whether it is within expected values.
- expected_valueslist[str] [default: None]
List of expected values. If None, the value is not checked whether the value is within expected values.
- accept_nonebool [default: False]
If True, no exceptions are raised if value is None.
- Returns:
- None
- Raises:
- TypeError
The specified value type is not supported.
- ValueError
The specified value is not in expected values.
fab.common.warn_model_properties module¶
- fab.common.warn_model_properties.warn_mandatory_features_irrelevant(comps, mandatory_feature_mask)¶
Logs warning for unexpectedly irrelevant features which are specified as the mandatory features.
- Parameters:
- compsList[LinearPredictionComponent or BSplinePredictionComponent]
List of components whose parameters are checked.
- mandatory_feature_masknp.array(bool), size = (num_features)
The mask of the mandatory relevant features for component.
- Returns:
- None