src.insertion_mod

Module to handle the proposed inserted curves to be descended.

The module exhibits global variables that are used to remember the state of the insertion step.

Global variables

known_curveslist[src.classes.curve]

List of member curves from the current iterate of the DGCG algorithm that have not yet been descended.

crossover_memorysrc.insertion_mod.ordered_list_of_lists

Object that keeps track of the crossover information between the found stationary curves.

cycling_iteriterator

Cycling iterator that keeps track on the number of consecutive crossover curves that have been proposed.

Module Contents

Classes

ordered_list_of_lists

Class to organize the found stationary curves and executed crossovers.

Functions

update_crossover_memory(index)

Updates the crossover memory by including a new stationary curve.

initialize(current_measure)

Initializes the global variables at the beggining of each insertion step.

propose(w_t, stationary_curves, energy_curves)

Propose a curve to be descended.

random_insertion(w_t)

Method that proposes a random curve to be descended.

rejection_sampling(t, w_t)

Rejection sampling over a density defined by the dual variable.

switch_at(curve1, curve2, idx)

Generate two crossover curves by switching at given time sample

crossover(curve1, curve2)

Obtain all the crossovers between two curves.

find_crossover(stationary_curves, energy_curves, w_t)

Finds a crossover curve to propose from the list of stationary curves.

class src.insertion_mod.ordered_list_of_lists

Class to organize the found stationary curves and executed crossovers.

Initializes with no arguments into an empty list of lists.

Attributes
datalist[list[tuple[list[int], int]]]

A list of size M, the number of known stationary curves, which at the entry i contains a list of size M-i-1. For i<j, The entry [i][j-i-1] contains crossover information between the i-th and the j-th stationary curves. This information is a tuple with a list of integers representing the indexes of the proposed crossovers and an integer indicating the total number of crossovers.

add_empty_element_in_index(self, i)

Insert an empty list in the target location.

Parameters
iint

index to insert an empty list.

Notes

The main effort is to shift all the known relationships when inserting a list in between.

GET(self, i, j)

Get the crossover information between the stationary stationary curves.

Parameters
i,jint

Indices of stationary curves. i < j.

Returns
tuple[list[int], int]

The crossover information between the chosen curves.

POST(self, i, j, val)

Modify the crossover information between two stationary curves.

Parameters
i,jint

Indices of stationary curves. i < j.

valtuple[list[int], int]
Returns
None
src.insertion_mod.update_crossover_memory(index)

Updates the crossover memory by including a new stationary curve.

This method is meant to be called outside this module, to modify the global variable crossover_memory, which is an instance of src.insertion_mod.ordered_list_of_lists.

Parameters
indexint

Location to insert a new stationary curve on the known set.

Returns
None
src.insertion_mod.known_curves = []
src.insertion_mod.crossover_memory
src.insertion_mod.cycling_iter
src.insertion_mod.initialize(current_measure)

Initializes the global variables at the beggining of each insertion step.

Parameters
current_measuresrc.classes.measure

The current iterate of the DGCG algorithm.

Returns
None
src.insertion_mod.propose(w_t, stationary_curves, energy_curves)

Propose a curve to be descended.

There are three types of proposed curves to insert:
  1. The already known curves from the current solution.

  2. Random curves placed by selecting random times and random locations.

3. Crossover curves, these are obtained by merging two good descended. candidates.

Parameters
w_tsrc.classes.dual_variable

Dual variable associated to the current iterate

stationary_curveslist[src.classes.curve]

List of found stationary curves

energy_curvesnumpy.ndarray

1-dimensional list of ordered floats with the respective Benamou-Brenier energy of stationary_curves. See also src.classes.curve.energy().

Returns
src.classes.curve

A curve to be descended by the multistart descent method.

Notes

This method will first propose all the known_curves from the current_measure. Then it will switch between proposing M consecutive crossover curves if possible and then a random curve. The parameter M is modulated by config.crossover_consecutive_inserts. For the random insertion, see src.insertion_mod.random_insertion(), For crossovers, see src.insertion_mod.find_crossover()

src.insertion_mod.random_insertion(w_t)

Method that proposes a random curve to be descended.

It selects a random number of time samples (controled via config.insertion_max_segments) and then to select the spatial points of the proposed curve, it uses the rejection-sampling algorithm using as information the input dual variable w_t.

Parameters
w_tsrc.classes.dual_variable

The dual variable associated to the current iterate of the algorithm.

Returns
src.classes.curve

A random curve.

Notes

For further information, check the paper that defined this code.

src.insertion_mod.rejection_sampling(t, w_t)

Rejection sampling over a density defined by the dual variable.

Parameters
tint

Index of time sample. Takes values between 0,1,…,T. Where (T+1) is the total number of time samples of the inverse problem.

w_tsrc.classes.dual_variable

Dual variable associated with the current iterate.

Returns
numpy.ndarray

A random point in Ω = [0,1]^2.

src.insertion_mod.switch_at(curve1, curve2, idx)

Generate two crossover curves by switching at given time sample

Parameters
curve1, curve2src.classes.curve

Curve to crossover

idxint

Time sample index where the crossover happens. Takes values in 0,..,T where (T+1) is the total number of time samples.

Returns
new_curve_1src.classes.curve
new_curve_2src.classes.curve
src.insertion_mod.crossover(curve1, curve2)

Obtain all the crossovers between two curves.

Parameters
curve1, curve2src.classes.curve

Curve to crossover.

Returns
list[src.classes.curve]

Notes

To obtain a crossover, a minimum distance threshold is set by config.crossover_max_distance. Then for every time these curves get closer than this and then separate, two new crossover curves are obtained.

src.insertion_mod.find_crossover(stationary_curves, energy_curves, w_t)

Finds a crossover curve to propose from the list of stationary curves.

Parameters
stationary_curveslist[src.classes.curve]

List of found stationary curves.

energy_curvesnumpy.array

1-dimensional array of respective energies of the stationary curves.

w_tsrc.classes.dual_variable.

Dual variable associated to the current iterate.

Returns
src.classes.curve or None

If a crossover is found, returns it. If not, returns None.