kilosort_folder_denoised,
    tsne_cortex_folder,
    spikes_used_with_original_indexing=spikes_in_cortex)
num_dims = 2
perplexity = 100
theta = 0.3
iterations = 4000
random_seed = 1
verbose = 2
exe_dir = r'E:\Software\Develop\Source\Repos\spikesorting_tsne_bhpart\Barnes_Hut\win\x64\Release'

tsne_results = tsne.t_sne(template_features,
                          files_dir=tsne_cortex_folder,
                          exe_dir=exe_dir,
                          num_dims=num_dims,
                          perplexity=perplexity,
                          theta=theta,
                          iterations=iterations,
                          random_seed=random_seed,
                          verbose=verbose)

tsne_results = tsne.t_sne_from_existing_distances(files_dir=tsne_cortex_folder,
                                                  data_has_exageration=True,
                                                  num_dims=num_dims,
                                                  theta=theta,
                                                  iterations=iterations,
                                                  random_seed=random_seed,
                                                  verbose=verbose,
                                                  exe_dir=exe_dir)

spike_info = preproc_kilo.generate_spike_info_from_full_tsne(
spike_rates_binary_0p1 = spike_rates_binary_0p1.transpose()

pca_sr_bin_0p1 = PCA()
pcs_ar_bin_0p1 = pca_sr_bin_0p1.fit_transform(spike_rates_binary_0p1)

number_of_top_pcs = 40
num_dims = 2
perplexity = 100
theta = 0.3
eta = 200
exageration = 12
iterations = 4000
random_seed = 1
verbose = 1
tsne_spike_rates_binary_pcs_0p1 = tsne.t_sne(pcs_ar_bin_0p1[:, :number_of_top_pcs], tsne_folder, barnes_hut_exe_dir,
                                         num_dims=num_dims,
                                         perplexity=perplexity, theta=theta, eta=eta, exageration=exageration,
                                         iterations=iterations, random_seed=random_seed, verbose=verbose)

tsne_result = tsne_io.load_tsne_result(tsne_folder)

plt.scatter(tsne_result[:, 0], tsne_result[:, 1], s=5, c='k')

tsne_pcs_count_image_file = join(tsne_folder, 'Tsne_of_13_top_PCs_of_0p1_count_spike_vectors.png')
tsne_pcs_count_image = plt.imread(tsne_pcs_count_image_file)
tsne_pcs_count_image_extent = [-4, 4, -4.6, 4.8]
# </editor-fold>
# -------------------------------------------------


# -------------------------------------------------
# <editor-fold desc="SHOW TSNE CORRELATED WITH VIDEO TSNE AND COMPARE TO FULL PROBE EQUIVALENT">
Beispiel #3
0
# OR Load it
template_features_sparse_clean = np.load(join(files_dir, 'data_to_tsne_(1091229, 579).npy'))


exe_dir = r'E:\Software\Develop\Source\Repos\spikesorting_tsne_bhpart\Barnes_Hut\x64\Release'
theta = 0.4
eta = 200.0
exageration = 20
num_dims = 2
perplexity = 100
iterations = 4000
random_seed = 1
verbose = 3
tsne = TSNE.t_sne(samples=template_features_sparse_clean, files_dir=files_dir, exe_dir=exe_dir, num_dims=num_dims,
                  perplexity=perplexity, theta=theta, eta=eta, exageration=exageration, iterations=iterations,
                  random_seed=random_seed, verbose=verbose)

# OR
tsne = io.load_tsne_result(join(base_folder, files_dir))

# OR
tsne = TSNE.t_sne_from_existing_distances(files_dir=files_dir, exe_dir=exe_dir, num_dims=num_dims,
                                          perplexity=perplexity, theta=theta, eta=eta, exageration=exageration,
                                          iterations=iterations, random_seed=random_seed, verbose=verbose)

spikes_used = np.load(join(files_dir, 'indices_of_spikes_used.npy'))

spike_templates = np.load(join(base_folder, 'spike_templates.npy'))
spike_templates_clean = spike_templates[spikes_used]
Beispiel #4
0
spike_rates_binary_0p1 = spike_rates_binary_0p1.transpose()

num_dims = 2
perplexity = 100
theta = 0.3
eta = 200
exageration = 12
iterations = 4000
random_seed = 1
verbose = 2
tsne_spike_rates_binary_0p1 = tsne.t_sne(spike_rates_binary_0p1,
                                         tsne_folder,
                                         barnes_hut_exe_dir,
                                         num_dims=num_dims,
                                         perplexity=perplexity,
                                         theta=theta,
                                         eta=eta,
                                         exageration=exageration,
                                         iterations=iterations,
                                         random_seed=random_seed,
                                         verbose=verbose)

# </editor-fold>
# -------------------------------------------------

# -------------------------------------------------
# <editor-fold desc="CREATE MATRIX, PCA IT AND RUN T-SNE ON THE PCs">

tsne_folder = join(tsne_folder_base,
                   'All_spikes_100msbin_count_top40PCs_6Kiter')
#   Run the t-sne
num_dims = 2
perplexity = 100
theta = 0.3
eta = 200
exageration = 12
iterations = 4000
random_seed = 1
verbose = 2
tsne_result = tsne.t_sne(pcs_flat_video[:, :100],
                         tsne_folder,
                         barnes_hut_exe_dir,
                         num_dims=num_dims,
                         perplexity=perplexity,
                         theta=theta,
                         eta=eta,
                         exageration=exageration,
                         iterations=iterations,
                         random_seed=random_seed,
                         verbose=verbose)

# </editor-fold>
# -------------------------------------------------

# -------------------------------------------------
# <editor-fold desc="DBSCAN THE TSNE AND SAVE THE RESULTING LABELS">

tsne_result = tsne_io.load_tsne_result(tsne_folder)

X = tsne_result.transpose()
template_features_matrix = np.load(
    join(tsne_folder, 'data_to_tsne_(699959, 645).npy'))

# First run of t-sne
num_dims = 2
perplexity = 100
theta = 0.3
iterations = 4000
random_seed = 1
verbose = 3

tsne_results = tsne.t_sne(template_features_matrix,
                          files_dir=tsne_folder,
                          num_dims=num_dims,
                          perplexity=perplexity,
                          theta=theta,
                          iterations=iterations,
                          random_seed=random_seed,
                          verbose=verbose)
spike_info = preproc_kilo.generate_spike_info_from_full_tsne(
    kilosort_folder=kilosort_folder, tsne_folder=tsne_folder)

# Run t-sne again with different parameters starting from the already calculated hd distances
num_dims = 2
perplexity = 100
theta = 0.3
iterations = 4000
random_seed = 1
verbose = 3

tsne_results = tsne.t_sne_from_existing_distances(files_dir=tsne_folder,
# Do the TSne on the masked pca features
files_dir = join(analysis_folder, 'KlustaKwik', cell, 'tsne')
exe_dir = r'E:\Software\Develop\Source\Repos\spikesorting_tsne_bhpart\Barnes_Hut\x64\Release'
theta = 0.1
eta = 200.0
num_dims = 2
perplexity = 100
iterations = 4000
random_seed = 1
verbose = 2
tsne = TSNE.t_sne(samples=masked_pca_features,
                  files_dir=files_dir,
                  exe_dir=exe_dir,
                  num_dims=num_dims,
                  perplexity=perplexity,
                  theta=theta,
                  eta=eta,
                  iterations=iterations,
                  random_seed=random_seed,
                  verbose=verbose)

# OR
tsne = io.load_tsne_result(files_dir)

# Grab the clusters from klustakwik
clusters_text_file = open(
    join(analysis_folder, 'KlustaKwik', cell, '.klustakwik2',
         "spike_clusters.0.txt"), "r")
clusters_of_all_extra_spikes = np.array(
    [int(line) for line in clusters_text_file.readlines()])
clusters_of_all_extra_spikes[np.argwhere(
Beispiel #8
0
                                                                  all_cells_full_templates.shape[1] * all_cells_full_templates.shape[2]))

pca_sr_full = PCA()
pcs_ar_full = pca_sr_full.fit_transform(all_cells_full_templates_flat)

number_of_top_pcs = 40
num_dims = 2
perplexity = 30
theta = 0.3
eta = 200
exageration = 12
iterations = 4000
random_seed = 1
verbose = 2
tsne_result_full = tsne.t_sne(pcs_ar_full[:, :number_of_top_pcs], tsne_folder_full, barnes_hut_exe_dir,
                                         num_dims=num_dims,
                                         perplexity=perplexity, theta=theta, eta=eta, exageration=exageration,
                                         iterations=iterations, random_seed=random_seed, verbose=verbose)

tsne_result_full = tsne_io.load_tsne_result(tsne_folder_full)

plt.figure(1)
plt.scatter(tsne_result_full[:, 0], tsne_result_full[:, 1], s=3, c='k')

plt.figure(2)
colors = ['k', 'r', 'b', 'y', 'g', 'm']
for ind, i in zip(indices_full, np.arange(len(indices_full))):
    plt.scatter(tsne_result_full[ind[0]:ind[1], 0], tsne_result_full[ind[0]:ind[1], 1], s=10, c=colors[i])
plt.legend(cell_folders)


# T-sne the decimated