beetroots.sampler.saver package
Submodules
beetroots.sampler.saver.abstract_saver module
- class beetroots.sampler.saver.abstract_saver.Saver(N: int, D: int, D_sampling: int, L: int, scaler: Scaler, results_path: str = '', batch_size: int | None = None, freq_save: int = 1, save_forward_map_evals: bool = False, list_idx_sampling: List[int] | None = None)[source]
Bases:
objectenable to regularly save the progression of the Markov chain to a
.hdf5file- Parameters:
N (int) – total number of pixels to reconstruct
D (int) – total number of physical parameters
D_sampling (int) – number of physical parameters that are optimized / sampled
L (int) – number of observed lines
scaler (Scaler) – contains the transformation of the Theta values from their scaled space (in which the sampling happens) to their natural space
results_path (str) – path towards the
.hdf5output file, by default “”batch_size (int, optional) – number of iterations between two saves on file, by default None
freq_save (int, optional) – save one sample in every (freq_save). Used to save disk space., by default 1
save_forward_map_evals (bool, optional) – wether to save the forward model evaluations and gradients, by default False
list_idx_sampling (Optional[List[int]], optional) – contains the indices of the physical parameters to be sampled
- D
total number of physical parameters
- Type:
int
- D_sampling
number of physical parameters that are optimized / sampled
- Type:
int
- L
number of observed lines
- Type:
int
- N
total number of pixels to reconstruct
- Type:
int
- batch_size
frequency of saves, i.e., “every
batch_sizenew iterates to be saved, the memory is saved to an.hdf5file and re-initialized- Type:
int
- check_need_to_save(t: int) bool[source]
checks wether or not the memory should be saved to a
.hdf5file- Parameters:
t (int) – current iteration index
- Returns:
wether or not to save to disk now
- Return type:
bool
- check_need_to_update_memory(t: int) bool[source]
checks wether or not the memory should be updated
- Parameters:
t (int) – current iteration index
- Returns:
wether or not to save to update the memory
- Return type:
bool
- final_next_batch_size
int:
- freq_save
frequency of saved iterates during the run (1 means that every iteration is saved)
- Type:
int
- abstract initialize_memory(T_MC: int, t: int, Theta: ndarray, forward_map_evals: dict = {}, nll_utils: dict = {}, dict_objective: dict = {}, additional_sampling_log: dict = {}) None[source]
initializes the memory with the correct shapes
- list_idx_sampling
contains the indices of the physical parameters to be sampled
- Type:
1D np.ndarray
- memory
stores the values before saving them to file
- Type:
dict[str, Union[float, np.ndarray]]
- next_batch_size
number of iterates to be stored in the next batch, i.e., until next save to file
- Type:
int
- results_path
path towards the
.hdf5output file- Type:
str
- save_additional(list_arrays: List[ndarray], list_names: List[str]) None[source]
saves additional content to a
.hdf5file- Parameters:
list_arrays (List[np.ndarray]) – list of the arrays to be saved
list_names (List[str]) – list of names for the arrays to be saved in the
.hdf5file
- save_forward_map_evals
wether to save the forward model evaluations and gradients
- Type:
bool
- scaler
contains the transformation of the Theta values from their natural space to their scaled space (in which the sampling happens)
- Type:
- set_results_path(results_path: str) None[source]
sets the path of the
.hdf5file to a new value- Parameters:
results_path (str) – path towards the
.hdf5output file
- t_last_init
time index of the last memory initialization
- Type:
int
- t_last_save
time index of the last save of the memory to
.hdf5file- Type:
int
- abstract update_memory(t: int, Theta: ndarray, forward_map_evals: dict = {}, nll_utils: dict = {}, dict_objective: dict = {}, additional_sampling_log: dict = {}, rng_state_array: ndarray | None = None, rng_inc_array: ndarray | None = None) None[source]
updates the memory with new information. All of the potential entries are optional except for the current iterate.
beetroots.sampler.saver.my_saver module
- class beetroots.sampler.saver.my_saver.MySaver(N: int, D: int, D_sampling: int, L: int, scaler: Scaler, results_path: str = '', batch_size: int | None = None, freq_save: int = 1, save_forward_map_evals: bool = False, list_idx_sampling: List[int] | None = None)[source]
Bases:
Saver- Parameters:
N (int) – total number of pixels to reconstruct
D (int) – total number of physical parameters
D_sampling (int) – number of physical parameters that are optimized / sampled
L (int) – number of observed lines
scaler (Scaler) – contains the transformation of the Theta values from their scaled space (in which the sampling happens) to their natural space
results_path (str) – path towards the
.hdf5output file, by default “”batch_size (int, optional) – number of iterations between two saves on file, by default None
freq_save (int, optional) – save one sample in every (freq_save). Used to save disk space., by default 1
save_forward_map_evals (bool, optional) – wether to save the forward model evaluations and gradients, by default False
list_idx_sampling (Optional[List[int]], optional) – contains the indices of the physical parameters to be sampled
- D
total number of physical parameters
- Type:
int
- D_sampling
number of physical parameters that are optimized / sampled
- Type:
int
- L
number of observed lines
- Type:
int
- N
total number of pixels to reconstruct
- Type:
int
- batch_size
frequency of saves, i.e., “every
batch_sizenew iterates to be saved, the memory is saved to an.hdf5file and re-initialized- Type:
int
- final_next_batch_size
int:
- freq_save
frequency of saved iterates during the run (1 means that every iteration is saved)
- Type:
int
- initialize_memory(T_MC: int, t: int, Theta: ndarray, forward_map_evals: dict = {}, nll_utils: dict = {}, dict_objective: dict = {}, additional_sampling_log: dict = {}) None[source]
initializes the memory with the correct shapes
- Parameters:
T_MC (int) – size of the Markov chain to be sampled / optimization procedure
t (int) – current iteration index
Theta (np.ndarray) – current iterate in the Markov chain / optimization run
forward_map_evals (dict, optional) – evaluations of the forward map and potentially derivatives, by default dict()
nll_utils (dict, optional) – evaluation of utilitary values of the Likelihood class, by default dict()
dict_objective (dict, optional) – contains the negative log posterior value and detailed components, by default dict()
additional_sampling_log (dict, optional) – additional data on the sampling / optimization run, by default dict()
- list_idx_sampling
contains the indices of the physical parameters to be sampled
- Type:
1D np.ndarray
- memory
stores the values before saving them to file
- Type:
dict[str, Union[float, np.ndarray]]
- next_batch_size
number of iterates to be stored in the next batch, i.e., until next save to file
- Type:
int
- results_path
path towards the
.hdf5output file- Type:
str
- save_forward_map_evals
wether to save the forward model evaluations and gradients
- Type:
bool
- scaler
contains the transformation of the Theta values from their natural space to their scaled space (in which the sampling happens)
- Type:
- t_last_init
time index of the last memory initialization
- Type:
int
- t_last_save
time index of the last save of the memory to
.hdf5file- Type:
int
- update_memory(t: int, Theta: ndarray, forward_map_evals: dict = {}, nll_utils: dict = {}, dict_objective: dict = {}, additional_sampling_log: dict = {}, rng_state_array: ndarray | None = None, rng_inc_array: ndarray | None = None) None[source]
updates the memory with new information. All of the potential entries are optional except for the current iterate.
- Parameters:
t (int) – current iteration index
Theta (np.ndarray) – current iterate in the Markov chain / optimization run
forward_map_evals (dict, optional) – evaluations of the forward map and potentially derivatives, by default dict()
nll_utils (dict, optional) – evaluation of utilitary values of the Likelihood class, by default dict()
dict_objective (dict, optional) – contains the negative log posterior value and detailed components, by default dict()
additional_sampling_log (dict, optional) – additional data on the sampling / optimization run, by default dict()
rng_state_array (Optional[np.ndarray], optional) – current state of the random generator (saved for sampling reproducibility), by default None
rng_inc_array (Optional[np.ndarray], optional) – current inc of the random generator (saved for sampling reproducibility), by default None