In this video, we're going to have a look at different ways of how we can go about calculating the
Giacobbe and matrixes that are required for the filter.
So previously we have calculated the Jacoby Matrixes analytically from equations using differentiation,
and we can see that this can be tedious.
We take the process model, measurement model, and then we have to differentiate the model with respect
to all the different inputs for the state, for the noise, for any inputs.
And this can be quite complex for very nonlinear systems.
There's also another way we can calculate the Jacobean matrix.
It is possible to calculate this Jacobean matrix numerically straight from the model itself.
And we can do this using numerical differentiation to get an idea of what numerical differentiation
is.
Imagine that we have a function F X and we want to differentiate the function with respect to X..
So this is basically saying we want to look at how the function output f changes with changes in X and
we can actually evaluate this using first principles.
So using first principles, if we have the function F evaluated at our initial condition or where we
want to, linear is a system about plus a little perturbed amount subtracted away from the function
evaluated at the initial condition, divided up by the D x amount.
We basically end up with this function here.
So this function looks at how F changes with changes in X, so basically we perturb X by a little amount
by the X and then we subtract off the initial condition so we get a change in our F and then we divide
it by the amount that we changed X.
And this is basically differentiation as the Delta X goes towards zero.
But when we do this numerically, we apply a non a small non-zero value and then calculate these functions
here and do the division.
And this will give us a numerical approximation of the derivative of the function F.
So we can actually have a look at this using some numbers, so let's say we have a function F X is equal
to two X, so we put a one in here.
It's going to give us to put a two.
It's going to give us four and so forth.
And we want to differentiate this function with respect to X..
So what we want to do is that we can define Adella X, so let's define a small perturbed amount of point
one.
And we want to carry out this whole process around our initial condition of, say, X equals one.
So we want to work out the derivative of this function around the value one.
So what we can do is we can basically take these equations and these numbers, put them into this equation
up here and evaluate it so we can substitute in if it's not plus Delta X, our function F X is just
two X, so we get two times the X, which is one because we're evaluating it around one plus our total
amount.
D.T. sorry, Dex, giving us point one.
So we get two times one plus point one and then we evaluate the function F at our initial condition.
Excellent.
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
which is point one.
So they go through and do the calculation, we end up with their derivative equal to and if we know
from numerical differentiation, if we differentiate this function here, the two X with respect to
X, the X drops away, I mean, just off of two.
So I can see that in this case, this is the numerical approximation of the derivative and it's going
to be exactly equal to the real derivative.
Now, this is a very benign example because the function to X is a linear system and finding the derivative
is very simple.
But this approximation holds for nonlinear systems as well.
So then how can this process of numerical differentiation help us to numerically calculate the Jacobean?
Well, let's say we give them a function Y is equal to F X you.
So this is a function F and we have two inputs.
We have an input X and an input you and we get an output of this whole function Y.
As also say that the inputs X you and the output Y are also vector functions, so our X is an X vector.
We have X states from one or way up to end.
Our U vector is going to be a vector of all of you components from one to L, and the output is going
to be output from one to M.
So let's define some input's.
So let's define X not being the initial condition that we want to calculate the UK about, so we store
the initial value of the X Factor.
Now we're going to define the X iveta, which is just the sum of the initial X Factor, plus this POTO
factor here and this term vector is just going to have the element in this vector, the Delta X and
all the other elements equal to zero.
So it just means we have the vector which has the element of X not perturbed by an amount Delta X.
So all this equation is showing here.
If we evaluate our Delta X, J and J and I are equal to each other, we set the value to be Delta X,
otherwise we will be zero.
So if this was X1, then this vector over here is just going to be our Delta X because X1 is going to
be equal to Delta X when I enjoy equal one and all the other times here going to be zero zero zero zero.
Likewise, if this was X three, this vector over here is going to be zero zero dollars zero zero zero
zero all the way up to X.
And so this is just the probation of this vector X with the element perturbed by the value Delta X.
We can go about and define the same thing for the year.
So basically, since we have a function here, it takes two inputs.
We have to define the initial condition or the linear ization point for both these inputs.
And in this case is going to be our, you know.
Now, we can also perturb the Uvalda in the same way, so basically we define our UI is just going to
be our, you know, vector and then a perturbed vector, which has the element inside this vector set
to Delta, you and all the other elements set to zero.
Now, using these inputs, we can define some outputs.
We're going to define why not just going to be the value of this function he evaluated at X not and
you know.
We're also we're also going to define our why EXI is going to be the function evaluated at Aleksi and
you know, so this is evaluating the function with the element of expert.
And we can show you the same thing for you so we can have a wide UI, which is evaluating the function
with the element of the you input vector perturbed.
So now that we define these different parameters, we can look at doing the actual Jacobean calculation
and forming the matrix.
So we can approximate the Jakobsson of the system evaluated at these liberalization point as being one
over Deltour X, and then the columns of the recovery matrix are just going to be Y, X, one minus
Y not.
And then it's going to be the Y x2 minus Y, not all the way up to Y and explain why not.
So basically we're going to form the columns of the covid matrixes just from differences of these vectors
up here, and then we're going to scale it all by Alberto to mount the X.
So this is just doing what we did on the first slide with the scalar example.
But we're going to do it now in vector form.
And when we do, this will end up with this describing matrix here.
So we're going to have the Jacobean and outputs because our Y matrix is going to be of size M and it's
going to have an input because our input function, Àlex Vector is going to be of size N.
So this is going to be I am by N Matrix.
We can do the same thing for the Caribbean with respect to the input.
So now we're going to divide it by one over our daughter, you.
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
end.
So basically, we're looking at how the output of the function changes with so probations in the U vector
instead of small probation's in the X Factor.
And when we do this, we're going to get out.
You carry a matrix with respect to you.
And again, it's going to have a output size of N by El where M is the number of outputs we have.
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
our input vector U.
So more concretely, let's actually have a look at how this algorithm works in general and how we can
actually define it.
So let's have a look at the state education algorithm.
Now, this is the calculation of the Giacobbe matrix or the function F respect to X for the function
given by Y is a Yoda.
If you.
Given the initial conditions, it's not and, you know, so these are the conditions that we want to
linearity the system about or calculate the Jacobin of the nominee system about.
The first step in the process is to calculate the appropriate amount X, so we're going to set Delta
X to be a small numerical value.
The next step is that we want to calculate the initial state.
So we take the linear Azanian position, we put it into a function F and we calculate why not now for
each element in the statement X, so we know we have x1 x2 all the way up to X and we want to perform
the following operations.
We first want to calculate the vector, so we want to calculate x y, which is just going to be Alisher,
which is just going to be our initial condition, plus the better vector which has the element in this
vector perturbed and all the other elements equal to zero.
That's what this equation here is explaining.
Once we have the perturbed input vector, then we want to calculate the perturbed output.
So that's basically substituting in our perturbed X Factor into the process model or into the function
and calculating output of the perturbed input.
Then we can calculate the difference between the vectors, so the perturbed output vector minus the
initial output vector divided by the total amount is going to give us the eighth column in the Giacobbe
matrix so we can just go through and do this multiple times, building up the metrics and we're going
to loop through end times until we get all the end input states for X.
So there's nothing too complicated going on with this algorithm here.
We just want to go through, build up the Jacoby and Matrix column by column, and each time we do that,
we just perturb X by a tiny bit and see how that affects the output and then calculate the difference
of this output and scale it by a bit perturbed amount.
But we can also do this for any of the other inputs inside the function, so this function F X has actually
two inputs, has an X factor and a new vector.
So we perturb the X Factor to get the extra came in.
We can do the same thing for the input you.
So if you want to work out the Giacobbe in respect to the other input, you we do basically the same
thing, except instead of perturbing X, we're now perturbing you.
So we have a defined observed amount you and then we want to go through for every element inside the
input vector you.
So for one all the way up to L we want to calculate the perturbed you vector substitutability into the
function and hold X constant this time.
But now we're perturbing you work out the output and then calculate the Caribbean for and calculate
the Jacobin by building up column by column with respect to the differences in the output for you.
Perturbations.
The calculating the GDP matrix numerically can be very useful, instead of sitting down and having to
go through all the mathematical operations to differentiate your process model, you can do it numerically.
And this becomes really handy, especially if you have a large system of like 50 states or even 12 states
trying to work out the analytical Jacquemin metrics can be very error prone and take a lot of time while
just using a numerical algorithm is perfectly acceptable.
And it gives you results that are close enough to the true analytical solution that the output of the
filter would be indifferent to whether you use the approximation or the true Jacobean.
So hopefully you have an idea of how we can go about calculating the Giacobbe metrics numerically and
hopefully you can see how it can have some advantages.
It stops you from doing having to do all the calculations by hand and it can save you from making small
errors which are very hard to track down.