Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,12 +14,12 @@ import tempfile
|
|
| 14 |
import platform
|
| 15 |
from sympy import symbols, solve, I, re, im, Poly, simplify, N
|
| 16 |
import mpmath
|
| 17 |
-
import scipy
|
| 18 |
|
| 19 |
# Set page config with wider layout
|
| 20 |
st.set_page_config(
|
| 21 |
page_title="Matrix Analysis Dashboard",
|
| 22 |
-
page_icon="
|
| 23 |
layout="wide",
|
| 24 |
initial_sidebar_state="expanded"
|
| 25 |
)
|
|
@@ -390,7 +390,7 @@ CubicRoots solveCubic(double a, double b, double c, double d) {
|
|
| 390 |
}
|
| 391 |
|
| 392 |
if (std::abs(delta0) < zero_threshold) {
|
| 393 |
-
// Delta0
|
| 394 |
double simple = std::cbrt(-delta1);
|
| 395 |
double doubleRoot = -simple/2 - shift;
|
| 396 |
double simpleRoot = simple - shift;
|
|
@@ -718,21 +718,21 @@ bool eigenvalueAnalysis(int n, int p, double a, double y, int fineness,
|
|
| 718 |
<< ", theory_tolerance = " << theory_tolerance << std::endl;
|
| 719 |
std::cout << "Output will be saved to: " << output_file << std::endl;
|
| 720 |
|
| 721 |
-
//
|
| 722 |
const int num_beta_points = fineness; // Controlled by fineness parameter
|
| 723 |
std::vector<double> beta_values(num_beta_points);
|
| 724 |
for (int i = 0; i < num_beta_points; ++i) {
|
| 725 |
beta_values[i] = static_cast<double>(i) / (num_beta_points - 1);
|
| 726 |
}
|
| 727 |
|
| 728 |
-
//
|
| 729 |
std::vector<double> max_eigenvalues(num_beta_points);
|
| 730 |
std::vector<double> min_eigenvalues(num_beta_points);
|
| 731 |
std::vector<double> theoretical_max_values(num_beta_points);
|
| 732 |
std::vector<double> theoretical_min_values(num_beta_points);
|
| 733 |
|
| 734 |
try {
|
| 735 |
-
//
|
| 736 |
std::random_device rd;
|
| 737 |
std::mt19937_64 rng{rd()};
|
| 738 |
std::normal_distribution<double> norm(0.0, 1.0);
|
|
@@ -742,7 +742,7 @@ bool eigenvalueAnalysis(int n, int p, double a, double y, int fineness,
|
|
| 742 |
for(int j = 0; j < n; ++j)
|
| 743 |
X.at<double>(i,j) = norm(rng);
|
| 744 |
|
| 745 |
-
//
|
| 746 |
for (int beta_idx = 0; beta_idx < num_beta_points; ++beta_idx) {
|
| 747 |
double beta = beta_values[beta_idx];
|
| 748 |
|
|
@@ -750,7 +750,7 @@ bool eigenvalueAnalysis(int n, int p, double a, double y, int fineness,
|
|
| 750 |
theoretical_max_values[beta_idx] = compute_theoretical_max(a, y, beta, theory_grid_points, theory_tolerance);
|
| 751 |
theoretical_min_values[beta_idx] = compute_theoretical_min(a, y, beta, theory_grid_points, theory_tolerance);
|
| 752 |
|
| 753 |
-
//
|
| 754 |
int k = static_cast<int>(std::floor(beta * p));
|
| 755 |
std::vector<double> diags(p, 1.0);
|
| 756 |
std::fill_n(diags.begin(), k, a);
|
|
@@ -761,10 +761,10 @@ bool eigenvalueAnalysis(int n, int p, double a, double y, int fineness,
|
|
| 761 |
T_n.at<double>(i,i) = diags[i];
|
| 762 |
}
|
| 763 |
|
| 764 |
-
//
|
| 765 |
cv::Mat B = (X.t() * T_n * X) / static_cast<double>(n);
|
| 766 |
|
| 767 |
-
//
|
| 768 |
cv::Mat eigVals;
|
| 769 |
cv::eigen(B, eigVals);
|
| 770 |
std::vector<double> eigs(n);
|
|
@@ -822,7 +822,7 @@ int main(int argc, char* argv[]) {
|
|
| 822 |
|
| 823 |
try {
|
| 824 |
if (mode == "eigenvalues") {
|
| 825 |
-
//
|
| 826 |
if (argc != 10) {
|
| 827 |
std::cerr << "Error: Incorrect number of arguments for eigenvalues mode." << std::endl;
|
| 828 |
std::cerr << "Usage: " << argv[0] << " eigenvalues <n> <p> <a> <y> <fineness> <theory_grid_points> <theory_tolerance> <output_file>" << std::endl;
|
|
@@ -859,7 +859,7 @@ int main(int argc, char* argv[]) {
|
|
| 859 |
|
| 860 |
# Compile the C++ code with the right OpenCV libraries
|
| 861 |
st.sidebar.title("Dashboard Settings")
|
| 862 |
-
need_compile = not os.path.exists(executable) or st.sidebar.button("
|
| 863 |
|
| 864 |
if need_compile:
|
| 865 |
with st.sidebar:
|
|
@@ -893,11 +893,11 @@ if need_compile:
|
|
| 893 |
|
| 894 |
if success:
|
| 895 |
compiled = True
|
| 896 |
-
st.success(f"
|
| 897 |
break
|
| 898 |
|
| 899 |
if not compiled:
|
| 900 |
-
st.error("
|
| 901 |
with st.expander("Compilation Details"):
|
| 902 |
st.code(compile_output)
|
| 903 |
st.stop()
|
|
@@ -906,7 +906,7 @@ if need_compile:
|
|
| 906 |
if platform.system() != "Windows":
|
| 907 |
os.chmod(executable, 0o755)
|
| 908 |
|
| 909 |
-
st.success("
|
| 910 |
|
| 911 |
# Set higher precision for mpmath
|
| 912 |
mpmath.mp.dps = 100 # 100 digits of precision
|
|
@@ -1044,7 +1044,7 @@ def compute_ImS_vs_Z(a, y, beta, num_points, z_min, z_max, progress_callback=Non
|
|
| 1044 |
progress_callback(i / num_points)
|
| 1045 |
|
| 1046 |
# Coefficients for the cubic equation:
|
| 1047 |
-
#
|
| 1048 |
coef_a = z * a
|
| 1049 |
coef_b = z * (a + 1) + a * (1 - y)
|
| 1050 |
coef_c = z + (a + 1) - y - y * beta * (a - 1)
|
|
@@ -1118,8 +1118,8 @@ def create_dash_style_visualization(result, cubic_a, cubic_y, cubic_beta):
|
|
| 1118 |
rows=2,
|
| 1119 |
cols=1,
|
| 1120 |
subplot_titles=(
|
| 1121 |
-
f"Imaginary Parts of Roots: a={cubic_a}, y={cubic_y},
|
| 1122 |
-
f"Real Parts of Roots: a={cubic_a}, y={cubic_y},
|
| 1123 |
),
|
| 1124 |
vertical_spacing=0.15,
|
| 1125 |
specs=[[{"type": "scatter"}], [{"type": "scatter"}]]
|
|
@@ -1131,9 +1131,9 @@ def create_dash_style_visualization(result, cubic_a, cubic_y, cubic_beta):
|
|
| 1131 |
x=z_values,
|
| 1132 |
y=ims_values1,
|
| 1133 |
mode='lines',
|
| 1134 |
-
name='Im(
|
| 1135 |
line=dict(color='rgb(239, 85, 59)', width=2.5),
|
| 1136 |
-
hovertemplate='z: %{x:.4f}<br>Im(
|
| 1137 |
),
|
| 1138 |
row=1, col=1
|
| 1139 |
)
|
|
@@ -1143,9 +1143,9 @@ def create_dash_style_visualization(result, cubic_a, cubic_y, cubic_beta):
|
|
| 1143 |
x=z_values,
|
| 1144 |
y=ims_values2,
|
| 1145 |
mode='lines',
|
| 1146 |
-
name='Im(
|
| 1147 |
line=dict(color='rgb(0, 129, 201)', width=2.5),
|
| 1148 |
-
hovertemplate='z: %{x:.4f}<br>Im(
|
| 1149 |
),
|
| 1150 |
row=1, col=1
|
| 1151 |
)
|
|
@@ -1155,9 +1155,9 @@ def create_dash_style_visualization(result, cubic_a, cubic_y, cubic_beta):
|
|
| 1155 |
x=z_values,
|
| 1156 |
y=ims_values3,
|
| 1157 |
mode='lines',
|
| 1158 |
-
name='Im(
|
| 1159 |
line=dict(color='rgb(0, 176, 80)', width=2.5),
|
| 1160 |
-
hovertemplate='z: %{x:.4f}<br>Im(
|
| 1161 |
),
|
| 1162 |
row=1, col=1
|
| 1163 |
)
|
|
@@ -1168,9 +1168,9 @@ def create_dash_style_visualization(result, cubic_a, cubic_y, cubic_beta):
|
|
| 1168 |
x=z_values,
|
| 1169 |
y=real_values1,
|
| 1170 |
mode='lines',
|
| 1171 |
-
name='Re(
|
| 1172 |
line=dict(color='rgb(239, 85, 59)', width=2.5),
|
| 1173 |
-
hovertemplate='z: %{x:.4f}<br>Re(
|
| 1174 |
),
|
| 1175 |
row=2, col=1
|
| 1176 |
)
|
|
@@ -1180,9 +1180,9 @@ def create_dash_style_visualization(result, cubic_a, cubic_y, cubic_beta):
|
|
| 1180 |
x=z_values,
|
| 1181 |
y=real_values2,
|
| 1182 |
mode='lines',
|
| 1183 |
-
name='Re(
|
| 1184 |
line=dict(color='rgb(0, 129, 201)', width=2.5),
|
| 1185 |
-
hovertemplate='z: %{x:.4f}<br>Re(
|
| 1186 |
),
|
| 1187 |
row=2, col=1
|
| 1188 |
)
|
|
@@ -1192,9 +1192,9 @@ def create_dash_style_visualization(result, cubic_a, cubic_y, cubic_beta):
|
|
| 1192 |
x=z_values,
|
| 1193 |
y=real_values3,
|
| 1194 |
mode='lines',
|
| 1195 |
-
name='Re(
|
| 1196 |
line=dict(color='rgb(0, 176, 80)', width=2.5),
|
| 1197 |
-
hovertemplate='z: %{x:.4f}<br>Re(
|
| 1198 |
),
|
| 1199 |
row=2, col=1
|
| 1200 |
)
|
|
@@ -1484,7 +1484,7 @@ def create_complex_plane_visualization(result, z_idx):
|
|
| 1484 |
symbol='circle',
|
| 1485 |
line=dict(width=1, color='black')
|
| 1486 |
),
|
| 1487 |
-
text=['
|
| 1488 |
textposition="top center",
|
| 1489 |
name='Roots'
|
| 1490 |
))
|
|
@@ -1616,7 +1616,7 @@ with st.sidebar.expander("Theme & Appearance"):
|
|
| 1616 |
color_theory_min = 'rgb(180, 30, 180)'
|
| 1617 |
|
| 1618 |
# Create tabs for different analyses
|
| 1619 |
-
tab1, tab2 = st.tabs(["
|
| 1620 |
|
| 1621 |
# Tab 1: Eigenvalue Analysis (KEEP UNCHANGED from original)
|
| 1622 |
with tab1:
|
|
@@ -1650,7 +1650,7 @@ with tab1:
|
|
| 1650 |
max_value=500,
|
| 1651 |
value=100,
|
| 1652 |
step=10,
|
| 1653 |
-
help="Number of points to calculate along the
|
| 1654 |
key="eig_fineness"
|
| 1655 |
)
|
| 1656 |
st.markdown('</div>', unsafe_allow_html=True)
|
|
@@ -1833,7 +1833,7 @@ with tab1:
|
|
| 1833 |
color=color_max,
|
| 1834 |
line=dict(color='white', width=1)
|
| 1835 |
),
|
| 1836 |
-
hovertemplate='
|
| 1837 |
))
|
| 1838 |
|
| 1839 |
fig.add_trace(go.Scatter(
|
|
@@ -1848,7 +1848,7 @@ with tab1:
|
|
| 1848 |
color=color_min,
|
| 1849 |
line=dict(color='white', width=1)
|
| 1850 |
),
|
| 1851 |
-
hovertemplate='
|
| 1852 |
))
|
| 1853 |
|
| 1854 |
fig.add_trace(go.Scatter(
|
|
@@ -1863,7 +1863,7 @@ with tab1:
|
|
| 1863 |
color=color_theory_max,
|
| 1864 |
line=dict(color='white', width=1)
|
| 1865 |
),
|
| 1866 |
-
hovertemplate='
|
| 1867 |
))
|
| 1868 |
|
| 1869 |
fig.add_trace(go.Scatter(
|
|
@@ -1878,7 +1878,7 @@ with tab1:
|
|
| 1878 |
color=color_theory_min,
|
| 1879 |
line=dict(color='white', width=1)
|
| 1880 |
),
|
| 1881 |
-
hovertemplate='
|
| 1882 |
))
|
| 1883 |
|
| 1884 |
# Configure layout for better appearance
|
|
@@ -1892,7 +1892,7 @@ with tab1:
|
|
| 1892 |
'yanchor': 'top'
|
| 1893 |
},
|
| 1894 |
xaxis={
|
| 1895 |
-
'title': {'text': '
|
| 1896 |
'tickfont': {'size': 14},
|
| 1897 |
'gridcolor': 'rgba(220, 220, 220, 0.5)',
|
| 1898 |
'showgrid': True
|
|
@@ -1988,7 +1988,7 @@ with tab1:
|
|
| 1988 |
color=color_max,
|
| 1989 |
line=dict(color='white', width=1)
|
| 1990 |
),
|
| 1991 |
-
hovertemplate='
|
| 1992 |
))
|
| 1993 |
|
| 1994 |
fig.add_trace(go.Scatter(
|
|
@@ -2003,7 +2003,7 @@ with tab1:
|
|
| 2003 |
color=color_min,
|
| 2004 |
line=dict(color='white', width=1)
|
| 2005 |
),
|
| 2006 |
-
hovertemplate='
|
| 2007 |
))
|
| 2008 |
|
| 2009 |
fig.add_trace(go.Scatter(
|
|
@@ -2018,7 +2018,7 @@ with tab1:
|
|
| 2018 |
color=color_theory_max,
|
| 2019 |
line=dict(color='white', width=1)
|
| 2020 |
),
|
| 2021 |
-
hovertemplate='
|
| 2022 |
))
|
| 2023 |
|
| 2024 |
fig.add_trace(go.Scatter(
|
|
@@ -2033,7 +2033,7 @@ with tab1:
|
|
| 2033 |
color=color_theory_min,
|
| 2034 |
line=dict(color='white', width=1)
|
| 2035 |
),
|
| 2036 |
-
hovertemplate='
|
| 2037 |
))
|
| 2038 |
|
| 2039 |
# Configure layout for better appearance
|
|
@@ -2047,7 +2047,7 @@ with tab1:
|
|
| 2047 |
'yanchor': 'top'
|
| 2048 |
},
|
| 2049 |
xaxis={
|
| 2050 |
-
'title': {'text': '
|
| 2051 |
'tickfont': {'size': 14},
|
| 2052 |
'gridcolor': 'rgba(220, 220, 220, 0.5)',
|
| 2053 |
'showgrid': True
|
|
@@ -2076,10 +2076,10 @@ with tab1:
|
|
| 2076 |
st.info("This is the previous analysis result. Adjust parameters and click 'Generate Analysis' to create a new visualization.")
|
| 2077 |
|
| 2078 |
except Exception as e:
|
| 2079 |
-
st.info("
|
| 2080 |
else:
|
| 2081 |
# Show placeholder
|
| 2082 |
-
st.info("
|
| 2083 |
|
| 2084 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 2085 |
|
|
@@ -2099,7 +2099,7 @@ with tab2:
|
|
| 2099 |
help="Parameter a > 1", key="cubic_a")
|
| 2100 |
cubic_y = st.number_input("Value for y", min_value=0.1, max_value=10.0, value=1.0, step=0.1,
|
| 2101 |
help="Parameter y > 0", key="cubic_y")
|
| 2102 |
-
cubic_beta = st.number_input("Value for
|
| 2103 |
help="Value between 0 and 1", key="cubic_beta")
|
| 2104 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 2105 |
|
|
@@ -2304,16 +2304,17 @@ with tab2:
|
|
| 2304 |
help="Select a specific z value to visualize its roots in the complex plane"
|
| 2305 |
)
|
| 2306 |
|
| 2307 |
-
|
|
|
|
| 2308 |
complex_fig = create_complex_plane_visualization(result, z_idx)
|
| 2309 |
st.plotly_chart(complex_fig, use_container_width=True)
|
| 2310 |
|
| 2311 |
except Exception as e:
|
| 2312 |
-
st.info("
|
| 2313 |
st.error(f"Error loading previous data: {str(e)}")
|
| 2314 |
else:
|
| 2315 |
# Show placeholder
|
| 2316 |
-
st.info("
|
| 2317 |
|
| 2318 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 2319 |
|
|
|
|
| 14 |
import platform
|
| 15 |
from sympy import symbols, solve, I, re, im, Poly, simplify, N
|
| 16 |
import mpmath
|
| 17 |
+
import scipy
|
| 18 |
|
| 19 |
# Set page config with wider layout
|
| 20 |
st.set_page_config(
|
| 21 |
page_title="Matrix Analysis Dashboard",
|
| 22 |
+
page_icon="ðÂÂÂ",
|
| 23 |
layout="wide",
|
| 24 |
initial_sidebar_state="expanded"
|
| 25 |
)
|
|
|
|
| 390 |
}
|
| 391 |
|
| 392 |
if (std::abs(delta0) < zero_threshold) {
|
| 393 |
+
// Delta0 â 0: One double root and one simple root
|
| 394 |
double simple = std::cbrt(-delta1);
|
| 395 |
double doubleRoot = -simple/2 - shift;
|
| 396 |
double simpleRoot = simple - shift;
|
|
|
|
| 718 |
<< ", theory_tolerance = " << theory_tolerance << std::endl;
|
| 719 |
std::cout << "Output will be saved to: " << output_file << std::endl;
|
| 720 |
|
| 721 |
+
// âÂÂâÂÂâ Beta range parameters âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
|
| 722 |
const int num_beta_points = fineness; // Controlled by fineness parameter
|
| 723 |
std::vector<double> beta_values(num_beta_points);
|
| 724 |
for (int i = 0; i < num_beta_points; ++i) {
|
| 725 |
beta_values[i] = static_cast<double>(i) / (num_beta_points - 1);
|
| 726 |
}
|
| 727 |
|
| 728 |
+
// âÂÂâÂÂâ Storage for results âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
|
| 729 |
std::vector<double> max_eigenvalues(num_beta_points);
|
| 730 |
std::vector<double> min_eigenvalues(num_beta_points);
|
| 731 |
std::vector<double> theoretical_max_values(num_beta_points);
|
| 732 |
std::vector<double> theoretical_min_values(num_beta_points);
|
| 733 |
|
| 734 |
try {
|
| 735 |
+
// âÂÂâÂÂâ RandomâÂÂGaussian X and S_n âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
|
| 736 |
std::random_device rd;
|
| 737 |
std::mt19937_64 rng{rd()};
|
| 738 |
std::normal_distribution<double> norm(0.0, 1.0);
|
|
|
|
| 742 |
for(int j = 0; j < n; ++j)
|
| 743 |
X.at<double>(i,j) = norm(rng);
|
| 744 |
|
| 745 |
+
// âÂÂâÂÂâ Process each beta value âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
|
| 746 |
for (int beta_idx = 0; beta_idx < num_beta_points; ++beta_idx) {
|
| 747 |
double beta = beta_values[beta_idx];
|
| 748 |
|
|
|
|
| 750 |
theoretical_max_values[beta_idx] = compute_theoretical_max(a, y, beta, theory_grid_points, theory_tolerance);
|
| 751 |
theoretical_min_values[beta_idx] = compute_theoretical_min(a, y, beta, theory_grid_points, theory_tolerance);
|
| 752 |
|
| 753 |
+
// âÂÂâÂÂâ Build T_n matrix âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
|
| 754 |
int k = static_cast<int>(std::floor(beta * p));
|
| 755 |
std::vector<double> diags(p, 1.0);
|
| 756 |
std::fill_n(diags.begin(), k, a);
|
|
|
|
| 761 |
T_n.at<double>(i,i) = diags[i];
|
| 762 |
}
|
| 763 |
|
| 764 |
+
// âÂÂâÂÂâ Form B_n = (1/n) * X * T_n * X^T âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
|
| 765 |
cv::Mat B = (X.t() * T_n * X) / static_cast<double>(n);
|
| 766 |
|
| 767 |
+
// âÂÂâÂÂâ Compute eigenvalues of B âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
|
| 768 |
cv::Mat eigVals;
|
| 769 |
cv::eigen(B, eigVals);
|
| 770 |
std::vector<double> eigs(n);
|
|
|
|
| 822 |
|
| 823 |
try {
|
| 824 |
if (mode == "eigenvalues") {
|
| 825 |
+
// âÂÂâÂÂâ Eigenvalue analysis mode âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ
|
| 826 |
if (argc != 10) {
|
| 827 |
std::cerr << "Error: Incorrect number of arguments for eigenvalues mode." << std::endl;
|
| 828 |
std::cerr << "Usage: " << argv[0] << " eigenvalues <n> <p> <a> <y> <fineness> <theory_grid_points> <theory_tolerance> <output_file>" << std::endl;
|
|
|
|
| 859 |
|
| 860 |
# Compile the C++ code with the right OpenCV libraries
|
| 861 |
st.sidebar.title("Dashboard Settings")
|
| 862 |
+
need_compile = not os.path.exists(executable) or st.sidebar.button("ð Recompile C++ Code")
|
| 863 |
|
| 864 |
if need_compile:
|
| 865 |
with st.sidebar:
|
|
|
|
| 893 |
|
| 894 |
if success:
|
| 895 |
compiled = True
|
| 896 |
+
st.success(f"âÂÂ
Successfully compiled with: {cmd}")
|
| 897 |
break
|
| 898 |
|
| 899 |
if not compiled:
|
| 900 |
+
st.error("â All compilation attempts failed.")
|
| 901 |
with st.expander("Compilation Details"):
|
| 902 |
st.code(compile_output)
|
| 903 |
st.stop()
|
|
|
|
| 906 |
if platform.system() != "Windows":
|
| 907 |
os.chmod(executable, 0o755)
|
| 908 |
|
| 909 |
+
st.success("âÂÂ
C++ code compiled successfully!")
|
| 910 |
|
| 911 |
# Set higher precision for mpmath
|
| 912 |
mpmath.mp.dps = 100 # 100 digits of precision
|
|
|
|
| 1044 |
progress_callback(i / num_points)
|
| 1045 |
|
| 1046 |
# Coefficients for the cubic equation:
|
| 1047 |
+
# zasó + [z(a+1)+a(1-y)]sò + [z+(a+1)-y-yò(a-1)]s + 1 = 0
|
| 1048 |
coef_a = z * a
|
| 1049 |
coef_b = z * (a + 1) + a * (1 - y)
|
| 1050 |
coef_c = z + (a + 1) - y - y * beta * (a - 1)
|
|
|
|
| 1118 |
rows=2,
|
| 1119 |
cols=1,
|
| 1120 |
subplot_titles=(
|
| 1121 |
+
f"Imaginary Parts of Roots: a={cubic_a}, y={cubic_y}, ò={cubic_beta}",
|
| 1122 |
+
f"Real Parts of Roots: a={cubic_a}, y={cubic_y}, ò={cubic_beta}"
|
| 1123 |
),
|
| 1124 |
vertical_spacing=0.15,
|
| 1125 |
specs=[[{"type": "scatter"}], [{"type": "scatter"}]]
|
|
|
|
| 1131 |
x=z_values,
|
| 1132 |
y=ims_values1,
|
| 1133 |
mode='lines',
|
| 1134 |
+
name='Im(sâÂÂ)',
|
| 1135 |
line=dict(color='rgb(239, 85, 59)', width=2.5),
|
| 1136 |
+
hovertemplate='z: %{x:.4f}<br>Im(sâÂÂ): %{y:.6f}<extra>Root 1</extra>'
|
| 1137 |
),
|
| 1138 |
row=1, col=1
|
| 1139 |
)
|
|
|
|
| 1143 |
x=z_values,
|
| 1144 |
y=ims_values2,
|
| 1145 |
mode='lines',
|
| 1146 |
+
name='Im(sâÂÂ)',
|
| 1147 |
line=dict(color='rgb(0, 129, 201)', width=2.5),
|
| 1148 |
+
hovertemplate='z: %{x:.4f}<br>Im(sâÂÂ): %{y:.6f}<extra>Root 2</extra>'
|
| 1149 |
),
|
| 1150 |
row=1, col=1
|
| 1151 |
)
|
|
|
|
| 1155 |
x=z_values,
|
| 1156 |
y=ims_values3,
|
| 1157 |
mode='lines',
|
| 1158 |
+
name='Im(sâÂÂ)',
|
| 1159 |
line=dict(color='rgb(0, 176, 80)', width=2.5),
|
| 1160 |
+
hovertemplate='z: %{x:.4f}<br>Im(sâÂÂ): %{y:.6f}<extra>Root 3</extra>'
|
| 1161 |
),
|
| 1162 |
row=1, col=1
|
| 1163 |
)
|
|
|
|
| 1168 |
x=z_values,
|
| 1169 |
y=real_values1,
|
| 1170 |
mode='lines',
|
| 1171 |
+
name='Re(sâÂÂ)',
|
| 1172 |
line=dict(color='rgb(239, 85, 59)', width=2.5),
|
| 1173 |
+
hovertemplate='z: %{x:.4f}<br>Re(sâÂÂ): %{y:.6f}<extra>Root 1</extra>'
|
| 1174 |
),
|
| 1175 |
row=2, col=1
|
| 1176 |
)
|
|
|
|
| 1180 |
x=z_values,
|
| 1181 |
y=real_values2,
|
| 1182 |
mode='lines',
|
| 1183 |
+
name='Re(sâÂÂ)',
|
| 1184 |
line=dict(color='rgb(0, 129, 201)', width=2.5),
|
| 1185 |
+
hovertemplate='z: %{x:.4f}<br>Re(sâÂÂ): %{y:.6f}<extra>Root 2</extra>'
|
| 1186 |
),
|
| 1187 |
row=2, col=1
|
| 1188 |
)
|
|
|
|
| 1192 |
x=z_values,
|
| 1193 |
y=real_values3,
|
| 1194 |
mode='lines',
|
| 1195 |
+
name='Re(sâÂÂ)',
|
| 1196 |
line=dict(color='rgb(0, 176, 80)', width=2.5),
|
| 1197 |
+
hovertemplate='z: %{x:.4f}<br>Re(sâÂÂ): %{y:.6f}<extra>Root 3</extra>'
|
| 1198 |
),
|
| 1199 |
row=2, col=1
|
| 1200 |
)
|
|
|
|
| 1484 |
symbol='circle',
|
| 1485 |
line=dict(width=1, color='black')
|
| 1486 |
),
|
| 1487 |
+
text=['sâÂÂ', 'sâÂÂ', 'sâÂÂ'],
|
| 1488 |
textposition="top center",
|
| 1489 |
name='Roots'
|
| 1490 |
))
|
|
|
|
| 1616 |
color_theory_min = 'rgb(180, 30, 180)'
|
| 1617 |
|
| 1618 |
# Create tabs for different analyses
|
| 1619 |
+
tab1, tab2 = st.tabs(["ð Eigenvalue Analysis (C++)", "ð Im(s) vs z Analysis (SymPy)"])
|
| 1620 |
|
| 1621 |
# Tab 1: Eigenvalue Analysis (KEEP UNCHANGED from original)
|
| 1622 |
with tab1:
|
|
|
|
| 1650 |
max_value=500,
|
| 1651 |
value=100,
|
| 1652 |
step=10,
|
| 1653 |
+
help="Number of points to calculate along the ò axis (0 to 1)",
|
| 1654 |
key="eig_fineness"
|
| 1655 |
)
|
| 1656 |
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
|
| 1833 |
color=color_max,
|
| 1834 |
line=dict(color='white', width=1)
|
| 1835 |
),
|
| 1836 |
+
hovertemplate='ò: %{x:.3f}<br>Value: %{y:.6f}<extra>Empirical Max</extra>'
|
| 1837 |
))
|
| 1838 |
|
| 1839 |
fig.add_trace(go.Scatter(
|
|
|
|
| 1848 |
color=color_min,
|
| 1849 |
line=dict(color='white', width=1)
|
| 1850 |
),
|
| 1851 |
+
hovertemplate='ò: %{x:.3f}<br>Value: %{y:.6f}<extra>Empirical Min</extra>'
|
| 1852 |
))
|
| 1853 |
|
| 1854 |
fig.add_trace(go.Scatter(
|
|
|
|
| 1863 |
color=color_theory_max,
|
| 1864 |
line=dict(color='white', width=1)
|
| 1865 |
),
|
| 1866 |
+
hovertemplate='ò: %{x:.3f}<br>Value: %{y:.6f}<extra>Theoretical Max</extra>'
|
| 1867 |
))
|
| 1868 |
|
| 1869 |
fig.add_trace(go.Scatter(
|
|
|
|
| 1878 |
color=color_theory_min,
|
| 1879 |
line=dict(color='white', width=1)
|
| 1880 |
),
|
| 1881 |
+
hovertemplate='ò: %{x:.3f}<br>Value: %{y:.6f}<extra>Theoretical Min</extra>'
|
| 1882 |
))
|
| 1883 |
|
| 1884 |
# Configure layout for better appearance
|
|
|
|
| 1892 |
'yanchor': 'top'
|
| 1893 |
},
|
| 1894 |
xaxis={
|
| 1895 |
+
'title': {'text': 'ò Parameter', 'font': {'size': 18, 'color': '#424242'}},
|
| 1896 |
'tickfont': {'size': 14},
|
| 1897 |
'gridcolor': 'rgba(220, 220, 220, 0.5)',
|
| 1898 |
'showgrid': True
|
|
|
|
| 1988 |
color=color_max,
|
| 1989 |
line=dict(color='white', width=1)
|
| 1990 |
),
|
| 1991 |
+
hovertemplate='ò: %{x:.3f}<br>Value: %{y:.6f}<extra>Empirical Max</extra>'
|
| 1992 |
))
|
| 1993 |
|
| 1994 |
fig.add_trace(go.Scatter(
|
|
|
|
| 2003 |
color=color_min,
|
| 2004 |
line=dict(color='white', width=1)
|
| 2005 |
),
|
| 2006 |
+
hovertemplate='ò: %{x:.3f}<br>Value: %{y:.6f}<extra>Empirical Min</extra>'
|
| 2007 |
))
|
| 2008 |
|
| 2009 |
fig.add_trace(go.Scatter(
|
|
|
|
| 2018 |
color=color_theory_max,
|
| 2019 |
line=dict(color='white', width=1)
|
| 2020 |
),
|
| 2021 |
+
hovertemplate='ò: %{x:.3f}<br>Value: %{y:.6f}<extra>Theoretical Max</extra>'
|
| 2022 |
))
|
| 2023 |
|
| 2024 |
fig.add_trace(go.Scatter(
|
|
|
|
| 2033 |
color=color_theory_min,
|
| 2034 |
line=dict(color='white', width=1)
|
| 2035 |
),
|
| 2036 |
+
hovertemplate='ò: %{x:.3f}<br>Value: %{y:.6f}<extra>Theoretical Min</extra>'
|
| 2037 |
))
|
| 2038 |
|
| 2039 |
# Configure layout for better appearance
|
|
|
|
| 2047 |
'yanchor': 'top'
|
| 2048 |
},
|
| 2049 |
xaxis={
|
| 2050 |
+
'title': {'text': 'ò Parameter', 'font': {'size': 18, 'color': '#424242'}},
|
| 2051 |
'tickfont': {'size': 14},
|
| 2052 |
'gridcolor': 'rgba(220, 220, 220, 0.5)',
|
| 2053 |
'showgrid': True
|
|
|
|
| 2076 |
st.info("This is the previous analysis result. Adjust parameters and click 'Generate Analysis' to create a new visualization.")
|
| 2077 |
|
| 2078 |
except Exception as e:
|
| 2079 |
+
st.info("ð Set parameters and click 'Generate Eigenvalue Analysis' to create a visualization.")
|
| 2080 |
else:
|
| 2081 |
# Show placeholder
|
| 2082 |
+
st.info("ð Set parameters and click 'Generate Eigenvalue Analysis' to create a visualization.")
|
| 2083 |
|
| 2084 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 2085 |
|
|
|
|
| 2099 |
help="Parameter a > 1", key="cubic_a")
|
| 2100 |
cubic_y = st.number_input("Value for y", min_value=0.1, max_value=10.0, value=1.0, step=0.1,
|
| 2101 |
help="Parameter y > 0", key="cubic_y")
|
| 2102 |
+
cubic_beta = st.number_input("Value for ò", min_value=0.0, max_value=1.0, value=0.5, step=0.05,
|
| 2103 |
help="Value between 0 and 1", key="cubic_beta")
|
| 2104 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 2105 |
|
|
|
|
| 2304 |
help="Select a specific z value to visualize its roots in the complex plane"
|
| 2305 |
)
|
| 2306 |
|
| 2307 |
+
|
| 2308 |
+
# Create complex plane visualization
|
| 2309 |
complex_fig = create_complex_plane_visualization(result, z_idx)
|
| 2310 |
st.plotly_chart(complex_fig, use_container_width=True)
|
| 2311 |
|
| 2312 |
except Exception as e:
|
| 2313 |
+
st.info("Set parameters and click 'Generate Im(s) vs z Analysis' to create a visualization.")
|
| 2314 |
st.error(f"Error loading previous data: {str(e)}")
|
| 2315 |
else:
|
| 2316 |
# Show placeholder
|
| 2317 |
+
st.info(" Set parameters and click 'Generate Im(s) vs z Analysis' to create a visualization.")
|
| 2318 |
|
| 2319 |
st.markdown('</div>', unsafe_allow_html=True)
|
| 2320 |
|