Bivariate#
Test.
# thebe-remove-input-init
import micropip
await micropip.install("../packages/pyvinecopulib-0.6.5-cp311-cp311-emscripten_3_1_45_wasm32.whl", keep_going=True)
await micropip.install("bivariate", keep_going=True)
import bivariate
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pyvinecopulib as cop
import scipy.stats as st
# Define distributions
s = 0.198
loc = 0.000
scale = 98.058
Q_1 = st.lognorm(s=s, loc=loc, scale=scale) # Random Variable Q_1, lognormal distribution
Q_2 = st.lognorm(s=s, loc=loc, scale=scale) # Random Variable Q_2, lognormal distribution
# Generate random samples
n = 10000 # Number of samples
Q_1_samples = Q_1.rvs(size=n) # Generate n samples from scipy instance Q_1, defined in cell above
Q_2_samples = Q_2.rvs(size=n) # Generate n samples from scipy instance Q_2, defined in cell above
# Combine marginal sample lists into a combined list
Q_combined_samples = np.array([Q_1_samples, Q_2_samples]).T
# Create an instance of the Region_of_interest class, by assigning the combined samples as an attribute
# This allows to perform operation, such as plotting
Q_class_A = bivariate.class_copula.Region_of_interest(random_samples=Q_combined_samples)
# Plot the emperical contours of the random samples
Q_class_A.plot_emperical_contours(bandwidth=4)
# Define reliability analysis function
def maximum_discharge_function(X1,X2):
Q_max = 275.0
function = (X1 + X2 - Q_max >= 0)
return function
# Assign the function to the class instance
Q_class_A.function = maximum_discharge_function
# Run the function needed to check if the points are inside the region of interest
Q_class_A.inside_function()
# Plot the points inside the region of interest
Q_class_A.plot_inside_function();