Skip to content

optim_tools⚓︎

Collection of tools that can be used in optimization schemes. Only put tools here that are so general that they can be used by several optimization schemes. If some method is only applicable to the update scheme you are implementing, leave it in that class.

clip_state(x, bounds) ⚓︎

Clip a state vector according to the bounds

Parameters:

Name Type Description Default
x array_like

The input state

required
bounds array_like

(min, max) pairs for each element in x. None is used to specify no bound.

required

Returns:

Name Type Description
x ndarray

The state after truncation

cov2corr(cov) ⚓︎

Transfroms a covaraince matrix to a correlation matrix

Parameters:

Name Type Description Default
cov array_like

The covaraince matrix, of shape (d,d).

required

Returns:

Name Type Description
out ndarray

The correlation matrix, of shape (d,d)

get_list_element(list, element) ⚓︎

Retrieve the value associated with a given element in a list of tuples.

Parameters:

Name Type Description Default
list list

A list of tuples, where each tuple contains two elements.

required
element any

The element to search for in the first position of the tuples.

required

Returns:

Type Description
any

The value associated with the given element in the list of tuples, or None if the element is not found.

get_sym_pos_semidef(a) ⚓︎

Force matrix to positive semidefinite

Parameters:

Name Type Description Default
a array_like

The input matrix, of shape (d,d)

required

Returns:

Name Type Description
a ndarray

The positive semidefinite matrix, of shape (d,d)

save_optimize_results(intermediate_result, folder=None) ⚓︎

Save optimize results

Parameters:

Name Type Description Default
intermediate_result OptimizeResult

An instance of an OptimizeResult class

required

toggle_ml_state(state, ml_ne) ⚓︎

Toggle the state from a dictionary to a list of levels, or from a list of levels to a dictionary. This is necessary when we are using multi-level ensembles.

Parameters:

Name Type Description Default
state dict or list

The current state, either as a dictionary or a list of levels.

required
ml_ne list

List of ensemble sizes for each level.

required

Returns:

Name Type Description
new_state dict or list

The toggled state, either as a list of levels or a dictionary.