Skip to content

Commit fd4cea8

Browse files
committed
Update visuals.py
1 parent 366e2f1 commit fd4cea8

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

linear_regression/visuals.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,13 @@ def show_interactive_line_tuner(
110110
if abs(b_float) >= 1e-15
111111
else max(y_spread / 80, 0.05, 1e-9)
112112
)
113-
step_b = min(step_b, b_rng / 5) if b_rng > 0 else step_b
114-
step_b = max(step_b, 1e-12)
113+
if b_rng > 0:
114+
step_b = min(step_b, b_rng / 5)
115+
# Never let step exceed the slider span (traitlets rejects some combinations)
116+
step_b = min(step_b, b_rng / 2.01)
117+
step_b = max(step_b, min(b_rng / 200, b_rng / 2.01))
118+
else:
119+
step_b = 1e-12
115120

116121
b_try = widgets.FloatSlider(
117122
value=b_val,
@@ -141,9 +146,14 @@ def show_interactive_line_tuner(
141146
half = max(4 * y_spread, 1.0)
142147
a_lo, a_hi = a_float - half, a_float + half
143148
a_min, a_max, a_val = _float_slider_range(a_lo, a_hi, a_float)
149+
a_rng = a_max - a_min
144150
step_a = max(y_spread / 80, 0.05, 1e-9)
145-
step_a = min(step_a, (a_max - a_min) / 5) if a_max > a_min else step_a
146-
step_a = max(step_a, 1e-12)
151+
if a_rng > 0:
152+
step_a = min(step_a, a_rng / 5)
153+
step_a = min(step_a, a_rng / 2.01)
154+
step_a = max(step_a, min(a_rng / 200, a_rng / 2.01))
155+
else:
156+
step_a = 1e-12
147157
a_try = widgets.FloatSlider(
148158
value=a_val,
149159
min=a_min,

0 commit comments

Comments
 (0)