evorbf.core package¶
evorbf.core.advanced_rbf module¶
- class evorbf.core.advanced_rbf.AdvancedRbfClassifier(center_finder='random', finder_params=None, rbf_kernel='gaussian', kernel_params=None, reg_lambda=0.1, has_bias=False, seed=42)[source]¶
Bases:
evorbf.core.advanced_rbf.BaseAdvancedRbf,sklearn.base.ClassifierMixinThis class implements an advanced Radial Basis Function (RBF) model specifically designed for classification tasks. It extends the BaseAdvancedRbf and ClassifierMixin classes, adding functionality for handling classification-specific metrics and data processing.
- CLS_OBJ_LOSSES¶
A list of classification objective loss functions supported by the model, such as “CEL”, “HL”, “KLDL”, and “BSL”.
- Type
list
- n_labels¶
The number of unique labels in the target data.
- Type
int
- scores()[source]¶
Computes a list of classification metrics for the given test data and true labels.
- Parameters for Initialization:
center_finder (str): Method for finding RBF centers (default: “random”). finder_params (dict or None): Parameters for the center-finding method (default: None). rbf_kernel (str): Type of RBF kernel to use (default: “gaussian”). kernel_params (dict or None): Parameters for the RBF kernel (default: None). reg_lambda (float): Regularization parameter (default: 0.1). has_bias (bool): Whether to include a bias term in the model (default: False). seed (int): Random seed for reproducibility (default: 42).
- Usage:
Instantiate the class with desired parameters.
Use the fit method to train the model on input features X and target labels y.
Use score, scores, or evaluate to assess the model’s performance.
- CLS_OBJ_LOSSES = ['CEL', 'HL', 'KLDL', 'BSL']¶
- class evorbf.core.advanced_rbf.AdvancedRbfNet(center_finder='random', finder_params=None, rbf_kernel='gaussian', kernel_params=None, reg_lambda=0.1, has_bias=False, seed=42)[source]¶
Bases:
objectImplements an advanced Radial Basis Function (RBF) network for supervised learning tasks.
This class provides a highly customizable RBF network with support for different kernel functions, center-finding strategies, regularization, and optional bias terms. It can be used for both regression and classification problems.
- SUPPORT_KERNELS¶
A dictionary of supported RBF kernel functions and their corresponding implementations. Options include:
“gaussian”: Gaussian kernel
“multiquadric”: Multiquadric kernel
“inverse_multiquadric”: Inverse multiquadric kernel
“linear”: Linear kernel
- Type
dict
- SUPPORT_CENTER_FINDERS¶
A dictionary of supported center-finding methods and their corresponding implementations. Options include:
“random”: Random center finder
“kmeans”: K-Means clustering
“meanshift”: Mean-Shift clustering
“dbscan”: DBSCAN clustering
- Type
dict
- reg_lambda¶
L2 regularization strength (default is 0.1). If reg_lambda=0, no regularization is applied.
- Type
float
- has_bias¶
Whether to include a bias term in the output layer (default is False).
- Type
bool
- seed¶
Random seed for reproducibility.
- Type
int
- centers¶
Array of RBF centers learned during training.
- Type
np.ndarray
- sigmas¶
Width parameters for the RBF functions (if applicable).
- Type
np.ndarray or None
- weights¶
Weights of the output layer learned during training.
- Type
np.ndarray
- bias¶
Bias term learned during training (if has_bias=True).
- Type
float or None
- n_centers¶
Number of centers learned during training.
- Type
int
- __init__(center_finder, finder_params, rbf_kernel, kernel_params, reg_lambda, has_bias, seed)[source]¶
Initializes the RBF network with specified configurations for center finding, kernel functions, and regularization.
- Parameters
center_finder (str or CenterFinder) – Method for finding RBF centers. Options include strings from SUPPORT_CENTER_FINDERS or an instance of a custom CenterFinder class. Default is “random”.
finder_params (dict, optional) – Hyperparameters for the center-finding method. Defaults to {“n_centers”: 10}.
rbf_kernel (str or Kernel) – RBF kernel function to use. Options include strings from SUPPORT_KERNELS or an instance of a custom Kernel class. Default is “gaussian”.
kernel_params (dict, optional) – Hyperparameters for the RBF kernel function. Default is None.
reg_lambda (float) – L2 regularization strength. Default is 0.1.
has_bias (bool) – Whether to include a bias term in the output layer. Default is False.
seed (int) – Random seed for reproducibility. Default is 42.
- Raises
ValueError – If an unsupported center-finding or kernel method is provided.
ValueError – If reg_lambda is not a float or None.
Example
>>> import numpy as np >>> from evorbf import AdvancedRbfNet >>> X = np.random.rand(100, 2) >>> y = np.sin(X[:, 0]) + np.cos(X[:, 1]) >>> rbf_net = AdvancedRbfNet(center_finder="kmeans", rbf_kernel="gaussian", reg_lambda=0.01, has_bias=True) >>> rbf_net.fit(X, y) >>> predictions = rbf_net.predict(X)
- SUPPORT_CENTER_FINDERS = {'dbscan': 'DbscanFinder', 'kmeans': 'KMeansFinder', 'meanshift': 'MeanShiftFinder', 'random': 'RandomFinder'}¶
- SUPPORT_KERNELS = {'gaussian': 'GaussianKernel', 'inverse_multiquadric': 'InverseMultiquadricKernel', 'linear': 'LinearKernel', 'multiquadric': 'MultiquadricKernel'}¶
- class evorbf.core.advanced_rbf.AdvancedRbfRegressor(center_finder='random', finder_params=None, rbf_kernel='gaussian', kernel_params=None, reg_lambda=0.1, has_bias=False, seed=42)[source]¶
Bases:
evorbf.core.advanced_rbf.BaseAdvancedRbf,sklearn.base.RegressorMixinThis class implements an advanced Radial Basis Function (RBF) model tailored for regression problems. It extends the BaseAdvancedRbf and RegressorMixin classes, providing additional methods specific to regression tasks.
- Parameters for Initialization:
center_finder (str): Method for finding RBF centers (default: “random”). finder_params (dict or None): Parameters for the center-finding method (default: None). rbf_kernel (str): Type of RBF kernel to use (default: “gaussian”). kernel_params (dict or None): Parameters for the RBF kernel (default: None). reg_lambda (float): Regularization parameter (default: 0.1). has_bias (bool): Whether to include a bias term in the model (default: False). seed (int): Random seed for reproducibility (default: 42).
- Usage:
Instantiate the class with desired parameters.
Use the fit method to train the model on input features X and targets y.
Use score, scores, or evaluate to assess the model’s performance.
- class evorbf.core.advanced_rbf.BaseAdvancedRbf(center_finder='random', finder_params=None, rbf_kernel='gaussian', kernel_params=None, reg_lambda=0.1, has_bias=False, seed=42)[source]¶
Bases:
sklearn.base.BaseEstimatorThis class serves as a wrapper for an advanced Radial Basis Function (RBF) network, providing utility methods for training, evaluating, and saving the model and its associated data. It extends the BaseEstimator class.
- SUPPORTED_CLS_METRICS¶
Supported classification metrics, obtained from get_all_classification_metrics.
- Type
dict
- SUPPORTED_REG_METRICS¶
Supported regression metrics, obtained from get_all_regression_metrics.
- Type
dict
- CLS_OBJ_LOSSES¶
Classification objective losses (defined by the user or inherited from subclasses).
- Type
list
- score()[source]¶
Computes a primary score (e.g., accuracy for classification or R² for regression) for the provided data.
- Private Methods:
__evaluate_reg: Evaluates regression metrics for given true and predicted values. __evaluate_cls: Evaluates classification metrics for given true and predicted values. __score_reg: Computes a regression score (e.g., R²) for the given data. __scores_reg: Computes multiple regression metrics for the given data. __score_cls: Computes a classification score (e.g., accuracy) for the given data. __scores_cls: Computes multiple classification metrics for the given data.
- Parameters for Initialization:
center_finder (str): Method for finding RBF centers (default: “random”). finder_params (dict or None): Parameters for the center-finding method (default: None). rbf_kernel (str): Type of RBF kernel to use (default: “gaussian”). kernel_params (dict or None): Parameters for the RBF kernel (default: None). reg_lambda (float): Regularization parameter (default: 0.1). has_bias (bool): Whether to include a bias term in the model (default: False). seed (int): Random seed for reproducibility (default: 42).
- CLS_OBJ_LOSSES = None¶
- SUPPORTED_CLS_METRICS = {'AS': 'max', 'BSL': 'min', 'CEL': 'min', 'CKS': 'max', 'F1S': 'max', 'F2S': 'max', 'FBS': 'max', 'GINI': 'min', 'GMS': 'max', 'HL': 'min', 'HS': 'max', 'JSI': 'max', 'KLDL': 'min', 'LS': 'max', 'MCC': 'max', 'NPV': 'max', 'PS': 'max', 'ROC-AUC': 'max', 'RS': 'max', 'SS': 'max'}¶
- SUPPORTED_REG_METRICS = {'A10': 'max', 'A20': 'max', 'A30': 'max', 'ACOD': 'max', 'APCC': 'max', 'AR': 'max', 'AR2': 'max', 'CI': 'max', 'COD': 'max', 'COR': 'max', 'COV': 'max', 'CRM': 'min', 'DRV': 'min', 'EC': 'max', 'EVS': 'max', 'GINI': 'min', 'GINI_WIKI': 'min', 'JSD': 'min', 'KGE': 'max', 'MAAPE': 'min', 'MAE': 'min', 'MAPE': 'min', 'MASE': 'min', 'ME': 'min', 'MRB': 'min', 'MRE': 'min', 'MSE': 'min', 'MSLE': 'min', 'MedAE': 'min', 'NNSE': 'max', 'NRMSE': 'min', 'NSE': 'max', 'OI': 'max', 'PCC': 'max', 'PCD': 'max', 'R': 'max', 'R2': 'max', 'R2S': 'max', 'RAE': 'min', 'RMSE': 'min', 'RSE': 'min', 'RSQ': 'max', 'SMAPE': 'min', 'VAF': 'max', 'WI': 'max'}¶
evorbf.core.base_rbf module¶
- class evorbf.core.base_rbf.BaseNiaRbf(size_hidden=10, center_finder='kmeans', regularization=True, obj_name=None, optim='BaseGA', optim_params=None, verbose=True, seed=None, lb=None, ub=None, mode='single', n_workers=None, termination=None)[source]¶
Bases:
evorbf.core.base_rbf.BaseRbfDefines the most general class for Nature-inspired Algorithm-based RBF models that inherits the BaseRbf class
Note
In this model, the sigmas will be learned during the training process.
So the sigmas parameter is removed in the init function.
Besides, the sigmas is a list of value, each value represent a sigma for Gaussian function used in hidden node.
- Parameters
size_hidden (int, default=10) – The number of hidden nodes
center_finder (str, default="kmeans") – The method is used to find the cluster centers
regularization (bool, default=True) – Determine if L2 regularization technique is used or not. If set to True, then the regularization lambda is learned during the training.
obj_name (None or str, default=None) – The name of objective for the problem, also depend on the problem is classification and regression.
optim (str or instance of Optimizer class (from Mealpy library), default = "BaseGA") – The Metaheuristic Algorithm that use to solve the feature selection problem. Current supported list, please check it here: https://github.com/thieu1995/mealpy. If a custom optimizer is passed, make sure it is an instance of Optimizer class.
optim_params (None or dict of parameter, default=None) – The parameter for the optimizer object. If None, the default parameters of optimizer is used (defined in https://github.com/thieu1995/mealpy.) If dict is passed, make sure it has at least epoch and pop_size parameters.
verbose (bool, default=True) – Whether to print progress messages to stdout.
seed (int, default=None) – The seed value is used for reproducibility.
lb (int, float, tuple, list, np.ndarray, optional) – Lower bounds for sigmas in network.
ub (int, float, tuple, list, np.ndarray, optional) – Upper bounds for sigmas in network.
mode (str, optional) – Mode for optimizer (default is ‘single’).
n_workers (int, optional) – Number of workers for parallel processing in optimizer (default is None).
termination (any, optional) – Termination criteria for optimizer (default is None).
Notes
This class is designed to be easily extended for hybrid metaheuristic-based RBF models.
Metrics can be customized using the Permetrics library: https://github.com/thieu1995/permetrics
- SUPPORTED_CLS_OBJECTIVES = {'AS': 'max', 'BSL': 'min', 'CEL': 'min', 'CKS': 'max', 'F1S': 'max', 'F2S': 'max', 'FBS': 'max', 'GINI': 'min', 'GMS': 'max', 'HL': 'min', 'HS': 'max', 'JSI': 'max', 'KLDL': 'min', 'LS': 'max', 'MCC': 'max', 'NPV': 'max', 'PS': 'max', 'ROC-AUC': 'max', 'RS': 'max', 'SS': 'max'}¶
- SUPPORTED_OPTIMIZERS = ['OriginalABC', 'OriginalACOR', 'AugmentedAEO', 'EnhancedAEO', 'ImprovedAEO', 'ModifiedAEO', 'OriginalAEO', 'MGTO', 'OriginalAGTO', 'DevALO', 'OriginalALO', 'OriginalAO', 'OriginalAOA', 'IARO', 'LARO', 'OriginalARO', 'OriginalASO', 'OriginalAVOA', 'OriginalArchOA', 'AdaptiveBA', 'DevBA', 'OriginalBA', 'DevBBO', 'OriginalBBO', 'OriginalBBOA', 'OriginalBES', 'ABFO', 'OriginalBFO', 'OriginalBMO', 'DevBRO', 'OriginalBRO', 'OriginalBSA', 'ImprovedBSO', 'OriginalBSO', 'CleverBookBeesA', 'OriginalBeesA', 'ProbBeesA', 'OriginalCA', 'OriginalCDO', 'OriginalCEM', 'OriginalCGO', 'DevCHIO', 'OriginalCHIO', 'OriginalCOA', 'OCRO', 'OriginalCRO', 'OriginalCSA', 'OriginalCSO', 'OriginalCircleSA', 'OriginalCoatiOA', 'JADE', 'OriginalDE', 'SADE', 'SAP_DE', 'DevDMOA', 'OriginalDMOA', 'OriginalDO', 'DevEFO', 'OriginalEFO', 'OriginalEHO', 'AdaptiveEO', 'ModifiedEO', 'OriginalEO', 'OriginalEOA', 'LevyEP', 'OriginalEP', 'CMA_ES', 'LevyES', 'OriginalES', 'Simple_CMA_ES', 'OriginalESOA', 'OriginalEVO', 'OriginalFA', 'DevFBIO', 'OriginalFBIO', 'OriginalFFA', 'OriginalFFO', 'OriginalFLA', 'DevFOA', 'OriginalFOA', 'WhaleFOA', 'DevFOX', 'OriginalFOX', 'OriginalFPA', 'BaseGA', 'EliteMultiGA', 'EliteSingleGA', 'MultiGA', 'SingleGA', 'OriginalGBO', 'DevGCO', 'OriginalGCO', 'OriginalGJO', 'OriginalGOA', 'DevGSKA', 'OriginalGSKA', 'Matlab101GTO', 'Matlab102GTO', 'OriginalGTO', 'GWO_WOA', 'IGWO', 'OriginalGWO', 'RW_GWO', 'OriginalHBA', 'OriginalHBO', 'OriginalHC', 'SwarmHC', 'OriginalHCO', 'OriginalHGS', 'OriginalHGSO', 'OriginalHHO', 'DevHS', 'OriginalHS', 'OriginalICA', 'OriginalINFO', 'OriginalIWO', 'DevJA', 'LevyJA', 'OriginalJA', 'DevLCO', 'ImprovedLCO', 'OriginalLCO', 'OriginalMA', 'OriginalMFO', 'OriginalMGO', 'OriginalMPA', 'OriginalMRFO', 'WMQIMRFO', 'OriginalMSA', 'DevMVO', 'OriginalMVO', 'OriginalNGO', 'ImprovedNMRA', 'OriginalNMRA', 'OriginalNRO', 'OriginalOOA', 'OriginalPFA', 'OriginalPOA', 'AIW_PSO', 'CL_PSO', 'C_PSO', 'HPSO_TVAC', 'LDW_PSO', 'OriginalPSO', 'P_PSO', 'OriginalPSS', 'DevQSA', 'ImprovedQSA', 'LevyQSA', 'OppoQSA', 'OriginalQSA', 'OriginalRIME', 'OriginalRUN', 'GaussianSA', 'OriginalSA', 'SwarmSA', 'DevSARO', 'OriginalSARO', 'DevSBO', 'OriginalSBO', 'DevSCA', 'OriginalSCA', 'QleSCA', 'OriginalSCSO', 'ImprovedSFO', 'OriginalSFO', 'L_SHADE', 'OriginalSHADE', 'OriginalSHIO', 'OriginalSHO', 'ImprovedSLO', 'ModifiedSLO', 'OriginalSLO', 'DevSMA', 'OriginalSMA', 'DevSOA', 'OriginalSOA', 'OriginalSOS', 'DevSPBO', 'OriginalSPBO', 'OriginalSRSR', 'DevSSA', 'OriginalSSA', 'OriginalSSDO', 'OriginalSSO', 'OriginalSSpiderA', 'OriginalSSpiderO', 'OriginalSTO', 'OriginalSeaHO', 'OriginalServalOA', 'OriginalTDO', 'DevTLO', 'ImprovedTLO', 'OriginalTLO', 'OriginalTOA', 'DevTPO', 'OriginalTS', 'OriginalTSA', 'OriginalTSO', 'EnhancedTWO', 'LevyTWO', 'OppoTWO', 'OriginalTWO', 'DevVCS', 'OriginalVCS', 'OriginalWCA', 'OriginalWDO', 'OriginalWHO', 'HI_WOA', 'OriginalWOA', 'OriginalWaOA', 'OriginalWarSO', 'OriginalZOA']¶
- SUPPORTED_REG_OBJECTIVES = {'A10': 'max', 'A20': 'max', 'A30': 'max', 'ACOD': 'max', 'APCC': 'max', 'AR': 'max', 'AR2': 'max', 'CI': 'max', 'COD': 'max', 'COR': 'max', 'COV': 'max', 'CRM': 'min', 'DRV': 'min', 'EC': 'max', 'EVS': 'max', 'GINI': 'min', 'GINI_WIKI': 'min', 'JSD': 'min', 'KGE': 'max', 'MAAPE': 'min', 'MAE': 'min', 'MAPE': 'min', 'MASE': 'min', 'ME': 'min', 'MRB': 'min', 'MRE': 'min', 'MSE': 'min', 'MSLE': 'min', 'MedAE': 'min', 'NNSE': 'max', 'NRMSE': 'min', 'NSE': 'max', 'OI': 'max', 'PCC': 'max', 'PCD': 'max', 'R': 'max', 'R2': 'max', 'R2S': 'max', 'RAE': 'min', 'RMSE': 'min', 'RSE': 'min', 'RSQ': 'max', 'SMAPE': 'min', 'VAF': 'max', 'WI': 'max'}¶
- class evorbf.core.base_rbf.BaseRbf(size_hidden=10, center_finder='kmeans', sigmas=2.0, reg_lambda=0.1, seed=None)[source]¶
Bases:
sklearn.base.BaseEstimatorDefines the most general class for RBF network that inherits the BaseEstimator class of Scikit-Learn library.
- Parameters
size_hidden (int, default=10) – The number of hidden nodes
center_finder (str, default="kmeans") – The method is used to find the cluster centers
sigmas (float, default=2.0) – The sigma values that are used in Gaussian function. In traditional RBF model, 1 sigma value is used for all of hidden nodes. But in Nature-inspired Algorithms (NIAs) based RBF model, each sigma is assigned to 1 hidden node.
reg_lambda (float, default=0.1) – The lamda value is used in regularization term. If set to 0, then no L2 is applied
seed (int, default=None) – The seed value is used for reproducibility.
- CLS_OBJ_LOSSES = None¶
- SUPPORTED_CLS_METRICS = {'AS': 'max', 'BSL': 'min', 'CEL': 'min', 'CKS': 'max', 'F1S': 'max', 'F2S': 'max', 'FBS': 'max', 'GINI': 'min', 'GMS': 'max', 'HL': 'min', 'HS': 'max', 'JSI': 'max', 'KLDL': 'min', 'LS': 'max', 'MCC': 'max', 'NPV': 'max', 'PS': 'max', 'ROC-AUC': 'max', 'RS': 'max', 'SS': 'max'}¶
- SUPPORTED_REG_METRICS = {'A10': 'max', 'A20': 'max', 'A30': 'max', 'ACOD': 'max', 'APCC': 'max', 'AR': 'max', 'AR2': 'max', 'CI': 'max', 'COD': 'max', 'COR': 'max', 'COV': 'max', 'CRM': 'min', 'DRV': 'min', 'EC': 'max', 'EVS': 'max', 'GINI': 'min', 'GINI_WIKI': 'min', 'JSD': 'min', 'KGE': 'max', 'MAAPE': 'min', 'MAE': 'min', 'MAPE': 'min', 'MASE': 'min', 'ME': 'min', 'MRB': 'min', 'MRE': 'min', 'MSE': 'min', 'MSLE': 'min', 'MedAE': 'min', 'NNSE': 'max', 'NRMSE': 'min', 'NSE': 'max', 'OI': 'max', 'PCC': 'max', 'PCD': 'max', 'R': 'max', 'R2': 'max', 'R2S': 'max', 'RAE': 'min', 'RMSE': 'min', 'RSE': 'min', 'RSQ': 'max', 'SMAPE': 'min', 'VAF': 'max', 'WI': 'max'}¶
- evaluate(y_true, y_pred, list_metrics=None)[source]¶
Return the list of performance metrics of the prediction. You can get metrics from Permetrics library: https://github.com/thieu1995/permetrics
- predict_proba(X)[source]¶
It is used for classification problem. The returned results are the probability for each sample
- class evorbf.core.base_rbf.CustomRBF(size_hidden=10, center_finder='kmeans', sigmas=2.0, reg_lambda=0.1, seed=None)[source]¶
Bases:
objectRadial Basis Function
- This class defines the general RBF model that:
use non-linear Gaussian function
use inverse matrix multiplication instead of Gradient-based
set up regulation term with hyperparameter lamda
- Parameters
size_hidden (int, default=10) – The number of hidden nodes
center_finder (str, default="kmeans") – The method is used to find the cluster centers
sigmas (float, int, np.ndarray, list, tuple, default=2.0) – The sigma values that are used in Gaussian function. In traditional RBF model, 1 sigma value is used for all of hidden nodes. But in Nature-inspired Algorithms (NIAs) based RBF model, each sigma is assigned to 1 hidden node.
reg_lambda (float, default=0.1) – The lamda value is used in regularization term. If set to 0, then no L2 is applied
seed (int, default=None) – The seed value is used for reproducibility.
- fit(X, y)[source]¶
Fit the core to data matrix X and target(s) y.
- Parameters
X (ndarray or sparse matrix of shape (n_samples, n_features)) – The input data.
y (ndarray of shape (n_samples,) or (n_samples, n_outputs)) – The target values (class labels in classification, real numbers in regression).
- Returns
self – Returns a trained RBF core.
- Return type
object
evorbf.core.nia_rbf module¶
- class evorbf.core.nia_rbf.NiaRbfClassifier(size_hidden=10, center_finder='kmeans', regularization=False, obj_name=None, optim='BaseGA', optim_params=None, verbose=True, seed=None, lb=None, ub=None, mode='single', n_workers=None, termination=None)[source]¶
Bases:
evorbf.core.base_rbf.BaseNiaRbf,sklearn.base.ClassifierMixinDefines the general class of Nature-inspired Algorithm-based RBF models for Classification problems. It inherits the BaseNiaRbf and ClassifierMixin (from scikit-learn library) classes.
- This class defines the InaRbf classifier model that:
Use NIA algorithm to find sigmas value and weights of output layer.
use non-linear Gaussian function with sigmas as standard deviation
set up regulation term with hyperparameter regularization
- Parameters
size_hidden (int, default=10) – The number of hidden nodes
center_finder (str, default="kmeans") – The method is used to find the cluster centers
regularization (bool, default=True) – Determine if L2 regularization technique is used or not. If set to True, then the regularization lambda is learned during the training.
obj_name (None or str, default=None) – The name of objective for the problem, also depend on the problem is classification and regression.
optim (str or instance of Optimizer class (from Mealpy library), default = "BaseGA") – The Metaheuristic Algorithm that use to solve the feature selection problem. Current supported list, please check it here: https://github.com/thieu1995/mealpy. If a custom optimizer is passed, make sure it is an instance of Optimizer class.
optim_params (None or dict of parameter, default=None) – The parameter for the optimizer object. If None, the default parameters of optimizer is used (defined in https://github.com/thieu1995/mealpy.) If dict is passed, make sure it has at least epoch and pop_size parameters.
verbose (bool, default=True) – Whether to print progress messages to stdout.
seed (int, default=None) – The seed value is used for reproducibility.
lb (int, float, tuple, list, np.ndarray, optional) – Lower bounds for sigmas in network.
ub (int, float, tuple, list, np.ndarray, optional) – Upper bounds for sigmas in network.
mode (str, optional) – Mode for optimizer (default is ‘single’).
n_workers (int, optional) – Number of workers for parallel processing in optimizer (default is None).
termination (any, optional) – Termination criteria for optimizer (default is None).
Examples
>>> from evorbf import Data, NiaRbfClassifier >>> from sklearn.datasets import make_classification >>> X, y = make_classification(n_samples=100, random_state=1) >>> data = Data(X, y) >>> data.split_train_test(test_size=0.2, random_state=1) >>> opt_paras = {"name": "WOA", "epoch": 100, "pop_size": 30} >>> print(NiaRbfClassifier.SUPPORTED_CLS_OBJECTIVES) >>> model = NiaRbfClassifier(size_hidden=25, center_finder="kmeans", regularization=False, obj_name="AS", >>> optim="OriginalWOA", optim_params=opt_paras, verbose=True, seed=42) >>> model.fit(data.X_train, data.y_train) >>> pred = model.predict(data.X_test) >>> print(pred) array([1, 0, 1, 0, 1])
- CLS_OBJ_LOSSES = ['CEL', 'HL', 'KLDL', 'BSL']¶
- create_network(X, y) Tuple[evorbf.core.base_rbf.CustomRBF, evorbf.helpers.scaler.ObjectiveScaler][source]¶
- evaluate(y_true, y_pred, list_metrics=('AS', 'RS'))[source]¶
Return the list of performance metrics on the given test data and labels.
- Parameters
y_true (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True values for X.
y_pred (array-like of shape (n_samples,) or (n_samples, n_outputs)) – Predicted values for X.
list_metrics (list, default=("AS", "RS")) – You can get metrics from Permetrics library: https://github.com/thieu1995/permetrics
- Returns
results – The results of the list metrics
- Return type
dict
- objective_function(solution=None)[source]¶
Evaluates the fitness function for classification metric
- Parameters
solution (np.ndarray, default=None) –
- Returns
result – The fitness value
- Return type
float
- score(X, y)[source]¶
Return the accuracy score on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
- Parameters
X (array-like of shape (n_samples, n_features)) – Test samples.
y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True labels for X.
- Returns
result – The result of selected metric
- Return type
float
- scores(X, y, list_metrics=('AS', 'RS'))[source]¶
Return the list of metrics on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
- Parameters
X (array-like of shape (n_samples, n_features)) – Test samples.
y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True labels for X.
list_metrics (list, default=("AS", "RS")) – You can get all metrics from Permetrics library: https://github.com/thieu1995/permetrics
- Returns
results – The results of the list metrics
- Return type
dict
- class evorbf.core.nia_rbf.NiaRbfRegressor(size_hidden=10, center_finder='kmeans', regularization=False, obj_name=None, optim='BaseGA', optim_params=None, verbose=True, seed=None, lb=None, ub=None, mode='single', n_workers=None, termination=None)[source]¶
Bases:
evorbf.core.base_rbf.BaseNiaRbf,sklearn.base.RegressorMixinDefines the general class of Nature-inspired Algorithm-based RBF models for Regression problems. It inherits the BaseNiaRbf and RegressorMixin (from scikit-learn library) classes.
- This class defines the InaRbf regressor model that:
Use NIA algorithm to find sigmas value and weights of output layer.
use non-linear Gaussian function with sigmas as standard deviation
set up regulation term with hyperparameter regularization
- Inherits:
BaseNiaRbf : The base class for NIA-based RBF networks.
RegressorMixin : Scikit-learn mixin class for regression estimators.
- Parameters
size_hidden (int, default=10) – The number of hidden nodes
center_finder (str, default="kmeans") – The method is used to find the cluster centers
regularization (bool, default=True) – Determine if L2 regularization technique is used or not. If set to True, then the regularization lambda is learned during the training.
obj_name (None or str, default=None) – The name of objective for the problem, also depend on the problem is classification and regression.
optim (str or instance of Optimizer class (from Mealpy library), default = "BaseGA") – The Metaheuristic Algorithm that use to solve the feature selection problem. Current supported list, please check it here: https://github.com/thieu1995/mealpy. If a custom optimizer is passed, make sure it is an instance of Optimizer class.
optim_params (None or dict of parameter, default=None) – The parameter for the optimizer object. If None, the default parameters of optimizer is used (defined in https://github.com/thieu1995/mealpy.) If dict is passed, make sure it has at least epoch and pop_size parameters.
verbose (bool, default=True) – Whether to print progress messages to stdout.
seed (int, default=None) – The seed value is used for reproducibility.
lb (int, float, tuple, list, np.ndarray, optional) – Lower bounds for sigmas in network.
ub (int, float, tuple, list, np.ndarray, optional) – Upper bounds for sigmas in network.
mode (str, optional) – Mode for optimizer (default is ‘single’).
n_workers (int, optional) – Number of workers for parallel processing in optimizer (default is None).
termination (any, optional) – Termination criteria for optimizer (default is None).
- network¶
The RBF network instance created during training.
- Type
object
- obj_weights¶
Weights assigned to output objectives for multi-objective tasks.
- Type
array-like
- X_temp¶
Training input data temporarily stored during optimization.
- Type
array-like
- y_temp¶
Training output data temporarily stored during optimization.
- Type
array-like
- fit(X, y)¶
Fit the NIA-RBF model to the training data.
- predict(X)¶
Predict regression outputs for the given input data.
- scores(X, y, list_metrics=('MSE', 'MAE'))[source]¶
Calculate and return a dictionary of performance metrics for the given data.
- evaluate(y_true, y_pred, list_metrics=('MSE', 'MAE'))[source]¶
Evaluate and return a dictionary of performance metrics for the provided true and predicted labels.
- objective_function(solution=None)[source]¶
Evaluate the fitness function for regression metrics using the given solution.
- create_network(X, y)[source]¶
Initialize and configure the RBF network structure based on the input data.
Examples
>>> from evorbf import NiaRbfRegressor, Data >>> from sklearn.datasets import make_regression >>> X, y = make_regression(n_samples=200, random_state=1) >>> data = Data(X, y) >>> data.split_train_test(test_size=0.2, random_state=1) >>> opt_paras = {"name": "GA", "epoch": 10, "pop_size": 30} >>> model = NiaRbfRegressor(size_hidden=10, center_finder="kmeans", regularization=False, >>> obj_name=None, optim="BaseGA", optim_params=opt_paras, verbose=True, seed=42) >>> model.fit(data.X_train, data.y_train) >>> pred = model.predict(data.X_test) >>> print(pred)
Notes
This class requires the Mealpy library for the metaheuristic optimization algorithms. More details and supported optimizers can be found at: https://github.com/thieu1995/mealpy.
For metrics, the Permetrics library is recommended: https://github.com/thieu1995/permetrics.
- evaluate(y_true, y_pred, list_metrics=('MSE', 'MAE'))[source]¶
Return the list of performance metrics of the prediction.
- Parameters
y_true (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True values for X.
y_pred (array-like of shape (n_samples,) or (n_samples, n_outputs)) – Predicted values for X.
list_metrics (list, default=("MSE", "MAE")) – You can get metrics from Permetrics library: https://github.com/thieu1995/permetrics
- Returns
results – The results of the list metrics
- Return type
dict
- objective_function(solution=None)[source]¶
Evaluates the fitness function for regression metric
- Parameters
solution (np.ndarray, default=None) –
- Returns
result – The fitness value
- Return type
float
- score(X, y)[source]¶
Return the R2S metric of the prediction.
- Parameters
X (array-like of shape (n_samples, n_features)) – Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape
(n_samples, n_samples_fitted), wheren_samples_fittedis the number of samples used in the fitting for the estimator.y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True values for X.
- Returns
result – The result of selected metric
- Return type
float
- scores(X, y, list_metrics=('MSE', 'MAE'))[source]¶
Return the list of metrics of the prediction.
- Parameters
X (array-like of shape (n_samples, n_features)) – Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape
(n_samples, n_samples_fitted), wheren_samples_fittedis the number of samples used in the fitting for the estimator.y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True values for X.
list_metrics (list, default=("MSE", "MAE")) – You can get all metrics from Permetrics library: https://github.com/thieu1995/permetrics
- Returns
results – The results of the list metrics
- Return type
dict
evorbf.core.rbf_tuner module¶
- class evorbf.core.rbf_tuner.HyperparameterProblem(bounds=None, minmax='max', X=None, y=None, model_class=None, metric_class=None, obj_name=None, cv=5, seed=None, **kwargs)[source]¶
Bases:
mealpy.utils.problem.ProblemA class for defining a hyperparameter optimization problem using cross-validation.
Inherits from the Problem class and implements an objective function to evaluate a given set of hyperparameters by training and evaluating a specified model class using cross-validation.
- model_class¶
The class of the model to be optimized.
- Type
type
- model¶
The model instance created during optimization.
- Type
object
- X¶
The feature matrix for training the model.
- Type
array-like
- y¶
The target variable for training the model.
- Type
array-like
- metric_class¶
The class used for evaluating the model’s performance.
- Type
type
- obj_name¶
The name of the metric to be extracted from the metric class.
- Type
str
- cv¶
The number of folds in cross-validation (default is 5).
- Type
int
- seed¶
The seed for random number generation for reproducibility.
- Type
int
- kf¶
The cross-validation iterator.
- Type
KFold
- obj_func(x)[source]¶
Evaluates the performance of the model with given hyperparameters using cross-validation and returns the mean performance score.
- obj_func(x)[source]¶
Evaluates the model’s performance for a given set of hyperparameters using cross-validation and returns the mean performance score.
- Parameters
x (array-like) – The hyperparameter configuration to be evaluated.
- Returns
The mean score of the model across all cross-validation folds.
- Return type
float
- class evorbf.core.rbf_tuner.NiaRbfTuner(problem_type='regression', bounds=None, cv=5, scoring='MSE', optim='OriginalWOA', optim_params=None, verbose=True, seed=None, mode='single', n_workers=None, termination=None)[source]¶
Bases:
objectA class for tuning hyperparameters of Radial Basis Function (RBF) neural networks using optimization algorithms.
This class supports both regression and classification tasks and can be configured to use different optimization algorithms from the Mealpy library to find the best set of hyperparameters for an RBF model.
- SUPPORTED_CLS_METRICS¶
Dictionary of supported metrics for classification tasks.
- Type
dict
- SUPPORTED_REG_METRICS¶
Dictionary of supported metrics for regression tasks.
- Type
dict
- network_class¶
The class of the RBF network, either RbfRegressor or RbfClassifier.
- Type
type
- scoring¶
The metric used for evaluating the model performance.
- Type
str
- minmax¶
Indicates whether the scoring metric should be maximized or minimized.
- Type
str
- metric_class¶
The class for the metric used for model evaluation, either RegressionMetric or ClassificationMetric.
- Type
type
- seed¶
Random seed for reproducibility.
- Type
int or None
- problem_type¶
Indicates whether the problem is a “regression” or “classification” task.
- Type
str
- bounds¶
The search space for hyperparameters.
- Type
list of tuples
- cv¶
The number of folds in cross-validation.
- Type
int
- verbose¶
Level of verbosity for the optimization process.
- Type
str
- optim_params¶
Parameters for the optimization algorithm.
- Type
dict or None
- optimizer¶
The optimization algorithm used for tuning hyperparameters.
- Type
Optimizer
- best_params¶
The best hyperparameters found.
- Type
dict or None
- best_estimator¶
The trained model with the best hyperparameters.
- Type
object or None
- loss_train¶
The training loss history during the optimization process.
- Type
list or None
- mode¶
Mode for optimization (default is ‘single’).
- Type
str, optional
- n_workers¶
Number of workers for parallel processing (default is None).
- Type
int, optional
- termination¶
Termination criteria for optimization (default is None).
- Type
any, optional
- _set_optim(optim, optim_params)[source]¶
Initializes and returns the optimizer instance based on the provided algorithm name and parameters.
- fit(X, y)[source]¶
Fits the model to the training data and optimizes the hyperparameters using the specified optimizer.
- SUPPORTED_CLS_METRICS = {'AS': 'max', 'BSL': 'min', 'CEL': 'min', 'CKS': 'max', 'F1S': 'max', 'F2S': 'max', 'FBS': 'max', 'GINI': 'min', 'GMS': 'max', 'HL': 'min', 'HS': 'max', 'JSI': 'max', 'KLDL': 'min', 'LS': 'max', 'MCC': 'max', 'NPV': 'max', 'PS': 'max', 'ROC-AUC': 'max', 'RS': 'max', 'SS': 'max'}¶
- SUPPORTED_REG_METRICS = {'A10': 'max', 'A20': 'max', 'A30': 'max', 'ACOD': 'max', 'APCC': 'max', 'AR': 'max', 'AR2': 'max', 'CI': 'max', 'COD': 'max', 'COR': 'max', 'COV': 'max', 'CRM': 'min', 'DRV': 'min', 'EC': 'max', 'EVS': 'max', 'GINI': 'min', 'GINI_WIKI': 'min', 'JSD': 'min', 'KGE': 'max', 'MAAPE': 'min', 'MAE': 'min', 'MAPE': 'min', 'MASE': 'min', 'ME': 'min', 'MRB': 'min', 'MRE': 'min', 'MSE': 'min', 'MSLE': 'min', 'MedAE': 'min', 'NNSE': 'max', 'NRMSE': 'min', 'NSE': 'max', 'OI': 'max', 'PCC': 'max', 'PCD': 'max', 'R': 'max', 'R2': 'max', 'R2S': 'max', 'RAE': 'min', 'RMSE': 'min', 'RSE': 'min', 'RSQ': 'max', 'SMAPE': 'min', 'VAF': 'max', 'WI': 'max'}¶
- fit(X, y)[source]¶
Fits the RBF model to the training data and optimizes the hyperparameters.
- Parameters
X (array-like) – The feature matrix for training.
y (array-like) – The target variable for training.
- Returns
The instance of the fitted NiaRbfTuner with optimized hyperparameters.
- Return type
self
- predict(X)[source]¶
Predicts the target values for the input data using the trained model.
- Parameters
X (array-like) – The feature matrix for making predictions.
- Returns
Predicted target values.
- Return type
array-like
- Raises
ValueError – If the model has not been trained yet.
- save_convergence(save_path='history', filename='convergence.csv')[source]¶
Save the convergence (fitness value) during the training process to csv file.
- Parameters
save_path (saved path (relative path, consider from current executed script path)) –
filename (name of the file, needs to have ".csv" extension) –
- save_model(save_path='history', filename='network.pkl')[source]¶
Save network to pickle file
- Parameters
save_path (saved path (relative path, consider from current executed script path)) –
filename (name of the file, needs to have ".pkl" extension) –
- save_performance_metrics(y_true, y_pred, list_metrics=('RMSE', 'MAE'), save_path='history', filename='metrics.csv')[source]¶
Save evaluation metrics to csv file
- Parameters
y_true (ground truth data) –
y_pred (predicted output) –
list_metrics (list of evaluation metrics) –
save_path (saved path (relative path, consider from current executed script path)) –
filename (name of the file, needs to have ".csv" extension) –
- save_y_predicted(X, y_true, save_path='history', filename='y_predicted.csv')[source]¶
Save the predicted results to csv file
- Parameters
X (The features data, nd.ndarray) –
y_true (The ground truth data) –
save_path (saved path (relative path, consider from current executed script path)) –
filename (name of the file, needs to have ".csv" extension) –
evorbf.core.standard_rbf module¶
- class evorbf.core.standard_rbf.RbfClassifier(size_hidden=10, center_finder='kmeans', sigmas=2.0, reg_lambda=0.1, seed=None)[source]¶
Bases:
evorbf.core.base_rbf.BaseRbf,sklearn.base.ClassifierMixinA Radial Basis Function (RBF) model for classification tasks.
This class implements an RBF classifier that uses non-linear Gaussian activation functions and inverse matrix multiplication for output weight calculation. It allows for regularization through an L2 term.
- Parameters
size_hidden (int, default=10) – The number of hidden nodes in the RBF network.
center_finder (str, default="kmeans") – The method used to find cluster centers. For example, “kmeans” applies the K-Means clustering algorithm.
sigmas (float, default=2.0) – The sigma value for the Gaussian activation function. In a traditional RBF model, one sigma is used for all hidden nodes. In Nature-inspired Algorithm-based RBF models, each hidden node may have its own sigma value.
reg_lambda (float, default=0.1) – The regularization parameter for the L2 regularization term. Setting this to 0 disables regularization.
seed (int or None, default=None) – The random seed for initializing the weights and biases. Specify an integer value for reproducibility.
- n_labels¶
The number of unique labels in the target dataset. Determined during the creation of the network.
- Type
int
Examples
>>> from evorbf import Data, RbfClassifier >>> from sklearn.datasets import make_classification >>> X, y = make_classification(n_samples=100, random_state=1) >>> data = Data(X, y) >>> data.split_train_test(test_size=0.2, random_state=1) >>> model = RbfClassifier(size_hidden=10, center_finder="kmeans", sigmas=2.0, reg_lambda=0.1, seed=None) >>> model.fit(data.X_train, data.y_train) >>> pred = model.predict(data.X_test) >>> print(pred) array([1, 0, 1, 0, 1])
Notes
This class requires the Permetrics library to evaluate performance metrics.
One-hot encoding is applied internally to handle multi-class classification problems.
- CLS_OBJ_LOSSES = ['CEL', 'HL', 'KLDL', 'BSL']¶
- create_network(X, y)[source]¶
Initializes the RBF network and prepares data for classification.
- Parameters
X (array-like of shape (n_samples, n_features)) – The input data.
y (array-like of shape (n_samples,)) – The target labels. Must be a 1D array or vector containing integer class labels.
- Returns
network (CustomRBF) – The initialized RBF network with the specified configuration.
obj_scaler (ObjectiveScaler) – The scaler that applies one-hot encoding and the softmax activation function.
- Raises
TypeError – If the target array y is not a 1D array or is of an unsupported type.
- evaluate(y_true, y_pred, list_metrics=('AS', 'RS'))[source]¶
Evaluates performance metrics for predicted values compared to true labels.
- Parameters
y_true (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True values for X.
y_pred (array-like of shape (n_samples,) or (n_samples, n_outputs)) – Predicted values for X.
list_metrics (list, default=("AS", "RS")) – You can get metrics from Permetrics library: https://github.com/thieu1995/permetrics
- Returns
results – A dictionary where keys are metric names and values are the computed metric scores.
- Return type
dict
- score(X, y)[source]¶
Calculates the accuracy of the model on the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
- Parameters
X (array-like of shape (n_samples, n_features)) – Test samples.
y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True labels for X.
- Returns
result – The accuracy score of the classifier.
- Return type
float
- scores(X, y, list_metrics=('AS', 'RS'))[source]¶
Computes multiple performance metrics for the given test data and labels.
In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.
- Parameters
X (array-like of shape (n_samples, n_features)) – Test samples.
y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True labels for X.
list_metrics (list, default=("AS", "RS")) – You can get all metrics from Permetrics library: https://github.com/thieu1995/permetrics
- Returns
results – A dictionary where keys are metric names and values are the computed metric scores.
- Return type
dict
- class evorbf.core.standard_rbf.RbfRegressor(size_hidden=10, center_finder='kmeans', sigmas=2.0, reg_lambda=0.1, seed=None)[source]¶
Bases:
evorbf.core.base_rbf.BaseRbf,sklearn.base.RegressorMixinImplements a Radial Basis Function (RBF) model for regression tasks.
- This class extends BaseRbf and RegressorMixin to provide a regression model that:
Uses a non-linear Gaussian kernel function.
Computes output weights using inverse matrix multiplication.
Incorporates L2 regularization with the reg_lambda parameter.
- Parameters
size_hidden (int, default=10) – Number of hidden nodes in the RBF network.
center_finder (str, default="kmeans") – Method for finding the cluster centers. Options include methods like “random” or “kmeans”.
sigmas (float, default=2.0) – The width (sigma) of the Gaussian kernel. - In the standard RBF model, a single sigma value is used for all hidden nodes. - In nature-inspired algorithms (NIAs)-based RBF models, each hidden node can have a unique sigma value.
reg_lambda (float, default=0.1) – Regularization parameter for L2 regularization. Set to 0 to disable regularization.
seed (int, default=None) – Random seed for reproducibility in center initialization and weight generation.
Examples
>>> from evorbf import RbfRegressor, Data >>> from sklearn.datasets import make_regression >>> X, y = make_regression(n_samples=200, random_state=1) >>> data = Data(X, y) >>> data.split_train_test(test_size=0.2, random_state=1) >>> model = RbfRegressor(size_hidden=10, center_finder="kmeans", sigmas=2.0, reg_lambda=0.1, seed=42) >>> model.fit(data.X_train, data.y_train) >>> pred = model.predict(data.X_test) >>> print(pred)
- create_network(X, y):
Constructs the RBF network based on the input data and labels.
- score(X, y):
Calculates the R^2 (R-squared) score for the model’s predictions.
- scores(X, y, list_metrics=("MSE", "MAE")):
Computes a list of specified performance metrics (e.g., MSE, MAE) for the model’s predictions.
- evaluate(y_true, y_pred, list_metrics=("MSE", "MAE")):
Evaluates the model’s performance using true and predicted values, based on a specified list of metrics.
- evaluate(y_true, y_pred, list_metrics=('MSE', 'MAE'))[source]¶
Return the list of performance metrics of the prediction.
- Parameters
y_true (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True values for X.
y_pred (array-like of shape (n_samples,) or (n_samples, n_outputs)) – Predicted values for X.
list_metrics (list, default=("MSE", "MAE")) – You can get metrics from Permetrics library: https://github.com/thieu1995/permetrics
- Returns
results – The results of the list metrics
- Return type
dict
- score(X, y)[source]¶
Return the R2S metric of the prediction.
- Parameters
X (array-like of shape (n_samples, n_features)) – Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape
(n_samples, n_samples_fitted), wheren_samples_fittedis the number of samples used in the fitting for the estimator.y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True values for X.
- Returns
result – The result of selected metric
- Return type
float
- scores(X, y, list_metrics=('MSE', 'MAE'))[source]¶
Return the list of metrics of the prediction.
- Parameters
X (array-like of shape (n_samples, n_features)) – Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape
(n_samples, n_samples_fitted), wheren_samples_fittedis the number of samples used in the fitting for the estimator.y (array-like of shape (n_samples,) or (n_samples, n_outputs)) – True values for X.
list_metrics (list, default=("MSE", "MAE")) – You can get all metrics from Permetrics library: https://github.com/thieu1995/permetrics
- Returns
results – The results of the list metrics
- Return type
dict