<jupyter_start><jupyter_text>Time-variant global reliability sensitivity analysis of structures with both input random variables and stochastic processes :  Method validation on included numerical example.In the paper above, their method is tested on a simple numerical example.<jupyter_code>import numpy as np
import openturns as ot
# from numba import jit
from joblib import Parallel, delayed
from functools import partial
import klfs
# the limit state function:
#@jit(nopython=True)
def g(t,x1, x2, y1):
    #function returns 1 if limit state is not exceeded on time interval
    out_g = np.sin(t)*x1 + np.square(x2) + 3*y1 - 5*(np.sin(t/8) + 1)
    return np.int(np.where(out_g<0,1,0).all())

# the function for multiprocessing on the limit state function
def g_mult(t,x1, x2, y1):
    # t is the time grid, and is invarient
    x1 = np.array(x1)
    N = x1.shape[0]
    x2 = np.array(x2)
    y1 = np.array(y1)
    output = Parallel(n_jobs=-1)(delayed(g) (t,x1[i], x2[i], y1[i]) for i in range(N))
    return ot.Point(output)

x = np.zeros((200,100))
uu = g_mult(x,x,x,x)
# Let's define a time grid. Let's say 100 samples over 10 seconds 
dimension = 1
NElem = [99]
mesher = ot.IntervalMesher(NElem)
lowerBound = [0] #s
upperBound = [10] #s
interval = ot.Interval(lowerBound,upperBound)
mesh = mesher.build(interval)
# 100 elements of 10 mm
# Process Y1:
model = ot.ExponentialModel()
algo = ot.KarhunenLoeveP1Algorithm(mesh, model)
algo.run()
kl_results = algo.getResult()
kl_results.setName('Y1')

# random Normals X1, X2
X1 = ot.Normal()
X1.setName('X1')
X2 = ot.Normal()
X2.setName('X2')

# The time grid :
t = np.array(mesh.getVertices())
# let's modify a bit our function as the time grid is invarient...
g_mod = partial(g_mult,t)
list_kl_results = [X1, X2, kl_results]
AggregatedKLRes = klfs.AggregatedKarhunenLoeveResults(list_kl_results)
# initialization of the function wrapper : 
FUNC = klfs.KarhunenLoeveGeneralizedFunctionWrapper(
                                AggregatedKarhunenLoeveResults = AggregatedKLRes,
                                func        = None, 
                                func_sample = g_mod,
                                n_outputs   = 1)
ot.RandomGenerator.SetSeed(111)
size = int(1e5)
experiment = klfs.KarhunenLoeveSobolIndicesExperiment(AggregatedKLRes, size, True)
sobolExp = experiment.generate()
response = FUNC(sobolExp)
sensitivityAnalysis = klfs.SobolKarhunenLoeveFieldSensitivityAlgorithm(computeSecondOrder=True)
sensitivityAnalysis.setDesign(sobolExp, response, size)
sensitivityAnalysis.setEstimator(ot.SaltelliSensitivityAlgorithm())
sensitivityAnalysis.__nSobolIndices__
sensitivityAnalysis.getFirstOrderIndices()
sensitivityAnalysis.getTotalOrderIndices()
display(sensitivityAnalysis.getSecondOrderIndices()[0])
X  = sensitivityAnalysis.__results__[0]
Q = X.getFirstOrderIndicesDistribution()
Q.getMarginal(1).computeBilateralConfidenceInterval(0.95)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10329595650696569, 'fraction_numerical': 0.02582398912674142, 'mean_word_length': 4.421731123388582, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '71480', 'license': 'MIT', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1001, 'n_words': 248, 'path': 'notebook/Research_paper_numerical_example.ipynb', 'repo_name': 'Kramer84/spsa', 'size': '2943'}