def slice_ShrinkRank_nolog(xx, P, s0, transpose):
    """
    Implementation of the shrinking rank slice sampler.

    :param xx: Initial points for the sampler.
    :param P: The function that will be used as sampling density.
    :param s0:
    :param transpose:
    :return:
    """

    if transpose:
        xx = xx.transpose()

    D = xx.shape[0]
    f = P(xx.transpose())

    logf = np.log(f)

    logy = np.log(np.random.uniform()) + logf

    theta = 0.95

    k = 0
    s = np.array([s0])
    c = np.zeros((D, 0))
    J = np.zeros((D, 0))
    while True:
        k += 1
        c = np.append(c, np.array(projNullSpace(J, xx + s[k - 1] * np.random.randn(D, 1))), axis=1)
        sx = np.divide(1., np.sum(np.divide(1., s)))
        mx = np.dot(
            sx,
            np.sum(
                np.multiply(
                    np.divide(1., s),
                    np.subtract(c, xx)
                ),
                1))
        xk = xx + projNullSpace(J, mx.reshape((D, 1)) +
                                np.multiply(sx, np.random.normal(size=(D, 1))))

        # TODO: add the derivative values (we're not considering them yet)
        fk, dfk = P(xk.transpose(), derivative=True)
        logfk = np.log(fk)
        dlogfk = np.divide(dfk, fk)

        if (logfk > logy).all():  # accept these values
            xx = xk.transpose()
            return xx
        else:  # shrink
            g = projNullSpace(J, dlogfk)
            if J.shape[1] < D - 1 and \
               np.dot(g.transpose(), dlogfk) > 0.5 * np.linalg.norm(g) * np.linalg.norm(dlogfk):
                J = np.append(J, np.divide(g, np.linalg.norm(g)), axis=1)
                # s[k] = s[k-1]
                s = np.append(s, s[k - 1])
            else:
                s = np.append(s, np.multiply(theta, s[k - 1]))
                if s[k] < np.spacing(1):
                    logger.error(
                        'bug found: contracted down to zero step size, still not accepted.\n')
                if transpose:
                    xx = xx.transpose()
                    return xx
                else:
                    return xx
dataset/ETHPy150Open automl/RoBO/robo/sampling/sampling.py/slice_ShrinkRank_nolog/original