beetroots.inversion.run package

Submodules

beetroots.inversion.run.abstract_run module

class beetroots.inversion.run.abstract_run.Run[source]

Bases: ABC

abstract class for inversion approach supervision, including sampling, optimization (MAP and MLE)

abstract main()[source]

sequentially calls prepare_run and run

abstract prepare_run()[source]

prepares the inversion

abstract run()[source]

runs the inversion

beetroots.inversion.run.run_mcmc module

class beetroots.inversion.run.run_mcmc.RunMCMC(path_data_csv_out: str, max_workers: int)[source]

Bases: Run

class that runs inversions using a sampling approach

Parameters:
  • path_data_csv_out (str) – path to the folder where results are to be saved

  • max_workers (int) – max number of workers that can be used to run the inversion

main(dict_posteriors: dict[str, Posterior], sampler_: Sampler, saver_: Saver, scaler: Scaler, N_runs: int, max_iter: int, T_BI: int, path_raw: str, path_csv_mle: str | None, path_csv_map: str | None, start_from: str | None, regu_spatial_N0: int | float = inf, regu_spatial_scale: float | None = 1.0, regu_spatial_vmin: float | None = 1e-08, regu_spatial_vmax: float | None = 100000000.0, freq_save: int = 1, can_run_in_parallel: bool = True) None[source]

sequentially calls prepare_run and run

Parameters:
  • dict_posteriors (dict[str, Posterior]) – dictionary of posterior distributions

  • sampler (Sampler) – sampler to be used to generate the Markov chain(s)

  • saver (Saver) – object responsible for progressively saving the Markov chain data during the run

  • scaler (Scaler) – contains the transformation of the Theta values from their natural space to their scaled space (in which the sampling happens)

  • N_runs (int) – number of independent Markov chains to run per posterior distribution

  • max_iter (int) – total duration of a Markov chain

  • T_BI (int) – duration of the Burn-in phase

  • path_raw (str) – path to the folders where the .hdf5 files are to be stored

  • path_csv_mle (Optional[str]) – path to the csv file containing the already estimated MLE

  • path_csv_map (Optional[str]) – path to the csv file containing the already estimated MAP

  • start_from (Optional[str]) – point at which the inversion will start, must be in [None, “MAP”]. For None, a random value is drawn uniformly in the scaled hypercube.

  • regu_spatial_N0 (Union[int, float], optional) – number of iterations defining the initial update phase (for spatial regularization weight optimization). np.infty means that the optimization phase never starts, and that the weight optimization is not applied. By default np.infty

  • regu_spatial_scale (Optional[float], optional) – scale parameter involved in the definition of the projected gradient step size (for spatial regularization weight optimization). by default 1.0

  • regu_spatial_vmin (Optional[float], optional) – lower limit of the admissible interval (for spatial regularization weight optimization), by default 1e-8

  • regu_spatial_vmax (Optional[float], optional) – upper limit of the admissible interval (for spatial regularization weight optimization), by default 1e8

  • freq_save (int, optional) – frequency of saved iterates during the run (1 means that every iteration is saved), by default 1

  • can_run_in_parallel (bool, optional) – wether the inversion can be run in parallel (may cause difficulties for forward maps based on neural networks run on GPU), by default True

max_workers

max number of workers that can be used to run the inversion

Type:

int

path_data_csv_out

path to the folder where results are to be saved

Type:

str

prepare_run(dict_posteriors: dict[str, Posterior], path_raw: str, N_runs: int, scaler: Scaler, start_from: str | None, path_csv_mle: str | None, path_csv_map: str | None) ndarray | None[source]

prepares the run in two ways :

  • step 1 : creates empty folders to save the run results

  • step 2 : reads Theta_0 if specified (as the MLE or MAP)

Parameters:
  • dict_posteriors (dict[str, Posterior]) – dictionary of posterior distributions

  • path_raw (str) – path to the folders where the .hdf5 files are to be stored

  • N_runs (int) – number of independent Markov chains to run per posterior distribution

  • scaler (Scaler) – contains the transformation of the Theta values from their natural space to their scaled space (in which the sampling happens)

  • start_from (Optional[str]) – point at which the inversion will start, must be in [None, “MAP”]. For None, a random value is drawn uniformly in the scaled hypercube.

  • path_csv_mle (Optional[str]) – path to the csv file containing the already estimated MLE

  • path_csv_map (Optional[str]) – path to the csv file containing the already estimated MAP

Returns:

starting point of the (in scaled space) inversion, Theta_0, if specified. Otherwise None.

Return type:

Optional[np.ndarray]

run(dict_posteriors: dict[str, Posterior], sampler_: Sampler, saver_: Saver, N_runs: int, max_iter: int, T_BI: int, path_raw: str, Theta_0: ndarray | None = None, regu_spatial_N0: int | float = inf, regu_spatial_scale: float | None = 1.0, regu_spatial_vmin: float | None = 1e-08, regu_spatial_vmax: float | None = 100000000.0, freq_save: int = 1, can_run_in_parallel: bool = True) None[source]

runs the inversion

