def BM25(): contain = 0 prevContain = 0 n = 0 lengthDocs = [] idfList = [] scores = [] preScore = [] #result = [] for i in range(len(keywords)): for j in range(len(textFiles)): lenD, freq = readFile(textFiles[j], keywords[i]) contain = contain + freq if contain != prevContain: n = n + 1 prevContain = contain if i==0: lengthDocs.append(lenD) # Calculating the IDF: tmp = (N - n + 0.5)/(n + 0.5) idf = math.log(abs(tmp)) idfList.append(idf) # Clearing the accumulated values from the variables: contain = 0 n = 0 # Calculating avgdl: avgdl = sum(lengthDocs)/N # Makes no sense why there is an error here... for i in range(len(textFiles)): for j in range(len(keywords)): lengthD, frequency = readFile(textFiles[i], keywords[j]) tmpScore = idfList[j]*((frequency * (k1 + 1))/(frequency + k1*(1 - b + b*(lengthD/avgdl)))) preScore.append(tmpScore) score = sum(preScore) # sum all the calculated scores for the current document scores.append(score) # put each calculated score for each document in an array. preScore = [] # Clearing preScore list in order to not add old values #print scores toBeOrdered = zip(textFiles,scores) #print toBeOrdered result = sorted(toBeOrdered, key=lambda toBeOrdered: toBeOrdered[1],reverse=True) return result
def anneal(file, numColors, temperature, minTemperature, alpha, steps): adjMatrix, numVertices = readFile(file) numColors = numColors numColors -= 1 temperature = temperature minTemperature = minTemperature alpha = alpha steps = steps solution = generateSolution(numVertices, numColors) cost, startNeighbour = checkCost(adjMatrix, solution) while temperature > minTemperature and cost != 0: i = 1 while i <= steps: newSolution = genNeighbour(solution, numColors, startNeighbour) newCost, startNeighbour = checkCost(adjMatrix, solution) accept = acceptance(cost, newCost, temperature) if accept > random(): solution = newSolution cost = newCost i += 1 print("Solution: " + str(solution) + " / " + " Colors: " + str(numColors + 1) + " / " + " Temp: " + str(temperature) + " / " + " Cost: " + str(cost)) temperature = temperature * alpha numColors += 1 return solution, cost
def reverse(FileName): listRe = [] for dirs in os.listdir(magneticDataPath +FileName): print dirs CF01x,CF01y,CF01z,CF01xyz = readFile(magneticDataPath +FileName,dirs); listRe.append(CF01xyz.reverse()) return listRe,
def main(): BC2x, BC2y, BC2z, BC2xyz = readFile(acceleroDataPath, 'BC.txt') BH2x, BH2y, BH2z, BH2xyz = readFile(acceleroDataPath, 'BH.txt') DB2x, DB2y, DB2z, DB2xyz = readFile(acceleroDataPath, 'AF.txt') AF2x, AF2y, AF2z, AF2xyz = readFile(acceleroDataPath, 'DB.txt') label = ['x', 'Y', 'Z', 'D'] AlistRaw = [BH2x, BH2y, BH2z, BH2xyz] #JZx,JZy,JZz,JZxyz=readFile('jiaozheng.txt')#path 1123 #plotNlines(AlistRaw,label) ############# AlistMean = [] AlistLPF = [] for data in AlistRaw: AlistMean.append(meanF(data, win)) for data2 in AlistMean: AlistLPF.append(LPF(data2)) #plotNlines(AlistRaw,AlistLPF) #plotLine3(BH2x,BH2y,BH2z) #plotLine1(BH2xyz) BC2xyzm = meanF(BC2xyz, win) BH2xyzm = meanF(BH2xyz, win) DB2xyzm = meanF(DB2xyz, win) AF2xyzm = meanF(AF2xyz, win) #lxyz = LPF(BH2xyzm) #plotLine2(BH2xyz,BH2xyzm) Wei = [] Scar = [] Kim = [] reaL = [14.8, 12, 30, 17.78] j = 0 dataList = [BC2xyzm, BH2xyzm, DB2xyzm, AF2xyzm] for data in dataList: stepizeList1, stepizeList2, stepizeList3 = StepSize(data) #print sum(stepizeList1),sum(stepizeList2),sum(stepizeList3),reaL[j],\ #sum(stepizeList1)/reaL[j],sum(stepizeList2)/reaL[j],sum(stepizeList3)/reaL[j]; print avrAbs(stepizeList1), avrAbs(stepizeList2), avrAbs(stepizeList3) Wei.append(stepizeList1) Scar.append(stepizeList2) Kim.append(stepizeList3) plotNline(Wei, Scar, Kim)
def readData(FileName): Datalist=[] MinLen = [] for dirs in os.listdir(magneticDataPath +FileName): print dirs CF01x,CF01y,CF01z,CF01xyz = readFile(magneticDataPath +FileName,dirs); Datalist.append(CF01xyz);MinLen.append(len(CF01xyz)) Datalist.append(CF01xyz);MinLen.append(len(CF01xyz)) minL = min(MinLen) return minL,Datalist
oupbOltOirPorcent = getPercentage(oltOupbOirRange, len(listOltOir)) if oupbMipOirPorcent <= oupbOltOirPorcent: oltminor = oltOupbOirRange[0].olt olthigher = oltOupbOirRange[len(oltOupbOirRange) - 1].olt else: oltminor = oltMipOirRange[0].olt olthigher = oltMipOirRange[len(oltMipOirRange) - 1].olt rangs = Perfil(csminor, cshigher, oirminor, oirhigher, oltvminor, oltvhigher, mipminor, miphigher, ocltvoltvminor, ocltvoltvhigher, nobminor, nobhigher, oupbminor, oupbhigher, oltminor, olthigher, idGrupo) return rangs data = [] data = readFile() perfiles = [] listToSearch = [] listToEval = [] grupo0complete = (list(filter(lambda x: x.grupo == 0, data))) grupo0final = (list(filter(lambda x: x.cs >= 660, grupo0complete))) perfiles.append(ranges(grupo0final, 832, 0, listToSearch, listToEval)) grupo1complete = (list(filter(lambda x: x.grupo == 1, data))) grupo1final = (list(filter(lambda x: x.cs >= 660, grupo1complete))) perfiles.append(ranges(grupo1final, 850, 1, listToSearch, listToEval)) grupo2complete = (list(filter(lambda x: x.grupo == 0, data))) grupo2final = (list(filter(lambda x: x.cs >= 510, grupo2complete))) perfiles.append(ranges(grupo2final, 660, 2, listToSearch, listToEval)) grupo3complete = (list(filter(lambda x: x.grupo == 1, data))) grupo3final = (list(filter(lambda x: x.cs >= 428, grupo3complete))) perfiles.append(ranges(grupo3final, 660, 3, listToSearch, listToEval))
def passageTermMatching(): contain = 0 #ok prevContain = 0 #ok n = 0 #ok #lengthDocs = [] idfList = [] wList = [] #termInPassage = [] scores = [] nList = [] #preScore = [] #result = [] for i in range(len(keywords)): for j in range(len(textFiles)): lenD, freq = readFile(textFiles[j], keywords[i]) contain = contain + freq if contain != prevContain: n = n + 1 #termInPassage.append(1) #else: #termInPassage.append(0) prevContain = contain #if i==0: # lengthDocs.append(lenD) # Calculating the IDF: nList.append(n) tmp = N/(n + 1) idf = math.log(tmp) #may need to use abs(x) idfList.append(idf) #clearing some variables: contain = 0 n = 0 for i in range(len(textFiles)): for j in range(len(keywords)): lengthD, frequency = readFile(textFiles[i], keywords[j]) if frequency > 0: tmp1 = N/(nList[j] + 1) w = math.log(tmp1) else: w = 0 wList.append(w) frequency = 0 score = sum(wList)/sum(idfList) scores.append(score) #Clearing some variables: wList = [] toBeOrdered = zip(textFiles,scores) result = sorted(toBeOrdered, key=lambda toBeOrdered: toBeOrdered[1],reverse=True) return result
def main(): BH1x, BH1y, BH1z, BH1xyz = readFile(magneticDataPath, 'BH1.txt') BH2x, BH2y, BH2z, BH2xyz = readFile(magneticDataPath, 'BH2.txt') BH3x, BH3y, BH3z, BH3xyz = readFile(magneticDataPath, 'BH3.txt') BCx, BCy, BCz, BCxyz = readFile(magneticDataPath, 'BC.txt') CFx, CFy, CFz, CFxyz = readFile(magneticDataPath, 'CF.txt') HGx, HGy, HGz, HGxyz = readFile(magneticDataPath, 'HG.txt') CBx, CBy, CBz, CBxyz = readFile(magneticDataPath, 'CB.txt') FCx, FCy, FCz, FCxyz = readFile(magneticDataPath, 'FC.txt') GHx, GHy, GHz, GHxyz = readFile(magneticDataPath, 'GH.txt') BC2x, BC2y, BC2z, BC2xyz = readFile(magneticDataPath, 'BC2.txt') CF2x, CF2y, CF2z, CF2xyz = readFile(magneticDataPath, 'CF2.txt') CFlist = [] CF01x, CF01y, CF01z, CF01xyz = readFile(magneticDataPath26, 'CF01.txt') CFlist.append(CF01xyz) CF02x, CF02y, CF02z, CF02xyz = readFile(magneticDataPath26, 'CF02.txt') CFlist.append(CF02xyz) CF03x, CF03y, CF03z, CF03xyz = readFile(magneticDataPath26, 'CF03.txt') CFlist.append(CF03xyz) CF04x, CF04y, CF04z, CF04xyz = readFile(magneticDataPath26, 'CF04.txt') CFlist.append(CF04xyz) CF05x, CF05y, CF05z, CF05xyz = readFile(magneticDataPath26, 'CF05.txt') CFlist.append(CF05xyz) CF06x, CF06y, CF06z, CF06xyz = readFile(magneticDataPath26, 'CF06.txt') CFlist.append(CF06xyz) CF07x, CF07y, CF07z, CF07xyz = readFile(magneticDataPath26, 'CF07.txt') CFlist.append(CF07xyz) CF08x, CF08y, CF08z, CF08xyz = readFile(magneticDataPath26, 'CF08.txt') CFlist.append(CF08xyz) CF09x, CF09y, CF09z, CF09xyz = readFile(magneticDataPath26, 'CF09.txt') CFlist.append(CF09xyz) CF10x, CF10y, CF10z, CF10xyz = readFile(magneticDataPath26, 'CF10.txt') CFlist.append(CF10xyz) BCx, BCy, BCz, BCxyz = readFile(magneticDataPath, 'BC.txt') BCxMI, BCyMI, BCzMI, BCxyzMI = readFile(magneticDataPathXiaoMi, 'BC.txt') BCxHW, BCyHW, BCzHW, BCxyzHW = readFile(magneticDataPathHuawei, 'BC.txt') #JZx,JZy,JZz,JZxyz=readFile('jiaozheng.txt')#path 1123 ACFx, ACFy, ACFz, ACFxyz = readFile(acceleroDataPath, 'CF.txt') #plotFilterLines(ACFx,ACFz) ADx, ADy, ADz, ADxyz = readFile(longTinePtah, 'AD.txt') AD1x, AD1y, AD1z, AD1xyz = readFile(longTinePtah, 'AD2.txt') AD2x, AD2y, AD2z, AD2xyz = readFile(longTinePtah, 'AD3.txt') AD3x, AD3y, AD3z, AD3xyz = readFile(longTinePtah, 'AD4.txt') mAD = meanF(ADxyz, win) mAD1 = meanF(AD1xyz, win) mAD2 = meanF(AD2xyz, win) mAD3 = meanF(AD3xyz, win) ADLF = LPF(mAD) ADLF1 = LPF(mAD1) ADLF2 = LPF(mAD2) ADLF3 = LPF(mAD3) ############# mGH = meanF(GHxyz, win) GHmhf1 = LPF(mGH) #plotLine2(GHmhf1,mGH,'LPF')#plot the LPF raw data ############# mBH1 = meanF(BH1xyz, win) mBH2 = meanF(BH2xyz, win) mBH3 = meanF(BH3xyz, win) BHf1 = LPF(mBH1) BHf2 = LPF(mBH2) BHf3 = LPF(mBH3) #plotLine3(BHf1,BHf2,BHf3)#plot the 3 in one ################## mBC = meanF(BCxyz, win) mCF = meanF(CFxyz, win) mHG = meanF(HGxyz, win) BCf = LPF(mBC) CFf = LPF(mCF) HGf = LPF(mHG) #plotLine4(BHf2,BCf,HGf,CFf)#4lines4gallary ################### mGH = meanF(GHxyz, win) GHf = LPF(mGH) GHf.reverse() #plotLine2(GHf,HGf,'direction')#plot the TWO direction #plotLine2(GHf,HGf,'HPF')#plot the HPFd raw data #plotFilterLines(BHf1,BHf2,BHf3,GHf,HGf) ################### mBC2 = meanF(BC2xyz, win) BC2f = LPF(mBC2) #plotLine2(BC2f,BCf,'') #print dtw (np.array(BC2f),np.array(BCf)) #and the slow ################### mCFlist = [] lpfCFlist = [] hpfCFlist = [] hlpfCFlist = [] standList = [] for Mdata in CFlist: mCFlist.append(meanF(Mdata, win)) for mCF0 in mCFlist: lpfCFlist.append(LPF(mCF0)) for mCF0 in mCFlist: hpfCFlist.append(HPF(mCF0)) for mhCF0 in hpfCFlist: hlpfCFlist.append(LPF(mhCF0)) #standList = standard(mCFlist) for dataLPF in lpfCFlist: standList.append(standard(dataLPF)) #plotNlines(lpfCFlist,hlpfCFlist,standList) ################### #plot 3 line for 3 devices mBC = meanF(BCxyz, win) BCL = LPF(mBC) mBCMI = meanF(BCxyzMI, win) BCLMI = LPF(mBCMI) mBCHW = meanF(BCxyzHW, win) BCLHW = LPF(mBCHW) #print dtw(mBC,mBCHW) #print dtw(mBCMI,mBC) #print dtw(mBCMI,mBCHW) #plotLine3(BCL,BCLMI,BCLHW)#plot the 3 DEVICES #plotFilterLines(ADLF,ADLF1,ADLF2,BCL,BCLMI,BCLHW) ##################### #plotFilterLines(BCxyz,mBC,BCL) ##################### mCF2 = meanF(CF2xyz, win) CF2f = LPF(mCF2) mCF02 = meanF(CF02xyz, win) CF02f = LPF(mCF02) mCF04 = meanF(CF04xyz, win) CF04f = LPF(mCF04) mCF01 = meanF(CF01xyz, win) CF01f = LPF(mCF01) mCF03 = meanF(CF03xyz, win) CF03f = LPF(mCF03) #print dtw (np.array(CF02f),np.array(CF2f)) #print dtw (np.array(CF02f),np.array(CF04f)) #print dtw (np.array(CF02f),np.array(HGf)) # plotLine4lines(BHf2,BCf,HGf,CFf) #plotLine3(CF02f,CF2f,CF04f) plotFilterLines(CF01f, CF04f, CF03f, BCL, BCLMI, BCLHW)