CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
_thresholding.cpython-310.pyc164 linesDownload Raw Back to __pycache__
1o

2��Yi#�@sndZddlZddgZddd�Zddd�Zdd	d3�Zddd�Zdd
d�Zeeeeeed�Z	ddd�Z4dd�ZdS)z[5The thresholding helper module implements the most popular signal thresholding6functions.7�N�	threshold�threshold_firmcCs�t�|�}t�|�}tjdd��d||}|jdd|d�||}Wd�n1s-wY|dkr8|St�||�}t�|||�S)N�ignore��divide�r��min�max�out��np�asarray�absolute�errstate�clip�less�where��data�value�8substitute�	magnitude�thresholded�cond�r�|E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\pywt/_thresholding.py�softs91011�rcCs�t�|�}t�|�}tjdd��d|d|d}|jdd|d�||}Wd�n1s1wY|dkr<|St�||�}t�|||�S)zNon-negative Garrote.rrr�rNrrrrrr�12nn_garrote!s131415�rcCs*t�|�}t�t�|�|�}t�|||�S)N)r
rrrr)rrrrrrr�hard3s16r cC�2t�|�}t�|�rtd��t�t�||�||�S)Nz,greater thresholding only supports real data)r
r�iscomplexobj�17ValueErrorrr�rrrrrr�greater9�1819r%cCr!)Nz)less thresholding only supports real data)r
rr"r#rr%r$rrrr@r&r)rr r%rZgarroteZgarottec	CsLz	t||||�WSty%dd�tt���D�}td�d�|����w)a�20    Thresholds the input data depending on the mode argument.21 22    In ``soft`` thresholding [1]_, data values with absolute value less than23    `param` are replaced with `substitute`. Data values with absolute value24    greater or equal to the thresholding value are shrunk toward zero25    by `value`.  In other words, the new value is26    ``data/np.abs(data) * np.maximum(np.abs(data) - value, 0)``.27 28    In ``hard`` thresholding, the data values where their absolute value is29    less than the value param are replaced with `substitute`. Data values with30    absolute value greater or equal to the thresholding value stay untouched.31 32    ``garrote`` corresponds to the Non-negative garrote threshold [2]_, [3]_.33    It is intermediate between ``hard`` and ``soft`` thresholding.  It behaves34    like soft thresholding for small data values and approaches hard35    thresholding for large data values.36 37    In ``greater`` thresholding, the data is replaced with `substitute` where38    data is below the thresholding value. Greater data values pass untouched.39 40    In ``less`` thresholding, the data is replaced with `substitute` where data41    is above the thresholding value. Lesser data values pass untouched.42 43    Both ``hard`` and ``soft`` thresholding also support complex-valued data.44 45    Parameters46    ----------47    data : array_like48        Numeric data.49    value : scalar50        Thresholding value.51    mode : {'soft', 'hard', 'garrote', 'greater', 'less'}52        Decides the type of thresholding to be applied on input data. Default53        is 'soft'.54    substitute : float, optional55        Substitute value (default: 0).56 57    Returns58    -------59    output : array60        Thresholded array.61 62    See Also63    --------64    threshold_firm65 66    References67    ----------68    .. [1] D.L. Donoho and I.M. Johnstone. Ideal Spatial Adaptation via69        Wavelet Shrinkage. Biometrika. Vol. 81, No. 3, pp.425-455, 1994.70        DOI:10.1093/biomet/81.3.42571    .. [2] L. Breiman. Better Subset Regression Using the Nonnegative Garrote.72        Technometrics, Vol. 37, pp. 373-384, 1995.73        DOI:10.2307/126973074    .. [3] H-Y. Gao.  Wavelet Shrinkage Denoising Using the Non-Negative75        Garrote.  Journal of Computational and Graphical Statistics Vol. 7,76        No. 4, pp.469-488. 1998.77        DOI:10.1080/10618600.1998.1047478978 79    Examples80    --------81    >>> import numpy as np82    >>> import pywt83    >>> data = np.linspace(1, 4, 7)84    >>> data85    array([ 1. ,  1.5,  2. ,  2.5,  3. ,  3.5,  4. ])86    >>> pywt.threshold(data, 2, 'soft')87    array([ 0. ,  0. ,  0. ,  0.5,  1. ,  1.5,  2. ])88    >>> pywt.threshold(data, 2, 'hard')89    array([ 0. ,  0. ,  2. ,  2.5,  3. ,  3.5,  4. ])90    >>> pywt.threshold(data, 2, 'garrote')91    array([ 0.        ,  0.        ,  0.        ,  0.9       ,  1.66666667,92            2.35714286,  3.        ])93    >>> pywt.threshold(data, 2, 'greater')94    array([ 0. ,  0. ,  2. ,  2.5,  3. ,  3.5,  4. ])95    >>> pywt.threshold(data, 2, 'less')96    array([ 1. ,  1.5,  2. ,  0. ,  0. ,  0. ,  0. ])97 98    css�|]	}d|�d�VqdS)�'Nr)�.0�keyrrr�	<genexpr>�s�zthreshold.<locals>.<genexpr>z.The mode parameter only takes values from: {}.z, )�thresholding_options�KeyError�sorted�keysr#�format�join)rr�moderr.rrrrQsR99���cCs�|dkrtd��||krtd��t�|�}t�|�}tjdd��"||}|d|||}|jdd|d�||}Wd�n1sEwYt�||k�}t�|d�r^||||<|S)	a_Firm threshold.100 101    The approach is intermediate between soft and hard thresholding [1]_. It102    behaves the same as soft-thresholding for values below `value_low` and103    the same as hard-thresholding for values above `thresh_high`.  For104    intermediate values, the thresholded value is in between that corresponding105    to soft or hard thresholding.106 107    Parameters108    ----------109    data : array-like110        The data to threshold.  This can be either real or complex-valued.111    value_low : float112        Any values smaller then `value_low` will be set to zero.113    value_high : float114        Any values larger than `value_high` will not be modified.115 116    Notes117    -----118    This thresholding technique is also known as semi-soft thresholding [2]_.119 120    For each value, `x`, in `data`. This function computes::121 122        if np.abs(x) <= value_low:123            return 0124        elif np.abs(x) > value_high:125            return x126        elif value_low < np.abs(x) and np.abs(x) <= value_high:127            return x * value_high * (1 - value_low/x)/(value_high - value_low)128 129    ``firm`` is a continuous function (like soft thresholding), but is130    unbiased for large values (like hard thresholding).131 132    If ``value_high == value_low`` this function becomes hard-thresholding.133    If ``value_high`` is infinity, this function becomes soft-thresholding.134 135    Returns136    -------137    val_new : array-like138        The values after firm thresholding at the specified thresholds.139 140    See Also141    --------142    threshold143 144    References145    ----------146    .. [1] H.-Y. Gao and A.G. Bruce. Waveshrink with firm shrinkage.147        Statistica Sinica, Vol. 7, pp. 855-874, 1997.148    .. [2] A. Bruce and H-Y. Gao. WaveShrink: Shrinkage Functions and149        Thresholds. Proc. SPIE 2569, Wavelet Applications in Signal and150        Image Processing III, 1995.151        DOI:10.1117/12.217582152    rzvalue_low must be non-negative.z6value_high must be greater than or equal to value_low.rrrNr)r#r
rrrrr�any)rZ	value_lowZ153value_highrZvdiffrZ154large_valsrrrr�s$8�155156157�)r)rr)�__doc__�numpyr
�__all__rrr r%rr+rrrrrr�<module>s"158159160161162�163 164\
Aluode/PerceptionLabPortable · CoolFace