waveletml.helpers package¶
waveletml.helpers.callbacks module¶
- class waveletml.helpers.callbacks.EarlyStoppingCallback(patience=5, min_delta=0.0001, monitor='val_loss')[source]¶
Bases:
BaseCallback
- class waveletml.helpers.callbacks.FileLoggerCallback(log_file='training_log.txt')[source]¶
Bases:
BaseCallback
- class waveletml.helpers.callbacks.ModelCheckpointCallback(save_path='best_model.pt', monitor='val_loss', mode='min')[source]¶
Bases:
BaseCallback
- class waveletml.helpers.callbacks.PrintLossCallback[source]¶
Bases:
BaseCallback
waveletml.helpers.data_preparer module¶
- class waveletml.helpers.data_preparer.Data(X=None, y=None, name='Unknown')[source]¶
Bases:
objectThe structure of our supported Data class
- Parameters:
X (np.ndarray) – The features of your data
y (np.ndarray) – The labels of your data
- SUPPORT = {'scaler': ['standard', 'minmax', 'max-abs', 'log1p', 'loge', 'sqrt', 'sinh-arc-sinh', 'robust', 'box-cox', 'yeo-johnson']}¶
- class waveletml.helpers.data_preparer.DataTransformer(scaling_methods=('standard',), list_dict_paras=None)[source]¶
Bases:
BaseEstimator,TransformerMixinThe class is used to transform data using different scaling techniques.
- Parameters:
scaling_methods (str, tuple, list, or np.ndarray) – The name of the scaler you want to use. Supported scaler names are: ‘standard’, ‘minmax’, ‘max-abs’, ‘log1p’, ‘loge’, ‘sqrt’, ‘sinh-arc-sinh’, ‘robust’, ‘box-cox’, ‘yeo-johnson’.
list_dict_paras (dict or list of dict) – The parameters for the scaler. If you have only one scaler, please use a dict. Otherwise, please use a list of dict.
- SUPPORTED_SCALERS = {'box-cox': <class 'waveletml.helpers.data_scaler.BoxCoxScaler'>, 'log1p': <class 'waveletml.helpers.data_scaler.Log1pScaler'>, 'loge': <class 'waveletml.helpers.data_scaler.LogeScaler'>, 'max-abs': <class 'sklearn.preprocessing._data.MaxAbsScaler'>, 'minmax': <class 'sklearn.preprocessing._data.MinMaxScaler'>, 'robust': <class 'sklearn.preprocessing._data.RobustScaler'>, 'sinh-arc-sinh': <class 'waveletml.helpers.data_scaler.SinhArcSinhScaler'>, 'sqrt': <class 'waveletml.helpers.data_scaler.SqrtScaler'>, 'standard': <class 'sklearn.preprocessing._data.StandardScaler'>, 'yeo-johnson': <class 'waveletml.helpers.data_scaler.YeoJohnsonScaler'>}¶
- fit(X, y=None)[source]¶
Fit the sequence of scalers on the data.
- Parameters:
X (array-like of shape (n_samples, n_features)) – The input data.
y (Ignored) – Not used, exists for compatibility with sklearn’s pipeline.
- Returns:
self – Fitted transformer.
- Return type:
object
- class waveletml.helpers.data_preparer.FeatureEngineering[source]¶
Bases:
objectA class for performing custom feature engineering on numeric datasets.
- create_threshold_binary_features(X, threshold)[source]¶
Add binary indicator columns to mark values below a given threshold. Each original column is followed by a new column indicating whether each value is below the threshold (1 if True, 0 otherwise).
- Parameters:
X (numpy.ndarray) – The input 2D matrix of shape (n_samples, n_features).
threshold (float) – The threshold value used to determine binary flags.
- Returns:
A new 2D matrix of shape (n_samples, 2 * n_features), where each original column is followed by its binary indicator column.
- Return type:
numpy.ndarray
- Raises:
ValueError – If X is not a NumPy array or not 2D. If threshold is not a numeric type.
- class waveletml.helpers.data_preparer.TimeSeriesDifferencer(interval=1)[source]¶
Bases:
objectA class for applying and reversing differencing on time series data.
Differencing helps remove trends and seasonality from time series for better modeling.
- difference(X)[source]¶
Apply differencing to the input time series.
- Parameters:
X (array-like) – The original time series data.
- Returns:
The differenced time series of length (len(X) - interval).
- Return type:
np.ndarray
- inverse_difference(diff_data)[source]¶
Reverse the differencing transformation using the stored original data.
- Parameters:
diff_data (array-like) – The differenced data to invert.
- Returns:
The reconstructed original data (excluding the first interval values).
- Return type:
np.ndarray
- Raises:
ValueError – If the original data is not available.
waveletml.helpers.data_scaler module¶
- class waveletml.helpers.data_scaler.BoxCoxScaler(lmbda=None)[source]¶
Bases:
BaseEstimator,TransformerMixinApply the Box-Cox transformation to stabilize variance and make the data more normally distributed. The Box-Cox transformation is only defined for positive data.
- class waveletml.helpers.data_scaler.LabelEncoder[source]¶
Bases:
objectEncode categorical labels as integer indices and decode them back.
This class maps unique categorical labels to integers from 0 to n_classes - 1.
- fit(y)[source]¶
Fit the encoder by finding unique labels in the input data.
- Parameters:
y (array-like) – Input labels.
- Returns:
self – Fitted LabelEncoder instance.
- Return type:
- fit_transform(y)[source]¶
Fit the encoder and transform labels in one step.
- Parameters:
y (array-like of shape (n_samples,)) – Input labels.
- Returns:
Encoded integer labels.
- Return type:
np.ndarray
- class waveletml.helpers.data_scaler.Log1pScaler[source]¶
Bases:
BaseEstimator,TransformerMixinApply the natural logarithm (base e) to each element of the input data. This is useful for transforming data that may have a long tail distribution.
- class waveletml.helpers.data_scaler.LogeScaler[source]¶
Bases:
BaseEstimator,TransformerMixinApply the natural logarithm (base e) to each element of the input data. This is useful for transforming data that may have a long tail distribution.
- class waveletml.helpers.data_scaler.ObjectiveScaler(obj_name='sigmoid', ohe_scaler=None)[source]¶
Bases:
objectFor label scaler in classification (binary and multiple classification)
- class waveletml.helpers.data_scaler.OneHotEncoder[source]¶
Bases:
objectA simple implementation of one-hot encoding for 1D categorical data.
- categories_¶
Sorted array of unique categories fitted from the input data.
- Type:
np.ndarray
- fit(X)[source]¶
Fit the encoder to the unique categories in X.
- Parameters:
X (array-like) – 1D array of categorical values.
- Returns:
Fitted OneHotEncoder instance.
- Return type:
self
- fit_transform(X)[source]¶
Fit the encoder to X and transform X.
- Parameters:
X (array-like) – 1D array of categorical values.
- Returns:
One-hot encoded array of shape (n_samples, n_categories).
- Return type:
np.ndarray
- inverse_transform(one_hot)[source]¶
Convert one-hot encoded data back to original categories.
- Parameters:
one_hot (np.ndarray) – 2D array of one-hot encoded data.
- Returns:
1D array of original categorical values.
- Return type:
np.ndarray
- Raises:
ValueError – If the encoder has not been fitted or shape mismatch occurs.
- transform(X)[source]¶
Transform input data into one-hot encoded format.
- Parameters:
X (array-like) – 1D array of categorical values.
- Returns:
One-hot encoded array of shape (n_samples, n_categories).
- Return type:
np.ndarray
- Raises:
ValueError – If the encoder has not been fitted or unknown category is found.
- class waveletml.helpers.data_scaler.SinhArcSinhScaler(epsilon=0.1, delta=1.0)[source]¶
Bases:
BaseEstimator,TransformerMixinApply the sinh-arc-sinh transformation to increase kurtosis and skewness of normal random variable. This transformation is useful for data that are normally distributed but need to be transformed to have higher kurtosis and skewness.
- class waveletml.helpers.data_scaler.SqrtScaler[source]¶
Bases:
BaseEstimator,TransformerMixinApply the square root transformation to each element of the input data. This is useful for transforming data that may have a long tail distribution.
waveletml.helpers.evaluator module¶
- waveletml.helpers.evaluator.get_all_classification_metrics()[source]¶
Gets a dictionary of all supported classification metrics.
This function returns a dictionary where keys are metric names and values are their optimization types (“min” or “max”).
- Returns:
A dictionary containing all supported classification metrics.
- Return type:
dict
- waveletml.helpers.evaluator.get_all_regression_metrics()[source]¶
Gets a dictionary of all supported regression metrics.
This function returns a dictionary where keys are metric names and values are their optimization types (“min” or “max”).
- Returns:
A dictionary containing all supported regression metrics.
- Return type:
dict
- waveletml.helpers.evaluator.get_metric_sklearn(task='classification', metric_names=None)[source]¶
Creates a dictionary of scorers for scikit-learn cross-validation.
This function takes the task type (classification or regression) and a list of metric names. It creates an appropriate metrics instance (ClassificationMetric or RegressionMetric) and iterates through the provided metric names. For each metric name, it checks if it exists in the metrics instance and retrieves the corresponding method. Finally, it uses make_scorer to convert the method to a scorer and adds it to a dictionary.
- Parameters:
task (str, optional) – The task type, either “classification” or “regression”. Defaults to “classification”.
metric_names (list, optional) – A list of metric names. Defaults to None.
- Returns:
A dictionary of scorers for scikit-learn cross-validation.
- Return type:
dict
- waveletml.helpers.evaluator.get_metrics(problem, y_true, y_pred, metrics=None, testcase='test')[source]¶
Calculates metrics for regression or classification tasks.
This function takes the true labels (y_true), predicted labels (y_pred), problem type (regression or classification), a dictionary or list of metrics to calculate, and an optional test case name. It returns a dictionary containing the calculated metrics with descriptive names.
- Parameters:
problem (str) – The type of problem, either “regression” or “classification”.
y_true (array-like) – The true labels.
y_pred (array-like) – The predicted labels.
metrics (dict or list, optional) – A dictionary or list of metrics to calculate. Defaults to None.
testcase (str, optional) – An optional test case name to prepend to the metric names. Defaults to “test”.
- Returns:
A dictionary containing the calculated metrics with descriptive names.
- Return type:
dict
- Raises:
ValueError – If the metrics parameter is not a list or dictionary.
waveletml.helpers.verifier module¶
- waveletml.helpers.verifier.check_bool(name: str, value: bool, bound=(True, False))[source]¶
Checks if a value is a boolean and optionally verifies it matches a specified bound.
- Parameters:
name (str) – The name of the variable being checked.
value (bool) – The value to check.
bound (tuple, optional) – A tuple of allowed boolean values.
- Returns:
The validated boolean value.
- Return type:
bool
- Raises:
ValueError – If the value is not a boolean or not in the bound (if provided).
- waveletml.helpers.verifier.check_float(name: str, value: None, bound=None)[source]¶
Checks if a value is a float and optionally verifies it falls within a specified bound.
- Parameters:
name (str) – The name of the variable being checked.
value (int or float) – The value to check.
bound (tuple, optional) – A tuple representing the lower and upper bound (inclusive).
- Returns:
The validated float value.
- Return type:
float
- Raises:
ValueError – If the value is not a float or falls outside the bound (if provided).
- waveletml.helpers.verifier.check_int(name: str, value: None, bound=None)[source]¶
Checks if a value is an integer and optionally verifies it falls within a specified bound.
- Parameters:
name (str) – The name of the variable being checked.
value (int or float) – The value to check.
bound (tuple, optional) – A tuple representing the lower and upper bound (inclusive).
- Returns:
The validated integer value.
- Return type:
int
- Raises:
ValueError – If the value is not an integer or falls outside the bound (if provided).
- waveletml.helpers.verifier.check_str(name: str, value: str, bound=None)[source]¶
Checks if a value is a string and optionally verifies it exists within a provided list.
- Parameters:
name (str) – The name of the variable being checked.
value (str) – The value to check.
bound (list, optional) – A list of allowed string values.
- Returns:
The validated string value.
- Return type:
str
- Raises:
ValueError – If the value is not a string or not found in the bound list (if provided).
- waveletml.helpers.verifier.check_tuple_float(name: str, values: tuple, bounds=None)[source]¶
Checks if a tuple contains only floats or integers and optionally verifies they fall within specified bounds.
- Parameters:
name (str) – The name of the variable being checked.
values (tuple) – The tuple of values to check.
bounds (list of tuples, optional) – A list of tuples representing lower and upper bounds for each value.
- Returns:
The validated tuple of floats.
- Return type:
tuple
- Raises:
ValueError – If the values are not all floats or integers or do not fall within the specified bounds.
- waveletml.helpers.verifier.check_tuple_int(name: str, values: None, bounds=None)[source]¶
Checks if a tuple contains only integers and optionally verifies they fall within specified bounds.
- Parameters:
name (str) – The name of the variable being checked.
values (tuple) – The tuple of values to check.
bounds (list of tuples, optional) – A list of tuples representing lower and upper bounds for each value.
- Returns:
The validated tuple of integers.
- Return type:
tuple
- Raises:
ValueError – If the values are not all integers or do not fall within the specified bounds.
- waveletml.helpers.verifier.is_in_bound(value, bound)[source]¶
Checks if a value falls within a specified numerical bound.
- Parameters:
value (float) – The value to check.
bound (tuple) – A tuple representing the lower and upper bound (inclusive for lists).
- Returns:
True if the value is within the bound, False otherwise.
- Return type:
bool
- Raises:
ValueError – If the bound is not a tuple or list.
- waveletml.helpers.verifier.is_str_in_list(value: str, my_list: list)[source]¶
Checks if a string value exists within a provided list.
- Parameters:
value (str) – The string value to check.
my_list (list, optional) – The list of possible values.
- Returns:
True if the value is in the list, False otherwise.
- Return type:
bool
waveletml.helpers.wavelet_funcs module¶
- waveletml.helpers.wavelet_funcs.haar(x)[source]¶
Computes the Haar wavelet function.
- Parameters:
x (torch.Tensor) – Input tensor.
- Returns:
Output tensor after applying the Haar wavelet function.
- Return type:
torch.Tensor
waveletml.helpers.wavelet_layers module¶
- class waveletml.helpers.wavelet_layers.WaveletExpansionLayer(in_features, out_features, wavelet_fn)[source]¶
Bases:
ModuleA custom layer for wavelet-based feature expansion, where each hidden neuron outputs a new feature space. The output of each hidden neuron is forming a new feature space. Wavelet-based feature expansion.
- in_features¶
The dimensionality of the input.
- Type:
int
- out_features¶
The number of output features.
- Type:
int
- wavelet_fn¶
The wavelet function to apply.
- Type:
callable
- centers¶
Learnable centers for each output feature and input dimension.
- Type:
torch.nn.Parameter
- scales¶
Learnable scales for each output feature and input dimension.
- Type:
torch.nn.Parameter
- forward(x)[source]¶
Performs the forward pass of the layer.
- Parameters:
x (torch.Tensor) – Input tensor of shape (batch_size, in_features).
- Returns:
Output tensor after applying the wavelet function, expanded to a new feature space.
- Return type:
torch.Tensor
- training: bool¶
- class waveletml.helpers.wavelet_layers.WaveletProductLayer(input_dim, num_neurons, wavelet_fn)[source]¶
Bases:
ModuleA custom layer where each hidden neuron is the product of wavelets applied to each input dimension. Each hidden neuron has d centers and d scales (d = input_dim). And the output of each hidden neuron is the product of d wavelets.
- input_dim¶
The dimensionality of the input.
- Type:
int
- num_neurons¶
The number of neurons in the hidden layer.
- Type:
int
- wavelet_fn¶
The wavelet function to apply.
- Type:
callable
- centers¶
Learnable centers for each neuron and input dimension.
- Type:
torch.nn.Parameter
- scales¶
Learnable scales for each neuron and input dimension.
- Type:
torch.nn.Parameter
- forward(x)[source]¶
Performs the forward pass of the layer.
- Parameters:
x (torch.Tensor) – Input tensor of shape (batch_size, input_dim).
- Returns:
Output tensor after applying the wavelet function and taking the product.
- Return type:
torch.Tensor
- training: bool¶
- class waveletml.helpers.wavelet_layers.WaveletSummationLayer(input_dim, num_neurons, wavelet_fn)[source]¶
Bases:
ModuleA custom layer where each hidden neuron is the sum of wavelets applied to each input dimension. Each hidden neuron has d centers and d scales (d = input_dim). And the output of each hidden neuron is the sum of d wavelets.
- input_dim¶
The dimensionality of the input.
- Type:
int
- num_neurons¶
The number of neurons in the hidden layer.
- Type:
int
- wavelet_fn¶
The wavelet function to apply.
- Type:
callable
- centers¶
Learnable centers for each neuron and input dimension.
- Type:
torch.nn.Parameter
- scales¶
Learnable scales for each neuron and input dimension.
- Type:
torch.nn.Parameter
- forward(x)[source]¶
Performs the forward pass of the layer.
- Parameters:
x (torch.Tensor) – Input tensor of shape (batch_size, input_dim).
- Returns:
Output tensor after applying the wavelet function and taking the sum.
- Return type:
torch.Tensor
- training: bool¶
- class waveletml.helpers.wavelet_layers.WaveletWeightedLinearLayer(input_dim, num_neurons, wavelet_fn)[source]¶
Bases:
ModuleA custom linear layer where each hidden neuron has a center and scale. The weights are learnable parameters connecting the input to the hidden layer. Each hidden neuron has an input (wx), then transform using center and scale before applying the wavelet function.
- input_dim¶
The dimensionality of the input.
- Type:
int
- num_neurons¶
The number of neurons in the hidden layer.
- Type:
int
- wavelet_fn¶
The wavelet function to apply.
- Type:
callable
- weights¶
Learnable weights for the input to hidden connections.
- Type:
torch.nn.Parameter
- centers¶
Learnable centers for each neuron.
- Type:
torch.nn.Parameter
- scales¶
Learnable scales for each neuron.
- Type:
torch.nn.Parameter
- forward(x)[source]¶
Performs the forward pass of the layer.
- Parameters:
x (torch.Tensor) – Input tensor of shape (batch_size, input_dim).
- Returns:
Output tensor after applying the wavelet function.
- Return type:
torch.Tensor
- training: bool¶