Ejemplo n.º 1
0
def create_routine_turn_overlap_plot(p1, p2, p3, n):
    prey_cloud_left = []
    for i in range(1, n + 1):
        data = load_data(p1, p2, f"{p3}-{i}")
        prey_1, pred_1 = get_clouds_with_action(data, 1)
        prey_cloud_left = prey_cloud_left + prey_1
    prey_cloud_right = []
    for i in range(1, n + 1):
        data = load_data(p1, p2, f"{p3}-{i}")
        prey_1, pred_1 = get_clouds_with_action(data, 2)
        prey_cloud_right = prey_cloud_right + prey_1
    n_samples = len(prey_cloud_left) + len(prey_cloud_right)
    # For left
    x = np.array([i[0] for i in prey_cloud_left])
    y = np.array([i[1] for i in prey_cloud_left])
    #y = np.negative(y)
    nbins = 300
    k = kde.gaussian_kde([y, x])
    yi, xi = np.mgrid[x.min():x.max():nbins * 1j, y.min():y.max():nbins * 1j]

    zi = k(np.vstack([xi.flatten(), yi.flatten()]))

    # For right
    x = np.array([i[0] for i in prey_cloud_right])
    y = np.array([i[1] for i in prey_cloud_right])
    #y = np.negative(y)
    nbins = 300
    k = kde.gaussian_kde([y, x])
    zi2 = k(np.vstack([xi.flatten(), yi.flatten()]))

    zi = zi2 - zi

    fig, ax = plt.subplots()

    ax.pcolormesh(xi, yi, zi.reshape(xi.shape), cmap='RdBu')

    ob = AnchoredHScaleBar(
        size=100,
        label="10mm",
        loc=4,
        frameon=True,
        pad=0.6,
        sep=4,
        linekw=dict(color="crimson"),
    )
    ax.add_artist(ob)
    plt.arrow(300, 220, 0, 40, width=10, color="red")
    ax.axes.get_xaxis().set_visible(False)
    ax.axes.get_yaxis().set_visible(False)
    plt.title(f"Feature: Prey, Action: Routine turns")
    plt.show()
Ejemplo n.º 2
0
def show_all_observations(p1, p2, p3, n):
    for action_num in range(0, 10):
        observation_tally = []
        for i in range(1, n + 1):
            data = load_data(p1, p2, f"{p3}-{i}")
            observation = data["observation"]
            time_points_for_bout = [
                i for i, a in enumerate(data["behavioural choice"])
                if a == action_num
            ]
            for index, o in enumerate(observation):
                if index in time_points_for_bout:
                    observation_tally.append(o)
        if len(observation_tally) > 0:
            observation_tally = observation_tally[:30]
            observation_tally = order_observation_tally(observation_tally)

            fig, axs = plt.subplots(len(observation_tally), 2, sharex=True)
            fig.set_size_inches(18.5, 20)

            plt.title(f"Action: {action_num}")
            for i, o in enumerate(observation_tally):
                o = convert_photons_to_int(o)
                left = o[:, :, 0]
                right = o[:, :, 1]
                left = np.expand_dims(left, axis=0)
                right = np.expand_dims(right, axis=0)

                axs[i][0].imshow(left, aspect="auto")
                axs[i][1].imshow(right, aspect="auto")
            axs[len(observation_tally) - 1][0].set_yticklabels([])
            axs[len(observation_tally) - 1][1].set_yticklabels([])

            plt.show()
def get_escape_sequences(model_name, assay_config, assay_id, n):
    all_escape_sequences = []
    for i in range(1, n + 1):
        data = load_data(model_name, assay_config, f"{assay_id}-{i}")
        all_escape_sequences = all_escape_sequences + extract_predator_action_sequences(
            data)[0]
    return all_escape_sequences
Ejemplo n.º 4
0
def average_visual_input_for_bouts(p1, p2, p3, n):
    for action_num in range(0, 10):
        observation_tally = []
        for i in range(1, n + 1):
            data = load_data(p1, p2, f"{p3}-{i}")
            data = remove_near_wall_data(data, 1500, 1500)
            observation = data["observation"]
            time_points_for_bout = [
                i for i, a in enumerate(data["behavioural choice"])
                if a == action_num
            ]
            for index, o in enumerate(observation):
                if index in time_points_for_bout:
                    observation_tally.append(o)

        if len(observation_tally) > 0:
            average_observation = take_observation_mode(observation_tally)
            left = average_observation[:, :, 0]
            right = average_observation[:, :, 1]
            left = np.expand_dims(left, axis=0)
            right = np.expand_dims(right, axis=0)

            fig, axs = plt.subplots(2, 1, sharex=True)

            plt.title(f"Action: {action_num}")
            axs[0].imshow(left, aspect="auto")
            axs[0].set_yticklabels([])
            axs[1].imshow(right, aspect="auto")
            axs[1].set_yticklabels([])

            plt.show()
