utils.my_plots.
animate_simulation
(out_dirs, myt_quantity)¶out_dirs – directory containing the simulation runs
myt_quantity – number of agents
utils.my_plots.
get_position_distances
(runs_sub, with_run=False)¶runs_sub – directory containing the simulation runs
with_run – boolean, default False
array containing distances from goal
utils.my_plots.
make_space_above
(axes, topmargin=1)¶Increase figure size to make topmargin (in inches) space for titles, without changing the axes sizes.
axes – axes of the image
topmargin – topmargin
utils.my_plots.
my_histogram
(prediction, x_label, img_dir, title, filename, label=None)¶prediction – predictions
x_label – label for the x-axis
img_dir – directory containing the simulation images
title – title of the image
filename – name of the image
label – label for the plot, default None
utils.my_plots.
my_scatterplot
(x, y, x_label, y_label, img_dir, title, filename)¶Plot a scatter plot. Usually with the groundtruth on x-axis and prediction on y-axis.
x – values for the x-axis
y – values for the y-axis
x_label – label for the x-axis
y_label – label for the y-axis
img_dir – directory containing the simulation images
title – title of the image
filename – name of the image
utils.my_plots.
plot_compared_distance_compressed
(dataset_folders, img_dir, datasets, title, filename, absolute=True)¶Warning
Limits on x and y axes have not yet been fixed.
Their value depends if it is used goal_position_distance
or
goal_position_distance_absolute
.
dataset_folders – directory containing the simulation runs
img_dir – directory containing the simulation images
datasets – names of the datasets to be uses
title – title of the image
filename – name of the image
absolute – boolean value that states is use absolute distances from goal (default: True)
utils.my_plots.
plot_compared_distance_from_goal
(dataset_folders, img_dir, title, filename, absolute=True)¶dataset_folders – directory containing the simulation runs
img_dir – directory containing the simulation images
title – title of the image
filename – name of the image
absolute – boolean value that states is use absolute distances from goal (default: True)
utils.my_plots.
plot_distance_from_goal
(runs_dir, img_dir, title, filename)¶runs_dir – directory containing the simulation runs
img_dir – directory containing the simulation images
title – title of the image
filename – name of the image
utils.my_plots.
plot_losses
(train_loss, valid_loss, img_dir, title, filename, goal)¶train_loss – the training losses
valid_loss – the testing losses
img_dir – directory for the output image
title – title of the image
filename – name of the image
utils.my_plots.
plot_regressor
(x, y, x_label, y_label, img_dir, title, filename)¶x – values for the x-axis
y – values for the y-axis
x_label – label for the x-axis
y_label – label for the y-axis
img_dir – directory containing the simulation images
title – title of the image
filename – name of the image
utils.my_plots.
plot_response
(x, y, x_label, img_dir, title, filename, index=None, y_label='control')¶x – values for the x-axis
y – values for the y-axis
x_label – label for the x-axis
img_dir – directory containing the simulation images
title – title of the image
filename – name of the image
index – this parameter is different from None only when x is the input sensing, otherwise, x is a 1D vector
y_label – label for the y-axis (optional, default: ‘control’)
utils.my_plots.
plot_sensing_timestep
(runs_dir, img_dir, net_input, model)¶runs_dir – directory containing the simulation runs
img_dir – directory containing the simulation images
net_input – input of the net between prox_values, prox_comm or all_sensors
model – model to be used
utils.my_plots.
plot_simulations
(out_dirs, myt_quantity)¶out_dirs – directory containing the simulation runs
myt_quantity – number of agents
utils.my_plots.
plot_target_distribution
(y_g, y_p, img_dir, title, filename)¶y_g – validation groundtruth
y_p – validation prediction
img_dir – directory containing the simulation images
title – title of the image
filename – name of the image
utils.my_plots.
save_visualisation
(filename, img_dir, make_space=False, axes=None)¶filename – name of the image
img_dir – path where to save the image
make_space – if make space above the image
axes – axes of the image
utils.my_plots.
test_controller_given_init_positions
(model_img, model, net_input)¶model_img – directory for the output image of the model
model – name of the model
net_input – input of the network (between: prox_values, prox_comm and all_sensors)
utils.my_plots.
thymio_quantity_distribution
(runs_dir, img_dir, title, filename)¶runs_dir – directory containing the simulation runs
img_dir – directory containing the simulation images
title – title of the image
filename – name of the image
utils.my_plots.
visualise_communication_simulation
(runs_dir, img_dir, simulation, title)¶runs_dir – directory containing the simulation runs
img_dir – directory containing the simulation images
simulation – simulation to use
title – title of the image
utils.my_plots.
visualise_communication_vs_control
(runs_dir, img_dir, title)¶runs_dir – directory containing the simulation runs
img_dir – directory containing the simulation images
title – title of the image
utils.my_plots.
visualise_communication_vs_distance
(runs_dir, img_dir, title)¶runs_dir – directory containing the simulation runs
img_dir – directory containing the simulation images
title – title of the image
utils.my_plots.
visualise_simulation
(runs_dir, img_dir, simulation, title, net_input)¶runs_dir – directory containing the simulation runs
img_dir – directory containing the simulation images
simulation – simulation to use
title – title of the image
net_input – input of the net between prox_values, prox_comm or all_sensors
utils.my_plots.
visualise_simulation_all_sensors
(runs_dir, img_dir, simulation, title, net_input)¶runs_dir – directory containing the simulation runs
img_dir – directory containing the simulation images
simulation – simultion to use
title – title of the image
net_input – input of the net between prox_values, prox_comm or all_sensors
utils.my_plots.
visualise_simulation_over_time_all_sensors
(runs_dir, img_dir, simulation, title)¶runs_dir – directory containing the simulation runs
img_dir – directory containing the simulation images
simulation – simulation to use
title – title of the image
utils.my_plots.
visualise_simulations_comparison
(runs_dir, img_dir, title, net_input)¶runs_dir – directory containing the simulation runs
img_dir – directory containing the simulation images
title – title of the image
net_input – input of the net between prox_values, prox_comm or all_sensors
utils.my_plots.
visualise_simulations_comparison_all_sensors
(runs_dir, img_dir, title, net_input)¶runs_dir – directory containing the simulation runs
img_dir – directory containing the simulation images
title – title of the image
net_input – input of the net between prox_values, prox_comm or all_sensors
utils.utils.
ThymioState
(state_dict)¶Object containing all the agent information :param state_dict
utils.utils.
cartesian_product
(*arrays)¶arrays – arrays used to compute the cartesian product
cartesian product
utils.utils.
check_dir
(directory)¶Check if the path is a directory, if not create it.
directory – path to the directory
utils.utils.
dataset_split
(file_name, num_run=1000)¶file_name – path to the file where to save the splits of the dataset
num_run – number of simulations, by default 1000
utils.utils.
directory_for_dataset
(dataset, controller)¶dataset – name of the dataset
controller – name of the controller
output directories for the simulations
utils.utils.
directory_for_model
(args)¶args – command line arguments
output directories for the models
utils.utils.
export_network
(model_dir, model, in_put, input_shape)¶model_dir – directory containing the model
model – name of the model
in_put – array of the same shape of the first network input
input_shape – array of the same shape of the second network input
utils.utils.
extract_colour_output
(runs, communication=False, input_combination=True)¶The output is the colour of the top led that depends by the position of the robot in the row.
runs – dataframe containing all the simulation runs
communication – states if the communication is used by the network
input_combination – states if using the input combination of the sensors, that means using only the central frontal sensor and the mean of the rear sensors
output array for the network and dataframe with the runs
utils.utils.
extract_input_output
(runs, in_label, N, communication=False, input_combination=True, myt_quantities=None, task='distribute')¶Whether the input is prox_values, prox_comm or all sensors, it corresponds to the response values of the sensors [array of 7 floats]. The input is normalised so that the average is around 1 or a constant (e.g. for all (dividing by 1000)). The output is the speed of the wheels (which we assume equals left and right) [array of 1 float]. There is no need to normalize the outputs.
runs – dataframe containing all the simulation runs
in_label – input of the net between prox_values, prox_comm or all_sensors
N – number of agents
communication – states if the communication is used by the network
input_combination – states if using the input combination of the sensors, that means using only the central frontal sensor and the mean of the rear sensors
myt_quantities – array containing the number agents for each simulation run
task – task to perform (can be distribute or colour)
input and output arrays for the network, array with the number of agents, dataframe with the runs and columns of the dataframe referred to the input label
utils.utils.
from_dataset_to_tensors
(train_sample, train_target, valid_sample, valid_target, test_sample, test_target, q_train, q_valid, q_test)¶train_sample – training set samples
train_target – training set targets
valid_sample – validation set samples
valid_target – validation set targets
test_sample – testing set samples
test_target – testing set targets
q_train – mask containing the number of agents for each sample of the training set
q_valid – mask containing the number of agents for each sample of the validation set
q_test – mask containing the number of agents for each sample of the testing set
test, train and valid TensorDataset
utils.utils.
from_indices_to_dataset
(runs_dir, train_indices, validation_indices, test_indices, net_input, communication=False, task='distribute')¶runs_dir – directory containing the simulations
train_indices – indices of the sample belonging to the training set
validation_indices – indices of the sample belonging to the validation set
test_indices – indices of the sample belonging to the testing set
net_input – input of the net between prox_values, prox_comm or all_sensors
communication – states if the communication is used by the network
task – task to perform (can be distribute or colour)
(train_sample, valid_sample, test_sample), train_target, valid_target, test_target, train_quantities, valid_quantities, test_quantities: all the train, validation and test samples, targets and masks
utils.utils.
generate_fake_simulations
(run_dir, model, initial_positions, myt_quantity)¶run_dir – directory containing the simulation runs
model – name of the model
initial_positions – initial position for the agents
myt_quantity – number of agents
directory containing the simulation run
utils.utils.
get_all_sensors
(prox_values, prox_comm)¶prox_values – prox_values reading
prox_comm – prox_comm reading
combination of the two sensor readings
utils.utils.
get_input_columns
(in_label)¶in_label – input of the net between prox_values, prox_comm or all_sensors
columns of the dataframe referred to the input label
utils.utils.
get_input_sensing
(in_label, myt, normalise=True)¶in_label – input of the net between prox_values, prox_comm or all_sensors
myt – agent
normalise – states if normalise the input sensing (default: True)
sensing perceived by the agent
utils.utils.
get_key_value_of_nested_dict
(nested_dict)¶Access a nested dictionary and return a list of tuples (rv) and values. Used to return the list of intensities given a prox_comm dictionary containing multiple senders.
nested_dict – nested dictionary, usually containing prox_comm_events
rv is a list of tuples where, in each of these, the first element is a list of keys and the second is the final value. Values is the list of inner values.
utils.utils.
get_prox_comm
(myt)¶Create a dictionary containing all the senders as key and the corresponding intensities as value.
myt – agent
prox_comm sensing
utils.utils.
get_received_communication
(myt, goal='distribute')¶Create a list containing the messages received from the back and front.
myt – agent
goal – goal of the task, by default distribute
the communication received from left to right
utils.utils.
get_transmitted_communication
(myt)¶Return the values transmitted during the communication.
myt – agent
the communication to be transmitted
utils.utils.
load_dataset
(runs_dir, dataset)¶runs_dir – directory containing the simulation runs
dataset – name of the dataset
resulting dataframe
utils.utils.
parse_prox_comm
(prox_comm)¶prox_comm – prox_comm dictionary
parsed prox_comm list
utils.utils.
prepare_dataset
(run_dir, split, num_run)¶run_dir – directory containing the simulation runs
split – states if generate or load the split file
num_run – number of runs used in the simulation
file containing the splits and the splits indices
utils.utils.
signed_distance
(state)¶state – object containing all the agent information
signed distance between current and the goal position, along the current theta of the robot