conditional_kde.util module¶
Important utilities.
- class conditional_kde.util.DataWhitener(algorithm='rescale')[source]¶
Bases:
objectWhitening of the data.
Implements several algorithms, depending on the desired whitening properties.
- Parameters:
algorithm (str) – either None, “center”, “rescale”, “PCA” or “ZCA”. None - leaves the data as is. center - calculates mean in every dimension and removes it from the data. rescale - calculates mean and standard deviation in each dimension and rescales it to zero-mean, unit-variance. In the absence of high correlations between dimensions, this is often sufficient. PCA - data is transformed into its PCA space and divided by the standard deviation of each dimension. ZCA - equivalent to the “PCA”, with additional step of rotating back to original space, i.e. the orientation of space is preserved.
- fit(X, weights=None, save_data=False)[source]¶
Fitting the whitener on the data X.
- Parameters:
X (array) – of shape (n_samples, n_dim).
weights (array) – of shape (n_samples,), weights of each sample in X.
save_data (bool) – if True, saves the data and whitened data as self.data, self.whitened_data.
- Returns:
Whitened array.
- class conditional_kde.util.Interpolator(points, values=None, method='linear', bounds_error=True, fill_value=nan)[source]¶
Bases:
RegularGridInterpolatorRegular grid interpolator.
Inherits from scipy.interpolate.RegularGridInterpolator. The difference with respect to the original class is to make weights and edges explicitly visible, for the more general usage case.
- Parameters:
points (list) – list of lists, where every sub-list defines the grid points.
values (array) – array of function values to interpolate. If not given, Interpolator won’t return any values, only weights and edges.
method (str) – either “linear” or “nearest”, defining the interpolation method. As the name says, “linear” returns linearly interpolated value and “nearest” only the nearest value on the grid.
bounds_error (bool) – either to raise an error if the point for which interpolation is requested is out of the grid bounds.
fill_value (float) – value to be filled for out of the grid points.
- __call__(xi, method=None, return_aux=True)[source]¶
Interpolation at coordinates.
If values were not passed during initialization, it doesn’t interpolate but returns grid coordinates and weights only.
- Parameters:
xi (array) – the coordinates to sample the gridded data at, of shape (…, ndim).
method (str) – The method of interpolation to perform. Supported are “linear” and “nearest”.
return_aux (bool) – If True, return includes grid coordinates and weights.
- Returns:
If function values were set during initialization, returns an array of interpolated values. If return_aux is True it will further return grid coordinates for every item in xi. In the case method is “nearest”, this will be only one relevant coordinate per xi sample, or multiple ones for “linear” method. For the latter, also weights of every coordinate will be returned.