RBFTransformer
RBFTransformer
- class RBFTransformer(centers=None, gamma=1.0, rbf_type='gaussian', apply_to='index', use_torch=False)[source]
A custom transformer to apply Radial Basis Functions (RBFs) to time series data.
This transformer allows the user to apply various RBF kernels such as Gaussian, multiquadric, and inverse multiquadric to time series data. The transformation generates new features that augment the input data based on the distances between time points and specified center points, offering a flexible and non-linear feature representation for machine learning models.
This implementation is inspired by the RepeatingBasisFunction transformer from the scikit-lego package: https://github.com/koaning/scikit-lego/blob/main/sklego/preprocessing/repeatingbasis.py
Mathematical Background: Consider a time series with time stamps \(t_1, t_2, \dots, t_N\)-
The transformation computes the kernel distance between the time points and a set of predefined “center points” \(c_1, \dots, c_K\). For each time point \(t_i\), the RBF is computed between \(t_i\) and every center point \(c_k\), producing a matrix of transformed values. Each kernel function depends on the distance between a time point and a center point.
Mathematically, the transformation for the Gaussian RBF is defined as:
\(\phi(t_i, c_k) = \exp(-\gamma (t_i - c_k)^2)\)
where \(\gamma\) is a scaling factor controlling the spread of the RBF.
Additional types of RBFs are available:
- Multiquadric:
\(\phi(t_i, c_k) = \sqrt{1 + \gamma (t_i - c_k)^2}\)
- Inverse Multiquadric:
\(\phi(t_i, c_k) = \frac{1}{\sqrt{1 + \gamma (t_i - c_k)^2}}\)
These transformations produce new features for each time point, enhancing the representational power of the data by adding non-linear transformations that account for proximity to center points.
- Parameters:
- centersarray-like, shape (n_centers,), optional (default=None)
The centers \(c_k\) of the RBFs. These define the points against which the distances from the input data are measured. If None, the centers will be evenly spaced over the range of the input data.
- gammafloat, optional (default=1.0)
The spread or scaling factor \(\gamma\) that controls the influence range of each RBF center. Larger values of \(\gamma\) make the RBF sharper (smaller spread), while smaller values make the RBF smoother.
- rbf_type{“gaussian”, “multiquadric”, “inverse_multiquadric”},
optional (default=”gaussian”)
The type of radial basis function to apply:
“gaussian”: \(\exp(-\gamma (t - c)^2)\)
“multiquadric”: \(\sqrt{1 + \gamma (t - c)^2}\)
“inverse_multiquadric”: \(\frac{1}{\sqrt{1 + \gamma (t - c)^2}}\)
- apply_to{“index”, “values”}, optional (default=”index”)
Determines whether the RBFs are applied to the time index or to the values of the time series.
“index”: Apply the RBFs to the time index.
“values”: Apply the RBFs to the values of the time series.
- use_torchbool, optional (default=False)
Whether to use torch for the RBF calculations. If True, the transformer will use PyTorch for the RBF calculations, if present. If not, will fall back to NumPy. If False, it will use NumPy.
- Attributes:
- fitted_centers_array-like, shape (n_centers_,)
The centers that are used for the RBF transformation. These are either provided by the user or computed from the data during fitting.
- torch_available_bool
Indicates if PyTorch is available. This is checked during fit.
Methods
check_is_fitted([method_name])Check if the estimator has been fitted.
clone()Obtain a clone of the object with same hyper-parameters and config.
clone_tags(estimator[, tag_names])Clone tags from another object as dynamic override.
create_test_instance([parameter_set])Construct an instance of the class, using first test parameter set.
create_test_instances_and_names([parameter_set])Create list of all test instances and a list of names for them.
fit(X[, y])Fit transformer to X, optionally to y.
fit_transform(X[, y])Fit to data, then transform it.
get_class_tag(tag_name[, tag_value_default])Get class tag value from class, with tag level inheritance from parents.
get_class_tags()Get class tags from class, with tag level inheritance from parent classes.
get_config()Get config flags for self.
get_fitted_params([deep])Get fitted parameters.
get_param_defaults()Get object's parameter defaults.
get_param_names([sort])Get object's parameter names.
get_params([deep])Get a dict of parameters values for this object.
get_tag(tag_name[, tag_value_default, ...])Get tag value from instance, with tag level inheritance and overrides.
get_tags()Get tags from instance, with tag level inheritance and overrides.
get_test_params()Return test parameter sets for the transformer.
inverse_transform(X[, y])Inverse transform X and return an inverse transformed version.
is_composite()Check if the object is composed of other BaseObjects.
load_from_path(serial)Load object from file location.
load_from_serial(serial)Load object from serialized memory container.
reset()Reset the object to a clean post-init state.
save([path, serialization_format])Save serialized self to bytes-like object or to (.zip) file.
set_config(**config_dict)Set config flags to given values.
set_params(**params)Set the parameters of this object.
set_random_state([random_state, deep, ...])Set random_state pseudo-random seed parameters for self.
set_tags(**tag_dict)Set instance level tag overrides to given values.
transform(X[, y])Transform X and return a transformed version.
update(X[, y, update_params])Update transformer with X, optionally y.

