ruckus.base.ProductRKHS class¶
- class ruckus.base.ProductRKHS(factors, *, copy_X=True)[source]¶
Bases:
ruckus.base.RKHSGiven a sequence of RKHS’s with Hilbert spaces \(H_1\), …, \(H_n\) and feature maps \(\phi_1\), …, \(\phi_n\), their composition lives in the tensor product Hilbert space \(H_1\otimes \dots \otimes H_n\) and has feature map \(\phi_1 \otimes \dots \otimes \phi_n\) [1]. Correspondingly, the
shape_out_of aProductRKHSinstance is the tuple-sum of theshape_out_tuples of its factors, while all its factors share the sameshape_in_.Product RKHS’s are particularly useful for working with kernel embeddings of distributions and their conditional probabilities [2]. A
ProductRKHScan be reduced to its marginal along a set of factors using themarginal()method, and can be reduced into a marginal space paired with a ridge-regressed conditional map using theconditional()method.- Parameters
factors (list of
RKHSobjects) – The factorRKHSobjects, listed in the order that their dimensions will appear in indexing.copy_X (
bool) – Default =True. IfTrue, inputXis copied and stored by the model in theX_fit_attribute. If no further changes will be done toX, settingcopy_X=Falsesaves 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.ndarrayof shape (n_samples,)+self.shape_in_) – The data which was used to fit the model.
- conditional(predictor_inds, response_inds, regressor=None, alpha=1.0)[source]¶
Returns a pair of outputs, the first being a
sklearn.pipelines.Pipelineconsisting of the marginal RKHS ofpredictor_indsand a regressor which represents the conditional distribution embedding, and the second being the marginal RKHS ofresponse_inds.For two systems \(X\) and \(Y\), embedded in Hilbert spaces \(H_1\) and \(H_2\) respectively, the conditional distribution embedding is a linear map \(C_{Y|X}:H_1\rightarrow H_2\) such that \(C_{Y|X}\phi_1(x)\) gives the kernel embedding of the distribution of \(Y\) conditioned on \(X=x\). This is typically determined by using a ridge regression, though we allow the user to pass a custom regressor for model selection purposes. See [1] for details.
- Parameters
predictor_inds (
array-like ofint) – List of indices of the factors inself.factorson which theresponse_indswill be conditioned.response_inds – List of indices of the factors in
self.factorswhich are to be conditioned on thepredictor_inds.regressor (
sklearn.base.BaseEstimator) – The regressor object to use to fit the conditional embedding. IfNone, asklearn.linear_model.Ridgeinstance is used withfit_intercept=Falseandalphaspecified below.alpha (float) – The ridge parameter used in the default Ridge regressor.
- Returns
(
pipe,``response``), wherepipeis a pipeline consisting of the marginal ofpredictor_indsand the fittedregressor, andresponseis the marginal ofresponse_inds.- Return type
(
sklearn.pipelines.Pipeline,ProductRKHS)
- fit(X, y=None)[source]¶
Fit the model from data in
X.- Parameters
X (
numpy.ndarrayof shape(n_samples, n_features_1,...,n_features_d)) – Training vector, wheren_samplesis 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 fac.take and fac.filter for each fac in self.factors.- Returns
The instance itself
- Return type
- kernel(X, Y=None)[source]¶
Evaluates the kernel on
XandY(orXandX) by multiplying the kernels of the factors.- Parameters
X (
numpy.ndarrayof shape(n_samples, n_features_1,...,n_features_d)) – Data vector, wheren_samplesis 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.ndarrayof shape(n_samples, n_features_1,...,n_features_d)) – Default =None. Data vector, wheren_samplesis the number of samples and(n_features_1,...,n_features_d)is the shape of the input data. These must matchself.shape_in_. IfNone,Xis used.
- Returns
The matrix
K[i,j] = k(X[i],Y[j])- Return type
numpy.ndarrayof shape(n_samples_1,n_samples_2)
- marginal(var_inds, copy_X=False)[source]¶
Construct a
ProductRKHSfrom only the factors specified byvar_inds. Only to be used ifProductRKHSis already fit, and you’d rather not fit again.- Parameters
var_inds (
array-like ofint) – List of indices of the factors inself.factorsfrom which to the marginalProductRKHS.copy_X (
bool) – Default =True. IfTrue, inputself.X_fit_is copied and stored as the new model’sX_fit_attribute. If no further changes will be done toX, settingcopy_X=Falsesaves memory by storing a reference.
- Returns
The marginal
ProductRKHSof thevar_inds.- Return type
ProductRKHS
- transform(X)[source]¶
Transform
X.- Parameters
X (
numpy.ndarrayof shape(n_samples, n_features_1,...,n_features_d)) – Data vector, wheren_samplesis 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.ndarrayof shape(n_samples,)+self.shape_out_