prakharg24 commited on
Commit
e549f99
·
verified ·
1 Parent(s): b8dedc5

Update my_pages/ica.py

Browse files
Files changed (1) hide show
  1. my_pages/ica.py +47 -19
my_pages/ica.py CHANGED
@@ -11,10 +11,11 @@ def render():
11
  add_instruction_text(
12
  """
13
  Explore the intention-convention-arbitrariness (ICA) framework.<br>
14
- Use the sliders to adjust the three dimensions simultaneously.
15
  """
16
  )
17
 
 
18
  if "weights" not in st.session_state:
19
  st.session_state.weights = {
20
  "Intentional": 0.33,
@@ -22,27 +23,56 @@ def render():
22
  "Arbitrary": 0.34
23
  }
24
 
 
 
 
 
25
  w = st.session_state.weights
 
26
 
27
  # --- Three sliders ---
28
  col1, col2, col3 = st.columns(3)
29
  with col1:
30
- i = st.slider("Intentional", 0.0, 1.0, w["Intentional"], 0.01)
31
  with col2:
32
- c = st.slider("Conventional", 0.0, 1.0, w["Conventional"], 0.01)
33
  with col3:
34
- a = st.slider("Arbitrary", 0.0, 1.0, w["Arbitrary"], 0.01)
35
-
36
- # Normalize to sum = 1
37
- total = i + c + a
38
- if total > 0:
39
- w["Intentional"] = round(i / total, 4)
40
- w["Conventional"] = round(c / total, 4)
41
- w["Arbitrary"] = round(a / total, 4)
42
- else:
43
- w["Intentional"] = w["Conventional"] = w["Arbitrary"] = round(1/3, 4)
44
-
45
- # Triangle vertices
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  vertices = np.array([
47
  [0.5, np.sqrt(3)/2], # Intentional
48
  [0, 0], # Conventional
@@ -56,7 +86,7 @@ def render():
56
  w["Arbitrary"] * vertices[2]
57
  )
58
 
59
- # Plot
60
  fig, ax = plt.subplots()
61
  ax.plot(*np.append(vertices, [vertices[0]], axis=0).T)
62
  ax.text(*vertices[0], "Intentional", ha="center", va="bottom", color="green", weight="heavy")
@@ -66,11 +96,10 @@ def render():
66
  ax.scatter(point[0], point[1], c="orange", s=10000, zorder=5, alpha=0.3)
67
  ax.set_aspect("equal")
68
  ax.axis("off")
69
-
70
  fig.patch.set_alpha(0)
71
  ax.patch.set_alpha(0)
72
 
73
- # --- Dummy points scattered inside triangle ---
74
  locations = [
75
  (0.9, 0.1, "Random Seeds", "Random Seeds are highly arbitrary, without any convention or intentionality.", "left", "bottom"),
76
  (0.35, 0.06, "Neural networks for Tabular Data", "Using neural networks of some arbitrary size (hidden layers) for a setting where they are not needed is highly conventional, a bit arbitrary, and has very low intentionality.", "left", "bottom"),
@@ -82,7 +111,6 @@ def render():
82
 
83
  torch_radius = 0.177
84
  explanations = []
85
- # Illuminate nearby points
86
  for (x, y, label, labeltext, ha, va) in locations:
87
  dist = np.linalg.norm([x - point[0], y - point[1]])
88
  if dist <= torch_radius:
 
11
  add_instruction_text(
12
  """
13
  Explore the intention-convention-arbitrariness (ICA) framework.<br>
14
+ Use the sliders to adjust the three dimensions.
15
  """
16
  )
17
 
18
+ # Initialize weights
19
  if "weights" not in st.session_state:
20
  st.session_state.weights = {
21
  "Intentional": 0.33,
 
23
  "Arbitrary": 0.34
24
  }
25
 
26
+ # Keep track of previous weights
27
+ if "prev_weights" not in st.session_state:
28
+ st.session_state.prev_weights = st.session_state.weights.copy()
29
+
30
  w = st.session_state.weights
31
+ prev_w = st.session_state.prev_weights
32
 
33
  # --- Three sliders ---
34
  col1, col2, col3 = st.columns(3)
35
  with col1:
36
+ i_new = st.slider("Intentional", 0.0, 1.0, w["Intentional"], 0.01)
37
  with col2:
38
+ c_new = st.slider("Conventional", 0.0, 1.0, w["Conventional"], 0.01)
39
  with col3:
40
+ a_new = st.slider("Arbitrary", 0.0, 1.0, w["Arbitrary"], 0.01)
41
+
42
+ # --- Adjust other sliders proportionally ---
43
+ # Detect which slider changed
44
+ if i_new != prev_w["Intentional"]:
45
+ diff = i_new - prev_w["Intentional"]
46
+ total_other = w["Conventional"] + w["Arbitrary"]
47
+ if total_other > 0:
48
+ w["Conventional"] -= diff * (w["Conventional"] / total_other)
49
+ w["Arbitrary"] -= diff * (w["Arbitrary"] / total_other)
50
+ w["Intentional"] = i_new
51
+
52
+ elif c_new != prev_w["Conventional"]:
53
+ diff = c_new - prev_w["Conventional"]
54
+ total_other = w["Intentional"] + w["Arbitrary"]
55
+ if total_other > 0:
56
+ w["Intentional"] -= diff * (w["Intentional"] / total_other)
57
+ w["Arbitrary"] -= diff * (w["Arbitrary"] / total_other)
58
+ w["Conventional"] = c_new
59
+
60
+ elif a_new != prev_w["Arbitrary"]:
61
+ diff = a_new - prev_w["Arbitrary"]
62
+ total_other = w["Intentional"] + w["Conventional"]
63
+ if total_other > 0:
64
+ w["Intentional"] -= diff * (w["Intentional"] / total_other)
65
+ w["Conventional"] -= diff * (w["Conventional"] / total_other)
66
+ w["Arbitrary"] = a_new
67
+
68
+ # Clamp small floating point errors
69
+ for k in w:
70
+ w[k] = max(0.0, min(1.0, round(w[k], 4)))
71
+
72
+ # Update prev_weights for next run
73
+ st.session_state.prev_weights = w.copy()
74
+
75
+ # --- Triangle vertices ---
76
  vertices = np.array([
77
  [0.5, np.sqrt(3)/2], # Intentional
78
  [0, 0], # Conventional
 
86
  w["Arbitrary"] * vertices[2]
87
  )
88
 
89
+ # --- Plot ---
90
  fig, ax = plt.subplots()
91
  ax.plot(*np.append(vertices, [vertices[0]], axis=0).T)
92
  ax.text(*vertices[0], "Intentional", ha="center", va="bottom", color="green", weight="heavy")
 
96
  ax.scatter(point[0], point[1], c="orange", s=10000, zorder=5, alpha=0.3)
97
  ax.set_aspect("equal")
98
  ax.axis("off")
 
99
  fig.patch.set_alpha(0)
100
  ax.patch.set_alpha(0)
101
 
102
+ # --- Dummy points ---
103
  locations = [
104
  (0.9, 0.1, "Random Seeds", "Random Seeds are highly arbitrary, without any convention or intentionality.", "left", "bottom"),
105
  (0.35, 0.06, "Neural networks for Tabular Data", "Using neural networks of some arbitrary size (hidden layers) for a setting where they are not needed is highly conventional, a bit arbitrary, and has very low intentionality.", "left", "bottom"),
 
111
 
112
  torch_radius = 0.177
113
  explanations = []
 
114
  for (x, y, label, labeltext, ha, va) in locations:
115
  dist = np.linalg.norm([x - point[0], y - point[1]])
116
  if dist <= torch_radius: