diff --git a/elfi/methods/inference/__init__.py b/elfi/methods/inference/__init__.py new file mode 100644 index 00000000..6e031999 --- /dev/null +++ b/elfi/methods/inference/__init__.py @@ -0,0 +1 @@ +# noqa: D104 diff --git a/elfi/methods/inference/romc.py b/elfi/methods/inference/romc.py index f75c1e91..8e278437 100644 --- a/elfi/methods/inference/romc.py +++ b/elfi/methods/inference/romc.py @@ -493,7 +493,8 @@ def __init__(self, model, bounds=None, discrepancy_name=None, output_names=None, self.distances = None self.result = None # RomcSample object - self.progress_bar = ProgressBar() + self.progress_bar = ProgressBar(prefix='Progress', suffix='Complete', + decimals=1, length=50, fill='=') super(ROMC, self).__init__(model, output_names, **kwargs) @@ -633,8 +634,9 @@ def _solve_gradients(self, **kwargs): attempted = [False for _ in range(n1)] tic = timeit.default_timer() if parallelize is False: + self.progress_bar.reinit_progressbar(reinit_msg="Solving gradients") for i in range(n1): - self.progress_bar.update_progressbar(i, n1) + self.progress_bar.update_progressbar(i + 1, n1) attempted[i] = True is_solved = optim_probs[i].solve_gradients(**kwargs) solved[i] = is_solved @@ -681,8 +683,9 @@ def _solve_bo(self, **kwargs): attempted = [] solved = [] tic = timeit.default_timer() + self.progress_bar.reinit_progressbar(reinit_msg="Bayesian Optimization") for i in range(n1): - self.progress_bar.update_progressbar(i, n1) + self.progress_bar.update_progressbar(i + 1, n1) attempted.append(True) is_solved = optim_problems[i].solve_bo(**kwargs) solved.append(is_solved) @@ -774,8 +777,9 @@ def _build_boxes(self, **kwargs): # main computed_bb = [False for _ in range(n1)] if parallelize is False: + self.progress_bar.reinit_progressbar(reinit_msg="Building boxes") for i in range(n1): - self.progress_bar.update_progressbar(i, n1) + self.progress_bar.update_progressbar(i + 1, n1) if accepted[i]: is_built = optim_problems[i].build_region(**kwargs) computed_bb.append(is_built) @@ -808,8 +812,9 @@ def _fit_models(self, **kwargs): # main if parallelize is False: + self.progress_bar.reinit_progressbar(reinit_msg="Fitting models") for i in range(n1): - self.progress_bar.update_progressbar(i, n1) + self.progress_bar.update_progressbar(i + 1, n1) if accepted[i]: optim_problems[i].fit_local_surrogate(**kwargs) else: diff --git a/elfi/methods/posteriors.py b/elfi/methods/posteriors.py index e396d6f3..2e49a349 100644 --- a/elfi/methods/posteriors.py +++ b/elfi/methods/posteriors.py @@ -320,7 +320,8 @@ def __init__(self, self.parallelize = parallelize self.partition = None - self.progress_bar = ProgressBar() + self.progress_bar = ProgressBar(prefix='Progress', suffix='Complete', + decimals=1, length=50, fill='=') def _pdf_unnorm_single_point(self, theta: np.ndarray) -> float: """Evaluate the unnormalised pdf, at a single input point. @@ -588,11 +589,12 @@ def sample(self, n2: int, seed=None) -> (np.ndarray, np.ndarray): if self.parallelize is False: w = [] distances = [] + self.progress_bar.reinit_progressbar(reinit_msg="Sampling posterior regions") for i in range(nof_regions): w.append([]) # indicator_region = self.regions[i].contains for j in range(n2): - self.progress_bar.update_progressbar(i * n2 + j, nof_regions * n2) + self.progress_bar.update_progressbar(i * n2 + j + 1, nof_regions * n2) cur_theta = theta[i, j] q = regions[i].pdf(cur_theta) if q == 0.0: