Exemple #1
0
def neuron_action_scores(event_triggered_averages):
    for n in range(len(event_triggered_averages["0"])):
        neuron_responses = [
            event_triggered_averages[str(i)][n] for i in range(10)
        ]
        plt.bar([get_action_name(i) for i in range(10)], neuron_responses)
        plt.show()
Exemple #2
0
def colored_2d_track_turns(position, action_choice, orientation_changes):
    # Note that due to the inverse scale in the environment, should be rotated in y axis.
    data = {}
    # sns.set()
    turn_stamps = [i for i, a in enumerate(action_choice) if a == 1 or a == 2]
    data["x"] = [p[0] for i, p in enumerate(position) if i in turn_stamps]
    data["y"] = [p[1] for i, p in enumerate(position) if i in turn_stamps]
    data["Bout"] = [
        get_action_name(a) for i, a in enumerate(action_choice)
        if i in turn_stamps
    ]
    data["s"] = [10 for i in range(len(action_choice))]
    data["Delta-Angle"] = [
        o for i, o in enumerate(orientation_changes) if i in turn_stamps
    ]
    colors = ['b', 'g', 'g', 'r', 'y', 'y', "k", "m", "m"]

    # colors = sns.color_palette("hls", len(set(action_choice)))
    # colors = sns.color_palette("hls", 2)
    colors = ["green", "lightgreen"]
    plt.figure(figsize=(10, 10))
    ax = sns.scatterplot(x="x",
                         y="y",
                         hue="Bout",
                         data=data,
                         palette=colors,
                         s=100,
                         alpha=1)
    plt.setp(ax.get_legend().get_title(), fontsize='25')
    plt.setp(ax.get_legend().get_texts(), fontsize='20')
    plt.xlim(0, 1500)
    plt.ylim(0, 1500)
    plt.show()
def create_boxplots(index, models, timestamp):
    # TODO: Note is not accurate at present - dont select on index, select on y-value proximity. Fix this.
    data = {"action": [], "model": [], "frequency": []}
    action_lists = []
    sns.set()
    for action in range(10):
        # points = []
        for model in models:
            data["action"].append(action)
            data["model"].append(model)
            x, y = get_action_choice(model, action)
            data["frequency"].append(y[index])

        # action_lists.append(points)
    # data["values"] = action_lists
    data = pd.DataFrame(data)
    fig = plt.figure()
    ax = sns.boxplot(y="frequency", x="action", data=data,
                     fliersize=0)  # whis=np.inf
    ax = sns.stripplot(y="frequency", x="action", data=data, color=".3")
    ax.tick_params(labelsize=10)
    plt.xticks(rotation=90, fontsize=12)
    ax.set_xticklabels([get_action_name(i) for i in range(10)])
    plt.title(f"Frequency of Actions at Step {str(timestamp)}")
    plt.xlabel("Action", fontsize=20)
    plt.ylabel("Action frequency", fontsize=20)
    fig.set_size_inches(10, 7)
    plt.tight_layout()
    plt.show()
def create_paired_boxplots(indexes, models, timestamps):
    data = {"action": [], "model": [], "frequency": [], "Step": []}
    action_lists = []
    sns.set()
    for i, index in enumerate(indexes):
        for action in range(10):
            # points = []
            for model in models:
                data["action"].append(action)
                data["model"].append(model)
                x, y = get_action_choice(model, action)
                data["frequency"].append(y[index])

                data["Step"].append(timestamps[i])
    data = pd.DataFrame(data)
    fig = plt.figure()
    ax = sns.boxplot(y="frequency",
                     x="action",
                     hue="Step",
                     data=data,
                     fliersize=0)  # whis=np.inf
    ax = sns.stripplot(y="frequency", x="action", data=data, color=".3")
    ax.tick_params(labelsize=10)
    plt.xticks(rotation=90, fontsize=12)
    ax.set_xticklabels([get_action_name(i) for i in range(10)])
    plt.xlabel("Action", fontsize=20)
    plt.ylabel("Action frequency", fontsize=20)
    fig.set_size_inches(10, 7)
    plt.tight_layout()
    plt.show()
