def test_exponentiated_weibull_distribution_icdf():
    """
    Tests the ICDF of the exponentiated Weibull distribution.
    """
    # Define dist with parameters from the distribution fitted to
    # dataset A with the MLE in https://arxiv.org/pdf/1911.12835.pdf .
    dist = ExponentiatedWeibullDistribution(alpha=0.0373,
                                            beta=0.4743,
                                            delta=46.6078)

    # ICDF(0.5) should be roughly 0.8, see Figure 12 in
    # https://arxiv.org/pdf/1911.12835.pdf .
    x = dist.icdf(0.5)
    assert x > 0.5
    assert x < 1

    # ICDF(0.9) should be roughly 1.8, see Figure 12
    # in https://arxiv.org/pdf/1911.12835.pdf .
    x = dist.icdf(0.9)
    assert x > 1
    assert x < 2

    # ICDF(value greater than 1) should be nan.
    x = dist.icdf(5)
    assert np.isnan(x)
def test_ExponentiatedWeibull_pdf_cdf_icdf(exp_weibull_reference_data):
    OMAE2020_param = {"alpha": 10.0, "beta": 2.42, "delta": 0.761}
    x = np.linspace(2, 15, num=100)
    p = np.linspace(0.01, 0.99, num=100)
    my_expweibull = ExponentiatedWeibullDistribution(**OMAE2020_param)
    my_pdf = my_expweibull.pdf(x)
    my_cdf = my_expweibull.cdf(x)
    my_icdf = my_expweibull.icdf(p)

    ref_pdf = exp_weibull_reference_data["ref_pdf"]
    ref_cdf = exp_weibull_reference_data["ref_cdf"]
    ref_icdf = exp_weibull_reference_data["ref_icdf"]

    np.testing.assert_allclose(my_pdf, ref_pdf)
    np.testing.assert_allclose(my_cdf, ref_cdf)
    np.testing.assert_allclose(my_icdf, ref_icdf)
def test_ExponentiatedWeibull_wlsq_fit(exp_weibull_reference_data_wlsq_fit):
    x = np.linspace(2, 15, num=100)
    p = np.linspace(0.01, 0.99, num=100)

    true_alpha = 10
    true_beta = 2.42
    true_delta = 0.761
    expweibull_samples = sts.exponweib.rvs(a=true_delta,
                                           c=true_beta,
                                           loc=0,
                                           scale=true_alpha,
                                           size=100,
                                           random_state=42)

    my_expweibull = ExponentiatedWeibullDistribution()

    my_expweibull.fit(expweibull_samples, method="lsq", weights="quadratic")

    my_pdf = my_expweibull.pdf(x)
    my_cdf = my_expweibull.cdf(x)
    my_icdf = my_expweibull.icdf(p)
    my_alpha = my_expweibull.alpha
    my_beta = my_expweibull.beta
    my_delta = my_expweibull.delta

    ref_pdf = exp_weibull_reference_data_wlsq_fit["ref_pdf"]
    ref_cdf = exp_weibull_reference_data_wlsq_fit["ref_cdf"]
    ref_icdf = exp_weibull_reference_data_wlsq_fit["ref_icdf"]
    ref_alpha = exp_weibull_reference_data_wlsq_fit["ref_alpha"]
    ref_beta = exp_weibull_reference_data_wlsq_fit["ref_beta"]
    ref_delta = exp_weibull_reference_data_wlsq_fit["ref_delta"]

    np.testing.assert_allclose(my_alpha, ref_alpha)
    np.testing.assert_allclose(my_beta, ref_beta)
    np.testing.assert_allclose(my_delta, ref_delta)
    np.testing.assert_allclose(my_pdf, ref_pdf)
    np.testing.assert_allclose(my_cdf, ref_cdf)
    np.testing.assert_allclose(my_icdf, ref_icdf)
true_alpha = 10
true_beta = 2.42
true_delta = 0.761
expweibull_samples = sts.exponweib.rvs(
    a=true_delta, c=true_beta, loc=0, scale=true_alpha, size=100, random_state=42
)

# %%
# my_expweibull = ExponentiatedWeibullDistribution(**OMAE2020_param)
my_expweibull = ExponentiatedWeibullDistribution()

my_expweibull.fit(expweibull_samples, method="lsq", weights="quadratic")

my_pdf = my_expweibull.pdf(x)
my_cdf = my_expweibull.cdf(x)
my_icdf = my_expweibull.icdf(p)

my_alpha = my_expweibull.alpha
my_beta = my_expweibull.beta
my_delta = my_expweibull.delta

# %%
import sys

sys.path.append("../viroconcom")
from viroconcom.distributions import ExponentiatedWeibullDistribution

# ref_expweibull = ExponentiatedWeibullDistribution(shape=OMAE2020_param["beta"],
#                                                   scale=OMAE2020_param["alpha"],
#                                                   shape2=OMAE2020_param["delta"])