API Reference#
A Distribution continuous random variable. |
|
Multivariate alpha stable distribution generator. |
|
Random number generation for Alpha Stable Distributions |
|
Statistics for Alpha Stable Distributions |
|
Machine Learning for Alpha Stable Distributions. |
- class aub_htp.AlphaStableKMeans(n_clusters: int = 8, alpha: float = 1.0, *, max_iter: int = 100, tol: float = 1e-06)#
Bases:
ClusterMixin,BaseEstimator- fit(X, y=None)#
- predict(X)#
- score(X, y=None, sample_weight=None)#
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') AlphaStableKMeans#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
Returns#
- selfobject
The updated object.
- class aub_htp.AlphaStableLinearRegressor(alpha: float = 1.0, *, max_iter: int = 5000, tol: float = 1e-06, optimizer: str = 'Powell')#
Bases:
RegressorMixin,BaseEstimatorScikit-learn compatible Alpha-stable linear regression.
Given \(\textbf{x}\) and \(\textbf{y}\) as training data, where \(\textbf{x}\) is a matrix of shape (n_samples, n_features) and \(\textbf{y}\) is a matrix of shape (n_samples, n_targets), the objective is to find the weights \(\textbf{w}\) and bias \(b\) that minimizes the loss function:
\[\mathrm{arg\,min}_{\mathbf{w}, b} P_\alpha(y - (\mathbf{x}\mathbf{w}^T + b))^\alpha\]- fit(X, y)#
- predict(X)#
- score(X, y, sample_weight=None)#
Return coefficient of determination on test data.
The coefficient of determination, \(R^2\), is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares
((y_true - y_pred)** 2).sum()and \(v\) is the total sum of squares((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.Parameters#
- Xarray-like of shape (n_samples, n_features)
Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape
(n_samples, n_samples_fitted), wheren_samples_fittedis the number of samples used in the fitting for the estimator.- yarray-like of shape (n_samples,) or (n_samples, n_outputs)
True values for X.
- sample_weightarray-like of shape (n_samples,), default=None
Sample weights.
Returns#
- scorefloat
\(R^2\) of
self.predict(X)w.r.t. y.
Notes#
The \(R^2\) score used when calling
scoreon a regressor usesmultioutput='uniform_average'from version 0.23 to keep consistent with default value ofr2_score(). This influences thescoremethod of all the multioutput regressors (except forMultiOutputRegressor).
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') AlphaStableLinearRegressor#
Configure whether metadata should be requested to be passed to the
scoremethod.Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with
enable_metadata_routing=True(seesklearn.set_config()). Please check the User Guide on how the routing mechanism works.The options for each parameter are:
True: metadata is requested, and passed toscoreif provided. The request is ignored if metadata is not provided.False: metadata is not requested and the meta-estimator will not pass it toscore.None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Parameters#
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weightparameter inscore.
Returns#
- selfobject
The updated object.
- class aub_htp.AlphaStablePCA(n_components: int = None, alpha: float = 1.0, *, shape_estimation_method: Literal['method1', 'method2', 'method3'] = 'method1')#
Bases:
TransformerMixin,BaseEstimator- components_: ndarray#
- fit(X, y=None)#
- fit_transform(X, y=None)#
Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Parameters#
- Xarray-like of shape (n_samples, n_features)
Input samples.
- yarray-like of shape (n_samples,) or (n_samples, n_outputs), default=None
Target values (None for unsupervised transformations).
- **fit_paramsdict
Additional fit parameters. Pass only if the estimator accepts additional params in its fit method.
Returns#
- X_newndarray array of shape (n_samples, n_features_new)
Transformed array.
- location_: ndarray#
- power_: ndarray#
- score(X, y=None)#
- shape_: ndarray#
- transform(X)#
- class aub_htp.AlphaStableShape(alpha: float = 1.0, alpha_kernel: float = None, alpha_data: float = None, method: Literal['method1', 'method2', 'method3'] = 'method1')#
Bases:
BaseEstimator- fit(X, y=None)#
- score(X, y=None)#
- class aub_htp.BaseSpectralMeasureSampler#
Bases:
ABCSpectral Measure Sampler is an interface to define the sampling algorithm for a spectral measure. The underlying mathematical spectral measure \(\Lambda\) has to uphold the following property:
\[\int_{\mathbb{S}^{d-1}}s\Lambda(ds)=0\]To create a custom spectral measure sampler, you need to inherit from this class and implement the following methods:
Example:
class CustomSpectralMeasureSampler(BaseSpectralMeasureSampler): def sample(self, number_of_samples: int, random_state: None | int | np.random.RandomState | np.random.Generator = None) -> np.ndarray: random_state = get_random_state_generator(random_state) return random_state.rand(number_of_samples, self.dimensions()) def dimensions(self) -> int: return 2 def mass(self) -> float: return 1.0
- abstractmethod dimensions() int#
Number of dimensions of the vector space of the spectral measure.
Returns#
dimensions : int
- abstractmethod sample(number_of_samples: int, random_state: None | int | RandomState | Generator = None) ndarray#
Sampling algorithm for the spectral measure sampler.
Parameters#
- number_of_samplesint
The number of samples to draw from the spectral measure.
- random_stateNone | int | np.random.RandomState | np.random.Generator, optional
The random state to use for the sampling. You are encouraged to use
aub_htp.random.get_random_state_generator()to get a random state generator as such:random_state = get_random_state_generator(random_state)
Returns#
- samplesnp.ndarray
The samples from the spectral measure.
- class aub_htp.DiscreteSampler(alpha: float, positions: ndarray, weights: ndarray)#
Bases:
BaseSpectralMeasureSampler- dimensions() int#
Number of dimensions of the vector space of the spectral measure.
Returns#
dimensions : int
- sample(number_of_samples: int, random_state: None | int | RandomState | Generator = None) ndarray#
Sampling algorithm for the spectral measure sampler.
Parameters#
- number_of_samplesint
The number of samples to draw from the spectral measure.
- random_stateNone | int | np.random.RandomState | np.random.Generator, optional
The random state to use for the sampling. You are encouraged to use
aub_htp.random.get_random_state_generator()to get a random state generator as such:random_state = get_random_state_generator(random_state)
Returns#
- samplesnp.ndarray
The samples from the spectral measure.
- class aub_htp.EllipticSampler(number_of_dimensions: int, alpha: float, sigma: ndarray, mass: float | None = None)#
Bases:
BaseSpectralMeasureSampler- dimensions() int#
Number of dimensions of the vector space of the spectral measure.
Returns#
dimensions : int
- sample(number_of_samples: int, random_state: None | int | RandomState | Generator = None) ndarray#
Sampling algorithm for the spectral measure sampler.
Parameters#
- number_of_samplesint
The number of samples to draw from the spectral measure.
- random_stateNone | int | np.random.RandomState | np.random.Generator, optional
The random state to use for the sampling. You are encouraged to use
aub_htp.random.get_random_state_generator()to get a random state generator as such:random_state = get_random_state_generator(random_state)
Returns#
- samplesnp.ndarray
The samples from the spectral measure.
- class aub_htp.IsotropicSampler(number_of_dimensions: int, alpha: float, gamma: float)#
Bases:
BaseSpectralMeasureSampler- dimensions() int#
Number of dimensions of the vector space of the spectral measure.
Returns#
dimensions : int
- sample(number_of_samples: int, random_state: None | int | RandomState | Generator = None) ndarray#
Sampling algorithm for the spectral measure sampler.
Parameters#
- number_of_samplesint
The number of samples to draw from the spectral measure.
- random_stateNone | int | np.random.RandomState | np.random.Generator, optional
The random state to use for the sampling. You are encouraged to use
aub_htp.random.get_random_state_generator()to get a random state generator as such:random_state = get_random_state_generator(random_state)
Returns#
- samplesnp.ndarray
The samples from the spectral measure.
- class aub_htp.MixedSampler(spectral_measures: list[BaseSpectralMeasureSampler], weights: ndarray)#
Bases:
BaseSpectralMeasureSampler- dimensions() int#
Number of dimensions of the vector space of the spectral measure.
Returns#
dimensions : int
- sample(number_of_samples: int, random_state: None | int | RandomState | Generator = None) ndarray#
Sampling algorithm for the spectral measure sampler.
Parameters#
- number_of_samplesint
The number of samples to draw from the spectral measure.
- random_stateNone | int | np.random.RandomState | np.random.Generator, optional
The random state to use for the sampling. You are encouraged to use
aub_htp.random.get_random_state_generator()to get a random state generator as such:random_state = get_random_state_generator(random_state)
Returns#
- samplesnp.ndarray
The samples from the spectral measure.
- class aub_htp.UnivariateSampler(alpha: float, beta: float, gamma: float)#
Bases:
BaseSpectralMeasureSampler- dimensions() int#
Number of dimensions of the vector space of the spectral measure.
Returns#
dimensions : int
- sample(number_of_samples: int, random_state: None | int | RandomState | Generator = None) ndarray#
Sampling algorithm for the spectral measure sampler.
Parameters#
- number_of_samplesint
The number of samples to draw from the spectral measure.
- random_stateNone | int | np.random.RandomState | np.random.Generator, optional
The random state to use for the sampling. You are encouraged to use
aub_htp.random.get_random_state_generator()to get a random state generator as such:random_state = get_random_state_generator(random_state)
Returns#
- samplesnp.ndarray
The samples from the spectral measure.
- aub_htp.alpha_location(data: ndarray, alpha: float) ndarray#
- aub_htp.alpha_power(data: ndarray, alpha: float) float#
- class aub_htp.alpha_stable_gen(momtype=1, a=None, b=None, xtol=1e-14, badvalue=None, name=None, longname=None, shapes=None, seed=None)#
Bases:
rv_continuous- cdf(x, *args, **kwds)#
Cumulative distribution function of the given RV.
Parameters#
- xarray_like
quantiles
- arg1, arg2, arg3,…array_like
The shape parameter(s) for the distribution (see docstring of the instance object for more information)
- locarray_like, optional
location parameter (default=0)
- scalearray_like, optional
scale parameter (default=1)
Returns#
- cdfndarray
Cumulative distribution function evaluated at x
- property parameterization#
- pdf(x, *args, **kwds)#
Probability density function at x of the given RV.
Parameters#
- xarray_like
quantiles
- arg1, arg2, arg3,…array_like
The shape parameter(s) for the distribution (see docstring of the instance object for more information)
- locarray_like, optional
location parameter (default=0)
- scalearray_like, optional
scale parameter (default=1)
Returns#
- pdfndarray
Probability density function evaluated at x
- rvs(*args, **kwds)#
Random variates of given type.
Parameters#
- arg1, arg2, arg3,…array_like
The shape parameter(s) for the distribution (see docstring of the instance object for more information).
- locarray_like, optional
Location parameter (default=0).
- scalearray_like, optional
Scale parameter (default=1).
- sizeint or tuple of ints, optional
Defining number of random variates (default is 1).
- random_state{None, int, numpy.random.Generator,
numpy.random.RandomState}, optional
If random_state is None (or np.random), the numpy.random.RandomState singleton is used. If random_state is an int, a new
RandomStateinstance is used, seeded with random_state. If random_state is already aGeneratororRandomStateinstance, that instance is used.
Returns#
- rvsndarray or scalar
Random variates of given size.
- with_parametrization(parametrization: Literal['S1', 'S0'])#
- aub_htp.get_random_state_generator(random_state: None | int | RandomState | Generator = None) Generator#
A scipy-compatible random state generator factory. This function is used to get a random state generator from a random state.
Parameters#
- random_stateNone | int | np.random.RandomState | np.random.Generator, optional
The random state to use for the sampling.
Returns#
- random_state_generatornp.random.Generator
The random state generator.
- aub_htp.l_alpha_loss(y, y_pred, *, alpha: float)#
- class aub_htp.multivariate_alpha_stable_gen(seed=None)#
Bases:
multi_rv_genericMultivariate alpha stable distribution generator.
This class provides the SciPy-compatible rvs interface for sampling multivariate alpha-stable law, and a pdf wrapper that caches the last computed density model so repeated evaluations reuse expensive internal precomputations.
- pdf(x: ArrayLike, alpha: float, spectral_measure_sampler: BaseSpectralMeasureSampler | Literal['standard_isotropic_2d', 'standard_isotropic_3d', '1x2_elliptic_2d', '1x2x4_elliptic_3d', 'coin_flip_discrete'] = 'standard_isotropic_2d', shift: ArrayLike = 0.0, number_of_spectral_samples: int = 200000, number_of_sphere_points: int | None = None, random_state: None | int | RandomState | Generator = None, exact: bool = False, sphere_method: str = 'sobol', antipodal: bool = False) NDArray#
Evaluate the multivariate alpha-stable density at point(s) x.
The method reuses the last computed internal density model when the pdf parameters are identical to the previous call. This preserves the costly MultivariateStableDensity setup for repeated evaluations.
- rvs(alpha: float, spectral_measure_sampler: BaseSpectralMeasureSampler | Literal['standard_isotropic_2d', 'standard_isotropic_3d', '1x2_elliptic_2d', '1x2x4_elliptic_3d', 'coin_flip_discrete'] = 'standard_isotropic_2d', shift: ndarray = 0, size: int | None = None, error: float = 0.01, random_state: None | int | RandomState | Generator = None)#
Sample from a multivariate alpha stable distribution.
Parameters#
- alphafloat
The alpha parameter of the alpha stable distribution.
- spectral_measure_samplerBaseSpectralMeasureSampler or str
The spectral measure sampler to use.
- shiftnp.ndarray
The shift vector to apply to the samples.
- sizeint or tuple of ints, optional
Defines the shape of the returned array. Default is 1.
- random_stateint or None, optional
Random state to use for the random number generator.
Returns#
- samplesndarray
Samples from the multivariate alpha stable distribution.
Raises#
- ValueError
If the spectral measure sampler is not supported.
- aub_htp.r_alpha_score(y, y_pred, *, alpha: float) float#
- aub_htp.sample_alpha_stable_vector(alpha: float, spectral_measure: BaseSpectralMeasureSampler, number_of_samples: int = 1, shift_vector: ndarray = 0, max_number_of_convergence_terms: int = 50000, error: float = 0.01, random_state: None | int | RandomState | Generator = None)#