Skip to content

Commit

Permalink
Replaces updated version of TaylorSeries
Browse files Browse the repository at this point in the history
  • Loading branch information
dimtsap committed Mar 16, 2021
1 parent 09f765b commit 0010ecf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 93 deletions.
29 changes: 1 addition & 28 deletions src/UQpy/Reliability/TaylorSeries/FORM.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,45 @@
from UQpy.Reliability.TaylorSeries.TaylorSeries import TaylorSeries


########################################################################################################################
########################################################################################################################
# First order reliability method
########################################################################################################################
class FORM(TaylorSeries):
"""
A class perform the First Order Reliability Method. The ``run`` method of the ``FORM`` class can be invoked many
times and each time the results are appended to the existing ones.
This is a child class of the ``TaylorSeries`` class.
**Input:**
See ``TaylorSeries`` class.
**Attributes:**
* **Pf_form** (`float`):
First-order probability of failure estimate.
* **beta_form** (`float`):
Hasofer-Lind reliability index.
* **DesignPoint_U** (`ndarray`):
Design point in the uncorrelated standard normal space **U**.
* **DesignPoint_X** (`ndarray`):
Design point in the parameter space **X**.
* **alpha** (`ndarray`):
Direction cosine.
* **form_iterations** (`int`):
Number of model evaluations.
* **u_record** (`list`):
Record of all iteration points in the standard normal space **U**.
* **x_record** (`list`):
Record of all iteration points in the parameter space **X**.
* **beta_record** (`list`):
Record of all Hasofer-Lind reliability index values.
* **dg_u_record** (`list`):
Record of the model's gradient in the standard normal space.
* **alpha_record** (`list`):
Record of the alpha (directional cosine).
* **g_record** (`list`):
Record of the performance function.
* **error_record** (`list`):
Record of the error defined by criteria `e1, e2, e3`.
**Methods:**
"""

