def fcit_wrapper(data_matrix, i, j, ks, **kwargs): x = data_matrix[:, i].reshape(-1, 1) y = data_matrix[:, j].reshape(-1, 1) if len(ks) == 0: res = fcit.test(x, y) else: res = fcit.test(x, y, data_matrix[:, list(ks)]) return 1.0 if np.isnan(res) else res
def testFCIT(ps, x, y, z=[]): import numpy as np from fcit import fcit X = [ps.ds[x[0]]] Y = [ps.ds[y[0]]] Z = [] for var in z: zdat = ps.ds[var] Z.append(zdat) Xa = np.array(X).transpose() #print('xshape = ', Xa.shape) Ya = np.array(Y).transpose() if Z: Za = np.array(Z).transpose() #print('zshape = ', Za.shape) pval = fcit.test(Xa, Ya, Za, num_perm=10, prop_test=.40) else: pval = fcit.test(Xa, Ya, num_perm=10, prop_test=.40) return pval
def nonparametric_fcit_test(X, Y, Z, data): """ X and Y are names of variables. Z is a list of names of variables. data is a pandas data frame. Return a float corresponding to the p-value computed from FCIT. """ x_np = np.transpose(np.asmatrix(data[X].values)) y_np = np.transpose(np.asmatrix(data[Y].values)) z_np = np.asmatrix(data[Z].values) p = fcit.test(x_np, y_np, z_np) return p
def nonparametric_fcit_test(X, Y, Z, data): """ X and Y are names of variables. Z is a list of names of variables. data is a pandas data frame. Return a float corresponding to the p-value computed from FCIT. """ # implement code here X_var = np.asmatrix(data[X].to_numpy()).transpose() Y_var = np.asmatrix(data[Y].to_numpy()).transpose() Z_var = np.asmatrix(data[Z].to_numpy()) print(X_var.shape, Y_var.shape, Z_var.shape) pval = fcit.test(X_var, Y_var, Z_var) return pval
def statistic_DFA(X,T=None, p0 = 5e-2, p1 = 0.1, n_perm = 15, n_itr=5,n_samp=250, verbos=False): if T is None: T = np.linspace(0,1,X.shape[0]) if len(T.shape) == 1: T = T.reshape(-1,1) nd,fd,di = list(range(X.shape[1])),[],[] if verbos: print("Searching all drifting features") rel = RIT(T,X,p0, n_itr,n_samp) if verbos: print("Searching drift inducing features") for i_num,i in enumerate(rel): if verbos: print(i_num,"/",len(rel)) nd.remove(i) R_i = np.array(np.hstack((range(0,i),range(i+1,X.shape[1]))),dtype=int) if fcit.test(T,X[:,i].reshape(-1,1),X[:,R_i],n_perm=n_perm) < p1: di.append(i) else: fd.append(i) return {"non-drifting":nd,"faithfully-drifting":fd,"drift-inducing":di}