Exemplo n.º 1
0
def generateTwoPositionTrainingData():
    '''
    This function creates training data using the first
    two participants' data and has joint positions as features
    for the samples.
    '''

    trainingData = TrainingData("Testing Data")
    index = 0

    for i in xrange(len(labels)):
        #Open the file
        fIn = open(sub1[i], 'r')
        f2In = open(sub2[i], 'r')

        #For each line of the files, create a feature vector
        # of the raw joint positions. Add that to the trainingData.
        for line in fIn:
            features = returnLine(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        fIn.close()

        for line in f2In:
            features = returnLine(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        f2In.close()

        index += 1

    return trainingData
Exemplo n.º 2
0
def generateTwoAngleTrainingData():
    '''
    This function creates training data using the first
    two participants' data and has joint angles as features
    for the samples.
    '''

    trainingData = TrainingData("Testing Data")
    index = 0

    for i in xrange(len(labels)):
        #Open the file
        fIn = open(sub1[i], 'r')
        f2In = open(sub2[i], 'r')

        #For each line of the files calculate the 
        # angles inbetween joints and use the resulting 
        # array as the feature vector. Add that to the trainingData.
        for line in fIn:
            features = generateAngles(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        fIn.close()

        for line in f2In:
            features = generateAngles(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        f2In.close()

        index += 1

    return trainingData
Exemplo n.º 3
0
def generateOneTrainPositionData():
    '''
    This creates a data set to be used to train a classifier.
    The data is from participant 1 and uses the joint positions
    as features.
    '''
    trainingData = TrainingData("Position Data")
    index = 0

    for filename in sub1:
        #Open the file
        fIn = open(filename, 'r')
        #For each line of the files, create a feature vector
        # of the raw joint positions. Add that to the trainingData.
        for line in fIn:
            features = returnLine(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        fIn.close()
        index += 1

    return trainingData
Exemplo n.º 4
0
def generateOneTrainPositionData():
    '''
    This creates a data set to be used to train a classifier.
    The data is from participant 1 and uses the joint positions
    as features.
    '''
    trainingData = TrainingData("Position Data")
    index = 0

    for filename in sub1:
        #Open the file
        fIn = open(filename, 'r')
        #For each line of the files, create a feature vector
        # of the raw joint positions. Add that to the trainingData.
        for line in fIn:
            features = returnLine(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        fIn.close()
        index += 1

    return trainingData
Exemplo n.º 5
0
def generateTwoPositionTrainingData():
    '''
    This function creates training data using the first
    two participants' data and has joint positions as features
    for the samples.
    '''

    trainingData = TrainingData("Testing Data")
    index = 0

    for i in xrange(len(labels)):
        #Open the file
        fIn = open(sub1[i], 'r')
        f2In = open(sub2[i], 'r')

        #For each line of the files, create a feature vector
        # of the raw joint positions. Add that to the trainingData.
        for line in fIn:
            features = returnLine(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        fIn.close()

        for line in f2In:
            features = returnLine(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        f2In.close()

        index += 1

    return trainingData
Exemplo n.º 6
0
def generateTwoAngleTrainingData():
    '''
    This function creates training data using the first
    two participants' data and has joint angles as features
    for the samples.
    '''

    trainingData = TrainingData("Testing Data")
    index = 0

    for i in xrange(len(labels)):
        #Open the file
        fIn = open(sub1[i], 'r')
        f2In = open(sub2[i], 'r')

        #For each line of the files calculate the
        # angles inbetween joints and use the resulting
        # array as the feature vector. Add that to the trainingData.
        for line in fIn:
            features = generateAngles(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        fIn.close()

        for line in f2In:
            features = generateAngles(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        f2In.close()

        index += 1

    return trainingData
Exemplo n.º 7
0
def generateTrainData():
    '''
    This creates a data set to be used to train a classifier.
    The data is from participant 1 and uses the calculated
    joint angles as features.
    '''
    trainingData = TrainingData("train data")
    index = 0

    for filename in sub1:
        # Open the file
        fIn = open(filename, 'r')
        # For each line of the file calculate the
        # angles inbetween joints and use the resulting
        # array as the feature vector. Add that to the trainingData.
        for line in fIn:
            features = np.array(json.loads(line)['feature'])
            trainingData.addSampleFromFeatures(features, labels[index])
        fIn.close()
        index += 1

    return trainingData
Exemplo n.º 8
0
def crossValidationPositions():
    '''
    Performs 10 fold cross validation on the total
    joint position dataset
    '''
    theData = generateAllPositionTrainingData()
    means, stdDevs = theData.normalizeData()
    k = 10

    #Partition the data into 10 subsets
    dataSets = theData.getKSegments(k)

    #For each of the 10 subsets leave one out, train on the
    # other 9, test on the one left out, print the accuracy.
    results = confusionMatrix(labels)
    for i in xrange(k):
        print i
        #testing set
        testSet = dataSets[i]
        #Build the training set
        trainingSet = TrainingData("CrossVal")
        trainingList = copy.deepcopy(dataSets)
        trainingList.pop(i)
        for elem in trainingList:
            trainingSet.combineWithNewData(elem)

        #train the classifier on the trainingSet
        testForest = RandomForest(trainingSet)
        testForest.train()

        #Evaluate the classifer on the test set

        for samp in testSet.getData():
            resultLabel = testForest.classify(samp)
            trueLabel = samp.getLabel()

            results.update(trueLabel, resultLabel)

    results.printMatrix()
Exemplo n.º 9
0
def crossValidationPositions():
    '''
    Performs 10 fold cross validation on the total 
    joint position dataset
    '''
    theData = generateAllPositionTrainingData() 
    means, stdDevs = theData.normalizeData()
    k = 10

    #Partition the data into 10 subsets
    dataSets = theData.getKSegments(k)

    #For each of the 10 subsets leave one out, train on the 
    # other 9, test on the one left out, print the accuracy. 
    results = confusionMatrix(labels)
    for i in xrange(k):
        print i
        #testing set
        testSet = dataSets[i]
        #Build the training set
        trainingSet = TrainingData("CrossVal")
        trainingList = copy.deepcopy(dataSets)
        trainingList.pop(i)
        for elem in trainingList:
            trainingSet.combineWithNewData(elem)

        #train the classifier on the trainingSet
        testForest = RandomForest(trainingSet)
        testForest.train()

        #Evaluate the classifer on the test set
        
        for samp in testSet.getData():
            resultLabel = testForest.classify(samp)
            trueLabel = samp.getLabel()

            results.update(trueLabel, resultLabel)

    results.printMatrix()
Exemplo n.º 10
0
def generateOneTrainAngleData():
    '''
    This creates a data set to be used to train a classifier.
    The data is from participant 1 and uses the calculated
    joint angles as features.
    '''
    trainingData = TrainingData("Angle Data")
    index = 0

    for filename in sub1:
        #Open the file
        fIn = open(filename, 'r')
        #For each line of the file calculate the 
        # angles inbetween joints and use the resulting 
        # array as the feature vector. Add that to the trainingData.
        for line in fIn:
            features = generateAngles(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        fIn.close()
        index += 1

    return trainingData
Exemplo n.º 11
0
def generateAllAngleTrainingData():
    '''
    This function creates one large TrainingData object
    containing data from all three participants but uses
    calculated angles as the features for each data sample.
    '''
    trainingData = TrainingData("Testing Data")
    index = 0

    for i in xrange(len(labels)):
        #Open the file
        fIn = open(sub1[i], 'r')
        f2In = open(sub2[i], 'r')
        f3In = open(sub3[i], 'r')

        #For each line of the files calculate the
        # angles inbetween joints and use the resulting
        # array as the feature vector. Add that to the trainingData.
        for line in fIn:
            features = generateAngles(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        fIn.close()

        for line in f2In:
            features = generateAngles(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        f2In.close()

        for line in f3In:
            features = generateAngles(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        f3In.close()

        index += 1

    #Return the data object
    return trainingData
Exemplo n.º 12
0
def generateAllPositionTrainingData():
    '''
    This function creates one large TrainingData object
    containing data from all three participants but uses
    regular position data as the features for each data sample.
    '''
    trainingData = TrainingData("Testing Data")
    index = 0

    for i in xrange(len(labels)):
        #Open the file
        fIn = open(sub1[i], 'r')
        f2In = open(sub2[i], 'r')
        f3In = open(sub3[i], 'r')

        #For each line of the files, create a feature vector
        # of the raw joint positions. Add that to the trainingData.
        for line in fIn:
            features = returnLine(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        fIn.close()

        for line in f2In:
            features = returnLine(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        f2In.close()

        for line in f3In:
            features = returnLine(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        f3In.close()

        index += 1

    #Return the data
    return trainingData
Exemplo n.º 13
0
def generateAllAngleTrainingData():
    '''
    This function creates one large TrainingData object 
    containing data from all three participants but uses
    calculated angles as the features for each data sample.
    '''
    trainingData = TrainingData("Testing Data")
    index = 0

    for i in xrange(len(labels)):
        #Open the file
        fIn = open(sub1[i], 'r')
        f2In = open(sub2[i], 'r')
        f3In = open(sub3[i], 'r')

        #For each line of the files calculate the 
        # angles inbetween joints and use the resulting 
        # array as the feature vector. Add that to the trainingData.
        for line in fIn:
            features = generateAngles(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        fIn.close()

        for line in f2In:
            features = generateAngles(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        f2In.close()

        for line in f3In:
            features = generateAngles(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        f3In.close()

        index += 1

    #Return the data object
    return trainingData
Exemplo n.º 14
0
def generateAllPositionTrainingData():
    '''
    This function creates one large TrainingData object 
    containing data from all three participants but uses
    regular position data as the features for each data sample.
    '''
    trainingData = TrainingData("Testing Data")
    index = 0

    for i in xrange(len(labels)):
        #Open the file
        fIn = open(sub1[i], 'r')
        f2In = open(sub2[i], 'r')
        f3In = open(sub3[i], 'r')

        #For each line of the files, create a feature vector
        # of the raw joint positions. Add that to the trainingData.
        for line in fIn:
            features = returnLine(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        fIn.close()

        for line in f2In:
            features = returnLine(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        f2In.close()

        for line in f3In:
            features = returnLine(line)
            trainingData.addSampleFromFeatures(features, labels[index])
        f3In.close()

        index += 1

    #Return the data
    return trainingData