Ejemplo n.º 1
0
def plotEntry(entry):
    accData = np.array(plotdata.readNumericData(entry["accfile"]))
    gyroData = np.array(plotdata.readNumericData(entry["gyrofile"]))

    accData, gyroData = process.cleanData(accData, gyroData)
    # process data
    accData, gyroData = process.processData(accData, gyroData)

    # take sample of data
    accData = accData[: len(accData) * dataPortion, :]
    gyroData = gyroData[: len(gyroData) * dataPortion, :]

    # plot accelerometer/gyroscope
    X = accData[:, 0]
    # X = range(1,len(accData[:,0])+1)

    # extract sample number
    # sample = re.search('[0-9]{5,7}', entry['accfile']).group(0)
    sample = entry["person"]
    print entry

    show3D = False

    if show3D:
        # animate motion
        fig = plt.figure()
        ax = fig.gca(projection="3d")
        ax.set_aspect("equal")
        r = [-1, 1]
        for s, e in combinations(np.array(list(product(r, r, r))), 2):
            if np.sum(np.abs(s - e)) == r[1] - r[0]:
                ax.plot3D(*zip(s, e), color="b")
        for pt in gyroData:
            print pt
            a = Arrow3D([0, 1], [0, 1], [0, 1], mutation_scale=20, lw=1, arrowstyle="-|>", color="k")
            ax.add_artist(a)

            plt.show()
            text = raw_input("Press enter for next one...")
    else:
        f, (ax1, ax2) = plt.subplots(2, 1)  # , sharex=True)
        ax1.set_title(entry["device"] + " - " + sample + " - accelerometer")
        ax1.plot(X, accData[:, 1], "r", label="x")
        ax1.plot(X, accData[:, 2], "g", label="y")
        ax1.plot(X, accData[:, 3], "b", label="z")

        ax1.legend()

        X = gyroData[:, 0]
        # X = range(1,len(gyroData[:,0])+1)
        # sample = re.search('[0-9]{5,7}', entry['gyrofile']).group(0)
        ax2.set_title(entry["person"] + " - " + sample + " - gyroscope")
        ax2.plot(X, gyroData[:, 1], "r", label="z")
        ax2.plot(X, gyroData[:, 2], "g", label="x")
        ax2.plot(X, gyroData[:, 3], "b", label="y")

        ax2.legend()
Ejemplo n.º 2
0
def get_dataset():
    all_sdk = SDK.query.all()
    result_all_sdk = sdks_schema.dump(all_sdk)
    all_app_sdk = App_SDK.query.all()
    result_all_app_sdk = app_sdks_schema.dump(all_app_sdk)

    selectedSDKs = request.json['selectedSDKs']
    selectedSDKs = list(filter(None, selectedSDKs))

    #slower (by far)
    #result = processData2(result_all_sdk, selectedSDKs, result_all_app_sdk)
    result = processData(result_all_sdk, result_all_app_sdk, selectedSDKs)

    return jsonify(result)
lRate = 0.02
nEpochs = 5000

# Import and initialize the data
filename = "GlassData.csv"
rawData = np.genfromtxt(filename, delimiter = ',', skip_header = 1)
rawData = rawData[:,1:len(rawData[0,:])] #Trim off the data point number in the GlassData.csv file
rows = len(rawData[:,0])
cols = len(rawData[0,:])

txtfile = "outputs.txt"
afile = open(txtfile,'w')


#Process and normalize the data
trainSet,trainAns,validSet,validAns,testSet,testAns = pc.processData(rawData, nOutputs)

# Add Noise
noise = 0.05
trainSet = pc.addNoise(trainSet,noise)

### DATA PROCESSING DONE AT THIS POINT ###

# Initialize ALL output nodes (hidden and final output) and the weights
hidden_o = np.zeros(nHidden)
outputs = np.zeros(nOutputs)

weightsHidden = 2*(np.random.rand(nHidden, nInputs)-0.5)
weightsOutput = 2*(np.random.rand(nOutputs, nHidden)-0.5)

## Call the train network function
Ejemplo n.º 4
0
def extractFeatures(features, entry, config):
    # require gyro and acc data
    if not config['data-filters']['gyrofile']: return
    if not config['data-filters']['accfile']: return

    accData = np.array(readNumericData(entry['accfile']))
    gyroData = np.array(readNumericData(entry['gyrofile']))

    # clean data up
    accData, gyroData = process.cleanData(accData, gyroData)
    # process data
    accData, gyroData = process.processData(accData, gyroData)

    #features += accData.mean(axis=0)[1:].tolist()
    features += accData.std(axis=0)[1:].tolist()
    totalAcc = sqrt((square(accData[:,1]) + square(accData[:,2]) + square(accData[:,3])))
    
    medFilterAccX = signal.medfilt(accData[:,1],11)
    medFilterAccY = signal.medfilt(accData[:,2],11)
    medFilterAccZ = signal.medfilt(accData[:,3],11)
    
    b, a = signal.butter(3, 10.0/25, btype='low')
    butterAccX = signal.filtfilt(b,a,medFilterAccX)
    butterAccY = signal.filtfilt(b,a,medFilterAccY)
    butterAccZ = signal.filtfilt(b,a,medFilterAccZ)
    
    b, a = signal.butter(3, 0.3/25, btype='low')
    gravityAccX = signal.filtfilt(b,a,butterAccX)
    gravityAccY = signal.filtfilt(b,a,butterAccY)
    gravityAccZ = signal.filtfilt(b,a,butterAccZ)

    
    b, a = signal.butter(3, 0.3/25, btype='high')
    bodyAccX = signal.filtfilt(b,a,butterAccX)
    bodyAccY = signal.filtfilt(b,a,butterAccY)
    bodyAccZ = signal.filtfilt(b,a,butterAccZ)
    totalAcc = sqrt(square(bodyAccX)+square(bodyAccY)+square(bodyAccZ))
    #features.append(mean(totalAcc))

    #features.append(mean(bodyAccX))
    #features.append(std(bodyAccX))
    #features.append(mean(bodyAccY))
    #features.append(std(bodyAccY))
    #features.append(mean(bodyAccZ))
    #features.append(std(bodyAccZ))
    #features.append(mean(gravityAccZ))
    #features.append(std(gravityAccZ))
    #features.append(mean(gravityAccX))
    #features.append(std(gravityAccX))
    #features.append(mean(gravityAccY))
    #features.append(std(gravityAccY))
    
    #features.append(sqrt(mean(square(bodyAccX))))
    features.append(sqrt(mean(square(bodyAccY))))
    #features.append(sqrt(mean(square(bodyAccZ))))
    
    #fx,Px = signal.welch(bodyAccX, fs=50.0, nperseg=128, noverlap=128.0/2, nfft=None, detrend='constant', return_onesided=False, scaling='density', axis=-1)
    #fy,Py = signal.welch(bodyAccY, fs=50.0, nperseg=128, noverlap=128.0/2, nfft=None, detrend='constant', return_onesided=False, scaling='density', axis=-1)
    #fz,Pz = signal.welch(bodyAccZ, fs=50.0, nperseg=128, noverlap=128.0/2, nfft=None, detrend='constant', return_onesided=False, scaling='density', axis=-1)
    
    #features.append(sum(square(Px)))
    #pylab.show()
    
    
    
    bodyJerkX=diff(bodyAccX,n=1)
    bodyJerkY=diff(bodyAccY,n=1)
    bodyJerkZ=diff(bodyAccZ,n=1)