File size: 6,336 Bytes
e933bd0
 
 
 
 
13b3d31
e933bd0
 
 
 
 
 
 
 
20c702f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7663b4
e933bd0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
726657d
 
 
e933bd0
726657d
 
 
 
 
e933bd0
726657d
 
 
 
 
 
e933bd0
a568849
e933bd0
a568849
e933bd0
 
 
 
a7663b4
 
 
 
e933bd0
13b3d31
 
 
 
 
 
e933bd0
005fc47
13b3d31
 
 
 
 
 
 
 
 
 
 
 
 
e734598
 
e2f352e
e734598
 
 
 
c2e6123
e734598
 
 
 
005fc47
 
 
 
 
 
 
e3e769d
005fc47
 
e3e769d
 
005fc47
e3e769d
a7663b4
 
 
 
 
 
e3e769d
a7663b4
 
 
 
13b3d31
c2e6123
 
 
 
 
005fc47
 
c2e6123
e3e769d
cbf836e
 
 
 
c3207d8
 
 
 
 
 
 
 
 
 
 
 
20ce2de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c3207d8
 
20ce2de
 
 
 
 
 
c3207d8
 
20ce2de
c3207d8
13b3d31
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# Import necessary libraries
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import norm
import plotly.graph_objects as go

# Define the functions from your code
def Phi(z):
    return norm.cdf(z)

def phi(z):
    return norm.pdf(z)

# Define the BCNOLLN CDF based on the provided formula
def F_BCNOLLN(y1, y2, mu1, sigma1, alpha1, beta1, mu2, sigma2, alpha2, beta2, lambd):
    # Convert y1, y2 to z-scores
    z1 = (y1 - mu1) / sigma1
    z2 = (y2 - mu2) / sigma2
    
    # Compute H functions
    H1_z1 = Phi(z1)**alpha1 + (1 - Phi(z1))**beta1
    H2_z2 = Phi(z2)**alpha2 + (1 - Phi(z2))**beta2
    
    # Compute the BCNOLLN CDF
    term1 = (Phi(z1)*alpha1 / H1_z1)**(-lambd)
    term2 = (Phi(z2)*alpha2 / H2_z2)**(-lambd)
    term = term1 + term2 - 1
    cdf = term**(-1/lambd)
    
    return cdf

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')

# Sidebar title and explanation
st.sidebar.title('Parameters')
st.sidebar.write('Adjust the parameters below to visualize the BCNOLLN distribution.')

# Input fields for parameters with sliders
mu1 = st.sidebar.slider('Mean μ1', min_value=-10.0, max_value=10.0, value=0.0, step=0.1)
sigma1 = st.sidebar.slider('Standard deviation σ1', min_value=0.1, max_value=10.0, value=1.0, step=0.1)
alpha1 = st.sidebar.slider('Alpha1 α1', min_value=0.0, max_value=1.0, value=0.2, step=0.01)
beta1 = st.sidebar.slider('Beta1 β1', min_value=0.0, max_value=1.0, value=0.2, step=0.01)

mu2 = st.sidebar.slider('Mean μ2', min_value=-10.0, max_value=10.0, value=0.0, step=0.1)
sigma2 = st.sidebar.slider('Standard deviation σ2', min_value=0.1, max_value=10.0, value=1.0, step=0.1)
alpha2 = st.sidebar.slider('Alpha2 α2', min_value=0.0, max_value=1.0, value=0.9, step=0.01)
beta2 = st.sidebar.slider('Beta2 β2', min_value=0.0, max_value=1.0, value=0.3, step=0.01)

lambd = st.sidebar.slider('Lambda λ', min_value=-1.0, max_value=1.0, value=-0.5, step=0.01)


# Generate y1 and y2 values
y1, y2 = np.meshgrid(np.linspace(-10, 10, 100), np.linspace(-10, 10, 100))

