Пример #1
0
 def slideWindow(self, distance):
     if self.waveStart + distance < 0 or self.waveEnd + distance > self.waveLength or distance == 0:
         return
     else:
         self.waveStart = self.waveStart + distance
         if distance > 0:
             self.oldX = self.x[:distance]
             self.oldY = self.y[:distance]
             (self.newX,
              self.newY) = tde.slidePhaseSpace(self.wave, self.waveEnd + 44,
                                               distance, self.tauX)
             self.x = np.concatenate((self.x[distance:], self.newX))
             self.y = np.concatenate((self.y[distance:], self.newY))
             newPts = ou.getPointObjects(self.newX, self.newY)
             self.oct.appendPoints(newPts)
         else:
             self.oldX = self.x[distance:]
             self.oldY = self.y[distance:]
             (self.newX,
              self.newY) = tde.slidePhaseSpace(self.wave, self.waveStart,
                                               distance, self.tauX)
             self.x = np.concatenate((self.newX, self.x[:distance]))
             self.y = np.concatenate((self.newY, self.y[:distance]))
             newPts = ou.getPointObjects(self.newX, self.newY)
             self.oct.prependPoints(newPts)
         self.waveEnd = self.waveEnd + distance
Пример #2
0
 def killTrajectory(self, anyBin):
     ou.removeTraj(self.front,self.back)
     self.front.removeTrajectory(self)
     self.back.removeTrajectory(self)
     if self.tempPoints is not None:
         for tempPoint in self.tempPoints:
             closestRelative = tempPoint.findClosestRelative([self.front,self.back])
             ou.removeTempPt(tempPoint,closestRelative)
             tempPoint.removeTrajectory(self)
Пример #3
0
 def createTrajectories(self,lastPoint,points,isSyncWithBin):
     for point in points:
         if isSyncWithBin:
             ou.syncNewPointWithBin(point,self.firstLevel,lastPoint)
         bin1 = lastPoint.lowestBin
         bin2 = point.lowestBin
         if bin1 != bin2:
             ou.addTrajectory(lastPoint, point,bin1,bin2)
             self.splitBin(bin2)
         lastPoint=point
Пример #4
0
 def killPoints(self, removal):
     for point in removal:
         for traj in point.trajectories:
             traj.killTrajectory(self.firstLevel)
         editBin = ou.getBin(self.firstLevel, point.binPath)
         editBin.removePoint(point)
         self.manageBinMerge(editBin)
Пример #5
0
 def drawOctree(self):
     self.ax.scatter([self.minX, self.minX, self.maxX, self.maxX],
                     [self.minY, self.maxY, self.minY, self.maxY],
                     color='w',
                     s=1)
     binFacts, checkExtendedFamily = self.oct.getDualScaleBins(
         self.oct.firstLevel)
     shiftFacts = ou.getExtendedFamilyShifts(checkExtendedFamily)
     if shiftFacts is not None:
         binFacts.extend(shiftFacts)
     for bounds, intensity, isKey in binFacts:
         if isKey:
             self.ax.add_patch(
                 patches.Rectangle((bounds.minX, bounds.minY),
                                   bounds.maxX - bounds.minX,
                                   bounds.maxY - bounds.minY,
                                   alpha=0.7,
                                   color='c',
                                   ec='k',
                                   zorder=3))
         else:
             self.ax.add_patch(
                 patches.Rectangle((bounds.minX, bounds.minY),
                                   bounds.maxX - bounds.minX,
                                   bounds.maxY - bounds.minY,
                                   alpha=0.1,
                                   color='w',
                                   ec='k'))
