def plot_syj_against_j(j1=2, j2=6, wtype=1, theoretical_Hurst=0.8, idx_simulation=0, OUTPUT_FILE=None): idx = int(theoretical_Hurst * 10) - 1 if(idx < 0 or idx > 10): idx = 7 simulation = np.cumsum(opas.get_simulation(), axis=-1) dico = wtspecq_statlog3(simulation[idx,idx_simulation], 2, 1, np.array(2), int(np.log2(simulation[idx,idx_simulation].shape[0])), 0, 0) Elog = dico['Elogmuqj'][0] Varlog = dico['Varlogmuqj'][0] nj = dico['nj'] regression = regrespond_det2(Elog, Varlog, nj, j1, j2, wtype) font = {'family' : 'normal', 'weight' : 'bold', 'size' : 22} changefont('font', **font) jmax = len(Elog) j_indices = np.arange(0,jmax + 2) fig = plt.plot(j_indices, j_indices * regression['Zeta'] + regression['aest']) plt.text(j_indices.mean() - 2 * j_indices.var() / jmax, Elog.mean() + Elog.var() / jmax, r'Hurst Exponent = %.2f'%(regression['Zeta']/2)) j_indices = np.arange(0,jmax) + 1 plt.plot(j_indices, Elog, 'ro') plt.xlabel('scale j') plt.ylabel('log Sy(j,2)') if not OUTPUT_FILE is None: plt.savefig(OUTPUT_FILE) plt.show()
def compute_estimators(length_simul): simulations = opas.get_simulation()[:,:,:length_simul] shape = (9, 1000, length_simul) simulations = np.reshape(simulations, (9000, length_simul)) N = simulations.shape[0] wavelet_estim = np.zeros(N) nb_vanishmoment = 2 j1 = 2 j2 = 6 wtype = 1 simulationsCS = np.cumsum(simulations, axis=-1) dico = wtspecq_statlog32(simulationsCS, nb_vanishmoment, 1, np.array(2), int(np.log2(length_simul)), 0, 0) Elog = dico['Elogmuqj'][:, 0] Varlog = dico['Varlogmuqj'][:, 0] nj = dico['nj'] for j in np.arange(0, N): sortie = regrespond_det2(Elog[j], Varlog[j], 2, nj, j1, j2, wtype) wavelet_estim[j] = sortie['Zeta'] / 2. wavelet_estim = np.reshape(wavelet_estim, shape[:-1]) welch_estim = welch_estimator(simulations) welch_estim = np.reshape(welch_estim, shape[:-1]) dfa_estim = hurstexp_dfa(simulations, CumSum=1) dfa_estim = np.reshape(dfa_estim, shape[:-1]) return wavelet_estim, welch_estim, dfa_estim
def compute_dfa_estimators(length_simul=4069, printout=0): simulations = opas.get_simulation()[:,:,:length_simul] shape = (9, 1000, length_simul) simulations = np.reshape(simulations, (9000, length_simul)) N = simulations.shape[0] j1 = 2 j2 = 6 wtype = 1 dfa_estim, dico = hurstexp_dfa(simulations, CumSum=1, polyfit=1) dfa_estim1, dico = hurstexp_dfa(simulations, CumSum=1) dfa_estim2, dico = hurstexp_dfa(simulations, CumSum=1, wtype=0) k = 0 if printout!=0: f, myplot = plt.subplots(1, 3, sharey=True) f.suptitle('Estimation of Hurst coefficient of fGn\nof length 514 by dfa implementation') for idx_subplot, (title, stat) in enumerate(zip(['dfa0', 'dfa1', 'dfa2'], [np.reshape(dfa_estim, shape[:-1]), np.reshape(dfa_estim1, shape[:-1]), np.reshape(dfa_estim2, shape[:-1])])): myplot[idx_subplot].set_title(title) bp = myplot[idx_subplot].boxplot(stat.T) for line in bp['medians']: x, y = line.get_xydata()[1] if(k <6): myplot[idx_subplot].text(x + 1.5, y - 0.02, '%.3f\n%.3e' % (np.mean(stat[k, :]), np.var(stat[k,:])), horizontalalignment='center') else: myplot[idx_subplot].text(x - 2, y - 0.02, '%.3f\n%.3e' % (np.mean(stat[k, :]), np.var(stat[k, :])), horizontalalignment='center') k += 1 k = 0 plt.show() return dfa_estim, dfa_estim1, dfa_estim2