CoolFace
Apppublic

Aluode/PerceptionLabPortable

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

2'�Yi��@sVddlZddlZddlmZddlmZdd�Zddd�Zej	fd	d3�Z4ddd
�ZdS)�N)�hilbert)�	logsumexpcCst�t|��tjdtjS)a.Compute normalized phase angles.5 6    Parameters7    ----------8    data : ndarray, shape (n_epochs, n_sources, n_times)9        The data to compute the phase angles for.10 11    Returns12    -------13    phase_angles : ndarray, shape (n_epochs, n_sources, n_times)14        The normalized phase angles.15    �)�npZangler�pi)�data�r��E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\mne/preprocessing/ctps_.py�_compute_normalized_phases
r16Tc	Cs�|jdkstd|j�d���|rt|�}n|}t�|d�}t�|d�}tt�|gd���D]\}}t|�\}}|||dd�f<|||dd�f<q/|||rQ|fSdfS)a�Compute cross-trial-phase-statistics [1].17 18    Note. It is assumed that the sources are already19    appropriately filtered20 21    Parameters22    ----------23    data: ndarray, shape (n_epochs, n_channels, n_times)24        Any kind of data of dimensions trials, traces, features.25    is_raw : bool26        If True it is assumed that data haven't been transformed to Hilbert27        space and phase angles haven't been normalized. Defaults to True.28 29    Returns30    -------31    ks_dynamics : ndarray, shape (n_sources, n_times)32        The kuiper statistics.33    pk_dynamics : ndarray, shape (n_sources, n_times)34        The normalized kuiper index for ICA sources and35        time slices.36    phase_angles : ndarray, shape (n_epochs, n_sources, n_times) | None37        The phase values for epochs, sources and time slices. If ``is_raw``38        is False, None is returned.39 40    References41    ----------42    [1] Dammers, J., Schiek, M., Boers, F., Silex, C., Zvyagintsev,43        M., Pietrzyk, U., Mathiak, K., 2008. Integration of amplitude44        and phase statistics for complete artifact removal in independent45        components of neuromagnetic recordings. Biomedical46        Engineering, IEEE Transactions on 55 (10), 2353-2362.47    �z!Data must have 3 dimensions, not �.r)�rrN)�ndim�48ValueErrorr49rZ50zeros_like�	enumerateZ	transpose�kuiper)	rZis_rawZphase_anglesZks_dynamicsZpk_dynamics�ii�source�ks�pkrrr	�ctpss51!52rcCs�tj|dd��|�}|j}t|�}|d}tj||d�dt|�}tj||d�t|�}|dkrC|dd�tjf}|dd�tjf}||jdd�}||jdd�}|}	||}53|54t	|55|	|d�fS)awKuiper's test of uniform distribution.56 57    Parameters58    ----------59    data : ndarray, shape (n_sources,) | (n_sources, n_times)60           Empirical distribution.61    dtype : str | obj62        The data type to be used.63 64    Returns65    -------66    ks : ndarray67        Kuiper's statistic.68    pk : ndarray69        Normalized probability of Kuiper's statistic [0, 1].70    r)�axis)�dtype��?r
N)71r�sortZastype�shape�len�arange�floatZnewaxis�max�_prob_kuiper)rrrZn_dimZn_trialsZj1�j2Zd1Zd2�n_eff�drrr	rRsr�f8c
Cs�t�|�}d}t�|�}|dd||}|d}t�|�dd}|�|��||�}d||d}	d	||}72d|	}t|73|d74d�d|}t�|dkd
|�}t�|dkd|�}|S)a�Test for statistical significance against uniform distribution.75 76    Parameters77    ----------78    d : float79        The kuiper distance value.80    n_eff : int81        The effective number of elements.82    dtype : str | obj83        The data type to be used. Defaults to double precision floats.84 85    Returns86    -------87    pk_norm : float88        The normalized Kuiper value such that 0 < ``pk_norm`` < 1.89 90    References91    ----------92    [1] Stephens MA 1970. Journal of the Royal Statistical Society, ser. B,93    vol 32, pp 115-122.94 95    [2] Kuiper NH 1962. Proceedings of the Koninklijke Nederlands Akademie96    van Wetenschappen, ser Vol 63 pp 38-4797    �dgףp=98��?g���Q��?g@r
rg@rg�r)�brg�������?g)	r�size�math�sqrtr�repeatZreshaper�where)
r#r"rZ
n_time_slicesZn_points�enZk_lambda�l2r!Zfact�ar&Zpk_normrrr	r ys99100r )T)r$)r(�numpyrZscipy.signalrZ
scipy.specialrr101rZfloat64rr rrrr	�<module>s1026'
Aluode/PerceptionLabPortable · CoolFace