コード例 #1
0
ファイル: nets.py プロジェクト: javurena7/tie_strengths
def iet_stats(x, end, start):
    """
    Function for obtaining data based on the sequence of events and the IET distribution
    Returns:
    mu = mean iet with KM
    siggma = std iet with KM
    burst = burstiness with KM
    mu_r  = avg relay time with KM
    r_frsh = relative freshness
    age = age of tie
    t_stab = temporal stability of the tie
    memory = memory coefficient of the tie
    """

    c_norm = 1  #60*60*24
    last = (end - start) / c_norm
    estimator = events.IntereventTimeEstimator(last, mode='censorall')
    w = len(x)
    x = [(t - start) / c_norm for t in x]
    estimator.add_time_seq(x)

    mu = estimator.estimate_moment(1, 'km')
    mu_na = estimator.estimate_moment(1, 'naive')
    if not mu_na:
        mu_na = np.inf

    try:
        mu2 = estimator.estimate_moment(2, 'km')
        sigma = np.sqrt(mu2 - mu**2)
    except:
        mu2 = np.inf
        sigma = np.inf

    try:
        burst = (sigma - mu) / (sigma + mu)
    except:
        burst = np.nan

    try:
        mu_r = (.5) * (mu2 / mu)
    except:
        mu_r = np.inf

    try:
        r_frsh = (last - x[-1]) / mu_na
    except:
        r_frsh = np.inf

    age = x[0]
    t_stab = x[-1] - x[0]

    try:
        m = memory_coefficient(x)
    except:
        m = np.nan

    return [w, mu_na, sigma, burst, mu_r, r_frsh, age, t_stab, m]
コード例 #2
0
ファイル: nets.py プロジェクト: javurena7/tie_strengths
def _km_versions(x, method, min_date=1167598799, max_date=1177970399.0):
    estimator = events.IntereventTimeEstimator(max_date, mode='censorall')
    if min_date is not None:
        x.insert(0, min_date)
    estimator.add_time_seq(x)
    mu = estimator.estimate_moment(1, method)
    var = estimator.estimate_moment(2, method)
    sigma = np.sqrt(var - mu**2)
    burst = (sigma - mu) / (sigma + mu)
    return round(mu, 2), round(var, 2), round(burst, 4)
コード例 #3
0
ファイル: nets.py プロジェクト: javurena7/tie_strengths
def inter_event_times(x, end, start, method='km'):
    """
    Obtains inter-event time estimators in terms of days

    """
    c_norm = 1.
    last = (end - start) / c_norm
    estimator = events.IntereventTimeEstimator(last, mode='censorall')
    x = [(t - start) / c_norm for t in x]
    estimator.add_time_seq(x)
    mu = estimator.estimate_moment(1, method)

    try:
        mu2 = estimator.estimate_moment(2, method)
        sigma = np.sqrt(mu2 - mu**2)
    except:
        mu2 = np.inf
        sigma = np.inf

    try:
        burst = (sigma - mu) / (sigma + mu)
    except:
        burst = np.nan

    try:
        avg_relay = (.5) * (mu2 / mu)
    except:
        avg_relay = np.inf

    try:
        n = len(x)
        r = sigma / mu
        burst_c = (np.sqrt(n + 1) * r - np.sqrt(n - 1)) / (
            (np.sqrt(n + 1) - 2) * r + np.sqrt(n - 1))
    except:
        burst_c = np.nan
    # RELATIVE FRESHNESS
    mu_na = estimator.estimate_moment(1, 'naive')
    try:
        r_fresh = (last - x[-1]) / mu_na
    except:
        r_fresh = np.inf
    # AGE OF TIE
    age_tie = x[0]

    # TEMPORAL STABILITY
    temp_stab = x[-1] - x[0]

    m = memory_coefficient(x)

    return [
        mu, sigma, burst, burst_c, r_fresh, age_tie, temp_stab, avg_relay, m
    ]
コード例 #4
0
ファイル: nets.py プロジェクト: javurena7/tie_strengths
def mean_inter_event_km(t_seq, mode='km+', max_date=1177970399., moment=1):
    """
    Other mode: naive
    """
    r = events.IntereventTimeEstimator(max_date, 'censorall')
    r.add_time_seq(t_seq)
    if mode == 'km+':
        mode = 'km'
        m = max(r.observed_iets)
        r.forward_censored_iets[m] = 1
        r.backward_censored_iets[m] = 1
    return r.estimate_moment(moment, mode)
コード例 #5
0
ファイル: nets.py プロジェクト: javurena7/tie_strengths
def km_residual_intervals(x, method='km', max_date=1177970399.):

    estimator = events.IntereventTimeEstimator(max_date, mode='censorall')
    if method == 'km+':
        method = 'km'
    if x[-1] < max_date:
        x.append(max_date)
    estimator.add_time_seq(x)
    m = max(estimator.observed_iets)
    estimator.forward_censored_iets[m] = 1
    estimator.backward_censored_iets[m] = 1
    mu = estimator.estimate_moment(1, method)
    return mu
コード例 #6
0
ファイル: nets.py プロジェクト: javurena7/tie_strengths
def km_burstiness(x, method='km', max_date=1177970399.):
    """
    Burstiness estimator with Mikko's library

    method='km' or 'naive', if 'km+', add values to be censored at beginning and end
    """
    estimator = events.IntereventTimeEstimator(max_date, mode='censorall')
    estimator.add_time_seq(x)
    #m = max(estimator.observed_iets)
    #estimator.forward_censored_iets[m] = 1
    #estimator.backward_censored_iets[m] = 1
    mu = estimator.estimate_moment(1, method)
    sigma = np.sqrt(estimator.estimate_moment(2, method) - mu**2)
    return (sigma - mu) / (sigma + mu)