1
00:00:11,870 --> 00:00:18,350
Now you might be curious how a linear model like linear regression is able to perfectly forecast the

2
00:00:18,350 --> 00:00:21,290
sine wave which is clearly non-linear.

3
00:00:21,290 --> 00:00:26,180
For those of you who are interested I'd like to share with you the derivation since I find this pretty

4
00:00:26,180 --> 00:00:27,850
interesting myself.

5
00:00:28,070 --> 00:00:33,290
If you are not interested you can consider this optional so don't feel like you have to understand this

6
00:00:33,590 --> 00:00:40,820
in order to understand the rest of the course.

7
00:00:40,870 --> 00:00:47,260
It turns out that it's possible to predict a sine wave perfectly using only two pass values of the time

8
00:00:47,260 --> 00:00:48,290
series.

9
00:00:48,400 --> 00:00:51,200
We call this an R2 model.

10
00:00:51,220 --> 00:00:55,750
Notice we do not even need a biased term so let's see how this might be true.

11
00:01:00,940 --> 00:01:06,520
First note that if you want to write a time series which is a function of time in a mathematical form

12
00:01:06,640 --> 00:01:07,660
it looks like this.

13
00:01:08,110 --> 00:01:16,060
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

14
00:01:16,060 --> 00:01:18,750
lowercase Omega just happens to look a lot like a W.

15
00:01:19,780 --> 00:01:25,150
Now if you recall we actually did something very similar to this when we created the data we said a

16
00:01:25,150 --> 00:01:32,330
series is equal to and put out sign of zero point one times and put out a range of two hundred so NPR

17
00:01:32,330 --> 00:01:38,110
got a range of two hundred it represents all the time points and zero point one was the angular frequency

18
00:01:43,280 --> 00:01:44,080
surprisingly.

19
00:01:44,090 --> 00:01:48,070
This is all we need to show that our R2 model can learn a sine wave.

20
00:01:49,010 --> 00:01:53,660
Let's just plug in the sine wave function into our recurrence relation.

21
00:01:53,660 --> 00:01:58,940
By the way recurrence relation is just a fancy way of describing the auto regressive model.

22
00:01:58,940 --> 00:02:03,260
The Fibonacci equation is also an example of a recurrence relation.

23
00:02:03,290 --> 00:02:10,800
In fact it has the exact same form as our R2 model with weights of 1 for this derivation.

24
00:02:10,800 --> 00:02:14,320
It's actually more convenient to shift the time steps up by 1.

25
00:02:14,490 --> 00:02:22,080
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

26
00:02:22,080 --> 00:02:29,020
of T and X T minus 1.

27
00:02:29,040 --> 00:02:33,680
The next step is to multiply out the terms inside of the sine functions.

28
00:02:33,690 --> 00:02:41,180
This still may not look like much but let's keep going.

29
00:02:41,290 --> 00:02:46,840
The key here is to remember all the way back to your high school math where you learned about trigonometric

30
00:02:46,840 --> 00:02:48,250
identities.

31
00:02:48,250 --> 00:02:50,710
Now don't worry I've forgotten these as well.

32
00:02:50,740 --> 00:02:56,180
These are not the type of thing you're using your day to day machine learning work so don't be too sad.

33
00:02:56,200 --> 00:02:58,480
The important identity is this one.

34
00:02:58,720 --> 00:03:05,780
It's the sign of a plus b plus the sign of a minus B equals two coast B sign a.

35
00:03:06,130 --> 00:03:11,820
Let's see why.

36
00:03:11,890 --> 00:03:17,920
First we can manipulate our sign I'll make a t equation by bringing the W term to the left hand side.

37
00:03:18,460 --> 00:03:27,670
So now we have sign of a mega T plus Omega minus W2 times sine of omega T minus Omega equals w one time

38
00:03:27,670 --> 00:03:28,680
sign of omega T.

39
00:03:33,820 --> 00:03:40,210
Now here's the main trick we have to recognize that both of these equations have the same format.

40
00:03:40,270 --> 00:03:48,130
If we look inside the sine terms we see that omega T is just a and Omega is just B immediately.

41
00:03:48,130 --> 00:03:51,550
This helps us figure out the constants w 1 and W2.

42
00:03:51,610 --> 00:03:55,780
We can already see that W2 must equal minus 1.

43
00:03:55,780 --> 00:04:02,310
This also means that w 1 is equal to 2 cost B which is equal to 2 cos Omega.

44
00:04:02,560 --> 00:04:07,530
Thus we prove that we can represent the sine wave as a recurrence relation.
