setup = 'onebin' ANALYSIS_DIR, analysis_num_str, R_tot_onebin, T_D_onebin, T, R_onebin, R_onebin_CI_lo, R_onebin_CI_hi = plots.load_analysis_results( recorded_system, rec_length, neuron_index, setup, CODE_DIR, regularization_method='shuffling', use_settings_path=use_settings_path) R_tot_onebin, T_D_index_onebin, max_valid_index_onebin = plots.get_R_tot( T, R_onebin, R_onebin_CI_lo) R_tot_onebin_CA1 += [R_tot_onebin / R_tot_bbc] R_tot_shuffling_CA1_median = np.median(R_tot_shuffling_CA1) R_tot_shuffling_CA1_median_loCI, R_tot_shuffling_CA1_median_hiCI = plots.get_CI_median( R_tot_shuffling_CA1) R_tot_fivebins_CA1_median = np.median(R_tot_fivebins_CA1) R_tot_fivebins_CA1_median_loCI, R_tot_fivebins_CA1_median_hiCI = plots.get_CI_median( R_tot_fivebins_CA1) R_tot_onebin_CA1_median = np.median(R_tot_onebin_CA1) R_tot_onebin_CA1_median_loCI, R_tot_onebin_CA1_median_hiCI = plots.get_CI_median( R_tot_onebin_CA1) R_tot_glm_CA1_median = np.median(R_tot_glm_CA1) R_tot_glm_CA1_median_loCI, R_tot_glm_CA1_median_hiCI = plots.get_CI_median( R_tot_glm_CA1) recorded_system = 'retina' rec_length = '90min' number_valid_neurons = 28 R_tot_shuffling_Retina = []
rate_CA1 = [] CV_CA1 = [] medianISI_CA1 = [] autocorrelation_time_CA1 = [] for neuron_index in range(number_valid_neurons): tau_R, R_tot = get_tau_R_and_R_tot(T_0, setup, regularization_method, recorded_system, rec_length, neuron_index, CODE_DIR, use_settings_path) stats = get_stats(bin_size_ms,T_0_ms, neuron_index, recorded_system, CODE_DIR) R_tot_CA1 += [R_tot] tau_R_CA1 += [tau_R*1000] rate_CA1 += [stats['rate']] medianISI_CA1 += [stats['medianISI']] CV_CA1 += [stats['CV']] autocorrelation_time_CA1 += [stats['autocorrelation_time']] R_tot_CA1_median = np.median(R_tot_CA1) R_tot_CA1_median_loCI, R_tot_CA1_median_hiCI = plots.get_CI_median(R_tot_CA1) tau_R_CA1_median = np.median(tau_R_CA1) tau_R_CA1_median_loCI, tau_R_CA1_median_hiCI = plots.get_CI_median(tau_R_CA1) rate_CA1_median = np.median(rate_CA1) rate_CA1_median_loCI, rate_CA1_median_hiCI = plots.get_CI_median(rate_CA1) medianISI_CA1_median = np.median(medianISI_CA1) medianISI_CA1_median_loCI, medianISI_CA1_median_hiCI = plots.get_CI_median(medianISI_CA1) CV_CA1_median = np.median(CV_CA1) CV_CA1_median_loCI, CV_CA1_median_hiCI = plots.get_CI_median(CV_CA1) autocorrelation_time_CA1_median = np.median(autocorrelation_time_CA1) autocorrelation_time_CA1_median_loCI, autocorrelation_time_CA1_median_hiCI = plots.get_CI_median(autocorrelation_time_CA1) recorded_system = 'retina' number_valid_neurons = 111 R_tot_retina = [] tau_R_retina = []
T_0 = T_0_ms / 1000. """Load data""" recorded_system = 'CA1' number_valid_neurons = 28 R_tot_CA1 = [] tau_R_CA1 = [] for neuron_index in range(number_valid_neurons): tau_R, R_tot = get_tau_R_and_R_tot(T_0, setup, regularization_method, recorded_system, rec_length, neuron_index, CODE_DIR, use_settings_path) R_tot_CA1 += [R_tot] tau_R_CA1 += [tau_R * 1000] R_tot_CA1_median = np.median(R_tot_CA1) R_tot_CA1_median_loCI, R_tot_CA1_median_hiCI = plots.get_CI_median(R_tot_CA1) tau_R_CA1_median = np.median(tau_R_CA1) tau_R_CA1_median_loCI, tau_R_CA1_median_hiCI = plots.get_CI_median(tau_R_CA1) recorded_system = 'retina' number_valid_neurons = 111 R_tot_retina = [] tau_R_retina = [] for neuron_index in range(number_valid_neurons): tau_R, R_tot = get_tau_R_and_R_tot(T_0, setup, regularization_method, recorded_system, rec_length, neuron_index, CODE_DIR, use_settings_path) R_tot_retina += [R_tot] tau_R_retina += [tau_R * 1000]
recorded_system = 'CA1' number_valid_neurons = 28 tau_R_shuffling_CA1 = [] tau_R_fivebins_CA1 = [] tau_R_onebin_CA1 = [] for neuron_index in range(number_valid_neurons): tau_R_bbc, tau_R_shuffling, tau_R_fivebins, tau_R_onebin = get_tau_R_for_different_estimators( T_0, recorded_system, rec_length, neuron_index, CODE_DIR, use_settings_path) tau_R_shuffling_CA1 += [tau_R_shuffling / tau_R_bbc] tau_R_fivebins_CA1 += [tau_R_fivebins / tau_R_bbc] tau_R_onebin_CA1 += [tau_R_onebin / tau_R_bbc] tau_R_shuffling_CA1_median = np.median(tau_R_shuffling_CA1) tau_R_shuffling_CA1_median_loCI, tau_R_shuffling_CA1_median_hiCI = plots.get_CI_median( tau_R_shuffling_CA1) tau_R_fivebins_CA1_median = np.median(tau_R_fivebins_CA1) tau_R_fivebins_CA1_median_loCI, tau_R_fivebins_CA1_median_hiCI = plots.get_CI_median( tau_R_fivebins_CA1) tau_R_onebin_CA1_median = np.median(tau_R_onebin_CA1) tau_R_onebin_CA1_median_loCI, tau_R_onebin_CA1_median_hiCI = plots.get_CI_median( tau_R_onebin_CA1) recorded_system = 'retina' number_valid_neurons = 111 tau_R_shuffling_retina = [] tau_R_fivebins_retina = [] tau_R_onebin_retina = [] for neuron_index in range(number_valid_neurons): tau_R_bbc, tau_R_shuffling, tau_R_fivebins, tau_R_onebin = get_tau_R_for_different_estimators(
def median_relative_mean_R_tot_and_T_avg(recorded_system, setup, N_neurons, rec_lengths, rec_lengths_Nsamples, CODE_DIR): if recorded_system == 'CA1': DATA_DIR = '{}/data/CA1/'.format(CODE_DIR) if recorded_system == 'retina': DATA_DIR = '{}/data/retina/'.format(CODE_DIR) if recorded_system == 'culture': DATA_DIR = '{}/data/culture/'.format(CODE_DIR) validNeurons = np.load( '{}validNeurons.npy'.format(DATA_DIR)).astype(int) R_tot_relative_mean = {} T_avg_relative_mean = {} np.random.seed(41) neuron_selection = np.random.choice(len(validNeurons), N_neurons, replace=False) for rec_length in rec_lengths: # arrays containing R_tot and mean T_avg for different neurons R_tot_mean_arr = [] T_avg_mean_arr = [] N_samples = rec_lengths_Nsamples[rec_length] for j in range(N_neurons): neuron_index = neuron_selection[j] R_tot_arr = [] T_avg_arr = [] for sample_index in range(N_samples): # Get run index run_index = j * N_samples + sample_index """Load data five bins""" if not rec_length == '90min': setup_subsampled = '{}_subsampled'.format(setup) else: run_index = neuron_index setup_subsampled = setup if setup == 'full_bbc': analysis_results = plots.load_analysis_results( recorded_system, rec_length, run_index, setup_subsampled, CODE_DIR, regularization_method='bbc', use_settings_path=use_settings_path) else: analysis_results = plots.load_analysis_results( recorded_system, rec_length, run_index, setup_subsampled, CODE_DIR, regularization_method='shuffling', use_settings_path=use_settings_path) if not analysis_results == None: ANALYSIS_DIR, analysis_num_str, R_tot, T_D, T, R, R_CI_lo, R_CI_hi = analysis_results if not len(R) == 0: R_tot_analysis_results = plots.get_R_tot(T, R, R_CI_lo) if not R_tot_analysis_results == None: R_tot, T_D_index, max_valid_index = R_tot_analysis_results # R_running_avg = plots.get_running_avg(R) dR = plots.get_dR(T,R,R_tot) T_avg = plots.get_T_avg(T, dR, T_0) T_avg_arr += [T_avg] R_tot_arr += [R_tot] else: print('CI_fail', recorded_system, setup, rec_length, run_index, neuron_index, sample_index) else: print('no valid embeddings', recorded_system, rec_length, setup, analysis_num_str) else: print('analysis_fail', recorded_system, rec_length, setup, run_index, neuron_index, sample_index) R_tot_mean_arr += [np.mean(R_tot_arr)] T_avg_mean_arr += [np.mean(T_avg_arr)] R_tot_relative_mean[rec_length] = np.array(R_tot_mean_arr) T_avg_relative_mean[rec_length] = np.array(T_avg_mean_arr) median_R_tot_relative_mean = [] median_CI_R_tot_relative_mean = [] median_T_avg_relative_mean = [] median_CI_T_avg_relative_mean = [] for rec_length in rec_lengths: R_tot_relative_mean_arr = R_tot_relative_mean[rec_length] / R_tot_relative_mean['90min']*100 T_avg_relative_mean_arr = T_avg_relative_mean[rec_length] / T_avg_relative_mean['90min']*100 # If no valid embeddings were found for BBC for all samples, the mean is nan so the neuron is not considered in the median operation R_tot_relative_mean_arr = R_tot_relative_mean_arr[~np.isnan(R_tot_relative_mean_arr)] T_avg_relative_mean_arr = T_avg_relative_mean_arr[~np.isnan(T_avg_relative_mean_arr)] # Computing the median and 95% CIs over the 10 neurons median_R_tot_relative_mean += [np.median(R_tot_relative_mean_arr)] median_CI_R_tot_relative_mean += [plots.get_CI_median(R_tot_relative_mean_arr)] median_T_avg_relative_mean += [np.median(T_avg_relative_mean_arr)] median_CI_T_avg_relative_mean += [plots.get_CI_median(T_avg_relative_mean_arr)] return np.array(median_R_tot_relative_mean), np.array(median_CI_R_tot_relative_mean), np.array(median_T_avg_relative_mean), np.array(median_CI_T_avg_relative_mean)