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
import utils.stitching.stitching as loop import utils.utils as ut import utils.MovingAverage as ma file = 'AMCs/598.amc' joint = 'rtibia' list = getAMCperiod(joint, file) stride = list[112:251] list = ut.alignByMax(stride) #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')
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()