Beispiel #1
0
def test_animated_hist():
    ## set the Masterpath to the folder where your output is saved
    n_epochs = 19

    masterpath = "/Users/clemens/Documents/Code/ModelClemens/output"
    ## set the subfolder to the Simulation you want to analyse

    subfolders = ["10_25-19_10_only_loc_1"]
    ## if more than the inital epoch is needed *1 needs to be run
    extensions = ["initial"] + [
        "testing/epoch{}".format(n) for n in range(1, n_epochs)
    ]

    object_list = data.load_testing_stimuli_info(
        masterpath + "/" +
        subfolders[0])  # assuming all the subfolders have the same
    n_stimuli = np.sum(obj['count'] for obj in object_list)

    current_index = 0
    object_indices = []
    for obj in object_list:
        object_indices.append(
            list(range(current_index, current_index + obj['count'])))
        current_index += obj["count"]

    # info_neurons is just an array of the information from above. This makes it easier to run the functions and pass the information.
    # info_times same for times
    network_architecture = dict(
        num_exc_neurons_per_layer=64 * 64,
        num_inh_neurons_per_layer=32 * 32,
        num_layers=4,
        # total_per_layer = num_exc_neurons_per_layer + num_inh_neurons_per_layer,
        # total_network = total_per_layer * num_layers,
        # num_stimuli = 16
    )

    info_times = dict(length_of_stimulus=2.0,
                      num_stimuli=n_stimuli,
                      time_start=1.5,
                      time_end=1.9)

    spikes = data.load_spikes_from_subfolders(masterpath, subfolders,
                                              extensions, False)
    start = timer()
    # rates_subfolders = firing.slow_calculate_rates_subfolder(
    #     spikes,
    #     network_architecture,
    #     info_times)
    # print("Non multiprocessing version took {}".format(timer() - start))

    start = timer()
    rates_subfolders = firing.calculate_rates_subfolder(
        spikes, network_architecture, info_times)
    print("Multiprocessing version took {}".format(timer() - start))
    exc_information, inhibitory_information = info.single_cell_information_all_epochs(
        rates_subfolders[0], object_indices, 3)
    ani = spikeplot.plot_animated_histogram(exc_information)
    import matplotlib.pyplot as plt
    plt.show()
Beispiel #2
0
def test_mutual_and_single_cell_info():
    ## set the Masterpath to the folder where your output is saved
    n_epochs = 188

    masterpath = "/Users/clemens/Documents/Code/ModelClemens/output"
    ## set the subfolder to the Simulation you want to analyse

    subfolders = ["11_05-20_04_loc1_both"]
    ## if more than the inital epoch is needed *1 needs to be run
    extensions = ["initial"]  # + ["testing/epoch180"]

    object_list = data.load_testing_stimuli_info(
        masterpath + "/" +
        subfolders[0])  # assuming all the subfolders have the same
    n_stimuli = np.sum(obj['count'] for obj in object_list)

    # info_neurons is just an array of the information from above. This makes it easier to run the functions and pass the information.
    # info_times same for times
    network_architecture = dict(
        num_exc_neurons_per_layer=64 * 64,
        num_inh_neurons_per_layer=32 * 32,
        num_layers=4,
        # total_per_layer = num_exc_neurons_per_layer + num_inh_neurons_per_layer,
        # total_network = total_per_layer * num_layers,
        # num_stimuli = 16
    )

    info_times = dict(length_of_stimulus=2.0,
                      num_stimuli=n_stimuli,
                      time_start=1.5,
                      time_end=1.9)

    # objects_in_training = [
    #     object_list[0]['indices'] + object_list[1]['indices'] + object_list[2]['indices'] + object_list[3]['indices'],
    #     object_list[4]['indices'] + object_list[5]['indices'] + object_list[6]['indices'] + object_list[7]['indices'],
    # ]
    # # These Objects were bound together in training with temporal trace. so it should have learned information about them.
    # print(objects_in_training)
    object_indices = [obj['indices'] for obj in object_list]

    spikes = data.load_spikes_from_subfolders(masterpath, subfolders,
                                              extensions, False)

    rates_subfolders = firing.calculate_rates_subfolder(
        spikes, network_architecture, info_times)
    exh_mutual_info, inh_mutual_info = info.firing_rates_to_mutual_information(
        rates_subfolders[0][0], object_indices, 3, calc_inhibitory=True)
    exc_single_cell, inh_single_cell = info.firing_rates_to_single_cell_information(
        rates_subfolders[0][0], object_indices, 3, calc_inhibitory=True)

    assert (np.all(
        np.isclose(exh_mutual_info[0], np.mean(exc_single_cell, axis=0))))
    assert (np.all(
        np.isclose(inh_mutual_info[0], np.mean(inh_single_cell, axis=0))))
