dd=args.VAL[0] if dd=='no': #print 'no data willbe plotted...' plotdata=dd elif (dd=='yes') or (args.VAL==[]): #print 'plot everything...' plotdata='yes' else: sys.exit("Error (-plotdata): Only 'yes' or 'no' values are admisible.") ####################### ### MAIN ############## ####################### sys.stdout.write("\a") #loading data points ('N' points for each one of the 'DIM' CVs) N=file_lines(args.INPUT) DIM=file_cols(args.INPUT) P1=load_data(args.INPUT,N,DIM) dK1=[] dK2=[] conv_all=[] # estimate the initial string (P2) of size Min P2 = string_ini(P1,DIM,args.K) Pini=string_ini(P1,DIM,args.K) PiniT=zip(*Pini) # maximun distances of the data to the images of the string maxdistances=maxvec(P1,P2) # Estimate the mean of the voronoid cells
####################################################### ###### Parsing arguments from the command line ######## ####################################################### def _make_parser(): parser = argparse.ArgumentParser(description="This tool performs a mean reversion test, that is, the tendency of a time series to drift towards its long-term mean. As input file this tool expects a time series for each column; any number of columns and rows can be processes. The use of the test here was inspired by applications in financial mathematics; in our implementation the Augmented Dickey-Fuller test (ADFT) was used. With ADFT we will optain for each columns a '1' ---> mean reversal (stationarity) or '0' ---> NO time reversal (no stationarity) of the time series. Further explanations and examples can be found at https://gist.github.com/r-hong/82515ca44fb35090b8c8 ",epilog="Thanks for using meanReversalTest.py!!") parser.add_argument('IN_file', help="Input file") return parser #------------------------------ _p = _make_parser() __doc__ += _p.format_help() ###################################################### if __name__ == '__main__': args = _p.parse_args() #Read filename nc = file_cols(args.IN_file) for i in range(nc): exec "c%s=[]" % (i) with open(args.IN_file) as file: reader = csv.reader(file, delimiter=' ',skipinitialspace=True) for row in reader: for i in range(nc): exec "c%s.append(float(row[%s]))" % (i,i) #perform test for i in range(nc): exec "t%s = ts.adfuller(c%s,1)" % (i,i) final=[] a="'1%'" b="'5%'"
args = _p.parse_args() #preprocessing the input file: # saving every args.stride value of args.IN_file and saving to tmp.dat ss="'" ss+='0~' ss+=`args.S` ss+='p' ss+="'" cmd='sed -n ' cmd+=ss cmd+=' ' cmd+=args.fileName cmd+=' > tmp.dat' os.system(cmd) ########################################## #get Number of rows and number of columns from the file and read from the file into a matrix 'vecT' nCol = file_cols('tmp.dat') vecT = readFile('tmp.dat',nCol) #print len(vecT[0]) #calculate the max likelihood estimators results = estValB(vecT,args.K,args.N) #print results[0] #format the results to 6 decimal points before printing myList=formatRes(results,6) print ' '.join(str(p) for p in myList)