Пример #1
0
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
Пример #2
0
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
Пример #3
0
def getData(fileName, vecSize):
    f  = open(fileName, 'r')
    all = []
    map = {}
    for line in f:
        splited = line.split()
        if len(splited) == 0:
            continue
        jointName = splited[0]
        if jointName in joints:
            if not jointName in map:#initialization 
                map[jointName] = []
                for _ in splited[1:]:
                    map[jointName].append([])
            for i,l in enumerate(map[jointName]):
                l.append(float(splited[1+i]))
                #map[jointName][i].append(a)  
                #except:
                #   pass
    ret = []
    for joint,vecs in map.items():
        for vec in vecs:
            _, uniformlySampled = inter.getUniformSampled(range(len(vec)), vec, vecSize)
            """
            maxV = np.max(uniformlySampled)
            minV = np.min(uniformlySampled)
            amp = maxV -minV
            if amp==0:
                print 'zeroi input'
            else:
                uniformlySampled = [2*v/amp -1 for v in uniformlySampled]
            """
            ret = ret + uniformlySampled.tolist()
    """      
    ret = []
    for i in xrange(0, len(all), vecSize):
        ret.append(all[i:i+vecSize])
    """
    return ret
Пример #4
0
for subject in subjects:
    for stride in xrange(1,13):
        file = '../AMCs/subjects/' + str(subject) + '/' + str(stride) + '.amc'
        features = []
        for joint in joints:
            try:
                input = getAMCperiod(joint, file)
            except:
                continue
            input = alignByMax(input)
            sub =  fig.add_subplot(frameSize*110 + subjects.index(subject))
            sub.plot(range(len(input)), input)
            sub_uniform = fig_uniform.add_subplot(frameSize*110 + subjects.index(subject))
            
            specialFeatures = [op(input) for op in specialOperators]
            new_time, uniform_input = inter.getUniformSampled(xrange(len(input)), input, lenVec)
            features += specialFeatures 
            features += uniform_input.tolist()
            sub_uniform.plot( xrange(len(uniform_input)), uniform_input)
            data.append(uniform_input)
            tags.append(subject)
            plt.xlabel('Time (in frames)')
            plt.ylabel(joint + ' angle')
            plt.title('subject: ' + str(subject))
        if len(features)==0:
            continue
        for f in features:
            out.write(str(f)+',')
        out.write(str(subject)+'\n')
"""
cl = KNeighborsClassifier()
plt.ylabel(joint + ' angle')
fig_uniform = plt.figure()
data = []
tags = []
for subject in subjects:
    for stride in xrange(1,13):
        file = 'AMCs/subjects/' + str(subject) + '/' + str(stride) + '.amc'
        try:
            input = getAMCperiod(joint, file)
        except:
            continue
        input = alignByMax(input)
        sub =  fig.add_subplot(frameSize*110 + subjects.index(subject))
        sub.plot(range(len(input)), input)
        sub_uniform = fig_uniform.add_subplot(frameSize*110 + subjects.index(subject))
        new_time, uniform_input = inter.getUniformSampled(xrange(len(input)), input, numOfFeatures)
        sub_uniform.plot( xrange(numOfFeatures), uniform_input)
        data.append(uniform_input)
        tags.append(subject)
        plt.xlabel('Time (in frames)')
        plt.ylabel(joint + ' angle')
        plt.title('subject: ' + str(subject))

cl = KNeighborsClassifier()
cl.n_neighbors = 5
cl.weights = 'distance' 
testSize = 35
score = crossValidate(cl, data, tags, testSize)


outFile = 'out.txt'