utils.adjust_hyperbox

The hbbrain.utils.adjust_hyperbox submodule implements various functions for hyperbox adjustment, e.g., hyperbox overlap test, overlap resolving, and hyperbox contraction.

hbbrain.utils.adjust_hyperbox.hyperbox_contraction_efmnn(V, W, case_contraction, id_extended_box, id_tested_box, alpha=1e-05)[source]

Adjust the coordinates of two hyperboxes for overlap resolving corresponding to nine overlap test cases.

Parameters:
Varray-like of shape (n_hyperboxes, n_features)

Lower bounds (minimum points) of all existing hyperboxes in the trained model.

Warray-like of shape (n_hyperboxes, n_features)

Upper bounds (maximum points) of all existing hyperboxes in the trained model.

case_contractiona list of two elements

This is a special struct which is the outcomes of the hyperbox_overlap_test_efmnn function to determine the overlap test case and corresponding overlapped dimension.

id_extended_boxint

id_extended_boxex of the extended hyperbox which needs to test for overlap.

id_tested_boxint

id_extended_boxex of the hyperbox to test for overlap with the extended hyperbox.

alphafloat

A very small value is used to avoid the overlap between two hyperboxes after contraction.

Returns:
Voutarray-like of shape (n_hyperboxes, n_features)

Lower bounds (minimum points) of all existing hyperboxes with two hyperboxes adjusted.

Woutarray-like of shape (n_hyperboxes, n_features)

Upper bounds (maximum points) of all existing hyperboxes with two hyperboxes adjusted.

hbbrain.utils.adjust_hyperbox.hyperbox_contraction_fmnn(V, W, case_contraction, id_extended_box, id_tested_box, alpha=1e-05)[source]

Adjust the coordinates of two hyperboxes for overlap resolving.

Parameters:
Varray-like of shape (n_hyperboxes, n_features)

Lower bounds (minimum points) of all existing hyperboxes in the trained model.

Warray-like of shape (n_hyperboxes, n_features)

Upper bounds (maximum points) of all existing hyperboxes in the trained model.

case_contractiona list of two elements

This is a special struct which is the outcomes of the hyperbox_overlap_test_fmnn() function to determine the overlap test case and corresponding overlapped dimension.

id_extended_boxint

id_extended_boxex of the extended hyperbox which needs to test for overlap.

id_tested_boxint

id_extended_boxex of the hyperbox to test for overlap with the extended hyperbox.

alphafloat, optional, default=0.00001

A very small value is used to avoid the overlap between two hyperboxes after contraction.

Returns:
Voutarray-like of shape (n_hyperboxes, n_features)

Lower bounds (minimum points) of all existing hyperboxes with two hyperboxes adjusted.

Woutarray-like of shape (n_hyperboxes, n_features)

Upper bounds (maximum points) of all existing hyperboxes with two hyperboxes adjusted.

hbbrain.utils.adjust_hyperbox.hyperbox_contraction_freq_cat_gfmm(Ei, Fi, case_contraction)[source]

Perform hyperbox contraction in categorical features for a given hyperbox.

Parameters:
Eiarray-like of shape (n_cat_features,)

Lower bounds for categorical features of the hyperbox which need to do contraction.

Fiarray-like of shape (n_cat_features,)

Upper bounds for categorical features of the hyperbox which need to do contraction.

case_contractiona list of two elements

This is a special struct which is the outcomes of the hyperbox_overlap_test_freq_cat_gfmm() function to determine the overlap test case and corresponding overlapped dimension for categorical features.

Returns:
E_outarray-like of shape (n_cat_features, )

Lower bounds for categorical features of the hyperboxes contracted.

F_outarray-like of shape (n_cat_features, )

Upper bounds for categorical features of the hyperboxes contracted.

hbbrain.utils.adjust_hyperbox.hyperbox_contraction_rfmnn(V, W, C, ids_parent_box, id_child_box, overlap_dim, scale=0.001)[source]

Adjusting or splitting min-max points of overlaping clusters in the refined fuzzy min-max neural network classifier. The detailed information of this procedure can be found in [1].

Parameters:
Varray-like of shape (n_hyperboxes, n_features)

Lower bounds (minimum points) of all existing hyperboxes in the trained model.

Warray-like of shape (n_hyperboxes, n_features)

Upper bounds (minimum points) of all existing hyperboxes in the trained model.

Carray-like of shape (n_hyperboxes,)

Class labels of all existing hyperboxes.

