def _process_matrix_cond(self, jobq, resq): while True: a = jobq.get() # get queued input if a is None: # if it is None, we are finished, put poison pill to resq break # break infinity cycle else: i, j, ph1, ph2, cond_ts = a # compute stuff resq.put((i, j, MI.cond_mutual_information(ph1, ph2, cond_ts, algorithm = 'EQQ2', bins = 4, log2 = False)))
def _process_TGsurrs(jobq, resq, nao, sg, pp, tau, mean, var): while jobq.get() is not None: sg.construct_fourier_surrogates(algorithm='FT') sg.add_seasonality(mean, var, None) caus_surrs_temp = np.zeros((2,5)) # no pressure = 3dim cond. x, y, z = MI.get_time_series_condition([nao, sg.data], tau=tau, dim_of_condition=3, eta=3, close_condition=True) # MIGAU caus_surrs_temp[0, 0] = MI.cond_mutual_information(x, y, z, algorithm='GCM', log2=False) # MIEQQ8 caus_surrs_temp[0, 1] = MI.cond_mutual_information(x, y, z, algorithm='EQQ2', bins=8, log2=False) # MIEQQ16 caus_surrs_temp[0, 2] = MI.cond_mutual_information(x, y, z, algorithm='EQQ2', bins=16, log2=False) # MIKNN16 caus_surrs_temp[0, 3] = MI.knn_cond_mutual_information(x, y, z, k=16, standardize=True, dualtree=True) # MIKNN64 caus_surrs_temp[0, 4] = MI.knn_cond_mutual_information(x, y, z, k=64, standardize=True, dualtree=True) # with pressure = 4dim cond. x, y, z = MI.get_time_series_condition([nao, sg.data], tau=tau, dim_of_condition=3, eta=3, add_cond = pp, close_condition=True) # MIGAU caus_surrs_temp[1, 0] = MI.cond_mutual_information(x, y, z, algorithm='GCM', log2=False) # MIEQQ8 caus_surrs_temp[1, 1] = MI.cond_mutual_information(x, y, z, algorithm='EQQ2', bins=8, log2=False) # MIEQQ16 caus_surrs_temp[1, 2] = MI.cond_mutual_information(x, y, z, algorithm='EQQ2', bins=16, log2=False) # MIKNN16 caus_surrs_temp[1, 3] = MI.knn_cond_mutual_information(x, y, z, k=16, standardize=True, dualtree=True) # MIKNN64 caus_surrs_temp[1, 4] = MI.knn_cond_mutual_information(x, y, z, k=64, standardize=True, dualtree=True) resq.put(caus_surrs_temp)
def _process_CMI_surrs(jobq, resq): while True: a = jobq.get() if a is None: break else: tau, la, lo = a if not np.any(np.isnan(sg.data[:, la, lo])): # 3d x, y, z = MI.get_time_series_condition([nao.data, sg.data[:, la, lo]], tau=tau, dim_of_condition=3, eta=3, close_condition=True) cmi_3d = MI.cond_mutual_information(x, y, z, algorithm='GCM', log2=False) # with pressure = 4dim cond. if not np.any(np.isnan(pp.data[:, la, lo])): x, y, z = MI.get_time_series_condition([nao.data, sg.data[:, la, lo]], tau=tau, dim_of_condition=3, eta=3, add_cond=pp.data[:, la, lo], close_condition=True) cmi_4d = MI.cond_mutual_information(x, y, z, algorithm='GCM', log2=False) else: cmi_4d = np.nan resq.put([tau, la, lo, cmi_3d, cmi_4d]) else: resq.put([tau, la, lo, np.nan, np.nan])
def _process_matrix_cond(self, jobq, resq): while True: a = jobq.get() # get queued input if a is None: # if it is None, we are finished, put poison pill to resq break # break infinity cycle else: i, j, ph1, ph2, cond_ts = a # compute stuff resq.put((i, j, MI.cond_mutual_information(ph1, ph2, cond_ts, algorithm='EQQ2', bins=4, log2=False)))
# compute causality NUM_SURRS = 100 WORKERS = 7 TAUS = np.arange(1,41,1) data_caus = np.zeros((2, TAUS.shape[0], 5)) # pp yes or no x delays x (MIGAU, MIEQQ8, MIEQQ16, knn16, knn64) surrs_NAOcaus = np.zeros((2, NUM_SURRS, TAUS.shape[0], 5)) surrs_TGcaus = np.zeros((2, NUM_SURRS, TAUS.shape[0], 5)) for tau, ii in zip(TAUS, range(TAUS.shape[0])): print("computing for lag %d..." % (tau)) # no pressure = 3dim cond. x, y, z = MI.get_time_series_condition([nao.data, prg_tg.data], tau=tau, dim_of_condition=3, eta=3, close_condition=True) # MIGAU data_caus[0, ii, 0] = MI.cond_mutual_information(x, y, z, algorithm='GCM', log2=False) # MIEQQ8 data_caus[0, ii, 1] = MI.cond_mutual_information(x, y, z, algorithm='EQQ2', bins=8, log2=False) # MIEQQ16 data_caus[0, ii, 2] = MI.cond_mutual_information(x, y, z, algorithm='EQQ2', bins=16, log2=False) # MIKNN16 data_caus[0, ii, 3] = MI.knn_cond_mutual_information(x, y, z, k=16, standardize=True, dualtree=True) # MIKNN64 data_caus[0, ii, 4] = MI.knn_cond_mutual_information(x, y, z, k=64, standardize=True, dualtree=True) # with pressure = 4dim cond. x, y, z = MI.get_time_series_condition([nao.data, prg_tg.data], tau=tau, dim_of_condition=3, eta=3, add_cond=prg_pp.data, close_condition=True) # MIGAU data_caus[1, ii, 0] = MI.cond_mutual_information(x, y, z, algorithm='GCM', log2=False) # MIEQQ8