def evalParams(m1=MEAN_COEFF, m2=STD_COEFF,  epsilon=EPSILON_FACTOR,gap=GAP_FACTOR, overlap=OVERLAP_FACTOR):       
    sum = 0
    for stitch in xrange(stitchesNum):
        data = []
        tags = []
        for subject in subjects:
            for index in xrange(8):
                try:
                    input = getAMCInput(joint, subject, index)
                except:
                    continue
                parts = st.createParts(input, partsAmount)
                stitched = st.stitch(parts, m1, m2, epsilon,gap, overlap)
                #plt.figure()
                #plt.plot(stitched)
                periods = pr.breakToPeriods(stitched)
                periods = ut.alignByMaxMany(periods)
                periods = inter.getUniformSampledVecs(periods, 100)
                data = data + periods
                tags = tags + [subject]*len(periods)
                #st.plotParts(periods)
        
        cl = KNeighborsClassifier()
        cl.n_neighbors = 5
        cl.weights = 'distance' 
        testSize = 1
        score = crossValidate(cl, data, tags, testSize, testAmount)
        #print str(m2)+' '+ str(score)
        sum+=score
    score = float(sum)/stitchesNum
    scores[m1, m2] = score
    return score
def stitchByDensity(time, angles, plot=False, startGrade=0.93, \
        minimalOverlap=10, maximalOverlap=200, lengthFactor=0, density=10):
    fracs = clusterByTime(time, angles, plot)
    fracs = filterOutliers(fracs, plot)   
    cleanedParts, originalParts = cleanFracs(fracs, plot)
    stitchedParts, partDescriptors = loop.stitch(cleanedParts, startGrade, minimalOverlap, \
                                         maximalOverlap, lengthFactor, density) 
    return cleanedParts, stitchedParts, partDescriptors
def stitchKinect(time, angles, weights=None, plot=False, startGrade=0.93, \
        minimalOverlap=10, maximalOverlap=200, lengthFactor=0, density=10):
    if(plot):
        plt.figure()
        plt.scatter(time, angles, c='yellow', label='Low confedence level')
    if(weights is not None):
        time, angles = removeLowConfedence(time, angles, weights, plot)
    fracs = clusterByTime(time, angles, plot)
    fracs = filterOutliers(fracs, plot)   
    cleanedParts, originalParts = cleanFracs(fracs, plot)
    parts, partDescriptors = loop.stitch(cleanedParts, startGrade, minimalOverlap, \
                                         maximalOverlap, lengthFactor, density)  
    
    if(plot and len(parts) != 0):
        plt.figure()
        plt.plot(parts[-1]) 
        loop.plotDesBypart(originalParts, cleanedParts, partDescriptors)
        loop.plotReconstruction(cleanedParts, partDescriptors[-1])
        plt.show()
        #an.animate( parts[-1])
    return parts[-1], partDescriptors[-1], fracs

    
Example #4
0
#list = ut.alignByMax(list)
noiseStdFactor = 0.04
amplitude = np.max(list) - np.min(list)
var = (amplitude*noiseStdFactor)**2
print var
partsAmount = 16
noisy_parts = createParts(list, True, partsAmount, var)
parts = ma.partsmovingAverage(noisy_parts)

frameSize = math.ceil(np.sqrt(len(parts)))
fig = plt.figure()
for i,part in enumerate(parts):
    curr = fig.add_subplot(frameSize,  frameSize, i+1)
    curr.plot(part)
        
merged, mergedDes = loop.stitch(parts)
print(len(merged))
bestFeatures = merged[-1]
des = mergedDes[-1]
outOff, listOff = ut.alignByBig(bestFeatures, list)
plt.figure()
plt.plot(xrange(listOff, listOff+len(list)), list, color='b')
plt.plot(xrange(outOff, outOff+len(bestFeatures)), bestFeatures, color='r')
sortingIndices = sorted(range(len(des)), key=lambda k: des[k][1])
frameSize = math.ceil(np.sqrt(len(sortingIndices)))

fig = plt.figure()
for step in xrange(1, len(sortingIndices)+1):
    curr = fig.add_subplot(frameSize, frameSize, step)
    for addedIndex in xrange(step):
        partNum = sortingIndices[addedIndex]
