Skip to content

Instantly share code, notes, and snippets.

@mtmoses
Created August 6, 2021 04:11
Show Gist options
  • Save mtmoses/74c43a10d790bb96567c0a248a46303e to your computer and use it in GitHub Desktop.
Save mtmoses/74c43a10d790bb96567c0a248a46303e to your computer and use it in GitHub Desktop.
def estimate_multifractal_spectrum(TAU_Q, Q, MIN_Q, MAX_Q):
TAU_Q_ESTIMATED = np.polyfit(Q[MIN_Q:MAX_Q], TAU_Q[MIN_Q:MAX_Q], 2)
F_A = [0 for x in range(len(q)-10)]
p = [0 for x in range(len(q)-10)]
a = TAU_Q_ESTIMATED[0][0]
b = TAU_Q_ESTIMATED[1][0]
c = TAU_Q_ESTIMATED[2][0]
for i in range(0, len(q)-10):
p[i] = 2*a*Q[i]+b
F_A[i] = ((p[i]-b)/(2*a))*p[i] - (a*((p[i]-b)/(2*a))**2 + b*((p[i]-b)/(2*a)) + c)
F_A = pd.DataFrame(F_A)
F_A.rename(columns={F_A.columns[0]:"f(a)"}, inplace=True)
F_A['p'] = p
print("Using the range of q's from " + str(Q[MIN_Q]) + " to " + str(Q[MAX_Q]) + ":")
print("The estimated parameters for tau(q) are: \n" + str(TAU_Q_ESTIMATED))
print("\nThus, the estimated parameters for f(a) are: \n" + str(1/(4*a)) + ", \n" + str((-2*b)/(4*a)) + ", \n"+ str((-4*a*c+b**2)/(4*a)))
return F_A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment