Utils
Training utilities
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.
best_so_far
best_so_far (m)
Returns best value up to each point along the second axis of a matrix for each row.
arrange_shape
arrange_shape (obj, mode='expand')
Makes all lists within a list have the same length. Can be mode ‘cut’ or ‘expand’
plot_trainings
plot_trainings (training_results, eval_optims=True, expl_optims=False, figsize=(10, 5), fontsize=18, ticksize=14)
Plots the training results.
get_indiv_times
get_indiv_times (tl_eval, convergence_crit=None)
Provides convergence times from individual ratios.
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.
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
CPU_Unpickler
CPU_Unpickler (file, fix_imports=True, encoding='ASCII', errors='strict', buffers=())
Unpickles from GPU to CPU
checkpoint2results
checkpoint2results (N, model, budget=None, IDs=None, episode=None)
Loads checkpoints from IDs and converts them to result format.
load_checkpoint
load_checkpoint (problem, budget, ID, episode)
load_benchmark
load_benchmark (problem, budget, method, suffix=None)
Loads benchmark data.
save_benchmark
save_benchmark (benchmark, problem, budget, method, suffix=None)
Saves benchmark data.
load_model
load_model (problem, budget, ID)
Loads agent model and parameters.
save_model
save_model (agent, problem, budget, ID)
Saves agent model and parameters.
get_checkpoint_file_name
get_checkpoint_file_name (problem, budget, ID, episode)
Returns a consistent file naming for checkpoints.
get_benchmark_file_name
get_benchmark_file_name (problem, budget, method)
Returns a consistent file naming for benchmarks.
get_memory_file_name
get_memory_file_name (problem, solver)
Returns a consistent file naming for memories.
get_agent_file_name
get_agent_file_name (problem, budget, ID)
Returns a consistent file naming for agents.
get_problem_file_name
get_problem_file_name (problem)
Returns a consistent file naming from a problem instance.
State transformations
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.
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).
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.
flip
flip (state, i)
Flips constraint i
from state.
T
T (state)
Takes state and converts it to torch.FloatTensor
state2str
state2str (state)
Takes state vector and outputs a (spaceless) string.
state2int
state2int (state)
Takes state vector as binary encoding of an integer.
fill_layout
fill_layout (L, N)
Fills layout with single-body terms that are missing.
simplify_layout
simplify_layout (L)
Simplifies the given layout of the form [np.array([0, 1]), np.array([0, 1, 2])]
.
Array operations
arrayfy
arrayfy (inp, size)
Transforms input into an array of the desired size.
array_in_list
array_in_list (array, array_list)
Checks whether an array is in a list of arrays.
Mathematical operations
binomial
binomial (n, k)
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
dist_exp
dist_exp (xmin, x)
Computes an eponential distance given a minimum value (in terms of absolute value).