Ejemplo n.º 1
0
def test_limit(parameters2):
    mu, alpha, beta = parameters2
    loc_limit = 10
    try:
        pyhawkes.sim_exp_hawkes(mu,
                                alpha,
                                beta,
                                length=T,
                                max=loc_limit,
                                rseed=seed)
    except RuntimeError:
        assert True
    else:
        assert False
Ejemplo n.º 2
0
def test_stationarity():
    mu = np.array([0.15, 0.15], dtype=float)
    alpha = np.array([[100, 100], [100, 100]], dtype=float)
    beta = np.array([[1, 1], [1, 1]], dtype=float)
    try:
        pyhawkes.sim_exp_hawkes(mu,
                                alpha,
                                beta,
                                length=T,
                                max=limit,
                                rseed=seed)
    except RuntimeError:
        assert True
    else:
        assert False
Ejemplo n.º 3
0
def hawkes_list(parameters2):
    mu, alpha, beta = parameters2
    hawkes = pyhawkes.sim_exp_hawkes(mu,
                                     alpha,
                                     beta,
                                     length=T,
                                     max=limit,
                                     rseed=seed)
    return hawkes
Ejemplo n.º 4
0
 def comp_list_stat_int(pos):
     mu, alpha, beta = parameters3
     hawkes = pyhawkes.sim_exp_hawkes(mu,
                                      alpha,
                                      beta,
                                      T,
                                      max=limit,
                                      rseed=seed)
     comp = pyhawkes.comp_exp_hawkes(mu, alpha, beta, hawkes, T)
     return comp[pos]
Ejemplo n.º 5
0
def test_exp_gen():
    mu = np.array([0.15], dtype=float)
    rho = np.array([[1]], dtype=float)
    m = np.array([[1]], dtype=float)
    M = np.array([[1]], dtype=int)
    epsilon = np.array([[0.5]], dtype=float)
    n = np.array([[0.5]], dtype=float)
    alpha = np.array([[0.5]], dtype=float)
    beta = np.array([[1]], dtype=float)
    hawkes_gen = pyhawkes.sim_gen_hawkes(mu,
                                         rho,
                                         m,
                                         M,
                                         epsilon,
                                         n,
                                         pfunc=base,
                                         length=T,
                                         max=limit,
                                         rseed=seed)
    hawkes_exp = pyhawkes.sim_exp_hawkes(mu,
                                         alpha,
                                         beta,
                                         length=T,
                                         max=limit,
                                         rseed=seed)
    comp_gen = pyhawkes.comp_gen_hawkes(mu,
                                        rho,
                                        m,
                                        M,
                                        epsilon,
                                        n,
                                        events=hawkes_gen,
                                        pfunc_int=base_int,
                                        length=T)
    comp_exp = pyhawkes.comp_exp_hawkes(mu,
                                        alpha,
                                        beta,
                                        events=hawkes_exp,
                                        length=T)
    _, p_value_gen = scipy.stats.kstest(comp_gen[0], 'expon', args=(0, 1))
    _, p_value_exp = scipy.stats.kstest(comp_exp[0], 'expon', args=(0, 1))
    ll_gen = pyhawkes.lik_gen_hawkes(mu,
                                     rho,
                                     m,
                                     M,
                                     epsilon,
                                     n,
                                     pfunc=base,
                                     pfunc_int=base_int,
                                     events=hawkes_gen,
                                     length=T)
    ll_exp = pyhawkes.lik_exp_hawkes(mu, alpha, beta, hawkes_exp, length=T)
    assert len(hawkes_exp[0]) == len(hawkes_gen[0])
    assert np.round(p_value_exp, 4) == np.round(p_value_gen, 4)
    assert np.abs(ll_exp - ll_gen) < 10
Ejemplo n.º 6
0
def test_ll(hawkes_list_stat, parameters3):
    mu, alpha, beta = parameters3
    mu = np.array([0.05, 0.3, 0.25])
    alpha = np.array([[0.4, 0.3, 0.1], [0.3, 0.4, 0.23], [0.18, 0.43, 0.31]])
    beta = np.array([[1, 2, 9], [1.2, 1.8, 1.4], [4.9, 1.15, 8.5]])
    hawkes = pyhawkes.sim_exp_hawkes(mu,
                                     alpha,
                                     beta,
                                     length=100000,
                                     max=200000,
                                     rseed=123)
    log_likelihood = pyhawkes.lik_exp_hawkes(mu, alpha, beta, hawkes, T)
    assert np.round(log_likelihood) == 204777
Ejemplo n.º 7
0
def hawkes_list_stat(parameters3):
    mu, alpha, beta = parameters3
    hawkes = pyhawkes.sim_exp_hawkes(mu, alpha, beta, T, max=limit, rseed=seed)
    return hawkes
Ejemplo n.º 8
0
    mu2d = np.array([0.25, 0.2, 0.25, 0.2], dtype=float)

    mu3d = np.array([0.13, 0.17, 0.13, 0.17, 0.13, 0.17], dtype=float)


    """
    1D
    """

    # EXPONENTIAL WITH CONSTANT BASE INTENSITY
    mu = np.array([0.5])
    alpha = np.array([[0.4]])
    beta = np.array([[0.8]])
    begin = time.time()
    hawkes = pyhawkes.sim_exp_hawkes(mu, alpha, beta, length=T, max=max_jumps, rseed=seed)
    end = time.time()
    logger.info("1D Hawkes simulation with an exponential kernel with constant base intensity of length "
                "{} lasted for {} s".format(len(hawkes[0]), end - begin))

    # EXPONENTIAL WITH QUADRATIC BASE INTENSITY
    rho = 1 / beta
    m = np.array([[1]], dtype=float)
    M = np.array([[1]], dtype=int)
    epsilon = np.array([[0.2]], dtype=float)
    n = alpha / beta
    begin = time.time()
    hawkes = pyhawkes.sim_gen_hawkes(mu1d, rho, m, M, epsilon, n, length=T, max=max_jumps,
                                     rseed=seed, pfunc=base)
    end = time.time()
    logger.info("1D Hawkes simulation with an exponential kernel with quadratic base intensity of length "