ids_parent_boxarray-like of shape (n_parent_hyperboxes,)

List of indices of parent hyperboxes fully containing the child hyperbox.

id_child_boxint

Index of a child hyperbox fully contained in parent hyperboxes

overlap_dimarray-like of shape (n_parent_hyperboxes,)

The overlapped dimensions between parent hyperboxes and the child hyperbox need to make contraction.

scalefloat, optional, default=0.001

A buffer value is used to avoid overlap on the edges between hyperboxes after contraction

Returns:
Voutarray-like of shape (n_hyperboxes, n_features)

Lower bounds (minimum points) of all existing hyperboxes after doing contraction.

Woutarray-like of shape (n_hyperboxes, n_features)

Upper bounds (minimum points) of all existing hyperboxes after doing contraction.

Coutarray-like of shape (n_hyperboxes,)

Class labels of all existing hyperboxes after doing contraction.

References

[1]

O. N. Al-Sayaydeh, M. F. Mohammed, E. Alhroob, H. Tao, and C. P. Lim, “A refined fuzzy min–max neural network with new learning procedures for pattern classification,” IEEE Transactions on Fuzzy Systems, vol. 28, no. 10, pp. 2480-2494, 2019.

hbbrain.utils.adjust_hyperbox.hyperbox_overlap_test_efmnn(V, W, id_extended_box, id_tested_box, X)[source]

Check the overlap of two input hyperboxes

Parameters:
Varray-like of shape (n_hyperboxes, n_features)

Lower bounds (minimum points) of all existing hyperboxes in the trained model.

Warray-like of shape (n_hyperboxes, n_features)

Upper bounds (maximum points) of all existing hyperboxes in the trained model.

id_extended_boxint

Index of the extended hyperbox which needs to test for overlap.

id_tested_boxint

Index of the hyperbox to test for overlap with the extended hyperbox.

Xarray-like of shape (n_features, )

Current input sample leads to the extension of the existing hyperbox (only be used for contraction case 9)

Returns:
dimlist with two integer elements

The first element contains the overlap test case which two hyperboxes overlap with each other. The second element contains the corresponding dimension where two hyperboxes overlap with each other.

hbbrain.utils.adjust_hyperbox.hyperbox_overlap_test_fmnn(V, W, id_extended_box, id_tested_box)[source]

Check the overlap of two input hyperboxes

Parameters:
Varray-like of shape (n_hyperboxes, n_features)

Lower bounds (minimum points) of all existing hyperboxes in the trained model.

Warray-like of shape (n_hyperboxes, n_features)

Upper bounds (maximum points) of all existing hyperboxes in the trained model.

id_extended_boxint

id_extended_boxex of the extended hyperbox which needs to test for overlap.

id_tested_boxint

id_extended_boxex of the hyperbox to test for overlap with the extended hyperbox.

Returns:
dimlist with two integer elements

The first element contains the overlap test case which two hyperboxes overlap with each other. The second element contains the corresponding dimension where two hyperboxes overlap with each other.

hbbrain.utils.adjust_hyperbox.hyperbox_overlap_test_freq_cat_gfmm(E, F, id_extended_box, id_tested_box, X_cat, similarity_of_cat_vals, cat_overlap_resolved_hyperbox_id)[source]

Test overlap in categorical features between two input hyperboxes.

Parameters:
Earray-like of shape (n_hyperboxes, n_cat_features)

Lower bounds for categorical features of all existing hyperboxes.

Farray-like of shape (n_hyperboxes, n_cat_features)

Upper bounds for categorical features of all existing hyperboxes.

id_extended_boxint

Index of the extended hyperbox which needs to test for overlap.

id_tested_boxint

Index of the hyperbox to test for overlap with the extended hyperbox.

X_catarray-like of shape (n_samples, n_cat_features)

Categorical features of all training data.

similarity_of_cat_valsarray-like of shape (n_cat_features,)

An array stores all similarity values among all pairs of categorical values for each categorical feature index. Each element in this array is an dictionary with keys being a hashed value of two categorical values and values of this dictionary being a similarity value.

cat_overlap_resolved_hyperbox_ida list of int

Indices of hyperboxes overlapping with the extended hyperbox but the overlapping regions among them were resolved by changing values on only categorical features. When replacing an overlap area by other values, we are not allowed to create the overlapping regions with the hyperboxes having indices stored in this list.

Returns:
dima list of two element in the form of [dimension, replaced values]

