<commit_before>import numpy as np
import matplotlib.pyplot as plt


def calculate_cum_reward(policy, last_history_id):
    cum_reward = {0: 0.0}
    for i in range(1, last_history_id + 1):
        cum_reward[i] = cum_reward[i - 1] + policy.historystorage.get_history(i).reward
    return cum_reward


def calculate_avg_reward(policy, last_history_id):
    cum_reward = calculate_cum_reward(policy, last_history_id)
    avg_reward = {}
    for i in range(1, last_history_id + 1):
        avg_reward[i] = cum_reward[i] / i
    return avg_reward


def plot_avg_reward(policy, last_history_id):
    avg_reward = calculate_avg_reward(policy, last_history_id)
    plt.plot(avg_reward.keys, avg_reward.values(), 'r-', label="average reward")
    plt.xlabel('time')
    plt.ylabel('avg reward')
    plt.legend()
    plt.title("Average Reward with respect to Time")
    plt.show()<commit_msg>finish rewardplot<commit_after>import numpy as np
import matplotlib.pyplot as plt


def calculate_cum_reward(policy, last_history_id):
    cum_reward = {-1: 0.0}
    time = {-1: 0.0}
    for i in range(0, last_history_id + 1):
        reward = policy.historystorage.get_history(i).reward
        time[i] = time[i - 1] + len(reward.values())
        cum_reward[i] = cum_reward[i - 1] + sum(reward.values())
    return cum_reward, time


def calculate_avg_reward(policy, last_history_id):
    cum_reward, time = calculate_cum_reward(policy, last_history_id)
    avg_reward = {}
    for i in range(0, last_history_id + 1):
        avg_reward[i] = cum_reward[i] / time[i]
    return avg_reward


def plot_avg_reward(policy, last_history_id):
    avg_reward = calculate_avg_reward(policy, last_history_id)
    plt.plot(avg_reward.keys(), avg_reward.values(), 'r-', label="average reward")
    plt.xlabel('time')
    plt.ylabel('avg reward')
    plt.legend()
    plt.title("Average Reward with respect to Time")
    plt.show()
{'fraction_non_alphanumeric': 0.11823436678928008, 'fraction_numerical': 0.010509721492380452, 'mean_word_length': 3.9326424870466323, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2322377', 'n_tokens_mistral': 723, 'n_tokens_neox': 691, 'n_words': 143}