Mpavan45 commited on
Commit
30e0876
·
verified ·
1 Parent(s): 1580b42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -60,7 +60,8 @@ if "x" not in st.session_state:
60
 
61
  # Function to handle iteration movement
62
  def update_iteration(step):
63
- if st.session_state.iteration + step >= 0 and st.session_state.iteration + step < len(st.session_state.x_vals):
 
64
  st.session_state.iteration += step
65
  st.session_state.x = st.session_state.x_vals[st.session_state.iteration]
66
  st.session_state.y_vals = [safe_eval(func_input, st.session_state.x)]
@@ -81,6 +82,20 @@ with col3:
81
  if st.button("⏩ Next", key="next", on_click=update_iteration, args=(1,)):
82
  pass
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  # Plotting
85
  x_range = np.linspace(-2, 6, 400) # Zoomed-in x-axis range for better visualization
86
  y_range = [safe_eval(func_input, x) for x in x_range]
 
60
 
61
  # Function to handle iteration movement
62
  def update_iteration(step):
63
+ """Moves to next or previous iteration when the buttons are clicked."""
64
+ if 0 <= st.session_state.iteration + step < len(st.session_state.x_vals):
65
  st.session_state.iteration += step
66
  st.session_state.x = st.session_state.x_vals[st.session_state.iteration]
67
  st.session_state.y_vals = [safe_eval(func_input, st.session_state.x)]
 
82
  if st.button("⏩ Next", key="next", on_click=update_iteration, args=(1,)):
83
  pass
84
 
85
+ # Buttons to run descent step and reset
86
+ col4, col5 = st.columns([1, 1])
87
+ with col4:
88
+ if st.button("🔄 Run Descent Step"):
89
+ grad = derivative(func_input, st.session_state.x)
90
+ st.session_state.x -= learning_rate * grad
91
+ st.session_state.iteration += 1
92
+ st.session_state.x_vals.append(st.session_state.x)
93
+ st.session_state.y_vals.append(safe_eval(func_input, st.session_state.x))
94
+
95
+ with col5:
96
+ if st.button("🔄 Reset", on_click=reset_state):
97
+ pass
98
+
99
  # Plotting
100
  x_range = np.linspace(-2, 6, 400) # Zoomed-in x-axis range for better visualization
101
  y_range = [safe_eval(func_input, x) for x in x_range]