ruckus.convolution module¶
- class ruckus.convolution.ConvolutionalRKHS(window_shape=(2,), stride=(1,), rkhs=None, *, flatten_samples=True, flatten_features=False, copy_X=True)[source]¶
Bases:
ruckus.base.RKHS
Kernels can be applied directly to data, or as a filter to a convolution [1]. This class allows one to convolve an RKHS filter over \(N\mathrm{D}\) data.
The dimension of the sample indices is set by the length of the
window_shape
andstride
parameters, which must match. For instance, one can take a \(2\times 3\) dimension window over the first two dimensions of the data by settingwindow_shape = (2,3)
andstride=(1,1)
. After pulling the sliding window data, it is fitted to or transformed by therkhs
specified by the parameters.- Parameters
window_shape (
tuple
) – Default = (2,). Specifies the shape of the sliding window to be passed over the firstlen(window_shape)
axes of the data.stride (
tuple
) – Default = (1,). Specifies how many steps the window takes in each direction during the convolution.rkhs (
RKHS
orNone
) – Default =None
. Specifies theRKHS
to be applied to the convolved data. IfNone
, a baseRKHS
instance is generated.flatten_samples (
bool
) – Default =True
. IfTrue
, the axes which the window was applied to are flattened after the convolution. Ideal for passing to otherRKHS
instances which only recognize one sample dimension.flatten_features (
bool
) – Default =False
. IfTrue
, the original features ofX
and the new window axes are flattened together.copy_X (
bool
) – Default =True
. IfTrue
, inputX
is copied and stored by the model in theX_fit_
attribute. If no further changes will be done toX
, settingcopy_X=False
saves memory by storing a reference.
- Parameters
shape_in_ (
tuple
) – The required shape of the input datapoints, aka the shape of the domain space \(X\).shape_out_ (
tuple
) – The final shape of the transformed datapoints, aka the shape of the Hilbert space \(H\).X_fit_ (
numpy.ndarray
of shape (n_samples,)+self.shape_in_) – The data which was used to fit the model.
- fit(X, y=None)[source]¶
Fit the model from data in
X
.- Parameters
X (
numpy.ndarray
of shape(n_samples, n_features_1,...,n_features_d)
) – Training vector, wheren_samples
is the number of samples and(n_features_1,...,n_features_d)
is the shape of the input data. Must be consistent with preprocessing instructions in self.rkhs.take and self.rkhs.filter after convolution.- Returns
The instance itself
- Return type
RKHS
- fit_transform(X, y=None)[source]¶
Fit the model from data in
X
and transformX
.- Parameters
X (
numpy.ndarray
of shape(n_samples, n_features_1,...,n_features_d)
) – Training vector, wheren_samples
is the number of samples and(n_features_1,...,n_features_d)
is the shape of the input data. Must be consistent with preprocessing instructions in self.rkhs.take and self.rkhs.filter after convolution.- Returns
The transformed data
- Return type
numpy.ndarray
of shape(n_samples,)+self.shape_out_
- transform(X)[source]¶
Transform
X
.- Parameters
X (
numpy.ndarray
of shape(n_samples, n_features_1,...,n_features_d)
) – Data vector, wheren_samples
is the number of samples and(n_features_1,...,n_features_d)
is the shape of the input data. These must matchself.shape_in_
.- Returns
The transformed data
- Return type
numpy.ndarray
of shape(n_samples,)+self.shape_out_