Ejemplo n.º 5
0
def get_measures_random(model, targeted_neurons, number_of_trials):
    prey_caught = 0
    predators_avoided = 0
    for i in range(1, number_of_trials+1):
        data1 = load_data(model, f"Ablation-Test-{targeted_neurons}", f"Random-Control-{i}")
        prey_caught = prey_caught + sum(data1['consumed'])
        predators_avoided = predators_avoided + get_predator_num(data1)
    return prey_caught/number_of_trials, predators_avoided/number_of_trials
Ejemplo n.º 6
0
def real_prey_position():
    data = load_data("new_even_prey_ref-3", f"Behavioural-Data-Free", "Prey-1")
    sns.set()
    chosen_prey_position = [step[5] for step in data["prey_positions"]][:100]
    plt.plot([i[0] for i in chosen_prey_position],
             [i[1] for i in chosen_prey_position])
    plt.show()
    x = True
Ejemplo n.º 7
0
def get_measures_random_gradient(model, targeted_neurons, percentage, number_of_trials):
    prey_caught = 0
    predators_avoided = 0
    for i in range(1, number_of_trials+1):
        print(i)
        data1 = load_data(model, f"Ablation-{targeted_neurons}", f"Ablated-{percentage}-{i}")
        prey_caught = prey_caught + sum(data1['consumed'])
        predators_avoided = predators_avoided + get_predator_num(data1)
    return prey_caught/number_of_trials, predators_avoided/number_of_trials
Ejemplo n.º 8
0
def get_full_eta(model_name, configuration, assay_id, number_of_trials, event):
    etas = [0 for i in range(0, 512)]
    for i in range(1, number_of_trials + 1):
        data = load_data(model_name, configuration, f"{assay_id}-{i}")
        eta = get_eta(data, event)
        etas = [new + etas[i] for i, new in enumerate(eta)]
    for i, et in enumerate(etas):
        etas[i] = et / number_of_trials
    return etas
def get_action_freq(model, ablation_config, per, number_of_trials):
    actions = [0 for i in range(10)]
    for i in range(1, number_of_trials + 1):
        data = load_data(model, f"Ablation-{ablation_config}",
                         f"Ablated-{per}-{i}")
        for a in range(10):
            actions[a] += len(
                [ac for ac in data["behavioural choice"] if ac == a])
    return actions
Ejemplo n.º 10
0
def get_all_density_plots_all_subsets(p1, p2, p3, n):
    for action_num in range(0, 10):
        prey_cloud = []
        pred_cloud = []
        for i in range(1, n + 1):
            if i > 12:
                data = load_data(p1, f"{p2}-2", f"{p3} {i}")
            else:
                data = load_data(p1, p2, f"{p3}-{i}")

            prey_1, pred_1 = get_clouds_with_action(data, action_num)
            prey_cloud = prey_cloud + prey_1
            pred_cloud = pred_cloud + pred_1

        if len(prey_cloud) > 2:
            create_density_cloud(prey_cloud, action_num, "Prey")

        if len(pred_cloud) > 2:
            create_density_cloud(pred_cloud, action_num, "Predator")
Ejemplo n.º 11
0
def get_first_order_transition_counts(p1, p2, p3, n):
    transition_counts = np.zeros((10, 10))
    for file_index in range(1, n + 1):
        data = load_data(p1, p2, f"{p3}-{file_index}")
        for i, a in enumerate(data["behavioural choice"]):
            if i == 0:
                pass
            else:
                transition_counts[data["behavioural choice"][i - 1]][a] += 1

    return transition_counts
