visualize.one_animation#

gen_animation_gss(func, bounds, history, **kwargs)[source]#

Generates an animation of the golden-section search on func between the bounds

Parameters:
  • func (Callable) – callable that depends on the first positional argument

  • bounds (tuple[float, float]) – tuple with left and right points on the x-axis

  • history (HistoryGSS) – a history object. a dict with lists. keys iteration, f_value, middle_point, left_point, right_point

Returns:

go.Figure with graph

Return type:

Figure

>>> def f(x): return x ** 3 - x ** 2 - x
>>> _, h = golden_section_search(f, (0, 2), keep_history=True)
>>> gen_animation_gss(f, (0, 2), h)
gen_animation_spi(func, bounds, history)[source]#

Generate animation. Per each iteration we create a go.Frame with parabola plot passing through three points

Parameters:
  • history (HistorySPI) – a history object. a dict with lists. keys iteration, f_value, middle_point, left_point, right_point

  • bounds ([float, float]) – tuple with left and right points on the x-axis

  • func (Callable[[float], float]) – the functions for which the story was created

Return type:

go.Figure

>>> def f(x): return x ** 3 - x ** 2 - x
>>> _, h = successive_parabolic_interpolation(f, (0, 2), keep_history=True)
>>> gen_animation_spi(f, (0, 2), h)
gen_animation_brent(func, history)[source]#

Returns a visualization of the Brent algorithm. Each iteration shows which iteration.

Parameters:
  • func (Callable[[float], float]) – callable that depends on the first positional argument

  • history (HistoryBrent) – brent optimization history

Returns:

animation of optimization

Return type:

Figure

>>> def f(x): return x ** 3 - x ** 2 - x
>>> _, h = brent(f, (0, 2), keep_history=True)
>>> gen_animation_brent(f, h)
parabolic_coefficients(x0, x1, x2, func)[source]#

Returns a parabolic function passing through the specified points x0, x1, x2 coeficients

>>> parabolic_coefficients(0, 1, 2, lambda x: x ** 2)
(1.0, 0.0, 0.0)
(1)#\[\begin{bmatrix} a \\ b \\ c \end{bmatrix} = \begin{bmatrix} x_0^2 & x_0 & 1 \\ x_1^2 & x_1 & 1 \\ x_2^2 & x_2 & 1 \end{bmatrix}^{-1} \cdot \begin{bmatrix} y_0 \\ y_1 \\ y_2 \end{bmatrix}\]
Parameters:
  • x0 (float) – first point

  • x1 (float) – second point

  • x2 (float) – third point

  • func (Callable[[float], float]) – the functions for which the story was created

Returns:

coefficients of the parabolic function

Return type:

[float, float, float]

transfer_history_gss(history, func)[source]#

Generate data for plotly express with using animation_frame for animate

>>> def f(x): return x ** 2
>>> _, hist = golden_section_search(f, (-1, 2), keep_history=True)
>>> data_for_plot = transfer_history_gss(hist, f)
Searching finished. Successfully. code 0
>>> data_for_plot[::30]

iteration

type

x

y

size

0

0

middle

0.500000

0.250000

3

30

4

left

-0.291796

0.085145

3

60

8

right

0.042572

0.001812

3

Parameters:
  • history (HistoryGSS) – a history object. a dict with lists. keys iteration, f_value, middle_point, left_point, right_point

  • func – the functions for which the story was created

Returns:

pd.DataFrame for gen_animation_gss. index - num of iteration.

Return type:

DataFrame