Beispiel #3
0
def test_single_cell_decoder():
    path = "/Users/clemens/Documents/Code/ModelClemens/output"
    experiment = "12_27-18_57_all_no_trace"
    extension = "testing/epoch300"

    object_list = data.load_testing_stimuli_indices_from_wildcarts(
        path + "/" + experiment, ["***l", "***r"])
    print(object_list)
    object_indices = [o['indices'] for o in object_list]
    print(object_indices)
    n_stimuli = np.sum([o['count'] for o in object_list])

    label_for_classifier = np.zeros((2, n_stimuli), dtype=bool)
    for i, o in enumerate(object_list):
        label_for_classifier[i, o['indices']] = True

    label_for_classifier_from_data_loading = data.load_testing_stimuli_label_matrix(
        path + "/" + experiment, ["***l", "***r"])
    assert (np.all(
        label_for_classifier == label_for_classifier_from_data_loading))

    print(label_for_classifier)

    network_architecture = dict(num_exc_neurons_per_layer=64 * 64,
                                num_inh_neurons_per_layer=32 * 32,
                                num_layers=4)

    info_times = dict(length_of_stimulus=2.0,
                      num_stimuli=n_stimuli,
                      time_start=1.5,
                      time_end=1.9)

    spikes = data.load_spikes_from_subfolders(path, [experiment], [extension],
                                              False)

    rates_subfolders = firing.calculate_rates_subfolder(
        spikes, network_architecture, info_times)

    exc_rates, inh_rates = helper.nested_list_of_stimuli_2_np(
        rates_subfolders[0][0])

    dec = info.SingleCellDecoder()
    perf_train = dec.fit(exc_rates, label_for_classifier)

    perf_sumary = dec.get_performance_summary(exc_rates, label_for_classifier)

    perf_test = perf_sumary.accuracy()

    assert (np.all(perf_train == perf_test))
    print(perf_train == perf_test)
    print("done")
Beispiel #4
0
def test_weighted_presynaptic_firing_rates():
    path = "/Users/clemens/Documents/Code/ModelClemens/output/"
    subfolders = ["11_06-15_00_loc1_centered"]
    extensions = ["initial"
                  ] + ["testing/epoch{}".format(e) for e in range(1, 30)]

    net, weights = data.load_weights_all_epochs(path + subfolders[0],
                                                range(1, 30))

    object_list = data.load_testing_stimuli_info(
        path + subfolders[0])  # assuming all the subfolders have the same
    n_stimuli = np.sum(obj['count'] for obj in object_list)
    object_indices = [obj['indices'] for obj in object_list]

    network_architecture = dict(num_exc_neurons_per_layer=64 * 64,
                                num_inh_neurons_per_layer=32 * 32,
                                num_layers=4)

    info_times = dict(length_of_stimulus=2.0,
                      num_stimuli=n_stimuli,
                      time_start=1.5,
                      time_end=1.9)

    spikes = data.load_spikes_from_subfolders(path, subfolders, extensions,
                                              False)

    rates_subfolders = firing.calculate_rates_subfolder(
        spikes, network_architecture, info_times)

    exc_rates, inh_rates = helper.nested_list_of_epochs_2_np(
        rates_subfolders[0])

    mymask = synapses.Synapse_Mask(network_architecture, net)

    neuron_id = 5939

    excitatory_mask = np.invert(mymask.inh_lateral())

    overall_mask = excitatory_mask & (net.post.values == neuron_id)

    weighted_current = synapses.weighted_presynaptic_actvity(
        overall_mask,
        net=net,
        weights=weights,
        firing_rates=(exc_rates, inh_rates))

    return weighted_current
Beispiel #5
0
def summary_for_experiment(name):
    exp_path = output_path + "/" + name

    overview_path = exp_path + "/" + overview_folder_name

    epoch_names = ["initial"] + data.get_epochs(exp_path)

    object_list = data.load_testing_stimuli_info(exp_path)
    n_stimuli = np.sum(obj['count'] for obj in object_list)
    object_indices = [obj['indices'] for obj in object_list]
    stimuli_names = data.load_testing_stimuli_names(exp_path)

    info_times["num_stimuli"] = n_stimuli

    spikes = data.load_spikes_from_subfolders(output_path, [name], epoch_names,
                                              False)

    rates_subfolders = firing.calculate_rates_subfolder(
        spikes, network_architecture, info_times)

    spikes = None

    exc_information, inh_information = info.single_cell_information_all_epochs(
        rates_subfolders[0], object_indices, 3)

    ### make and save plots
    os.mkdir(overview_path)

    info_dev_plot = spikeplot.plot_information_development(exc_information,
                                                           mean_of_top_n=500,
                                                           threshold=1)
    info_dev_plot.savefig(overview_path + "/performance_dev.png")

    for r in plot_fr_at:
        epoch_id = int(r * (len(epoch_names) - 1))

        cur_epoch_fr_plot = spikeplot.plot_fr_ranked(
            rates_subfolders[0][epoch_id],
            stimuli_names,
            percentage_to_plot=0.5)
        epoch_name = epoch_names[epoch_id].split("/")[-1]
        make_pdf("{}/firing_rates_{}.pdf".format(overview_path, epoch_name),
                 cur_epoch_fr_plot)

    return
