def _get_mutual_inf_KNN(a): """ Gets mutual information using EQQ algorithm for given data. """ i, j, ph1, ph2 = a return i, j, MI.knn_mutual_information(ph1, ph2, k = 32, dualtree = True)
def _process_matrix(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, method = a # compute stuff if method == "MPC": # get phase diff diff = ph1 - ph2 # compute mean phase coherence coh = np.power(np.mean(np.cos(diff)), 2) + np.power(np.mean(np.sin(diff)), 2) resq.put((i, j, coh)) elif method == "MIEQQ": resq.put((i, j, MI.mutual_information(ph1, ph2, algorithm = 'EQQ2', bins = 4, log2 = False))) elif method == "MIKNN": resq.put((i, j, MI.knn_mutual_information(ph1, ph2, k = 32, dualtree = True))) elif method == "MIGAU": corr = np.corrcoef([ph1, ph2])[0, 1] mi = -0.5 * np.log(1 - np.power(corr, 2)) if corr < 1. else 0 resq.put((i, j, mi)) elif method == "COV": resq.put((i, j, np.cov(ph1, ph2, ddof = 1)[0,1])) elif method == "CORR": resq.put((i, j, st.pearsonr(ph1, ph2)[0])) elif method == "WCOH": # input field must be wave from wavelet!!!! w1 = np.complex(0, 0) w2 = w1; w3 = w1 for t in range(0, self.time.shape[0]): w1 += ph1[t] * np.conjugate(ph2[t]) w2 += ph1[t] * np.conjugate(ph1[t]) w3 += ph2[t] * np.conjugate(ph2[t]) w1 /= np.sqrt(np.abs(w2) * np.abs(w3)) resq.put((i, j, np.abs(w1))) elif method[0] == 'L': p = int(method[1]) res = 0 for t in range(ph1.shape[0]): res += np.power(np.abs(ph1[t] - ph2[t]), p) resq.put((i, j, np.power(res, 1./p)))