FFT used in the Tensorflow Time Series tutorial

I am following the tutorial about Time Series from the official documentation of Tensorflow (Time series forecasting  |  TensorFlow Core)

Very early in the tutorial they transform the datetime to Sine and Cosine signals to help train the model. This signals are created using the number of seconds in a day and year. They then explain that it can be checked using a FFT function. In the graph that is generated there are clear peaks on “1/year” and “1/day”. I guess this is the reason they used this timelapses to create the Sine and Cosine columns.

In a classic FFT, the Y axis usually represents the amplitude of a sound, for instance. My question relies on what this stands for in terms of time and why the peaks are the values chosen for the sine and cosine columns.

@markdaoust do you know about this?

Yes. I wrote this.

I’m no meterologist. But we all naturally expect the weather to act differently depending on the time of day, and the time of year.

The sine and cos signals I pass to the model are just a convenient and smooth way to tell it the time of day and time of year.

But even more simply, we also expect there to be some periodicity at 1/day and 1/year (the sun is important). A linear model with just those two sine and cos features will be able to account for that periodicity.

One way to think of the FFT is as the linear model weights for the sine and cos across every frequency. In this special case (orthonormal functions) the weights are the portion of the variance contained in the signal at each frequency.

You could use any sin/cos frequencies as input, but those two frequencies are good choices since that’s where a lot of the variance is.

2 Likes

Thank you for your explanation, I know understand the meaning behind the FFT shown in the tutorial.

I have one further question related to the tutorial. On all the single shot models this layer is added to the model:

tf.keras.layers.Dense(OUT_STEPS*num_features, kernel_initializer=tf.initializers.zeros())                    ,

My question is about the reasoning behind “OUT_STEPS*num_features” as the way to set the number of units for the layer. Is it necessary to set a number equal to product between the label width and the number of features, is it a good practice or is it just an example? I am currently trying to edit and play around with the layers and I don’t know if that has to be mantained or I can put the number of units I want.

Thank you

IIRC that’s just there is case you want to generate more than one output time, like the 3 next steps or something.

2 Likes

Thanks. I am currently using your tutorial as part of my end of university project. It has been really helpful and I would like to reference the tutorial in the written part of the project. Should I write your name as author of the tutorial or should I leave it as “Tensorflow Team”? I am currently using APA format for references and bibliography.

I leave it as “Tensorflow Team”?

Yes. I added the FFT part, but many people have contributed to this file over the years.

2 Likes