def get_tau_R_and_R_tot(T_0, setup, regularization_method, recorded_system, rec_length, neuron_index, CODE_DIR, use_settings_path): ANALYSIS_DIR, analysis_num_str, R_tot, T_D, T, R, R_CI_lo, R_CI_hi = plots.load_analysis_results( recorded_system, rec_length, neuron_index, setup, CODE_DIR, regularization_method = regularization_method, use_settings_path = use_settings_path) R_tot = plots.get_R_tot(T, R, R_CI_lo)[0] dR = plots.get_dR(T,R,R_tot) tau_R = plots.get_T_avg(T, dR, T_0) return tau_R, R_tot
def main(): # Load glm settings with open('{}/settings/{}_glm.yaml'.format(CODE_DIR,recorded_system), 'r') as glm_settings_file: glm_settings = yaml.load(glm_settings_file, Loader=yaml.BaseLoader) # Load the 900 minute simulated recording DATA_DIR = '{}/{}'.format(data_path,recorded_system) spiketimes = np.load('{}/spiketimes_900min.npy'.format(DATA_DIR)) # Preprocess spiketimes and compute binary counts for current spiking spiketimes, counts = glm.preprocess_spiketimes(spiketimes, glm_settings) # Load embedding-optimized estimates ANALYSIS_DIR, analysis_num_str, R_tot, T_D, T, R, R_CI_lo, R_CI_hi = plots.load_analysis_results(recorded_system, rec_length, sample_index, setup, CODE_DIR, regularization_method = regularization_method, use_settings_path = use_settings_path) R_tot, T_D_index, max_valid_index = plots.get_R_tot(T, R, R_CI_lo) # Load embedding parameters from embedding optimization embedding_parameters, analysis_num_str = glm.load_embedding_parameters( rec_length, sample_index, ANALYSIS_DIR, regularization_method = regularization_method) # Compute glm for optimized embedding parameters for temporal depth, only if sample_index = 0 compute for all T if sample_index > 0: embedding_parameters_benchmark = embedding_parameters[:,T_D_index:max_valid_index] else: embedding_parameters_benchmark = embedding_parameters # Compute history dependence with GLM for the same embeddings as found with bbc/shuffling glm_benchmark = glm.compute_benchmark(embedding_parameters_benchmark, spiketimes, counts, glm_settings) # Save results to glm_benchmarks.csv glm.save_glm_benchmark_to_CSV(glm_benchmark, embedding_parameters_benchmark, ANALYSIS_DIR, analysis_num_str, regularization_method=regularization_method) return EXIT_SUCCESS
import hde_plotutils as plots """Load data""" recorded_system = 'CA1' rec_length = '90min' number_valid_neurons = 28 R_tot_shuffling_CA1 = [] R_tot_fivebins_CA1 = [] R_tot_onebin_CA1 = [] R_tot_glm_CA1 = [] for neuron_index in range(number_valid_neurons): setup = 'full_bbc' ANALYSIS_DIR, analysis_num_str, R_tot_bbc, T_D_bbc, T, R_bbc, R_bbc_CI_lo, R_bbc_CI_hi = plots.load_analysis_results( recorded_system, rec_length, neuron_index, setup, CODE_DIR, regularization_method='bbc', use_settings_path=use_settings_path) R_tot_bbc, T_D_index_bbc, max_valid_index_bbc = plots.get_R_tot( T, R_bbc, R_bbc_CI_lo) # Load GLM R_tot R_tot_glm = plots.load_analysis_results_glm(ANALYSIS_DIR, analysis_num_str) R_tot_glm_CA1 += [R_tot_glm / R_tot_bbc] setup = 'full_shuffling' ANALYSIS_DIR, analysis_num_str, R_tot_shuffling, T_D_shuffling, T, R_shuffling, R_shuffling_CI_lo, R_shuffling_CI_hi = plots.load_analysis_results( recorded_system, rec_length, neuron_index,
DATA_DIR = '{}/data/{}'.format(CODE_DIR, recorded_system) """Compute measures""" tau_list = [70, 85, 100, 120, 150, 198, 300, 500] m_list = [] R_tot_list = [] tau_R_list = [] for tau in tau_list: if tau == 198: sample_index = 0 else: sample_index = tau m = np.exp(-bin_size * 1000 / tau) ANALYSIS_DIR, analysis_num_str, R_tot, T_D, T_R, R, R_CI_lo, R_CI_hi = plots.load_analysis_results( recorded_system, rec_length, sample_index, setup, CODE_DIR, regularization_method='shuffling', use_settings_path=use_settings_path) R_tot, T_D_index, max_valid_index = plots.get_R_tot(T_R, R, R_CI_lo) dR_arr = plots.get_dR(T_R, R, R_tot) # transform T to ms T_R_ms = T_R * 1000 tau_R = plots.get_T_avg(T_R_ms, dR_arr, T_0_ms) m_list += [m] R_tot_list += [R_tot] tau_R_list += [tau_R] """Plotting""" rc('text', usetex=True) matplotlib.rcParams['font.size'] = '15.0' matplotlib.rcParams['xtick.labelsize'] = '15'
setup_index = i % 2 rec_length_index = int(i / 2) rec_length = rec_lengths[rec_length_index] if setup_index == 0: bbc_setup = 'full_bbc' shuffling_setup = 'full_shuffling' else: bbc_setup = 'full_bbc_withCV' shuffling_setup = 'full_shuffling_withCV' """Load data""" # Load settings from yaml file ANALYSIS_DIR, analysis_num_str, R_tot_bbc, T_D_bbc, T_bbc, R_bbc, R_bbc_CI_lo, R_bbc_CI_hi = plots.load_analysis_results( recorded_system, rec_length, sample_index, bbc_setup, CODE_DIR, regularization_method='bbc', use_settings_path=use_settings_path) R_tot_bbc, T_D_index_bbc, max_valid_index_bbc = plots.get_R_tot( T_bbc, R_bbc, R_bbc_CI_lo) dR_bbc = plots.get_dR(T_bbc, R_bbc, R_tot_bbc) tau_R_bbc = plots.get_T_avg(T_bbc, dR_bbc, T_0) glm_bbc_csv_file_name = '{}/ANALYSIS{}/glm_benchmark_bbc.csv'.format( ANALYSIS_DIR, analysis_num_str) glm_bbc_pd = pd.read_csv(glm_bbc_csv_file_name) R_glm_bbc = np.array(glm_bbc_pd['R_GLM']) T_glm_bbc = np.array(glm_bbc_pd['T'])
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)