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.

aug_optim_state(state, list_state) ⚓︎

Augment the state variables to get one augmented array.

Parameters:

Name Type Description Default
state dict

Dictionary of state variables for optimization. OBS: 1D arrays!

required
list_state list

Fixed list of keys in the state dictionary.

required

Returns:

Name Type Description
aug_state ndarray

Augmented 1D array of state variables.

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

corr2BlockDiagonal(state, corr) ⚓︎

Makes the correlation matrix block diagonal. The blocks are the state varible types.

Parameters:

Name Type Description Default
state

Current control state, including state names

required
corr array_like

Correlation matrix, of shape (d, d)

required

Returns:

Name Type Description
corr_blocks list

block matrices, one for each variable type

corr2cov(corr, std) ⚓︎

Transfroms a correlation matrix to a covaraince matrix

Parameters:

Name Type Description Default
corr array_like

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

required
std array_like

Array of the standard deviations, of shape (d, ).

required

Returns:

Name Type Description
out ndarray

The covaraince matrix, of shape (d,d)

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_optimize_result(obj) ⚓︎

Collect optimize results based on requested

Parameters:

Name Type Description Default
obj Optimize

An instance of an optimization class

required

Returns:

Name Type Description
save_dict OptimizeResult

The requested optimization results

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) ⚓︎

Save optimize results

Parameters:

Name Type Description Default
intermediate_result OptimizeResult

An instance of an OptimizeResult class

required

time_correlation(a, state, n_timesteps, dt=1.0) ⚓︎

Constructs correlation matrix with time correlation using an autoregressive model.

\[ Corr(t_1, t_2) = a^{|t_1 - t_2|} \]

Assumes that each varaible in state is time-order such that x = [x1, x2,..., xi,..., xn], where i is the time index, and xi is d-dimensional.

Parameters:

Name Type Description Default
a float

Correlation coef, in range (0, 1).

required
state dict

Control state (represented in a dict).

required
n_timesteps int

Number of time-steps to correlate for each component.

required
dt float or int

Duration between each time-step. Default is 1.

1.0

Returns:

Name Type Description
out ndarray

Correlation matrix with time correlation

update_optim_state(aug_state, state, list_state) ⚓︎

Extract the separate state variables from an augmented state array.

It is assumed that the augmented state array is made in the aug_optim_state method, hence this is the reverse method.

Parameters:

Name Type Description Default
aug_state ndarray

Augmented state array. OBS: 1D array.

required
state dict

Dictionary of state variables for optimization.

required
list_state list

Fixed list of keys in the state dictionary.

required

Returns:

Name Type Description
state dict

State dictionary updated with aug_state.