First order second moment
[1]:
# Import auxiliary libraries for demonstration
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
plt.rcParams[ "figure.figsize" ] = [ 5, 4 ]
plt.rcParams[ "figure.dpi" ] = 80
plt.rcParams[ "font.family" ] = "Times New Roman"
plt.rcParams[ "font.size" ] = '14'
Mean value FOSM
FOSM with mean value algorithm can be expressed by the following equation,
\[\beta = \frac{g(\mu_1, \mu_2, \dots, \mu_n)}{\sqrt{ \sum_{i=1}^n \alpha_i \sigma_i}}\]
where \(g\) is the limit state function (LSF); \(\alpha_i\) is given by,
\[\alpha_i = \frac{\partial g}{ \partial X_i} \Bigr|_{\mu_i}\]
Function mvalFOSM
implements the FOSM with mean value algorithm.
Reference: Nowak, A.S. and Collins, K.R., 2012. Reliability of structures. CRC press.
Function help
[2]:
from ffpack.rrm import mvalFOSM
help( mvalFOSM )
Help on function mvalFOSM in module ffpack.rrm.firstOrderSecondMoment:
mvalFOSM(dim, g, dg, mus, sigmas, dx=1e-06)
First order second moment method based on mean value algorithm.
Parameters
----------
dim: integer
Space dimension ( number of random variables ).
g: function
Limit state function. It will be called like g( [ x1, x2, ... ] ).
dg: array_like of function
Gradient of the limit state function. It should be an array_like of function
like dg = [ dg_dx1, dg_dx2, ... ]. To get the derivative of i-th random
variable at ( x1*, x2*, ... ), dg[ i ]( x1*, x2*, ... ) will be called.
dg can be None, see the following Notes.
mus: 1d array
Mean of the random variables.
sigmas: 1d array
Variance of the random variables.
dx : scalar, optional
Spacing for auto differentiation. Not required if dg is provided.
Returns
-------
beta: scalar
Reliability index.
pf: scalar
probability of failure.
Raises
------
ValueError
If the dim is less than 1.
If the dim does not match the length of mus and sigmas.
Notes
-----
If dg is None, the numerical differentiation will be used. The tolerance of the
numerical differentiation can be changed in globalConfig.
Examples
--------
>>> from ffpack.rrm import mvalFOSM
>>> dim = 2
>>> g = lambda X: 3 * X[ 0 ] - 2 * X[ 1 ]
>>> dg = [ lambda X: 3, lambda X: -2 ]
>>> mus = [ 1, 1 ]
>>> sigmas = [ 3, 4 ]
>>> beta, pf = mvalFOSM( dim, g, dg, mus, sigmas)
Example with explicit derivative of LSF
[3]:
# Define the dimension for the FOSM problem
dim = 2
# Define the limit state function (LSF) g
g = lambda X: 3 * X[ 0 ] - 2 * X[ 1 ]
# Explicit derivative of LSF
# dg is a list in which each element is a partial derivative function of g w.r.t. X
# dg[0] = partial g / partial X[0]
# dg[1] = partial g / partial X[1]
dg = [ lambda X: 3, lambda X: -2 ]
# Mean and standard deviation of the random variables
mus = [ 1, 1 ]
sigmas = [ 3, 4 ]
# Use mean value algorithm to get results
beta, pf = mvalFOSM( dim, g, dg, mus, sigmas)
[4]:
print( "Reliability index: " )
print( beta )
print()
print( "Failure probability: " )
print( pf )
Reliability index:
0.08304547985373997
Failure probability:
0.46690768839408386
Example with automatic differentiation of LSF
[5]:
# Define the dimension for the FOSM problem
dim = 2
# Define the limit state function (LSF) g
g = lambda X: 3 * X[ 0 ] - 2 * X[ 1 ]
# If dg is None, the internal automatic differentiation algorithm will be used
dg = None
# Mean and standard deviation of the random variables
mus = [ 1, 1 ]
sigmas = [ 3, 4 ]
# Use mean value algorithm to get results
beta, pf = mvalFOSM( dim, g, dg, mus, sigmas)
[6]:
print( "Reliability index: " )
print( beta )
print()
print( "Failure probability: " )
print( pf )
Reliability index:
0.08304547985853711
Failure probability:
0.46690768839217667