Exemple #5
0
def plot_average_action_scores(event_triggered_averages):
    mean_scores = []
    for a in range(10):
        m = np.mean(event_triggered_averages[str(a)])
        mean_scores.append(m)
    plt.figure(figsize=(15, 5))
    plt.bar([get_action_name(i) for i in range(10)], mean_scores)
    plt.xlabel("Action-Triggered Average")
    plt.ylabel("Action")
    plt.show()
Exemple #6
0
def colored_2d_track(position, action_choice, capture_positions=None):
    # Note that due to the inverse scale in the environment, should be rotated in y axis.
    data = {}
    if capture_positions:
        data["x"] = [i[0]
                     for i in position] + [i[0] for i in capture_positions]
        data["y"] = [i[1]
                     for i in position] + [i[1] for i in capture_positions]
        data["Bout"] = [get_action_name(a) for a in action_choice
                        ] + ["Consumption" for i in capture_positions]
        colors = sns.color_palette("hls", len(set(action_choice)) + 1)
    else:
        data["x"] = [i[0] for i in position]
        data["y"] = [i[1] for i in position]
        data["Bout"] = [get_action_name(a) for a in action_choice]
        colors = sns.color_palette("hls", len(set(action_choice)))
    data["s"] = [10 for i in range(len(action_choice))]

    actions = []
    for action in data["Bout"]:
        if action not in actions:
            actions.append(action)
    colors = create_color_map(actions)

    plt.figure(figsize=(10, 10))
    ax = sns.scatterplot(x="x",
                         y="y",
                         hue="Bout",
                         data=data,
                         palette=colors,
                         s=100,
                         alpha=1)
    plt.setp(ax.get_legend().get_title(), fontsize='25')
    plt.setp(ax.get_legend().get_texts(), fontsize='20')
    plt.xlim(0, 1500)
    plt.ylim(0, 1500)
    plt.show()
def plot_action_use(model,
                    ablation_config,
                    number_of_trials,
                    ablation_groups=range(0, 105, 10)):
    sns.set()
    action_use = [[] for i in range(10)]
    for per in ablation_groups:
        if per == 35: per = 40
        actions = get_action_freq(model, ablation_config, per,
                                  number_of_trials)
        for i, a in enumerate(actions):
            action_use[i].append(a)

    fig, ax = plt.subplots(figsize=(7, 7))
    for a, action in enumerate(action_use):
        ax.plot(ablation_groups, action, label=get_action_name(a))

    ax.legend()

    plt.xlabel("Percentage ablated", fontsize=15)
    plt.ylabel("Bout Counts", fontsize=15)
    plt.show()
def plot_action_use_multiple_models_predator_sequences(models,
                                                       ablation_config,
                                                       number_of_trials,
                                                       ablation_groups=range(
                                                           0, 105, 10)):
    sns.set()
    action_use = [[[] for m in models] for i in range(10)]
    for per in ablation_groups:
        if per == 35: per = 40
        for m, model in enumerate(models):
            actions = get_action_freq_predator_sequences(
                model, ablation_config, per, number_of_trials)
            for i, a in enumerate(actions):
                action_use[i][m].append(a)

    high_v = [[] for i in range(10)]
    low_v = [[] for i in range(10)]

    action_use = np.array(action_use)
    average_action_use = [[] for i in range(10)]
    for a, action in enumerate(average_action_use):
        for p, per in enumerate(ablation_groups):
            high_v[a].append(max(action_use[a, :, p]))
            low_v[a].append(min(action_use[a, :, p]))
            average_action_use[a].append(np.mean(action_use[a, :, p]))

    fig, ax = plt.subplots(figsize=(7, 7))
    for a, action in enumerate(average_action_use):
        ax.plot(ablation_groups, action, label=get_action_name(a))
        low_v_x = low_v[a]
        high_v_x = high_v[a]
        ax.fill_between(ablation_groups, low_v_x, high_v_x, alpha=0.2)

    ax.legend()

    plt.xlabel("Percentage of neurons ablated", fontsize=15)
    plt.ylabel("Bout Counts", fontsize=15)
    plt.show()
