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_memory
src.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¶
Class to organize the found stationary curves and executed crossovers. |
Functions¶
|
Updates the crossover memory by including a new stationary curve. |
|
Initializes the global variables at the beggining of each insertion step. |
|
Propose a curve to be descended. |
|
Method that proposes a random curve to be descended. |
|
Rejection sampling over a density defined by the dual variable. |
|
Generate two crossover curves by switching at given time sample |
|
Obtain all the crossovers between two curves. |
|
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 entryicontains a list of sizeM-i-1. Fori<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
globalvariable crossover_memory, which is an instance ofsrc.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_measure
src.classes.measure The current iterate of the DGCG algorithm.
- current_measure
- 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:
The already known curves from the current solution.
Random curves placed by selecting random times and random locations.
3. Crossover curves, these are obtained by merging two good descended. candidates.
- Parameters
- w_t
src.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 alsosrc.classes.curve.energy().
- w_t
- Returns
src.classes.curveA curve to be descended by the multistart descent method.
Notes
This method will first propose all the
known_curvesfrom thecurrent_measure. Then it will switch between proposingMconsecutive crossover curves if possible and then a random curve. The parameterMis modulated byconfig.crossover_consecutive_inserts. For the random insertion, seesrc.insertion_mod.random_insertion(), For crossovers, seesrc.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_t
src.classes.dual_variable The dual variable associated to the current iterate of the algorithm.
- w_t
- Returns
src.classes.curveA 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_t
src.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, curve2
src.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.
- curve1, curve2
- Returns
- new_curve_1
src.classes.curve - new_curve_2
src.classes.curve
- new_curve_1
-
src.insertion_mod.crossover(curve1, curve2)¶ Obtain all the crossovers between two curves.
- Parameters
- curve1, curve2
src.classes.curve Curve to crossover.
- curve1, curve2
- Returns
- list[
src.classes.curve]
- list[
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_t
src.classes.dual_variable. Dual variable associated to the current iterate.
- stationary_curveslist[
- Returns
src.classes.curveor NoneIf a crossover is found, returns it. If not, returns None.