File size: 2,255 Bytes
e933bd0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# Import necessary libraries
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
# Define the functions from your code
def Phi(z):
return norm.cdf(z)
def phi(z):
return norm.pdf(z)
def f_BCNOLLN(y1, y2, mu1, sigma1, alpha1, beta1, mu2, sigma2, alpha2, beta2, lambd):
z1 = (y1 - mu1) / sigma1
z2 = (y2 - mu2) / sigma2
H1_z1 = Phi(z1)**alpha1 + (1 - Phi(z1))**beta1
H2_z2 = Phi(z2)**alpha2 + (1 - Phi(z2))**beta2
term1 = (Phi(z1)**alpha1 / H1_z1)**(-lambd)
term2 = (Phi(z2)**alpha2 / H2_z2)**(-lambd)
common_term = (term1 + term2 - 1)**(-(2*lambd + 1)/lambd)
factor1 = (phi(z1) * Phi(z1)**(alpha1 - 1) * (1 - Phi(z1))**(beta1 - 1) *
(alpha1 + (beta1 - alpha1) * Phi(z1))) / (sigma1 * H1_z1**2)
factor2 = (phi(z2) * Phi(z2)**(alpha2 - 1) * (1 - Phi(z2))**(beta2 - 1) *
(alpha2 + (beta2 - alpha2) * Phi(z2))) / (sigma2 * H2_z2**2)
pdf = (lambd + 1) * common_term * (factor1 * factor2)
return pdf
# Streamlit app
st.title('BCNOLLN Distribution Visualizer')
# Input fields for parameters
mu1 = st.sidebar.number_input('Mean μ1', value=0.0)
sigma1 = st.sidebar.number_input('Standard deviation σ1', value=1.0, min_value=0.1)
alpha1 = st.sidebar.number_input('Alpha1 α1', value=0.2, min_value=0.0, max_value=1.0)
beta1 = st.sidebar.number_input('Beta1 β1', value=0.2, min_value=0.0, max_value=1.0)
mu2 = st.sidebar.number_input('Mean μ2', value=0.0)
sigma2 = st.sidebar.number_input('Standard deviation σ2', value=1.0, min_value=0.1)
alpha2 = st.sidebar.number_input('Alpha2 α2', value=0.9, min_value=0.0, max_value=1.0)
beta2 = st.sidebar.number_input('Beta2 β2', value=0.3, min_value=0.0, max_value=1.0)
lambd = st.sidebar.number_input('Lambda λ', value=-0.5)
# Generate y1 and y2 values
y1, y2 = np.meshgrid(np.linspace(-3, 3, 100), np.linspace(-3, 3, 100))
# Calculate PDF values
pdf_values = f_BCNOLLN(y1, y2, mu1, sigma1, alpha1, beta1, mu2, sigma2, alpha2, beta2, lambd)
# Plotting
fig, ax = plt.subplots()
cp = ax.contourf(y1, y2, pdf_values, cmap='viridis')
fig.colorbar(cp)
ax.set_title('BCNOLLN PDF Contour Plot')
ax.set_xlabel('y1')
ax.set_ylabel('y2')
st.pyplot(fig)
|