Exemple #9
0
def plot_average_action_scores_comparison(atas, labels, stds=None):
    atas2 = []
    used_actions = []
    for ata in atas:
        mean_scores = []
        for a in range(10):
            m = np.mean(ata[str(a)])
            if m != 0:
                mean_scores.append(m * 0.35)
                used_actions.append(a)
        atas2.append(mean_scores)
    atas2 = normalise_vrvs(atas2)
    used_actions = list(set(used_actions))
    df = pd.DataFrame({label: data for data, label in zip(atas2, labels)})
    sns.set()
    df.plot.bar(
        rot=0, figsize=(10, 6), yerr=stds
    )  # , color={labels[0]: "blue", labels[1]: "blue", labels[2]: "red"}
    plt.ylabel("Normalised Action-Triggered Average", fontsize=20)
    plt.xlabel("Bout", fontsize=20)
    plt.xticks([a for a in range(len(used_actions))],
               [get_action_name(a) for a in used_actions],
               fontsize=15)
    plt.show()
Exemple #10
0
def display_all_atas(atas, groups=None):

    used_indexes = [int(key) for key in atas.keys() if sum(atas[key]) != 0]
    atas = [atas[key] for key in atas.keys() if sum(atas[key]) != 0]
    atas = [[atas[action][neuron] for action in range(len(atas))]
            for neuron in range(len(atas[0]))]
    for i, neuron in enumerate(atas):
        for j, action in enumerate(neuron):
            if action > 1000:
                atas[i][j] = 1000
            elif action < -1000:
                atas[i][j] = -1000

    atas = normalise_vrvs(atas)
    fig, ax = plt.subplots()
    fig.set_size_inches(1.85 * len(used_indexes), 20)
    ax.tick_params(labelsize=15)
    if groups:
        ordered_atas = []
        indexes = [
            j for sub in [groups[i] for i in groups.keys()] for j in sub
        ]
        for i in indexes:
            ordered_atas.append(atas[i])
        ax.pcolor(ordered_atas, cmap='coolwarm')

        transition_points = [
            len(groups[key]) for i, key in enumerate(groups.keys())
        ]
        cumulative_tps = []
        for i, t in enumerate(transition_points):
            if i == 0:
                continue
            cumulative_tps.append(sum(transition_points[:i]))
        transition_points = cumulative_tps

        # cluster_labels = [i for i in range(len(transition_points))]

        def format_func_cluster(value, tick):
            for i, tp in enumerate(transition_points):
                if value < tp:
                    return i
            return len(transition_points)

        for t in transition_points:
            ax.axhline(t, color="black", linewidth=1)
        ax.set_yticks(transition_points, minor=True)
        ax2 = ax.secondary_yaxis("right")
        ax2.tick_params(axis='y', labelsize=20)
        # ax2.yaxis.grid(True, which='minor', linewidth=20, linestyle='-', color="b")
        ax2.yaxis.set_major_locator(plt.FixedLocator(transition_points))
        ax2.yaxis.set_major_formatter(plt.FuncFormatter(format_func_cluster))
        ax2.set_ylabel("Cluster ID", fontsize=40)
        ax2.tick_params(axis='y', labelsize=20)
    else:
        # atas, t, cat = order_vectors_by_kmeans(atas)
        ax.pcolor(atas, cmap='coolwarm')
    # ax.grid(True, which='minor', axis='both', linestyle='-', color='k')
    plt.xticks(range(len(used_indexes)),
               [get_action_name(i) for i in used_indexes],
               fontsize=25)
    ax.set_ylabel("Neuron", fontsize=40)
    ax.set_xlabel("Bout Choice", fontsize=40)
    ax.tick_params(axis="x", labelrotation=45)
    fig.tight_layout()

    plt.show()