If this list is empty, there is no overlapping area among categorical features in two hyperboxes. Otherwise, this list shows the categorical dimension where the overlap occurs. If the first element in this list (dimension) gets the value of -1, it means that there is an overlapping region but we cannot find a suitable value to replace for any dimension to resolve the overlap in the categorical features. The second element in this list contains two new values for lower and upper bounds in the categorical dimension shown in dimension. If the second value of this list is None, then no change happens in the bounds in that categorical dimension.

hbbrain.utils.adjust_hyperbox.is_overlap_cat_features_one_by_one(E1, F1, E2, F2)[source]

Check whether all categorical features of two input hyperboxes repsented by lower bounds E1, E2 and upper bounds F1, F2 overlap with each other.

Parameters:
E1array-like of shape (n_cat_features, )

Lower bound for categorical features of the first hyperbox.

F1array-like of shape (n_cat_features, )

Upper bound for categorical features of the first hyperbox.

E2array-like of shape (n_cat_features, )

Lower bound for categorical features of the second hyperbox.

F2array-like of shape (n_cat_features, )

Upper bound for categorical features of the second hyperbox.

Returns:
bool

True if all categorical features in bounds overlap with each other. Otherwise, return False.

hbbrain.utils.adjust_hyperbox.is_overlap_cat_features_one_vs_many(E1, F1, E, F, tested_box_ids=[])[source]

Check for overlap in categorical features between an input hyperbox and a list of existing hyperboxes.

Parameters:
E1array-like of shape (n_cat_features, )

Lower bound for categorical features of the hyperbox which needs to check for overlap.

F1array-like of shape (n_cat_features, )

Upper bound for categorical features of the hyperbox which needs to check for overlap.

Earray-like of shape (n_hyperboxes, n_cat_features)

Lower bounds for categorical features of all existing hyperboxes.

Farray-like of shape (n_hyperboxes, n_cat_features)

Upper bounds for categorical features of all existing hyperboxes.

tested_box_idsa list of int, optional, default=[]

The indices of existing hyperboxes with which the input hyperbox needs to check overlap.

Returns:
bool

Return True if the categorical features of the input hyperbox overlap with any existing hyperboxes that are checked for.

hbbrain.utils.adjust_hyperbox.is_overlap_diff_labels_num_data_rfmnn(V, W, V_cmp, W_cmp, find_dim_min_overlap=True)[source]

Check whether there is any overlapping region between the hyperbox represented by minimum point V_cmp and maximum point W_cmp and any hyperbox in the existing list of hyperboxes belonging to other classes. The detailed information of this procedure can be found in [1].

Parameters:
Varray-like of shape (n_hyperboxes, n_features)

Lower bounds (minimum points) of hyperboxes representing other classes compared to V_cmp.

Warray-like of shape (n_hyperboxes, n_features)

Upper bounds (maximum points) of hyperboxes representing other classes compared to W_cmp.

V_cmparray-like of shape (n_features,)

Minimum point of the compared hyperbox.

W_cmparray-like of shape (n_features,)

Maximum point of the compared hyperbox.

find_dim_min_overlapboolean, optional, default=True

If True, then find the dimension causing the minimum overlap between the hyperbox [V_cmp, W_cmp] and any hyperboxes in the list of hyperboxes represented by [V, W]. Otherwise, only test whether there is any existing overlap zone.

Returns:
if find_dim_min_overlap == False:

return False - no overlap, True - overlap

else:
return:
  • is_overlap: False - no overlap, True - overlap

  • hyperbox_ids_overlap: indices of hyperboxes overlap with [V_cmp, W_cmp] - numpy array

  • min_overlap_dimension: dimension with minimum overlap value > 0 corresponding to hyperboxes with id located in hyperbox_id_overlap

if is_overlap == False:

hyperbox_ids_overlap = min_overlap_dimension = None

References

[1]

O. N. Al-Sayaydeh, M. F. Mohammed, E. Alhroob, H. Tao, and C. P. Lim, “A refined fuzzy min–max neural network with new learning procedures for pattern classification,” IEEE Transactions on Fuzzy Systems, vol. 28, no. 10, pp. 2480-2494, 2019.

hbbrain.utils.adjust_hyperbox.is_overlap_one_many_diff_label_hyperboxes_mixed_data_general(V, W, D, N_samples, V_cmp, W_cmp, D_cmp, N_samples_cmp)[source]

Check whether an input hyperbox overlaps with any hyperboxes representing different classes with the input hyperbox

