prakharg24 commited on
Commit
64eeded
·
verified ·
1 Parent(s): 9a4bcc6

Update my_pages/ica.py

Browse files
Files changed (1) hide show
  1. 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
- st.write("Adjust the sliders to change the position of the decision in the triangle.")
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
- # Sliders (manually enforce sum to 1)
17
- intentional = st.slider("Intentional", 0.0, 1.0, st.session_state.intentional, 0.01)
18
- remaining_for_two = 1.0 - intentional
19
- conventional = st.slider("Conventional", 0.0, remaining_for_two, st.session_state.conventional, 0.01)
20
- arbitrary = 1.0 - intentional - conventional
 
 
 
 
 
 
 
 
21
 
22
- # Save back to session_state
23
- st.session_state.intentional = intentional
24
- st.session_state.conventional = conventional
25
- st.session_state.arbitrary = arbitrary
 
 
 
 
 
 
 
 
 
 
 
26
 
27
- st.write(f"**Arbitrary:** {arbitrary:.2f}")
 
 
 
28
 
29
  # Triangle vertices (equilateral)
30
  vertices = np.array([
@@ -33,16 +53,16 @@ def render():
33
  [1, 0] # Arbitrary
34
  ])
35
 
36
- # Compute point location from barycentric coordinates
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-') # Triangle outline
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
- # Show explanation text based on closeness
58
  closest = max(
59
- [("Intentional", intentional), ("Conventional", conventional), ("Arbitrary", arbitrary)],
 
 
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