Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -98,7 +98,7 @@ with col1:
|
|
| 98 |
learning_rate = st.number_input("Learning Rate:", value=0.1, step=0.01, format="%.2f", key="learning_rate", on_change=reset_session)
|
| 99 |
|
| 100 |
# Buttons for actions with styling
|
| 101 |
-
col1.button("π Next Step", key="next", use_container_width=True, help="Perform one step of gradient descent", on_click=None
|
| 102 |
col1.button("π Reset", key="reset", use_container_width=True, help="Reset the gradient descent", on_click=reset_session)
|
| 103 |
iteration_data_button = col1.button("π Iteration Data", key="iteration_data", use_container_width=True)
|
| 104 |
|
|
@@ -143,6 +143,22 @@ with col2:
|
|
| 143 |
|
| 144 |
st.plotly_chart(plot)
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
# Show iteration data in a new section when the button is clicked
|
| 147 |
if iteration_data_button:
|
| 148 |
st.subheader("π Iteration Data")
|
|
|
|
| 98 |
learning_rate = st.number_input("Learning Rate:", value=0.1, step=0.01, format="%.2f", key="learning_rate", on_change=reset_session)
|
| 99 |
|
| 100 |
# Buttons for actions with styling
|
| 101 |
+
col1.button("π Next Step", key="next", use_container_width=True, help="Perform one step of gradient descent", on_click=None)
|
| 102 |
col1.button("π Reset", key="reset", use_container_width=True, help="Reset the gradient descent", on_click=reset_session)
|
| 103 |
iteration_data_button = col1.button("π Iteration Data", key="iteration_data", use_container_width=True)
|
| 104 |
|
|
|
|
| 143 |
|
| 144 |
st.plotly_chart(plot)
|
| 145 |
|
| 146 |
+
# Perform gradient descent operation when button is clicked
|
| 147 |
+
if st.button("π Next Step", key="next", use_container_width=True):
|
| 148 |
+
try:
|
| 149 |
+
grad = compute_derivative(st.session_state.func_input, st.session_state.x_current)
|
| 150 |
+
st.session_state.x_current = st.session_state.x_current - st.session_state.learning_rate * grad
|
| 151 |
+
st.session_state.iter_count += 1
|
| 152 |
+
|
| 153 |
+
# Add current iteration data
|
| 154 |
+
st.session_state.iter_data.append({
|
| 155 |
+
"Iteration": st.session_state.iter_count,
|
| 156 |
+
"x": st.session_state.x_current,
|
| 157 |
+
"f(x)": evaluate_function(st.session_state.func_input, st.session_state.x_current),
|
| 158 |
+
})
|
| 159 |
+
except Exception as e:
|
| 160 |
+
st.error(f"Error: {e}")
|
| 161 |
+
|
| 162 |
# Show iteration data in a new section when the button is clicked
|
| 163 |
if iteration_data_button:
|
| 164 |
st.subheader("π Iteration Data")
|