|
9 | 9 | },
|
10 | 10 | {
|
11 | 11 | "cell_type": "code",
|
12 |
| - "execution_count": 33, |
| 12 | + "execution_count": 5, |
13 | 13 | "metadata": {},
|
14 | 14 | "outputs": [],
|
15 | 15 | "source": [
|
16 | 16 | "import numpy as np\n",
|
17 | 17 | "import os\n",
|
18 | 18 | "import csv\n",
|
19 |
| - "import matplotlib.pyplot as plt" |
| 19 | + "import matplotlib.pyplot as plt\n", |
| 20 | + "import pandas as pd" |
20 | 21 | ]
|
21 | 22 | },
|
22 | 23 | {
|
|
240 | 241 | " writer.writerow(row) \n"
|
241 | 242 | ]
|
242 | 243 | },
|
| 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 | + }, |
243 | 294 | {
|
244 | 295 | "cell_type": "code",
|
245 | 296 | "execution_count": null,
|
|
264 | 315 | "name": "python",
|
265 | 316 | "nbconvert_exporter": "python",
|
266 | 317 | "pygments_lexer": "ipython3",
|
267 |
| - "version": "3.6.7" |
| 318 | + "version": "3.6.8" |
268 | 319 | }
|
269 | 320 | },
|
270 | 321 | "nbformat": 4,
|
|
0 commit comments