Пример #6
0
 def getBoundsCreatePoints(self, xList, yList):
     self.maxX = float("-inf")
     self.maxY = float("-inf")
     self.minX = float("inf")
     self.minY = float("inf")
     prev_pt = None
     for idx, x in enumerate(xList):
         x = float(xList[idx])
         if math.isnan(x):
             prev_pt = None
         else:
             y = float(yList[idx])
             if y > self.maxY:
                 self.maxY = y
             if y < self.minY:
                 self.minY = y
             if x > self.maxX:
                 self.maxX = x
             if x < self.minX:
                 self.minX = x
             newPt = ou.getPointObject(x, y, 0, prevPt=prev_pt)
             if prev_pt != None:
                 prev_pt.setNext(newPt)
             self.points.append(newPt)
             self.x.append(x)
             self.y.append(y)
             prev_pt = newPt
     midX = (self.maxX + self.minX) / 2
     midY = (self.maxY + self.minY) / 2
     halfSide = max(self.maxX - midX, self.maxY - midY) * 1.05
     return Bounds.Bounds(midX - halfSide, midY - halfSide, -1,
                          midX + halfSide, midY + halfSide, 1)
Пример #7
0
def getKdSubsampling(bounds,points):
    pointObjs = []
    for point in points:
        pointObjs.append( ou.getPointObjects(point[0],point[1]))
    myOctree = oct.Octree(5)
    myOctree.createOctree(pointObjs, True)
    return myOctree.getKdSubsamplePoints()
Пример #8
0
 def manageBinMerge(self, editedBin):
     editedParent = editedBin.parent
     if (editedParent.trajCt < self.trajThreshold or not editedParent.checkAncestorsTraj(self.trajThreshold)) and editedBin.depth>=self.trajThreshold:
         siblingPts = ou.getChildPtCount(editedParent)
         if self.splitPtThresh>(siblingPts/len(self.points)):
             editedParent.mergeChildren()
             self.manageBinMerge(editedParent)
Пример #9
0
 def test(self, octDyn, pts, newPts):
     pts[len(newPts):].extend(newPts)
     staticPts = ou.copyPointObjects(pts)
     octStatic = Octree.Octree(8, octDyn.bounds, 35, 100)
     octStatic.createOctree(staticPts, True)
     isEqual = octDyn.compare(octStatic)
     print(isEqual)
     isEqual = True
     return pts, isEqual
Пример #10
0
 def divide(self):
     for i in range(8):
         childBound = self.bounds.getChild(i)
         pts = []
         newChild = OctreeBin(self, pts, childBound, self.depth + 1, 0)
         self.children.append(newChild)
     if not self.arePointsSorted:
         self.sortPoints()
     prevPointId = -10
     firstLvl = ou.getFirstLevelBin(self)
     for ptIdx, point in enumerate(self.points):
         if point.pointId - prevPointId == 1:
             bin2, newBinPath = ou.getRelaxedBinAndBinPath(
                 firstLvl, point, self.points[ptIdx - 1])
             point.addToBinPath([newBinPath[-1]])
             bin2.addPoints([point])
             bin1 = ou.getBin(firstLvl, self.points[ptIdx - 1].binPath)
             notContainedinTraj = True
             #if the point contains a traj, check to see if other point is in traj.
             #if so, then don't create a new one, just increment point's bin's ct
             if point.trajectories:
                 for traj in point.trajectories:
                     if traj.contains(self.points[ptIdx - 1]):
                         notContainedinTraj = False
                         bin2.incrementTrajectoryCount()
                         for extraPt in traj.tempPoints:
                             exBin = ou.incrementExtraPointBins(
                                 extraPt, firstLvl,
                                 [point, self.points[ptIdx - 1]])
             if bin1 != bin2 and notContainedinTraj:
                 ou.addTrajectory(self.points[ptIdx - 1], point, bin1, bin2)
         #the point has to have a neighbor in another binset
         else:
             binIdx = self.findIndex(point)
             self.children[binIdx].addPoints([point])
             point.addToBinPath([binIdx])
             for traj in point.trajectories:
                 for extraPt in traj.tempPoints:
                     if extraPt.binPath[:self.depth -
                                        1] == point.binPath[:self.depth -
                                                            1]:
                         exBin = ou.incrementExtraPointBins(
                             extraPt, firstLvl,
                             [point, self.points[ptIdx - 1]])
             myBin = ou.getBin(firstLvl, point.binPath)
             myBin.incrementTrajectoryCount()
         prevPointId = point.pointId
     self.points = []
