Mpavan45 commited on
Commit
2ef136a
·
verified ·
1 Parent(s): a43c583

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -11
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 = [point[0] for point in st.session_state.history]
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
- current_x = st.session_state.x_current
131
- current_y = evaluate_function(function_input, current_x)
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 (with more space now)
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)