1
00:00:03,640 --> 00:00:08,020
In this video, we're going to have a look at different ways of how we can go about calculating the

2
00:00:08,020 --> 00:00:10,680
Giacobbe and matrixes that are required for the filter.

3
00:00:11,500 --> 00:00:18,340
So previously we have calculated the Jacoby Matrixes analytically from equations using differentiation,

4
00:00:18,520 --> 00:00:20,720
and we can see that this can be tedious.

5
00:00:21,040 --> 00:00:26,650
We take the process model, measurement model, and then we have to differentiate the model with respect

6
00:00:26,650 --> 00:00:30,210
to all the different inputs for the state, for the noise, for any inputs.

7
00:00:30,850 --> 00:00:34,760
And this can be quite complex for very nonlinear systems.

8
00:00:35,920 --> 00:00:39,190
There's also another way we can calculate the Jacobean matrix.

9
00:00:39,670 --> 00:00:44,860
It is possible to calculate this Jacobean matrix numerically straight from the model itself.

10
00:00:45,880 --> 00:00:52,630
And we can do this using numerical differentiation to get an idea of what numerical differentiation

11
00:00:52,630 --> 00:00:53,000
is.

12
00:00:53,290 --> 00:00:58,750
Imagine that we have a function F X and we want to differentiate the function with respect to X..

13
00:00:59,470 --> 00:01:06,160
So this is basically saying we want to look at how the function output f changes with changes in X and

14
00:01:06,160 --> 00:01:09,030
we can actually evaluate this using first principles.

15
00:01:09,430 --> 00:01:15,640
So using first principles, if we have the function F evaluated at our initial condition or where we

16
00:01:15,640 --> 00:01:22,060
want to, linear is a system about plus a little perturbed amount subtracted away from the function

17
00:01:22,060 --> 00:01:26,920
evaluated at the initial condition, divided up by the D x amount.

18
00:01:27,190 --> 00:01:29,000
We basically end up with this function here.

19
00:01:29,410 --> 00:01:37,120
So this function looks at how F changes with changes in X, so basically we perturb X by a little amount

20
00:01:37,120 --> 00:01:44,050
by the X and then we subtract off the initial condition so we get a change in our F and then we divide

21
00:01:44,050 --> 00:01:46,450
it by the amount that we changed X.

22
00:01:47,050 --> 00:01:52,020
And this is basically differentiation as the Delta X goes towards zero.

23
00:01:52,630 --> 00:01:59,020
But when we do this numerically, we apply a non a small non-zero value and then calculate these functions

24
00:01:59,020 --> 00:02:00,220
here and do the division.

25
00:02:00,700 --> 00:02:05,590
And this will give us a numerical approximation of the derivative of the function F.

26
00:02:07,880 --> 00:02:13,520
So we can actually have a look at this using some numbers, so let's say we have a function F X is equal

27
00:02:13,520 --> 00:02:15,600
to two X, so we put a one in here.

28
00:02:15,650 --> 00:02:17,440
It's going to give us to put a two.

29
00:02:17,450 --> 00:02:19,540
It's going to give us four and so forth.

30
00:02:19,550 --> 00:02:23,090
And we want to differentiate this function with respect to X..

31
00:02:24,320 --> 00:02:29,920
So what we want to do is that we can define Adella X, so let's define a small perturbed amount of point

32
00:02:29,990 --> 00:02:30,350
one.

33
00:02:30,800 --> 00:02:37,630
And we want to carry out this whole process around our initial condition of, say, X equals one.

34
00:02:38,000 --> 00:02:43,820
So we want to work out the derivative of this function around the value one.

35
00:02:44,540 --> 00:02:49,070
So what we can do is we can basically take these equations and these numbers, put them into this equation

36
00:02:49,070 --> 00:02:58,040
up here and evaluate it so we can substitute in if it's not plus Delta X, our function F X is just

37
00:02:58,040 --> 00:03:04,310
two X, so we get two times the X, which is one because we're evaluating it around one plus our total

38
00:03:04,310 --> 00:03:04,580
amount.

39
00:03:04,580 --> 00:03:07,900
D.T. sorry, Dex, giving us point one.

40
00:03:08,330 --> 00:03:16,120
So we get two times one plus point one and then we evaluate the function F at our initial condition.

41
00:03:16,130 --> 00:03:16,710
Excellent.

42
00:03:16,730 --> 00:03:24,650
So we put in our one into our two X, so this is our two XY and then we divide it by the perturbed amount