Ejemplo n.º 12
0
def create_full_response_vector(model_name, background=False):
    # Creates the full 484 dimensional response vector.
    response_vectors = [[] for i in range(512)]
    file_precursors = ["Prey", "Predator"]
    prey_assay_ids = [
        "Prey-Static-5", "Prey-Static-10", "Prey-Static-15", "Prey-Left-5",
        "Prey-Left-10", "Prey-Left-15", "Prey-Right-5", "Prey-Right-10",
        "Prey-Right-15", "Prey-Away", "Prey-Towards"
    ]
    predator_assay_ids = [
        "Predator-Static-40", "Predator-Static-60", "Predator-Static-80",
        "Predator-Left-40", "Predator-Left-60", "Predator-Left-80",
        "Predator-Right-40", "Predator-Right-60", "Predator-Right-80",
        "Predator-Away", "Predator-Towards"
    ]
    if background:
        prey_assay_ids += ["Background-" + i for i in prey_assay_ids]
        predator_assay_ids += ["Background-" + i for i in predator_assay_ids]
    for file_p in file_precursors:
        if "Prey" in file_p:
            for aid in prey_assay_ids:
                data = load_data(model_name, f"{file_p}-Full-Response-Vector",
                                 aid)
                stimulus_data = load_stimulus_data(
                    model_name, f"{file_p}-Full-Response-Vector", aid)
                # stimulus_data = new_load_stimulus_data(model_name, f"{file_p}-Full-Response-Vector", aid)
                new_vector_section = get_all_neuron_vectors(
                    data, "prey 1", stimulus_data, "rnn state")
                for i, n in enumerate(response_vectors):
                    response_vectors[i] = n + new_vector_section[i]
        elif "Predator" in file_p:
            for aid in predator_assay_ids:
                data = load_data(model_name, f"{file_p}-Full-Response-Vector",
                                 aid)
                stimulus_data = load_stimulus_data(
                    model_name, f"{file_p}-Full-Response-Vector", aid)
                new_vector_section = get_all_neuron_vectors(
                    data, "predator 1", stimulus_data, "rnn state")
                for i, n in enumerate(response_vectors):
                    response_vectors[i] = n + new_vector_section[i]
    return response_vectors
Ejemplo n.º 13
0
def create_behavioural_response_vector(model_name, background=False):
    # Creates the full 484 dimensional response vector.
    action_vector = []
    if background:
        file_precursors = [
            "Prey", "Predator", "Background-Prey", "Background-Predator"
        ]
    else:
        file_precursors = ["Prey", "Predator"]
    prey_assay_ids = [
        "Prey-Static-5", "Prey-Static-10", "Prey-Static-15", "Prey-Left-5",
        "Prey-Left-10", "Prey-Left-15", "Prey-Right-5", "Prey-Right-10",
        "Prey-Right-15", "Prey-Away", "Prey-Towards"
    ]
    predator_assay_ids = [
        "Predator-Static-40", "Predator-Static-60", "Predator-Static-80",
        "Predator-Left-40", "Predator-Left-60", "Predator-Left-80",
        "Predator-Right-40", "Predator-Right-60", "Predator-Right-80",
        "Predator-Away", "Predator-Towards"
    ]
    for file_p in file_precursors:
        if "Prey" in file_p:
            for aid in prey_assay_ids:
                data = load_data(model_name, f"{file_p}-Full-Response-Vector",
                                 aid)
                stimulus_data = load_stimulus_data(
                    model_name, f"{file_p}-Full-Response-Vector", aid)
                new_vector_section = get_behavioural_vector(
                    data, "prey 1", stimulus_data)
                action_vector = action_vector + new_vector_section
        elif "Predator" in file_p:
            for aid in predator_assay_ids:
                data = load_data(model_name, f"{file_p}-Full-Response-Vector",
                                 aid)
                stimulus_data = load_stimulus_data(
                    model_name, f"{file_p}-Full-Response-Vector", aid)
                new_vector_section = get_behavioural_vector(
                    data, "predator 1", stimulus_data)
                action_vector = action_vector + new_vector_section
    return action_vector
Ejemplo n.º 14
0
def save_all_categorisations(model_name):
    event_triggered_average_data = load_data(model_name, "Naturalistic",
                                             "Naturalistic-1")
    action_triggered_averages = get_eta(event_triggered_average_data,
                                        "actions")
    # TODO: Make work for any other associations
    full_rv = create_full_response_vector(model_name)
    full_sv = create_full_stimulus_vector(model_name)
    sel = label_all_units_selectivities(full_rv, full_sv)
    broad_categories = assign_neuron_names(sel)
    d = get_formatted_data(broad_categories, action_triggered_averages, sel)
    with open(f"../Categorisation-Data/{model_name}_categories.json",
              "w") as outfile:
        json.dump(d, outfile, indent=4)
