def estimateSample(self, interpolationSample, time): estimatedSample = PredictionSample() estimatedSample.sample.time = time estimatedSample.sample.position = self.calculatePosition( interpolationSample, time) estimatedSample.velocity = deepcopy(interpolationSample.velocity) return estimatedSample
def calcExtrapolationSample(self, currentSample, targetSample): deltaPosition = targetSample.position - currentSample.position deltaTime = targetSample.time - currentSample.time invDeltaTimeVector = Vector(1 / float(deltaTime), 1 / float(deltaTime), 1 / float(deltaTime)) velocity = deltaPosition * invDeltaTimeVector extrapolationSample = PredictionSample() extrapolationSample.sample = deepcopy(currentSample) extrapolationSample.velocity = velocity return extrapolationSample
def calcExtrapolationSample(self, snapSample, targetSample): deltaPosition = targetSample.position - snapSample.position deltaTime = targetSample.time - snapSample.time invDeltaTimeVector = Vector( 1 / float(deltaTime), \ 1 / float(deltaTime), \ 1 / float(deltaTime)) velocity = deltaPosition * invDeltaTimeVector extrapolationSample = PredictionSample() extrapolationSample.sample = deepcopy(snapSample) extrapolationSample.velocity = velocity return extrapolationSample
def findInterpolationSample(self, currentSample, targetSample): deltaPosition = targetSample.position - \ currentSample.position deltaTime = targetSample.time - \ currentSample.time invDeltaTimeVector = Vector( 1 / float(deltaTime), \ 1 / float(deltaTime), \ 1 / float(deltaTime)) velocity = deltaPosition * invDeltaTimeVector interpolationSample = PredictionSample() interpolationSample.sample = deepcopy(currentSample) interpolationSample.velocity = velocity return interpolationSample
def findInterpolationSample(self, currentSample, targetSample): deltaPosition = targetSample.sample.position - \ currentSample.sample.position deltaTime = targetSample.sample.time - \ currentSample.sample.time invDeltaTimeVector = Vector( 1 / float(deltaTime), \ 1 / float(deltaTime), \ 1 / float(deltaTime)) velocity = deltaPosition * invDeltaTimeVector interpolationSample = PredictionSample() interpolationSample.sample = deepcopy(currentSample.sample) interpolationSample.velocity = velocity return interpolationSample
def executeAlgorithm(self): self.predictedData = [] for index, sample in enumerate(self.inputData): if sample.time < self.predictionInterval: # Set initial values predictionSample = PredictionSample() predictionSample.sample = copy(sample) predictionSample.velocity = Vector() self.predictedData.append(predictionSample) else: shift = index - self.predictionInterval / self.samplingInterval # Calculate velocity deltaPosition = self.inputData[index].position - \ self.inputData[shift].position deltaTime = self.inputData[index].time - \ self.inputData[shift].time invDeltaTimeVector = Vector( 1 / float(deltaTime), \ 1 / float(deltaTime), \ 1 / float(deltaTime)) velocity = deltaPosition * invDeltaTimeVector # Populate data structures predictionSample = PredictionSample() predictionSample.sample = copy(sample) predictionSample.velocity = velocity self.predictedData.append(predictionSample)
def executeAlgorithm(self): self.reconstructedSignal = [] self.reconstructedSignal.append(deepcopy(self.rawSignal[0].sample)) extrapolationSample = self.rawSignal[0] futureExtrapolationSample = None nextTimeToRecord = self.reconstructedSignal[0].time + 1 tempRawSignal = self.rawSignal[1:] for index, predictionSample in enumerate(tempRawSignal): while predictionSample.sample.time > nextTimeToRecord: if futureExtrapolationSample != None and \ futureExtrapolationSample.sample.time == nextTimeToRecord: extrapolationSample = futureExtrapolationSample futureExtrapolationSample = None self.reconstructedSignal.append( deepcopy(extrapolationSample.sample)) else: estimatedSample = self.estSample(extrapolationSample, nextTimeToRecord) self.reconstructedSignal.append(deepcopy(estimatedSample)) nextTimeToRecord += 1 lastEstimatedSample = self.reconstructedSignal[-1] targetSample = self.calcTargetSample(predictionSample) snapSample = self.calcSnapSample(predictionSample.sample, lastEstimatedSample) extrapolationSample = self.calcExtrapolationSample( snapSample, targetSample) futureExtrapolationSample = PredictionSample( targetSample, predictionSample.velocity) self.reconstructedSignal.append(deepcopy(snapSample)) nextTimeToRecord += 1
def executeAlgorithm(self): self.reconstructedSignal = [] nextTimeToRecord = 0 timeDiff = self.rawSignal[0].sample.time % self.samplingInterval if timeDiff == 0: self.reconstructedSignal.append( deepcopy(self.rawSignal[0].sample) ) nextTimeToRecord = self.rawSignal[0].sample.time + \ self.samplingInterval else: change = self.samplingInterval - timeDiff newSample = Sample() newSample.time = self.rawSignal[0].sample.time + change newSample.position = deepcopy(self.rawSignal[0].sample.position) self.reconstructedSignal.append(newSample) nextTimeToRecord = newSample.time + self.samplingInterval interpolationSample = PredictionSample() interpolationSample.sample = self.reconstructedSignal[0] interpolationSample.velocity = self.rawSignal[0].velocity for index, predictionSample in enumerate(self.rawSignal): if predictionSample.sample.time == nextTimeToRecord: estimatedSample = self.calculateEstSample(interpolationSample, \ nextTimeToRecord) self.reconstructedSignal.append(estimatedSample) targetSample = self.findTarget(predictionSample) interpolationSample = self.findInterpolationSample(estimatedSample, \ targetSample) nextTimeToRecord = nextTimeToRecord + self.samplingInterval elif predictionSample.sample.time > nextTimeToRecord: while predictionSample.sample.time > nextTimeToRecord: estimatedSample = self.calculateEstSample(interpolationSample, \ nextTimeToRecord) self.reconstructedSignal.append(estimatedSample) nextTimeToRecord = nextTimeToRecord + self.samplingInterval if predictionSample.sample.time == nextTimeToRecord: estimatedSample = self.calculateEstSample(interpolationSample, \ nextTimeToRecord) self.reconstructedSignal.append(estimatedSample) targetSample = self.findTarget(predictionSample) interpolationSample = self.findInterpolationSample(estimatedSample, \ targetSample) nextTimeToRecord = nextTimeToRecord + self.samplingInterval else: targetSample = self.findTarget(predictionSample) interpolationSample = self.findInterpolationSample(self.reconstructedSignal[-1], \ targetSample)
def findSnapSample(self, currentSample, estimatedSample, targetSample): deltaPosition = targetSample.sample.position - \ currentSample.sample.position deltaPosition.x *= self.snapLimit deltaPosition.y *= self.snapLimit deltaPosition.z *= self.snapLimit snapPosition = currentSample.sample.position + deltaPosition deltaPosition = targetSample.sample.position - snapPosition deltaTime = targetSample.sample.time - \ currentSample.sample.time invDeltaTimeVector = Vector( 1 / float(deltaTime), \ 1 / float(deltaTime), \ 1 / float(deltaTime)) velocity = deltaPosition * invDeltaTimeVector snapSample = PredictionSample() snapSample.sample = Sample(currentSample.sample.time, snapPosition) snapSample.velocity = velocity return snapSample
def executeAlgorithm(self): self.predictedData = [] for index, sample in enumerate(self.inputData): if sample.time < self.predictionInterval: # Set initial values predictionSample = PredictionSample() predictionSample.sample = copy(sample) predictionSample.velocity = Vector() self.predictedData.append( predictionSample ) else: shift = index - self.predictionInterval / self.samplingInterval # Calculate velocity deltaPosition = self.inputData[index].position - \ self.inputData[shift].position deltaTime = self.inputData[index].time - \ self.inputData[shift].time invDeltaTimeVector = Vector( 1 / float(deltaTime), \ 1 / float(deltaTime), \ 1 / float(deltaTime)) velocity = deltaPosition * invDeltaTimeVector # Populate data structures predictionSample = PredictionSample() predictionSample.sample = copy(sample) predictionSample.velocity = velocity self.predictedData.append( predictionSample )
def executeAlgorithm(self): self.reconstructedSignal = [] self.reconstructedSignal.append( self.findFirstSample() ) reconstructionTime = self.reconstructedSignal[0].time + self.samplingInterval interpolationSample = PredictionSample(self.reconstructedSignal[0], self.rawSignal[0].velocity) targetSample = None for index, predictionSample in enumerate(self.rawSignal[1:]): currentTime = predictionSample.sample.time if currentTime < reconstructionTime: estimatedSample = self.estimateSample(interpolationSample, currentTime) targetSample = self.findTarget(predictionSample) interpolationSample = self.findInterpolationSample(estimatedSample, targetSample) elif currentTime == reconstructionTime: previousEstimatedSample = self.estimateSample(interpolationSample, reconstructionTime - self.samplingInterval) targetSample = self.findTarget(predictionSample) interpolationSample = self.findInterpolationSample(previousEstimatedSample, targetSample) estimatedSample = self.estimateSample(interpolationSample, reconstructionTime) self.reconstructedSignal.append(deepcopy(estimatedSample.sample)) reconstructionTime += self.samplingInterval elif currentTime > reconstructionTime: while currentTime > reconstructionTime: if targetSample != None and reconstructionTime >= targetSample.sample.time: interpolationSample = targetSample targetSample = None estimatedSample = self.estimateSample(interpolationSample, reconstructionTime) self.reconstructedSignal.append(deepcopy(estimatedSample.sample)) reconstructionTime += self.samplingInterval if currentTime < reconstructionTime: estimatedSample = self.estimateSample(interpolationSample, currentTime) targetSample = self.findTarget(predictionSample) interpolationSample = self.findInterpolationSample(estimatedSample, targetSample) elif currentTime == reconstructionTime: previousEstimatedSample = self.estimateSample(interpolationSample, reconstructionTime - self.samplingInterval) targetSample = self.findTarget(predictionSample) interpolationSample = self.findInterpolationSample(previousEstimatedSample, targetSample) estimatedSample = self.estimateSample(interpolationSample, reconstructionTime) self.reconstructedSignal.append(deepcopy(estimatedSample.sample)) reconstructionTime += self.samplingInterval
def estimateSample(self, interpolationSample, time): estimatedSample = PredictionSample() estimatedSample.sample.time = time estimatedSample.sample.position = self.calculatePosition(interpolationSample, time) estimatedSample.velocity = deepcopy(interpolationSample.velocity) return estimatedSample