# don't overwrite... results = [ [] for h in hs] means = np.zeros(hs.shape) stdevs = np.zeros(hs.shape) for H_i, H in enumerate(hs): print(H) for j in range(0,stat_n): print(" ",j) z2d = fract.fbm2D_spectral(H, N) try: res1 = fract.dfa_H(z2d, data=False) print(" ",res1) except Exception as ex: res1 = np.nan print("Exception ", ex) results[H_i].append(res1) np_res = np.array(results) if first_time == False: disk_np_res = np.hstack(( disk_np_res, np_res )) elif first_time == True: disk_np_res = np_res
stdevs = np.zeros(hs.shape) for H_i, H in enumerate(hs): gen_params = fract.save_fbm2D_exact_generator_params(H,N) print(H) for j in range(0,stat_n//2): print(" ",j) z2d1, z2d2 = fract.fbm2D_exact_from_generator(*gen_params) z2d1 = fract.cut_profile(z2d1, contour_H) z2d2 = fract.cut_profile(z2d2, contour_H) res1 = 0 res2 = 0 try: detect_H1 = fract.dfa_H(z2d1, data=False) print(" ",detect_H1) except Exception as ex: res1 = np.nan print("Exception ", ex) try: detect_H2 = fract.dfa_H(z2d2, data=False) # print(" ",res2) except Exception as ex: res2 = np.nan print("Exception ", ex) results[H_i].append(detect_H1) results[H_i].append(detect_H2)
for (i, H) in enumerate(np.arange(start, stop=stop, step=step)): # H = start + i*step stat_res = np.zeros(stat_n) print("H", H) for j in range(1, stat_n): # generate # Random.seed!(729 + i*34); data = fract.fbm2D(H, N=N) data_plane, _ = np.mgrid[0:data.shape[0], 0:data.shape[1]] # data = data + data_plane/5.0 # dfa h_detected, c, scales, flucts = fract.dfa_H(data, approx="quadratic", estimator="rms") stat_res[j] = h_detected # print(" ", j) av_h_detected = np.mean(stat_res) std_h_detected = np.std(stat_res) print(" av. H detected =", av_h_detected) newrow = np.transpose([H, av_h_detected, std_h_detected]) res[i, :] = newrow # print(res) plt.errorbar(res[:, 0], res[:, 1], yerr=res[:, 2]) plt.xlabel("generation H") plt.ylabel("detected H")
print("data_H", data_H) for (i, contour_H) in enumerate(np.arange(start, stop=stop, step=step)): stat_res = np.zeros(stat_n) # print("contour_H", contour_H) for j in range(1, stat_n): # generate data = fract.fbm2D(data_H, N=N) data = cut_profile(data, contour_H) # plt.imshow(data) # plt.show() # dfa try: h_detected, c, scales, flucts = fract.dfa_H(data) stat_res[j] = h_detected except: stat_res[j] = np.nan av_h_detected = np.mean(stat_res[~np.isnan(stat_res)]) std_h_detected = np.std(stat_res[~np.isnan(stat_res)]) # print(" av. H detected =", av_h_detected) newrow = np.transpose([contour_H, av_h_detected, std_h_detected]) res[i, :] = newrow # full square stat_res_fullsq = np.zeros(stat_n) for j in range(1, stat_n): # generate
def dfa_H_discard(*args, **kwargs): try: dfa_H, dfa_c, scales3, flucts3 = fract.dfa_H(*args, **kwargs) return dfa_H except: return np.nan
print("fourier_H", fourier_H) plt.figure() plt.scatter(freqs, powers) plt.plot(freqs, fract.power_law(freqs, freq_exp, f_c), color="red", label="fourier") plt.xscale("log") plt.yscale("log") plt.legend() plt.show() #### dfa dfa_H, dfa_c, scales3, flucts3 = fract.dfa_H(npy_points, messages=False, min_nonzero=0.99) print("dfa_H", dfa_H) ### first branch dfa_H2, c2, pcov = fract.autoseeded_weighted_power_law_fit( scales3[:17], flucts3[:17], flucts3[:17]) print("dfa_H2", dfa_H2) plt.figure() plt.scatter(scales3, flucts3) plt.plot(scales3, fract.power_law(scales3, dfa_H, dfa_c), color="springgreen", label="dfa: H =" + str(dfa_H)) plt.plot(scales3,
means = np.zeros(hs.shape) stdevs = np.zeros(hs.shape) for H_i, H in enumerate(hs): gen_params = fract.save_fbm2D_exact_generator_params(H,N) print(H) for j in range(0,stat_n//2): print(" ",j) z2d1, z2d2 = fract.fbm2D_exact_from_generator(*gen_params) res1 = 0 res2 = 0 try: res1 = fract.dfa_H(z2d1, data=False) print(" ",res1) except Exception as ex: res1 = np.nan print("Exception ", ex) try: res2 = fract.dfa_H(z2d2, data=False) # print(" ",res2) except Exception as ex: res2 = np.nan print("Exception ", ex) results[H_i].append(res1) results[H_i].append(res2)
# mixed scale # small z2d = fract.fbm2D(0.6, N=9) # large z2d += fract.fbm2D(0.1, N=9) ## fourier fourier_H, freq_exp, f_c, freqs, powers = fract.fourier_H(np.copy(z2d), fill_with_mean=True, images=True, corr=True) print("fourier_H", fourier_H) #### dfa dfa_H, c, scales3, flucts3 = fract.dfa_H(z2d, messages=False, min_nonzero=0.99) print("dfa_H", dfa_H) # fourier plot freq_exp_2, fc2, pcov = fract.autoseeded_weighted_power_law_fit( freqs[:20], powers[:20], powers[:20]) plt.figure() plt.scatter(freqs, powers) plt.plot(freqs, fract.power_law(freqs, freq_exp, f_c), color="red", label="fourier: H =" + str(fract.freq_exp_to_H(freq_exp))) plt.plot(freqs, fract.power_law(freqs, freq_exp_2, fc2),
import numpy as np import matplotlib.pyplot as plt import fract from fract import * N = 10 H = 0.8 z = fbm2D_exact(H, N) gen_params = fract.save_fbm2D_exact_generator_params(H, N) for j in range(5): z2d1, z2d2 = fract.fbm2D_exact_from_generator(*gen_params) try: res1 = fract.dfa_H(z2d1) print(" ", res1) except Exception as ex: res1 = np.nan print("Exception ", ex) try: res2 = fract.dfa_H(z2d2) # print(" ",res2) except Exception as ex: res2 = np.nan print("Exception ", ex)