Update my_pages/ica.py
Browse files- my_pages/ica.py +27 -23
my_pages/ica.py
CHANGED
|
@@ -5,46 +5,50 @@ import numpy as np
|
|
| 5 |
def render():
|
| 6 |
st.title("Intentional / Conventional / Arbitrary Triangle")
|
| 7 |
|
| 8 |
-
# Initialize state for
|
| 9 |
if "intentional" not in st.session_state:
|
| 10 |
st.session_state.intentional = 0.33
|
| 11 |
st.session_state.conventional = 0.33
|
| 12 |
st.session_state.arbitrary = 0.34
|
| 13 |
|
| 14 |
-
# Sliders
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Plot triangle
|
| 29 |
fig, ax = plt.subplots(figsize=(5, 5))
|
| 30 |
|
| 31 |
-
# Triangle vertices
|
| 32 |
-
vertices = np.array([[0.5, np.sqrt(3)/2], [0, 0], [1, 0]])
|
| 33 |
labels = ["Intentional", "Conventional", "Arbitrary"]
|
| 34 |
|
| 35 |
-
# Draw triangle
|
| 36 |
ax.plot([vertices[0][0], vertices[1][0]], [vertices[0][1], vertices[1][1]], 'k-')
|
| 37 |
ax.plot([vertices[1][0], vertices[2][0]], [vertices[1][1], vertices[2][1]], 'k-')
|
| 38 |
ax.plot([vertices[2][0], vertices[0][0]], [vertices[2][1], vertices[0][1]], 'k-')
|
| 39 |
|
| 40 |
-
# Add labels
|
| 41 |
for i, label in enumerate(labels):
|
| 42 |
ax.text(vertices[i][0], vertices[i][1] + 0.05, label, ha='center', fontsize=12, fontweight='bold')
|
| 43 |
|
| 44 |
# Convert (intentional, conventional, arbitrary) to XY coords
|
| 45 |
point = (
|
| 46 |
-
|
| 47 |
-
(np.sqrt(3)/2) *
|
| 48 |
)
|
| 49 |
|
| 50 |
# Plot point
|
|
@@ -54,11 +58,11 @@ def render():
|
|
| 54 |
ax.axis('off')
|
| 55 |
st.pyplot(fig)
|
| 56 |
|
| 57 |
-
#
|
| 58 |
dominant = max(
|
| 59 |
-
("Intentional",
|
| 60 |
-
("Conventional",
|
| 61 |
-
("Arbitrary",
|
| 62 |
key=lambda x: x[1]
|
| 63 |
)[0]
|
| 64 |
|
|
|
|
| 5 |
def render():
|
| 6 |
st.title("Intentional / Conventional / Arbitrary Triangle")
|
| 7 |
|
| 8 |
+
# Initialize session state for sliders
|
| 9 |
if "intentional" not in st.session_state:
|
| 10 |
st.session_state.intentional = 0.33
|
| 11 |
st.session_state.conventional = 0.33
|
| 12 |
st.session_state.arbitrary = 0.34
|
| 13 |
|
| 14 |
+
# Sliders
|
| 15 |
+
intentional = st.slider("Intentional", 0.0, 1.0, st.session_state.intentional, 0.01)
|
| 16 |
+
conventional = st.slider("Conventional", 0.0, 1.0, st.session_state.conventional, 0.01)
|
| 17 |
+
arbitrary = st.slider("Arbitrary", 0.0, 1.0, st.session_state.arbitrary, 0.01)
|
| 18 |
|
| 19 |
+
# Normalize values so sum is always 1
|
| 20 |
+
total = intentional + conventional + arbitrary
|
| 21 |
+
if total == 0:
|
| 22 |
+
total = 1
|
| 23 |
+
intentional /= total
|
| 24 |
+
conventional /= total
|
| 25 |
+
arbitrary /= total
|
| 26 |
+
|
| 27 |
+
# Store back in session state
|
| 28 |
+
st.session_state.intentional = intentional
|
| 29 |
+
st.session_state.conventional = conventional
|
| 30 |
+
st.session_state.arbitrary = arbitrary
|
| 31 |
|
| 32 |
# Plot triangle
|
| 33 |
fig, ax = plt.subplots(figsize=(5, 5))
|
| 34 |
|
| 35 |
+
# Triangle vertices (Intentional, Conventional, Arbitrary)
|
| 36 |
+
vertices = np.array([[0.5, np.sqrt(3)/2], [0, 0], [1, 0]])
|
| 37 |
labels = ["Intentional", "Conventional", "Arbitrary"]
|
| 38 |
|
| 39 |
+
# Draw triangle edges
|
| 40 |
ax.plot([vertices[0][0], vertices[1][0]], [vertices[0][1], vertices[1][1]], 'k-')
|
| 41 |
ax.plot([vertices[1][0], vertices[2][0]], [vertices[1][1], vertices[2][1]], 'k-')
|
| 42 |
ax.plot([vertices[2][0], vertices[0][0]], [vertices[2][1], vertices[0][1]], 'k-')
|
| 43 |
|
| 44 |
+
# Add vertex labels
|
| 45 |
for i, label in enumerate(labels):
|
| 46 |
ax.text(vertices[i][0], vertices[i][1] + 0.05, label, ha='center', fontsize=12, fontweight='bold')
|
| 47 |
|
| 48 |
# Convert (intentional, conventional, arbitrary) to XY coords
|
| 49 |
point = (
|
| 50 |
+
conventional + 0.5 * intentional,
|
| 51 |
+
(np.sqrt(3)/2) * intentional
|
| 52 |
)
|
| 53 |
|
| 54 |
# Plot point
|
|
|
|
| 58 |
ax.axis('off')
|
| 59 |
st.pyplot(fig)
|
| 60 |
|
| 61 |
+
# Show dominant property description
|
| 62 |
dominant = max(
|
| 63 |
+
("Intentional", intentional),
|
| 64 |
+
("Conventional", conventional),
|
| 65 |
+
("Arbitrary", arbitrary),
|
| 66 |
key=lambda x: x[1]
|
| 67 |
)[0]
|
| 68 |
|