Update my_pages/ica.py
Browse files- my_pages/ica.py +42 -20
my_pages/ica.py
CHANGED
|
@@ -5,26 +5,46 @@ import numpy as np
|
|
| 5 |
def render():
|
| 6 |
st.title("ICA Triangle")
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
# Initialize values in session_state so they persist
|
| 11 |
if "intentional" not in st.session_state:
|
| 12 |
st.session_state.intentional = 0.33
|
| 13 |
st.session_state.conventional = 0.33
|
| 14 |
st.session_state.arbitrary = 0.34
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# Triangle vertices (equilateral)
|
| 30 |
vertices = np.array([
|
|
@@ -33,16 +53,16 @@ def render():
|
|
| 33 |
[1, 0] # Arbitrary
|
| 34 |
])
|
| 35 |
|
| 36 |
-
# Compute point
|
| 37 |
point = (
|
| 38 |
-
intentional * vertices[0] +
|
| 39 |
-
conventional * vertices[1] +
|
| 40 |
-
arbitrary * vertices[2]
|
| 41 |
)
|
| 42 |
|
| 43 |
# Plot
|
| 44 |
fig, ax = plt.subplots()
|
| 45 |
-
ax.plot(*np.append(vertices, [vertices[0]], axis=0).T, 'k-') #
|
| 46 |
ax.scatter(vertices[:,0], vertices[:,1], c=["blue", "green", "red"], s=100)
|
| 47 |
ax.text(*vertices[0], "Intentional", ha="center", va="bottom")
|
| 48 |
ax.text(*vertices[1], "Conventional", ha="right", va="top")
|
|
@@ -54,9 +74,11 @@ def render():
|
|
| 54 |
|
| 55 |
st.pyplot(fig)
|
| 56 |
|
| 57 |
-
#
|
| 58 |
closest = max(
|
| 59 |
-
[("Intentional", intentional),
|
|
|
|
|
|
|
| 60 |
key=lambda x: x[1]
|
| 61 |
)[0]
|
| 62 |
|
|
|
|
| 5 |
def render():
|
| 6 |
st.title("ICA Triangle")
|
| 7 |
|
| 8 |
+
# Initialize state
|
|
|
|
|
|
|
| 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 |
+
st.write("Adjust one slider at a time. The others will update automatically so the total = 1.")
|
| 15 |
+
|
| 16 |
+
# Choose which one to control
|
| 17 |
+
control_choice = st.radio(
|
| 18 |
+
"Which dimension do you want to adjust?",
|
| 19 |
+
["Intentional", "Conventional", "Arbitrary"],
|
| 20 |
+
horizontal=True
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Get current values
|
| 24 |
+
i = st.session_state.intentional
|
| 25 |
+
c = st.session_state.conventional
|
| 26 |
+
a = st.session_state.arbitrary
|
| 27 |
|
| 28 |
+
if control_choice == "Intentional":
|
| 29 |
+
i = st.slider("Intentional", 0.0, 1.0, i, 0.01)
|
| 30 |
+
remaining = 1.0 - i
|
| 31 |
+
c = min(c, remaining)
|
| 32 |
+
a = remaining - c
|
| 33 |
+
elif control_choice == "Conventional":
|
| 34 |
+
c = st.slider("Conventional", 0.0, 1.0, c, 0.01)
|
| 35 |
+
remaining = 1.0 - c
|
| 36 |
+
i = min(i, remaining)
|
| 37 |
+
a = remaining - i
|
| 38 |
+
elif control_choice == "Arbitrary":
|
| 39 |
+
a = st.slider("Arbitrary", 0.0, 1.0, a, 0.01)
|
| 40 |
+
remaining = 1.0 - a
|
| 41 |
+
i = min(i, remaining)
|
| 42 |
+
c = remaining - i
|
| 43 |
|
| 44 |
+
# Save updated values
|
| 45 |
+
st.session_state.intentional = round(i, 4)
|
| 46 |
+
st.session_state.conventional = round(c, 4)
|
| 47 |
+
st.session_state.arbitrary = round(a, 4)
|
| 48 |
|
| 49 |
# Triangle vertices (equilateral)
|
| 50 |
vertices = np.array([
|
|
|
|
| 53 |
[1, 0] # Arbitrary
|
| 54 |
])
|
| 55 |
|
| 56 |
+
# Compute point position
|
| 57 |
point = (
|
| 58 |
+
st.session_state.intentional * vertices[0] +
|
| 59 |
+
st.session_state.conventional * vertices[1] +
|
| 60 |
+
st.session_state.arbitrary * vertices[2]
|
| 61 |
)
|
| 62 |
|
| 63 |
# Plot
|
| 64 |
fig, ax = plt.subplots()
|
| 65 |
+
ax.plot(*np.append(vertices, [vertices[0]], axis=0).T, 'k-') # Outline
|
| 66 |
ax.scatter(vertices[:,0], vertices[:,1], c=["blue", "green", "red"], s=100)
|
| 67 |
ax.text(*vertices[0], "Intentional", ha="center", va="bottom")
|
| 68 |
ax.text(*vertices[1], "Conventional", ha="right", va="top")
|
|
|
|
| 74 |
|
| 75 |
st.pyplot(fig)
|
| 76 |
|
| 77 |
+
# Explanation
|
| 78 |
closest = max(
|
| 79 |
+
[("Intentional", st.session_state.intentional),
|
| 80 |
+
("Conventional", st.session_state.conventional),
|
| 81 |
+
("Arbitrary", st.session_state.arbitrary)],
|
| 82 |
key=lambda x: x[1]
|
| 83 |
)[0]
|
| 84 |
|