Skip to content

Commit 259aaef

Browse files
author
Nikhil Babu
committed
Updated preprocessing to smooth rewards
1 parent f80d531 commit 259aaef

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

TMaze results preprocessing.ipynb

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
},
1010
{
1111
"cell_type": "code",
12-
"execution_count": 33,
12+
"execution_count": 5,
1313
"metadata": {},
1414
"outputs": [],
1515
"source": [
1616
"import numpy as np\n",
1717
"import os\n",
1818
"import csv\n",
19-
"import matplotlib.pyplot as plt"
19+
"import matplotlib.pyplot as plt\n",
20+
"import pandas as pd"
2021
]
2122
},
2223
{
@@ -240,6 +241,56 @@
240241
" writer.writerow(row) \n"
241242
]
242243
},
244+
{
245+
"cell_type": "code",
246+
"execution_count": 6,
247+
"metadata": {},
248+
"outputs": [],
249+
"source": [
250+
"def smooth(X, gamma = 0.9):\n",
251+
" \"\"\" Returns exponential moving average. \"\"\"\n",
252+
" y = np.mean(X[:500])\n",
253+
" out = []\n",
254+
" for x in X:\n",
255+
" y = gamma * y + (1-gamma) * x\n",
256+
" out.append(y)\n",
257+
" return out"
258+
]
259+
},
260+
{
261+
"cell_type": "code",
262+
"execution_count": 28,
263+
"metadata": {},
264+
"outputs": [],
265+
"source": [
266+
"def cleanData(filename):\n",
267+
" dataframe = pd.read_csv(filename)\n",
268+
" X = dataframe.iloc[:,1].values #reward column\n",
269+
" print(X)\n",
270+
" X = smooth(X,0.99)\n",
271+
" dataframe['smoothReward'] = X\n",
272+
" #x = dataframe.as_matrix(columns)\n",
273+
" #dataframe['smoothReward'] = dataframe['reward'].apply(lambda x: smooth(x,0.99))\n",
274+
" dataframe.to_csv(filename, index=False)"
275+
]
276+
},
277+
{
278+
"cell_type": "code",
279+
"execution_count": 29,
280+
"metadata": {},
281+
"outputs": [
282+
{
283+
"name": "stdout",
284+
"output_type": "stream",
285+
"text": [
286+
"[ -2.82 -23.29 -23.2 ... 3.8 3.8 3.9 ]\n"
287+
]
288+
}
289+
],
290+
"source": [
291+
"cleanData('rewards.csv')"
292+
]
293+
},
243294
{
244295
"cell_type": "code",
245296
"execution_count": null,
@@ -264,7 +315,7 @@
264315
"name": "python",
265316
"nbconvert_exporter": "python",
266317
"pygments_lexer": "ipython3",
267-
"version": "3.6.7"
318+
"version": "3.6.8"
268319
}
269320
},
270321
"nbformat": 4,

TMaze.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@
16221622
"name": "python",
16231623
"nbconvert_exporter": "python",
16241624
"pygments_lexer": "ipython3",
1625-
"version": "3.6.7"
1625+
"version": "3.6.8"
16261626
}
16271627
},
16281628
"nbformat": 4,

0 commit comments

Comments
 (0)