Anamorphosis🍋
Gaussian anamorphosis: Gaussian scores of a sample and their Hermite expansion.
Gaussian scores
By default (GaussScoreMethod.RANK), the i-th smallest of n valid values gets
the score norm.ppf((i - 0.5) / n), the Hazen plotting position used by the
GSLIB nscore program. Tied values share their average rank, hence their
score. NaN values are ignored and keep a NaN score.
With declustering weights , e.g. from cell_declustering, each
value gets the middle of its step of the weighted cumulative distribution,
as in nscore: norm.ppf((W_before + w_i / 2) / W), where W_before is
the total weight of the smaller values and W the total weight. Tied
values share the middle of their joint step. Without weights, or with
equal weights, these are the rank scores above.
Tails
Rank scores stay within ±norm.ppf(1 - 0.5 / n): ±2.58 for 100 values,
±3.29 for 1,000, ±3.89 for 10,000 and ±4.89 for 1,000,000. Beyond the
extreme scores the anamorphosis is constant: the empirical transforms
return the data minimum and maximum, and the Hermite coefficients are
fitted to a piece-wise linear anamorphosis extended by these constant
values. Anamorphosis.theoretical_inverse_transform searches Gaussian
values within ±5.2. With weights, the extreme scores are
±norm.ppf(1 - w / (2 W)), where w is the weight of the extreme value:
a declustered value with a small weight gets a more extreme score.
GaussScoreMethod.QUANTILE_TRANSFORM is the default of GeoLime 2.x and
earlier, the scikit-learn quantile transform with at most 1000
quantiles. It always maps the data minimum and maximum to ±5.2 whatever
the sample size, interpolates the scores of the most extreme 0.1% of the
data between the last two quantiles, and only uses a random subsample
of 100,000 values on larger datasets, values beyond the subsample range
sharing the score ±5.2. On skewed data this biases the variance of the
Hermite expansion, hence the change of support coefficient and the
uniform conditioning results. For lognormal samples with a log standard
deviation of 1, it is 3% to 27% too low with 1,000 values, 15% to 65%
too high with 100,000 values and 30% to 300% too high with 1,000,000
values, and the error grows with skewness. Rank scores keep it within 4%
of the data variance from 1,000 values on.
Anamorphosis
🍋
Anamorphosis class.
Allows to transform skew data into standardize data. Transformation is bijective in the interval defined by the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ndarray
|
Numpy array containing the data. |
required |
gauss_scores
|
ndarray | None
|
Option to use the Gaussian scores of the sample as an input
directly. By default None. If None, the Gaussian scores will
be obtained with |
None
|
gauss_score_method
|
GaussScoreMethod
|
Method used to compute the Gaussian scores when
gauss_scores is None, see |
RANK
|
weights
|
ndarray | None
|
Declustering weights used to compute the Gaussian scores
when gauss_scores is None, see |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
data |
Vector
|
Data in real space. |
gauss_scores |
Vector
|
Data in gaussian space. |
hermite_coefficients |
ndarray
|
Coefficients of hermite polynomials used to transform data from real to gaussian. |
gauss_scores
property
🍋
hermite_coefficients
property
🍋
Return coefficients of Hermite Polynomials transform function.
Returns:
| Type | Description |
|---|---|
ndarray
|
Coefficients of Hermite polynomials. |
empirical_inverse_transform(x)
🍋
empirical_transform(x)
🍋
theoretical_inverse_transform(x, r=1.0)
🍋
Compute the gaussian inverse anamorphosis of the input array using an interpolation with Hermite polynomials of the gaussian scores. Obtained values are approximates from results of transform gausian values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input array containing values in reel space. |
required |
r
|
float
|
Change of support coefficient. |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Transformed array = gaussian values. |
theoretical_transform(x, r=1.0)
🍋
Compute the gaussian anamorphosis of the input array using an interpolation with Hermite polynomials of the gaussian scores.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
ndarray
|
Input array containing values in gaussian space. |
required |
r
|
float
|
Change of support coefficient. |
1.0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
Transformed array = real values. |
gauss_score(z, method=GaussScoreMethod.RANK, weights=None)
🍋
Function to obtain the (standard) Gaussian scores of a sample.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
Vector
|
numpy array containing the data. |
required |
method
|
GaussScoreMethod
|
How the scores are computed. By default
|
RANK
|
weights
|
Vector | None
|
Declustering weights, one per element of z, e.g. from
|
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
A numpy array that contains the Gaussian scores. |
Raises:
| Type | Description |
|---|---|
ValueError
|
|
NaN values
NaN values are filtered out before performing the gaussian score computation.
Tails
Rank scores stay within ±norm.ppf(1 - 0.5 / n), e.g. ±3.29 for
1,000 values. The quantile transform always maps the data minimum
and maximum to ±5.2 and compresses the scores of the most extreme
0.1% of the data, which biases the anamorphosis of skewed data. See
the module documentation above for details.
Changed in 3.0.0
Gaussian scores are rank-based by default. Pass
method=GaussScoreMethod.QUANTILE_TRANSFORM to reproduce the scores
of GeoLime 2.x.