43
00:03:24,680 --> 00:03:25,850
which is point one.

44
00:03:26,880 --> 00:03:33,750
So they go through and do the calculation, we end up with their derivative equal to and if we know

45
00:03:33,900 --> 00:03:38,310
from numerical differentiation, if we differentiate this function here, the two X with respect to

46
00:03:38,310 --> 00:03:41,280
X, the X drops away, I mean, just off of two.

47
00:03:41,280 --> 00:03:45,990
So I can see that in this case, this is the numerical approximation of the derivative and it's going

48
00:03:45,990 --> 00:03:48,280
to be exactly equal to the real derivative.

49
00:03:49,350 --> 00:03:55,020
Now, this is a very benign example because the function to X is a linear system and finding the derivative

50
00:03:55,020 --> 00:03:55,730
is very simple.

51
00:03:56,190 --> 00:03:59,370
But this approximation holds for nonlinear systems as well.

52
00:04:03,040 --> 00:04:09,160
So then how can this process of numerical differentiation help us to numerically calculate the Jacobean?

53
00:04:10,450 --> 00:04:15,230
Well, let's say we give them a function Y is equal to F X you.

54
00:04:15,250 --> 00:04:17,530
So this is a function F and we have two inputs.

55
00:04:17,540 --> 00:04:22,660
We have an input X and an input you and we get an output of this whole function Y.

56
00:04:23,830 --> 00:04:31,630
As also say that the inputs X you and the output Y are also vector functions, so our X is an X vector.

57
00:04:31,660 --> 00:04:34,870
We have X states from one or way up to end.

58
00:04:35,410 --> 00:04:41,980
Our U vector is going to be a vector of all of you components from one to L, and the output is going

59
00:04:41,980 --> 00:04:43,840
to be output from one to M.

60
00:04:46,360 --> 00:04:48,190
So let's define some input's.

61
00:04:49,210 --> 00:04:55,660
So let's define X not being the initial condition that we want to calculate the UK about, so we store

62
00:04:55,690 --> 00:04:58,120
the initial value of the X Factor.

63
00:04:58,900 --> 00:05:05,760
Now we're going to define the X iveta, which is just the sum of the initial X Factor, plus this POTO

64
00:05:05,770 --> 00:05:13,060
factor here and this term vector is just going to have the element in this vector, the Delta X and

65
00:05:13,060 --> 00:05:14,970
all the other elements equal to zero.

66
00:05:15,340 --> 00:05:23,150
So it just means we have the vector which has the element of X not perturbed by an amount Delta X.

67
00:05:23,620 --> 00:05:25,390
So all this equation is showing here.

68
00:05:25,390 --> 00:05:33,370
If we evaluate our Delta X, J and J and I are equal to each other, we set the value to be Delta X,

69
00:05:33,370 --> 00:05:34,780
otherwise we will be zero.

70
00:05:35,230 --> 00:05:41,830
So if this was X1, then this vector over here is just going to be our Delta X because X1 is going to

71
00:05:41,830 --> 00:05:47,800
be equal to Delta X when I enjoy equal one and all the other times here going to be zero zero zero zero.

72
00:05:48,400 --> 00:05:54,550
Likewise, if this was X three, this vector over here is going to be zero zero dollars zero zero zero

73
00:05:54,550 --> 00:05:55,720
zero all the way up to X.

74
00:05:55,720 --> 00:06:04,720
And so this is just the probation of this vector X with the element perturbed by the value Delta X.

75
00:06:05,940 --> 00:06:09,280
We can go about and define the same thing for the year.

76
00:06:09,810 --> 00:06:12,350
So basically, since we have a function here, it takes two inputs.

77
00:06:12,360 --> 00:06:17,540
We have to define the initial condition or the linear ization point for both these inputs.

78
00:06:17,880 --> 00:06:20,160
And in this case is going to be our, you know.

79
00:06:21,320 --> 00:06:27,980
Now, we can also perturb the Uvalda in the same way, so basically we define our UI is just going to

80
00:06:27,980 --> 00:06:34,970
be our, you know, vector and then a perturbed vector, which has the element inside this vector set

81
00:06:34,970 --> 00:06:38,900
to Delta, you and all the other elements set to zero.

82
00:06:42,600 --> 00:06:45,450
Now, using these inputs, we can define some outputs.

83
00:06:45,940 --> 00:06:51,990
We're going to define why not just going to be the value of this function he evaluated at X not and

84
00:06:51,990 --> 00:06:52,470
you know.

85
00:06:53,460 --> 00:07:02,190
We're also we're also going to define our why EXI is going to be the function evaluated at Aleksi and

86
00:07:02,190 --> 00:07:07,720
you know, so this is evaluating the function with the element of expert.

87
00:07:08,100 --> 00:07:13,890
And we can show you the same thing for you so we can have a wide UI, which is evaluating the function

88
00:07:13,890 --> 00:07:17,430
with the element of the you input vector perturbed.

89
00:07:18,120 --> 00:07:22,830
So now that we define these different parameters, we can look at doing the actual Jacobean calculation

90
00:07:22,830 --> 00:07:23,880
and forming the matrix.

91
00:07:25,630 --> 00:07:31,450
So we can approximate the Jakobsson of the system evaluated at these liberalization point as being one

92
00:07:31,450 --> 00:07:39,010
over Deltour X, and then the columns of the recovery matrix are just going to be Y, X, one minus

93
00:07:39,010 --> 00:07:39,550
Y not.

94
00:07:39,790 --> 00:07:46,090
And then it's going to be the Y x2 minus Y, not all the way up to Y and explain why not.

95
00:07:46,510 --> 00:07:52,390
So basically we're going to form the columns of the covid matrixes just from differences of these vectors

96
00:07:52,390 --> 00:07:56,490
up here, and then we're going to scale it all by Alberto to mount the X.

97
00:07:57,520 --> 00:08:02,040
So this is just doing what we did on the first slide with the scalar example.

98
00:08:02,230 --> 00:08:04,440
But we're going to do it now in vector form.

99
00:08:05,710 --> 00:08:08,910
And when we do, this will end up with this describing matrix here.

100
00:08:08,920 --> 00:08:15,910
So we're going to have the Jacobean and outputs because our Y matrix is going to be of size M and it's

101
00:08:15,910 --> 00:08:22,060
going to have an input because our input function, Àlex Vector is going to be of size N.

102
00:08:23,880 --> 00:08:26,190
So this is going to be I am by N Matrix.

103
00:08:27,480 --> 00:08:31,240
We can do the same thing for the Caribbean with respect to the input.

104
00:08:31,680 --> 00:08:35,130
So now we're going to divide it by one over our daughter, you.

105
00:08:35,520 --> 00:08:41,630
And instead of using our X1 here, we're going to be using our you want you to all the way up to a year

106
00:08:41,640 --> 00:08:41,890
end.

107
00:08:42,270 --> 00:08:48,960
So basically, we're looking at how the output of the function changes with so probations in the U vector

108
00:08:48,960 --> 00:08:51,760
instead of small probation's in the X Factor.

109
00:08:52,770 --> 00:08:54,420
And when we do this, we're going to get out.

110
00:08:54,420 --> 00:08:56,110
You carry a matrix with respect to you.

111
00:08:56,130 --> 00:09:04,260
And again, it's going to have a output size of N by El where M is the number of outputs we have.

112
00:09:04,500 --> 00:09:13,470
So that's the size of the Y vector and is going to be of number of columns l where L is the size of

113
00:09:13,470 --> 00:09:15,150
our input vector U.

114
00:09:19,430 --> 00:09:25,010
So more concretely, let's actually have a look at how this algorithm works in general and how we can

115
00:09:25,010 --> 00:09:25,770
actually define it.

116
00:09:26,390 --> 00:09:29,240
So let's have a look at the state education algorithm.

117
00:09:29,270 --> 00:09:35,660
Now, this is the calculation of the Giacobbe matrix or the function F respect to X for the function

118
00:09:35,660 --> 00:09:37,400
given by Y is a Yoda.

119
00:09:37,400 --> 00:09:38,570
If you.

120
00:09:39,850 --> 00:09:44,470
Given the initial conditions, it's not and, you know, so these are the conditions that we want to

121
00:09:44,470 --> 00:09:49,330
linearity the system about or calculate the Jacobin of the nominee system about.

122
00:09:51,210 --> 00:09:56,930
The first step in the process is to calculate the appropriate amount X, so we're going to set Delta

123
00:09:56,940 --> 00:09:59,090
X to be a small numerical value.

124
00:09:59,880 --> 00:10:02,510
The next step is that we want to calculate the initial state.

125
00:10:02,880 --> 00:10:11,460
So we take the linear Azanian position, we put it into a function F and we calculate why not now for

126
00:10:11,460 --> 00:10:17,700
each element in the statement X, so we know we have x1 x2 all the way up to X and we want to perform

