Beispiel #1
0
def g_erp(t0, t1, g):
    """
    Usage
    -----
    The Edit distance with Real Penalty between trajectory t0 and t1.

    Parameters
    ----------
    param t0 : len(t0)x2 numpy_array
    param t1 : len(t1)x2 numpy_array

    Returns
    -------
    dtw : float
          The Dynamic-Time Warping distance between trajectory t0 and t1
    """
    n0 = len(t0)
    n1 = len(t1)
    C = np.zeros((n0 + 1, n1 + 1))

    C[1:, 0] = sum(
        map(lambda x: abs(great_circle_distance(g[0], g[1], x[0], x[1])), t0))
    C[0, 1:] = sum(
        map(lambda y: abs(great_circle_distance(g[0], g[1], y[0], y[1])), t1))
    for i in np.arange(n0) + 1:
        for j in np.arange(n1) + 1:
            derp0 = C[i - 1, j] + great_circle_distance(
                t0[i - 1][0], t0[i - 1][1], g[0], g[1])
            derp1 = C[i, j - 1] + great_circle_distance(
                g[0], g[1], t1[j - 1][0], t1[j - 1][1])
            derp01 = C[i - 1, j - 1] + great_circle_distance(
                t0[i - 1][0], t0[i - 1][1], t1[j - 1][0], t1[j - 1][1])
            C[i, j] = min(derp0, derp1, derp01)
    erp = C[n0, n1]
    return erp
def g_erp(t0,t1,g):
    """
    Usage
    -----
    The Edit distance with Real Penalty between trajectory t0 and t1.

    Parameters
    ----------
    param t0 : len(t0)x2 numpy_array
    param t1 : len(t1)x2 numpy_array

    Returns
    -------
    dtw : float
          The Dynamic-Time Warping distance between trajectory t0 and t1
    """
    n0 = len(t0)
    n1 = len(t1)
    C=np.zeros((n0+1,n1+1))

    C[1:,0]=sum(map(lambda x : abs(great_circle_distance(g[0],g[1],x[0],x[1])),t0))
    C[0,1:]=sum(map(lambda y : abs(great_circle_distance(g[0],g[1],y[0],y[1])),t1))
    for i in np.arange(n0)+1:
        for j in np.arange(n1)+1:
            derp0 = C[i-1,j] + great_circle_distance(t0[i-1][0],t0[i-1][1],g[0],g[1])
            derp1 = C[i,j-1] + great_circle_distance(g[0],g[1],t1[j-1][0],t1[j-1][1])
            derp01 = C[i-1,j-1] + great_circle_distance(t0[i-1][0],t0[i-1][1],t1[j-1][0],t1[j-1][1])
            C[i,j] = min(derp0,derp1,derp01)
    erp = C[n0,n1]
    return erp
Beispiel #3
0
def g_dtw(t0, t1):
    """
    Usage
    -----
    The Dynamic-Time Warping distance between trajectory t0 and t1.

    Parameters
    ----------
    param t0 : len(t0)x2 numpy_array
    param t1 : len(t1)x2 numpy_array

    Returns
    -------
    dtw : float
          The Dynamic-Time Warping distance between trajectory t0 and t1
    """
    n0 = len(t0)
    n1 = len(t1)
    C = np.zeros((n0 + 1, n1 + 1))
    C[1:, 0] = float('inf')
    C[0, 1:] = float('inf')
    for i in np.arange(n0) + 1:
        for j in np.arange(n1) + 1:
            C[i, j] = great_circle_distance(
                t0[i - 1][0], t0[i - 1][1], t1[j - 1][0], t1[j - 1][1]) + min(
                    C[i, j - 1], C[i - 1, j - 1], C[i - 1, j])
    dtw = C[n0, n1]
    return dtw
def g_edr(t0, t1,eps):
    """
    Usage
    -----
    The Edit Distance on Real sequence between trajectory t0 and t1.

    Parameters
    ----------
    param t0 : len(t0)x2 numpy_array
    param t1 : len(t1)x2 numpy_array
    eps : float

    Returns
    -------
    edr : float
           The Longuest-Common-Subsequence distance between trajectory t0 and t1
    """
    n0 = len(t0)
    n1 = len(t1)
    # An (m+1) times (n+1) matrix
    C = [[0] * (n1+1) for _ in range(n0+1)]
    for i in range(1, n0+1):
        for j in range(1, n1+1):
            if great_circle_distance(t0[i-1][0],t0[i-1][1],t1[j-1][0],t1[j-1][1])<eps:
                subcost = 0
            else:
                subcost = 1
            C[i][j] = min(C[i][j-1]+1, C[i-1][j]+1,C[i-1][j-1]+subcost)
    edr = float(C[n0][n1])/max([n0,n1])
    return edr
