Part 12 (5 points, coding task)
After building our deep neural network architecture in Part 11 and before using it to train our model, we need to prepare our training dataset.
Let us look at a simple application of deep neural network in studying harmonic motion in physics.
Write code to construct the following training dataset:
-
Use
sample_size
to store the number of samples. Set the value as 1000. -
Define
x_train
as a tensor whose shape is(sample_size,)
and the value on each entry is uniformly drawn between 0 and 1. -
Define
y_train
as a tensor whose values are obtained from the following element-wise mapping fromx_train
:y = \sin \left( 2 \pi x \right) + 0.1 \cdot \mathcal N \left( 0, 1 \right) ,where \mathcal N \left( 0, 1 \right) is a standard normal random variable.
-
Print the dimensions of
x_train
andy_train
. -
Print the shapes of
x_train
andy_train
.