Ejemplo n.º 1
0
    def transformSub(self, cumSums, cumSums_2, wCumSums, pos):

        transformedSub = np.zeros(self.wordSize)

        #window mean and std
        if not (self.meanNorm or self.stdNorm):
            meanSub = 0
            sigmaSub = 1
        elif self.stdNorm:
            meanSub = (cumSums[pos + self.winLen] - cumSums[pos]) / self.winLen
            meanSub_2 = (cumSums_2[pos + self.winLen] -
                         cumSums_2[pos]) / self.winLen
            varSub = meanSub_2 - meanSub * meanSub
            sigmaSub = np.sqrt(varSub) if varSub > 0 else 1
            if not self.meanNorm:
                meanSub = 0
        else:
            meanSub = (cumSums[pos + self.winLen] - cumSums[pos]) / self.winLen
            sigmaSub = 1

        #timestamp parameters
        startPts = self.segStarts[:len(self.segStarts) - 1] + pos
        finishPts = self.segStarts[1:] + pos
        sum_X = gu.getAriSeqSum(startPts, finishPts - 1)
        mean_X = sum_X / self.segSizes
        mean_X2 = gu.getSumOfSquares(startPts, finishPts - 1) / self.segSizes

        #segment parameters
        #             sumSegs = cumSums[self.segStarts[1 :]] - cumSums[self.segStarts[: len(self.segStarts) - 1]]
        sumSegs = cumSums[finishPts] - cumSums[startPts]
        meanSegs = (sumSegs / self.segSizes - meanSub) / sigmaSub
        #             wCumSegs = wCumSums[self.segStarts[1 :]] - wCumSums[self.segStarts[: len(self.segStarts) - 1]]
        wCumSegs = wCumSums[finishPts] - wCumSums[startPts]
        wMeanSegs = (wCumSegs - meanSub * sum_X) / self.segSizes / sigmaSub

        #the coefficients
        slopes = (wMeanSegs - mean_X * meanSegs) / (mean_X2 - mean_X * mean_X)
        intercepts = meanSegs - slopes * mean_X
        if self.posNorm:
            intercepts += startPts * slopes  #shift to the same starting timestamp of 0
        transformedSub[0:self.wordSize - 1:2] = slopes
        transformedSub[1:self.wordSize:2] = intercepts
        return transformedSub
Ejemplo n.º 2
0
def getAllSumX(tsLen, segSize):

    first = gu.getAriSeqSum(0, segSize - 1, 1)
    return np.arange(first, first + segSize * (tsLen - segSize) + 1, segSize)