예제 #1
0
def LoadTrainingData(namelist):
    print namelist
    trainingData = []
    trainingLabel = []
    i = 0
    # Load the data in numpy's type
    for name in namelist:
        data = np.genfromtxt(name, delimiter=',')
        print data.shape
        # Do preprocessing & moving average
        temp_ind=data[:,0]    
        temp_ind = temp_ind.reshape((len(temp_ind),1))
        data = np.hstack((temp_ind, dynamicRangeCheck(data[:,1:7])))
        [axis1, axis2, axis3, axis4, axis5, axis6] = Preprocessing(data, maxLen=250, n=5)

        cleanedData = np.array([axis1, axis2, axis3, axis4, axis5, axis6])

        # Collect data which has been processing
        trainingData.append(cleanedData)
        # Create training label
        trainingLabel.extend([i for _ in range(axis1.shape[0])])
        i+=1

    trainingLabel = trainingLabel * len(trainingData[0])

    # Training Model
    modelPool, p_pool, p_table, testingData, _, scaleRange, scaleMin, rangeOfData, LogRegPool = TrainingModel(trainingData, trainingLabel)
    return modelPool, p_pool, trainingData, trainingLabel, scaleRange, scaleMin, LogRegPool
예제 #2
0
def DataRepresent(trainingData, trainingLabel, rawdata_test, scaleRange, scaleMin):
    # Preprocessing
    temp_ind=rawdata_test[:,0]    
    temp_ind = temp_ind.reshape((len(temp_ind),1))
    rawdata_test = np.hstack((temp_ind, dynamicRangeCheck(rawdata_test[:,1:7])))
    [axis1, axis2, axis3, axis4, axis5, axis6] = Preprocessing(rawdata_test, maxLen=192, n=5)
    testingData = np.array([axis1, axis2, axis3, axis4, axis5, axis6])

    testingFeature = np.zeros((testingData.shape[1], 1))
    # Vectorization
    for x in testingData:
        testingFeature = np.insert(testingFeature, testingFeature.shape[1], Vectorize(x), axis=1)

    testingFeature = np.delete(testingFeature, 0, axis=1)

    # Envelope
    for idx in range(len(trainingData[0])):
        tmp = []
        for i in range(len(trainingData)):
            tmp.extend(trainingData[i][idx].tolist())

        envelopeResult = np.array(envelope(np.array(trainingLabel[idx*len(tmp):(idx+1)*len(tmp)]), tmp, testingData[idx].tolist(), 1))
        testingFeature = np.insert(testingFeature, testingFeature.shape[1], envelopeResult.T, axis=1)

    # Max-min Normalize
    testingFeature = (testingFeature-scaleMin)/scaleRange

    return testingFeature
예제 #3
0
def DataRepresent(dataPool, trainingLabel, rawdata):
    # Preprocessing
    temp_ind=rawdata[:,0]    
    temp_ind = temp_ind.reshape((len(temp_ind),1))
    result = np.hstack((temp_ind, dynamicRangeCheck(rawdata[:,1:7])))
    [axis1, axis2, axis3, axis4, axis5, axis6] = Preprocessing(result, maxLen=250, n=5)
    testingData = np.array([axis1, axis2, axis3, axis4, axis5, axis6])
    
    #print testingData

    testingFeature = np.zeros((testingData.shape[1], 1))

    # Envelope
    for idx in range(6):
        training_sample = []
        map(lambda i: training_sample.extend(dataPool[i][idx].tolist()), xrange(4))

        envelopeResult = np.array(envelope(np.array(trainingLabel[idx*len(training_sample):(idx+1)*len(training_sample)]), training_sample, testingData[idx].tolist(), 1))
        testingFeature = np.insert(testingFeature, testingFeature.shape[1], envelopeResult.T, axis=1)
    print testingFeature
    testingFeature = np.delete(testingFeature, 0, axis=1)

    return testingFeature