Exemple #1
0
def find_opt_h(x_list, eps):
    N = len(x_list)
    X = x_list
    shift = min(X)
    X_shifted = [x - shift for x in X]

    scale = 1 / max(X_shifted)
    X_shifted_scale = [x * scale for x in X_shifted]

    sigma = stdev(X_shifted_scale)

    phi6 = (-15 / (16 * math.sqrt(math.pi))) * math.pow(sigma, -7)
    phi8 = (105 / (32 * math.sqrt(math.pi))) * math.pow(sigma, -9)

    g1 = (-6 / (math.sqrt(2 * math.pi) * phi6 * N))**(1 / 7)
    g2 = (30 / (math.sqrt(2 * math.pi) * phi8 * N))**(1 / 9)

    D4 = FUDD(N, N, X_shifted_scale, X_shifted_scale, g1, 4, eps)
    D4.evaluate()
    phi4 = sum(D4.pD) / (N - 1)

    D6 = FUDD(N, N, X_shifted_scale, X_shifted_scale, g2, 6, eps)
    D6.evaluate()
    phi6 = sum(D6.pD) / (N - 1)

    constant1 = (1 / (2 * math.sqrt(math.pi) * N))**(1 / 5)
    constant2 = (-6 * math.sqrt(2) * phi4 / phi6)**(1 / 7)

    h_initial = constant1 * phi4**(-1 / 5)

    h = ls(
        fast_h_fun,
        h_initial,
        bounds=(0, np.inf),
        ftol=1e-14,
        xtol=1e-14,
        verbose=1,
        args=(N, X_shifted_scale, constant1, constant2, eps),
    )

    h = float(h.x) / scale
    print(h)

    sortX = sorted(X_shifted_scale)
    D0 = FUDD(N, N, sortX, sortX, h, 0, eps)
    D0.evaluate()
    return h, D0.pD
def _get_opt_h(x_list, eps):
    N = len(x_list)
    X_shifted_scale, scale = _get_scale_list(x_list)

    sigma = std(X_shifted_scale)

    phi6 = (-15 / (16 * sqrt(pi))) * power(sigma, -7)
    phi8 = (105 / (32 * sqrt(pi))) * power(sigma, -9)

    g1 = (-6 / (sqrt(2 * pi) * phi6 * N))**(1 / 7)
    g2 = (30 / (sqrt(2 * pi) * phi8 * N))**(1 / 9)

    D4 = FUDD(N, N, X_shifted_scale, X_shifted_scale, g1, 4, eps)
    D6 = FUDD(N, N, X_shifted_scale, X_shifted_scale, g2, 6, eps)

    D4.evaluate()
    D6.evaluate()

    phi4 = sum(D4.pD) / (N - 1)
    phi6 = sum(D6.pD) / (N - 1)

    constant1 = (1 / (2 * sqrt(pi) * N))**(1 / 5)
    constant2 = (-6 * sqrt(2) * phi4 / phi6)**(1 / 7)

    h_initial = constant1 * phi4**(-1 / 5)
    h = ls(
        _fast_h_fun,
        h_initial,
        bounds=(0, inf),
        ftol=1e-14,
        xtol=1e-14,
        verbose=0,
        args=(N, X_shifted_scale, constant1, constant2, eps),
    )
    h = float(h.x) / scale
    return h
Exemple #3
0
def fast_h_fun(h, N, X, c1, c2, eps):
    lam = c2 * h**(5 / 7)
    D4 = FUDD(N, N, X, X, float(lam), 4, eps)
    D4.evaluate()
    phi4 = sum(D4.pD) / (N - 1)
    return h - c1 * phi4**(-1 / 5)