def checkerboard_svc(data, metadata, stimulus_list, lab_notebook, plot_directory, nsamples, n_draws=30, px_per_deg=10.453): sizes = glia.get_stimulus_parameters(stimulus_list, "CHECKERBOARD", 'size') name = metadata["name"] if name == 'checkerboard-contrast': training_data = glia.bin_100ms(data["training_data"]) validation_data = glia.bin_100ms(data["validation_data"]) training_target = data["training_target"] validation_target = data["validation_target"] conditions = glia.get_checkerboard_contrasts(stimulus_list) condition_name = "contrast" elif name == "checkerboard-durations": training_data = glia.bin_100ms(data["training_data"]) validation_data = glia.bin_100ms(data["validation_data"]) training_target = data["training_target"] validation_target = data["validation_target"] conditions = glia.get_stimulus_parameters(stimulus_list, "CHECKERBOARD", 'lifespan') condition_name = "durations" elif name == "checkerboard": training_100ms = glia.bin_100ms(data["training_data"])[0] training_sum = glia.bin_sum(data["training_data"])[0] training_data = [training_100ms, training_sum] validation_100ms = glia.bin_100ms(data["validation_data"])[0] validation_sum = glia.bin_sum(data["validation_data"])[0] validation_data = [validation_100ms, validation_sum] tt = data["training_target"][0] training_target = [tt, tt] vt = data["validation_target"][0] validation_target = [vt, vt] conditions = ['100ms bins', 'spike count'] condition_name = None else: raise (ValueError(f'Unknown experiment {metadata["name"]}')) if nsamples > 0: plot_diff_nsamples(data, stimulus_list, plot_directory, "checkerboard", sizes, conditions, condition_name) else: acuity(training_data, training_target, validation_data, validation_target, stimulus_list, plot_directory, "checkerboard", sizes, conditions, condition_name, n_draws, units="cpd", px_per_deg=px_per_deg)
def tiled_letter_svc(data, metadata, stimulus_list, lab_notebook, plot_directory, nsamples): print("Classifying Letters - warning not using latest acuity function") # TODO sizes = glia.get_stimulus_parameters(stimulus_list, "TILED_LETTER", 'size') name = metadata["name"] # n_sizes, n_training, n_steps, n_x, n_y, n_units = data["training_data"].shape logger.debug(data["training_data"].shape) # add nconditions dim training_100ms = glia.bin_100ms(np.expand_dims(data["training_data"], 0)) validation_100ms = glia.bin_100ms( np.expand_dims(data["validation_data"], 0)) logger.debug(f'training_100ms shape {training_100ms.shape}') logger.debug(f'sizes {sizes}') for i, size in enumerate(sizes): print(f'SVC for size {size}') # note: no expand dims, hardcoded 1 ncondition training_target = data["training_target"][i] validation_target = data["validation_target"][i] logger.debug(np.size(training_target)) svr = svm.SVC() parameters = {'C': [1, 10, 100, 1000], 'gamma': [0.001, 0.0001]}, clf = GridSearchCV(svr, parameters, n_jobs=12) report, confusion = glia.classifier_helper( clf, (training_100ms[0, i], training_target), (validation_100ms[0, i], validation_target)) with open(f"{plot_directory}/letter-{size}.txt", "w") as f: f.write(report + '\n') f.write(str(confusion))
def grating_svc(data, metadata, stimulus_list, lab_notebook, plot_directory, nsamples, n_draws=30, sinusoid=False, px_per_deg=10.453): if sinusoid: stimulus_type = "SINUSOIDAL_GRATING" plot_name = "Sinusoidal grating" else: stimulus_type = 'GRATING' plot_name = "grating" sizes = glia.get_stimulus_parameters(stimulus_list, stimulus_type, "width") if metadata["name"] in \ ['grating-contrast', 'grating-sinusoidal-contrast']: training_data = glia.bin_100ms(data["training_data"]) validation_data = glia.bin_100ms(data["validation_data"]) training_target = data["training_target"] validation_target = data["validation_target"] conditions = glia.get_grating_contrasts(stimulus_list, stimulus_type) condition_name = "contrast" elif metadata["name"] in \ ["grating-durations", "grating-sinusoidal-durations"]: training_data = glia.bin_100ms(data["training_data"]) validation_data = glia.bin_100ms(data["validation_data"]) training_target = data["training_target"] validation_target = data["validation_target"] conditions = glia.get_stimulus_parameters(stimulus_list, stimulus_type, 'lifespan') condition_name = "durations" elif metadata["name"] in \ ["grating-speeds", "grating-sinusoidal-speeds"]: training_data = glia.bin_100ms(data["training_data"]) validation_data = glia.bin_100ms(data["validation_data"]) training_target = data["training_target"] validation_target = data["validation_target"] conditions = glia.get_stimulus_parameters(stimulus_list, stimulus_type, 'speed') condition_name = "speeds" elif metadata["name"] in \ ["grating", "grating-sinusoidal"]: training_100ms = glia.bin_100ms(data["training_data"])[0] training_sum = glia.bin_sum(data["training_data"])[0] training_data = [training_100ms, training_sum] validation_100ms = glia.bin_100ms(data["validation_data"])[0] validation_sum = glia.bin_sum(data["validation_data"])[0] validation_data = [validation_100ms, validation_sum] tt = data["training_target"][0] training_target = [tt, tt] vt = data["validation_target"][0] validation_target = [vt, vt] conditions = ['100ms bins', 'spike count'] condition_name = None else: raise (ValueError(f'Unknown experiment {metadata["name"]}')) if nsamples > 0: plot_diff_nsamples(data, stimulus_list, plot_directory, plot_name, sizes, conditions, condition_name) else: acuity(training_data, training_target, validation_data, validation_target, stimulus_list, plot_directory, plot_name, sizes, conditions, condition_name, n_draws, units="cpd", px_per_deg=px_per_deg)