Beispiel #1
0
def test_param_errors_is_dict_with_errors_after_fit(fit_func, fit_data):
    model = Model(fit_func)
    model.fit(*fit_data)
    err = np.array([model.param_errors[n] for n in model._param_names])

    expected_err = np.sqrt(np.diag(model.covariance))
    assert (np.array_equal(err, expected_err))
Beispiel #2
0
def test_plot_plots_fitted_func(fit_func, fit_data):
    model = Model(fit_func)
    model.fit(*fit_data)

    plt.figure()
    model.plot()

    assert (len(plt.gca().lines) > 0)
Beispiel #3
0
def test_plot_uses_dx_point_spacing(fit_func, fit_data):
    model = Model(fit_func)
    model.fit(*fit_data)

    plt.figure()
    model.plot(dx=0.1)

    line = plt.gca().lines[0]
    xdata = line.get_xdata()

    assert (len(xdata) == 60 or len(xdata) == 61)
Beispiel #4
0
def test_plot_uses_n_points(fit_func, fit_data):
    model = Model(fit_func)
    model.fit(*fit_data)

    plt.figure()
    model.plot(n=1000)

    line = plt.gca().lines[0]
    xdata = line.get_xdata()

    assert (len(xdata) == 1000)
Beispiel #5
0
def test_plot_uses_plot_style(fit_func, fit_data):
    model = Model(fit_func)
    model.fit(*fit_data)

    plt.figure()
    model.plot(style='--')

    line = plt.gca().lines[0]
    style = line.get_linestyle()

    assert (style == '--')
Beispiel #6
0
def test_fit_converts_data_to_numpy_array(fit_func):
    model = Model(fit_func)
    model.fit([-3, -2, 0, 2, 3], [5, 4, 0, 4, 5])

    assert (type(model._xdata) == np.ndarray)
    assert (type(model._ydata) == np.ndarray)
Beispiel #7
0
def test_fit_does_fit_with_guess_from_generator(fit_func, fit_data):
    model = Model(fit_func, guess_gen={'A': lambda x, y: 10})
    model.fit(*fit_data)
    assert (model._guess == [10, 1, 1])
Beispiel #8
0
def test_fit_does_fit(fit_func, fit_data):
    model = Model(fit_func)
    model.fit(*fit_data)
    assert (model._has_fitted)
Beispiel #9
0
def test_ydata_is_private_ydata_after_fit(fit_func, fit_data):
    model = Model(fit_func)
    model.fit(*fit_data)
    assert (np.array_equal(model.ydata, model._ydata))
Beispiel #10
0
def test_covariance_is_internal_cov_after_fit(fit_func, fit_data):
    model = Model(fit_func)
    model.fit(*fit_data)
    assert (np.array_equal(model.covariance, model._cov))
Beispiel #11
0
def test_resiuduals_is_array_with_residuals_after_fit(fit_func, fit_data):
    model = Model(fit_func)
    model.fit(*fit_data)

    expected_residuals = fit_data[1] - model.fitted_func(fit_data[0])
    assert (np.array_equal(model.residuals, expected_residuals))
Beispiel #12
0
def test_params_is_dict_with_optimal_parameters_after_fit(fit_func, fit_data):
    model = Model(fit_func)
    model.fit(*fit_data)
    assert (sorted(model.params.keys()) == ['A', 'c', 'x0'])
Beispiel #13
0
def test_fitted_func_is_function_after_fit(fit_func, fit_data):
    model = Model(fit_func)
    model.fit(*fit_data)
    assert (callable(model.fitted_func))
Beispiel #14
0
def test_getattr_returns_fit_param_after_fit(fit_func, fit_data):
    model = Model(fit_func)
    model.fit(*fit_data)
    assert (isinstance(model.A, float))
Beispiel #15
0
def test_repr_html_is_html_table_after_fit(fit_func, fit_data):
    model = Model(fit_func)
    model.fit(*fit_data)
    assert ('<table>' in model._repr_html_())
Beispiel #16
0
def test_does_not_raise_outside_of_jupyter_notebook(fit_func, fit_data):
    model = Model(fit_func)
    model.fit(*fit_data)

    model.display_html()