Beispiel #6
0
def test_functional_freq_table():
    ## set the Masterpath to the folder where your output is saved

    masterpath = "/Users/clemens/Documents/Code/ModelClemens/output"
    ## set the subfolder to the Simulation you want to analyse

    subfolders = ["2017:10:20-16:50:34_only_first_location_123_epochs"]
    ## if more than the inital epoch is needed *1 needs to be run
    extensions = ["testing/epoch5", "testing/epoch123"]

    # info_neurons is just an array of the information from above. This makes it easier to run the functions and pass the information.
    # info_times same for times
    network_architecture = dict(
        num_exc_neurons_per_layer=64 * 64,
        num_inh_neurons_per_layer=32 * 32,
        num_layers=4,
        # total_per_layer = num_exc_neurons_per_layer + num_inh_neurons_per_layer,
        # total_network = total_per_layer * num_layers,
        # num_stimuli = 16
    )

    info_times = dict(length_of_stimulus=2.0,
                      num_stimuli=16,
                      time_start=1.5,
                      time_end=1.9)

    spikes = data.load_spikes_from_subfolders(masterpath, subfolders,
                                              extensions, False)

    rates_subfolders = firing.calculate_rates_subfolder(
        spikes, network_architecture, info_times)
    final_epoch_rates = rates_subfolders[0][1]
    objects = [[0, 1, 2, 3, 8, 9, 10, 11], [4, 5, 6, 7, 12, 13, 14,
                                            15]]  # each is presented twice
    exc_rates, inh_rates = helper.nested_list_of_stimuli_2_np(
        final_epoch_rates)
    freq_table = combine.response_freq_table(exc_rates, objects)
    single_cell_info = info.single_cell_information(freq_table)
    return single_cell_info
    def test_single_cell_information(self):
        masterpath = "/Users/clemens/Documents/Code/ModelClemens/output"
        ## set the subfolder to the Simulation you want to analyse

        subfolders = ["10_26-18_14_short_test_loc1"]
        ## if more than the inital epoch is needed *1 needs to be run
        extensions = ["initial"]

        # info_neurons is just an array of the information from above. This makes it easier to run the functions and pass the information.
        # info_times same for times
        network_architecture = dict(
            num_exc_neurons_per_layer=64 * 64,
            num_inh_neurons_per_layer=32 * 32,
            num_layers=4,
            # total_per_layer = num_exc_neurons_per_layer + num_inh_neurons_per_layer,
            # total_network = total_per_layer * num_layers,
            # num_stimuli = 16
        )

        info_times = dict(length_of_stimulus=2.0,
                          num_stimuli=16,
                          time_start=1.5,
                          time_end=1.9)
        n_bins = 3

        spikes = data.load_spikes_from_subfolders(masterpath,
                                                  subfolders,
                                                  extensions,
                                                  input_layer=False)

        firing_rates = firing.calculate_rates_subfolder(
            spikes, network_architecture, info_times)

        rates = firing_rates[0][0]
        exc_rates, inh_rates = helper.nested_list_of_stimuli_2_np(rates)

        objects = [[0, 1, 2, 3, 8, 9, 10, 11], [4, 5, 6, 7, 12, 13, 14,
                                                15]]  # each is presented twice

        start = timer()
        exc_table = combine.response_freq_table(exc_rates,
                                                objects,
                                                n_bins=n_bins)

        exc_info = info.single_cell_information(exc_table)

        final_new_info_l2 = exc_info[:,
                                     2, :]  # shape [2, n_neurons] for both objects all info in layer 2
        print("New version of info calc took {}s".format(timer() - start))

        ### calculating it the old way
        import InformationAnalysis as infoOld

        categories = np.zeros((56, 1))
        categories[
            28:,
            0] = 1  # simulating the fact that we have 2 objects -> stimuli with only one attribute, object_id 1 or 0

        start = timer()
        digitized_firing_rates = firing.digitize_firing_rates_with_equispaced_bins(
            exc_rates, n_bins=n_bins)

        digitized_firing_rates_l2 = digitized_firing_rates[:, 2, :]

        freq_table_old = infoOld.frequency_table(digitized_firing_rates_l2,
                                                 categories,
                                                 list(range(n_bins)))
        final_old_info_l2 = infoOld.single_cell_information(
            freq_table_old, categories)[0]
        print("Old version of info calc took {}s".format(timer() - start))

        assert (np.all(np.isclose(final_new_info_l2, final_old_info_l2)))