Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jmduarte committed May 2, 2024
1 parent c14b4f2 commit e0048dd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 29 deletions.
36 changes: 12 additions & 24 deletions homeworks/homework_3/homework_3.tex
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
Machine Learning in Physics \hfill
UCSD PHYS 139/239 \hfill \\[1pt]
Homework 3\hfill
Draft version due: Friday, February 17, 2023, 5:00pm\\
Due: Friday, May 10, 2024, 8:00pm\\
\hfill
Final version due: Wednesday, February 22, 2023, 5:00pm\\
Corrections due: Wednesday, May 15, 2024, 8:00pm\\
}
}
}
Expand All @@ -21,23 +21,13 @@

\section*{Policies}

\section*{Policies}
\begin{itemize}
\item Draft version due 5:00pm, Friday, February 17 on Gradescope (report and code).
\item Final version due 5:00pm, Wednesday, February 22 on Gradescope (report and code).
\item You are free to collaborate on all of the problems, subject to the collaboration policy stated in the syllabus.
\item You should submit all code used in the homework.
Please use Python 3 and sklearn version $\geq$0.18 for your code, and that you comment your code such that the TA can follow along and run it without any issues.
\end{itemize}

\section*{Submission Instructions}
\textbf{PLEASE NOTE} that there are two steps to submitting your Homework.
Both must be submitted by the deadline.

\begin{itemize}
\item Please submit your report as a single .pdf file to Gradescope under ``Homework 3 Report Draft" or ``Homework 3 Report Final".
\item Please submit your report as a single .pdf file to Gradescope under ``Homework 3" or ``Homework 3 Corrections".
\textbf{In the report, include any images generated by your code along with your answers to the questions.}
For instructions specifically pertaining to the Gradescope submission process, see \url{https://www.gradescope.com/get_started#student-submission}.
\item Please submit your code as a .zip archive to Gradescope under ``Homework 3 Code Draft'' or ``Homework 3 Code Final".
\item Please submit your code as a .zip archive to Gradescope under ``Homework 3 Code'' or ``Homework 3 Code Corrections".
The .zip file should contain your code files.
Submit your code either as Jupyter notebook .ipynb files or .py files.
\end{itemize}
Expand Down Expand Up @@ -82,22 +72,20 @@ \section{GitHub [20 Points]}
\end{problem}

\section{RNNs vs. CNNs for Time Series [40 points]}
\materials{lectures 9 and 10}
% \materials{lectures 9 and 10}

This problem revisits the hands-on notebook \url{https://github.com/jmduarte/phys139_239/blob/main/notebooks/05_Time_Series_Data_RNN.ipynb}.
This problem uses the hands-on notebook \url{https://github.com/jmduarte/phys139_239/blob/main/notebooks/05_Time_Series_Data_RNN.ipynb}.
For this problem, we will use the full 50k traces, by setting
\begin{lstlisting}[language=python]
n_train = 40000
n_test = 10000
\end{lstlisting}
We will also use a slightly modified learning rate schedule:
\begin{lstlisting}[language=python]
ExponentialDecay(initial_learning_rate=1e-3, decay_steps=100, decay_rate=0.8)
\end{lstlisting}
We \emph{highly recommend} using the GPU-enabled DataHub with the latest \texttt{jmduarte/phys139_239:latest} image for this problem.
We \emph{highly recommend} using the GPU-enabled DataHub for this problem.
Note the training can be sped up by increasing the batch size to, e.g., 2048, but this requires tuning the learning rate and schedule to achieve the same performance.

\begin{problem}[15]
Replace the LSTM layers with bidirectional LSTM layers.
Replace the LSTM layers with bidirectional LSTM layers using the \texttt{layers.Bidirectional} wrapper function: \url{https://keras.io/api/layers/recurrent_layers/bidirectional/}.
Note for the first layer, the \texttt{input_shape} argument needs to be an input to the outer \texttt{layers.Bidirectional} wrapper function instead of the inner \texttt{layers.LSTM} function.
Set \texttt{verbose=1} in the \texttt{model.fit()} command to be able to see the output during training, \texttt{batch\_size=2048} to speed up the training, and \texttt{epochs=100} to train the model for (up to) 100 epochs.
How many trainable parameters does the model have?
How long does 1 epoch of training take (approximately)?
Expand All @@ -113,7 +101,7 @@ \section{RNNs vs. CNNs for Time Series [40 points]}
\end{problem}

\begin{problem}[10]
Purely from an accuracy/AUC perspective, which model performs better?
From an accuracy/AUC perspective, how do the two models compare?
Which model trains faster?
\end{problem}

Expand Down
9 changes: 4 additions & 5 deletions notebooks/05_Time_Series_Data_RNN.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
"id": "Bw8tkc1Xb54I"
},
"source": [
"#### Pre-processing of data and RNN training"
"#### RNN training"
]
},
{
Expand All @@ -221,13 +221,12 @@
"results = model.fit(\n",
" x_train[..., np.newaxis],\n",
" y_train,\n",
" batch_size=2048,\n",
" batch_size=256,\n",
" epochs=20,\n",
" verbose=0,\n",
" validation_split=0.1,\n",
" callbacks=[\n",
" keras.callbacks.ReduceLROnPlateau(factor=0.5, patience=5, verbose=0, min_lr=1e-5),\n",
" keras.callbacks.EarlyStopping(patience=15, verbose=0),\n",
" keras.callbacks.EarlyStopping(patience=15, verbose=0, restore_best_weights=True),\n",
" ],\n",
")"
]
Expand Down Expand Up @@ -286,7 +285,7 @@
"metadata": {},
"source": [
"## Exercises\n",
"1. Replace the LSTM layers with bidirectional LSTM layers: `layers.Bidirectional(layers.LSTM(...))`. How does the number of parameters of the model change? How does the performance change?\n",
"1. Replace the LSTM layers with bidirectional LSTM layers: `layers.Bidirectional(layers.LSTM(...))` (See https://keras.io/api/layers/recurrent_layers/bidirectional/). Note for the first layer, the `input_shape` argument needs to be an input to the outer `layers.Bidirectional` function instead of the inner `layers.LSTM` function. How does the number of parameters of the model change? How does the performance change?\n",
"2. Replace the LSTM layers with GRU layers. How does the number of parameters of the model change? How does the performance change?\n",
"3. Replace the LSTM layers with 1D convolutional layers `layers.Conv1D(...)` with the following parameters. How does the number of parameters of the model change? How does the performance change?\n",
" - `filters=32, kernel_size=5, strides=1, padding=\"same\", activation=\"relu\"` \n",
Expand Down

0 comments on commit e0048dd

Please sign in to comment.