def cleanFracs(fracs, plot=False, MAwindowSize=8, MAexp=1.4): frameSize = math.ceil(np.sqrt(len(fracs))) cleanedParts = [] originalParts = [] if(plot): pass #figOrigin = plt.figure() #figCleaned = plt.figure() i=1 for time, values in fracs: if(plot): pass #curr = figOrigin.add_subplot(frameSize, frameSize, i) #curr.plot(time,values) #length = int((time[-1] - time[0]) / 30) time, values = inter.getUniformSampled(time, values) originalParts.append(values) cleanesdValues = ma.movingAverage(values, MAwindowSize, MAexp) if(plot): plt.figure() plt.plot(values) plt.plot(cleanesdValues) plt.show() #curr = figCleaned.add_subplot(frameSize, frameSize, i) #curr.plot(time,values) cleanedParts.append(cleanesdValues) i+=1 return cleanedParts, originalParts
def analyzeDataInner(time, data, label): vec = [] featuresNames = [] v, f = getStats(data, label) vec += v featuresNames += f _, un = inter.getUniformSampled(time, data) cleaned = ma.movingAverage(un, 20, 1.1) v, f = getStats(cleaned, label + "after LPF ") vec += v featuresNames += f velocity = np.diff(cleaned) v, f = getStats(velocity, label + " velocity") vec += v featuresNames += f acceleration = np.diff(velocity) v, f = getStats(acceleration, label + " acceleration") vec += v featuresNames += f jurk = np.diff(acceleration) v, f = getStats(jurk, label + " jurk") vec += v featuresNames += f return vec, featuresNames
def plotResults(self, vec, positive, negetive): plt.figure() #plt.plot(vec) filtered = ma.movingAverage(vec, 50, 1.0) #plt.plot(filtered) filtered = pu.normalizeVector(filtered) plt.plot(filtered) change = [filtered[i+1]-filtered[i] for i in range(len(filtered)-1)] change = ma.movingAverage(change, 75, 1.0) change = pu.normalizeVector(change) plt.plot(change) #plt.figure() clustersByPercentilies = spike.clusterByPercemtile(change, 700, 80) plt.plot(clustersByPercentilies) clustersByPercentilies = pu.smoothOutliers(clustersByPercentilies) plt.plot(clustersByPercentilies) #plt.figure() ranges = self.prepareRanges(clustersByPercentilies) self.printConfedence(filtered, ranges, positive, negetive) plt.show()
row=[] for p2 in minedParts: dis = getDistanceBetweenFracs(p1, p2, lenOfCycle) row.append(dis) mat.append(row) print mat path = solve_tsp( mat ) print path #whole = qu.orderWithCost(minedParts, getDistanceBetweenFracs, appendFracs) whole = minedParts[path[0]] for i in path[1:]: whole = appendFracs(whole, minedParts[path[i]], lenOfCycle) whole = whole[0] plt.figure() whole = ma.movingAverage(whole, 10, 1.3) plt.plot(whole) #plt.plot() #plt.show() periods =[] strides = [] stances = [] swings = [] maximaOrder=15 clusteringGranularity=0.5 breaked = prt.breakToPeriods(whole,maximaOrder, clusteringGranularity) for cycle in breaked: if len(cycle)>25 and len(cycle)<60: #periods.append(cycle) strides.append(cycle) min = np.argmin(cycle)
def LPF(self): self.analysisVec = ma.movingAverage(self.analysisVec, 30, 1.1) return self.analysisVec