Parameters:
  • dict_posteriors (dict[str, Posterior]) – dictionary of posterior distributions

  • sampler (Sampler) – sampler to be used to generate the Markov chain(s)

  • saver (Saver) – object responsible for progressively saving the Markov chain data during the run

  • N_runs (int) – number of independent Markov chains to run per posterior distribution

  • max_iter (int) – total duration of a Markov chain

  • T_BI (int) – duration of the Burn-in phase

  • path_raw (str) – path to the folders where the .hdf5 files are to be stored

  • Theta_0 (Optional[np.ndarray], optional) – starting point, by default None

  • regu_spatial_N0 (Union[int, float], optional) – number of iterations defining the initial update phase (for spatial regularization weight optimization). np.infty means that the optimization phase never starts, and that the weight optimization is not applied. by default np.infty

  • regu_spatial_scale (Optional[float], optional) – scale parameter involved in the definition of the projected gradient step size (for spatial regularization weight optimization). by default 1.0

  • regu_spatial_vmin (Optional[float], optional) – lower limit of the admissible interval (for spatial regularization weight optimization), by default 1e-8

  • regu_spatial_vmax (Optional[float], optional) – upper limit of the admissible interval (for spatial regularization weight optimization), by default 1e8

  • freq_save (int, optional) – frequency of saved iterates during the run (1 means that every iteration is saved), by default 1

  • can_run_in_parallel (bool, optional) – wether the inversion can be run in parallel (may cause difficulties for forward maps based on neural networks run on GPU), by default True

beetroots.inversion.run.run_optim_map module

class beetroots.inversion.run.run_optim_map.RunOptimMAP(path_data_csv_out: str, max_workers: int)[source]

Bases: Run

class that runs inversions using an optimization approach, considering all pixels / components at once

Parameters:
  • path_data_csv_out (str) – path to the folder where results are to be saved

  • max_workers (int) – max number of workers that can be used to run the inversion

main(dict_posteriors: dict[str, Posterior], sampler_: Sampler, saver_: Saver, scaler: Scaler, N_runs: int, max_iter: int, path_raw: str, path_csv_mle: str | None = None, start_from: str | None = None, freq_save: int = 1, can_run_in_parallel: bool = True) None[source]

sequentially calls prepare_run and run

Parameters:
  • dict_posteriors (dict[str, Posterior]) – dictionary of posterior distributions

  • sampler (Sampler) – optimizer

  • saver (Saver) – object responsible for progressively saving the optimization run data during the run

  • scaler (Scaler) – contains the transformation of the Theta values from their natural space to their scaled space (in which the sampling happens)

  • N_runs (int) – number of independent optimization runs to run per posterior distribution

  • max_iter (int) – total duration of an optimization run

  • path_raw (str) – path to the folders where the .hdf5 files are to be stored

  • path_csv_mle (Optional[str]) – path to the csv file containing the already estimated MLE

  • start_from (Optional[str], optional) – name of the starting point, such as “MAP”, by default None

  • freq_save (int, optional) – frequency of saved iterates during the run (1 means that every iteration is saved), by default 1

  • can_run_in_parallel (bool, optional) – wether the inversion can be run in parallel (may cause difficulties for forward maps based on neural networks run on GPU), by default True

max_workers

max number of workers that can be used to run the inversion

Type:

int

path_data_csv_out

path to the folder where results are to be saved

Type:

str

prepare_run(dict_posteriors: dict[str, Posterior], path_raw: str, N_runs: int, scaler: Scaler, start_from: str | None = None, path_csv_mle: str | None = None) ndarray | None[source]

prepares the run in two ways :

  • step 1 : creates empty folders to save the run results

  • step 2 : reads Theta_0 if specified (as the MLE)

Parameters:
  • dict_posteriors (dict[str, Posterior]) – dictionary of posterior distributions

  • path_raw (str) – path to the folders where the .hdf5 files are to be stored

  • N_runs (int) – number of independent optimization runs to run per posterior distribution

  • scaler (Scaler) – contains the transformation of the Theta values from their natural space to their scaled space (in which the sampling happens)

  • start_from (Optional[str]) – point at which the inversion will start, must be in [None, “MAP”]. For None, a random value is drawn uniformly in the scaled hypercube.

  • path_csv_mle (Optional[str]) – path to the csv file containing the already estimated MLE

Returns:

starting point of the (in scaled space) inversion, Theta_0, if specified. Otherwise None.

Return type:

Optional[np.ndarray]

run(dict_posteriors: dict[str, Posterior], sampler_: Sampler, saver_: Saver, N_runs: int, max_iter: int, path_raw: str, Theta_0: ndarray | None = None, freq_save: int = 1, can_run_in_parallel: bool = True) None[source]

runs the inversion

Parameters:
  • dict_posteriors (dict[str, Posterior]) – dictionary of posterior distributions

  • sampler (Sampler) – optimizer

  • saver (Saver) – object responsible for progressively saving the optimization run data during the run

  • N_runs (int) – number of independent optimization runs to run per posterior distribution

  • max_iter (int) – total duration of an optimization run

  • path_raw (str) – path to the folders where the .hdf5 files are to be stored

  • Theta_0 (Optional[np.ndarray], optional) – starting point, by default None

  • freq_save (int, optional) – frequency of saved iterates during the run (1 means that every iteration is saved), by default 1

  • can_run_in_parallel (bool, optional) – wether the inversion can be run in parallel (may cause difficulties for forward maps based on neural networks run on GPU), by default True

Module contents