Example #1
0
def test_optimizer_history():
    # create the necessary results
    result_1 = create_optimization_history()
    result_2 = create_optimization_history()

    # test a standard call
    visualize.optimizer_history(result_1)

    # test plotting of lists
    visualize.optimizer_history([result_1, result_2])
Example #2
0
def test_optimizer_history_with_options():
    # create the necessary results
    result_1 = create_optimization_history()
    result_2 = create_optimization_history()

    # alternative figure size and plotting options
    (_, _, ref3, _, ref_point) = create_plotting_options()
    alt_fig_size = (9.0, 8.0)

    # Test with y-limits as vector
    with pytest.warns(UserWarning, match="Invalid lower bound"):
        visualize.optimizer_history(
            result_1,
            y_limits=[-0.5, 2.5],
            start_indices=[0, 1, 4, 11],
            reference=ref_point,
            size=alt_fig_size,
            trace_x='steps',
            trace_y='fval',
            offset_y=-10.0,
            colors=[1.0, 0.3, 0.3, 0.5],
        )

    # Test with linear scale
    visualize.optimizer_history(
        [result_1, result_2],
        y_limits=[-0.5, 2.5],
        start_indices=[0, 1, 4, 11],
        reference=ref_point,
        size=alt_fig_size,
        scale_y='lin',
    )

    # Test with y-limits as float
    visualize.optimizer_history(
        result_1,
        y_limits=5.0,
        start_indices=3,
        reference=ref3,
        trace_x='time',
        trace_y='gradnorm',
        offset_y=10.0,
    )
Example #3
0
        for name in problem.x_names
    ]
    x_sorted = [opt_result['x'][sorted_par_idx[ix]] for ix in
                range(len(problem.x_names))]
    opt_result['x'] = x_sorted
    result.optimize_result.append(opt_result)

result.optimize_result.sort()


prefix = '__'.join([MODEL, DATA, str(N_HIDDEN), OPTIMIZER])

waterfall(result, scale_y='log10', offset_y=0.0)
plot_and_save_fig(prefix + '__waterfall.pdf')

optimizer_history(result, scale_y='log10')
plot_and_save_fig(prefix + '__optimizer_trace.pdf')

parameters(result)
plot_and_save_fig(prefix + '__parameters.pdf')

optimizer_convergence(result)
plot_and_save_fig(prefix + '__optimizer_convergence.pdf')

fig_embedding, axes_embedding = plt.subplots(1, N_STARTS,
                                             figsize=(18.5, 10.5))

embedding_fun = theano.function(
    [mae.encoder_pars],
    mae.encode(mae.encoder_pars)
)
                     balance_alpha=False)
visualize.parameters(result1_dogleg,
                     legends='dogleg',
                     reference=ref,
                     size=(15, 10),
                     start_indices=[0, 1, 2, 3, 4, 5],
                     balance_alpha=False)

df = result1_tnc.optimize_result.as_dataframe(
    ['fval', 'n_fval', 'n_grad', 'n_hess', 'n_res', 'n_sres', 'time'])
df.head()

###### Optimizer History
# plot one list of waterfalls
visualize.optimizer_history([result1_bfgs, result1_tnc],
                            legends=['L-BFGS-B', 'TNC'],
                            reference=ref)
# plot one list of waterfalls
visualize.optimizer_history(result1_dogleg, reference=ref)

# plot one list of waterfalls
visualize.optimizer_history([result1_bfgs, result1_tnc],
                            legends=['L-BFGS-B', 'TNC'],
                            reference=ref,
                            offset_y=0.)

# plot one list of waterfalls
visualize.optimizer_history([result1_bfgs, result1_tnc],
                            legends=['L-BFGS-B', 'TNC'],
                            reference=ref,
                            scale_y='lin',