def get_action_freq_predator_sequences(model, ablation_config, per,
                                       number_of_trials):
    actions = [0 for i in range(10)]
    for i in range(1, number_of_trials + 1):
        data = load_data(model, f"Ablation-{ablation_config}",
                         f"Ablated-{per}-{i}")
        for a in range(10):
            predator_timestamps = [
                i - 1 for i in data["step"] if data["predator"][i - 1] == 1
            ]
            actions[a] += len([
                ac for i, ac in enumerate(data["behavioural choice"])
                if ac == a and i in predator_timestamps
            ])
    return actions
Ejemplo n.º 16
0
def get_all_attempted_captures(model_name, assay_name, n=6):
    percentages = range(0, 110, 10)
    attempted_captures = []
    successful_captures = []
    sns.set()
    for per in percentages:
        attempted, successful = 0, 0
        for i in range(1, n + 1):
            ac, sc = extract_attempted_captures(
                load_data(model_name, f"Ablation-Test-{assay_name}",
                          f"Ablated-{per}-{i}"))
            attempted += ac
            successful += sc
        attempted_captures.append(attempted / n)
        successful_captures.append(successful / n)
    return attempted_captures
def create_photoreceptor_input_graph(model, config, assay_id):
    data = load_data(model, config, assay_id)
    observation = data["observation"]
    left_1 = observation[:, :, :, 0]
    left_1 = np.swapaxes(left_1, 0, 1)
    right_1 = observation[:, :, :, 1]
    right_1 = np.swapaxes(right_1, 0, 1)

    fig, axs = plt.subplots(2, 1, sharex=True)

    axs[0].imshow(left_1, aspect="auto")
    axs[0].set_ylabel("Left eye Photoreceptor")
    axs[1].imshow(right_1, aspect="auto")
    axs[1].set_ylabel("Right eye Photoreceptor")
    axs[1].set_xlabel("Step")
    plt.show()
Ejemplo n.º 18
0
def get_full_predator_eta_timeseries(model_name,
                                     configuration,
                                     assay_id,
                                     number_of_trials,
                                     window=5):
    eta_timeseries = [[0 for j in range(2 * window)] for k in range(512)]
    used_trials = 0
    for i in range(1, number_of_trials + 1):
        print(i)
        data = load_data(model_name, configuration, f"{assay_id}-{i}")
        new_ata_t = get_predator_eta_timeseries(data, window)
        if new_ata_t is not None:
            used_trials += 1
            eta_timeseries = [[m + new_ata_t[i][j] for j, m in enumerate(n)]
                              for i, n in enumerate(eta_timeseries)]
    for i, neuron in enumerate(eta_timeseries):
        eta_timeseries[i] = [
            neuron[n] / used_trials for n in range(len(neuron))
        ]
    return eta_timeseries
Ejemplo n.º 19
0
def get_full_action_triggered_average(model_name, configuration, assay_id,
                                      number_of_trials):
    action_triggered_averages = {
        str(i): [0 for i in range(512)]
        for i in range(10)
    }
    for i in range(1, number_of_trials + 1):
        data = load_data(model_name, configuration, f"{assay_id}-{i}")
        new_ata = get_action_triggered_average(data)
        for key in new_ata.keys():
            action_triggered_averages[key] = [
                n + new_ata[key][i]
                for i, n in enumerate(action_triggered_averages[key])
            ]
    for key in action_triggered_averages.keys():
        action_triggered_averages[key] = [
            action_triggered_averages[key][n] / number_of_trials
            for n in range(len(action_triggered_averages[key]))
        ]
    return action_triggered_averages
Ejemplo n.º 20
0
def get_full_ata_timeseries(model_name,
                            configuration,
                            assay_id,
                            number_of_trials,
                            window=5):
    ata_timeseries = {
        str(i): [[0 for j in range(2 * window)] for k in range(512)]
        for i in range(10)
    }
    for i in range(1, number_of_trials + 1):
        data = load_data(model_name, configuration, f"{assay_id}-{i}")
        new_ata_t = get_ata_timeseries(data, window)
        for key in new_ata_t.keys():
            ata_timeseries[key] = [[
                m + new_ata_t[key][i][j] for j, m in enumerate(n)
            ] for i, n in enumerate(ata_timeseries[key])]
    for key in ata_timeseries.keys():
        for i, neuron in enumerate(ata_timeseries[key]):
            ata_timeseries[key][i] = [
                neuron[n] / number_of_trials for n in range(len(neuron))
            ]
    return ata_timeseries
