def mergeDictionaryWithClass(name): readFile.clear() readFile.readFile(name) # Unigram print("Add uni") for x in readFile.unigram: # tmp = readFile.isInDictionary(x["word"], UNIGRAM) tmp = readFile.BinarySearchNgramWithClass(UNIGRAM, x.key) if tmp > -1: # print(UNIGRAM[tmp].key) UNIGRAM[tmp].count = UNIGRAM[tmp].count + x.count else: # print(x.key) UNIGRAM.append(x) UNIGRAM.sort(key=lambda x: x.key) # Ngram print("Add nrg ") for idx, x in enumerate(readFile.ngram): # tmp = readFile.isNgramInDictionary(x, NGRAM) t = time.time() tmp = readFile.BinarySearchNgramWithClass(NGRAM, x.key) # print(format(idx) + "/" + format(len(readFile.ngram)) + " : " + format(tmp)) # print(time.time() - t) if time.time() - t > 500 * 10**(-3): print("teo") if tmp > -1: NGRAM[tmp].count = NGRAM[tmp].count + x.count else: NGRAM.append(x) NGRAM.sort(key=lambda x: x.key)
def load_files(): paths = readFile.readFile(globalvars.FILENAME_PATHS) waypoint_list = readFile.readFile(globalvars.FILENAME_WAYPOINTS) obstacle_list = readFile.readFile(globalvars.FILENAME_OBSTACLES) drawObstaclesPath.drawObstaclesPath(obstacle_list, paths, globalvars.FIELD_HEIGHT, globalvars.FIELD_WIDTH)
def _write_dic_to_json(name): readFile.clear() readFile.readFile(name) with open('unigram_json.txt', 'w') as uni_json_file: json.dump(readFile.unigramDict, uni_json_file) with open('ngram_json.txt', 'w') as ngr_json_file: json.dump(readFile.ngramDict, ngr_json_file)
def _write_dic_to_text(): readFile.clear() readFile.readFile("DicTest.txt") global UNIGRAM_DICT global NGRAM_DICT UNIGRAM_DICT = copy.deepcopy(readFile.unigramDict) NGRAM_DICT = copy.deepcopy(readFile.ngramDict) writeFile._write_dic_to_text(UNIGRAM_DICT, NGRAM_DICT)
def hasil(menu, kalimat): # fungsi yang mengembalikan kalimat terjemahan untuk # kalimatSunda dalam bahasa Indonesia atau # kalimatIndo dalam bahasa Sunda # algoritma string matching yang digunakan adalah algoritma KMP (Knuth-Morris-Pratt) # list yang menampung kata-kata hasil terjemahan kalimatHasil = [] # kalimat hasil hasilTerjemahan = '' # mengubah kalimat menjadi list of kata kata, kataPure = kalimatToKata(kalimat) # kata : array of kata tanpa character dan "teh" # kataPure : array of kata dengan chacacter dan "teh" # current working dir curr = os.getcwd() dir = curr + ".\\doc\\" # read file sunda.txt untuk menu "STI" if (menu == "STI"): kamus = readFile(dir + 'sunda.txt') # read file indo.txt untuk menu "ITS" else: kamus = readFile(dir + 'indonesia.txt') # mengecek seluruh isi kamus menemukan kata yang sama for j in range(len(kata)): idx = -1 # idx adalah indeks pattern ditemukan di kamus[i] i = 0 # i adalah indeks yang digunakan untuk iterasi kamus # jika kataPure[j] bukan merupakan character atau teh if (kata[j] != ''): # hasil indeks dengan algoritma yang digunakan adalah KMP while (i < len(kamus)) and (idx != 0): idx = KMPmatching(kamus[i], kata[j]) i += 1 # jika kata ditemukan dalam kamus if (idx != -1): kalimatHasil.append(getHasilTerjemahan(i - 1, kamus, j) + ' ') # jika kata tidak ditemukan dalam kamus else: kalimatHasil.append(kataPure[j]) else: # ignore teh di hasil terjemahan if (kataPure[j] != "teh "): kalimatHasil.append(kataPure[j]) for k in kalimatHasil: hasilTerjemahan += k return hasilTerjemahan
def b2bCL(folder): dtFiles = glob(folder+'/*_dt0.tsv') s = re.compile('_') filePos = [] for file in dtFiles: sp = s.split(file) filePos.append(tuple(map(lambda x: int(x),filter(lambda x: x.isdigit(),sp)))) ncols = max(map(lambda x: x[1],filePos))+1 nrows = max(map(lambda x: x[0],filePos))+1 data = np.zeros((nrows,ncols),dtype='object') dataX = np.zeros(data.shape,dtype='object') dataY = np.zeros(data.shape,dtype='object') for (file,pos) in zip(dtFiles,filePos): data[pos] = readFile(file)['cell'+str(pos[0])+'_'+str(pos[1])+'/vOld/cl'] for row in range(nrows): for col in range(ncols): pos = (row,col) temp = data[pos] i=0 for i in range(len(temp)): if np.isnan(temp[i]): temp[i] = np.nanmean(temp) temp = signal.medfilt(temp) i += 1 # if temp.max() > 600: # continue dataY[pos] = np.array(temp) dataX[pos] = np.array(calcPartialSums(temp)) # linestyle = '-' if temp.max() < 600 else 'None' # plt.plot(dataY[pos],dataX[pos]) # plt.show() return dataX,dataY
def main(): filepath = ( "/Users/peterschwarz/VS Code Projekte/readFile-Parse/elektrolyse_20200326.csv" ) file = readFile(filepath) parsing_file = parseExport() parsing_file.parse(file.read())
def takeinput_from_doc(): from readFile import readFile global file_name file_name = filedialog.askopenfilename(filetypes=[("Text files", "*.*")]) print("selected_filename: ", file_name) input_string = readFile(file_name) input_string_Box.delete(1.0, END) input_string_Box.insert(END, input_string)
def createHaiku(fileName): data = readFile(fileName).split(); haiku = ""; lines = [5,7,5]; for line in lines: haiku += writeLine(line, data) print haiku
def b2bClusters(folder, nextBeatDist=3): dtFiles = glob(folder + '/*_dt0.tsv') s = re.compile('_') filePos = [] for file in dtFiles: sp = s.split(file) filePos.append( tuple(map(lambda x: int(x), filter(lambda x: x.isdigit(), sp)))) nrows = max(map(lambda x: x[0], filePos)) + 1 ncols = max(map(lambda x: x[1], filePos)) + 1 dataPK = np.zeros((nrows, ncols), dtype='object') dataMT = np.zeros((nrows, ncols), dtype='object') for (file, pos) in zip(dtFiles, filePos): dataPK[pos] = readFile(file)['cell' + str(pos[0]) + '_' + str(pos[1]) + '/vOld/peak'] dataMT[pos] = readFile(file)['cell' + str(pos[0]) + '_' + str(pos[1]) + '/vOld/maxt'] tVals, vVals, cells, beatLists = calcClusters(dataPK, dataMT, nextBeatDist) return tVals, vVals, cells, beatLists
def mergeDictionary(name): readFile.clear() readFile.readFile(name) # Unigram print("Add uni") for x in readFile.unigram: # tmp = readFile.isInDictionary(x["word"], UNIGRAM) tmp = readFile.BinarySearchUni(UNIGRAM, x["word"]) if tmp > -1: if "count" in x: if "count" in UNIGRAM[tmp]: if x["count"] != 0: UNIGRAM[tmp][ "count"] = UNIGRAM[tmp]["count"] + x["count"] else: UNIGRAM[tmp] = x else: UNIGRAM.append(x) UNIGRAM.sort(key=lambda x: x["word"]) # Ngram print("Add nrg " + format(len(readFile.ngram))) for idx, x in enumerate(readFile.ngram): # tmp = readFile.isNgramInDictionary(x, NGRAM) print( format(idx) + "/" + format(len(readFile.ngram)) + " : " + format(tmp)) t = time.time() tmp = readFile.BinarySearchNgram(NGRAM, readFile.mergeNgram(x)) print(time.time() - t) if time.time() - t > 500 * 10**(-3): print("teo") if tmp > -1: if "count" in x: if "count" in NGRAM[tmp]: if x["count"] != 0: NGRAM[tmp]["count"] = NGRAM[tmp]["count"] + x["count"] else: NGRAM[tmp] = x else: NGRAM.append(x) NGRAM.sort(key=lambda x: readFile.mergeNgram(x))
def b2bSync(folder, nextBeatDist=3): dtFiles = glob(folder + '/*_dt0.tsv') s = re.compile('_') filePos = [] for file in dtFiles: sp = s.split(file) filePos.append( tuple(map(lambda x: int(x), filter(lambda x: x.isdigit(), sp)))) ncols = max(map(lambda x: x[1], filePos)) + 1 nrows = max(map(lambda x: x[0], filePos)) + 1 dataPK = np.zeros((nrows, ncols), dtype='object') dataMT = np.zeros((nrows, ncols), dtype='object') for (file, pos) in zip(dtFiles, filePos): dataPK[pos] = readFile(file)['cell' + str(pos[0]) + '_' + str(pos[1]) + '/vOld/peak'] dataMT[pos] = readFile(file)['cell' + str(pos[0]) + '_' + str(pos[1]) + '/vOld/maxt'] T, syncT, syncV = calcTimeSync(dataPK, dataMT, nextBeatDist) # plt.plot(syncT) # plt.plot(syncV) plt.show() return T, syncT, syncV
def rake(filePath): ''' Main function of our project params: filePath | string : Path of file which we have to read. return: keywordsList | string : List of index keywords. ''' rawText = readFile.readFile(filePath) preObj = preprocessing.Preprocess() candidateKeywordList = preObj.preprocess(rawText) indexKeywordList = postprocessing.postprocess(candidateKeywordList) return indexKeywordList
def train(fn): # number of training iterations nTimes = 10000000 # step size (learning rate) rate = 5e-25 # data, # of training examples, # of input features + 1 data, n, m = readFile(fn) # slice input features only X = data[:, :-1] # slice targets only y = data[:, -1] # initial values for parameters thetas = np.random.rand(m) # initialize gradients gradient = np.zeros(m) # initialize the objects for cost function continuous replotting fig_cost, ax_cost, xdata_cost, ydata_cost, curve = init_cost( 'Movie Revenue') # initialize the objects for the continuous replotting of the fitted line fig_line, ax_line, xdata_line, line, = init_line(X, y, thetas) # the actual training process for k in range(nTimes): h = np.matmul(X, thetas) delta = y - h # get the partial derivatives gradient = -2 * np.sum(X * delta[:, np.newaxis], axis=0) # update the parameters thetas -= rate * gradient # cost function's current value J = np.sum(delta * delta) # replot the cost function and the fitted line replot_cost(fig_cost, ax_cost, curve, nTimes, xdata_cost, ydata_cost, k, J) replot_line(fig_line, ax_line, xdata_line, line, X, thetas, k, nTimes) # this line is needed for graphs to stay afterwards plt.ioff() # save the .png of the graphs for later reference plt.savefig('LR/line_graph.png') plt.savefig('LR/final_line.png') return thetas
def makeMovie(src, moviename, fps=40, flipY=False, metadata=None, slowFactor=2, cmap='hot'): ''' creates a movie from the voltage values for a grid simulation src: the directory that contains the files moviename: the name of the movie (should end in .mp4) ex. makeMovie('/home/dgratz/Documents/data092517-1149/','data092517-1149.mp4') ''' src = Path(src) moviename = Path(moviename) files = list(src.glob('*dvars.tsv')) s = re.compile('_') filePos = [] for file in files: file = str(file) sp = s.split(file) filePos.append( tuple(map(lambda x: int(x), filter(lambda x: x.isdigit(), sp)))) ncols = max(map(lambda x: x[1], filePos)) + 1 nrows = max(map(lambda x: x[0], filePos)) + 1 first = True print('Reading Cells: ', end='') for i, (file, pos) in enumerate(zip(files, filePos)): data = readFile(file) if first: times = np.zeros((nrows, ncols, len(data['t']))) voltages = np.zeros((nrows, ncols, len(data['vOld']))) first = False times[pos] = data['t'] voltages[pos] = data['vOld'] print(pos, '', end='') print() makeMovieArray(times, voltages, moviename, fps=fps, flipY=flipY, metadata=metadata, slowFactor=slowFactor, cmap=cmap) return times
def main(argv): filePath = '' algo = '' bSize = 0 rndSeed = 0 bORr = 0 try: opts, args = getopt.getopt( argv, "hm:a:b:r:", ["mdp=", "algorithm=", "batchsize=", "randomseed="]) except getopt.GetoptError: print('test.py -i <inputfile> -o <outputfile>') sys.exit(2) for opt, arg in opts: if opt in ("-m", "--mdp"): filePath = arg elif opt in ("-a", "--algorithm"): algo = arg elif opt in ("-b", "--batchsize"): bSize = arg bORr = 1 elif opt in ("-r", "--randomseed"): rndSeed = arg bORr = 2 print('mdp path = ', filePath) print('algo = ', algo) print('Batch Size = ', bSize) print('Random Seed = ', rndSeed) nS, nA, R, T, gamma = rf.readFile(filePath) print(nS) print(nA) print(R) print(T) print(gamma) lp.lppi(nS, nA, R, T, gamma)
def generateMarchovChain(): # parse text corpus = readFile("timeMachine.txt").lower(); corpus = corpus.translate(string.maketrans("",""), string.punctuation) corpus = corpus.split(); # parse text last = len(corpus)-1 chain = {} for index, word in enumerate(corpus): if (index != last): Next = corpus[(index+1)] state = {} if word in chain: state = chain[word] if Next in state: state[Next] += 1 else: state[Next] = 1 else: state[Next] = 1 chain[word] = state return chain
def readTimes(src): src = Path(src) files = list(src.glob('*dvars.tsv')) s = re.compile('_') filePos = [] for file in files: file = str(file) sp = s.split(file) filePos.append( tuple(map(lambda x: int(x), filter(lambda x: x.isdigit(), sp)))) ncols = max(map(lambda x: x[1], filePos)) + 1 nrows = max(map(lambda x: x[0], filePos)) + 1 first = True print('Reading Cells: ', end='') for i, (file, pos) in enumerate(zip(files, filePos)): data = readFile(file) if first: times = np.zeros((nrows, ncols, len(data['t']))) first = False times[pos] = data['t'] print(pos, '', end='') print() return times
from readFile import readFile for i in range(4,11): file1 = readFile("completeGraphs\\cond"+str(i)+".txt",1) file2 = readFile("graphData\\CF_"+str(i)+"_Uniq.txt",1) pointer1=0 pointer2=0 out_list=[] #assuming sorted ''' while pointer1<len(file1) and pointer2<len(file2): if file1[pointer1]!=file2[pointer2]: pointer1+=1 else: out_list.append(file1[pointer1]) pointer2+=1''' #unsorted set1 = set() for line in file1: #print(line) set1.add(str(line[1])) for line in file2: if str(line[1]) in set1: out_list.append(line.split(':')) f=open("completeCFintersection\\int"+str(i)+".txt",'w') for i,line in enumerate(out_list): #print(line) #print(line[0]) #print(line[1])
from readFile import readFile for i in range(4, 11): file1 = readFile("completeGraphs\\cond" + str(i) + ".txt", 1) file2 = readFile("graphData\\CF_" + str(i) + "_Uniq.txt", 1) pointer1 = 0 pointer2 = 0 out_list = [] #assuming sorted ''' while pointer1<len(file1) and pointer2<len(file2): if file1[pointer1]!=file2[pointer2]: pointer1+=1 else: out_list.append(file1[pointer1]) pointer2+=1''' #unsorted set1 = set() for line in file1: #print(line) set1.add(str(line[1])) for line in file2: if str(line[1]) in set1: out_list.append(line.split(':')) f = open("completeCFintersection\\int" + str(i) + ".txt", 'w') for i, line in enumerate(out_list): #print(line) #print(line[0]) #print(line[1])
""" from readFile import readFile import re from glob import glob import numpy as np import matplotlib.pyplot as plt s = re.compile('/') u = re.compile('_') datadir = 'D:/synchrony-data/AllConnAndRand/' conns = list(map(lambda x: float(s.split(x)[-1]), glob(datadir + '0/*'))) data = np.zeros((2, 26, 20)) files = glob(datadir + '*/*/cell*dt0.tsv*') for file in files: temp = readFile(file) fnames = s.split(file) uparts = u.split(fnames[-1]) (row, col) = tuple(map(lambda x: int(x), filter(lambda x: x.isdigit(), uparts))) conn = float(fnames[-2]) connPos = conns.index(conn) simNum = int(fnames[-3]) data[col, connPos, simNum] = np.min(temp['cell' + str(row) + '_' + str(col) + '/vOld/cl'][-10:-1]) plt.figure(0) vOld_cl_line = np.zeros(shape=(2, 26)) vOld_cl_line[0, :] = np.mean(data[0, :, :], axis=1) vOld_cl_line[1, :] = np.mean(data[1, :, :], axis=1) vOld_cl_error = np.zeros(shape=(2, 26)) vOld_cl_error[0, :] = np.std(data[0, :, :], axis=1)
def makeDataCsv(): curr = 0 process = 0 print("Start reading CSV files...") events = [] players = [] for i in range(9): year = 2010 + i print("File " + str(year) + '...') filepath = root + '/Events_' + str(year) + '.csv' events.extend(readFile(filepath)) filepath = root + '/Players_' + str(year) + '.csv' players.extend(readFile(filepath)) offset = int(players[0][0]) divisor = round(len(events) / 100) # Initialize empty cells with the first column is player ID lines = [] for elm in players: if elm[0] == '648095': for i in range(642767, 648095): line = [i] line.extend([0] * 28) lines.append(line) line = [elm[0], elm[1]] line.extend([0] * 26) line.append(elm[3]) lines.append(line) # Store player ID and initial time of who are playing on the field print("Start processing event file...") hasPlayed = [] playerID = [] start = [] for event in events: # Print complete ratio of the process if not round(curr / divisor) == process: process = round(curr / divisor) print('Process complete: ', process, '%') # If event type is sub_in, record row = int(event[9]) - offset if event[10] == 'sub_in': if not event[9] in hasPlayed: hasPlayed.append(event[9]) playerID.append(event[9]) start.append(int(event[7])) # If event type is sub_out, check if the player has been recorded elif event[10] == 'sub_out': # Player is recorded, time is the interval if not event[9] in hasPlayed: hasPlayed.append(event[9]) if event[9] in playerID: lines[row][2] += int(event[7]) - start.pop( playerID.index(event[9])) playerID.pop(playerID.index(event[9])) # Player is not recorded, time is from the beginning else: lines[row][2] += int(event[7]) else: # The player has been on the field from the beginning # if not event[9] in hasPlayed: # hasPlayed.append(event[9]) # if not event[9] in playerID: # playerID.append(event[9]) # start.append(0) if event[9] in hasPlayed: if not event[9] in playerID: playerID.append(event[9]) start.append(int(event[7])) else: hasPlayed.append(event[9]) playerID.append(event[9]) start.append(0) column = header.index(event[10]) lines[row][column] += 1 # Check if it is the last event for a match. Empty playerID and start if it is if curr + 1 == len(events) or int(event[7]) > int(events[curr + 1][7]): while hasPlayed: lines[int(hasPlayed[0]) - offset][3] += 1 hasPlayed.pop(0) while playerID: lines[int(playerID[0]) - offset][2] += max(2400, int(event[7])) - start[0] playerID.pop(0) start.pop(0) curr += 1 # Write to a new csv file if not os.path.isfile('data.csv'): with open('data.csv', 'w') as outcsv: writer = csv.writer(outcsv) writer.writerow(header) writer.writerows(lines)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Tue Oct 24 15:58:02 2017 @author: dgratz """ import numpy as np from glob import glob from readFile import readFile import re from ParameterSensitivity import ParamSensetivity import matplotlib.pyplot as plt from calcSync import calcTimeSync, calcSyncVarLen pvars = list(readFile('D:/synchrony-data/2SAN1RandLogNormal/0/cell_0_0_dss0_pvars.tsv').keys()) #datadir = 'D:/synchrony-data/2SAN1RandLogNormal/' datadir = 'D:/synchrony-data/2SAN1RandLogNormalT3_0038/' #datadir = 'D:/synchrony-data/2SAN1RandLogNormal_00038/' #datadir = 'D:/synchrony-data/2SAN1RandLogNormalManyCond/' filesPvars = glob(datadir+'*/*_pvars.tsv') numData = len(filesPvars)//2 pvarsVals = np.zeros((2,numData,len(pvars))) s = re.compile('/') u = re.compile('_') for file in filesPvars: file = file.replace('\\','/') temp = readFile(file) fnames = s.split(file) uparts = u.split(fnames[-1])
#sleep(8) myserial.closePort() ''' #Serial Initialization myserial = mySerial.mySerial('/dev/ttyUSB0', 9600) #Imaging Processing #Sound Processing #Main A infinite loop while True: os.cmd('') # System Command [isFinished,x,y] = readFile.readFile() if isFinished == True: break else: move(x,y) def move(a,b): #Problems! Don't know the specific steps in one cycle! myserial.send(resetString()) myserial.send(getString()) myserial.send(graspString()) myserial.send(turnToString(x,y)) myserial.send(putDownString())
from readFile import readFile from DFS import DFS from BFS import BFS from A_star import A_star from Graph import Graph import copy import sys clients = readFile(sys.argv[2]); cli = clients.openFile(); line = []; mapas = readFile(sys.argv[1]); mapa = mapas.openFile(); graph = Graph(); #Read each connection and add a node respectively for i in range(0, mapas.numConnects): graph.graph = mapas.readMap(graph.graph) output = clients.file.replace('.cli', '.sol') output = open(output, 'w') #Read each client separately for i in range (0, clients.numClients): line.append(i) line[i] = clients.readLine() # print (line[i])
size_with_IP = bits_res + (20 * 8) packets.insert(0, Packet(size_with_IP, frameNumber)) total_size_packet = total_size_packet + size_with_IP else: size_with_IP = size + (20 * 8) packets.insert(0, Packet(size_with_IP, frameNumber)) total_size_packet = total_size_packet + size_with_IP bits_res = bits_res - size return packets, total_size_packet if __name__ == "__main__": V1 = readFile('V1.txt') #V2 = readFile('V2.txt') #V3 = readFile('V3.txt') #V1 = V1[0:num_frame] ''' t = [int(i) for i in range(len(V1))] plt.figure('Plot V1') plt.plot(t[0:10000], V1[0:10000]) ''' with Manager() as manager: L = manager.list( ) # <-- can be shared between processes. Packet store in L PLR = manager.list() fulled_released = manager.list([0, 0]) processes = [] p1 = Process(target=arrive,
else: uPointer = (1 + uPointer) % len(uid) print 'up:' + str(uPointer) rid = [i for i in range(len(tid))] printFile('/output/reTrainData.dat', \ 'id, gender, age, occupation, zipcode, title, genres, rating', \ rid, '::', rgd, '::', rage, '::', roc, '::', rzc, '::', rtt, '::', rgn, '::', rrt) uid = [] gd = [] age = [] oc = [] zc = [] mid = [] tt = [] gn = [] tuid = [] tmid = [] rt = [] tid = [] [uid, gd, age, oc, zc] = readFile('/original/users.dat', 0, '::') [mid, tt, gn] = readFile('/original/movies.dat', 0, '::') [tuid, tmid, rt, tid] = readFile('/original/training_ratings_for_kaggle_comp-backup.csv', 1, ',') reTrainData(uid, gd, age, oc, zc, mid, tt, gn, tuid, tmid, rt, tid)
'W': '[A|T]', 'H': '[A|C|T]', 'B': '[C|G|T]', 'V': '[A|C|G]', 'D': '[A|G|T]' } enc_pam = {'f': '', 'r': ''} rc_pam = RC(pam) for n, m in zip(pam, rc_pam): enc_pam['f'] += encoder[n] enc_pam['r'] += encoder[m] return enc_pam enc_pam = create_PAM(PAM) ref = readFile.readFile(file) results = [] for n in range(len(ref)): seq = ref[n][0] gRNA = [] if seq[30] == "C": pc = seq[29:31] if pc == "TC": L = list(seq) L[30] = "Y" #seq[30]="Y" seq = ''.join(L) for i in range(windowstart - 1, windowend): pStart = 30 + spacerLen - i if regex.match(enc_pam['f'], seq[pStart:pStart + pamLen]): gRNA.append(seq[30 - i:30 - i + pamLen + spacerLen])
def main(): #mult=poly_mult(['x-3','x-1'],['x-2','x**2-4*x+5','x','x-7']) #print(mult) #mult_after_div = poly_div(mult,['x-7']) #print(mult_after_div) list_of_lists_of_input_lines=[] start_time=time.time() poly_dict={} factor_dict={} poly_lists=[] order=int(input("please enter the order")) #get all the polynomials of order < the given order we are looking at for i in range(1,order): file_name="graphData\\cf_"+str(i)+"_uniq.txt" list_of_input_lines = readFile(file_name) list_of_lists_of_input_lines.append(list_of_input_lines) #print(list_of_lists_of_input_lines) for j in range(len(list_of_input_lines)): if j%10000==0: print("file:",i,"line:",j) list_of_input_lines[j][0] = breakIntoFactors(list_of_input_lines[j][0]) current_poly=list_of_input_lines[j][0] # we need to assocaite the polys with thier graph numbers for output purposes proper_poly_graphs=list_of_input_lines[j][1] proper_poly_graphs=tuple(proper_poly_graphs) #makes a frozenSet out of factor:freq pairs proper_poly=frozenset(Counter(current_poly).items()) poly_dict[proper_poly]=proper_poly_graphs #updates the factor dictionary with all the polys of this order poly_lists.append([line[0] for line in list_of_input_lines]) update_dict_of_interesting_factors(i,list_of_input_lines,factor_dict) #get the polynomials of the order we want to factorise file_name="completeCfIntersection\\int"+str(order)+".txt" list_of_input_lines = readFile(file_name) list_of_lists_of_input_lines.append(list_of_input_lines) #print(list_of_lists_of_input_lines) for j in range(len(list_of_input_lines)): if j%10000==0: print("file:",order,"line:",j) list_of_input_lines[j][0] = breakIntoFactors(list_of_input_lines[j][0]) current_poly=list_of_input_lines[j][0] # we need to assocaite the polys with thier graph numbers for output purposes proper_poly_graphs=list_of_input_lines[j][1] proper_poly_graphs=tuple(proper_poly_graphs) #makes a frozenSet out of factor:freq pairs proper_poly=frozenset(Counter(current_poly).items()) poly_dict[proper_poly]=proper_poly_graphs poly_lists.append([line[0] for line in list_of_input_lines]) update_dict_of_interesting_factors(order,list_of_input_lines,factor_dict) #gets all the polynomials from the file, makes them into frozensets and puts them in a big set for lookup #makes a dictionary of the non (x-a) factors from the input polynomials '''for x in factor_dict: if len(factor_dict[x])>1: print(factor_dict[x])''' '''for poly in poly_dict: print(poly)''' print(time.time()-start_time) #start=0 #stop=999 valid_inputs=False while not valid_inputs: try: start=int(input("please enter a start value\n")) stop=input("please enter an end value (press enter for all)\n") chunk_len = input("please enter a chunk length (enter for unlimited) \n") if stop == "": stop = int(len(list_of_input_lines)) else: stop=int(stop) if chunk_len == "": chukn_len=False else: chunk_len=int(chunk_len) if start>=1 and start<=stop: valid_inputs=True else: print("ensure start>=0 and start>=stop") except ValueError: print("please ensure you enter integers") #go through all the polynomials from start to stop in the input file #print([line[0] for line in list_of_input_lines[start:stop]]) #just loop through the polynomials from line start to line stop of input lines if chunk_len: chunks = (stop-(start-1))//chunk_len+1 else: chunks=1 chunk_len=stop-(start-1) for i in range(chunks): out_f=open("Results//v2_order_"+str(order)+"_lines_"+str(start+i*chunk_len)+"to"+str(min(start+(i+1)*chunk_len-1,stop))+".txt",'w') #note that stop is not included #for index in range(len([line[0] for line in list_of_input_lines[start:stop]])): for index in range(start-1+i*chunk_len,min(start-1+(i+1)*chunk_len,stop)): #print(index) found_factorisation=False if index%10==0: print(index) line_num=index+1 p_id=str(order)+':'+str(line_num) #print(p_id) p=list_of_input_lines[index][0] p_graph_numbers=list_of_input_lines[index][1] #out_f.write("$\n") #out_f.write("P ") printable_p=sympyFormat(p) #out_f.write(printable_p+ " : " + " ".join(p_graph_numbers)) #out_f.write("\n") p_string="P "+printable_p + " : " + " ".join(p_graph_numbers)+"\n" out_f.write(p_string) #get the two lists of polynomials which could be h1 and h2 # item in interesting_list and boring_list is a list. #first element is the degree, second is the poly boring_list,interesting_list,p_boring=get_poly_lists(p,p_id,order,factor_dict,poly_lists) #print("b",boring_list) #print("i",interesting_list) if p_boring: look_through_pairs(boring_list,boring_list,order,True,p,poly_dict,out_f,list_of_lists_of_input_lines,found_factorisation,p_string) #look through all pairs in the boring list else: #if there is nothing in interesting list, there are no polys with the same factors that p #had so we should not look for a factorisation if len(interesting_list)>0: #look through boring/interesting pairs, and interesting interesting pairs look_through_pairs(boring_list,interesting_list,order,False,p,poly_dict,out_f,list_of_lists_of_input_lines,found_factorisation,p_string) look_through_pairs(interesting_list,interesting_list,order,True,p,poly_dict,out_f,list_of_lists_of_input_lines,found_factorisation,p_string) '''print("current p:",p) print("boring list:",boring_list) print("interesting list:" ,interesting_list)''' print(time.time()-start_time)
import readFile import pdb print readFile.readFile('textFile.txt') def test_read_file_1(file_name): content = [] with open(file_name) as f: lines = f.readlines() pdb.set_trace() for line in lines: content.append(line) return ''.join(content) def test_read_file_2(file_name): content = [] with open(file_name) as f: tmp = f.readline() while tmp: content.append(tmp) tmp = f.readline() return ''.join(content) if __name__ == '__main__': # print test_read_file_1('textFile.txt') print test_read_file_2('textFile.txt')
myAuths = list(map(int, inp.split())) if (len(myAuths) <= 21): H = G.subgraph(myAuths) print(mf.calcGrNr(myAuths, G)) else: print("Number of Authors are bigger than 21") except: print("Input is not valid") #read file dataq = input("Please enter 'r' for reduced dataset or 'f' for full dataset: ") try: if dataq == "f": print("Loading full Data...") dataset = rf.readFile('full_dblp.json') elif dataq == "r": print("Loading reduced Data...") dataset = rf.readFile('reduced_dblp.json') else: print("Wrong input, loading reduced Data...") dataset = rf.readFile('reduced_dblp.json') # create graph G = nx.Graph() # functions for inverted index print("Creating Dataset...") inv = mf.invertedAuth(dataset, G) invpub = mf.invertedPub(dataset) # function for connecting nodes print("Calculating Similarities...") mf.jacsim(G, inv, invpub)
from linearKernel import linearKernel from getVocabList import getVocabList plt.ion() ## ==================== Part 1: Email Preprocessing ==================== # To use an SVM to classify emails into Spam v.s. Non-Spam, you first need # to convert each email into a vector of features. In this part, you will # implement the preprocessing steps for each email. You should # complete the code in processEmail.m to produce a word indices vector # for a given email. print('\nPreprocessing sample email (emailSample1.txt)\n') # Extract Features file_contents = readFile('emailSample1.txt') word_indices = processEmail(file_contents) # Print Stats print('Word Indices: \n') print(word_indices) print('\n\n') input('Program paused. Press enter to continue.\n') ## ==================== Part 2: Feature Extraction ==================== # Now, you will convert each email into a vector of features in R^n. # You should complete the code in emailFeatures.m to produce a feature # vector for a given email. print('\nExtracting features from sample email (emailSample1.txt)\n')
# import the reader from readFile import readFile from math import sqrt ######################################### def writeFile(newName, x, y): '''File writing function''' f = open(newName, 'w') for i in range(0, x.shape[0]): line = str(x[i]) + " " + str(y[i]) + "\n" f.write(line) f.close() print("Written to", newName) ######################################### if __name__ == '__main__': '''Main''' filename = "../data/Wiggle1.txt" # read data x, y = readFile(filename) # do some maths to the file y = y * sqrt(2) # write the results newName = 'aNewFile.txt' writeFile(newName, x, y)
while usable_edges: cost, n1, n2 = heappop(usable_edges) if n2 not in used: used.add(n2) mst.append((n1, n2, cost)) for e in conn[n2]: if e[2] not in used: heappush(usable_edges, e) return mst edges = [] nodes = [] edges, nodes, vertex = readFile("base.txt") result = prim(nodes, edges) buildVertex(vertex) addNeighbor(cutPrim(result, 7)) ColorVertex() resp = open("primCut.txt", 'w') for u in range(len(k)): resp.write(str(k[u].no)+str("\n")) resp.write(str("Coordenada: ")+str("(")+str(k[u].dx)+str(", ")+str(k[u].dy)+str(")")+str("\n")) resp.write(str("Vizinhos: ")+str(k[u].neighbor)+str("\n"))
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Aug 7 11:08:12 2019 @author: henriaycard """ from readFile import readFile test = readFile('test.csv') test.read() test.readMail(2) test.readLinkedin(5) test.readEtablissement(9) test.numberByEtablissement() test.createFileMail()
from readFile import readFile from GSAT import GSAT from WalkSAT import WalkSAT from DPLL import DPLL import time import sys # Python version: 3.5 # read input file file = readFile(sys.argv[1]) file = file.openFile() output = file.file.replace(".cnf", ".sol") output = open(output, "w") output.write("c TYPE SOLUTION VARIABLES CLAUSES CPUSECS MEASURE1 \n") # The knowledge Base KB = file.readClauses(file) ## uf20-files take on average 30 s using GSAT max_restarts = 10000 max_climbs = 10 ## uf20-files are almost instantly for the WalkSAT max_flips = 30000 probability = 5 GSAT = GSAT(KB, file, max_restarts, max_climbs) start_time = time.time() solution = GSAT.search() cpu_secsGSAT = time.time() - start_time
def main(): config_data = readFile() # HDD_size = config_data.get("HDD_size") # TB Rep_num = config_data.get("R_number") DISK_num = config_data.get("DISK_num") Latency_range = config_data.get("Latency_range") REP_FAC = config_data.get("REP_FAC") DATA_NUM = config_data.get("DATA_NUM") print(config_data) r_data = list() x_y_temp = dict() batch = 10 ''' Initialize ''' print("--------------- Initialize ---------------") disks = init_disks(DISK_num, Latency_range) data_list, replica_list = init_datas(DATA_NUM, REP_FAC) deploy_replica(disks, replica_list) Result_data = dict() # for i in range(0, batch): print("--------------- hadoop ---------------") disk_cp1 = copy.deepcopy(disks) x1, y1, max_load = hadoop_naive(disk_cp1, data_list, replica_list) x_y_temp = dict() x_y_temp["x"] = x1 x_y_temp["y"] = y1 r_data.append(x_y_temp) # Result_data["hadoop"] # # print("--------------- random ---------------") # disk_cp2 = copy.deepcopy(disks) # x2,y2, max_load = random_naive(disk_cp2, data_list, replica_list) # print("--------------- greedy ---------------") disk_cp3 = copy.deepcopy(disks) x3, y3, max_load = greedy(disk_cp3, data_list, replica_list) x_y_temp = dict() x_y_temp["x"] = x3 x_y_temp["y"] = y3 r_data.append(x_y_temp) print("--------------- DLP-random ---------------") disk_cp4 = copy.deepcopy(disks) x4, y4, max_load = DLP_random(disk_cp4, data_list, replica_list) x_y_temp = dict() x_y_temp["x"] = x4 x_y_temp["y"] = y4 r_data.append(x_y_temp) with open("r_data", "w") as file: json.dump(r_data, file) plt.figure() plt.xlim([0, DISK_num - 1]) plt.xticks(fontsize=14) plt.yticks(fontsize=14) plt.xlabel("disk", fontsize=14) plt.ylabel("latency", fontsize=14) plt.step(x1, y1, color="red", label="Hadoop", where="post") # plt.step(x2, y2, label="random", color="blue", where="post") plt.step(x3, y3, color="black", label="HTS-greedy", linestyle="-.", where="post") plt.step(x4, y4, color="green", label="HTS-rdm", linestyle="--", where="post") plt.legend(loc="upper right") # foo_fig = plt.gcf() # 'get current figure' # foo_fig.savefig('instance.eps', format='eps', dpi=1000) # plt.savefig('./plteps.eps', format='eps', dpi=1000) file_name = "fig3_6.eps" plt.savefig(file_name, bbox_inches='tight', format='eps', dpi=5000) plt.show() with open("r_data_6", "w") as file: json.dump(r_data, file)
temp = input[i].split(" ") command = temp[0] argument = int(temp[1]) if command == 'nop': i += 1 if command == 'acc': i += 1 acc += argument if command == 'jmp': i += argument return acc, True input = readFile.readFile(FILE) ######part1############ acc, _ = process(input) ########part2########## acc2: int = 0 for i in range(len(input)): temp = input[i].split(" ") command = temp[0] argument = temp[1] if command == 'acc': continue
e_occu = [str(i) for i in range(21)] w_occu = getRanWeight(len(e_occu), 1) e_zcode = [str(i) for i in range(10)] w_zcode = getRanWeight(len(e_zcode), 1) e_year = [str(i) for i in range(190, 202)] w_year = getRanWeight(len(e_year), 1) e_genres = ['Action', 'Adventure', 'Animation', "Children's", 'Comedy', 'Crime' , 'Documentary', 'Drama', 'Fantasy', 'Film-Noir', 'Horror', 'Musical' , 'Mystery', 'Romance', 'Sci-Fi', 'Thriller', 'War', 'Western'] w_genres = getRanWeight(len(e_genres), 1) [id, gender, age, occupation, zipcode, title, genres, rating] = readFile('/test/reTrainData.test.dat', 1, '::') gender = np.array([[0.0] for i in range(len(e_gender))]) age = np.array([[0.0] for i in range(len(e_age))]) occu = np.array([[0.0] for i in range(len(e_occu))]) zcode = np.array([[0.0] for i in range(len(e_zcode))]) year = np.array([[0.0] for i in range(len(e_year))]) genres = np.array([[0.0] for i in range(len(e_genres))]) rating = 0 layer0 = np.array([[0.0] for i in range(6)]) # value of layer0 syn0 = getRanWeight(len(layer0), len(layer0) * 2) layer1 = None syn1 = getRanWeight(len(layer0) * 2, 1)