def test_sorm(setup): dist1 = Normal(loc=500, scale=100) dist2 = Normal(loc=1000, scale=100) dist = [dist1, dist2] form_obj = FORM(distributions=dist, runmodel_object=setup) form_obj.run() sorm_obj = SORM(form_object=form_obj) for file_name in glob.glob("Model_Runs_*"): shutil.rmtree(file_name) np.testing.assert_allclose(sorm_obj.failure_probability, 2.8803e-7, rtol=1e-02)
def test_seeds_xu_is_none(setup): path = os.path.abspath(os.path.dirname(__file__)) os.chdir(path) dist1 = Normal(loc=200, scale=20) dist2 = Normal(loc=150, scale=10) dist = [dist1, dist2] form_obj = FORM(distributions=dist, runmodel_object=setup) form_obj.run() for file_name in glob.glob("Model_Runs_*"): shutil.rmtree(file_name) np.testing.assert_allclose(form_obj.u_record[0][0][0], [0., 0.], rtol=1e-02)
def test_seeds_x_is_none(setup): path = os.path.abspath(os.path.dirname(__file__)) os.chdir(path) dist1 = Normal(loc=200, scale=20) dist2 = Normal(loc=150, scale=10) dist = [dist1, dist2] form_obj = FORM(distributions=dist, runmodel_object=setup, seed_u=[1, 1]) form_obj.run() for file_name in glob.glob("Model_Runs_*"): shutil.rmtree(file_name) np.testing.assert_allclose(form_obj.failure_probability, 0.0126, rtol=1e-02)
def test_form_example(): path = os.path.abspath(os.path.dirname(__file__)) os.chdir(path) model = PythonModel(model_script='pfn3.py', model_object_name='example1', delete_files=True) RunModelObject = RunModel(model=model) dist1 = Normal(loc=200., scale=20.) dist2 = Normal(loc=150, scale=10.) Q = FORM(distributions=[dist1, dist2], runmodel_object=RunModelObject, tol1=1e-5, tol2=1e-5) Q.run() # print results np.allclose(Q.DesignPoint_U, np.array([-2., 1.])) np.allclose(Q.DesignPoint_X, np.array([160., 160.])) assert Q.beta[0] == 2.236067977499917 assert Q.failure_probability[0] == 0.012673659338729965 np.allclose(Q.dg_u_record, np.array([0., 0.]))
# %% # %% md # # Initially we have to import the necessary modules. # %% from UQpy.run_model.RunModel import RunModel from UQpy.run_model.model_execution.PythonModel import PythonModel from UQpy.distributions import Normal from UQpy.reliability import FORM dist1 = Normal(loc=20., scale=3.5) dist2 = Normal(loc=5., scale=0.8) dist3 = Normal(loc=4., scale=0.4) model = PythonModel( model_script='pfn.py', model_object_name="example3", ) RunModelObject3 = RunModel(model=model) Z0 = FORM(distributions=[dist1, dist2, dist3], runmodel_object=RunModelObject3) Z0.run() print('Design point in standard normal space: %s' % Z0.DesignPoint_U) print('Design point in original space: %s' % Z0.DesignPoint_X) print('Hasofer-Lind reliability index: %s' % Z0.beta) print('FORM probability of failure: %s' % Z0.failure_probability)
import shutil import numpy as np import matplotlib.pyplot as plt from UQpy.run_model.RunModel import RunModel from UQpy.run_model.model_execution.PythonModel import PythonModel from UQpy.distributions import Normal from UQpy.reliability import FORM model = PythonModel(model_script='pfn.py', model_object_name="example1") RunModelObject = RunModel(model=model) dist1 = Normal(loc=200., scale=20.) dist2 = Normal(loc=150, scale=10.) Q = FORM(distributions=[dist1, dist2], runmodel_object=RunModelObject, tol1=1e-5, tol2=1e-5) Q.run() # print results print('Design point in standard normal space: %s' % Q.DesignPoint_U) print('Design point in original space: %s' % Q.DesignPoint_X) print('Hasofer-Lind reliability index: %s' % Q.beta) print('FORM probability of failure: %s' % Q.failure_probability) print(Q.dg_u_record) # Supporting function def multivariate_gaussian(pos, mu, Sigma): n = mu.shape[0] Sigma_det = np.linalg.det(Sigma)
import shutil import numpy as np from UQpy.run_model.RunModel import RunModel from UQpy.run_model.model_execution.PythonModel import PythonModel from UQpy.distributions import Normal from UQpy.reliability import FORM from UQpy.reliability import SORM from UQpy.distributions import Lognormal m0 = 7 v0 = 1.4 mu = np.log(m0) - np.log(np.sqrt(1 + (v0 / m0) ** 2)) scale = np.exp(mu) s = np.sqrt(np.log(1 + (v0 / m0) ** 2)) loc_ = 0.0 dist1 = Normal(loc=20., scale=2) dist2 = Lognormal(s=s, loc=0.0, scale=scale) model = PythonModel(model_script='pfn.py', model_object_name="example4",) RunModelObject4 = RunModel(model=model) form = FORM(distributions=[dist1, dist2], runmodel_object=RunModelObject4) form.run() Q0 = SORM(form_object=form) # print results print('SORM probability of failure: %s' % Q0.failure_probability)
# :math:`g(U) = -\frac{1}{\sqrt{d}}\sum_{i=1}^{d} u_i + \beta` # # The probability of failure in this case is :math:`P(F) ≈ 10^{−3}` for :math:`β = 3.0902` # # Initially we have to import the necessary modules. #%% import shutil from UQpy.run_model.RunModel import RunModel from UQpy.run_model.model_execution.PythonModel import PythonModel from UQpy.distributions import Normal from UQpy.reliability import FORM dist1 = Normal(loc=0., scale=1.) dist2 = Normal(loc=0., scale=1.) model = PythonModel(model_script='pfn.py', model_object_name="example2") RunModelObject2 = RunModel(model=model) Z = FORM(distributions=[dist1, dist2], runmodel_object=RunModelObject2) Z.run() # print results print('Design point in standard normal space: %s' % Z.DesignPoint_U) print('Design point in original space: %s' % Z.DesignPoint_X) print('Hasofer-Lind reliability index: %s' % Z.beta) print('FORM probability of failure: %s' % Z.failure_probability)