class ProbDriver(Driver): def __init__(self): self.svmProcessor = SVMProcessor() self.probFeatureExtractor = ProbFeatureExtractor() self.preProcessor = PreProcessor() def data_process(self, filePath): ListT, ListX, ListY, ListP = self.pre_process(filePath) ListR = self.svmProcessor.radius(ListX, ListY) ListVX = self.svmProcessor.velocity_of_x(ListX, ListT) ListVY = self.svmProcessor.velocity_of_y(ListY, ListT) ListAX = self.svmProcessor.acc_of_vx(ListVX, ListT) ListAY = self.svmProcessor.acc_of_vy(ListVY, ListT) return ListT, ListR, ListVX, ListVY, ListAX, ListAY def generate_features(self, filePath): ListT, ListR, ListVX, ListVY, ListAX, ListAY = self.data_process( filePath) self.probFeatureExtractor.generate_features(ListT, ListR, ListVX, ListVY, ListAX, ListAY) return self.probFeatureExtractor.features() def feature_clear(self): self.probFeatureExtractor.clear() def PS(self, F): P = [] for i in range(len(F)): p = numpy.exp(-1 * pow( (F[i] - self.meanF[i]), 2) / 2 / self.varF[i]) / numpy.sqrt( 2 * self.meanF[i] * self.varF[i]) P.append(p) # print [round(p, 11) for p in P] # print numpy.isnan(P) PArray = numpy.asarray(P) PArray[numpy.isnan(PArray)] = 0 return PArray.sum() def ps_temp(self, ListF): self.meanF = [] self.varF = [] Features = [] for F in ListF: for i in range(len(F)): if i >= len(Features): Features.append([]) Features[i].append(F[i]) for F in Features: self.meanF.append(numpy.mean(F)) self.varF.append(numpy.var(F))
class ProbDriver(Driver): def __init__(self): self.svmProcessor = SVMProcessor() self.probFeatureExtractor = ProbFeatureExtractor() self.preProcessor = PreProcessor() def data_process(self, filePath): ListT, ListX, ListY, ListP = self.pre_process(filePath) ListR = self.svmProcessor.radius(ListX, ListY) ListVX = self.svmProcessor.velocity_of_x(ListX, ListT) ListVY = self.svmProcessor.velocity_of_y(ListY, ListT) ListAX = self.svmProcessor.acc_of_vx(ListVX, ListT) ListAY = self.svmProcessor.acc_of_vy(ListVY, ListT) return ListT, ListR, ListVX, ListVY, ListAX, ListAY def generate_features(self, filePath): ListT, ListR, ListVX, ListVY, ListAX, ListAY = self.data_process(filePath) self.probFeatureExtractor.generate_features(ListT, ListR, ListVX, ListVY, ListAX, ListAY) return self.probFeatureExtractor.features() def feature_clear(self): self.probFeatureExtractor.clear() def PS(self, F): P = [] for i in range(len(F)): p = numpy.exp(-1 * pow((F[i] - self.meanF[i]), 2) / 2 / self.varF[i]) / numpy.sqrt( 2 * self.meanF[i] * self.varF[i] ) P.append(p) # print [round(p, 11) for p in P] # print numpy.isnan(P) PArray = numpy.asarray(P) PArray[numpy.isnan(PArray)] = 0 return PArray.sum() def ps_temp(self, ListF): self.meanF = [] self.varF = [] Features = [] for F in ListF: for i in range(len(F)): if i >= len(Features): Features.append([]) Features[i].append(F[i]) for F in Features: self.meanF.append(numpy.mean(F)) self.varF.append(numpy.var(F))
class SVMDriver(Driver): def __init__(self): self.preProcessor = PreProcessor() self.svmProcessor = SVMProcessor() self.svmFeatureExtractor = SVMFeatureExtractor() def data_process(self, fileName): ListT, ListX, ListY, ListP = self.pre_process(fileName) ListR = self.svmProcessor.radius(ListX, ListY) ListVX = self.svmProcessor.velocity_of_x(ListX, ListT) ListVY = self.svmProcessor.velocity_of_y(ListY, ListT) ListVR = self.svmProcessor.velocity_of_r(ListR, ListT) ListVP = self.svmProcessor.velocity_of_p(ListP, ListT) ListAX = self.svmProcessor.acc_of_vx(ListVX, ListT) ListAY = self.svmProcessor.acc_of_vy(ListVY, ListT) ListAR = self.svmProcessor.acc_of_vr(ListVR, ListT) return ListT, ListX, ListY, ListP, ListR, ListVX, ListVY, ListVR, ListVP, ListAX, ListAY, ListAR def generate_features(self, fileName): ListT, ListX, ListY, ListR, ListP, ListVX, ListVY, ListVR, ListVP, ListAX, ListAY, ListAR = self.data_process( fileName ) self.svmFeatureExtractor.generate_features( ListT, ListX, ListY, ListR, ListP, ListVX, ListVY, ListVR, ListVP, ListAX, ListAY, ListAR ) return self.svmFeatureExtractor.features() def feature_clear(self): self.svmFeatureExtractor.clear()
class SVMDriver(Driver): def __init__(self): self.preProcessor = PreProcessor() self.svmProcessor = SVMProcessor() self.svmFeatureExtractor = SVMFeatureExtractor() def data_process(self, fileName): ListT, ListX, ListY, ListP = self.pre_process(fileName) ListR = self.svmProcessor.radius(ListX, ListY) ListVX = self.svmProcessor.velocity_of_x(ListX, ListT) ListVY = self.svmProcessor.velocity_of_y(ListY, ListT) ListVR = self.svmProcessor.velocity_of_r(ListR, ListT) ListVP = self.svmProcessor.velocity_of_p(ListP, ListT) ListAX = self.svmProcessor.acc_of_vx(ListVX, ListT) ListAY = self.svmProcessor.acc_of_vy(ListVY, ListT) ListAR = self.svmProcessor.acc_of_vr(ListVR, ListT) return ListT, ListX, ListY, ListP, ListR, ListVX, ListVY, ListVR, \ ListVP, ListAX, ListAY, ListAR def generate_features(self, fileName): ListT, ListX, ListY, ListR, ListP, ListVX, ListVY, ListVR, ListVP, \ ListAX, ListAY, ListAR = self.data_process(fileName) self.svmFeatureExtractor.generate_features(ListT, ListX, ListY, ListR, ListP, ListVX, ListVY, ListVR, ListVP, ListAX, ListAY, ListAR) return self.svmFeatureExtractor.features() def feature_clear(self): self.svmFeatureExtractor.clear()
def __init__(self): self.svmProcessor = SVMProcessor() self.probFeatureExtractor = ProbFeatureExtractor() self.preProcessor = PreProcessor()
def features_of_acceleration(self, ListAR, ListAX, ListAY): """ acceleration related features """ maxAR = self._max(ListAR) maxAX = self._max(ListAX) maxAY = self._max(ListAY) minAR = self._min(ListAR) minAX = self._min(ListAX) minAY = self._min(ListAY) avgAR = self._avg(ListAR) avgAX = self._avg(ListAX) avgAY = self._avg(ListAY) stdAX = self._std(ListAX) stdAY = self._std(ListAY) avgPosAX = numpy.mean(self._select_positive(ListAX)) avgPosAY = numpy.mean(self._select_positive(ListAY)) avgNegAX = numpy.mean(self._select_negative(ListAX)) avgNegAY = numpy.mean(self._select_negative(ListAY)) ListAbsAX = SVMProcessor.abs_acc_of_x(SVMProcessor(), ListAX) ListAbsAY = SVMProcessor.abs_acc_of_y(SVMProcessor(), ListAY) avgAbsAX = self._avg(ListAbsAX) avgAbsAY = self._avg(ListAbsAY) maxAbsAX = self._max(ListAbsAX) maxAbsAY = self._max(ListAbsAY) stdAbsAX = self._std(ListAbsAX) stdAbsAY = self._std(ListAbsAY) pointsCntGtZeroAX = self._points_gt_zero(ListAX) pointsCntLtZeroAX = self._points_lt_zero(ListAX) pointsCntGtZeroAY = self._points_gt_zero(ListAY) pointsCntLtZeroAY = self._points_lt_zero(ListAY) self.svmFeature.append(maxAR) # 88 self.svmFeature.append(avgAR) # 89 self.svmFeature.append(0) # 90 ####TODO#### self.svmFeature.append(0) # 91 ####TODO#### self.svmFeature.append(stdAX) # 92 self.svmFeature.append(stdAY) # 93 self.svmFeature.append(avgAbsAX / maxAbsAX) # 94 self.svmFeature.append(avgAbsAY / maxAbsAY) # 95 self.svmFeature.append(avgAX / self.avgPosVX) # 96 self.svmFeature.append(avgAY / self.avgPosVY) # 97 self.svmFeature.append(avgAR / self.maxVR) # 98 self.svmFeature.append(minAR / self.avgVR) # 99 self.svmFeature.append(minAY / avgAY) # 100 self.svmFeature.append(avgPosAX / avgNegAX) # 101 self.svmFeature.append(maxAR / self.avgPosVX) # 102 self.svmFeature.append(maxAR / self.avgPosVY) # 103 self.svmFeature.append(maxAR / self.avgNegVX) # 104 self.svmFeature.append(maxAR / self.avgNegVY) # 105 self.svmFeature.append(minAR / self.avgPosVX) # 106 self.svmFeature.append(minAR / self.avgPosVY) # 107 self.svmFeature.append(minAR / self.avgNegVX) # 108 self.svmFeature.append(minAR / self.avgNegVY) # 109 self.svmFeature.append(avgNegAY / avgPosAY) # 110 self.svmFeature.append(avgAR / self.avgNegVX) # 111 self.svmFeature.append(avgAR / self.avgNegVY) # 112 self.svmFeature.append(avgAbsAX) # 113 self.svmFeature.append(avgAbsAY) # 114 self.svmFeature.append(stdAbsAX) # 115 self.svmFeature.append(stdAbsAY) # 116 self.svmFeature.append(maxAX) # 117 self.svmFeature.append(minAX) # 118 self.svmFeature.append(maxAY) # 119 self.svmFeature.append(minAY) # 120 self.svmFeature.append(avgAX) # 121 self.svmFeature.append(avgAY) # 122 self.svmFeature.append(pointsCntGtZeroAX) # 123 self.svmFeature.append(pointsCntLtZeroAX) # 124 self.svmFeature.append(pointsCntGtZeroAY) # 125 self.svmFeature.append(pointsCntLtZeroAY) # 126
def features_of_velocity(self, ListVX, ListVY, ListVR): """ velocity related features """ # 将ListVX, ListVY, ListVR保存 self.ListVX = ListVX self.ListVY = ListVY self.ListVR = ListVR self.avgVX = self._avg(ListVX) self.avgVY = self._avg(ListVY) self.avgVR = self._avg(ListVR) self.maxVX = self._max(ListVX) self.maxVY = self._max(ListVY) self.maxVR = self._max(ListVR) self.minVX = self._min(ListVX) self.minVY = self._min(ListVY) self.minVR = self._min(ListVR) posVX = self._select_positive(ListVX) posVY = self._select_positive(ListVY) negVX = self._select_negative(ListVX) negVY = self._select_negative(ListVY) self.avgPosVX = numpy.mean(posVX) self.avgPosVY = numpy.mean(posVY) self.maxPosVX = max(posVX) self.maxPosVY = max(posVY) self.minPosVX = min(posVX) self.minPosVY = min(posVY) self.avgNegVX = numpy.mean(negVX) self.avgNegVY = numpy.mean(negVY) self.maxNegVX = max(negVX) self.maxNegVY = max(negVY) self.minNegVX = min(negVX) self.minNegVY = min(negVY) self.stdVX = self._std(ListVX) self.stdVY = self._std(ListVY) ListAbsVX = SVMProcessor.abs_velocity_of_x(SVMProcessor(), ListVX) ListAbsVY = SVMProcessor.abs_velocity_of_y(SVMProcessor(), ListVY) self.avgAbsVX = self._avg(ListAbsVX) self.avgAbsVY = self._avg(ListAbsVY) self.stdAbsVX = self._std(ListAbsVX) self.stdAbsVY = self._std(ListAbsVY) self.svmFeature.append(self.avgVX) # 1 self.svmFeature.append(self.avgVY) # 2 self.svmFeature.append(self.stdVX) # 3 self.svmFeature.append(self.stdVY) # 4 self.svmFeature.append(self.avgVR) # 5 self.svmFeature.append(self.maxVX/self.maxVY) # 6 self.svmFeature.append(self.avgPosVX/self.maxPosVX) # 7 self.svmFeature.append(self.avgPosVY/self.maxPosVY) # 8 self.svmFeature.append(self.avgNegVX/self.maxNegVX) # 9 self.svmFeature.append(self.avgNegVY/self.maxNegVY) # 10 self.svmFeature.append(self.avgVR/self.maxVR) # 11 self.svmFeature.append(self.minVX/self.maxVX) # 12 self.svmFeature.append(self.minVY/self.maxVY) # 13 self.svmFeature.append(self.minVX/self.avgVX) # 14 self.svmFeature.append(self.minVY/self.avgVY) # 15 self.svmFeature.append(self.minVR/self.maxVR) # 16 self.svmFeature.append(self.avgPosVX/self.avgNegVX) # 17 self.svmFeature.append(self.avgPosVY/self.avgNegVY) # 18 self.svmFeature.append(self.avgPosVX/self.avgPosVY) # 19 self.svmFeature.append(self.avgPosVX/self.avgNegVY) # 20 self.svmFeature.append(self.avgNegVX/self.avgPosVY) # 21 self.svmFeature.append(self.avgNegVX/self.avgNegVY) # 22 self.svmFeature.append(self.avgPosVX/self.maxNegVX) # 23 self.svmFeature.append(self.avgPosVY/self.maxNegVY) # 24 self.svmFeature.append(self.minVX/self.avgVX) # 25 self.svmFeature.append(self.minVY/self.avgVY) # 26 self.svmFeature.append(self.avgVX/self.maxVX) # 27 self.svmFeature.append(self.avgVY/self.maxVY) # 28 self.svmFeature.append(self.avgPosVX) # 29 self.svmFeature.append(self.avgPosVY) # 30 self.svmFeature.append(self.avgNegVX) # 31 self.svmFeature.append(self.avgNegVY) # 32 self.svmFeature.append(self.maxVX) # 33 self.svmFeature.append(self.maxVY) # 34 self.svmFeature.append(self.avgVX) # 35 self.svmFeature.append(self.avgVY) # 36 self.svmFeature.append(self.avgAbsVX) # 37 self.svmFeature.append(self.avgAbsVY) # 38 self.svmFeature.append(self.stdAbsVX) # 39 self.svmFeature.append(self.stdAbsVY) # 40 self.svmFeature.append(self._points_lt_zero(self.ListVX)) # 41 self.svmFeature.append(self._points_lt_zero(self.ListVY)) # 42 self.svmFeature.append(self._points_gt_zero(self.ListVX)) # 43 self.svmFeature.append(self._points_gt_zero(self.ListVY)) # 44 self.svmFeature.append(self.maxNegVX) # 45 self.svmFeature.append(self.maxNegVY) # 46