Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,9 +27,12 @@ def calculate_tangent(expression, x_value, x_range):
|
|
| 27 |
|
| 28 |
# Reset state
|
| 29 |
def reset_session_state():
|
|
|
|
| 30 |
st.session_state.x_current = st.session_state.initial_point
|
| 31 |
st.session_state.iter_count = 0
|
| 32 |
-
st.session_state.history = [
|
|
|
|
|
|
|
| 33 |
st.session_state.current_index = 0
|
| 34 |
|
| 35 |
# Initialize session state variables
|
|
@@ -59,9 +62,10 @@ with left_col:
|
|
| 59 |
initial_point = st.number_input(
|
| 60 |
"Initial Value of x", value=4.0, step=0.1, format="%.2f", key="initial_point", on_change=reset_session_state
|
| 61 |
)
|
| 62 |
-
|
| 63 |
-
"Learning Rate", value=
|
| 64 |
-
|
|
|
|
| 65 |
st.markdown("---")
|
| 66 |
|
| 67 |
# Reset Button
|
|
@@ -74,7 +78,7 @@ with right_col:
|
|
| 74 |
if st.button("🔄 Run Descent Step", type="primary"):
|
| 75 |
try:
|
| 76 |
gradient = compute_derivative(function_input, st.session_state.x_current)
|
| 77 |
-
st.session_state.x_current -= learning_rate * gradient
|
| 78 |
st.session_state.iter_count += 1
|
| 79 |
st.session_state.history.append(
|
| 80 |
(st.session_state.x_current, evaluate_function(function_input, st.session_state.x_current))
|
|
|
|
| 27 |
|
| 28 |
# Reset state
|
| 29 |
def reset_session_state():
|
| 30 |
+
"""Resets the session state for a fresh start."""
|
| 31 |
st.session_state.x_current = st.session_state.initial_point
|
| 32 |
st.session_state.iter_count = 0
|
| 33 |
+
st.session_state.history = [
|
| 34 |
+
(st.session_state.initial_point, evaluate_function(st.session_state.math_function, st.session_state.initial_point))
|
| 35 |
+
]
|
| 36 |
st.session_state.current_index = 0
|
| 37 |
|
| 38 |
# Initialize session state variables
|
|
|
|
| 62 |
initial_point = st.number_input(
|
| 63 |
"Initial Value of x", value=4.0, step=0.1, format="%.2f", key="initial_point", on_change=reset_session_state
|
| 64 |
)
|
| 65 |
+
st.number_input(
|
| 66 |
+
"Learning Rate", value=st.session_state.learning_rate, step=0.01, format="%.2f",
|
| 67 |
+
key="learning_rate"
|
| 68 |
+
) # Updates session state directly without reset
|
| 69 |
st.markdown("---")
|
| 70 |
|
| 71 |
# Reset Button
|
|
|
|
| 78 |
if st.button("🔄 Run Descent Step", type="primary"):
|
| 79 |
try:
|
| 80 |
gradient = compute_derivative(function_input, st.session_state.x_current)
|
| 81 |
+
st.session_state.x_current -= st.session_state.learning_rate * gradient
|
| 82 |
st.session_state.iter_count += 1
|
| 83 |
st.session_state.history.append(
|
| 84 |
(st.session_state.x_current, evaluate_function(function_input, st.session_state.x_current))
|