def isBetween_c_Vec( a, # Previous position. b, # Current position. c, # Positions of all targets. r, # Target radius.): # True at the indices of found targets.
Checks whether point c is crossing the line formed with point a and b.
Parameters
a : tensor, shape = (1,2) Previous position. b : tensor, shape = (1,2) Current position. c : tensor, shape = (Nt,2) Positions of all targets. r : int/float Target radius.
Returns
mask : array of boolean values True at the indices of found targets.
def coord_mod( coord1, # First coordinate. coord2, # Second coordinate, substracted from coord1. mod, # World size.): # Distance difference (with correct sign, not absolute value).
Computes the distance difference between two coordinates, in a world with size ‘mod’ and periodic boundary conditions.
Parameters
coord1 : value, np.array, tensor (can be shape=(n,1)) First coordinate. coord2 : np.array, tensor – shape=(1,1) Second coordinate, substracted from coord1. mod : int World size.
def isBetween_c_Vec_nAgents( a, # Previous position of all n agents. b, # Current position of all n agents. c, # Positions of all targets. r, # Target radius): # True at the indices of found targets.
Checks whether point c is crossing the line formed with point a and b. Code to run several agents in parallel.
Parameters
a : array, shape = (n,2) Previous position of all n agents. b : array, shape = (n,2) Current position of all n agents. c : array, shape = (Nt,2) Positions of all targets. r : float Target radius
Returns
mask : array of boolean values, shape = (Nt, n) True at the indices of found targets.
def get_encounters( agent_previous_pos, # Position of the n agents before taking the step. agent_pos, # Position of the n agents. target_positions, # Positions of the targets. L, # World size. r, # Radius of the targets.): # True at the indices of found targets.
Considering the agent walks, it checks whether the agent finds a target while walking the current step. Code to run several agents in parallel.
Parameters
agent_previous_pos : array, shape = (n,2) Position of the n agents before taking the step. agent_pos : array, shape = (n,2) Position of the n agents. target_positions : array, shape = (Nt,2) Positions of the targets. L : int World size. r : float Radius of the targets.
Returns
mask_encounters : array of boolean values, shape = (Nt, n) True at the indices of found targets.
def isBetween_c_Vec_numba( a, # Previous position. b, # Current position. c, # Positions of all targets. r, # Target radius.): # True at the indices of found targets.
Checks whether point c is crossing the line formed with point a and b.
Parameters
a : tensor, shape = (1,2) Previous position. b : tensor, shape = (1,2) Current position. c : tensor, shape = (Nt,2) Positions of all targets. r : int/float Target radius.
Returns
mask : array of boolean values True at the indices of found targets.
:param arr: A 1D numpy array of values to sample from. :param prob: A 1D numpy array of probabilities for the given samples. :return: A random sample from the given array with a given probability.
def rand_choice_vectorized( probs, # A 2D numpy array of shape (num_agents, num_actions) where each row contains# the probability distribution for an agent.): # A 1D numpy array of sampled actions for each agent.
Vectorized random choice for multiple agents.
Parameters
probs : np.array A 2D numpy array of shape (num_agents, num_actions) where each row contains the probability distribution for an agent.
Returns
actions : np.array A 1D numpy array of sampled actions for each agent.
def get_config( config, # Config name (e.g. exp_0) config_path:str='configurations/learning/', # path to configurations): # Dictionary with the parameters of the loaded configuration.
Get the configuration file of the given experiment and config name (e.g. exp_0).
Parameters
config : str Config name (e.g. exp_0) experiment : str Experiment name (e.g. ‘learning’) config_path : str path to configurations
Returns
config_dict : dict Dictionary with the parameters of the loaded configuration.
def get_performance( results_path, # Path of the folder from which to extract the data. agent_list, # List with the agent indices. episode_list, # List with the episodes.): # Average performances obtained by the agents in the postlearning analysis.
Extract data with the efficiencies obtained in the postlearning analysis.
Parameters
results_path : str Path of the folder from which to extract the data. agent_list : list List with the agent indices. episode_list : list List with the episodes.
Returns
post_training_performance : np.array, shape=(len(agent_list), len(episode_list)) Average performances obtained by the agents in the postlearning analysis. sem : np.array, shape=(len(agent_list), len(episode_list)) Standard deviation of the mean.
def get_opt( path, # Path from which to get the data. df, # Dataframe with the results from the optimization with Tune.): # Efficiency of each walk.
Get the highest efficiency obtained by the benchmark models and the corresponding parameters.
Parameters
path : str Path from which to get the data. df : panda dataframe Dataframe with the results from the optimization with Tune.
Returns
list Efficiency of each walk. list Parameters of the benchmark model that achieved the highest efficiency. Levy - list of the form [beta] Bi-exp. - list of the form [d_int, d_ext, p]