def evalParams(partsAmount):
    noiseStdFactor = 0.02       
    stances = {}
    swings = {}
    for subject in subjects:
        for index in xrange(8):
            try:
                input = getAMCInput(joint, subject, index)
            except:
                continue
            amplitude = np.max(input) - np.min(input)
            var = (amplitude*noiseStdFactor)**2
            for stitch in xrange(stitchesNum):
                try:
                    noisy_parts = st.createParts(input, False, partsAmount, var)
                except:
                    continue
                parts = ma.partsmovingAverage(noisy_parts)
                stitched_parts, des = loop.stitch(parts)
                if(len(stitched_parts) == len(parts)):
                    continue
                stitched = stitched_parts[-1]
                input = stitched
                tmpSwings, tmpStances = getSwingsAndStances(input)
                key = (stitch, subject) 
                for stanceLen, swingLen in zip(tmpStances, tmpSwings):
                    if(stanceLen > 55):
                        stances[key] = stances.get(key, []) + [stanceLen]
                    if(swingLen > 35):
                        swings[key] = swings.get(key, []) + [swingLen]
    stancesCV = []
    swingsCV = []
    strideCV = []
    strideLengths = {}
    stancesLengths = {}
    swingsLengths = {}
    for stitch in xrange(stitchesNum):
        for subject in subjects:
            key = (stitch, subject)
            stance = None
            if not(key in stances and key in swings):
                continue
            stance = stances[key]
            cv = getCV(stance)
            if not math.isnan(cv) and 0 < cv :
                stancesCV.append(cv)
            stancesLengths[subject] = stancesLengths.get(subject, []) + stance
            
            swing = swings[key]
            cv = getCV(swing)
            if not math.isnan(cv) and 0 < cv :
                swingsCV.append(cv)
            swingsLengths[subject] = swingsLengths.get(subject, []) + swing
            
            strideLength = [x+y for x,y in zip(stance, swing)]
            cv = getCV(strideLength)
            if not math.isnan(cv) and 0 < cv :
                strideCV.append(cv)
            strideLengths[subject] = strideLengths.get(subject, []) + strideLength
    
    stancesLengths = [stancesLengths[subject] for subject in stancesLengths]
    swingsLengths = [swingsLengths[subject] for subject in swingsLengths]
    strideLengths = [strideLengths[subject] for subject in strideLengths]
    strideReference = [115.61538461538461, 113.66666666666667, 116.11111111111111, 126.375]
    strideMeans = [np.mean(seq) for seq in strideLengths]
    finalGrade = np.mean([np.abs(y-x)/x for x,y in zip(strideReference, strideMeans)])   
    stanceCVmean = np.mean(stancesCV)
    swingCVmean = np.mean(swingsCV)
    strideCVsMean = np.mean(strideCV)
    titles = ['Subject: ' + str(x) for x in subjects]
    #plotParts(stancesLengths, 'Stance number', 'Stance time(in frames)', titles)
    #plotParts(swingsLengths, 'Swing number', 'Swing time(in frames)', titles)
    #plotParts(strideLengths, 'Stride number', 'Stride time(in frames)', titles)
    print 'partsAmount', partsAmount
    print stanceCVmean, [np.mean(seq) for seq in stancesLengths]
    print  swingCVmean, [np.mean(seq) for seq in swingsLengths]
    print strideCVsMean, strideMeans
    return finalGrade
import numpy as np
import numpy.random as rnd
import matplotlib.pyplot as plt 
from utils.vicon.amcParser import getAMCperiod
from utils.stitching.stitching import MAXIMA_ORDER, CLUSTER_COEFF, plotParts, createParts
import utils.stitching.stitching as loop
import utils.periodAnalysisUtils as ut
from operator import add, sub
import utils.LPF as LPF 

file = 'AMCs/598.amc'
joint = 'root'
list = getAMCperiod(joint, file)
list = list[:538]
#stride = list[112:251] 
#list = ut.alignByMax(stride)
#list = ut.alignByMax(list)
amplitude = np.max(list) - np.min(list)
parts = createParts(list, True, 9, amplitude/10)
merged = loop.stitch(parts)
merged.sort()
print(len(merged))
#out = ut.alignByMax(merged[-1])
out = LPF.clean(merged[-1]) 
outOff, listOff = ut.alignByBig(out, list)
plt.figure()
plt.plot(xrange(listOff, listOff+len(list)), list)
plt.plot(xrange(outOff, outOff+len(out)), out)
plt.show()
Example #7
0
import utils.stitching.stitching as loop

fileName = 'inputs/asc_gyro_l.skl'#alon_multi_right.skl
joint = 'AnkleRight_X'
time, angles = ae.getAngleVec(fileName, joint, True)
startGrade=0.93
minimalOverlap=10
maximalOverlap=200
lengthFactor=0
density = 2
parts, stitchedParts, partDescriptors = ex.stitchByDensity(time, angles, False, 
   startGrade, minimalOverlap, maximalOverlap, lengthFactor, density)
for des in partDescriptors:
    loop.plotDes(parts, des)
minimalOverlap=5
maximalOverlap=15
density = 5
stitchedParts, partDescriptors = loop.stitch(stitchedParts, startGrade, minimalOverlap, \
                                         maximalOverlap, lengthFactor, density)
for des in partDescriptors:
    loop.plotDes(parts, des)
"""
fracs = ex.clusterByTime(time, angles, False)
fracs = ex.filterOutliers(fracs, False)   
cleanedParts, originalParts = ex.cleanFracs(fracs, False)
parts, partDescriptors = loop.stitch(cleanedParts, startGrade, minimalOverlap, \
    maximalOverlap, lengthFactor, density)
"""
plt.figure()
plt.plot(stitchedParts[-1])
plt.show()