def test_fit_simualtion():

    parameters = {
        'B_1A': 0.7,
        'B_2A': 0.0,
        'B_3A': 0.0,
        'C_1A': 10.0,
        'C_3A': 0.0,
        'C_5A': 0.0,
    }

    bounds = {
        'B_1A': (-np.inf, np.inf),  # Assuming only positive coefficients
        'B_2A': (-np.inf, np.inf),  # Assuming only positive coefficients
        'B_3A': (-np.inf, np.inf),  # Assuming only positive coefficients
    }

    direct_estimator = EstimatorCubic(fit_method='integration', bounds=bounds)
    phi0 = np.deg2rad(10)
    phi1d0 = 0
    t = np.arange(0, 10, 0.01)
    X = simulate(t=t, phi0=phi0, phi1d0=phi1d0, **parameters)

    X['phi2d'] = np.gradient(X['phi1d'].values, X.index.values)
    check(X=X, estimator=direct_estimator, parameters=parameters)
def test_fit_simualtion_full_cubic():

    parameters = {
        'B_1A': 0.7,
        'B_2A': 1.0,
        'B_3A': 3.0,
        'C_1A': 10.0,
        'C_3A': 10.0,
        'C_5A': 0.0,
    }

    direct_estimator = EstimatorCubic(fit_method='integration')
    phi0 = np.deg2rad(20)
    phi1d0 = 0
    t = np.arange(0, 10, 0.01)
    X = simulate(t=t, phi0=phi0, phi1d0=phi1d0, **parameters)

    X['phi2d'] = np.gradient(X['phi1d'].values, X.index.values)
    check(X=X, estimator=direct_estimator, parameters=parameters)
def test_simulation():

    parameters = {
        'B_1A': 0.3,
        'B_2A': 0.0,
        'B_3A': 0.0,
        'C_1A': 0.3,
        'C_3A': 0.0,
        'C_5A': 0.0,
    }

    phi0 = np.deg2rad(10)
    phi1d0 = 0
    t = np.arange(0, 10, 0.1)
    X = simulate(t=t, phi0=phi0, phi1d0=phi1d0, **parameters)

    direct_estimator = EstimatorCubic.load(**parameters)

    direct_estimator.is_fitted_ = True
    X_pred = direct_estimator.predict(X=X)
    assert_almost_equal(X['phi'].values, X_pred['phi'].values)
def test_fit_simualtion_cubic_damping_not_converged():

    parameters = {
        'B_1A': 0.7,
        'B_2A': 1.5,
        'B_3A': 5.0,
        'C_1A': 10.0,
        'C_3A': 0.0,
        'C_5A': 0.0,
    }

    direct_estimator = EstimatorCubic(
        fit_method='integration',
        maxfev=1,
    )
    phi0 = np.deg2rad(10)
    phi1d0 = 0
    t = np.arange(0, 10, 0.01)
    X = simulate(t=t, phi0=phi0, phi1d0=phi1d0, **parameters)

    X['phi2d'] = np.gradient(X['phi1d'].values, X.index.values)

    with pytest.raises(FitError):
        check(X=X, estimator=direct_estimator, parameters=parameters)
def simulate(t, phi0, phi1d0, **kwargs):

    estimator = EstimatorCubic.load(**kwargs)

    return estimator.simulate(t=t, phi0=phi0, phi1d0=phi1d0)