iui-group-l-name-zensiert/1-first-project/ies/Tensor.ipynb

386 lines
9.9 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "42f984d5",
"metadata": {},
"outputs": [],
"source": [
"# import os\n",
"# os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'\n",
"# os.environ['CUDA_VISIBLE_DEVICES'] = '2'\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "ec63028f",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import tensorflow as tf\n",
"import matplotlib.pyplot as plt\n",
"from math import isqrt\n",
"import pickle\n",
"from tqdm import tqdm\n",
"delim = ';'\n",
"\n",
"user_count = 100\n",
"base_path = '/opt/iui-datarelease1-sose2021/'\n",
"Xpickle_file = './X.pickle'\n",
"ypickle_file = './y.pickle'"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "dc9ddde3",
"metadata": {},
"outputs": [],
"source": [
"def load_pickles():\n",
" _p = open(Xpickle_file, 'rb')\n",
" X = pickle.load(_p)\n",
" _p.close()\n",
" \n",
" _p = open(ypickle_file, 'rb')\n",
" y = pickle.load(_p)\n",
" _p.close()\n",
" \n",
" return (np.asarray(X, dtype=pd.DataFrame), np.asarray(y, dtype=str))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "e99c1e58",
"metadata": {},
"outputs": [],
"source": [
"x,y = load_pickles()\n",
"xshorted_pickle_file = './X_shorted.pickle'"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "7138aeeb",
"metadata": {},
"outputs": [],
"source": [
"\n",
"# yshorted_pickle_file = \"./y_shorted.pickle\" wird glaube ich nicht benötigt"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "abba0b88",
"metadata": {},
"outputs": [],
"source": [
"def shorten(l):\n",
" temp = l\n",
" thresh = 100\n",
" temp_over_T = 0\n",
" isOver = False\n",
" temp_short = []\n",
" temp_final = []\n",
" \n",
" for a in range (0, len(temp) ):\n",
" if(temp[a]>thresh):\n",
" temp_over_T = a\n",
" isOver = True\n",
" break\n",
" \n",
" for x in range(temp_over_T-3, len(temp)):\n",
" temp_short.append(f[x])\n",
" \n",
" isOver = False\n",
" \n",
" for y in range ((len(temp_short)-1),0, -1): \n",
" if(temp_short[y] > thresh):\n",
" temp_over_T = y\n",
" isOver = True\n",
" break\n",
" \n",
" for z in range(0, temp_over_T+1):\n",
" temp_final.append(temp_short[z])\n",
" \n",
" temp_final.append(0)\n",
" return temp_final"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d06fb083",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 7,
"id": "557f0030",
"metadata": {},
"outputs": [],
"source": [
"\n",
"def save_shorted(l):\n",
" _p = open(xshorted_pickle_file, 'wb')\n",
" pickle.dump(l, _p)\n",
" _p.close()\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "7dcb89ad",
"metadata": {},
"outputs": [],
"source": [
"def shorten_pickle(l):\n",
" temp = l\n",
" thresh = 100\n",
" temp_over_T = 0\n",
" isOver = False\n",
" temp_short = [] ##Daten nachdem vorne abgeschnitten wird\n",
" temp_final = [] ##Daten nachdem auch hinten abgeschnitten wurde\n",
" \n",
" temp_X = [] ## Zweite Dimension von Temp, beinhaltet force \n",
" temp_short_X = []\n",
" \n",
" for a in tqdm(range (0, len(temp))): \n",
" temp_X = temp[a] \n",
" \n",
" \n",
"# for b in range (0, len(temp_X)): \n",
"# if(temp_X[b]>thresh):\n",
"# temp_over_T = b\n",
"# isOver = True ##gucken ob löschen\n",
"# break\n",
" \n",
" \n",
"# for x in range (temp_over_T,len(temp_X)):\n",
"# temp_short_X.append(temp_X[x]) ##hier werden die Daten von y appended in eine liste ( Von form data[x][y])\n",
" \n",
"# isOver = False\n",
" \n",
"# for y in range ((len(temp_short_X)-1),0, -1): \n",
"# if(temp_short_X[y] > thresh):\n",
"# temp_over_T = y\n",
"# isOver = True\n",
"# break\n",
" \n",
"# for z in range(0, temp_over_T+1):\n",
"# temp_short.append(temp_short_X[z]) ##hier wird [y] als einzelne Datei gespeichert\n",
" \n",
"# temp_short.append(0) # Damit beim Plot die linie bis nach unten geht\n",
" \n",
" \n",
"# temp_final.append(temp_short)\n",
"# temp_final = shorten_v2()\n",
" \n",
" \n",
" \n",
" return temp_final\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "537d751b",
"metadata": {},
"outputs": [],
"source": [
"# shorted_f = shorten_pickle(f_data)\n",
" \n",
"# print(shorted_f[0])\n",
"# print (\"Saving now...\")\n",
"# save_shorted(shorted_f)\n",
"\n",
"# print (\"Saving complete\")\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "a23e6a6a",
"metadata": {},
"outputs": [],
"source": [
"def load_shorted():\n",
" _p = open(xshorted_pickle_file, 'rb')\n",
" x = pickle.load(_p)\n",
" _p.close()\n",
" \n",
" \n",
" print(\"done\")\n",
" return (np.asarray(x, dtype=pd.DataFrame))"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "8b41532e",
"metadata": {},
"outputs": [],
"source": [
"# %%time\n",
"# frame = load_shorted()\n",
"# print (\"returned\")\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "4db9e8f5",
"metadata": {},
"outputs": [],
"source": [
"def shorten_v2(l):\n",
" \n",
" \n",
" temp_X = l['Force']\n",
" thresh = 100\n",
" temp_over_T = 0\n",
" \n",
" temp_short = [] ##Daten nachdem vorne abgeschnitten wird\n",
" temp_final = [] ##Daten nachdem auch hinten abgeschnitten wurde\n",
" temp_short_X = []\n",
" \n",
" \n",
" \n",
" for b in range (0, len(temp_X)): \n",
" if(temp_X[b]>thresh):\n",
" temp_over_T = b\n",
" break\n",
" \n",
" for x in range (temp_over_T,len(temp_X)):\n",
" temp_short_X.append(temp_X[x]) ##hier werden die Daten von y appended in eine liste ( Von form data[x][y])\n",
" \n",
" \n",
" for y in range ((len(temp_short_X)-1),0, -1): \n",
" if(temp_short_X[y] > thresh):\n",
" temp_over_T = y\n",
" break\n",
" \n",
" for z in range(0, temp_over_T+1):\n",
" temp_short.append(temp_short_X[z]) ##hier wird [y] als einzelne Datei gespeichert\n",
" \n",
" temp_short.append(0) # Damit beim Plot die linie bis nach unten geht\n",
" \n",
" \n",
" temp_final.append(temp_short)\n",
" \n",
" return temp_final\n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "99c61605",
"metadata": {},
"outputs": [],
"source": [
"data = list(map(shorten_v2, x))\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "bd7aff75",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[list([108.0, 362.0, 683.0, 994.0, 1306.0, 1380.0, 1526.0, 1724.0, 1895.0, 1985.0, 2077.0, 2040.0, 1997.0, 1917.0, 1623.0, 1357.0, 1087.0, 785.0, 450.0, 146.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 67.0, 615.0, 927.0, 1212.0, 1450.0, 1483.0, 1546.0, 1634.0, 1617.0, 1691.0, 1654.0, 1663.0, 1618.0, 1550.0, 1519.0, 1519.0, 1742.0, 1892.0, 1966.0, 1966.0, 2092.0, 2040.0, 2048.0, 1997.0, 1953.0, 1946.0, 1926.0, 1791.0, 1497.0, 1112.0, 678.0, 279.0, 0])]\n",
"----------------------\n",
"[list([656.0, 729.0, 1036.0, 1253.0, 1465.0, 1662.0, 1707.0, 1730.0, 1897.0, 1890.0, 1885.0, 1856.0, 1833.0, 1789.0, 1746.0, 1752.0, 1766.0, 1799.0, 1780.0, 1759.0, 1743.0, 1732.0, 1735.0, 1824.0, 1788.0, 1737.0, 1637.0, 1547.0, 1443.0, 1199.0, 862.0, 400.0, 127.0, 0])]\n"
]
}
],
"source": [
"data = np.asarray(data)\n",
"#data.shape\n",
"print(data[0])\n",
"print (\"----------------------\")\n",
"print(data[len(data)-1])"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "f57350ff",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(13102, 1)"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"data.shape"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "78157f79",
"metadata": {},
"outputs": [],
"source": [
"save_shorted(data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ec8f2fea",
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}