127
00:10:17,700 --> 00:10:19,100
the following operations.

128
00:10:19,530 --> 00:10:26,700
We first want to calculate the vector, so we want to calculate x y, which is just going to be Alisher,

129
00:10:27,120 --> 00:10:32,400
which is just going to be our initial condition, plus the better vector which has the element in this

130
00:10:32,400 --> 00:10:35,450
vector perturbed and all the other elements equal to zero.

131
00:10:35,490 --> 00:10:37,590
That's what this equation here is explaining.

132
00:10:38,220 --> 00:10:42,640
Once we have the perturbed input vector, then we want to calculate the perturbed output.

133
00:10:42,660 --> 00:10:49,260
So that's basically substituting in our perturbed X Factor into the process model or into the function

134
00:10:49,260 --> 00:10:52,140
and calculating output of the perturbed input.

135
00:10:53,490 --> 00:10:58,260
Then we can calculate the difference between the vectors, so the perturbed output vector minus the

136
00:10:58,260 --> 00:11:04,320
initial output vector divided by the total amount is going to give us the eighth column in the Giacobbe

137
00:11:04,320 --> 00:11:10,410
matrix so we can just go through and do this multiple times, building up the metrics and we're going

138
00:11:10,410 --> 00:11:16,040
to loop through end times until we get all the end input states for X.

139
00:11:17,930 --> 00:11:20,570
So there's nothing too complicated going on with this algorithm here.

140
00:11:20,590 --> 00:11:25,460
We just want to go through, build up the Jacoby and Matrix column by column, and each time we do that,

141
00:11:25,460 --> 00:11:30,620
we just perturb X by a tiny bit and see how that affects the output and then calculate the difference

142
00:11:30,620 --> 00:11:33,860
of this output and scale it by a bit perturbed amount.

143
00:11:34,900 --> 00:11:42,010
But we can also do this for any of the other inputs inside the function, so this function F X has actually

144
00:11:42,010 --> 00:11:44,550
two inputs, has an X factor and a new vector.

145
00:11:45,250 --> 00:11:48,610
So we perturb the X Factor to get the extra came in.

146
00:11:49,360 --> 00:11:51,870
We can do the same thing for the input you.

147
00:11:51,880 --> 00:11:56,980
So if you want to work out the Giacobbe in respect to the other input, you we do basically the same

148
00:11:56,980 --> 00:12:00,610
thing, except instead of perturbing X, we're now perturbing you.

149
00:12:00,620 --> 00:12:06,820
So we have a defined observed amount you and then we want to go through for every element inside the

150
00:12:06,820 --> 00:12:08,010
input vector you.

151
00:12:08,290 --> 00:12:14,590
So for one all the way up to L we want to calculate the perturbed you vector substitutability into the

152
00:12:14,590 --> 00:12:17,260
function and hold X constant this time.

153
00:12:17,260 --> 00:12:24,280
But now we're perturbing you work out the output and then calculate the Caribbean for and calculate

154
00:12:24,280 --> 00:12:31,180
the Jacobin by building up column by column with respect to the differences in the output for you.

155
00:12:31,180 --> 00:12:32,260
Perturbations.

156
00:12:35,060 --> 00:12:40,520
The calculating the GDP matrix numerically can be very useful, instead of sitting down and having to

157
00:12:40,520 --> 00:12:46,760
go through all the mathematical operations to differentiate your process model, you can do it numerically.

158
00:12:46,760 --> 00:12:52,760
And this becomes really handy, especially if you have a large system of like 50 states or even 12 states

159
00:12:53,090 --> 00:13:00,170
trying to work out the analytical Jacquemin metrics can be very error prone and take a lot of time while

160
00:13:00,290 --> 00:13:03,320
just using a numerical algorithm is perfectly acceptable.

161
00:13:03,500 --> 00:13:09,560
And it gives you results that are close enough to the true analytical solution that the output of the

162
00:13:09,560 --> 00:13:13,970
filter would be indifferent to whether you use the approximation or the true Jacobean.

163
00:13:14,600 --> 00:13:19,520
So hopefully you have an idea of how we can go about calculating the Giacobbe metrics numerically and

164
00:13:19,520 --> 00:13:22,300
hopefully you can see how it can have some advantages.

165
00:13:22,550 --> 00:13:27,470
It stops you from doing having to do all the calculations by hand and it can save you from making small

166
00:13:27,470 --> 00:13:29,330
errors which are very hard to track down.
