src/orion/algo/tpe.py
def adaptive_parzen_estimator(
    mus, low, high, prior_weight=1.0, equal_weight=False, flat_num=25
):
    """Return the sorted mus, the corresponding sigmas and weights with adaptive kernel estimator.

    This adaptive parzen window estimator is based on the original papers and also refer the use of
    prior mean in `this implementation
    <https://github.com/hyperopt/hyperopt/blob/40bd617a0ca47e09368fb65919464ba0bfa85962/hyperopt/tpe.py#L400-L468>`_.

    :param mus: list of real values for observed mus.
    :param low: real value for lower bound of points.
    :param high: real value for upper bound of points.
    :param prior_weight: real value for the weight of the prior mean.
    :param equal_weight: bool value indicating if all points with equal weights.
    :param flat_num: int value indicating the number of the most recent trials which
        get the full weight where the others will be applied with a linear ramp
        from 0 to 1.0. It will only take effect if equal_weight is False.
    """
    mus = numpy.asarray(mus)

    prior_mu = (low + high) * 0.5
    prior_sigma = (high - low) * 1.0

    size = len(mus)
    if size > 1:
        order = numpy.argsort(mus)
        sorted_mus = mus[order]
        prior_mu_pos = numpy.searchsorted(sorted_mus, prior_mu)

        weights = ramp_up_weights(size, flat_num, equal_weight)

        mixture_mus = numpy.zeros(size + 1)
        mixture_mus[:prior_mu_pos] = sorted_mus[:prior_mu_pos]
        mixture_mus[prior_mu_pos] = prior_mu
        mixture_mus[prior_mu_pos + 1 :] = sorted_mus[prior_mu_pos:]

        mixture_weights = numpy.ones(size + 1)
        mixture_weights[:prior_mu_pos] = weights[:prior_mu_pos]
        mixture_weights[prior_mu_pos] = prior_weight
        mixture_weights[prior_mu_pos + 1 :] = weights[prior_mu_pos:]

        sigmas = numpy.ones(size + 1)
        sigmas[0] = mixture_mus[1] - mixture_mus[0]
        sigmas[-1] = mixture_mus[-1] - mixture_mus[-2]
        sigmas[1:-1] = numpy.maximum(
            (mixture_mus[1:-1] - mixture_mus[0:-2]),
            (mixture_mus[2:] - mixture_mus[1:-1]),
        )
        sigmas = numpy.clip(
            sigmas, prior_sigma / max(10, numpy.sqrt(size)), prior_sigma
        )

    else:
        if prior_mu < mus[0]:

            mixture_mus = numpy.array([prior_mu, mus[0]])
            sigmas = numpy.array([prior_sigma, prior_sigma * 0.5])
            mixture_weights = numpy.array([prior_weight, 1.0])
        else:
            mixture_mus = numpy.array([mus[0], prior_mu])
            sigmas = numpy.array([prior_sigma * 0.5, prior_sigma])
            mixture_weights = numpy.array([1.0, prior_weight])

    weights = mixture_weights / mixture_weights.sum()

    return mixture_mus, sigmas, weights
Return the sorted mus, the corresponding sigmas and weights with adaptive kernel estimator.

    This adaptive parzen window estimator is based on the original papers and also refer the use of
    prior mean in `this implementation
    <https://github.com/hyperopt/hyperopt/blob/40bd617a0ca47e09368fb65919464ba0bfa85962/hyperopt/tpe.py#L400-L468>`_.

    :param mus: list of real values for observed mus.
    :param low: real value for lower bound of points.
    :param high: real value for upper bound of points.
    :param prior_weight: real value for the weight of the prior mean.
    :param equal_weight: bool value indicating if all points with equal weights.
    :param flat_num: int value indicating the number of the most recent trials which
        get the full weight where the others will be applied with a linear ramp
        from 0 to 1.0. It will only take effect if equal_weight is False.
    
Return the sorted mus, the corresponding sigmas and weights with adaptive kernel estimator.
This adaptive parzen window estimator is based on the original papers and also refer the use of
prior mean in `this implementation
`_.
Return the sorted mus the corresponding sigmas and weights with adaptive kernel estimator . This adaptive parzen window estimator is based on the original papers and also refer the use of prior mean in ` this implementation ` _ .
def adaptive_parzen_estimator(
    mus, low, high, prior_weight=1.0, equal_weight=False, flat_num=25
):
    mus = numpy.asarray(mus)
    prior_mu = (low + high) * 0.5
    prior_sigma = (high - low) * 1.0
    size = len(mus)
    if size > 1:
        order = numpy.argsort(mus)
        sorted_mus = mus[order]
        prior_mu_pos = numpy.searchsorted(sorted_mus, prior_mu)
        weights = ramp_up_weights(size, flat_num, equal_weight)
        mixture_mus = numpy.zeros(size + 1)
        mixture_mus[:prior_mu_pos] = sorted_mus[:prior_mu_pos]
        mixture_mus[prior_mu_pos] = prior_mu
        mixture_mus[prior_mu_pos + 1 :] = sorted_mus[prior_mu_pos:]
        mixture_weights = numpy.ones(size + 1)
        mixture_weights[:prior_mu_pos] = weights[:prior_mu_pos]
        mixture_weights[prior_mu_pos] = prior_weight
        mixture_weights[prior_mu_pos + 1 :] = weights[prior_mu_pos:]
        sigmas = numpy.ones(size + 1)
        sigmas[0] = mixture_mus[1] - mixture_mus[0]
        sigmas[-1] = mixture_mus[-1] - mixture_mus[-2]
        sigmas[1:-1] = numpy.maximum(
            (mixture_mus[1:-1] - mixture_mus[0:-2]),
            (mixture_mus[2:] - mixture_mus[1:-1]),
        )
        sigmas = numpy.clip(
            sigmas, prior_sigma / max(10, numpy.sqrt(size)), prior_sigma
        )
    else:
        if prior_mu < mus[0]:
            mixture_mus = numpy.array([prior_mu, mus[0]])
            sigmas = numpy.array([prior_sigma, prior_sigma * 0.5])
            mixture_weights = numpy.array([prior_weight, 1.0])
        else:
            mixture_mus = numpy.array([mus[0], prior_mu])
            sigmas = numpy.array([prior_sigma * 0.5, prior_sigma])
            mixture_weights = numpy.array([1.0, prior_weight])
    weights = mixture_weights / mixture_weights.sum()
    return mixture_mus, sigmas, weights
