4 "cell_type": "markdown",
5 "id": "881b3085-13b7-420e-9fc5-1d51778a8933",
8 "# Tensorboard Setup\n",
10 "https://www.tensorflow.org/tensorboard/get_started\n",
12 "Run all code cells below, then run on console:\n",
14 "`tensorboard --logdir logs/train`"
19 "execution_count": null,
20 "id": "730eaef2-51b5-4596-9454-2c0ef3706b86",
26 "sys.path.append(\"..\")"
31 "execution_count": null,
32 "id": "4916811f-67b8-4abd-b38e-7f0645dd56f6",
37 "import reproducibility\n",
39 "# both can change\n",
41 "import numpy as np\n",
42 "import pandas as pd\n",
43 "import tensorflow as tf\n",
44 "from keras.models import Sequential\n",
45 "from keras.layers import Dense, SimpleRNN\n",
46 "# from keras.utils.vis_utils import plot_model\n",
47 "from keras.utils import plot_model\n",
49 "from sklearn.preprocessing import MinMaxScaler\n",
50 "from sklearn.metrics import mean_squared_error\n",
53 "import matplotlib.pyplot as plt\n",
54 "import tensorflow as tf\n",
55 "import keras.backend as K\n",
56 "# from keras.utils.vis_utils import plot_model\n",
57 "from scipy.interpolate import LinearNDInterpolator, interpn\n",
58 "from scipy.optimize import root\n",
59 "import pickle, os\n",
60 "from utils import hash2\n",
61 "%matplotlib inline\n",
63 "# Local modules for handling data and running moisture models\n",
64 "import data_funcs as datf\n",
65 "from data_funcs import format_raws, retrieve_raws, format_precip, fixnan, load_and_fix_data\n",
66 "from data_funcs import raws_data, synthetic_data, plot_data, check_data, rmse_data, to_json, from_json\n",
67 "import moisture_models as mod\n",
68 "from moisture_rnn import run_case, run_rnn, create_RNN_2, staircase, create_rnn_data, train_rnn, rnn_predict\n"
73 "execution_count": null,
74 "id": "e49a4c0a-78d0-4a7e-a39e-012a882d78e8",
79 "# Change directory for data read/write\n",
81 "dict_file='../data/raws_CO_202306.pickle' # input path of FMDA dictionaries\n",
82 "reproducibility_file='../data/reproducibility_dict.pickle'\n",
84 "# read test datasets\n",
86 "test_dict.update(load_and_fix_data(dict_file))\n",
87 "print(test_dict.keys())\n",
90 "repro_dict.update(load_and_fix_data(reproducibility_file))\n",
91 "print(repro_dict.keys())"
96 "execution_count": null,
97 "id": "bc72419b-a2fa-4e54-addd-5778785d387b",
101 "# Build Case Data\n",
102 "id = \"CPTC2_202306010000\"\n",
103 "case_data=test_dict[id]\n",
104 "case_data[\"hours\"]=len(case_data['fm'])\n",
105 "case_data[\"h2\"]=int(24*20)"
110 "execution_count": null,
111 "id": "968595b9-905d-4fec-81f8-6a50aee6d0e2",
115 "# Linear Activation Params\n",
117 " 'purpose':'test 1',\n",
119 " 'scale':1, # every feature in [0, scale]\n",
120 " 'rain_do':True,\n",
121 " 'verbose':False,\n",
123 " 'activation':['linear','linear'],\n",
124 " 'hidden_units':1, \n",
125 " 'dense_units':1, # do not change\n",
126 " 'dense_layers':1, # do not change\n",
127 " 'centering':[0.0,0.0], # should be activation at 0\n",
128 " 'DeltaE':[0,-1], # bias correction\n",
129 " 'synthetic':False, # run also synthetic cases\n",
130 " 'T1': 0.1, # 1/fuel class (10)\n",
131 " 'fm_raise_vs_rain': 2.0, # fm increase per mm rain \n",
132 " 'train_frac':0.5, # time fraction to spend on training\n",
134 " 'verbose_fit':False,\n",
135 " 'verbose_weights':False,\n",
141 "execution_count": null,
142 "id": "c38ee016-a418-456f-ab10-5cbe9ec0d7c3",
147 "log_dir = \"logs\"\n",
148 "tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)"
153 "execution_count": null,
154 "id": "9fb46a3c-0dbd-42da-87c7-8db947a53ae5",
158 "reproducibility.set_seed() # Set seed for reproducibility\n",
159 "rnn_dat = create_rnn_data(case_data,params)\n",
160 "model1 = train_rnn(\n",
163 " rnn_dat['hours'],\n",
165 " callbacks = [tensorboard_callback]\n",
167 "case_data['m'] = rnn_predict(model1, params, rnn_dat)\n",
168 "fit_linear = case_data['m']"
173 "execution_count": null,
174 "id": "a4335a23-6fab-4782-8b74-a282a5b9ab81",
178 "plot_data(case_data,title2='Trained RNN Linear')"
182 "cell_type": "markdown",
183 "id": "565e04ce-87d7-401d-81c8-d00941263d52",
190 "display_name": "Python 3 (ipykernel)",
191 "language": "python",
199 "file_extension": ".py",
200 "mimetype": "text/x-python",
202 "nbconvert_exporter": "python",
203 "pygments_lexer": "ipython3",