Пример #11
0
 def initActivityRecognition(self, sub_idx):
     #testortrain = ['test','train']
     testortrain = ['test']
     #iterations = ['1','2','3','4']
     iterations = ['1']
     self.runtime = 0
     self.tot_run = 0
     for tot in testortrain:
         for iteration in iterations:
             saveLocation = '.\\Data\\Subject' + sub_idx + '\\Subsamples_' + tot + '\\It_' + iteration + '\\'
             self.windows = ss.getWindowedPoints(sub_idx, iteration, tot)
             i = 0
             for window in self.windows:
                 self.wave = window
                 self.waveStart = 0
                 self.waveEnd = tde.getWaveEnd(self.waveStart)
                 self.x = [float(i[0]) for i in self.wave]
                 self.y = [float(i[1]) for i in self.wave]
                 self.z = [float(i[2]) for i in self.wave]
                 self.x = np.array(self.x)
                 self.y = np.array(self.y)
                 self.z = np.array(self.z)
                 self.points = ou.getPointObjects(self.x, self.y, self.z)
                 binThreshold = math.ceil(1000 / len(self.points))
                 binThreshold = min(3, binThreshold)
                 bounds = self.getBoundsThree(self.points)
                 self.oct = Octree.Octree(4, bounds, binThreshold, 10)
                 start = time.perf_counter()
                 self.oct.createOctree(self.points, True)
                 self.runtime += time.perf_counter() - start
                 self.tot_run += 1
                 # sample = self.oct.getKdSubsamplePoints()
                 # while len(sample) < 3 and self.oct.trajThreshold > 1:
                 # self.oct.decreaseThreshold()
                 # sample = self.oct.getKdSubsamplePoints()
                 # if not os.path.exists(saveLocation):
                 # os.makedirs(saveLocation)
                 # with open(saveLocation + 'joint'+str((i%6)+1)+'window'+str((i//6)+1)+'.csv','w',newline='') as outFile:
                 # writer = csv.writer(outFile)
                 # for point in sample:
                 # writer.writerow(point)
                 # i+=1
                 # plt.cla()
                 del self.oct
Пример #12
0
 def __init__(self,fig,ax):
     self.fig = fig
     self.ax = ax
     self.wave = np.array(Startup())
     self.waveStart = 0
     self.waveEnd = tde.getWaveEnd(self.waveStart)
     self.waveLength = self.wave.size
     [self.x,self.y, self.tauX] = tde.getPhaseData(self.wave, self.waveStart, self.waveEnd)
     self.oldX = []
     self.oldY = []
     self.newX = []
     self.newY = []
     self.points = ou.getPointObjects(self.x,self.y)
     self.oct = Octree.Octree(5)
     start = time.perf_counter()
     self.oct.createOctree(self.points,True)
     self.drawScatter()
     self.drawOctree()
     self.fig.canvas.draw()
     print(time.perf_counter()-start)
Пример #13
0
 def initMisc(self):
     self.wave = ss.getPointsFromFile()
     self.waveStart = 0
     self.waveEnd = tde.getWaveEnd(self.waveStart)
     self.x = [float(i[0]) for i in self.wave]
     self.y = [float(i[1]) for i in self.wave]
     self.z = [float(i[2]) for i in self.wave]
     self.x = np.array(self.x)
     self.y = np.array(self.y)
     self.z = np.array(self.z)
     self.points = ou.getPointObjects(self.x, self.y, self.z)
     binThreshold = 2
     bounds = self.getBoundsThree(self.points)
     self.oct = Octree.Octree(4, bounds, binThreshold, 10)
     start = time.perf_counter()
     self.oct.createOctree(self.points, True)
     self.visualizePaths()
     self.drawOctree()
     plt.show()
     sample = self.oct.getKdSubsamplePoints()
     print(time.perf_counter() - start)