# Calculate PDF values
pdf_values = f_BCNOLLN(y1, y2, mu1, sigma1, alpha1, beta1, mu2, sigma2, alpha2, beta2, lambd)

# Calculate CDF values
cdf_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.subheader('Results for PDF Plot')

# Create a 3D contour plot with Plotly
fig = go.Figure(data=[go.Surface(z=pdf_values, x=y1, y=y2, colorscale='Viridis')])
fig.update_layout(title='BCNOLLN PDF 3D Contour Plot', autosize=True,
                  scene=dict(
                      xaxis_title='y1',
                      yaxis_title='y2',
                      zaxis_title='PDF'
                  ))

# Display the plot in Streamlit
st.plotly_chart(fig)

# Create the contour plot
fig, ax = plt.subplots()
contours = ax.contour(y1, y2, pdf_values, levels=20)
ax.clabel(contours, inline=True, fontsize=8, fmt='%.3f')  # Add labels to the contours

ax.set_xlabel('y1')
ax.set_ylabel('y2')
ax.set_title('BCEOLLN PDF Distribution Contour Plot')

# Display the plot in Streamlit
st.pyplot(fig)

# Create a 2D contour plot for PDF using Matplotlib
fig_2d, ax = plt.subplots()
cp = ax.contourf(y1, y2, pdf_values, cmap='viridis')
fig_2d.colorbar(cp)
ax.set_title('BCNOLLN PDF 2D Contour Plot')
ax.set_xlabel('y1')
ax.set_ylabel('y2')

# Display the PDF plot in Streamlit using Matplotlib
st.pyplot(fig_2d)


st.subheader('Results for CDF Plot')

# Create a 3D contour plot with Plotly
fig = go.Figure(data=[go.Surface(z=cdf_values, x=y1, y=y2, colorscale='Viridis')])
fig.update_layout(title='BCNOLLN CDF 3D Contour Plot', autosize=True,
                  scene=dict(
                      xaxis_title='y1',
                      yaxis_title='y2',
                      zaxis_title='CDF'
                  ))

# Display the plot in Streamlit
st.plotly_chart(fig)

# Create the contour plot
fig, ax = plt.subplots()
contours = ax.contour(y1, y2, cdf_values, levels=20)
ax.clabel(contours, inline=True, fontsize=8, fmt='%.3f')  # Add labels to the contours

ax.set_xlabel('y1')
ax.set_ylabel('y2')
ax.set_title('BCEOLLN CDF Distribution Contour Plot')

# Display the plot in Streamlit
st.pyplot(fig)


# Create a 2D contour plot for PDF using Matplotlib
fig_2d, ax = plt.subplots()
cp = ax.contourf(y1, y2, cdf_values, cmap='viridis')
fig_2d.colorbar(cp)
ax.set_title('BCNOLLN CDF 2D Contour Plot')
ax.set_xlabel('y1')
ax.set_ylabel('y2')

# Display the PDF plot in Streamlit using Matplotlib
st.pyplot(fig_2d)

# Create a Plotly figure for the 2D contour plot
#fig_2d_plotly = go.Figure(data=
#    go.Contour(
#        z=cdf_values, 
#        x=y1,  # Corresponds to Y1's axis values
#        y=y2,  # Corresponds to Y2's axis values
#        colorscale='Viridis',
#        contours=dict(
#            coloring ='heatmap',  # Use 'heatmap' for a filled contour plot
#            showlabels = True,  # Show labels on contours
#            labelfont = dict(  # Label font properties
#                size = 12,
#                color = 'white',
#            ),
#        )
#    )
#)

# Update layout of the figure
#fig_2d_plotly.update_layout(
#    title='BCNOLLN CDF 2D Contour Plot',
#    xaxis_title='y1',
#    yaxis_title='y2',
#    autosize=True,
#)

# Display the plot in Streamlit
#st.plotly_chart(fig_2d_plotly)

#st.pyplot(fig)