def makeRQAcsvFiles(dataSets, pathFile, lenTimeSeries = 25, epsilon = 0.08, lambd = 2, interpolationKind = None): content = [] title = "TimeSeries; || ;RR; DET; LAM; RATIO; averageL; averageH; Lmax; Hmax; DIV; ENTR; averageTime1; averageTime2\n" content.append(title) for dataSet in dataSets: for i in range(int(len(dataSet)/lenTimeSeries)): start = i*lenTimeSeries end = (i+1)*lenTimeSeries rqa = getRQA(dataSet[start:end], epsilon = epsilon, lambd = lambd, interpolationKind = interpolationKind, typeReturn = 'array') print(rqa) line = str(dataSet[start:end]) + "; || " if (rqa!=None): for item in rqa: line += ";" + str(item) line += '\n' content.append(line) line = "---------; || ;; ; ; ; ; ; ; ; ; ; ; \n" content.append(line) myCrpFunctions.writeContentToFile(pathFile, content) return 0
def makeRQAcsvFiles(dataSets, pathFile, windowSize=10, epsilon=0.08, lambd=2, interpolationKind=None, numPointInterp=201): content = [] title = "Shape ;RR; DET; LAM; averageL; averageH; Lmax; Hmax; ENTR; averageTime1; averageTime2\n" content.append(title) for dataSet in dataSets: shape = dataSet[1][0] if (shape > 0): timeSeries = dataSet[0] # print('---------data--------',dataSet[0]) for i in range(len(timeSeries) - windowSize): start = i end = i + windowSize rqa = getRQA(timeSeries[start:end], epsilon=epsilon, lambd=lambd, interpolationKind=interpolationKind, typeReturn='array', numPointInterp=numPointInterp) print(rqa) if (rqa != None): line = str(shape) + " " for item in rqa: line += ";" + str(item) for sample in timeSeries[start:end]: line += ";" + str(sample) line += "\n" content.append(line) # content.append(line) print('content: \n') print(content) myCrpFunctions.writeContentToFile(pathFile, content) return 0
def checkRecall(outputFolder=None): TP = TN = FP = FN = 1 floatShape = float(shape) for i in range(len(testShape)): if (floatShape == shapePredict[i]): if (floatShape == testShape[i]): TP += 1 else: FP += 1 else: if (floatShape != testShape[i]): TN += 1 else: FN += 1 print("TP: %5d, FP: %5d, FN: %5d, TN: %5d" % (TP, FP, FN, TN)) pi = TP / (TP + FP) p = TP / (TP + FN) f1 = 2 * pi * p / (pi + p) print("pi = %2.2f" % pi) print("p = %2.2f" % p) print("f1 = %2.2f" % f1) if (outputFolder != None): print(outputFolder) import time import datetime checkID = datetime.datetime.fromtimestamp( time.time()).strftime('%d/%m/%Y::%Hh%Mp%Ss') content = ["{}\n{}".format(checkID, outputFolder)] content.append( '\n TP: {:5}\n FP: {:5}\n FN: {:5}\n TN: {:5}\n '.format( TP, FP, FN, TN)) content.append('pi = {:2.2}\n '.format(pi)) content.append('p = {:2.2}\n '.format(p)) content.append('f1 = {:2.2}\n '.format(f1)) pathOut = outputFolder + "readme.txt" myCrpFunctions.writeContentToFile(pathOut, content)
def rqaCalculate(rpBinaryMatrix, keyDot = 1, lambd = 2, typeReturn = 'array', showCRP = 0): import math len_rpBinaryMatrix = int(np.size(rpBinaryMatrix[0])) N = high_rpBinaryMatrix = int(np.size(rpBinaryMatrix)/len_rpBinaryMatrix) content = [] for y in range(high_rpBinaryMatrix): s = ";".join(str(i+2) for i in rpBinaryMatrix[y] ) s += "\n" content.append(s) myCrpFunctions.writeContentToFile('rqaOut.csv', content) RR =0 DET = 0 LAM = 0 RATIO = 0 averageL = 0 averageH = 0 DIV = 0 ENTR = 0 TT = 0 # Duyệt các đường cao Ph, Hmax, averageTime1, averageTime2 = getPverticalLengthDot(rpBinaryMatrix, high_rpBinaryMatrix, len_rpBinaryMatrix, keyDot = keyDot) #Đếm số đường chéo theo độ dài Pl, Lmax = getPdiagonalLengthDot(rpBinaryMatrix, high_rpBinaryMatrix, len_rpBinaryMatrix, keyDot = keyDot) num_L = 0 num_H = 0 sum_Well_L = 0 sum_Well_H = 0 num_Well_L = 0 num_Well_H = 0 sumDot = Ph[0] # Đếm số điểm chấm theo đường thẳng, ph[0] là những đoạn chỉ có 1 chấm lmin = lambd - 1 for i in range(1, N+1, 1): sumDot += (i+1)*Ph[i] num_L += Pl[i] num_H += Ph[i] if (i>=lmin): sum_Well_L += Pl[i]*i sum_Well_H += Ph[i]*i num_Well_L += Pl[i] num_Well_H += Ph[i] RR = sumDot/(N**2) if num_L*num_Well_L > 0: DET = num_Well_L/num_L averageL = sum_Well_L/num_Well_L if (DET > 0): RATIO = DET/RR if num_H*num_Well_H > 0: LAM = num_Well_H/num_H averageH = sum_Well_H/num_Well_H for i in range(lmin, N, 1): if (Pl[i] > 0): pl = Pl[i]/num_Well_L ENTR -= pl*math.log(pl) if Lmax > 0: DIV = 1/Lmax if (showCRP == 1): import matplotlib.pyplot as plt x = myCrpFunctions.crossRecurrencePlots("test", rpBinaryMatrix, keyDot = keyDot, dotSize = 10 ) plt.show() print(RR) print(DET) print(LAM) print("averageL, averageH", averageL, averageH) print(Lmax, Hmax) print(DIV) print(ENTR) print("averageTime1, averageTime2", averageTime1, averageTime2) if (typeReturn == 'array'): return [RR, DET, LAM, RATIO, averageL, averageH, Lmax, Hmax, DIV, ENTR, averageTime1, averageTime2] if (typeReturn == 'dict'): return { "RR" : RR, "DET" : DET, "LAM" : LAM, "RATIO" : RATIO, "averageL" : averageL, "averageH" : averageH, "Lmax" : Lmax, "Hmax" : Hmax, "DIV" : DIV, "ENTR" : ENTR, "averageTime1" : averageTime1, "averageTime2" : averageTime2 }