Parameters:
Varray-like of shape (n_hyperboxes, n_continuous_features)

Lower continuous bounds (minimum points) of hyperboxes representing other classes compared to V_cmp.

Warray-like of shape (n_hyperboxes, n_continuous_features)

Upper continuous bounds (maximum points) of hyperboxes representing other classes compared to W_cmp.

Darray-like of shape (n_hyperboxes, n_cat_features)

A matrix stores a special structure for categorical features of all hyperboxes representing other classes compared to D_cmp. Each element in D stores a set of symbolic values with their cardinalities for the j-th categorical dimension of a given hyperbox.

N_samplesarray-like of shape (n_hyperboxes, )

A vector save the number of samples contained in each hyperbox stored in the lists of V, W, D

V_cmparray-like of shape (n_continuous_features,)

Minimum point of the compared hyperbox.

W_cmparray-like of shape (n_continuous_features,)

Maximum point of the compared hyperbox.

D_cmparray-like of shape (n_cat_features,)

Categorical bound of the compared hyperbox. It contains a set of symbolic values with their cardinalities for the j-th categorical dimension of the compared hyperbox.

N_samples_cmpint

A scalar storing the number of hyperboxes included in the hyperbox represented by [V_cmp, W_cmp, D_cmp]

Returns:
bool

Show if the input hyperbox overlaps with any hyperbox in the list of hyperboxes representing the classes other than the input hyperbox.

hbbrain.utils.adjust_hyperbox.is_overlap_one_many_diff_label_hyperboxes_num_data_general(V, W, V_cmp, W_cmp)[source]

Check whether an input hyperbox overlaps with any hyperboxes representing different classes with the input hyperbox

Parameters:
Varray-like of shape (n_hyperboxes, n_features)

Lower bounds (minimum points) of hyperboxes representing other classes compared to V_cmp.

Warray-like of shape (n_hyperboxes, n_features)

Upper bounds (maximum points) of hyperboxes representing other classes compared to W_cmp.

V_cmparray-like of shape (n_features,)

Minimum point of the compared hyperbox.

W_cmparray-like of shape (n_features,)

Maximum point of the compared hyperbox.

Returns:
bool

Show if the input hyperbox overlaps with any hyperbox in the list of hyperboxes representing the classes other than the input hyperbox.

hbbrain.utils.adjust_hyperbox.is_overlap_one_many_hyperboxes_num_data_general(V, W, C, id_box)[source]

Check overlap between the hyperbox at the position id_box and remaning hyperboxes in the current list.

Note

The current input list of hyperboxes contains all existing hyperboxes including the hyperboxes representing the same class as the hyperbox at the position id_box. Therefore, to perform overlap testing, the list of hyperboxes representing the class labels other than the class label of the id_box-th hyperbox should be first filtered. Finally, the overlap test is only conducted on this filtered list.

Parameters:
Varray-like of shape (n_hyperboxes, n_features)

Lower bounds (minimum points) of all existing hyperboxes in the trained model.

Warray-like of shape (n_hyperboxes, n_features)

Upper bounds (minimum points) of all existing hyperboxes in the trained model.

Carray-like of shape (n_hyperboxes,)

Class labels of all existing hyperboxes.

id_boxint

id_extended_boxex of the hyperbox to be checked for overlap.

Returns:
bool

Show if the input hyperbox overlaps with any hyperbox in the list of hyperboxes representing the classes other than its class label.

hbbrain.utils.adjust_hyperbox.is_two_hyperboxes_overlap_num_data_free_range_general(Vi, Wi, Vk, Wk)[source]

Check if two hyperboxes Bi and Bk overlap with each other or not. This function uses a general formula concerning the determination of an hyperbox within the overlaping region. If this hyperbox exists for all dimensions, two hyperboxes Bi and Bk overlap, else no overlap occurs.

Parameters:
Viarray-like of shape (n_features,)

Minimum coordinate of the hyperbox Bi.

Wiarray-like of shape (n_features,)

Maximum coordinate of the hyperbox Bi.

Vkarray-like of shape (n_features,)

Minimum coordinate of the hyperbox Bk.

Wkarray-like of shape (n_features,)

Maximum coordinate of the hyperbox Bk.

Returns:
is_overlapboolean

Show if two hyperboxes Bi and Bk overlap or not.

hbbrain.utils.adjust_hyperbox.is_two_hyperboxes_overlap_num_data_general(Vi, Wi, Vk, Wk)[source]