def adaptive_parzen_estimator ( mus , low , high , prior_weight = 1.0 , equal_weight = False , flat_num = 25 ) : mus = numpy . asarray ( mus ) prior_mu = ( low + high ) * 0.5 prior_sigma = ( high - low ) * 1.0 size = len ( mus ) if size > 1 : order = numpy . argsort ( mus ) sorted_mus = mus [ order ] prior_mu_pos = numpy . searchsorted ( sorted_mus , prior_mu ) weights = ramp_up_weights ( size , flat_num , equal_weight ) mixture_mus = numpy . zeros ( size + 1 ) mixture_mus [ : prior_mu_pos ] = sorted_mus [ : prior_mu_pos ] mixture_mus [ prior_mu_pos ] = prior_mu mixture_mus [ prior_mu_pos + 1 : ] = sorted_mus [ prior_mu_pos : ] mixture_weights = numpy . ones ( size + 1 ) mixture_weights [ : prior_mu_pos ] = weights [ : prior_mu_pos ] mixture_weights [ prior_mu_pos ] = prior_weight mixture_weights [ prior_mu_pos + 1 : ] = weights [ prior_mu_pos : ] sigmas = numpy . ones ( size + 1 ) sigmas [ 0 ] = mixture_mus [ 1 ] - mixture_mus [ 0 ] sigmas [ - 1 ] = mixture_mus [ - 1 ] - mixture_mus [ - 2 ] sigmas [ 1 : - 1 ] = numpy . maximum ( ( mixture_mus [ 1 : - 1 ] - mixture_mus [ 0 : - 2 ] ) , ( mixture_mus [ 2 : ] - mixture_mus [ 1 : - 1 ] ) , ) sigmas = numpy . clip ( sigmas , prior_sigma / max ( 10 , numpy . sqrt ( size ) ) , prior_sigma ) else : if prior_mu < mus [ 0 ] : mixture_mus = numpy . array ( [ prior_mu , mus [ 0 ] ] ) sigmas = numpy . array ( [ prior_sigma , prior_sigma * 0.5 ] ) mixture_weights = numpy . array ( [ prior_weight , 1.0 ] ) else : mixture_mus = numpy . array ( [ mus [ 0 ] , prior_mu ] ) sigmas = numpy . array ( [ prior_sigma * 0.5 , prior_sigma ] ) mixture_weights = numpy . array ( [ 1.0 , prior_weight ] ) weights = mixture_weights / mixture_weights . sum ( ) return mixture_mus , sigmas , weights
Return the sorted mus, the corresponding sigmas and weights with adaptive kernel estimator.
Return the sorted mus the corresponding sigmas and weights with adaptive kernel estimator .
"""Return the sorted mus, the corresponding sigmas and weights with adaptive kernel estimator.

    This adaptive parzen window estimator is based on the original papers and also refer the use of
    prior mean in `this implementation
    <https://github.com/hyperopt/hyperopt/blob/40bd617a0ca47e09368fb65919464ba0bfa85962/hyperopt/tpe.py#L400-L468>`_.

    :param mus: list of real values for observed mus.
    :param low: real value for lower bound of points.
    :param high: real value for upper bound of points.
    :param prior_weight: real value for the weight of the prior mean.
    :param equal_weight: bool value indicating if all points with equal weights.
    :param flat_num: int value indicating the number of the most recent trials which
        get the full weight where the others will be applied with a linear ramp
        from 0 to 1.0. It will only take effect if equal_weight is False.
    """
mus
list of real values for observed mus.
list of real values for observed mus .
low
real value for lower bound of points.
real value for lower bound of points .
high
real value for upper bound of points.
real value for upper bound of points .
prior_weight
real value for the weight of the prior mean.
real value for the weight of the prior mean .
equal_weight
bool value indicating if all points with equal weights.
bool value indicating if all points with equal weights .
flat_num
int value indicating the number of the most recent trials which
get the full weight where the others will be applied with a linear ramp
from 0 to 1.0. It will only take effect if equal_weight is False.
int value indicating the number of the most recent trials which get the full weight where the others will be applied with a linear ramp from 0 to 1 . 0 . It will only take effect if equal_weight is False .