def identify_neuron_types(): # get trials for a single dummy neuron real_data = load_mouse_data() dummy_session = real_data[3] #dummy_session = get_data_from_a_dummy_sesion() # this is the first neuron from the dummy session: print('Analyze two example neurons first.') neuron_index = 0 # we will try to decide whether this is a choice neuron left_vs_right_accuracy, accuracy_left_vs_nogo, accuracy_right_vs_nogo = compare_prediction_accuracies_for_neuron(dummy_session, neuron_index) print('accuracies (left vs right, left vs no go, right vs no go):' + str(left_vs_right_accuracy) + ' ' + str(accuracy_left_vs_nogo) + ' ' + str(accuracy_right_vs_nogo)) neuron_type = guess_type(left_vs_right_accuracy, accuracy_left_vs_nogo, accuracy_right_vs_nogo) print ("neuron idx", neuron_index, neuron_type) print('----------------------------------------------------------------------') neuron_index = 55 # we will try to decide whether this is a choice neuron left_vs_right_accuracy, accuracy_left_vs_nogo, accuracy_right_vs_nogo = compare_prediction_accuracies_for_neuron(dummy_session, neuron_index) print('accuracies (left vs right, left vs no go, right vs no go):' + str(left_vs_right_accuracy) + ' ' + str(accuracy_left_vs_nogo) + ' ' + str(accuracy_right_vs_nogo)) neuron_type = guess_type(left_vs_right_accuracy, accuracy_left_vs_nogo, accuracy_right_vs_nogo) print ("neuron idx", neuron_index, neuron_type) print('Analyze all neurons from this session and check accuracy of predictions:') number_of_neurons = dummy_session['spks'].shape[0] neuron_type_guesses = [] for neuron_index in range(number_of_neurons): left_vs_right_accuracy, accuracy_left_vs_nogo, accuracy_right_vs_nogo = compare_prediction_accuracies_for_neuron(dummy_session, neuron_index) neuron_type = guess_type(left_vs_right_accuracy, accuracy_left_vs_nogo, accuracy_right_vs_nogo) neuron_type_guesses.append(neuron_type) compare_predicted_to_ground_truth_type(dummy_session['dummy_type'], neuron_type_guesses)
def train_test_split(train_size: float = 0.8): """ split the dataset into training and test set """ # load dataset data = load_mouse_data() split_trial_indices = create_dataset_split_indices(data, train_size) train_data = get_training_data(data, split_trial_indices) test_data = get_test_data(data, split_trial_indices) return train_data, test_data
def main(): all_data = load_data.load_mouse_data() print("Data loaded") # test_data = split_test_and_training_data.get_test_data(all_data) # training_data = split_test_and_training_data.get_training_data(all_data) train_data, test_data = split_test_and_training_data.train_test_split( train_size=0.8) train_data = dimensionality_reduction(train_data, 0.9)
def get_training_data_for_simulation(): """ Load the training data. We need this to get the real behavioural data. We will later replace the real firing data with simulated data. """ mouse_data = load_data.load_mouse_data() training_data = split_test_and_training_data.get_training_data(mouse_data) simulated_data = copy.deepcopy(training_data) return simulated_data
def test_create_dataset_split_indices(): data = load_mouse_data() train_size = 0.7 session_id = 3 trials_split_dict = create_dataset_split_indices(data, train_size) total_trials_in_sessionid = data[session_id]['spks'].shape[1] assert isinstance(trials_split_dict, dict) split_found = trials_split_dict[session_id]['train'].shape[0] split_percent = int(train_size * total_trials_in_sessionid) assert (split_found == split_percent)
def process_on_real_data(session_id: int = 10, single_neuron_id_for_train=5, single_neuron_id_for_test=9): # default train test split is set = 0.8 data = load_mouse_data() train_data, test_data = train_test_split() session_data = train_data[session_id] single_neuron_session_train_data = session_data['spks'][single_neuron_id_for_train] single_neuron_session_test_data = session_data['spks'][single_neuron_id_for_test] left_vs_right = get_accuracy_predicting_left_vs_right(session_data, single_neuron_session_train_data) print ("left_vs_right : {}".format(left_vs_right)) left_vs_nogo = get_accuracy_predicting_left_vs_no_go(session_data, single_neuron_session_train_data) print ("left_vs_no_go : {}".format(left_vs_nogo)) right_vs_nogo = get_accuracy_predicting_right_vs_no_go(session_data, single_neuron_session_train_data) print ("right_vs_no_go : {}".format(right_vs_nogo))
def test_get_test_data(): # check if it splits the same way every time data = load_mouse_data() session_id = 10 train_size = 0.8 trials_split_dict = create_dataset_split_indices(data, train_size) test_data_1 = get_test_data(data, trials_split_dict) test_data_2 = get_test_data(data, trials_split_dict) assert np.allclose(test_data_1[session_id]['contrast_right'], test_data_2[session_id]['contrast_right'], rtol=1e-05, atol=1e-08, equal_nan=False)
def test_get_test_and_training_data(): data = load_mouse_data() train_size = 0.7 session_id = 6 training_data, test_data = train_test_split(train_size) num_of_trials_all_example = data[session_id]['spks'].shape[1] num_of_trials_test_example = test_data[session_id]['spks'].shape[1] num_of_trials_training_example = training_data[session_id]['spks'].shape[1] assert num_of_trials_all_example == (num_of_trials_test_example + num_of_trials_training_example) num_of_trials_all_example = data[session_id]['contrast_right'].shape[0] num_of_trials_test_example = test_data[session_id]['contrast_right'].shape[ 0] num_of_trials_training_example = training_data[session_id][ 'contrast_right'].shape[0] assert num_of_trials_all_example == (num_of_trials_test_example + num_of_trials_training_example)
def get_real_data_from_session(session_id: int = 10): data = load_mouse_data() session_data = data[session_id] return session_id