Utils

Utility functions come in all kinds and shapes. We tried to group them in a sensible way.

Training utilities


source

plot_exploration

 plot_exploration (exploration_results, expl_optims=True,
                   highlight_max=False, figsize=(10, 5), fontsize=18,
                   ticksize=14)

Plots exploration results. It shows the best bound obtained for every new visited state. If expl_optims=True, it also shows the proximity to the optimal relaxation.


source

best_so_far

 best_so_far (m)

Returns best value up to each point along the second axis of a matrix for each row.


source

arrange_shape

 arrange_shape (obj, mode='expand')

Makes all lists within a list have the same length. Can be mode ‘cut’ or ‘expand’


source

plot_trainings

 plot_trainings (training_results, eval_optims=True, expl_optims=False,
                 figsize=(10, 5), fontsize=18, ticksize=14)

Plots the training results.


source

get_indiv_times

 get_indiv_times (tl_eval, convergence_crit=None)

Provides convergence times from individual ratios.


source

indiv_convergence_time

 indiv_convergence_time (results, max_epochs=800, tol=0.0005, T=50,
                         t_avg=20, return_diffs=False)

Similar to convergence_time but with each agent.


source

convergence_time

 convergence_time (results, tol=0.0005, T=50, t_avg=20,
                   return_diffs=False)

Returns the convergence with criterion of not changing result by tol for T epochs.

Load and save data


source

CPU_Unpickler

 CPU_Unpickler (file, fix_imports=True, encoding='ASCII', errors='strict',
                buffers=())

Unpickles from GPU to CPU


source

checkpoint2results

 checkpoint2results (N, model, budget=None, IDs=None, episode=None)

Loads checkpoints from IDs and converts them to result format.


source

load_checkpoint

 load_checkpoint (problem, budget, ID, episode)

source

load_benchmark

 load_benchmark (problem, budget, method, suffix=None)

Loads benchmark data.


source

save_benchmark

 save_benchmark (benchmark, problem, budget, method, suffix=None)

Saves benchmark data.


source

load_model

 load_model (problem, budget, ID)

Loads agent model and parameters.


source

save_model

 save_model (agent, problem, budget, ID)

Saves agent model and parameters.


source

get_checkpoint_file_name

 get_checkpoint_file_name (problem, budget, ID, episode)

Returns a consistent file naming for checkpoints.


source

get_benchmark_file_name

 get_benchmark_file_name (problem, budget, method)

Returns a consistent file naming for benchmarks.


source

get_memory_file_name

 get_memory_file_name (problem, solver)

Returns a consistent file naming for memories.


source

get_agent_file_name

 get_agent_file_name (problem, budget, ID)

Returns a consistent file naming for agents.


source

get_problem_file_name

 get_problem_file_name (problem)

Returns a consistent file naming from a problem instance.

State transformations


source

action_mask

 action_mask (state, basis)

Mask of the actions that can be performed. Better to use SdPEnvironment.action_mask if possible, it’s much faster.


source

contained_constraints

 contained_constraints (state, basis)

Returns a mask indicating which constraints in the state are contained by larger elements of the basis in the same state, excluding themselves. Better to use the SdPEnvironment.contained_constraints method when possible (it’s faster).


source

add_subgraph_size

 add_subgraph_size (subgraphs)

Takes a list of subgraphs up to any given size and adds a sublist with all the possible subgraphs of a larger size. It assumes the graph edges as minimal graph size.


source

flip

 flip (state, i)

Flips constraint i from state.


source

T

 T (state)

Takes state and converts it to torch.FloatTensor


source

state2str

 state2str (state)

Takes state vector and outputs a (spaceless) string.


source

state2int

 state2int (state)

Takes state vector as binary encoding of an integer.


source

fill_layout

 fill_layout (L, N)

Fills layout with single-body terms that are missing.


source

simplify_layout

 simplify_layout (L)

Simplifies the given layout of the form [np.array([0, 1]), np.array([0, 1, 2])].

Array operations


source

arrayfy

 arrayfy (inp, size)

Transforms input into an array of the desired size.


source

array_in_list

 array_in_list (array, array_list)

Checks whether an array is in a list of arrays.

Mathematical operations


source

binomial

 binomial (n, k)

source

dist_poly

 dist_poly (x, xmin, xmax, d)

Computes a linear decay bound from 1 to 0 given a minimum and maximum value (in terms of absolute value). Exponentiate the line to get better shapes


source

dist_exp

 dist_exp (xmin, x)

Computes an eponential distance given a minimum value (in terms of absolute value).