ruckus.base.CompositeRKHS class¶
- class ruckus.base.CompositeRKHS(components, *, copy_X=True)[source]¶
Bases:
ruckus.base.RKHS
Given a sequence of RKHS’s with Hilbert spaces \(H_1\), …, \(H_n\) and feature maps \(\phi_1\), …, \(\phi_n\), their composition lives in the final Hilbert space \(H_n\) but has feature map \(\phi_n \circ \dots \circ \phi_1\) [1]. Correspondingly, a
CompositeRKHS
class has theshape_out_
of its final component, theshape_in_
of its first component, andtransform()
is applied to the data by implementingtransform
sequentially for each of the component spaces. This is useful for building pipelines and deep kernels.- Parameters
components (list of
RKHS
objects) – The componentRKHS
objects, listed from the first to be applied to the last.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.components[0].take and self.components[0].filter.- Returns
The instance itself
- Return type
- 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.components[0].take and self.components[0].filter.- Returns
The transformed data
- Return type
numpy.ndarray
of shape(n_samples,)+self.shape_out_
- kernel(X, Y=None)[source]¶
Evaluates the kernel on
X
andY
(orX
andX
) by iterating over component embeddings. As such,CompositeRKHS
kernels can only be evaluated after fitting to data.- 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_
.Y (
numpy.ndarray
of shape(n_samples, n_features_1,...,n_features_d)
) – Default =None
. 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_
. IfNone
,X
is used.
- Returns
The matrix
K[i,j] = k(X[i],Y[j])
- Return type
numpy.ndarray
of shape(n_samples_1,n_samples_2)
- 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_