Пример #14
0
 def divide(self):
     for i in range(8):
         childBound = self.bounds.getChild(i)
         pts=[]
         newChild = OctreeBin(self,pts,childBound, self.depth+1,0)
         self.children.append(newChild)
     prevPoint=None
     for ptIdx,point in enumerate(self.points):
         if point.prev==prevPoint and prevPoint!=None:
             bin2 = ou.getRelaxedBin(point,prevPoint)
             point.lowestBin = bin2
             bin2.addPoints([point])
             bin1 = prevPoint.lowestBin
             notContainedinTraj = True
             #if the point contains a traj, check to see if other point is in traj.
             #if so, then don't create a new one, just increment point's bin's ct
             if point.trajectories:
                 for traj in point.trajectories:
                     if traj.contains(prevPoint):
                         notContainedinTraj=False
                         bin2.incrementTrajectoryCount()
                         for extraPt in traj.tempPoints:
                             ou.incrementExtraPointBins(extraPt)
             if bin1 != bin2 and notContainedinTraj:
                 ou.introduceTrajectory(prevPoint,point,bin1,bin2)
         #the point has to have a neighbor in another binset
         else:
             binIdx = self.findIndex(point)
             receivingBin = self.children[binIdx]
             receivingBin.addPoints([point])
             point.updateBin(receivingBin)
             for traj in point.trajectories:
                 for extraPt in traj.tempPoints:
                     if extraPt.lowestBin == point.lowestBin.parent:
                         ou.incrementExtraPointBins(extraPt)
             myBin = point.lowestBin
             myBin.incrementTrajectoryCount()
         prevPoint=point
     self.points=[]
Пример #15
0
 def preprocessData(self, bounds, binDepth):
     min_dist = max((bounds.maxX - bounds.minX),
                    (bounds.maxY - bounds.minY)) / (2**binDepth)
     new_points = []
     for idx, pt in enumerate(self.points):
         prevPt = pt.prev
         if prevPt != None:
             max_coord_dist = max(abs(pt.X - prevPt.X),
                                  abs(pt.Y - prevPt.Y))
             if max_coord_dist > min_dist:
                 num_points = math.ceil(max_coord_dist / min_dist)
                 dist_added_x = (pt.X - prevPt.X) / num_points
                 dist_added_y = (pt.Y - prevPt.Y) / num_points
                 dist_added_z = (pt.Z - prevPt.Z) / num_points
                 add_pts = []
                 for sub_idx in range(num_points):
                     xval = prevPt.X + dist_added_x * (sub_idx + 1)
                     yval = prevPt.Y + dist_added_y * (sub_idx + 1)
                     zval = prevPt.Z + dist_added_z * (sub_idx + 1)
                     add_pts.append((xval, yval, zval, idx))
                 new_points.append(add_pts)
     for point_list in new_points:
         first_pt = point_list[0]
         append_prev = self.points[first_pt[3]]
         append_last = append_prev.nxt
         for point in point_list:
             new_pt = ou.getPointObject(point[0],
                                        point[1],
                                        point[2],
                                        prevPt=append_prev)
             append_prev.setNext(new_pt)
             append_prev = new_pt
             self.points.append(new_pt)
         append_prev.setNext(append_last)
         if append_last:
             append_last.setPrev(append_prev)
Пример #16
0
    overlap = 500
    newPts = dim[(i*overlap)+windowSize:((i+1)*overlap)+windowSize]
    return newPts

def getWindow(dim, i):
    windowSize = 1000
    overlap = 500
    newPts = dim[(i*overlap)+windowSize:((i+1)*overlap)+windowSize]
    return newPts


if __name__ == '__main__':
    windowSize = 1000
    overlap = 500
    dataStream = getPointsFromFile()
    points = ou.getPointObsFromSingleSrc(dataStream)
    myOctree = oct.Octree(5)
    baseSet = points[0:windowSize]
    myOctree.createOctree(baseSet,True)
    iterations = floor((len(points)-len(baseSet))/(windowSize-overlap))
    sampling = []
    for i in range(iterations):
        newPts = points[(i*overlap)+windowSize:((i+1)*overlap)+windowSize]
        myOctree.appendPoints(newPts)
        sample = myOctree.getKdSubsamplePoints()
        sampling.append(sample)
    with open('sampling.csv', 'w', newline='') as outFile:
        writer = csv.writer(outFile)
        i=0
        for line in sampling:
            i=i+1