Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -113,9 +113,8 @@ with right_col:
|
|
| 113 |
go.Scatter(x=x_vals, y=y_vals, mode="lines", line=dict(color="green", width=3), name="Function Curve")
|
| 114 |
)
|
| 115 |
|
| 116 |
-
# Add gradient descent points
|
| 117 |
-
x_points =
|
| 118 |
-
y_points = [point[1] for point in st.session_state.history]
|
| 119 |
plot.add_trace(
|
| 120 |
go.Scatter(
|
| 121 |
x=x_points,
|
|
@@ -126,13 +125,9 @@ with right_col:
|
|
| 126 |
)
|
| 127 |
)
|
| 128 |
|
| 129 |
-
# Add tangent line
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
slope = compute_derivative(function_input, current_x)
|
| 133 |
-
tangent_x = np.linspace(current_x - 2, current_x + 2, 100)
|
| 134 |
-
tangent_y = calculate_tangent(function_input, current_x, tangent_x)
|
| 135 |
-
|
| 136 |
plot.add_trace(
|
| 137 |
go.Scatter(
|
| 138 |
x=tangent_x,
|
|
@@ -153,5 +148,5 @@ with right_col:
|
|
| 153 |
height=500, # Reduce the graph height for better fitting
|
| 154 |
)
|
| 155 |
|
| 156 |
-
# Display the plot in the right side
|
| 157 |
st.plotly_chart(plot, use_container_width=True)
|
|
|
|
| 113 |
go.Scatter(x=x_vals, y=y_vals, mode="lines", line=dict(color="green", width=3), name="Function Curve")
|
| 114 |
)
|
| 115 |
|
| 116 |
+
# Add gradient descent points up to the current index
|
| 117 |
+
x_points, y_points = zip(*st.session_state.history[:st.session_state.current_index + 1])
|
|
|
|
| 118 |
plot.add_trace(
|
| 119 |
go.Scatter(
|
| 120 |
x=x_points,
|
|
|
|
| 125 |
)
|
| 126 |
)
|
| 127 |
|
| 128 |
+
# Add tangent line at the selected point
|
| 129 |
+
tangent_x = np.linspace(selected_x - 2, selected_x + 2, 100)
|
| 130 |
+
tangent_y = calculate_tangent(function_input, selected_x, tangent_x)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
plot.add_trace(
|
| 132 |
go.Scatter(
|
| 133 |
x=tangent_x,
|
|
|
|
| 148 |
height=500, # Reduce the graph height for better fitting
|
| 149 |
)
|
| 150 |
|
| 151 |
+
# Display the plot in the right side
|
| 152 |
st.plotly_chart(plot, use_container_width=True)
|