Skip to content

Commit

Permalink
added state_function attribute, correct attribute behavior when max n…
Browse files Browse the repository at this point in the history
…umber of iterations is reached
  • Loading branch information
connor-krill committed Aug 17, 2023
1 parent adafcdf commit 5a6a1ce
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/UQpy/reliability/taylor_series/InverseFORM.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def __init__(
"""Record of the number of iterations before algorithm termination"""
self.failure_probability_record: list = []
"""Record of the probability of failure defined by :math:`p_{fail} = \\Phi(-\\beta_{HL})`"""
self.state_function: list = []
"""State function :math:`G(u)` evaluated at each step in the optimization"""

def run(self, seed_x: Union[list, np.ndarray] = None, seed_u: Union[list, np.ndarray] = None):
"""Runs the inverse FORM algorithm.
Expand All @@ -144,6 +146,7 @@ def run(self, seed_x: Union[list, np.ndarray] = None, seed_u: Union[list, np.nda

# Allocate u and the gradient of G(u) as arrays
u = np.zeros([self.max_iterations + 1, self.dimension])
state_function = np.full(self.max_iterations + 1, np.nan)
state_function_gradient = np.zeros([self.max_iterations + 1, self.dimension])

# Set initial seed. If both seed_x and seed_u are None, the initial seed is a vector of zeros in U space.
Expand All @@ -170,12 +173,14 @@ def run(self, seed_x: Union[list, np.ndarray] = None, seed_u: Union[list, np.nda
self.nataf_object.run(samples_z=z, jacobian=True)
x = self.nataf_object.samples_x
self.logger.info(f'Design Point U: {u[iteration, :]}\nDesign Point X: {x}\n')
state_function_gradient[iteration + 1, :], _, _ = self._derivatives(point_u=u[iteration, :],
point_x=x,
runmodel_object=self.runmodel_object,
nataf_object=self.nataf_object,
df_step=self.df_step,
order='first')
state_function_gradient[iteration + 1, :], qoi, _ = self._derivatives(point_u=u[iteration, :],
point_x=x,
runmodel_object=self.runmodel_object,
nataf_object=self.nataf_object,
df_step=self.df_step,
order='first')
self.logger.info(f'State Function: {qoi}')
self.state_function[iteration] = qoi

alpha = state_function_gradient[iteration + 1]
alpha /= np.linalg.norm(state_function_gradient[iteration + 1])
Expand All @@ -196,11 +201,11 @@ def run(self, seed_x: Union[list, np.ndarray] = None, seed_u: Union[list, np.nda

if iteration >= self.max_iterations:
self.logger.info(f'UQpy: Maximum number of iterations {self.max_iterations} reached before convergence')
else:
self.alpha_record.append(alpha)
self.beta_record.append(self.beta)
self.design_point_u.append(u[iteration, :])
self.design_point_x.append(x)
self.error_record.append((error_u, error_gradient))
self.iteration_record.append(iteration)
self.failure_probability_record.append(self.p_fail)
self.alpha_record.append(alpha)
self.beta_record.append(self.beta)
self.design_point_u.append(u[iteration, :])
self.design_point_x.append(x)
self.error_record.append((error_u, error_gradient))
self.iteration_record.append(iteration)
self.failure_probability_record.append(self.p_fail)
self.state_function.append(state_function)

0 comments on commit 5a6a1ce

Please sign in to comment.