CoolFace
Apppublic

Aluode/PerceptionLabPortable

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

2'�Yi��@s|ddlZddlZddlmZmZmZdd�Zddd�Z	dd	d3�Z4ddd�Zdd
d�Zddd�Z
ddd�Zdd�Zdd�ZdS)�N�)�5Covariance�_smart_eigh�compute_whitenercCsp|dus|dur6dS|dkr(t||j|d|dd�}t|||ddd�d}|S|d	kr4t|||�}|Std7��)z�Get restricting matrix to C_ref rank-dimensional principal subspace.8 9    Returns matrix of shape (rank, n_chs) used to restrict or10    restrict+rescale (whiten) covariances matrices.11    NZ	whiteningZbadsZprojsrT�error)�rankZpca�verboseZrestrictingzKrestr_type should either be callable or one of ('whitening', 'restricting'))rZch_namesr�_get_restr_mat�12ValueError)ZC_refZ13restr_type�inforZ	C_ref_cov�	restr_mat�r
�{E:\DocsHouse\542 percep lab latest\PerceptionLab\PerceptionLab_Portable\python_embed\Lib\site-packages\mne/decoding/_ged.py�_handle_restr_mats 14��15���rc	Csv|durtj�||�\}}||fS|||j}|||j}|dur)|||g�}tj�||�\}}|j|}||fS)a�Perform smart generalized eigenvalue decomposition (GED) of S and R.16 17    If restr_mat is provided S and R will be restricted to the principal subspace18    of a reference matrix with rank r (see _handle_restr_mat), then GED is performed19    on the restricted S and R and then generalized eigenvectors are transformed back20    to the original space. The g-eigenvectors matrix is of shape (n_chs, r).21    If callable R_func is provided the GED will be performed on (S, R_func(S,R))22    N)�scipy�linalgZeigh�T)	�S�RrZR_func�evals�evecsZS_restrZR_restr�evecs_restrr
r
r�23_smart_ged"s	24r�H�����z>cCs2|durdt�t�|��}tjj|||d�}|S)Nr)�rtol�atol)�np�max�absrrZissymmetric)�covrrZis_symmr
r
r�_is_cov_symm9sr cCsRtj�|�}|durdt�t�|��}t�||k�rdSt�||k�r'dSdS)z�Get definiteness of symmetric cov matrix.25 26    All evals in (-eval_tol, eval_tol) will be considered zero,27    while all evals smaller than -eval_tol will be considered28    negative.29    Nr�pos_def�pos_semidefZindef)rrZeigvalshrrr�all)r�eval_tolrr
r
r�_get_cov_def@sr%cCst||d�}|dvS)N�r$)r!r"�r%�rr$Zcov_defr
r
r�_is_cov_pos_semidefR�r)cCst||d�}|dkS)Nr&r!r'r(r
r
r�_is_cov_pos_defWr*r+c	s�ddlm}�dur!tdd�|D��}|std��||�\}}|Stdd�|D��}|s0td��t��fd	d�|D�t�}||�\}}t|j||�}�j|}|S)30a�Perform smart approximate joint diagonalization.31 32    If restr_mat is provided all the cov matrices will be restricted to the33    principal subspace of a reference matrix with rank r (see _handle_restr_mat),34    then GED is performed on the restricted S and R and then generalized eigenvectors35    are transformed back to the original space.36    The matrix of generalized eigenvectors is of shape (n_chs, r).37    �)�	_ajd_phamNcS�g|]}t|��qSr
)r+��.0rr
r
r�38<listcomp>h�z_smart_ajd.<locals>.<listcomp>zZIf C_ref is not provided by covariance estimator, all the covs should be positive definitecSr.r
)r)r/r
r
rr1rr2zSAll the covs should be positive semi-definite for approximate joint diagonalizationcsg|]	}�|�j�qSr
)rr/�rr
rr1xs)	Zcspr-r#r39r�array�float�_normalize_eigenvectorsr)	�covsr�weightsr-Zare_all_pos_defr�DZare_all_pos_semidefrr
r3r�40_smart_ajd\s&	��41r:cCs&t|||dddd�\}}}||}|S)zNGet matrix restricting covariance to rank-dimensional principal subspace of C.TF�data)Z
proj_subspaceZdo_compute_rankZlog_ch_type)r)�Crr�_Z	ref_evecs�maskrr
r
rr	s�r	cCsttj|d|d�}t|jd�D](}t�t�|dd�|fj|�|dd�|f�}|dd�|ft�|�<q|S)Nr)Zaxisr8r,)rZaverage�range�shape�dotr�sqrt)rr7Zsample_weightsZmean_cov�ii�tmpr
r
rr6�s42. r6)NN)rN)N)�numpyrZscipy.linalgrrrrrrrr r%r)r+r:r	r6r
r
r
r�<module>s434445464748#
Aluode/PerceptionLabPortable · CoolFace