Conditional variable#
In this example, we will demonstrate how to define a conditional variable. This is a variable which parameters depend on a value of another variable.
First, let’s import the necessary packages:
[1]:
from probabilistic_library import DistributionType, ReliabilityMethod, ReliabilityProject, ConditionalValue
import matplotlib.pyplot as plt
Consider a variable \(h\) (kPa/m), which represents the pore water pressure in a clay layer of a levee. The variable follows a log-normal distribution, but its mean and standard deviation depend on the overtopping discharge \(q\) (l/s/m), which varies per day. We assume the following relationships between the overtopping discharge \(q\) and the mean and standard deviation of \(h\):
[2]:
q = [0, 0.1, 1.0, 10.0, 30.0, 50.0, 75.0]
mu = [0, 1.42, 2.24, 3.63, 6.53, 6.31, 6.48]
sigma = [0, 0.32, 1.10, 1.32, 1.70, 2.15, 2.65]
plt.plot(q, mu, '-o', label="mean of h")
plt.plot(q, sigma, '-o', label="deviation of h")
plt.grid()
plt.legend()
plt.xlabel("q (l/s/m)")
plt.ylabel("Values (kPa/m)")
[2]:
Text(0, 0.5, 'Values (kPa/m)')
Let’s assume that on a certain day the overtopping discharge \(q\) is normally distributed with a mean of \(50.0\) l/s/m and a standard deviation of \(1.0\) l/s/m. The goal is to find the probability that the pore water pressure \(h\) exceeds a level of \(8.0\) kPa/m:
\(\int P(h>8.0|q) \cdot f(q) dq\) and \(q \sim N(50.0, 1.0)\)
To compute this probability, we define the following limit state function, in which both \(h\) and \(q\) are included as inputs:
[3]:
def pore_water_pressue(q, h, level):
return level-h
Next, we define a reliability project that uses the above limit state function as its model:
[4]:
project = ReliabilityProject()
project.model = pore_water_pressue
Then, we define the variable \(q\) and the exceedance level:
[5]:
project.variables["q"].distribution = DistributionType.normal
project.variables["q"].mean = 50.0
project.variables["q"].deviation = 1.0
project.variables["level"].distribution = DistributionType.deterministic
project.variables["level"].mean = 8.0
The conditional variable \(h\) is defined as follows. It is necessary to specify the source of the variable - namely, the parameter \(q\) - and to define the relationship between the values of \(q\) and the parameters of \(h\). In the case of a conditional variable, the distribution parameters will be interpolated between the grid points. When extrapolating, the first and last points from the grid will be used.
[6]:
project.variables["h"].distribution = DistributionType.log_normal
project.variables["h"].mean = 0
project.variables["h"].deviation = 1
project.variables["h"].conditional = True
project.variables["h"].conditional_source = "q"
for ii in range(0, len(q)):
conditional = ConditionalValue()
conditional.x = q[ii]
conditional.mean = mu[ii]
conditional.deviation = sigma[ii]
project.variables["h"].conditional_values.append(conditional)
project.variables["h"].print()
project.variables["h"].plot()
Variable h:
distribution = log_normal
Definition:
conditional source = q
q = [0.0, 0.1, 1.0, 10.0, 30.0, 50.0, 75.0]
mean = [0.0, 1.42, 2.24, 3.63, 6.53, 6.31, 6.48]
deviation = [0.0, 0.32, 1.1, 1.32, 1.7, 2.15, 2.65]
We use the reliability method form and run the calculations.
[ ]:
project.settings.reliability_method = ReliabilityMethod.form
project.settings.relaxation_factor = 0.75
project.settings.maximum_iterations = 50
project.settings.epsilon_beta = 0.01
project.run()
The reliability results are as follows:
[8]:
project.design_point.print()
Reliability (FORM)
Reliability index = 0.8817
Probability of failure = 0.189
Convergence = 0.0053 (converged)
Model runs = 15
Alpha values:
q: alpha = -0.0069, x = 50.0061
h: alpha = -1.0, x = 7.9998
level: alpha = 0.0, x = 8.0
On a different day, when the distribution of \(q\) is normal with a mean of \(20.0\) and a standard deviation of \(1.5\), the probability that the pore water pressure exceeds \(8.0\) kPa/m becomes:
[9]:
project.variables["q"].distribution = DistributionType.normal
project.variables["q"].mean = 20.0
project.variables["q"].deviation = 1.5
project.run()
project.design_point.print()
Reliability (FORM)
Reliability index = 1.7774
Probability of failure = 0.0377
Convergence = 0.0043 (converged)
Model runs = 12
Alpha values:
q: alpha = -0.1078, x = 20.2873
h: alpha = -0.9942, x = 7.9998
level: alpha = 0.0, x = 8.0