# Path: src/pylogit/bootstrap_utils.py
# def check_conf_percentage_validity(conf_percentage):
#     """
#     Ensures that `conf_percentage` is in (0, 100). Raises a helpful ValueError
#     if otherwise.
#     """
#     msg = "conf_percentage MUST be a number between 0.0 and 100."
#     condition_1 = isinstance(conf_percentage, Number)
#     if not condition_1:
#         raise ValueError(msg)
#     else:
#         condition_2 = 0 < conf_percentage < 100
#         if not condition_2:
#             raise ValueError(msg)
#     return None
# 
# Path: src/pylogit/bootstrap_utils.py
# def ensure_samples_is_ndim_ndarray(samples, name='bootstrap', ndim=2):
#     """
#     Ensures that `samples` is an `ndim` numpy array. Raises a helpful
#     ValueError if otherwise.
#     """
#     assert isinstance(ndim, int)
#     assert isinstance(name, str)
#     if not isinstance(samples, np.ndarray) or not (samples.ndim == ndim):
#         sample_name = name + "_samples"
#         msg = "`{}` MUST be a {}D ndarray.".format(sample_name, ndim)
#         raise ValueError(msg)
#     return None
# 
# Path: src/pylogit/bootstrap_utils.py
# def get_alpha_from_conf_percentage(conf_percentage):
#     """
#     Calculates `100 - conf_percentage`, which is useful for calculating alpha
#     levels.
#     """
#     return 100.0 - conf_percentage
# 
# Path: src/pylogit/bootstrap_utils.py
# def combine_conf_endpoints(lower_array, upper_array):
#     """
#     Concatenates upper and lower endpoint arrays for a given confidence level.
#     """
#     return np.concatenate([lower_array[None, :], upper_array[None, :]], axis=0)


import numpy as np
from scipy.stats import norm
from .bootstrap_utils import check_conf_percentage_validity
from .bootstrap_utils import ensure_samples_is_ndim_ndarray
from .bootstrap_utils import get_alpha_from_conf_percentage
from .bootstrap_utils import combine_conf_endpoints
    DiCiccio, Thomas J., and Bradley Efron. "Bootstrap confidence intervals."
        Statistical science (1996): 189-212.
    """
    # Check validity of arguments
    check_conf_percentage_validity(conf_percentage)
    ensure_samples_is_ndim_ndarray(bootstrap_replicates, ndim=2)
    ensure_samples_is_ndim_ndarray(jackknife_replicates,
                                   name='jackknife', ndim=2)
    # Calculate the alpha * 100% value
    alpha_percent = get_alpha_from_conf_percentage(conf_percentage)
    # Estimate the bias correction for the bootstrap samples
    bias_correction =\
        calc_bias_correction_bca(bootstrap_replicates, mle_params)
    # Estimate the acceleration
    acceleration = calc_acceleration_bca(jackknife_replicates)
    # Get the lower and upper percent value for the raw bootstrap samples.
    lower_percents =\
        calc_lower_bca_percentile(alpha_percent, bias_correction, acceleration)
    upper_percents =\
        calc_upper_bca_percentile(alpha_percent, bias_correction, acceleration)
    # Get the lower and upper endpoints for the desired confidence intervals.
    lower_endpoints = np.diag(np.percentile(bootstrap_replicates,
                                            lower_percents,
                                            interpolation='lower',
                                            axis=0))
    upper_endpoints = np.diag(np.percentile(bootstrap_replicates,
                                            upper_percents,
                                            interpolation='higher',
                                            axis=0))
    # Combine the enpoints into a single ndarray.

# Path: src/pylogit/bootstrap_utils.py
# def check_conf_percentage_validity(conf_percentage):
#     """
#     Ensures that `conf_percentage` is in (0, 100). Raises a helpful ValueError
#     if otherwise.
#     """
#     msg = "conf_percentage MUST be a number between 0.0 and 100."
#     condition_1 = isinstance(conf_percentage, Number)
#     if not condition_1:
#         raise ValueError(msg)
#     else:
#         condition_2 = 0 < conf_percentage < 100
#         if not condition_2:
#             raise ValueError(msg)
#     return None
# 
# Path: src/pylogit/bootstrap_utils.py
# def ensure_samples_is_ndim_ndarray(samples, name='bootstrap', ndim=2):
#     """
#     Ensures that `samples` is an `ndim` numpy array. Raises a helpful
#     ValueError if otherwise.
#     """
#     assert isinstance(ndim, int)
#     assert isinstance(name, str)
#     if not isinstance(samples, np.ndarray) or not (samples.ndim == ndim):
#         sample_name = name + "_samples"
#         msg = "`{}` MUST be a {}D ndarray.".format(sample_name, ndim)
#         raise ValueError(msg)
#     return None
# 
# Path: src/pylogit/bootstrap_utils.py
# def get_alpha_from_conf_percentage(conf_percentage):
#     """
#     Calculates `100 - conf_percentage`, which is useful for calculating alpha
#     levels.
#     """
#     return 100.0 - conf_percentage
# 
# Path: src/pylogit/bootstrap_utils.py
# def combine_conf_endpoints(lower_array, upper_array):
#     """
#     Concatenates upper and lower endpoint arrays for a given confidence level.
#     """
#     return np.concatenate([lower_array[None, :], upper_array[None, :]], axis=0)


# Path: src/pylogit/bootstrap_calcs.py
import numpy as np
from scipy.stats import norm
from .bootstrap_utils import check_conf_percentage_validity
from .bootstrap_utils import ensure_samples_is_ndim_ndarray
from .bootstrap_utils import get_alpha_from_conf_percentage
from .bootstrap_utils import combine_conf_endpoints

    DiCiccio, Thomas J., and Bradley Efron. "Bootstrap confidence intervals."
        Statistical science (1996): 189-212.
    """
    # Check validity of arguments
    check_conf_percentage_validity(conf_percentage)
    ensure_samples_is_ndim_ndarray(bootstrap_replicates, ndim=2)
    ensure_samples_is_ndim_ndarray(jackknife_replicates,
                                   name='jackknife', ndim=2)
    # Calculate the alpha * 100% value
    alpha_percent = get_alpha_from_conf_percentage(conf_percentage)
    # Estimate the bias correction for the bootstrap samples
    bias_correction =\
        calc_bias_correction_bca(bootstrap_replicates, mle_params)
    # Estimate the acceleration
    acceleration = calc_acceleration_bca(jackknife_replicates)
    # Get the lower and upper percent value for the raw bootstrap samples.
    lower_percents =\
        calc_lower_bca_percentile(alpha_percent, bias_correction, acceleration)
    upper_percents =\
        calc_upper_bca_percentile(alpha_percent, bias_correction, acceleration)
    # Get the lower and upper endpoints for the desired confidence intervals.
    lower_endpoints = np.diag(np.percentile(bootstrap_replicates,
                                            lower_percents,
                                            interpolation='lower',
                                            axis=0))
    upper_endpoints = np.diag(np.percentile(bootstrap_replicates,
                                            upper_percents,
                                            interpolation='higher',
                                            axis=0))
    # Combine the enpoints into a single ndarray.

    conf_intervals = combine_conf_endpoints(lower_endpoints, upper_endpoints)