Ejemplo n.º 21
0
def plot_attempted_captures(model_name, assay_name, n=6):
    percentages = range(0, 110, 10)
    attempted_captures = []
    successful_captures = []
    sns.set()
    for per in percentages:
        attempted, successful = 0, 0
        for i in range(1, n + 1):
            ac, sc = extract_attempted_captures(
                load_data(model_name, f"Ablation-Test-{assay_name}",
                          f"Ablated-{per}-{i}"))
            attempted += ac
            successful += sc
        attempted_captures.append(attempted / n)
        successful_captures.append(successful / n)

    plt.plot(percentages, successful_captures, label="Successful captures")
    plt.plot(percentages, attempted_captures, label="Attempted captures")
    plt.xlabel("Percentage ablated")
    plt.ylabel("Captures")
    plt.legend()
    plt.show()
Ejemplo n.º 22
0
def get_full_eta_timeseries(model_name,
                            configuration,
                            assay_id,
                            number_of_trials,
                            event="consumed",
                            window=10):
    if event == "predator":
        return get_full_predator_eta_timeseries(model_name,
                                                configuration,
                                                assay_id,
                                                number_of_trials,
                                                window=5)
    eta_timeseries = [[0 for j in range(2 * window + 1)] for k in range(512)]
    for i in range(1, number_of_trials + 1):
        data = load_data(model_name, configuration, f"{assay_id}-{i}")
        new_ata_t = get_eta_timeseries(data, event, window)
        eta_timeseries = [[m + new_ata_t[i][j] for j, m in enumerate(n)]
                          for i, n in enumerate(eta_timeseries)]
    for i, neuron in enumerate(eta_timeseries):
        eta_timeseries[i] = [
            neuron[n] / number_of_trials for n in range(len(neuron))
        ]
    return eta_timeseries
Ejemplo n.º 23
0
    # axs[4].plot(rnn_data[3])
    # axs[4].set_ylabel("Unit 4 activity", fontsize=25)
    axs[3].set_xlabel("Step", fontsize=25)
    axs[0].tick_params(labelsize=15)
    axs[1].tick_params(labelsize=15)
    axs[2].tick_params(labelsize=15)
    axs[3].tick_params(labelsize=15)
    # axs[4].tick_params(labelsize=15)

    # axs[0].set_ylim(0.5, 1.5)
    fig.set_size_inches(18.5, 20)
    fig.savefig('test2png.png', dpi=100)
    plt.show()


data = load_data("changed_penalties-2", "Naturalistic", "Naturalistic-1")

# with open("../Assay-Output/base-1/Visual-Stimulus-Assay-1.json", "r") as file:
#     data = json.load(file)

# Shorten action choice

# action_choice = action_choice[200: 500]
# rnn_unit_1 = rnn_unit_1[200: 500]
# rnn_unit_2 = rnn_unit_2[200: 500]
# rnn_unit_3 = rnn_unit_3[200: 500]
# rnn_unit_200 = rnn_unit_200[200: 500]


# To print individual for each action
# for i in range(6):
Ejemplo n.º 24
0
                prey_timestamps.append(i)
                break
    # Check prey near at each step and add to timestamps.
    null_timestamps = predator_timestamps + wall_timestamps + prey_timestamps
    null_timestamps = set(null_timestamps)
    desired_timestamps = [
        i for i in range(len(data["behavioural choice"]))
        if i not in null_timestamps
    ]
    return desired_timestamps


def get_space_triggered_averages(data, indexes):
    neuron_baseline = [
        np.mean(data["rnn state"][:, :, i])
        for i in range(len(data["rnn state"][0][0]))
    ]
    neuron_averages = [0 for i in range(len(data["rnn state"][0][0]))]
    for i in indexes:
        for n in range(len(data["rnn state"][0][0])):
            neuron_averages[n] += data["rnn state"][i, 0, n]
    for n, neuron in enumerate(neuron_averages):
        neuron_averages[n] = (((neuron / len(indexes)) - neuron_baseline[n]) /
                              neuron_baseline[n]) * 100
    return neuron_averages


