Commit 15b8657e authored by Oskars Linde's avatar Oskars Linde
Browse files

Cleaned project

parent 2a1bd7f5
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
{
"cells": [
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib\n",
"import matplotlib.pyplot as plt\n",
"import tensorflow as tf # Version 1.0.0 (some previous versions are used in past commits)\n",
"from sklearn import metrics\n",
"from sklearn.model_selection import train_test_split\n",
"from scipy import stats\n",
"import seaborn as sns\n",
"\n",
"import os\n",
"\n",
"import keras\n",
"from keras.models import Sequential\n",
"from keras.layers import Dense, Dropout, Activation\n",
"from keras.layers import Conv1D, MaxPooling1D, LSTM, CuDNNLSTM\n",
"from keras.callbacks import ModelCheckpoint\n",
"from keras.layers.normalization import BatchNormalization\n",
"from keras.models import model_from_json\n",
"\n",
"RANDOM_SEED = 42"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"inputFile = 'data/workindData_02_01_IRI_50hz.txt'\n",
"outputFile = \"data/workindData_02_01_IRI_50hz.txt\"\n",
"#Period in milliseconds\n",
"period = 20"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
"columns = ['user','activity','timestamp', 'x-axis', 'y-axis', 'z-axis']\n",
"df = pd.read_csv(inputFile, header = None, names = columns)\n",
"df = df.dropna()"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"Walking\n",
"(0, 824)\n",
"------------------------\n",
"2\n",
"Walking\n",
"(824, 1648)\n",
"------------------------\n",
"3\n",
"Downstairs\n",
"(1648, 2472)\n",
"------------------------\n",
"4\n",
"Downstairs\n",
"(2472, 3296)\n",
"------------------------\n",
"5\n",
"Walking\n",
"(3296, 4120)\n",
"------------------------\n",
"6\n",
"Downstairs\n",
"(4120, 4944)\n",
"------------------------\n",
"7\n",
"Walking\n",
"(4944, 5768)\n",
"------------------------\n",
"8\n",
"Downstairs\n",
"(5768, 6592)\n",
"------------------------\n",
"9\n",
"Downstairs\n",
"(6592, 7416)\n",
"------------------------\n",
"10\n",
"Walking\n",
"(7416, 8240)\n",
"------------------------\n",
"11\n",
"Downstairs\n",
"(8240, 9064)\n",
"------------------------\n",
"12\n",
"Walking\n",
"(9064, 9888)\n",
"------------------------\n",
"13\n",
"Walking\n",
"(9888, 10712)\n",
"------------------------\n",
"14\n",
"Walking\n",
"(10712, 11536)\n",
"------------------------\n",
"15\n",
"Downstairs\n",
"(11536, 12360)\n",
"------------------------\n",
"16\n",
"Downstairs\n",
"(12360, 13184)\n",
"------------------------\n",
"17\n",
"Walking\n",
"(13184, 14008)\n",
"------------------------\n",
"18\n",
"Standing\n",
"(14008, 14832)\n",
"------------------------\n",
"19\n",
"Upstairs\n",
"(14832, 15656)\n",
"------------------------\n",
"20\n",
"Downstairs\n",
"(15656, 16480)\n",
"------------------------\n",
"21\n",
"Walking\n",
"(16480, 17304)\n",
"------------------------\n",
"22\n",
"Upstairs\n",
"(17304, 18128)\n",
"------------------------\n",
"23\n",
"Walking\n",
"(18128, 18951)\n",
"------------------------\n"
]
}
],
"source": [
"counter = 0\n",
"totalcounter = 0\n",
"partsCounter = 0\n",
"startList = []\n",
"endList = []\n",
"for x in range (1,len(df.index)):\n",
" totalcounter = totalcounter + 1\n",
" counter = counter + 1\n",
" if (df['timestamp'].iloc[x]-df['timestamp'].iloc[x-1]>100):\n",
" partsCounter = partsCounter + 1\n",
" print(partsCounter)\n",
" #print(df['activity'].iloc[x-1], df['timestamp'].iloc[x-1])\n",
" #print(df['activity'].iloc[x], df['timestamp'].iloc[x] , df['timestamp'].iloc[x]-df['timestamp'].iloc[x-1] ,df['x-axis'].iloc[x])\n",
" print(df['activity'].iloc[x-1])\n",
" #print(df['activity'].iloc[x+1], df['timestamp'].iloc[x+1])\n",
" startList.append(totalcounter - counter)\n",
" endList.append(totalcounter)\n",
" print(totalcounter - counter, totalcounter)\n",
" counter = 0\n",
" print(\"------------------------\")\n",
" \n",
"partsCounter = partsCounter + 1\n",
"print(partsCounter)\n",
"#print(df['activity'].iloc[x-1], df['timestamp'].iloc[x-1])\n",
"#print(df['activity'].iloc[x], df['timestamp'].iloc[x] , df['timestamp'].iloc[x]-df['timestamp'].iloc[x-1] ,df['x-axis'].iloc[x])\n",
"print(df['activity'].iloc[x-1])\n",
"#print(df['activity'].iloc[x+1], df['timestamp'].iloc[x+1])\n",
"startList.append(totalcounter - counter)\n",
"endList.append(totalcounter)\n",
"print(totalcounter - counter, totalcounter)\n",
"counter = 0\n",
"print(\"------------------------\")\n",
"\n",
" \n",
"dataPartsDF = pd.DataFrame(\n",
" {'starttime': startList,\n",
" 'endtime': endList,\n",
" })"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(0, 23, 'Walking', 0, 2951)\n",
"(1544391199547, 1544391258548)\n",
"33,Walking,1544391216027,1.3822524809523808,-9.355628571428571,2.4553108333333338\n",
"\n",
"Done\n",
"(1, 23, 'Walking', 2951, 5902)\n",
"(1544429598717, 1544429657717)\n",
"33,Walking,1544429615197,-5.756096118181818,-9.356540045454546,-0.10621549181818182\n",
"\n",
"Done\n",
"(2, 23, 'Downstairs', 5902, 8853)\n",
"(1544429727337, 1544429786336)\n",
"33,Downstairs,1544429743817,1.7525555952380956,-3.047248738095238,-3.2807403666666666\n",
"\n",
"Done\n",
"(3, 23, 'Downstairs', 8853, 11804)\n",
"(1544429871656, 1544429930656)\n",
"33,Downstairs,1544429888136,4.638526304999999,-10.18445563,-6.304890980000001\n",
"\n",
"Done\n",
"(4, 23, 'Walking', 11804, 14755)\n",
"(1544430060836, 1544430119836)\n",
"33,Walking,1544430077316,0.5228936344999999,-2.02405807,7.4593747000000015\n",
"\n",
"Done\n",
"(5, 23, 'Downstairs', 14755, 17706)\n",
"(1544438728034, 1544438787040)\n",
"33,Downstairs,1544438744514,5.872862790476191,-13.243356142857142,5.566404914285713\n",
"\n",
"Done\n",
"(6, 23, 'Walking', 17706, 20657)\n",
"(1544452028979, 1544452087975)\n",
"33,Walking,1544452045459,2.7140670800000004,-4.8726796000000006,-1.0764330920000003\n",
"\n",
"Done\n",
"(7, 23, 'Downstairs', 20657, 23608)\n",
"(1544509936070, 1544509995068)\n",
"33,Downstairs,1544509952550,-0.32417491899999995,-7.904217470000002,-0.7144297685000001\n",
"\n",
"Done\n",
"(8, 23, 'Downstairs', 23608, 26559)\n",
"(1544616183909, 1544616242909)\n",
"33,Downstairs,1544616200389,0.4254838338095239,-16.32207080952381,5.1318003714285725\n",
"\n",
"Done\n",
"(9, 23, 'Walking', 26559, 29510)\n",
"(1544616314474, 1544616373473)\n",
"33,Walking,1544616330954,2.150863659090909,-8.972161409090909,0.8875959226363639\n",
"\n",
"Done\n",
"(10, 23, 'Downstairs', 29510, 32461)\n",
"(1544683008679, 1544683067680)\n",
"33,Downstairs,1544683025159,-0.8523358000000002,-11.425131,-1.8866308999999997\n",
"\n",
"Done\n",
"(11, 23, 'Walking', 32461, 47212)\n",
"(1544715755096, 1544716050095)\n",
"33,Walking,1544715771576,1.318726355,-3.636792330000001,3.9681498800000004\n",
"\n",
"Done\n",
"(12, 23, 'Walking', 47212, 58181)\n",
"(1544737674618, 1544737893985)\n",
"33,Walking,1544737691098,-6.094201030000002,3.5807679815,5.6613292699999995\n",
"\n",
"Done\n",
"(13, 23, 'Walking', 58181, 69246)\n",
"(1544741411063, 1544741632342)\n",
"33,Walking,1544741427543,-14.470555400000002,-13.226527149999999,-0.1364694996\n",
"\n",
"Done\n",
"(14, 23, 'Downstairs', 69246, 70608)\n",
"(1545027915105, 1545027942322)\n",
"33,Downstairs,1545027931585,-0.1500366333333334,-11.176133333333333,1.327983866666667\n",
"\n",
"Done\n",
"(15, 23, 'Downstairs', 70608, 73559)\n",
"(1545056498137, 1545056557138)\n",
"33,Downstairs,1545056514617,-12.536040000000002,-8.896853,-1.6663644\n",
"\n",
"Done\n",
"(16, 23, 'Walking', 73559, 103060)\n",
"(1545335676238, 1545336266237)\n",
"33,Walking,1545335692718,-1.043872,-13.283031000000001,-4.261679\n",
"\n",
"Done\n",
"(17, 23, 'Standing', 103060, 107451)\n",
"(1549039447065, 1549039534864)\n",
"33,Standing,1549039463545,2.336741,-9.72189555,0.176692083\n",
"\n",
"Done\n",
"(18, 23, 'Upstairs', 107451, 109587)\n",
"(1549039595727, 1549039638430)\n",
"33,Upstairs,1549039612207,0.07852982000000008,-8.393113,4.179318640000001\n",
"\n",
"Done\n",
"(19, 23, 'Downstairs', 109587, 111692)\n",
"(1549039648827, 1549039690904)\n",
"33,Downstairs,1549039665307,1.1579608260869563,-9.051748130434783,-4.817550195652174\n",
"\n",
"Done\n",
"(20, 23, 'Walking', 111692, 113674)\n",
"(1549039711405, 1549039751024)\n",
"33,Walking,1549039727885,2.3914655904761903,-2.466255876190476,-0.6006025666666668\n",
"\n",
"Done\n",
"(21, 23, 'Upstairs', 113674, 115738)\n",
"(1549039765694, 1549039806945)\n",
"33,Upstairs,1549039782174,1.4802412304347827,-10.564882956521739,0.4118027008695652\n",
"\n",
"Done\n",
"(22, 23, 'Walking', 115738, 116776)\n",
"(1549039825865, 1549039846603)\n",
"33,Walking,1549039842345,0.1013545349999998,-10.717245083333333,1.6751431333333333\n",
"\n",
"Done\n"
]
}
],
"source": [
"import numpy as np\n",
"from scipy.interpolate import interp1d\n",
"from numpy import arange\n",
"from matplotlib.pyplot import figure,show\n",
"\n",
"#print(len(dataPartsDF.index))\n",
"\n",
"\n",
"for i in range(0, len(dataPartsDF.index), 1):\n",
"#for i in range(27, 28, 1):\n",
" \n",
" startInt = dataPartsDF['starttime'].iloc[i]\n",
" endInt = dataPartsDF['endtime'].iloc[i]\n",
" \n",
" print(i,len(dataPartsDF.index),df['activity'].iloc[startInt] , dataPartsDF['starttime'].iloc[i], dataPartsDF['endtime'].iloc[i])\n",
"\n",
" \n",
" realTimestamp = []\n",
" realXvalues = []\n",
" realYvalues = []\n",
" realZvalues = []\n",
" \n",
" plotThis = False;\n",
"\n",
" #def interResample(startData, endData):\n",
" # data = df[df['activity'] == activity][['x-axis', 'y-axis', 'z-axis']][:200]\n",
"\n",
" for x in range (startInt,endInt):\n",
" realTimestamp.append(df['timestamp'].iloc[x])\n",
" realXvalues.append(df['x-axis'].iloc[x])\n",
" realYvalues.append(df['y-axis'].iloc[x])\n",
" realZvalues.append(df['z-axis'].iloc[x])\n",
"\n",
" #print(realTimestamp[0]-realTimestamp[-1])\n",
" # First interpolation\n",
" fx = interp1d(realTimestamp, realXvalues, kind=\"linear\")\n",
" fy = interp1d(realTimestamp, realYvalues, kind=\"linear\")\n",
" fz = interp1d(realTimestamp, realZvalues, kind=\"linear\")\n",
" xnew = arange(realTimestamp[0], realTimestamp[-1], 1)\n",
" #ENd of first interpolation\n",
"\n",
" #Manual resampling using for loop\n",
" resampledTimeList = []\n",
" resampledXValueList = []\n",
" resampledYValueList = []\n",
" resampledZValueList = []\n",
" \n",
" print(realTimestamp[0], realTimestamp[-1])\n",
" for x in range(realTimestamp[0], realTimestamp[-1], 20):\n",
" resampledTimeList.append(x)\n",
" resampledXValueList.append(fx(x))\n",
" resampledYValueList.append(fy(x))\n",
" resampledZValueList.append(fz(x))\n",
"\n",
" resampledTimeList.append(realTimestamp[-1])\n",
" resampledXValueList.append(fx(realTimestamp[-1]))\n",
" resampledYValueList.append(fy(realTimestamp[-1]))\n",
" resampledZValueList.append(fz(realTimestamp[-1]))\n",
" \n",
" #End of manual resampling\n",
" #print(len(resampledXValueList))\n",
" \n",
" #Interpolate the resampled values\n",
" fx2 = interp1d(resampledTimeList, resampledXValueList, kind=\"cubic\")\n",
" fy2 = interp1d(resampledTimeList, resampledYValueList, kind=\"cubic\")\n",
" fz2 = interp1d(resampledTimeList, resampledZValueList, kind=\"cubic\")\n",
" #xnew2 = arange(resampledTimeList[0], resampledTimeList[-1], 33)\n",
" xnew2 = arange(resampledTimeList[0], resampledTimeList[0]+16500, period)\n",
" #xnew2 = np.append(xnew2, resampledTimeList[-1])\n",
" #End of interpolate the resampled values \n",
"\n",
" if (plotThis):\n",
" figure(num=None, figsize=(30, 20), dpi=80, facecolor='w', edgecolor='k')\n",
" fig = figure(1)\n",
" ax = fig.add_subplot(212)\n",
"\n",
" #ax.plot(realTimestamp, realXvalues, label=\"Real\")\n",
" #ax.plot(realTimestamp, realXvalues,\"\", label=\"Real\")\n",
" #ax.plot(xnew2, f2(xnew2), label=\"Interpolate + resample + interpolate\")\n",
" ax.plot(xnew2, fx2(xnew2), \"\" ,label=\"IRI X\")\n",
" ax.plot(xnew2, fy2(xnew2), \"\" ,label=\"IRI Y\")\n",
" ax.plot(xnew2, fz2(xnew2), \"\" ,label=\"IRI Z\")\n",
"\n",
" ax.grid(True)\n",
"\n",
" #ax.set_ylim((-2, 2))\n",
" #ax.set_xlim(1544391199547+1000,1544391199547+2000)\n",
"\n",
" l = ax.set_xlabel('Real function')\n",
" l.set_color('g')\n",
" l.set_fontsize('large')\n",
"\n",
" ax.legend()\n",
" show()\n",
"\n",
" #print(df['activity'].iloc[startInt])\n",
" lineToWrite = \"\"\n",
" userID = str(33)\n",
" activityType = str(df['activity'].iloc[startInt])\n",
" accFile = open(outputFile, \"a\")\n",
" for x in xnew2:\n",
" lineToWrite = userID + \",\" + activityType + \",\" + str(x) + \",\" + str(fx2(x)) + \",\" + str(fy2(x)) + \",\" + str(fz2(x)) + \"\\n\"\n",
" if (x!=xnew2[-1]):\n",
" accFile.write(lineToWrite)\n",
" continue\n",
" else:\n",
" print(lineToWrite)\n",
" \n",
" accFile.close()\n",
" print(\"Done\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
This diff is collapsed.
......@@ -807,14 +807,14 @@
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
"pygments_lexer": "ipython3",
"version": "3.6.7"
}
},
"nbformat": 4,
......
Now the file has one more line!
\ No newline at end of file
......@@ -191,14 +191,14 @@
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
"pygments_lexer": "ipython3",
"version": "3.6.7"
}
},
"nbformat": 4,
......
(dp0
S'train_acc'
p1
(lp2
cnumpy.core.multiarray
scalar
p3
(cnumpy
dtype
p4
(S'f4'
p5
I0
I1
tp6
Rp7
(I3
S'<'
p8
NNNI-1
I-1
I0
tp9
bS'\xe7\x91j?'
p10
tp11
Rp12
ag3
(g7
S'\xebhs?'
p13
tp14
Rp15
ag3
(g7
S'X$s?'
p16
tp17
Rp18
ag3
(g7
S'\x9c\x1fj?'
p19
tp20
Rp21
ag3
(g7
S'#\xb2w?'
p22
tp23
Rp24
ag3
(g7
S' \x12w?'
p25
tp26
Rp27
ag3
(g7
S'\xd8?w?'
p28
tp29
Rp30
ag3
(g7
S'\x93\rx?'
p31
tp32
Rp33
ag3
(g7
S'\xe8\xc8r?'
p34
tp35
Rp36
ag3
(g7
S'X[{?'