<commit_before>import numpy as np


def monetary_reward_per_timestep(agent_vars):
    """
    Calculate the sum of monetary reward per timestep in the simulation.
    The rewards are as follows
        - unsuccessful: 0
        - successful & fraudulent: -amount
        - successful & genuine: 0.25*amount + 0.25
    :param agent_vars: 
    :return: 
    """
    num_steps = 366*24
    rewards = np.zeros(num_steps)
    for step in range(num_steps):
        try:
            success = np.array(agent_vars.loc[step]['TransactionSuccessful'], dtype=float)
            fraud = np.array(agent_vars.loc[step]['Target'], dtype=float)
            amount = np.array(agent_vars.loc[step]['Amount'], dtype=float)

            # calculate reward
            reward = fraud * (-amount)
            reward += (1 - fraud) * (0.003 * amount + 0.01)
            reward *= success

            rewards[step] = np.sum(reward)
        except KeyError:
            pass
    return rewards


def satisfaction_reward_per_timestep(agent_vars):
    """
    Get the satisfaction reward (i.e., estimated satisfaction from view<commit_msg>functions for only positive/negative reward<commit_after>import numpy as np


def monetary_reward_per_timestep(agent_vars):
    """
    Calculate the sum of monetary reward per timestep in the simulation.
    The rewards are as follows
        - unsuccessful: 0
        - successful & fraudulent: -amount
        - successful & genuine: 0.25*amount + 0.25
    :param agent_vars: 
    :return: 
    """
    num_steps = 366*24
    rewards = np.zeros(num_steps)
    for step in range(num_steps):
        try:
            success = np.array(agent_vars.loc[step]['TransactionSuccessful'], dtype=float)
            fraud = np.array(agent_vars.loc[step]['Target'], dtype=float)
            amount = np.array(agent_vars.loc[step]['Amount'], dtype=float)

            # calculate reward
            reward = fraud * (-amount)
            reward += (1 - fraud) * (0.003 * amount + 0.01)
            reward *= success

            rewards[step] = np.sum(reward)
        except KeyError:
            pass
    return rewards


def money_lost_per_timestep(agent_vars):
    num_steps = 366*24
    rewards = np.zeros(num_steps)
    for step in range(num_steps):
        try:
            success = np.array(agent_vars.loc[step]['TransactionSuccessful'], dtype=float)
            fraud = np.array(agent_vars.loc[step]['Target'], dtype=float)
            amount = np.array(agent_vars.loc[step]['Amount'], dtype=float)

            # calculate reward
            reward = (1 - fraud) * (0.003 * amount + 0.01)
            reward *= success

            rewards[step] = np.sum(reward)
        except KeyError:
            pass
    return rewards


def money_made_per_timestep(agent_vars):
    num_steps = 366*24
    rewards = np.zeros(num_steps)
    for step in range(num_steps):
        try:
            success = np.array(agent_vars.loc[step]['TransactionSuccessful'], dtype=float)
            fraud = np.array(agent_vars.loc[step]['Target'], dtype=float)
            amount = np.array(agent_vars.loc[step]['Amount'], dtype=float)

            # calculate reward
            reward = fraud * (-amount)
            reward *= success

            rewards[step] = np.sum(reward)
        except KeyError:
            pass
    return rewards


def satisfaction_reward_per_timestep(agent_vars):
    """
    Get the satisfaction reward (i.e., estimated satisfaction from view
{'fraction_non_alphanumeric': 0.10774119006354708, 'fraction_numerical': 0.016753321779318313, 'mean_word_length': 2.3107074569789674, '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': '4189497', 'n_tokens_mistral': 1044, 'n_tokens_neox': 998, 'n_words': 240}