Skip to content

Commit d9332cf

Browse files
committed
Enhance ELBO optimization: update progress bar with current and best values.
1 parent 8734578 commit d9332cf

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

predicators/approaches/pp_param_learning_approach.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def _learn_process_parameters(self,
139139

140140
# Keep track of iterations for progress display
141141
iteration_count = 0
142+
best_elbo = -np.inf
142143
progress_bar = tqdm(desc="Optim. params.", unit="iter")
143144

144145
# 2. Define objective and optimize
@@ -147,7 +148,7 @@ def objective(params):
147148
148149
It does some preparation and then calls the -ELBO function.
149150
"""
150-
nonlocal iteration_count
151+
nonlocal iteration_count, best_elbo
151152
nonlocal start_times
152153
nonlocal all_possible_atoms
153154
nonlocal atom_to_val_to_gps
@@ -163,14 +164,21 @@ def objective(params):
163164
}
164165

165166
elbo_val = self.elbo(atom_option_dataset,
166-
self._processes,
167167
self.ground_processes,
168168
guide,
169169
frame_strength=params[0],
170-
predicates=self._get_current_predicates(),
171170
start_times=start_times,
172171
all_possible_atoms=set(all_possible_atoms),
173172
atom_to_val_to_gps=atom_to_val_to_gps,)
173+
# Update best ELBO
174+
if elbo_val > best_elbo:
175+
best_elbo = elbo_val
176+
177+
# Update progress bar with current and best ELBO
178+
progress_bar.set_postfix({
179+
'Current ELBO': f'{elbo_val:.4f}',
180+
'Best ELBO': f'{best_elbo:.4f}'
181+
})
174182
return -elbo_val
175183

176184
result = minimize(
@@ -186,6 +194,7 @@ def objective(params):
186194
method="L-BFGS-B") # terminate in 19464iter
187195
progress_bar.close()
188196
logging.info(f"Best likelihood bound: {-result.fun}")
197+
breakpoint()
189198

190199
# 3. Set the optimized parameters
191200
self._set_process_parameters(result.x[1:num_proc_params])
@@ -357,8 +366,7 @@ def elbo(
357366
H -= p * np.log(p)
358367

359368
elbo = ll + H
360-
logging.debug(f"H={H:.4f}, ELBO={elbo:.4f}")
361-
breakpoint()
369+
# logging.debug(f"H={H:.4f}, ELBO={elbo:.4f}")
362370
return elbo
363371

364372
def _set_process_parameters(self, parameters: Sequence[float]) -> None:

0 commit comments

Comments
 (0)