Example #1
0
                                               num_of_frames_to_average)
speeds_0p25[0] = 0
# </editor-fold>

#  -------------------------------------------------
# <editor-fold desc="CREATE THE MUTUAL INFORMATION MEASURE BETWEEN SPEED AND THE FIRING RATES OF ALL NEURONS (FOR THE WHOLE RECORDING)">
# Calculate the mutual information between the speed and all firing rates (for the whole of the experiment)
# using the lnc code (a Kraskov with some local non-uniform correction for better very high correlations)

n = 0
mutual_infos_spikes_vs_speed = []
for rate in spike_rates_0p25:
    mutual_infos_spikes_vs_speed.append(
        MI.mi_LNC([rate.tolist(), speeds_0p25],
                  k=10,
                  base=np.exp(1),
                  alpha=0.4,
                  intens=1e-10))
    n += 1
    print('Done neuron {}'.format(str(n)))

mutual_infos_spikes_vs_speed = np.array(mutual_infos_spikes_vs_speed)
np.save(
    join(mutual_information_folder,
         'mutual_infos_spikes_vs_speed_corrected.npy'),
    mutual_infos_spikes_vs_speed)
# ----------------------------------------------------

template_info = pd.read_pickle(join(kilosort_folder, 'template_info.df'))
mutual_infos_spikes_vs_speed = np.load(
    join(mutual_information_folder,
Example #2
0
    join(mutual_information_folder, 'mutual_infos_spikes_vs_speed.npy'))

speed_very_corr_neurons_index = np.squeeze(
    np.argwhere(mutual_infos_spikes_vs_speed > 0.15))
speed_very_corr_neurons = template_info.loc[speed_very_corr_neurons_index]

brain_positions_of_corr_neurons = speed_very_corr_neurons[
    'position Y'].values * const.POSITION_MULT

plt.plot(np.array(spike_rates_0p25[speed_very_corr_neurons, :]).T)

# Calculate MI between the FRs of the two neurons
t1 = MI.mi_LNC([
    spike_rates_0p25[speed_very_corr_neurons[0], :].tolist(),
    spike_rates_0p25[speed_very_corr_neurons[1], :].tolist()
],
               k=10,
               base=np.exp(1),
               alpha=0.4,
               intens=1e-10)

# Calculate MI between the FR of the same neuron and itself
t2 = MI.mi_LNC([
    spike_rates_0p25[speed_very_corr_neurons[1], :].tolist(),
    spike_rates_0p25[speed_very_corr_neurons[1], :].tolist()
],
               k=10,
               base=np.exp(1),
               alpha=0.4,
               intens=1e-10)

# Calculate MI between the speed and itself
Example #3
0
np.save(join(patterned_vs_non_patterned_folder, 'spike_rates_non_patterned_behaviour_0p25.npy'),
        spike_rates_non_patterned_behaviour_0p25)


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


# -------------------------------------------------
# <editor-fold desc="RUN THE MUTUAL INFORMATION">

#   Do the patterned behaviour vs speed
n = 0
mi_pb_spikes_vs_speed = []
for rate in spike_rates_patterned_behaviour_0p25:
    mi_pb_spikes_vs_speed.append(MI.mi_LNC([rate.tolist(), speeds_patterned_behaviour_0p25],
                                           k=10, base=np.exp(1), alpha=0.4, intens=1e-10))
    n += 1
    print('Done neuron {}'.format(str(n)))

mi_pb_spikes_vs_speed = np.array(mi_pb_spikes_vs_speed)
np.save(join(mutual_information_folder, 'mutual_infos_spikes_vs_speed_patterned_behaviour.npy'), mi_pb_spikes_vs_speed)

#   Do the shuffle of the best patterned behaviour vs speed
max_neuron = np.argmax(mi_pb_spikes_vs_speed)

shuffled, mean, conf_intervals = MI.shuffle_test(MI.mi_LNC,  spike_rates_patterned_behaviour_0p25[max_neuron],
                                                 speeds_patterned_behaviour_0p25,
                                                 z=False, ns=1000, ci=0.95, k=10, base=np.exp(1), alpha=0.4,
                                                 intens=1e-10)
np.save(join(mutual_information_folder, 'shuffled_mut_info_spike_rate_589_vs_speed_patterned_behaviour.npy'), shuffled)
Example #4
0
#  -------------------------------------------------
# CREATE THE MUTUAL INFORMATION MEASURE BETWEEN SPEED AND THE FIRING RATES OF ALL NEURONS (FOR THE WHOLE RECORDING)
#  -------------------------------------------------

# Calculate the mutual information between the speed and all firing rates (for the whole of the experiment)
# using the lnc code (a Kraskov with some local non-uniform correction for better very high correlations)

n = 0
mutual_infos_spikes_vs_speed = []
for rate in spike_rates_0p25:
    mutual_infos_spikes_vs_speed.append(
        MI.mi_LNC([
            rate.tolist()[:const.BRAIN_DATA_UP_TO_QUARTER_SECOND],
            speeds_0p25[:const.BRAIN_DATA_UP_TO_QUARTER_SECOND]
        ],
                  k=10,
                  base=np.exp(1),
                  alpha=0.4,
                  intens=1e-10))
    n += 1
    print('Done neuron {}'.format(str(n)))

mutual_infos_spikes_vs_speed = np.array(mutual_infos_spikes_vs_speed)
np.save(
    join(mutual_information_folder,
         'mutual_infos_spikes_vs_speed_corrected_for_large_acc.npy'),
    mutual_infos_spikes_vs_speed)

movement_bins = np.squeeze(np.argwhere(speeds_0p25_array > 4))
moving_spike_rates_0p25 = np.squeeze(spike_rates_0p25[:, movement_bins])
moving_speeds_0p25 = speeds_0p25_array[movement_bins].tolist()
                                                                       np.mean, fr_smooth_frames, fr_smooth_frames)

distance_traveled_from_poke_smoothed = binning.rolling_window_with_step(distance_traveled_from_poke,
                                                                        np.mean, fr_smooth_frames, fr_smooth_frames)

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


# -------------------------------------------------
# <editor-fold desc="DO THE MIs (RUN ONCE)">
# NOTE The MIs were done with fr_smooth_time = 0.5
n = 0
mi_spike_rates_vs_distance_traveled_from_poke = []
for rate in spike_rates_away_from_poke_smoothed:
    mi_spike_rates_vs_distance_traveled_from_poke.append(MI.mi_LNC([rate.tolist(), distance_traveled_from_poke_smoothed],
                                                                  k=10, base=np.exp(1), alpha=0.4, intens=1e-10))
    n += 1
    print('Done neuron {}'.format(str(n)))

mi_spike_rates_vs_distance_traveled_from_poke = np.array(mi_spike_rates_vs_distance_traveled_from_poke)
np.save(join(mutual_information_folder, 'mutual_infos_spikes_vs_distance_traveled_from_poke.npy'),
        mi_spike_rates_vs_distance_traveled_from_poke)


#   Do the shuffle of the best fr vs distance to travel to next poke
max_neuron = np.argmax(mi_spike_rates_vs_distance_traveled_from_poke)

shuffled, mean, conf_intervals = MI.shuffle_test(MI.mi_LNC,  spike_rates_away_from_poke_smoothed[max_neuron],
                                                 distance_traveled_from_poke_smoothed,
                                                 z=False, ns=1000, ci=0.95, k=10, base=np.exp(1), alpha=0.4,
                                                 intens=1e-10)
Example #6
0
# -------------------------------------------------
# <editor-fold desc="CHECK FOR CORRELATIONS BETWEEN SPIKES RATES OF ALL NEURONS AROUND EVENT">

fr_norm_sorted = tns

cov = np.cov(fr_norm_sorted)

# MUTUAL INFO BETWEEN RATES
n = 0
mutual_infos = []
for rate1 in fr_norm_sorted:
    for rate2 in fr_norm_sorted:
        mutual_infos.append(
            MI.mi_LNC([rate1.tolist(), rate2.tolist()],
                      k=10,
                      base=np.exp(1),
                      alpha=0.4,
                      intens=1e-10))
    n += 1
    print('Done neuron {}'.format(str(n)))

mutual_infos = np.reshape(np.array(mutual_infos),
                          (fr_norm_sorted.shape[0], fr_norm_sorted.shape[0]))
np.save(
    join(
        analysis_folder, 'Results', 'MutualInformation',
        'mutual_infos_NPsparceProbe_spike_rates_vs_spike_rates_all_neurons_around_succ_trials.npy'
    ), mutual_infos)

# </editor-fold>
distance_to_travel_to_poke_smoothed = binning.rolling_window_with_step(
    distance_to_travel_to_poke, np.mean, fr_smooth_frames, fr_smooth_frames)

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

# -------------------------------------------------
# <editor-fold desc="DO THE MIs (RUN ONCE)">
# NOTE The MIs were done with fr_smooth_time = 0.5
n = 0
mi_spike_rates_vs_distance_to_travel_to_poke = []
for rate in spike_rates_away_from_poke_smoothed:
    mi_spike_rates_vs_distance_to_travel_to_poke.append(
        MI.mi_LNC([rate.tolist(), distance_to_travel_to_poke],
                  k=10,
                  base=np.exp(1),
                  alpha=0.4,
                  intens=1e-10))
    n += 1
    print('Done neuron {}'.format(str(n)))

mi_spike_rates_vs_distance_to_travel_to_poke = np.array(
    mi_spike_rates_vs_distance_to_travel_to_poke)
np.save(
    join(mutual_information_folder,
         'mutual_infos_spikes_vs_distance_to_travel_to_poke.npy'),
    mi_spike_rates_vs_distance_to_travel_to_poke)

#   Do the shuffle of the best fr vs distance to travel to next poke
max_neuron = np.argmax(mi_spike_rates_vs_distance_to_travel_to_poke)
# </editor-fold>

# -------------------------------------------------
# <editor-fold desc="CHECK FOR CORRELATIONS BETWEEN SPIKES RATES OF ALL NEURONS AROUND EVENT">

fr_norm_sorted = tns

cov = np.cov(fr_norm_sorted)


# MUTUAL INFO BETWEEN RATES
n = 0
mutual_infos = []
for rate1 in fr_norm_sorted:
    for rate2 in fr_norm_sorted:
        mutual_infos.append(MI.mi_LNC([rate1.tolist(), rate2.tolist()],
                                            k=10, base=np.exp(1), alpha=0.4, intens=1e-10))
    n += 1
    print('Done neuron {}'.format(str(n)))


mutual_infos = np.reshape(np.array(mutual_infos), (fr_norm_sorted.shape[0], fr_norm_sorted.shape[0]))
np.save(join(analysis_folder, 'Results', 'MutualInformation',
             'mutual_infos_NSprobe_spike_rates_vs_spike_rates_all_neurons_around_succ_trials.npy'), mutual_infos)

# </editor-fold>


# ----------------------------------------------------------------------------------------------------------------------
# <editor-fold desc="COMPARE THE FRs AROUND THE POKE EVENTS WITH THE ONES AROUND THE RANDOM ONES">

time_around_beam_break = 8