d = load_data("even_prey_ref-5", "Empty-Environment", "Empty-1")
ind = get_free_swimming_indexes(d)
sta = get_space_triggered_averages(d, ind)
x = True
Ejemplo n.º 25
0
    n_subplots = len(neuron_data)
    n_per_plot = 20
    n_plots = math.ceil(n_subplots / n_per_plot)

    for i in range(n_plots):
        if i == n_plots - 1:
            neuron_subset_data = neuron_data[(i * n_per_plot):]
        else:
            neuron_subset_data = neuron_data[(i *
                                              n_per_plot):(i * n_per_plot) +
                                             n_per_plot]
        create_plot(neuron_subset_data, i + 1, len(neuron_subset_data),
                    i * n_per_plot)


data1 = load_data("even_prey_ref-5", "For-Traces", "Predator-Static-40")
data2 = load_data("even_prey_ref-5", "For-Traces", "Prey-Static-10")
n_c_neurons = data1["left_conv_4"].shape[-1]

# a_neuron = [data["left_conv_4"][i, 0, :, 0] for i in range(len(data["left_conv_4"]))]

left_neurons = [[
    data1["left_conv_4"][i, 0, :, j] for i in range(len(data1["left_conv_4"]))
] for j in range(n_c_neurons)]
right_neurons = [[
    data2["right_conv_4"][i, 0, :, j]
    for i in range(len(data2["right_conv_4"]))
] for j in range(n_c_neurons)]

plot_multiple_traces(left_neurons)
plot_multiple_traces(right_neurons)
Ejemplo n.º 26
0
    predators_avoided_gradient = []
    percentages = list(range(0, 100, 5)) + list(range(96, 100, 1))

    for per in percentages:
        # if per == 35: continue  # Remove later.
        prey_caught, predators_avoided = get_measures_random_gradient(model, targeted_neurons, per,
                                                                      number_of_trials)
        print(f"Ablations: {per}%, Prey caught: {prey_caught}, Predators avoided: {predators_avoided}")
        prey_caught_gradient.append(prey_caught)
        predators_avoided_gradient.append(predators_avoided)

    # prey_caught_cont_abl, predators_avoided = get_measures_random(model, targeted_neurons, number_of_trials)
    # print(f"Control (random ablation): Prey caught: {prey_caught_cont_abl}, Predators avoided: {predators_avoided}")
    return prey_caught_gradient, predators_avoided_gradient

for i in range(1,13):
    data1 = load_data("new_even_prey_ref-4", "Ablation-Test-Predator_Only-behavioural_data", f"Random-Control-{i}")
    print(sum(data1["consumed"]))

# get_both_measures_random_gradient("new_even_prey_ref-1", "Indiscriminate-even_prey_only", 3)
# print("\n")
# get_both_measures_random_gradient("new_even_prey_ref-1", "Indiscriminate-even_naturalistic", 3)

# get_both_measures("new_differential_prey_ref-4", "Prey-Sighted-differential_prey_low_predator", 3)
# get_both_measures("new_differential_prey_ref-4", "No-Response-differential_prey_low_predator", 3)

# get_both_measures("new_differential_prey_ref-4", "Prey-Sighted-differential_prey_only", 3)
# get_both_measures("new_differential_prey_ref-4", "No-Response-differential_prey_only", 3)


Ejemplo n.º 27
0
    # fig = plt.figure(figsize=(2, 1.25))
    # patches = [
    #     mpatches.Patch(color=color, label=label)
    #     for label, color in zip(labels, colors)]
    # fig.legend(patches, labels, loc='center', frameon=False)
    # plt.show()


import json
#
with open(f"../../Categorisation-Data/final_even2.json", 'r') as f:
    data2 = json.load(f)
placeholder_list = data2["new_even_prey_ref-4"]["3"] + data2[
    "new_even_prey_ref-4"]["16"]

data1 = load_data("new_even_prey_ref-4", "Behavioural-Data-Free",
                  "Naturalistic-8")
plot_certain_neurons(data1, 200, placeholder_list[:10])

