コード例 #1
0
ファイル: lab1_report.py プロジェクト: ImpyAngel/opt-methods
def grad_shower(func: ExtendedFunction,
                start_point: np.ndarray,
                strategy_sup: Callable[[ExtendedFunction], StepStrategy],
                max_iters=15,
                initial_steps=(0.01, 0.1, 1, 10)
                ):
    strategy = strategy_sup(func)
    data = [draw_grad_des(func, start_point, strategy, initial_step=s, max_iters=max_iters) for s in initial_steps]

    draw_grid(data, ncols=2)
コード例 #2
0
def draw_test_grad():
    data = [draw_one_test_grad(n) for n in range(2, 6)]
    draw_grid(data, ncols=2)
コード例 #3
0
ファイル: lab1_report.py プロジェクト: aprox13/opt-methods
        results_yy.append(res.x)

    iter_by_eps[e_name] = (xx, iter_yy)
    calls_by_eps[e_name] = (xx, calls_yy)
    results_by_eps[e_name] = (xx, results_yy)

grid = [
    by_eps_plot("Iterations by eps", iter_by_eps),
    by_eps_plot("Calls by eps", calls_by_eps),
    by_eps_plot("Result by eps", results_by_eps)
]

for e_name in ENGINES.keys():
    grid.append(range_plt(e_name, 1e-4))

draw_grid(grid, ncols=engines_cnt)

# %%
"""
### Покажем результат работы метода градиентного спуска на некоторых примерах
"""


# %%
def draw_grad_des(e_func: ExtendedFunction,
                  start: np.ndarray,
                  strategy: StepStrategy,
                  max_iters=30,
                  initial_step=1):
    def _drawer(ax):
        grad = GradDescent()