```python= from sklearn.model_selection import KFold def examplar_epoch_data(epochs_in, N, navg): epo = epochs_in.copy()[range(N)] fold_num = N // navg if N % navg > 0: fold_num += 1 X1 = epo.get_data() # signals: n_epochs, n_channels, n_times y1 = epo.events[:, 2] n_trl, n_ch, n_times = epo.get_data().shape kf = KFold(n_splits=fold_num, shuffle= True) kf_idx = [x for x in kf.split(X1, y1)] train_y = [y1[x[0]] for x in kf_idx] # get y labels of each training-fold test_y = [x[1] for x in kf_idx] # get y labels of each testing-fold exampler_data = np.zeros((fold_num, n_ch, n_times)) for i in range(fold_num): temp = epo[test_y[i]].average().data exampler_data[i,:,:] = temp pass y = np.ones(fold_num) return exampler_data, y def decode_logit(epo1, epo2, navg): n_c1 = epo1.get_data().shape[0] n_c2 = epo2.get_data().shape[0] N = min([n_c1, n_c2]) examplar_data_c1, y1 = examplar_epoch_data(epo1, N, navg) examplar_data_c2, y2 = examplar_epoch_data(epo2, N, navg) X = np.concatenate((examplar_data_c1, examplar_data_c2), axis = 0) y = [1] * len(y1) + [2] * len(y2) clf = make_pipeline(StandardScaler(), SVC(kernel='linear',gamma='auto')) #LinearModel(LogisticRegression(solver='lbfgs'))) time_decod = SlidingEstimator(clf, n_jobs=1, scoring='roc_auc', verbose = False) scores = cross_val_multiscore(time_decod, X, y, cv=5, n_jobs=-1) # Mean scores across cross-validation splits scores = np.mean(scores, axis=0) fig, ax = plt.subplots() ax.plot(epo1.times, scores, label='score') ax.axhline(.5, color='k', linestyle='--', label='chance') ax.set_xlabel('Times') ax.set_ylabel('AUC') # Area Under the Curve ax.legend() ax.axvline(.0, color='k', linestyle='-') ax.set_title('Sensor space decoding') return scores epo1 = epochs['Auditory/Left'] epo2 = epochs['Visual/Left'] scores = decode_logit(epo1, epo2, 4) ``` # dementia project, envelop connectivity ```bash=1 conda install -c conda-forge mne-connectivity ``` # MNE python 維護 (2022/06/28, Mac M1 Max) https://mne.tools/stable/install/manual_install.html ```bash=1 conda install --channel=conda-forge --name=base mamba mamba create --override-channels --channel=conda-forge --name=mne ``` ## (old macbook pro)Upgrading all packages Generally speaking, if you want to upgrade your whole software stack including all the dependencies, the best approach is to re-create it as a new virtual environment, because neither conda nor pip are fool-proof at making sure all packages remain compatible with one another during upgrades. Here we’ll demonstrate renaming the old environment first, as a safety measure. We’ll assume that the existing environment is called mne and you want to rename the old one so that the new, upgraded environment can be called mne instead. Unfortunately conda doesn’t have a “rename” command so we’ll first clone the old one with a new name (old_mne), then delete the original, then create the new, updated environment re-using the original name. In the first step we’ll also use conda in --offline mode so that it uses cached copies of all the packages instead of re-downloading them. ```bash=1 conda create --name old_mne --clone mne --offline # copy with new name, conda env remove --name mne --all # remove original, conda create --name mne --channel conda-forge mne # replace with updated ``` ```bash=4 conda install --name=base nb_conda_kernels # to use Jupyter notebook conda install -c conda-forge notebook ``` To use Alice dataset for Eelbrain ```bash=6 conda install -c conda-forge eelbrain conda install -c conda-forge jupytext pip install https://github.com/christianbrodbeck/TRF-Tools/archive/win.zip pip install https://github.com/christianbrodbeck/gammatone/archive/fmax.zip ``` ```bash=7 pip install fathon # DFA pip install emd # ``` Added `ipywidgets` to avoid `ImportError: IProgress not found. Please update jupyter and ipywidgets ```bash= conda install -c conda-forge ipywidgets ``` # using WSL issues about launching X Display https://ripon-banik.medium.com/run-x-display-from-wsl-f94791795376 # TO DO Install libeemd, pyemd, emd