Example #1
0
def prey_position():
    stimulus_data = load_stimulus_data("new_differential_prey_ref-3",
                                       f"Prey-Full-Response-Vector",
                                       "Prey-Right-10")
    diff = stimulus_data[0]["prey 1"]["Onset"] - stimulus_data[0]["prey 1"][
        "Pre-onset"]
    steps = [[l["prey 1"]["Onset"], l["prey 1"]["Onset"] + diff]
             for l in stimulus_data]
    angles = [l["prey 1"]["Angle"] for l in stimulus_data]

    interpolated_steps = [list(range(st[0], st[1])) for st in steps]
    # interpolated_steps = []
    # for i in int_steps:
    #     interpolated_steps += i

    interpolated_angles = []
    for i, a in enumerate(angles):
        if i == len(angles) - 1:
            interpolated_angles.append(
                list(np.linspace(a, a + (angles[1] - angles[0]), diff)))
        else:
            interpolated_angles.append(
                list(np.linspace(a, angles[i + 1], diff)))

    sns.set()
    for i, step in enumerate(interpolated_steps):
        if i == len(angles) - 1:
            continue
        plt.plot(step, interpolated_angles[i])
    plt.ylabel("Stimulus Angle (pi radians)")
    plt.xlabel("Time (steps)")
    plt.show()
Example #2
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
Example #3
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
Example #4
0
def create_full_stimulus_vector(model_name, background=False):
    full_stimulus_vector = []
    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:
                stimulus_data = load_stimulus_data(
                    model_name, f"{file_p}-Full-Response-Vector", aid)
                stimulus_vector = get_stimulus_vector(stimulus_data, "prey 1")
                stimulus_vector = [aid + "-" + str(s) for s in stimulus_vector]
                full_stimulus_vector += stimulus_vector

        elif "Predator" in file_p:
            for aid in predator_assay_ids:
                stimulus_data = load_stimulus_data(
                    model_name, f"{file_p}-Full-Response-Vector", aid)
                stimulus_vector = get_stimulus_vector(stimulus_data,
                                                      "predator 1")
                stimulus_vector = [aid + "-" + str(s) for s in stimulus_vector]
                full_stimulus_vector += stimulus_vector

    return full_stimulus_vector
Example #5
0
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",
                                    "Predator-Static-40")

unit_activity1 = [[data1["rnn state"][i - 1][0][j] for i in data1["step"]]
                  for j in range(512)]
unit_activity2 = [[data2["rnn state"][i - 1][0][j] for i in data2["step"]]
                  for j in range(512)]

#
# plot_multiple_traces([unit_activity1, unit_activity2],
#                      [stimulus_data1, stimulus_data2],
#                      ["Prey", "Predator"])

data1 = load_data("even_prey_ref-50", "For-Traces", "Prey-Static-5")
data2 = load_data("even_prey_ref-50", "For-Traces", "Prey-Static-10")
Example #6
0
def plot_actions_and_activity(data, trace):
    action_choice = data["behavioural choice"]
    separated_actions = []
    fig, axs = plt.subplots(2, 1, sharex=True)
    for action in range(max(action_choice)):
        action_timestamps = [
            i for i, a in enumerate(action_choice) if a == action
        ]
        separated_actions.append(action_timestamps)
    colors = sns.color_palette("hls", max(action_choice))
    axs[0].plot(trace)
    axs[1].eventplot(separated_actions, color=colors)
    axs[0].set_ylabel("Unit activity")
    axs[1].set_ylabel("Action")
    axs[1].set_xlabel("Step")
    plt.show()


data1a = load_data("even_prey_ref-4", "Prey-Full-Response-Vector",
                   "Prey-Left-15")
stimulus_data1 = load_stimulus_data("even_prey_ref-4",
                                    "Prey-Full-Response-Vector",
                                    "Prey-Left-15")
unit_activity1a = [[data1a["rnn state"][i - 1][0][j] for i in data1a["step"]]
                   for j in range(512)]
activity = unit_activity1a[273]

# plot_actions_and_activity(data1a, activity)

# plot_traces(unit_activity1a, stimulus_data1)
Example #7
0
                          )
    axs[1].plot(rnn_data[1])
    axs[1].set_ylabel("Unit 2 activity", fontsize=25)
    axs[2].plot(rnn_data[2])
    axs[2].set_ylabel("Unit 3 activity", fontsize=25)
    axs[3].plot(rnn_data[3])
    axs[3].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[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("even_prey_ref-5", "For-Traces", "Prey-Static-10")
from Analysis.load_stimuli_data import load_stimulus_data
stimulus_data1 = load_stimulus_data("even_prey_ref-5", "For-Traces", "Prey-Static-10")

rnn_unit_1 = [data["rnn state"][i-1][0][0] for i in data["step"]]
rnn_unit_3 = [data["rnn state"][i-1][0][20] for i in data["step"]]
rnn_unit_200 = [data["rnn state"][i-1][0][70] for i in data["step"]]
conv_unit_1 = [data["rnn state"][i-1][0][69] for i in data["step"]]

unit_activity = [rnn_unit_1, rnn_unit_3, rnn_unit_200, conv_unit_1]
plot_activity(unit_activity, stimulus_data1)
Example #8
0
    continuous_trace = 1
    for i, step in enumerate(timesteps):
        if i == 0:
            pass
        else:
            if step - 1 == timesteps[i - 1]:
                continuous_trace += 1
            else:
                if continuous_trace != 1:
                    print(continuous_trace)
                continuous_trace = 1


data = load_data("large_all_features-1", "Controlled_Visual_Stimuli",
                 "Curved_prey")
stimulus_data = load_stimulus_data("large_all_features-1",
                                   "Controlled_Visual_Stimuli")

normalised_traces = normalise_all_traces(data)
normalised_traces = remove_arbitrary_traces(normalised_traces)

example_n = normalised_traces[332]
a, b = get_deviation_periods(example_n)
deviation_durations(a)
print("---")
deviation_durations(b)

# normalised_traces = normalised_traces[:50]
# plot_multiple_traces(normalised_traces)

#
# unit_activity = [[data["rnn state"][i-1][0][j] for i in data["step"]] for j in range(50)]