Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- PRECISION = 100
- def osc(tau, f, x, precision=10000):
- ens = np.linspace(x-tau, x+tau, precision)
- # Computes (precision)-values of f between x-tau and x+tau
- voisinage = f(ens)
- # returns the maximum amplitude
- return abs(np.amax(voisinage) - np.amin(voisinage))
- vect_osc = np.vectorize(osc)
- def var(tau, f, a, b):
- global PRECISION
- x = np.linspace(a, b, PRECISION)
- # Computes the oscillation of f for different values of x
- y = vect_osc(tau, f, x)
- # returns the average oscillation for each x around tau
- return np.average(y)
- vect_var = np.vectorize(var)
- def variation_dimension(f, a, b):
- global PRECISION
- # from 0.00...001 to 0.99...99 since log(1) = 0 and log(0) is undefined
- taus = np.linspace(1e-9, 1-1e-9, PRECISION)
- # Computes the variation for different values of tau
- variations = vect_var(taus, f, a, b)
- # Fits linearly the x=log(taus) and y=log(variations)
- coeffs = np.polyfit(np.log(taus), np.log(variations), 1)
- # Computes the estimated fractal dimension
- dim = 2 - coeffs[0]
- return dim, taus, variations
Advertisement
Add Comment
Please, Sign In to add comment