Check if two hyperboxes Bi and Bk overlap with each other or not. This function uses a general formula built from a shortest gap-based similarity measure. If this measure returns a value of 1, it means that these two hyperboxes overlap with each other. Otherwise, two hyperboxes Bi and Bk do not overlap. See the references [1] and [2] for more details.

Parameters:
Viarray-like of shape (n_features,)

Minimum coordinate of the hyperbox Bi.

Wiarray-like of shape (n_features,)

Maximum coordinate of the hyperbox Bi.

Vkarray-like of shape (n_features,)

Minimum coordinate of the hyperbox Bk.

Wkarray-like of shape (n_features,)

Maximum coordinate of the hyperbox Bk.

Returns:
is_overlapboolean

Show if two hyperboxes Bi and Bk overlap or not.

References

For more details regarding the way of checking the overlap between two hyperboxes, please see the following articles:

[1]

B. Gabrys, “Agglomerative learning algorithms for general fuzzy min-max neural network,” Journal of VLSI signal processing systems for signal, image and video technology, vol. 32, no. 1, pp. 67-82, 2002.

[2]

T.T. Khuat and B. Gabrys, “An Online Learning Algorithm for a Neuro-Fuzzy Classifier with Mixed-Attribute Data,” ArXiv Preprint, no. arXiv:2009.14670, 2020.

hbbrain.utils.adjust_hyperbox.overlap_resolving_num_data(Vi, Wi, ci, Vk, Wk, ck, alpha=1e-05)[source]

Resolve overlap between two hyperboxes Bi and Bk with coordinates being numerical features. For more details regarding the way of contracting two overlapping hyperboxes, please see the article [1]:

Parameters:
Viarray-like of shape (n_features,)

Minimum coordinate of the hyperbox Bi.

Wiarray-like of shape (n_features,)

Maximum coordinate of the hyperbox Bi.

ciint

Class label of the hyperbox Bi.

Vkarray-like of shape (n_features,)

Minimum coordinate of the hyperbox Bk.

Wkarray-like of shape (n_features,)

Maximum coordinate of the hyperbox Bk.

ckint

Class label of the hyperbox Bk.

alphafloat, optional, default=0.00001

A very small value is used to avoid the overlap between two hyperboxes after contraction.

Returns:
Viarray-like of shape (n_features,)

Minimum coordinate of the hyperbox Bi after contraction.

Wiarray-like of shape (n_features,)

Maximum coordinate of the hyperbox Bi after contraction.

Vkarray-like of shape (n_features,)

Minimum coordinate of the hyperbox Bk after contraction.

Wkarray-like of shape (n_features,)

Maximum coordinate of the hyperbox Bk after contraction.

References

[1]

T.T. Khuat and B. Gabrys, “Accelerated learning algorithms of general fuzzy min-max neural network using a novel hyperbox selection rule,” Information Sciences, vol. 547, pp. 887-909, 2021.

hbbrain.utils.adjust_hyperbox.overlap_resolving_num_data_free_range(Vi, Wi, ci, Vk, Wk, ck, alpha=1e-05)[source]

Resolve overlap between two hyperboxes Bi and Bk with coordinates being numerical features with unlimited ranges. For more details regarding the way of contracting two overlapping hyperboxes, please see [1].

Parameters:
Viarray-like of shape (n_features,)

Minimum coordinate of the hyperbox Bi.

Wiarray-like of shape (n_features,)

Maximum coordinate of the hyperbox Bi.

ciint

Class label of the hyperbox Bi.

Vkarray-like of shape (n_features,)

Minimum coordinate of the hyperbox Bk.

Wkarray-like of shape (n_features,)

Maximum coordinate of the hyperbox Bk.

ckint

Class label of the hyperbox Bk.

alphafloat

A very small value is used to avoid the overlap between two hyperboxes after contraction.

Returns:
Viarray-like of shape (n_features,)

Minimum coordinate of the hyperbox Bi after contraction.

Wiarray-like of shape (n_features,)

Maximum coordinate of the hyperbox Bi after contraction.

Vkarray-like of shape (n_features,)

Minimum coordinate of the hyperbox Bk after contraction.

Wkarray-like of shape (n_features,)

Maximum coordinate of the hyperbox Bk after contraction.

References

[1]

T.T. Khuat and B. Gabrys, “Accelerated learning algorithms of general fuzzy min-max neural network using a novel hyperbox selection rule,” Information Sciences, vol. 547, pp. 887-909, 2021.