Beispiel #5
0
def g_lcss(t0, t1, eps):
    """
    Usage
    -----
    The Longuest-Common-Subsequence distance between trajectory t0 and t1.

    Parameters
    ----------
    param t0 : len(t0)x2 numpy_array
    param t1 : len(t1)x2 numpy_array
    eps : float

    Returns
    -------
    lcss : float
           The Longuest-Common-Subsequence distance between trajectory t0 and t1
    """
    n0 = len(t0)
    n1 = len(t1)
    # An (m+1) times (n+1) matrix
    C = [[0] * (n1 + 1) for _ in range(n0 + 1)]
    for i in range(1, n0 + 1):
        for j in range(1, n1 + 1):
            if great_circle_distance(t0[i - 1, 0], t0[i - 1, 1], t1[j - 1, 0],
                                     t1[j - 1, 1]) < eps:
                C[i][j] = C[i - 1][j - 1] + 1
            else:
                C[i][j] = max(C[i][j - 1], C[i - 1][j])
    lcss = 1 - float(C[n0][n1]) / min([n0, n1])
    return lcss
def g_dtw(t0,t1):
    """
    Usage
    -----
    The Dynamic-Time Warping distance between trajectory t0 and t1.

    Parameters
    ----------
    param t0 : len(t0)x2 numpy_array
    param t1 : len(t1)x2 numpy_array

    Returns
    -------
    dtw : float
          The Dynamic-Time Warping distance between trajectory t0 and t1
    """
    n0 = len(t0)
    n1 = len(t1)
    C=np.zeros((n0+1,n1+1))
    C[1:,0]=float('inf')
    C[0,1:]=float('inf')
    for i in np.arange(n0)+1:
        for j in np.arange(n1)+1:
            C[i,j]=great_circle_distance(t0[i-1][0],t0[i-1][1],t1[j-1][0],t1[j-1][1]) + min(C[i,j-1],C[i-1,j-1],C[i-1,j])
    dtw = C[n0,n1]
    return dtw
def g_lcss(t0, t1,eps):
    """
    Usage
    -----
    The Longuest-Common-Subsequence distance between trajectory t0 and t1.

    Parameters
    ----------
    param t0 : len(t0)x2 numpy_array
    param t1 : len(t1)x2 numpy_array
    eps : float

    Returns
    -------
    lcss : float
           The Longuest-Common-Subsequence distance between trajectory t0 and t1
    """
    n0 = len(t0)
    n1 = len(t1)
    # An (m+1) times (n+1) matrix
    C = [[0] * (n1+1) for _ in range(n0+1)]
    for i in range(1, n0+1):
        for j in range(1, n1+1):
            if great_circle_distance(t0[i-1,0],t0[i-1,1],t1[j-1,0],t1[j-1,1])<eps:
                C[i][j] = C[i-1][j-1] + 1
            else:
                C[i][j] = max(C[i][j-1], C[i-1][j])
    lcss = 1-float(C[n0][n1])/min([n0,n1])
    return lcss
Beispiel #8
0
def g_edr(t0, t1, eps):
    """
    Usage
    -----
    The Edit Distance on Real sequence between trajectory t0 and t1.

    Parameters
    ----------
    param t0 : len(t0)x2 numpy_array
    param t1 : len(t1)x2 numpy_array
    eps : float

    Returns
    -------
    edr : float
           The Longuest-Common-Subsequence distance between trajectory t0 and t1
    """
    n0 = len(t0)
    n1 = len(t1)
    # An (m+1) times (n+1) matrix
    C = [[0] * (n1 + 1) for _ in range(n0 + 1)]
    for i in range(1, n0 + 1):
        for j in range(1, n1 + 1):
            if great_circle_distance(t0[i - 1][0], t0[i - 1][1], t1[j - 1][0],
                                     t1[j - 1][1]) < eps:
                subcost = 0
            else:
                subcost = 1
            C[i][j] = min(C[i][j - 1] + 1, C[i - 1][j] + 1,
                          C[i - 1][j - 1] + subcost)
    edr = float(C[n0][n1]) / max([n0, n1])
    return edr