def hfd(X, Kmax):
    """ Compute Hjorth Fractal Dimension of a time series X, kmax
     is an HFD parameter
    """
    L = []
    x = []
    N = len(X)
    for k in range(1, Kmax):
        Lk = []
        for m in range(0, k):
            Lmk = 0
            for i in range(1, int(numpy.floor((N - m) / k))):
                Lmk += abs(X[m + i * k] - X[m + i * k - k])
            Lmk = Lmk * (N - 1) / numpy.floor((N - m) / float(k)) / k
            Lk.append(Lmk)
        L.append(numpy.log(numpy.mean(Lk)))
        x.append([numpy.log(float(1) / k), 1])

    (p, r1, r2, s) = numpy.linalg.lstsq(x, L)
    return p[0]
def hfd ( X , Kmax ) : L = [ ] x = [ ] N = len ( X ) for k in range ( 1 , Kmax ) : Lk = [ ] for m in range ( 0 , k ) : Lmk = 0 for i in range ( 1 , int ( numpy . floor ( ( N - m ) / k ) ) ) : Lmk += abs ( X [ m + i * k ] - X [ m + i * k - k ] ) Lmk = Lmk * ( N - 1 ) / numpy . floor ( ( N - m ) / float ( k ) ) / k Lk . append ( Lmk ) L . append ( numpy . log ( numpy . mean ( Lk ) ) ) x . append ( [ numpy . log ( float ( 1 ) / k ) , 1 ] ) ( p , r1 , r2 , s ) = numpy . linalg . lstsq ( x , L ) return p [ 0 ]
Compute Hjorth Fractal Dimension of a time series X, kmax
     is an HFD parameter