Skip to content

Commit

Permalink
Minor modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfjl committed Aug 9, 2024
1 parent cef5d82 commit 3e03b57
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion popt/cost_functions/epf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def epf(r, c_eq=0, c_iq=0):
The external penalty function, given as
.. math::
0.5r(\sum_i c_{eq}^2 + \sum(\max(c_{iq},0)^2)
We assume that the ensemble members are stacked as columns.
"""

return r*0.5*( np.sum(c_eq**2) + np.sum(np.maximum(-c_iq,0)**2) )
return r*0.5*( np.sum(c_eq**2, axis=0) + np.sum(np.maximum(-c_iq,0)**2, axis=0) )
7 changes: 3 additions & 4 deletions popt/loop/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,9 @@ def run_loop(self):
epf_not_converged = False
if self.epf:
if self.epf_iteration > self.epf['max_epf_iter']: # max epf_iterations set to 10
logger.info(
f' -----> EPF-EnOpt: maximum epf iterations reached') # print epf info
logger.info(f' -----> EPF-EnOpt: maximum epf iterations reached') # print epf info
break
p = np.abs(previous_state-self.mean_state) / np.abs(previous_state)
p = np.abs(previous_state-self.mean_state) / (np.abs(previous_state) + 1.0e-9)
conv_crit = self.epf['conv_crit']
if np.any(p > conv_crit):
epf_not_converged = True
Expand All @@ -207,7 +206,7 @@ def run_loop(self):
logger.info(f' -----> EPF-EnOpt: {self.epf_iteration}, {r} (outer iteration, penalty factor)') # print epf info
else:
logger.info(f' -----> EPF-EnOpt: converged, no variables changed more than {conv_crit*100} %') # print epf info
final_obj_no_penalty = str(round(self.fun(self.mean_state)[0],4))
final_obj_no_penalty = str(round(self.fun(self.mean_state),4))
logger.info(f' -----> EPF-EnOpt: objective value without penalty = {final_obj_no_penalty}') # print epf info

def save(self):
Expand Down
1 change: 1 addition & 0 deletions popt/update_schemes/enopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def __set__variable(var_name=None, defalut=None):
self.optimize_result = ot.get_optimize_result(self)
ot.save_optimize_results(self.optimize_result)
if self.logger is not None:
self.logger.info('\n\n')
self.logger.info(' ====== Running optimization - EnOpt ======')
self.logger.info('\n'+pprint.pformat(self.options))
info_str = ' {:<10} {:<10} {:<15} {:<15} {:<15} '.format('iter', 'alpha_iter',
Expand Down

0 comments on commit 3e03b57

Please sign in to comment.