def __init__(self, dist_object, runmodel_object, form_object=None, seed_x=None, seed_u=None, df_step=None,
def __init__(self, dist_object, runmodel_object, form_object=None, seed_x=None, seed_u=None, df_step=0.01,
corr_x=None, corr_z=None, n_iter=100, tol1=None, tol2=None, tol3=None, verbose=False):

super().__init__(dist_object, runmodel_object, form_object, corr_x, corr_z, seed_x, seed_u, n_iter, tol1, tol2,
Expand All @@ -76,8 +54,6 @@ def __init__(self, dist_object, runmodel_object, form_object=None, seed_x=None,
if df_step is not None:
if not isinstance(df_step, (float, int)):
raise ValueError('UQpy: df_step must be of type float or integer.')
else:
df_step = 0.01

# Initialize output
self.beta_form = None
Expand Down Expand Up @@ -116,11 +92,8 @@ def __init__(self, dist_object, runmodel_object, form_object=None, seed_x=None,
def run(self, seed_x=None, seed_u=None):
"""
Run FORM
This is an instance method that runs FORM.
**Input:**
* **seed_u** or **seed_x** (`ndarray`):
See ``TaylorSeries`` parent class.
"""
Expand Down
22 changes: 3 additions & 19 deletions src/UQpy/Reliability/TaylorSeries/SORM.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,20 @@
from UQpy.Reliability.TaylorSeries.TaylorSeries import TaylorSeries


########################################################################################################################
########################################################################################################################
# Second order reliability method
########################################################################################################################
class SORM(TaylorSeries):
"""
A class to perform the Second Order Reliability Method. This class is used to correct the estimated FORM probability
using second-order information.
``SORM`` is a child class of the ``TaylorSeries`` class.
**Input:**
The ``SORM`` class requires an object of type ``FORM`` as input.
**Output/Returns:**
The ``SORM`` class has the same outputs as the ``FORM`` class plus
* **Pf_sorm** (`float`):
Second-order probability of failure estimate.
* **beta_sorm** (`float`):
Second-order reliability index.
**Methods:**
"""

def __init__(self, form_object, dist_object=None, seed_u=None, seed_x=None, runmodel_object=None, def_step=None,
Expand Down Expand Up @@ -68,15 +55,12 @@ def _run(self):

"""
Run SORM
This is an instance method that runs SORM.
"""

if self.verbose:
print('UQpy: Calculating SORM correction...')

self.df_step = self.form_object.df_step

self.beta_form = self.form_object.beta_form[-1]
self.nataf_object = self.form_object.nataf_object
self.DesignPoint_U = self.form_object.DesignPoint_U[-1]
Expand Down Expand Up @@ -124,10 +108,10 @@ def normalize(v):
matrix_b = np.dot(np.dot(r1, hessian_g), r1.T) / np.linalg.norm(dg_u_record[-1])
kappa = np.linalg.eig(matrix_b[:self.dimension-1, :self.dimension-1])
if self.call is None:
self.Pf_sorm = [stats.norm.cdf(-1 * self.beta_form) * np.prod(1 / (1 + self.beta_form * kappa[0]) ** 0.5)]
self.Pf_sorm = [stats.norm.cdf(-self.beta_form) * np.prod(1 / (1 + self.beta_form * kappa[0]) ** 0.5)]
self.beta_sorm = [-stats.norm.ppf(self.Pf_sorm)]
else:
self.Pf_sorm = self.Pf_sorm + [stats.norm.cdf(-1 * self.beta_form) * np.prod(1 / (1 + self.beta_form *
self.Pf_sorm = self.Pf_sorm + [stats.norm.cdf(-self.beta_form) * np.prod(1 / (1 + self.beta_form *
kappa[0]) ** 0.5)]
self.beta_sorm = self.beta_sorm + [-stats.norm.ppf(self.Pf_sorm)]

Expand Down
46 changes: 0 additions & 46 deletions src/UQpy/Reliability/TaylorSeries/TaylorSeries.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,45 @@
class TaylorSeries:
"""
Perform First and Second Order Reliability (FORM/SORM) methods.
This is the parent class to all Taylor series expansion algorithms.
**Input:**
* **dist_object** ((list of ) ``Distribution`` object(s)):
Marginal probability distributions of each random variable. Must be an object of type
``DistributionContinuous1D`` or ``JointInd``.
* **runmodel_object** (``RunModel`` object):
The computational model. It should be of type ``RunModel`` (see ``RunModel`` class).
* **form_object** (``FORM`` object):
It should be of type ``FORM`` (see ``FORM`` class). Used to calculate SORM correction.
* **corr_z** or **corr_x** (`ndarray`):
Covariance matrix
If `corr_x` is provided, it is the correlation matrix (:math:`\mathbf{C_X}`) of the random vector **X** .
If `corr_z` is provided, it is the correlation matrix (:math:`\mathbf{C_Z}`) of the standard normal random
vector **Z** .
Default: `corr_z` is specified as the identity matrix.
* **seed_u** or **seed_x** (`ndarray`):
The initial starting point for the `Hasofer-Lind` algorithm.
Either `seed_u` or `seed_x` must be provided.
If `seed_u` is provided, it should be a point in the uncorrelated standard normal space of **U**.
If `seed_x` is provided, it should be a point in the parameter space of **X**.
Default: `seed_u = (0, 0, ..., 0)`
* **tol1** (`float`):
Convergence threshold for criterion `e1` of the `HLRF` algorithm.
Default: 1.0e-3
* **tol2** (`float`):
Convergence threshold for criterion `e2` of the `HLRF` algorithm.
Default: 1.0e-3
* **tol3** (`float`):
Convergence threshold for criterion `e3` of the `HLRF` algorithm.
Default: 1.0e-3
* **n_iter** (`int`):
Maximum number of iterations for the `HLRF` algorithm.
Default: 100
* **df_step** ('float'):
Finite difference step in standard normal space.
Default: 0.01 (see `derivatives` class)
* **verbose** (`Boolean`):
A boolean declaring whether to write text to the terminal.
**Methods:**
"""

def __init__(self, dist_object, runmodel_object, form_object, corr_x, corr_z, seed_x, seed_u, n_iter, tol1, tol2,
Expand Down Expand Up @@ -123,58 +96,39 @@ def derivatives(point_u, point_x, runmodel_object, nataf_object, order='first',
"""
A method to estimate the derivatives (1st-order, 2nd-order, mixed) of a function using a central difference
scheme after transformation to the standard normal space.
This is a static method of the ``FORM`` class.
**Inputs:**
* **point_u** (`ndarray`):
Point in the uncorrelated standard normal space at which to evaluate the gradient with shape
`samples.shape=(1, dimension)`.
Either `point_u` or `point_x` must be specified. If `point_u` is specified, the derivatives are computed
directly.
* **point_x** (`ndarray`):
Point in the parameter space at which to evaluate the model with shape
`samples.shape=(1, dimension)`.
Either `point_u` or `point_x` must be specified. If `point_x` is specified, the variable is transformed to
standard normal using the ``Nataf`` transformation and derivatives are computed.
* **runmodel_object** (``RunModel`` object):
The computational model. It should be of type ``RunModel`` (see ``RunModel`` class).
* **nataf_object** (``Nataf`` object):
An object of the ``Nataf`` class (see ``Nataf`` class).
* **order** (`str`):
Order of the derivative. Available options: 'first', 'second', 'mixed'.
Default: 'first'.
* **point_qoi** (`float`):
Value of the model evaluated at ``point_u``. Used only for second derivatives.
* **df_step** (`float`):
Finite difference step in standard normal space.
Default: 0.01
* **verbose** (Boolean):
A boolean declaring whether to write text to the terminal.
**Output/Returns:**
* **du_dj** (`ndarray`):
Vector of first-order derivatives (if order = 'first').
* **d2u_dj** (`ndarray`):
Vector of second-order derivatives (if order = 'second').
* **d2u_dij** (`ndarray`):
Vector of mixed derivatives (if order = 'mixed').
"""

list_of_samples = list()
Expand Down

0 comments on commit 0010ecf

Please sign in to comment.