artlib.common.utils
General utilities used throughout ARTLib.
Attributes
Functions
|
Normalize data column-wise between 0 and 1. |
|
Restore column-wise normalized data to original scale. |
|
Complement code the data. |
|
Find the centroid of complement coded data. |
|
Get the L1 norm of a vector using Numba. |
|
Get the squared L2 norm of a vector. |
|
Get the fuzzy AND operation between two vectors. |
|
Get argsort indices for elementwise fractions |
|
Get the index that maximizes the elementwise fractions |
|
Binarizes each feature in the data using thermometer encoding. |
Module Contents
- artlib.common.utils.IndexableOrKeyable
- artlib.common.utils.normalize(data: numpy.ndarray, d_max: numpy.ndarray | None = None, d_min: numpy.ndarray | None = None) Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]
Normalize data column-wise between 0 and 1.
- Parameters:
data (np.ndarray) – 2D array of dataset (rows = samples, columns = features).
d_max (np.ndarray, optional) – Maximum values for each column.
d_min (np.ndarray, optional) – Minimum values for each column.
- Returns:
np.ndarray – Normalized data.
np.ndarray – Maximum values for each column.
np.ndarray – Minimum values for each column.
- artlib.common.utils.de_normalize(data: numpy.ndarray, d_max: numpy.ndarray, d_min: numpy.ndarray) numpy.ndarray
Restore column-wise normalized data to original scale.
- Parameters:
data (np.ndarray) – Normalized data.
d_max (np.ndarray) – Maximum values for each column.
d_min (np.ndarray) – Minimum values for each column.
- Returns:
De-normalized data.
- Return type:
np.ndarray
- artlib.common.utils.complement_code(data: numpy.ndarray) numpy.ndarray
Complement code the data.
- Parameters:
data (np.ndarray) – Dataset.
- Returns:
complement coded data.
- Return type:
np.ndarray
- artlib.common.utils.de_complement_code(data: numpy.ndarray) numpy.ndarray
Find the centroid of complement coded data.
- Parameters:
data (np.ndarray) – Dataset.
- Returns:
De-complement coded data.
- Return type:
np.ndarray
- artlib.common.utils.l1norm(x: numpy.ndarray) float
Get the L1 norm of a vector using Numba.
- Parameters:
x (np.ndarray) – Input vector.
- Returns:
L1 norm.
- Return type:
- artlib.common.utils.l2norm2(data: numpy.ndarray) float
Get the squared L2 norm of a vector.
- Parameters:
data (np.ndarray) – Input vector.
- Returns:
Squared L2 norm.
- Return type:
- artlib.common.utils.fuzzy_and(x: numpy.ndarray, y: numpy.ndarray) numpy.ndarray
Get the fuzzy AND operation between two vectors.
- Parameters:
x (np.ndarray) – First input vector.
y (np.ndarray) – Second input vector.
- Returns:
Fuzzy AND result.
- Return type:
np.ndarray
- artlib.common.utils.fracsort(num: numpy.typing.ArrayLike, den: numpy.typing.ArrayLike) numpy.typing.NDArray[numpy.intp]
Get argsort indices for elementwise fractions
num[i] / den[i]without division.This function returns an index array that sorts the rational values exactly using cross-multiplication in a compiled C++ backend (no division is performed). Ties are broken by the lowest original index.
- Parameters:
num (ArrayLike) – 1D array-like of nonnegative numerators. Must be convertible to a contiguous NumPy array with dtype
np.uint32ornp.uint64.den (ArrayLike) – 1D array-like of denominators with
den[i] >= 1. Must be convertible to a contiguous NumPy array with dtypenp.uint32ornp.uint64and have the same shape and dtype asnum.
- Returns:
Indices that sort
num[i] / den[i]in ascending order, with ties broken by the lowest index.- Return type:
NDArray[np.intp]
- artlib.common.utils.fracargmax(num: numpy.typing.ArrayLike, den: numpy.typing.ArrayLike) numpy.intp
Get the index that maximizes the elementwise fractions
num[i] / den[i]without division.This function returns the index of the maximum rational value exactly using cross-multiplication in a compiled C++ backend (no division is performed). Ties are broken first by the larger denominator, then by the lowest original index.
- Parameters:
num (ArrayLike) – 1D array-like of nonnegative numerators. Must be convertible to a contiguous NumPy array with dtype
np.uint32ornp.uint64.den (ArrayLike) – 1D array-like of denominators with
den[i] >= 1. Must be convertible to a contiguous NumPy array with dtypenp.uint32ornp.uint64and have the same shape and dtype asnum.
- Returns:
Index
ithat maximizesnum[i] / den[i](descending). Ties are broken by larger denominator first, then the lowest index.- Return type:
np.intp
- artlib.common.utils.binarize_features_thermometer(data: numpy.ndarray, n_bits: int) numpy.ndarray
Binarizes each feature in the data using thermometer encoding.
- Parameters:
data (np.ndarray) – Input array of shape (n, m), where n is the number of samples and m is the number of features.
n_bits (int) – Number of bits to use for thermometer encoding.
- Returns:
- A thermometer-coded representation of the input data with
shape (n, m * n_bits).
- Return type:
np.ndarray