Example #1
0
waves = np.load(pwd + 'wf{}_{}.npy'.format(wf, scid))
plt.plot(waves[1000])
plt.show()
# =============================================================================
# Fit-Transforming PCA on acquired waves:
fitted = utils.pca_projections(waves, 3, svd_solver='arpack')
print('Fitted PCA: {}'.format(fitted.shape))
xs = fitted[:, 0]
ys = fitted[:, 1]
zs = fitted[:, 2]

utils.plot_3d_mod(xs,
                  ys,
                  zs,
                  title='wf{} {}'.format(wf, scid),
                  s=5,
                  edge='navy',
                  xlabel='PC1',
                  ylabel='PC2',
                  zlabel='PC3',
                  add_info='PAT{} ({})'.format(wf, scid))
if input('Satisfied? (y|N)\n') != 'y':
    raise Exception('Not satisified :(')
# =============================================================================
# Gaussian Mixture Models and, if needed, additional clustering
n_components = int(input('Type the number of components to split into: '))

fitted_copy = fitted

cluster_means, clusters, ns, ks, clusters_list = utils.gaussian_mixture_pca_projections(
    fitted,
    waves,
pwd = '/home/ov/data/stacked/'
# =============================================================================
# Load waves:
#stacked_waves = np.load(pwd_stacked_out)
stacked_waves = utils.load_waves_by_pat_scid([patient_nr], scid, pwd)
waves = utils.acces_waves_by_type(None, stacked_waves, wave_type)
print('Stacked size: {}'.format(stacked_waves.shape))
print('Unstacked {} waves: {}'.format(wave_type, waves.shape))
# =============================================================================
# Fit-Transforming PCA on acquired waves:
fitted = utils.pca_projections(waves, 3, svd_solver='arpack')
print('Fitted PCA: {}'.format(fitted.shape))
xs = fitted[:, 0]
ys = fitted[:, 1]
zs = fitted[:, 2]
"""
utils.plot_3d_mod(xs, ys, zs,
                    title='',
                    s=1,
                    edge = 'navy',
                    xlabel = 'PC1',
                    ylabel = 'PC2',
                    zlabel = 'PC3',
                    add_info = 'PAT{} ({})'.format(patient_nr, scid))
if input('Satisfied? (y|N)\n') != 'y':
    raise Exception('Not satisified :(')
"""
# =============================================================================
# Gaussian Mixture Models and, if needed, additional clustering
n_components = int(input('Type the number of components to split into: '))
Example #3
0
    #pwd_stacked = pwd + 'nfpat' + str(patid) + scid + '.stacked_icp_abp.npy'
    #stacked_by_pat = np.load(pwd_stacked)
    stacked_by_pat = load_waves_by_pat_scid([patid], scid, pwd)
    waves_by_pat = utils.acces_waves_by_type(None, stacked_by_pat, wave_type)
    fitted = utils.pca_projections(waves_by_pat, 3, svd_solver='arpack')
    print('Fitted PCA: {}'.format(fitted.shape))
    xs = fitted[:, 0]
    ys = fitted[:, 1]
    zs = fitted[:, 2]
    fig, ax = utils.plot_3d_mod(
        xs,
        ys,
        zs,
        title='',
        s=1,
        edge='navy',  #utils.default_colors[i],
        fig=fig,
        ax=ax,
        xlabel='PC1',
        ylabel='PC2',
        zlabel='PC3',
        add_info='PAT{} ({})'.format(patid, scid),
        pause_time=0.1)
    i += 1
plt.suptitle('PCA projection of entire {} data'.format(scid))
plt.show(block=False)
plt.pause(0.001)
"""
i = 0
pwd = pwd_stacked
face = 'none'
for patid in patids:
Example #4
0
        wf_waves = utils.load_waves(pwd + 'wf{}_{}.npy'.format(wf, scid),
                                    wf_waves)

        fitted = utils.pca_projections(wf_waves, 3, svd_solver='arpack')
        xs_list.append(fitted[:, 0])
        ys_list.append(fitted[:, 1])
        zs_list.append(fitted[:, 2])
# Test:
assert wf_types.shape[0] == waves.shape[0]

from sklearn.manifold import TSNE
embedded_waves = TSNE(n_components=3, verbose=1).fit_transform(waves)
embedded_waves.shape
fitted = embedded_waves

utils.plot_3d_mod(fitted[:, 0], fitted[:, 1], fitted[:, 2])
# =============================================================================
# Plot PCA proj. of ICP corresponding to each wf:
title = 'Projection of ICP waves corresponding to all {} wfs'.format(scid)
utils.stack_plot(xs_list, ys_list, zs_list, label_prefix='wf', title=title)
# =============================================================================
# Fit PCA and plot by scid
fitted = utils.pca_projections(waves, 3, svd_solver='arpack')
print('Fitted PCA: {}'.format(fitted.shape))
xs = fitted[:, 0]
ys = fitted[:, 1]
zs = fitted[:, 2]
figu, axu = utils.plot_3d_mod(
    xs,
    ys,
    zs,
Example #5
0
waves = utils.acces_waves_by_type(None, stacked_waves, wave_type)
print('Stacked size: {}'.format(stacked_waves.shape))
print('Unstacked {} waves: {}'.format(wave_type, waves.shape))
# =============================================================================
# Fit-Transforming PCA on acquired waves:
fitted = utils.pca_projections(waves, 3, svd_solver='arpack')
print('Fitted PCA: {}'.format(fitted.shape))
xs = fitted[:, 0]
ys = fitted[:, 1]
zs = fitted[:, 2]

utils.plot_3d_mod(xs, ys, zs,
                    title='PCA projection of {} waves of PAT{} ({})'.format(wave_type,
                                                                            patient_nr,
                                                                            scid),
                    s=1,
                    edge = 'navy',
                    xlabel = 'PC1',
                    ylabel = 'PC2',
                    zlabel = 'PC3',
                    add_info = 'PAT{} ({})'.format(patient_nr, scid))

if input('\nContinue to clustering? (y|N)\n') != 'y':
    raise Exception('Not satisified :(')
# =============================================================================
# Gaussian Mixture Models and, if needed, additional clustering
n_components = int(input('Type the number of components to split into: '))

cluster_means, clusters, ns, ks, clusters_list = utils.gaussian_mixture_pca_projections(
                                                fitted, waves, n_components,
                                                npat=patient_nr, scid=scid,
                                                wave_type=wave_type)
Example #6
0
# =============================================================================
# Plot PCA proj. of ICP corresponding to each wf:
title = 'Projection of ICP waves corresponding to all wfs'
utils.stack_plot(xs_list, ys_list, zs_list, label_prefix='scid', title=title)
# =============================================================================
# Fit PCA and plot
fitted = utils.pca_projections(waves, 3, svd_solver='arpack')
print('Fitted PCA: {}'.format(fitted.shape))
xs = fitted[:, 0]
ys = fitted[:, 1]
zs = fitted[:, 2]
figu, axu = utils.plot_3d_mod(xs,
                              ys,
                              zs,
                              title='all icp waves from selected wfs',
                              s=10,
                              edge='navy',
                              xlabel='PC1',
                              ylabel='PC2',
                              zlabel='PC3',
                              add_info='({})'.format(scid))

if input('\nSatisfied? (y|N)\n') != 'y':
    raise Exception('Not satisified :(')

# =============================================================================
# Gaussian Mixture Models OR HDBSCAN and, if needed, additional clustering *
decision = input('dbscan or gmm: ')
if decision == 'gmm':
    n_components = int(input('Type the number of components to split into: '))

    cluster_means, clusters, ns, ks, clusters_list = utils.gaussian_mixture_pca_projections(