## Naturalistic traces
# data1 = load_data("new_differential_prey_ref-4", "Behavioural-Data-Free-1", "Naturalistic-8")
# plot_certain_neurons(data1, 200, [20, 21, 139, 156, 161, 135, 133, 196])
# plot_behavioural_events(data1, 200)
# # Get exploraiton timeseries and add to that
# unit_activity1 = [[data1["rnn state"][i - 1][0][j] for i in range(200)] for j in range(512)]
# plot_traces(unit_activity1)

data1 = load_data("even_prey_ref-5", "For-Traces", "Prey-Static-10")
data2 = load_data("even_prey_ref-5", "For-Traces", "Predator-Static-40")
stimulus_data1 = load_stimulus_data("even_prey_ref-5", "For-Traces",
                                    "Prey-Static-10")
stimulus_data2 = load_stimulus_data("even_prey_ref-5", "For-Traces",
Ejemplo n.º 28
0
from Analysis.Behavioural.circle_maths import make_circle


def calculate_circle_diameter_for_points(data):
    x_values = [i[0] for i in data]
    y_values = [i[1] for i in data]
    max_x_i = x_values.index(max(x_values))
    min_x_i = x_values.index(min(x_values))
    max_y_i = y_values.index(max(y_values))
    min_y_i = y_values.index(min(y_values))

    ex_indexes = np.unique([max_x_i, min_y_i, min_x_i, max_y_i])
    extremeties = [data[i] for i in ex_indexes]
    r = make_circle(extremeties)[-1]
    return r * 2


def calculate_exploration_index(data, window_size):
    exploration_i = []
    for i in range(window_size, len(data["step"])):
        window_data = data["position"][i - window_size:i]
        exploration_i.append(calculate_circle_diameter_for_points(window_data))
    return exploration_i


data = load_data("large_all_features-1", "Naturalistic", "Naturalistic-1")

ex = calculate_exploration_index(data, 10)

x = True
Ejemplo n.º 29
0
# with open(f"../../Categorisation-Data/latest_even.json", 'r') as f:
#     data2 = json.load(f)

#
with open(f"../../Categorisation-Data/final_even2.json", 'r') as f:
    data2 = json.load(f)

# Single-point
ata = get_full_action_triggered_average("new_even_prey_ref-4",
                                        "Behavioural-Data-Free",
                                        "Naturalistic", 10)

# display_all_atas(ata, data2["new_even_prey_ref-4"])

data = load_data("new_even_prey_ref-4", "Behavioural-Data-Free",
                 "Naturalistic-1")
ex1 = get_full_eta("new_even_prey_ref-4", "Behavioural-Data-Free",
                   "Naturalistic", 10, "exploration")
ex2 = get_full_eta("new_even_prey_ref-4", "Behavioural-Data-Free",
                   "Naturalistic", 10, "consumed")
ex3 = get_full_eta("new_even_prey_ref-4", "Behavioural-Data-Free",
                   "Naturalistic", 10, "predator")

# display_all_etas([ex1, ex2, ex3], ["Exploration", "Consumption", "Predator"], data2["new_even_prey_ref-4"])

placeholder_list = data2["new_even_prey_ref-4"]["3"] + data2[
    "new_even_prey_ref-4"]["16"]
predator_only_ns = [
    2, 13, 19, 23, 27, 29, 34, 36, 46, 50, 60, 66, 81, 82, 93, 94, 95, 99, 100,
    106, 110, 113, 117, 119, 122, 135, 145, 150, 156, 163, 165, 169, 171, 174,
    182, 185, 186, 201, 203, 217, 218, 219, 220, 225, 226, 227, 238, 244, 259,
Ejemplo n.º 30
0
import numpy as np

from Analysis.load_data import load_data


def remove_near_wall_data(data, env_x, env_y, buffer=200):
    steps_near_wall = [
        i for i, position in enumerate(data["position"])
        if position[0] < buffer or position[1] < buffer
        or position[0] > env_x - buffer or position[1] > env_y - buffer
    ]
    # Doesnt work as this, might be best to decide what to do with the data - removal possibly, but would require splitting of the data.
    for key in data.keys():
        if key == 'consumed' or key == 'predator':
            pass
        else:
            # for step in reversed(steps_near_wall):
            data[key] = np.delete(data[key], steps_near_wall, axis=0)
    return data


data = load_data("even_prey-1", "Naturalistic", "Naturalistic-1")
data = remove_near_wall_data(data, 1500, 1500)

x = True