# This function creates as many time series as requested (via the batch_size argument),
# each of length n_steps, and there is just one value per time step in each series
# (i.e., all series are univariate)
def generate_time_series(batch_size, n_steps):
freq1, freq2, offsets1, offsets2 = np.random.rand(4, batch_size, 1)
# The linspace() function returns evenly spaced numbers over a specified interval
time = np.linspace(0, 1, n_steps)
series = 0.5 * np.sin((time - offsets1) * (freq1 * 10 + 10)) # wave 1
series += 0.2 * np.sin((time - offsets2) * (freq2 * 20 + 20)) # + wave 2
series += 0.1 * (np.random.rand(batch_size, n_steps) - 0.5) # + noise
# The function returns a NumPy array of shape [batch size, time steps, 1],
# where each series is the sum of two sine waves of fixed amplitudes but
# random frequencies and phases, plus a bit of noise
return series[..., np.newaxis].astype(np.float32)
The last layer is not ideal as it must have a single unit because we want to forecast a univariate time series, and this means we must have a single output value per time step. However, having a single unit means that the hidden state is just a single number which is not much useful.
Also, since a SimpleRNN layer uses the tanh activation function by default, the predicted values must lie within the range –1 to 1. But what if you want to use another activation function? Hope this explains why it is not much useful.
I understood the "activation function" reason. But can you please ellaorate on "hidden state is just a single number which is not much useful" ? Do you mean it won't be useful when we are dealing with multi-variate output?
This may be because you may have opened them but didn't code anything. The notebooks in which you coded in the guided projects will be on the cloudxlab_jupyter_notebooks folder.
Please login to comment
11 Comments
# This function creates as many time series as requested (via the batch_size argument),
# each of length n_steps, and there is just one value per time step in each series
# (i.e., all series are univariate)
def generate_time_series(batch_size, n_steps):
freq1, freq2, offsets1, offsets2 = np.random.rand(4, batch_size, 1)
# The linspace() function returns evenly spaced numbers over a specified interval
time = np.linspace(0, 1, n_steps)
series = 0.5 * np.sin((time - offsets1) * (freq1 * 10 + 10)) # wave 1
series += 0.2 * np.sin((time - offsets2) * (freq2 * 20 + 20)) # + wave 2
series += 0.1 * (np.random.rand(batch_size, n_steps) - 0.5) # + noise
# The function returns a NumPy array of shape [batch size, time steps, 1],
# where each series is the sum of two sine waves of fixed amplitudes but
# random frequencies and phases, plus a bit of noise
return series[..., np.newaxis].astype(np.float32)
Please make me understand this function
Upvote Sharei understood
Upvote Sharemy lab account has only two directories one that I created and the other is cloudxlab_jupyter_notebooks
Upvote ShareI dont see the notebok file used in the video in my lab account
Upvote ShareHi, you can see the notebook at https://github.com/cloudxlab/iitr-deep-learning-spl-tf2/blob/master/processing_sequences_using_rnn_cnns/processing_sequences_using_rnns_and_cnns.ipynb
Upvote ShareHi, I didn't understand why the last layer is not ideal. Can you please ellaborate? slide 59.
Upvote ShareHi,
The last layer is not ideal as it must have a single unit because we want to forecast a univariate time series, and this means we must have a single output value per time step. However, having a single unit means that the hidden state is just a single number which is not much useful.
Also, since a SimpleRNN layer uses the tanh activation function by default, the predicted values must lie within the range –1 to 1. But what if you want to use another activation function? Hope this explains why it is not much useful.
Thanks.
Upvote ShareI understood the "activation function" reason. But can you please ellaorate on "hidden state is just a single number which is not much useful" ? Do you mean it won't be useful when we are dealing with multi-variate output?
Upvote ShareHi,
Multi-variable itself means multiple numbers. So it will not be much useful having a single unit.
Thanks.
1 Upvote ShareI am finding some notebooks as empty on my jupyter lab.What to do?
Upvote ShareHi,
This may be because you may have opened them but didn't code anything. The notebooks in which you coded in the guided projects will be on the cloudxlab_jupyter_notebooks folder.
Thanks.
Upvote Share