Now you might be curious how a linear model like linear regression is able to perfectly forecast the
sine wave which is clearly non-linear.
For those of you who are interested I'd like to share with you the derivation since I find this pretty
interesting myself.
If you are not interested you can consider this optional so don't feel like you have to understand this
in order to understand the rest of the course.
It turns out that it's possible to predict a sine wave perfectly using only two pass values of the time
series.
We call this an R2 model.
Notice we do not even need a biased term so let's see how this might be true.
First note that if you want to write a time series which is a function of time in a mathematical form
it looks like this.
So x of T equals the sign of Omega times t and the s the letter inside the sign is Omega and not w the
lowercase Omega just happens to look a lot like a W.
Now if you recall we actually did something very similar to this when we created the data we said a
series is equal to and put out sign of zero point one times and put out a range of two hundred so NPR
got a range of two hundred it represents all the time points and zero point one was the angular frequency
surprisingly.
This is all we need to show that our R2 model can learn a sine wave.
Let's just plug in the sine wave function into our recurrence relation.
By the way recurrence relation is just a fancy way of describing the auto regressive model.
The Fibonacci equation is also an example of a recurrence relation.
In fact it has the exact same form as our R2 model with weights of 1 for this derivation.
It's actually more convenient to shift the time steps up by 1.
So instead of predicting x of T using X T minus 1 and X T minus 2 will predict x of T plus 1 using x
of T and X T minus 1.
The next step is to multiply out the terms inside of the sine functions.
This still may not look like much but let's keep going.
The key here is to remember all the way back to your high school math where you learned about trigonometric
identities.
Now don't worry I've forgotten these as well.
These are not the type of thing you're using your day to day machine learning work so don't be too sad.
The important identity is this one.
It's the sign of a plus b plus the sign of a minus B equals two coast B sign a.
Let's see why.
First we can manipulate our sign I'll make a t equation by bringing the W term to the left hand side.
So now we have sign of a mega T plus Omega minus W2 times sine of omega T minus Omega equals w one time
sign of omega T.
Now here's the main trick we have to recognize that both of these equations have the same format.
If we look inside the sine terms we see that omega T is just a and Omega is just B immediately.
This helps us figure out the constants w 1 and W2.
We can already see that W2 must equal minus 1.
This also means that w 1 is equal to 2 cost B which is equal to 2 cos Omega.
Thus we prove that we can represent the sine wave as a recurrence relation.