Hey all, 

I’m running into some trouble with using HTM for a gesture recognition 
application and would appreciate some help. 
First, the data is collected from 17 users performing 5 gestures of each of 16 
different gesture classes using motion sensors. The feature vector for each 
sample is a sequence of discretized directions calculated using bezier control 
points after curve fitting the gesture trace. 

For a baseline, I fed the data to 16 10-state HMMs for training and again for 
testing. The classification accuracy achieved is 95.7%. 

For HTM, I created 16 CLA models using parameters from a medium swarm. I ran 
the data through the models for training where each model is trained on only 1 
gesture class. For testing, I fed the same data again with learning turned off 
and recorded the anomaly score (averaged across each sequence) for each model. 
Classification was done by seeking the model with the minimum anomaly score. 
Accuracy turned out to be a puzzling 0.0%!!

Below is the relevant section of the code. I would appreciate any hints. 
Thanks,
Nick

def run_experiment():
    print "Running experiment..."

    model = [0]*16
    for i in range(0, 16):
        model[i] = ModelFactory.create(model_params, logLevel=0)
        model[i].enableInference({"predictedField": FIELD_NAME})

    with open(FILE_PATH, "rb") as f:
        csv_reader = csv.reader(f)
        data = []
        labels = []
        for row in csv_reader:
            r = [int(item) for item in row[:-1]]
            data.append(r)
            labels.append(int(row[-1]))

        # data_train, data_test, labels_train, labels_test = 
cross_validation.train_test_split(data, labels, test_size=0.4, random_state=0)
        data_train = data
        data_test = data
        labels_train = labels
        labels_test = labels

    for passes in range(0, TRAINING_PASSES):
        sample = 0
        for (ind, row) in enumerate(data_train):
            for r in row:
                value = int(r)
                result = model[labels_train[ind]].run({FIELD_NAME: value, 
'_learning': True})
                prediction = result.inferences["multiStepBestPredictions"][1]
                anomalyScore = result.inferences["anomalyScore"]
            model[labels[ind]].resetSequenceStates()
            sample += 1
            print "Processing training sample %i" % sample
            if sample == 100:
                break

    sample = 0
    labels_predicted = []
    for row in data_test:
        anomaly = [0]*16
        for i in range(0, 16):
            model[i].resetSequenceStates()
            for r in row:
                value = int(r)
                result = model[i].run({FIELD_NAME: value, '_learning': False})
                prediction = result.inferences["multiStepBestPredictions"][1]
                anomalyScore = result.inferences["anomalyScore"]
                # print value, prediction, anomalyScore
                if value == int(prediction) and anomalyScore == 0:
                    # print "No prediction made"
                    anomalyScore = 1
                anomaly[i] += anomalyScore
            anomaly[i] /= len(row)
        sample += 1
        print "Processing testing sample %i" % sample
        labels_predicted.append(np.min(np.array(anomaly)))
        print anomaly, row[-1]
        if sample == 100:
            break

    accuracy = np.sum(np.array(labels_predicted) == 
np.array(labels_test))*100.0/len(labels_test)
    print "Testing accuracy is %0.2f" % accuracy

Reply via email to