5 "execution_count": null,
6 "id": "2106ddc4-8330-44ca-8a69-742f53796740",
11 "sys.path.append(\"..\")\n",
12 "import reproducibility\n",
13 "import pandas as pd\n",
14 "from data_funcs import load_and_fix_data\n",
15 "from moisture_rnn import create_RNN_2, create_rnn_data_1, create_rnn_data_2, train_rnn"
20 "execution_count": null,
21 "id": "f5b25c8a-e879-4d3f-b144-ae7876aa70c3",
25 "reproducibility_file='../data/reproducibility_dict.pickle'\n",
26 "repro=load_and_fix_data(reproducibility_file)"
31 "execution_count": null,
32 "id": "af32b30f-ad9c-44a2-9586-3012ba0450f5",
36 "from module_param_sets import param_sets"
41 "execution_count": null,
42 "id": "4a5a4137-2c9b-4fd9-8ad0-00b773ee99cd",
46 "params = param_sets['0']"
51 "execution_count": null,
52 "id": "b93faa27-c0f8-46cb-9084-7405f93470ea",
56 "# Simplify params\n",
57 "params['batch_size']=3\n",
58 "params[\"timesteps\"]=2\n",
59 "params[\"epochs\"]=1\n",
60 "params[\"initialize\"]=False\n",
61 "params[\"hidden_units\"]=1\n",
62 "params[\"rain_do\"]=False\n",
68 "execution_count": null,
69 "id": "0be61c7d-59c4-4b3c-afec-6393a9289439",
74 "case_data = repro[\"case11\"]\n",
76 "reproducibility.set_seed() # Set seed for reproducibility\n",
77 "rnn_dat = create_rnn_data_1(case_data,params)\n",
78 "create_rnn_data_2(rnn_dat,params)"
83 "execution_count": null,
84 "id": "d1ced401-0b81-4404-b8dd-3bbb756be244",
88 "features = rnn_dat[\"X\"].shape[1]\n",
94 "execution_count": null,
95 "id": "26d61ce5-f492-4d20-88d8-f5bbd41f31a4",
100 "reproducibility.set_seed()\n",
101 "model = create_RNN_2(\n",
102 " hidden_units=params[\"hidden_units\"], \n",
103 " dense_units=1, \n",
104 " activation=params[\"activation\"],\n",
105 " batch_shape=(params[\"batch_size\"],params[\"timesteps\"],features),\n",
108 "# Print initial weights\n",
109 "model.get_weights()"
114 "execution_count": null,
115 "id": "bca3b758-dde0-491b-9566-4a868f45286c",
119 "# Run a sample through\n",
120 "X = rnn_dat[\"x_train\"][0,:,:].reshape(-1,params[\"timesteps\"],features)\n",
126 "execution_count": null,
127 "id": "0e8b055c-426e-430c-ace8-87ea482876c7",
131 "preds = model.predict(X)\n",
137 "execution_count": null,
138 "id": "fa267c9b-e76f-46c7-a10a-d3434c913aaa",
142 "y = rnn_dat[\"y_train\"][0].reshape(-1, 1)"
147 "execution_count": null,
148 "id": "9d11f8c4-d8c9-4665-8c93-6fd887b864d7",
158 "execution_count": null,
159 "id": "d6b9b56e-52b7-4636-a524-ab310c059fe7",
163 "# Use loss calculation from before to manually update weights\n",
169 "execution_count": null,
170 "id": "c3c47f67-52a2-4c13-ac5b-d1fc0de077bd",
174 "model.optimizer.learning_rate.value"
179 "execution_count": null,
180 "id": "d373fa86-2dc8-4a80-8882-cacc0db281c6",
184 "reproducibility.set_seed()\n",
185 "history = model.fit(X, \n",
187 " epochs=params[\"epochs\"], \n",
188 " batch_size=params[\"batch_size\"])"
193 "execution_count": null,
194 "id": "34bfa036-dbed-4fe9-a4cb-9e90b2de9185",
203 "execution_count": null,
204 "id": "ceac8930-bcc5-4a06-b929-7c5c943d6581",
208 "# Print Trained Weights\n",
209 "model.get_weights()"
214 "execution_count": null,
215 "id": "3624a803-a45b-4314-b3d9-6628b1d2161b",
223 "display_name": "Python 3 (ipykernel)",
224 "language": "python",
232 "file_extension": ".py",
233 "mimetype": "text/x-python",
235 "nbconvert_exporter": "python",
236 "pygments_lexer": "ipython3",