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