WEBVTT

00:00:00.000 --> 00:00:02.460 align:middle line:90%
[SQUEAKING]

00:00:02.460 --> 00:00:04.428 align:middle line:90%
[RUSTLING]

00:00:04.428 --> 00:00:05.412 align:middle line:90%
[CLICKING]

00:00:05.412 --> 00:00:10.225 align:middle line:90%


00:00:10.225 --> 00:00:12.850 align:middle line:84%
FRANK SCHAFER: Yeah, so, yeah,
I plan to split it in two parts,

00:00:12.850 --> 00:00:14.940 align:middle line:84%
so the first part is about
ordinary differential

00:00:14.940 --> 00:00:19.560 align:middle line:84%
equations, so just a quick recap
what an ordinary differential

00:00:19.560 --> 00:00:21.630 align:middle line:84%
equation actually
is, and then we'll

00:00:21.630 --> 00:00:24.340 align:middle line:84%
go into this kind of
sensitivity analysis,

00:00:24.340 --> 00:00:26.310 align:middle line:84%
so how to compute
derivatives of solutions

00:00:26.310 --> 00:00:28.020 align:middle line:84%
of ordinary
differential equations.

00:00:28.020 --> 00:00:31.410 align:middle line:84%
And specifically, we will
pick out one very important

00:00:31.410 --> 00:00:32.655 align:middle line:90%
of these methods.

00:00:32.655 --> 00:00:35.248 align:middle line:90%


00:00:35.248 --> 00:00:37.040 align:middle line:84%
So, yeah, an ordinary
differential equation

00:00:37.040 --> 00:00:39.207 align:middle line:84%
is basically described by
this kind of initial value

00:00:39.207 --> 00:00:43.340 align:middle line:84%
problem, where we have the
state at a given initial time

00:00:43.340 --> 00:00:47.900 align:middle line:84%
t0 is equal to u0, and then
the dynamics of this state

00:00:47.900 --> 00:00:50.820 align:middle line:84%
is described by this
kind of time evolution.

00:00:50.820 --> 00:00:54.530 align:middle line:84%
So we have that the
derivative of u is--

00:00:54.530 --> 00:00:57.650 align:middle line:84%
the time derivative of u
is equal to this function f

00:00:57.650 --> 00:01:00.710 align:middle line:84%
that can depend on time,
on the state itself,

00:01:00.710 --> 00:01:03.510 align:middle line:90%
and on some parameters p.

00:01:03.510 --> 00:01:06.180 align:middle line:84%
And the first natural
question to ask

00:01:06.180 --> 00:01:10.980 align:middle line:84%
is, basically, how do
we solve such an ODE?

00:01:10.980 --> 00:01:15.630 align:middle line:84%
And let's say the probably
simplest ODE I could imagine

00:01:15.630 --> 00:01:19.170 align:middle line:84%
basically is one of a
free-falling particle

00:01:19.170 --> 00:01:22.245 align:middle line:84%
or a ball, which
is described by--

00:01:22.245 --> 00:01:25.260 align:middle line:84%
well, probably, you
have all seen this--

00:01:25.260 --> 00:01:28.350 align:middle line:84%
by Newton's law, or something
like the acceleration

00:01:28.350 --> 00:01:32.230 align:middle line:84%
is equal to minus the
gravitational constant.

00:01:32.230 --> 00:01:35.580 align:middle line:84%
And for these kind of
easy ordinary differential

00:01:35.580 --> 00:01:39.120 align:middle line:84%
equations, right, we can
solve that analytically,

00:01:39.120 --> 00:01:42.690 align:middle line:84%
so we simply integrate
that equation twice, right?

00:01:42.690 --> 00:01:48.330 align:middle line:84%
So we have that z
prime is equal to some

00:01:48.330 --> 00:01:54.435 align:middle line:90%
offset minus g t minus t0.

00:01:54.435 --> 00:01:56.310 align:middle line:84%
And then we could
integrate it a second time,

00:01:56.310 --> 00:01:58.920 align:middle line:84%
and we'd get, like, the
full analytical solution

00:01:58.920 --> 00:02:03.505 align:middle line:84%
of the height, in that
case, with respect to time.

00:02:03.505 --> 00:02:06.250 align:middle line:90%


00:02:06.250 --> 00:02:07.870 align:middle line:84%
Here, on this
slide, I did already

00:02:07.870 --> 00:02:10.389 align:middle line:84%
something that's very
meaningful to solve

00:02:10.389 --> 00:02:14.500 align:middle line:84%
ODEs numerically, and that's,
like, we want to bring down

00:02:14.500 --> 00:02:17.320 align:middle line:84%
these kind of ODEs, which
are sometimes described

00:02:17.320 --> 00:02:20.050 align:middle line:84%
with second-order
derivatives, to just

00:02:20.050 --> 00:02:21.310 align:middle line:90%
first-order derivatives.

00:02:21.310 --> 00:02:23.350 align:middle line:84%
And the basic trick
is to introduce

00:02:23.350 --> 00:02:26.410 align:middle line:84%
this additional variable
v, right, so the velocity

00:02:26.410 --> 00:02:28.840 align:middle line:84%
in that case, which
can be written as--

00:02:28.840 --> 00:02:39.370 align:middle line:84%
right, so v of t is
equal to dz of t dt.

00:02:39.370 --> 00:02:43.090 align:middle line:84%
OK, so for that kind of ODE, we
know the analytical solution,

00:02:43.090 --> 00:02:44.950 align:middle line:84%
and it's basically
easy to solve.

00:02:44.950 --> 00:02:48.250 align:middle line:84%
Now, coming back to the
more general case, where

00:02:48.250 --> 00:02:54.217 align:middle line:84%
we have some nice
function f, but solving

00:02:54.217 --> 00:02:56.050 align:middle line:84%
for the analytical
solution is tough, right,

00:02:56.050 --> 00:02:57.970 align:middle line:84%
because integrating
is already tough

00:02:57.970 --> 00:03:00.130 align:middle line:84%
and solving these kind
of initial value problems

00:03:00.130 --> 00:03:02.890 align:middle line:84%
is even tougher,
we can fall back

00:03:02.890 --> 00:03:06.470 align:middle line:84%
to some numerical routines,
basically, to solve it.

00:03:06.470 --> 00:03:08.890 align:middle line:84%
And the easiest
numerical routine

00:03:08.890 --> 00:03:11.740 align:middle line:84%
is called Euler
solver, where we--

00:03:11.740 --> 00:03:13.570 align:middle line:84%
and probably all of
us could have come up

00:03:13.570 --> 00:03:17.930 align:middle line:84%
with that by ourselves-- so
we simply discretize time.

00:03:17.930 --> 00:03:21.940 align:middle line:84%
So we introduce this
tn, discrete time steps

00:03:21.940 --> 00:03:25.000 align:middle line:84%
of our solution, and
then if we plug that

00:03:25.000 --> 00:03:27.370 align:middle line:84%
into the definition of the
derivative, we get something

00:03:27.370 --> 00:03:29.330 align:middle line:84%
like these finite
difference equations.

00:03:29.330 --> 00:03:34.090 align:middle line:84%
So, right, if we see here,
the du dt would be u n plus 1

00:03:34.090 --> 00:03:36.730 align:middle line:84%
at the-- so that's basically
the state at the time tn

00:03:36.730 --> 00:03:41.050 align:middle line:84%
plus 1 minus the state at the
time tn divided by delta t,

00:03:41.050 --> 00:03:44.030 align:middle line:84%
and if we bring the delta t and
the state to the other side,

00:03:44.030 --> 00:03:47.385 align:middle line:84%
we get this explicit
Euler method.

00:03:47.385 --> 00:03:48.760 align:middle line:84%
STEVEN JOHNSON:
And last week, we

00:03:48.760 --> 00:03:50.860 align:middle line:84%
talked about finite
difference approximations,

00:03:50.860 --> 00:03:53.530 align:middle line:84%
so this is exactly
taking that derivative

00:03:53.530 --> 00:03:55.510 align:middle line:84%
and making a forward
difference approximation.

00:03:55.510 --> 00:03:56.343 align:middle line:90%
FRANK SCHAFER: Yeah.

00:03:56.343 --> 00:03:57.410 align:middle line:90%
Yeah, exactly.

00:03:57.410 --> 00:04:00.100 align:middle line:84%
And you can have more
sophisticated methods,

00:04:00.100 --> 00:04:03.220 align:middle line:84%
of course, to solve your ODEs,
but for the rest of today,

00:04:03.220 --> 00:04:05.470 align:middle line:84%
it's basically enough
to just think of,

00:04:05.470 --> 00:04:07.870 align:middle line:84%
if we don't know the
analytical solution,

00:04:07.870 --> 00:04:09.460 align:middle line:84%
we can use some
numerical routine

00:04:09.460 --> 00:04:12.250 align:middle line:84%
to solve for the state
as a function of time.

00:04:12.250 --> 00:04:15.040 align:middle line:84%
And, yeah, actually, I wanted
to implement that very quickly

00:04:15.040 --> 00:04:20.620 align:middle line:84%
with you, like, for the case
of the free-falling ball,

00:04:20.620 --> 00:04:21.985 align:middle line:90%
so for that kind of ODE.

00:04:21.985 --> 00:04:27.090 align:middle line:90%


00:04:27.090 --> 00:04:32.240 align:middle line:84%
So let's define some
initial height, some kind

00:04:32.240 --> 00:04:40.380 align:middle line:84%
of initial velocity, the
gravitational constant,

00:04:40.380 --> 00:04:45.450 align:middle line:84%
and, well, maybe let's
say that's basically

00:04:45.450 --> 00:04:49.930 align:middle line:90%
our parameter, g.

00:04:49.930 --> 00:04:53.800 align:middle line:84%
We can say our initial
state, right, is then

00:04:53.800 --> 00:04:57.310 align:middle line:84%
this vector where
we stack together

00:04:57.310 --> 00:04:59.650 align:middle line:84%
initial height and
initial velocity.

00:04:59.650 --> 00:05:03.330 align:middle line:90%


00:05:03.330 --> 00:05:05.940 align:middle line:84%
And we say maybe,
in our task, we

00:05:05.940 --> 00:05:10.320 align:middle line:84%
want to integrate that
equation from some initial time

00:05:10.320 --> 00:05:16.640 align:middle line:84%
to some final time, and we have
to provide this kind of time

00:05:16.640 --> 00:05:18.560 align:middle line:90%
discretization.

00:05:18.560 --> 00:05:22.220 align:middle line:84%
Let's choose some small
time discretization.

00:05:22.220 --> 00:05:24.950 align:middle line:90%


00:05:24.950 --> 00:05:26.870 align:middle line:84%
Everybody's happy
with that so far?

00:05:26.870 --> 00:05:30.210 align:middle line:90%


00:05:30.210 --> 00:05:35.460 align:middle line:84%
So then we want to define our
ODE function, which is also

00:05:35.460 --> 00:05:40.320 align:middle line:84%
called the vector field, where
we just insert the definitions

00:05:40.320 --> 00:05:42.090 align:middle line:90%
I had on this slide, basically.

00:05:42.090 --> 00:05:48.080 align:middle line:84%
So we have that the derivative
of the height with respect

00:05:48.080 --> 00:05:51.080 align:middle line:84%
to time is the velocity, right,
which is here, in our case, now

00:05:51.080 --> 00:05:52.970 align:middle line:90%
the second component.

00:05:52.970 --> 00:05:55.640 align:middle line:84%
And we have that the
derivative of the time

00:05:55.640 --> 00:05:58.040 align:middle line:84%
is equal to-- the
derivative of the velocity

00:05:58.040 --> 00:06:01.100 align:middle line:84%
with respect to time is
equal to minus g, which

00:06:01.100 --> 00:06:03.320 align:middle line:84%
is on the right-hand
side of the board,

00:06:03.320 --> 00:06:07.642 align:middle line:84%
and then we return, basically,
again, the vector of these two.

00:06:07.642 --> 00:06:10.100 align:middle line:84%
STEVEN JOHNSON: We're going to
get g from the parameters, p

00:06:10.100 --> 00:06:10.600 align:middle line:90%
[INAUDIBLE].

00:06:10.600 --> 00:06:12.540 align:middle line:90%
FRANK SCHAFER: Oh, yeah.

00:06:12.540 --> 00:06:13.560 align:middle line:90%
Let's say it like that.

00:06:13.560 --> 00:06:14.060 align:middle line:90%
Thanks.

00:06:14.060 --> 00:06:16.410 align:middle line:90%


00:06:16.410 --> 00:06:22.320 align:middle line:84%
And so now we want to
implement our Euler

00:06:22.320 --> 00:06:25.110 align:middle line:90%
solver, which should take--

00:06:25.110 --> 00:06:28.200 align:middle line:84%
well, the kind of function
that we want to solve,

00:06:28.200 --> 00:06:32.543 align:middle line:84%
we want it to take
the initial condition.

00:06:32.543 --> 00:06:33.960 align:middle line:84%
Let's write it a
bit more general.

00:06:33.960 --> 00:06:36.560 align:middle line:90%


00:06:36.560 --> 00:06:40.860 align:middle line:84%
The time span of
the simulation--

00:06:40.860 --> 00:06:42.350 align:middle line:90%
STEVEN JOHNSON: tspan.

00:06:42.350 --> 00:06:46.670 align:middle line:84%
FRANK SCHAFER: tspan,
yeah, and the parameters,

00:06:46.670 --> 00:06:47.940 align:middle line:90%
and maybe even dt.

00:06:47.940 --> 00:06:52.510 align:middle line:90%


00:06:52.510 --> 00:06:57.120 align:middle line:84%
And let's say our time
at some point will be--

00:06:57.120 --> 00:07:00.130 align:middle line:84%
so we make a copy so we don't
overwrite into the array.

00:07:00.130 --> 00:07:03.915 align:middle line:84%
So that this is preserved,
we make a time grid.

00:07:03.915 --> 00:07:07.968 align:middle line:90%


00:07:07.968 --> 00:07:10.260 align:middle line:84%
This is actually big enough
on the screen for everyone?

00:07:10.260 --> 00:07:10.760 align:middle line:90%
Oh, good.

00:07:10.760 --> 00:07:30.690 align:middle line:90%


00:07:30.690 --> 00:07:32.955 align:middle line:84%
Right, we have to be a bit
careful with the endpoint

00:07:32.955 --> 00:07:34.830 align:middle line:84%
because we don't want
it to step one too far.

00:07:34.830 --> 00:07:40.060 align:middle line:90%


00:07:40.060 --> 00:07:44.980 align:middle line:84%
And then the update rule is
basically we take u at a given

00:07:44.980 --> 00:07:49.100 align:middle line:90%
time, and that's-- whoops.

00:07:49.100 --> 00:07:53.932 align:middle line:90%


00:07:53.932 --> 00:07:55.890 align:middle line:84%
STEVEN JOHNSON: And you
don't need the deepcopy

00:07:55.890 --> 00:07:59.275 align:middle line:84%
since you're not overwriting
u in place anyway.

00:07:59.275 --> 00:08:00.400 align:middle line:90%
FRANK SCHAFER: That's true.

00:08:00.400 --> 00:08:04.895 align:middle line:84%
I think I will need it later
for one modification, so--

00:08:04.895 --> 00:08:07.817 align:middle line:84%
STEVEN JOHNSON: But you
don't need any copy.

00:08:07.817 --> 00:08:09.150 align:middle line:90%
FRANK SCHAFER: That's also true.

00:08:09.150 --> 00:08:09.650 align:middle line:90%
OK.

00:08:09.650 --> 00:08:12.840 align:middle line:90%


00:08:12.840 --> 00:08:15.210 align:middle line:84%
And let's say I'm not
interested in the full solution

00:08:15.210 --> 00:08:17.880 align:middle line:84%
as a function of time, but
just in the endpoint as--

00:08:17.880 --> 00:08:20.525 align:middle line:90%


00:08:20.525 --> 00:08:22.025 align:middle line:84%
OK, let's see if
that works already.

00:08:22.025 --> 00:08:36.289 align:middle line:90%


00:08:36.289 --> 00:08:39.380 align:middle line:90%
All right, that's good.

00:08:39.380 --> 00:08:41.870 align:middle line:90%
u should be at ti, for sure.

00:08:41.870 --> 00:08:49.890 align:middle line:90%


00:08:49.890 --> 00:08:53.980 align:middle line:84%
Yeah, we can check if that's the
correct solution by plugging it

00:08:53.980 --> 00:08:55.485 align:middle line:90%
into our analytical equation.

00:08:55.485 --> 00:08:58.450 align:middle line:90%


00:08:58.450 --> 00:08:59.935 align:middle line:90%
Let me just pull the form.

00:08:59.935 --> 00:09:08.470 align:middle line:90%


00:09:08.470 --> 00:09:11.080 align:middle line:84%
Right, so we have now written
a numerical routine that

00:09:11.080 --> 00:09:13.540 align:middle line:84%
spits out the state
at a given time t,

00:09:13.540 --> 00:09:15.820 align:middle line:84%
and I think that
looks actually good.

00:09:15.820 --> 00:09:23.560 align:middle line:84%
So we have t equal to 0, so
our z should be z0 minus g--

00:09:23.560 --> 00:09:27.420 align:middle line:90%


00:09:27.420 --> 00:09:38.935 align:middle line:84%
minus v0 times 1 plus v0
times 1 minus 1/2 times g.

00:09:38.935 --> 00:09:42.538 align:middle line:90%


00:09:42.538 --> 00:09:44.080 align:middle line:84%
And, yeah, that
looks basically good.

00:09:44.080 --> 00:09:46.247 align:middle line:84%
That's the discretization
error of the Euler method,

00:09:46.247 --> 00:09:48.675 align:middle line:84%
and we could check the same
for the second component.

00:09:48.675 --> 00:09:50.800 align:middle line:84%
STEVEN JOHNSON: Yeah, so
the correct answer is 0.1,

00:09:50.800 --> 00:09:52.495 align:middle line:84%
and then it's--
it's, like, 0.105.

00:09:52.495 --> 00:09:53.620 align:middle line:90%
FRANK SCHAFER: Yeah, it's--

00:09:53.620 --> 00:09:56.650 align:middle line:84%
yeah, exactly, it's slightly
off because we have not the most

00:09:56.650 --> 00:09:59.320 align:middle line:90%
sophisticated numerical solver.

00:09:59.320 --> 00:10:00.850 align:middle line:90%
OK, cool.

00:10:00.850 --> 00:10:03.130 align:middle line:84%
So that's how we
solve ODEs numerically

00:10:03.130 --> 00:10:05.830 align:middle line:84%
if we don't have an
analytical solution,

00:10:05.830 --> 00:10:09.460 align:middle line:84%
and, yeah, now we get into the
kind of sensitivity analysis

00:10:09.460 --> 00:10:12.740 align:middle line:84%
if we have a numerical
routine available.

00:10:12.740 --> 00:10:16.480 align:middle line:84%
So there are two different ways,
fundamentally different ways,

00:10:16.480 --> 00:10:18.830 align:middle line:90%
to do sensitivity analysis.

00:10:18.830 --> 00:10:21.340 align:middle line:84%
One is called discrete
sensitivity analysis,

00:10:21.340 --> 00:10:24.310 align:middle line:84%
and one is called continuous
sensitivity analysis.

00:10:24.310 --> 00:10:27.490 align:middle line:84%
And the first one
is basically you

00:10:27.490 --> 00:10:29.770 align:middle line:84%
imagine that you wrote
that solver that we just

00:10:29.770 --> 00:10:31.570 align:middle line:84%
wrote in some language
that's compatible

00:10:31.570 --> 00:10:33.140 align:middle line:90%
with automatic differentiation.

00:10:33.140 --> 00:10:36.070 align:middle line:84%
And so we first discretize,
basically is the task,

00:10:36.070 --> 00:10:37.850 align:middle line:90%
and then we differentiate it.

00:10:37.850 --> 00:10:40.690 align:middle line:84%
And the second one
is basically we

00:10:40.690 --> 00:10:43.640 align:middle line:84%
write a custom rule for
the sensitivity analysis,

00:10:43.640 --> 00:10:45.920 align:middle line:84%
and so we first
approximate, basically,

00:10:45.920 --> 00:10:50.780 align:middle line:84%
the gradient that we want to
compute and then differentiate

00:10:50.780 --> 00:10:51.380 align:middle line:90%
it--

00:10:51.380 --> 00:10:54.430 align:middle line:90%
and then discretize it.

00:10:54.430 --> 00:10:59.230 align:middle line:84%
And for each of these methods,
these different paradigms,

00:10:59.230 --> 00:11:01.583 align:middle line:84%
basically, in either first
discretizing and then

00:11:01.583 --> 00:11:03.250 align:middle line:84%
differentiating or
first differentiating

00:11:03.250 --> 00:11:06.280 align:middle line:84%
and then discretizing, there
are two different modes

00:11:06.280 --> 00:11:09.190 align:middle line:84%
that you also probably have
covered in the lecture already.

00:11:09.190 --> 00:11:12.820 align:middle line:84%
You can either derive a forward,
or also called tangent, mode

00:11:12.820 --> 00:11:14.530 align:middle line:90%
or a reverse, adjoint, mode.

00:11:14.530 --> 00:11:17.890 align:middle line:84%
And depending on if you
have many input parameters

00:11:17.890 --> 00:11:21.070 align:middle line:84%
and a small number of
outputs, one of these modes

00:11:21.070 --> 00:11:23.200 align:middle line:84%
is basically preferred
to each other.

00:11:23.200 --> 00:11:26.740 align:middle line:84%
So in the setting where you have
many parameters with respect

00:11:26.740 --> 00:11:29.350 align:middle line:84%
to which you want to compute
a gradient or derivative,

00:11:29.350 --> 00:11:32.230 align:middle line:84%
you usually want to
have some adjoint mode,

00:11:32.230 --> 00:11:35.560 align:middle line:84%
and if you have
high memory demands,

00:11:35.560 --> 00:11:38.570 align:middle line:84%
you typically want to have these
continuous sensitivity methods.

00:11:38.570 --> 00:11:41.620 align:middle line:84%
So it's a very relevant
case to consider

00:11:41.620 --> 00:11:44.800 align:middle line:84%
these continuous adjoints,
basically, and that's

00:11:44.800 --> 00:11:48.790 align:middle line:90%
what we will do today.

00:11:48.790 --> 00:11:50.580 align:middle line:84%
So what are
sensitivities good for?

00:11:50.580 --> 00:11:53.310 align:middle line:84%
Just as a recap, so
sensitivity analysis

00:11:53.310 --> 00:11:57.270 align:middle line:84%
basically just, well,
describes what it says.

00:11:57.270 --> 00:12:00.000 align:middle line:84%
So we might be interested
in just describing

00:12:00.000 --> 00:12:03.780 align:middle line:84%
how maybe the height of our
ball would change if we slightly

00:12:03.780 --> 00:12:06.360 align:middle line:84%
perturb the parameter of
the differential equation,

00:12:06.360 --> 00:12:08.610 align:middle line:84%
but we can also use the
gradient of these ODEs

00:12:08.610 --> 00:12:11.880 align:middle line:84%
to do more fancy stuff,
as Steven mentioned,

00:12:11.880 --> 00:12:15.390 align:middle line:84%
like parameter estimation
in, what, chemical reaction

00:12:15.390 --> 00:12:19.740 align:middle line:84%
networks or so, or control
for whatever physical system

00:12:19.740 --> 00:12:22.740 align:middle line:84%
or chemical system
you have at hand.

00:12:22.740 --> 00:12:25.520 align:middle line:84%
So once again, so for the
free-falling particle,

00:12:25.520 --> 00:12:28.550 align:middle line:84%
it might be the task that
we have some terminal cost

00:12:28.550 --> 00:12:31.760 align:middle line:84%
or so, that could be this
G of u at the final time,

00:12:31.760 --> 00:12:34.052 align:middle line:84%
and we are interested
in maybe saying

00:12:34.052 --> 00:12:35.510 align:middle line:84%
how the height
changes with respect

00:12:35.510 --> 00:12:37.050 align:middle line:90%
to the gravitational constant.

00:12:37.050 --> 00:12:40.430 align:middle line:84%
And so the claim is
that this is always easy

00:12:40.430 --> 00:12:43.370 align:middle line:84%
if we can solve the ODE
analytically, right,

00:12:43.370 --> 00:12:47.840 align:middle line:84%
so if we look at the
solution there of the ODE,

00:12:47.840 --> 00:12:51.020 align:middle line:84%
can someone say what's the
sensitivity that I wrote down,

00:12:51.020 --> 00:12:55.990 align:middle line:84%
like, the sensitivity of the
final height with respect to g?

00:12:55.990 --> 00:12:59.330 align:middle line:90%


00:12:59.330 --> 00:13:00.065 align:middle line:90%
Yup?

00:13:00.065 --> 00:13:03.040 align:middle line:84%
AUDIENCE: Negative 1/2
t minus [INAUDIBLE]..

00:13:03.040 --> 00:13:04.870 align:middle line:84%
FRANK SCHAFER: Yeah,
exactly, so and now we

00:13:04.870 --> 00:13:06.578 align:middle line:84%
will basically cover
how we do that if we

00:13:06.578 --> 00:13:09.970 align:middle line:84%
don't have the analytic
solution available.

00:13:09.970 --> 00:13:13.037 align:middle line:84%
For this, we will have
to do some derivation.

00:13:13.037 --> 00:13:13.537 align:middle line:90%
Uh-huh.

00:13:13.537 --> 00:13:14.037 align:middle line:90%
Yup.

00:13:14.037 --> 00:13:18.270 align:middle line:90%


00:13:18.270 --> 00:13:19.710 align:middle line:90%
Let me move them.

00:13:19.710 --> 00:13:24.960 align:middle line:90%


00:13:24.960 --> 00:13:30.680 align:middle line:84%
So we'll do continuous
adjoins today.

00:13:30.680 --> 00:13:40.330 align:middle line:90%


00:13:40.330 --> 00:13:43.060 align:middle line:84%
So let's first write down
one of these cost functions

00:13:43.060 --> 00:13:45.760 align:middle line:84%
which I just had in a
bit more general way.

00:13:45.760 --> 00:13:48.750 align:middle line:84%
So we have some
cost that depends

00:13:48.750 --> 00:13:51.750 align:middle line:84%
on the state as a
function of time and p,

00:13:51.750 --> 00:13:57.130 align:middle line:84%
where the state
itself, of course,

00:13:57.130 --> 00:14:00.090 align:middle line:90%
also depends on the parameters.

00:14:00.090 --> 00:14:05.205 align:middle line:84%
And we'll say that this
function can be written as the--

00:14:05.205 --> 00:14:15.394 align:middle line:90%


00:14:15.394 --> 00:14:18.780 align:middle line:90%
all right, so we say we can--

00:14:18.780 --> 00:14:20.640 align:middle line:84%
we don't have, maybe,
just the final value,

00:14:20.640 --> 00:14:22.380 align:middle line:84%
but we are interested
in general in

00:14:22.380 --> 00:14:27.252 align:middle line:84%
some functional on the solution
of the differential equation.

00:14:27.252 --> 00:14:29.460 align:middle line:84%
AUDIENCE: And you can think
of capital G and little g

00:14:29.460 --> 00:14:31.000 align:middle line:90%
as just being scalar functions?

00:14:31.000 --> 00:14:31.792 align:middle line:90%
FRANK SCHAFER: Yes.

00:14:31.792 --> 00:14:31.950 align:middle line:90%
AUDIENCE: OK.

00:14:31.950 --> 00:14:32.640 align:middle line:90%
FRANK SCHAFER: Yup.

00:14:32.640 --> 00:14:33.140 align:middle line:90%
Yup.

00:14:33.140 --> 00:14:35.570 align:middle line:90%


00:14:35.570 --> 00:14:38.930 align:middle line:84%
And now comes basically
the first nice trick

00:14:38.930 --> 00:14:41.990 align:middle line:84%
in this kind of derivation,
and that's related

00:14:41.990 --> 00:14:43.558 align:middle line:90%
to Lagrange multipliers.

00:14:43.558 --> 00:14:45.808 align:middle line:84%
STEVEN JOHNSON: Do you want
to write down the ODE that

00:14:45.808 --> 00:14:47.600 align:middle line:90%
at least satisfies?

00:14:47.600 --> 00:14:51.210 align:middle line:84%
FRANK SCHAFER: Yeah,
probably a good idea.

00:14:51.210 --> 00:14:53.360 align:middle line:90%
All right, such that--

00:14:53.360 --> 00:15:01.430 align:middle line:90%


00:15:01.430 --> 00:15:02.420 align:middle line:90%
Oh, I see.

00:15:02.420 --> 00:15:21.272 align:middle line:90%


00:15:21.272 --> 00:15:22.980 align:middle line:84%
OK, so the first trick
that we want to do

00:15:22.980 --> 00:15:27.150 align:middle line:84%
is basically to add a 0 to
this kind of function, so--

00:15:27.150 --> 00:15:28.650 align:middle line:84%
STEVEN JOHNSON: Can
we pause to make

00:15:28.650 --> 00:15:30.480 align:middle line:84%
sure we're understanding
what you're doing?

00:15:30.480 --> 00:15:34.710 align:middle line:84%
So you have some ODE,
you solve for u of t,

00:15:34.710 --> 00:15:38.880 align:middle line:84%
and then you're going to compute
a number at the end, capital G,

00:15:38.880 --> 00:15:42.330 align:middle line:84%
by keeping the ODE solution
and integrating some function

00:15:42.330 --> 00:15:45.300 align:middle line:84%
little g into that
solution, right?

00:15:45.300 --> 00:15:48.180 align:middle line:84%
And the ODE depends
on some parameters,

00:15:48.180 --> 00:15:50.700 align:middle line:84%
and you want to
find the derivative

00:15:50.700 --> 00:15:53.550 align:middle line:84%
of this final output,
capital G, with respect

00:15:53.550 --> 00:15:56.110 align:middle line:90%
to all those parameters of p.

00:15:56.110 --> 00:15:59.234 align:middle line:84%
So little p might
be a vector, it

00:15:59.234 --> 00:16:06.530 align:middle line:90%
might be 10,000 reaction rates.

00:16:06.530 --> 00:16:11.710 align:middle line:84%
And capital G might
be the integral

00:16:11.710 --> 00:16:15.580 align:middle line:84%
of the squared difference
between the ODE solution

00:16:15.580 --> 00:16:18.863 align:middle line:84%
and some experimental data
on the chemical reaction,

00:16:18.863 --> 00:16:20.776 align:middle line:84%
you know, the
concentration, [INAUDIBLE]..

00:16:20.776 --> 00:16:24.192 align:middle line:90%


00:16:24.192 --> 00:16:25.400 align:middle line:90%
FRANK SCHAFER: Yeah, exactly.

00:16:25.400 --> 00:16:27.110 align:middle line:84%
Does everybody see
why that's a 0?

00:16:27.110 --> 00:16:31.370 align:middle line:90%


00:16:31.370 --> 00:16:32.595 align:middle line:90%
Right, so why--

00:16:32.595 --> 00:16:34.970 align:middle line:84%
STEVEN JOHNSON: Yeah, so,
sorry, I was talking about that

00:16:34.970 --> 00:16:41.740 align:middle line:84%
and then maybe you need
to say what the 0 is

00:16:41.740 --> 00:16:45.070 align:middle line:84%
FRANK SCHAFER: Right, so
because, by definition,

00:16:45.070 --> 00:16:49.660 align:middle line:84%
basically, our state fulfills
this ordinary differential

00:16:49.660 --> 00:16:54.010 align:middle line:84%
equation, we can introduce this
kind of Lagrange multiplier,

00:16:54.010 --> 00:16:55.600 align:middle line:90%
and that term is 0.

00:16:55.600 --> 00:16:59.830 align:middle line:84%
So if we add that term to
this kind of cost function,

00:16:59.830 --> 00:17:05.440 align:middle line:84%
we basically do nothing, but
we have this free Lagrange

00:17:05.440 --> 00:17:08.030 align:middle line:84%
multiplier that we
can choose later on.

00:17:08.030 --> 00:17:12.130 align:middle line:84%
So that will be kind of the
trick that we will play.

00:17:12.130 --> 00:17:15.280 align:middle line:84%
And now, as Steven
already said, so we're

00:17:15.280 --> 00:17:21.369 align:middle line:84%
interested in
computing dG over dp,

00:17:21.369 --> 00:17:24.849 align:middle line:84%
right, so that's the kind
of sensitivity gradient

00:17:24.849 --> 00:17:27.550 align:middle line:84%
information that
we want to have.

00:17:27.550 --> 00:17:30.400 align:middle line:90%


00:17:30.400 --> 00:17:33.670 align:middle line:84%
There will be a long line,
so what we basically do

00:17:33.670 --> 00:17:37.825 align:middle line:84%
is just doing all the chain rule
on that term and these terms.

00:17:37.825 --> 00:17:51.702 align:middle line:90%


00:17:51.702 --> 00:17:53.660 align:middle line:84%
STEVEN JOHNSON: And now
think of p as a scalar,

00:17:53.660 --> 00:17:56.180 align:middle line:84%
but in general, it could
be a vector or something.

00:17:56.180 --> 00:17:59.309 align:middle line:84%
And if it's the
gradient, of dG dp.

00:17:59.309 --> 00:18:07.850 align:middle line:90%


00:18:07.850 --> 00:18:10.630 align:middle line:84%
FRANK SCHAFER: Yeah, it's
a gradient transpose, yeah.

00:18:10.630 --> 00:18:13.376 align:middle line:84%
STEVEN JOHNSON: So what we were
calling G prime in the book.

00:18:13.376 --> 00:18:27.650 align:middle line:90%


00:18:27.650 --> 00:18:29.850 align:middle line:84%
FRANK SCHAFER: Yeah, let
me quickly write it down

00:18:29.850 --> 00:18:33.360 align:middle line:84%
because it's easy to do
mistakes on that part.

00:18:33.360 --> 00:18:37.260 align:middle line:90%


00:18:37.260 --> 00:18:40.134 align:middle line:84%
Oh, minus sign from the
minus we had before.

00:18:40.134 --> 00:18:57.745 align:middle line:90%


00:18:57.745 --> 00:19:00.120 align:middle line:84%
STEVEN JOHNSON: Maybe you
could write it a little bigger?

00:19:00.120 --> 00:19:01.260 align:middle line:90%
FRANK SCHAFER: Oh.

00:19:01.260 --> 00:19:01.760 align:middle line:90%
OK.

00:19:01.760 --> 00:19:23.830 align:middle line:90%


00:19:23.830 --> 00:19:26.890 align:middle line:84%
OK, I'll leave out the
utp's to save some space,

00:19:26.890 --> 00:19:29.928 align:middle line:84%
but every u here
depends on t and p.

00:19:29.928 --> 00:19:42.040 align:middle line:90%


00:19:42.040 --> 00:19:45.280 align:middle line:84%
I guess that's maybe
hard to read at the end,

00:19:45.280 --> 00:19:49.278 align:middle line:84%
but there's a dt
only missing here.

00:19:49.278 --> 00:19:52.223 align:middle line:84%
Is that readable for
you on that side?

00:19:52.223 --> 00:19:53.140 align:middle line:90%
AUDIENCE: [INAUDIBLE].

00:19:53.140 --> 00:19:54.057 align:middle line:90%
FRANK SCHAFER: I know.

00:19:54.057 --> 00:19:56.050 align:middle line:84%
I will repeat that
term in a second,

00:19:56.050 --> 00:19:58.540 align:middle line:84%
so you will see again
what's that term.

00:19:58.540 --> 00:20:04.060 align:middle line:90%


00:20:04.060 --> 00:20:08.500 align:middle line:84%
Right, so let's
call that basically,

00:20:08.500 --> 00:20:12.880 align:middle line:84%
like, the sensitivity,
call that, and yet, let's

00:20:12.880 --> 00:20:14.270 align:middle line:90%
simplify a bit the notation.

00:20:14.270 --> 00:20:15.460 align:middle line:90%
So that's my small g.

00:20:15.460 --> 00:20:20.080 align:middle line:84%
I'm sorry, my small g's and
small f's look fairly similar.

00:20:20.080 --> 00:20:24.490 align:middle line:84%
That's small gu, so
I'll always denote

00:20:24.490 --> 00:20:29.878 align:middle line:84%
by subscript with respect
to what we differentiate.

00:20:29.878 --> 00:20:32.170 align:middle line:84%
STEVEN JOHNSON: This is like
in the homework, you know,

00:20:32.170 --> 00:20:36.220 align:middle line:84%
has a few problems where partial
derivatives are subscripts.

00:20:36.220 --> 00:20:42.340 align:middle line:84%
FRANK SCHAFER: Small gp, and in
this term, what we can do here

00:20:42.340 --> 00:20:44.920 align:middle line:84%
is basically swap the
derivative with respect

00:20:44.920 --> 00:20:47.300 align:middle line:90%
to p and with respect to time.

00:20:47.300 --> 00:20:54.080 align:middle line:84%
So we get here a prime, right,
so because when we swap it,

00:20:54.080 --> 00:20:57.280 align:middle line:84%
we have du dp, which
is s, and then we

00:20:57.280 --> 00:21:00.040 align:middle line:90%
have the time derivative.

00:21:00.040 --> 00:21:13.100 align:middle line:84%
And we have here some fu times
s, and the last term is f--

00:21:13.100 --> 00:21:14.500 align:middle line:90%
that last term is fp.

00:21:14.500 --> 00:21:19.720 align:middle line:90%


00:21:19.720 --> 00:21:22.230 align:middle line:84%
OK, let me go to the center
because I think it's probably

00:21:22.230 --> 00:21:23.445 align:middle line:90%
better readable from there.

00:21:23.445 --> 00:21:25.320 align:middle line:84%
STEVEN JOHNSON: Can you
scroll the board down

00:21:25.320 --> 00:21:25.752 align:middle line:90%
so we can see more?

00:21:25.752 --> 00:21:26.752 align:middle line:90%
FRANK SCHAFER: Oh, Yeah.

00:21:26.752 --> 00:21:28.063 align:middle line:90%
STEVEN JOHNSON: All right.

00:21:28.063 --> 00:21:28.980 align:middle line:90%
FRANK SCHAFER: Oh, OK.

00:21:28.980 --> 00:21:32.385 align:middle line:90%


00:21:32.385 --> 00:21:33.600 align:middle line:90%
STEVEN JOHNSON: Thank you.

00:21:33.600 --> 00:21:34.600 align:middle line:90%
FRANK SCHAFER: Oh, yeah.

00:21:34.600 --> 00:21:35.990 align:middle line:90%
OK.

00:21:35.990 --> 00:21:38.780 align:middle line:84%
So, yeah, I wrote this second
term, which was probably

00:21:38.780 --> 00:21:40.220 align:middle line:90%
hard to read, a bit bigger.

00:21:40.220 --> 00:22:03.160 align:middle line:90%


00:22:03.160 --> 00:22:06.858 align:middle line:84%
So that's the second term
on the right-hand side and--

00:22:06.858 --> 00:22:08.650 align:middle line:84%
STEVEN JOHNSON: Could
I maybe say something

00:22:08.650 --> 00:22:09.860 align:middle line:90%
to try and clarify?

00:22:09.860 --> 00:22:10.930 align:middle line:90%
FRANK SCHAFER: Yup.

00:22:10.930 --> 00:22:16.440 align:middle line:84%
STEVEN JOHNSON:
So, right, so you

00:22:16.440 --> 00:22:19.650 align:middle line:84%
have this function you're
trying to differentiate,

00:22:19.650 --> 00:22:23.430 align:middle line:84%
and if you just differentiate
this p directly,

00:22:23.430 --> 00:22:26.550 align:middle line:84%
you get this term,
which is easy.

00:22:26.550 --> 00:22:29.010 align:middle line:84%
Right, if the function depends
directly on the parameters,

00:22:29.010 --> 00:22:30.480 align:middle line:90%
you can take that derivative.

00:22:30.480 --> 00:22:32.430 align:middle line:90%
Often, that derivative is 0.

00:22:32.430 --> 00:22:34.260 align:middle line:84%
This term, which
is easy, this is

00:22:34.260 --> 00:22:37.480 align:middle line:84%
your cost function, how does
it depend on the solution.

00:22:37.480 --> 00:22:39.503 align:middle line:90%
This term is hard.

00:22:39.503 --> 00:22:41.920 align:middle line:84%
How do you get the derivative
of the solution with respect

00:22:41.920 --> 00:22:43.180 align:middle line:90%
to the parameters?

00:22:43.180 --> 00:22:46.055 align:middle line:84%
So the goal and
adding 0 here is going

00:22:46.055 --> 00:22:48.430 align:middle line:84%
to be-- is going to give us
this extra degree of freedom,

00:22:48.430 --> 00:22:53.470 align:middle line:84%
lambda, that will-- if he's
clever in how he chooses this,

00:22:53.470 --> 00:22:55.540 align:middle line:84%
there'll be a trick
that allows him

00:22:55.540 --> 00:22:59.230 align:middle line:84%
to cancel this term
this term that's hard

00:22:59.230 --> 00:23:02.110 align:middle line:84%
and get a differential
equation for lambda.

00:23:02.110 --> 00:23:07.030 align:middle line:84%
So that's-- it's often
good to sort of show--

00:23:07.030 --> 00:23:08.410 align:middle line:84%
there's kind of
a magic step here

00:23:08.410 --> 00:23:10.330 align:middle line:84%
where you added
this lambda term,

00:23:10.330 --> 00:23:13.030 align:middle line:84%
and you know, sometimes
it's good to not

00:23:13.030 --> 00:23:15.580 align:middle line:84%
keep people in
suspense as to why

00:23:15.580 --> 00:23:17.140 align:middle line:90%
the hell did you add this term.

00:23:17.140 --> 00:23:19.010 align:middle line:90%
FRANK SCHAFER: That's true.

00:23:19.010 --> 00:23:19.790 align:middle line:90%
Yeah, exactly.

00:23:19.790 --> 00:23:20.330 align:middle line:90%
Yes.

00:23:20.330 --> 00:23:22.640 align:middle line:84%
One step before we can
actually do that trick

00:23:22.640 --> 00:23:26.720 align:middle line:84%
to eliminate the s, and
that's basically this

00:23:26.720 --> 00:23:32.030 align:middle line:84%
s prime that we got, which
we first have to get rid of.

00:23:32.030 --> 00:23:34.640 align:middle line:84%
Anybody has an idea,
maybe, how to do that,

00:23:34.640 --> 00:23:38.720 align:middle line:84%
like, our plans to
turn s prime into an s?

00:23:38.720 --> 00:23:45.750 align:middle line:90%


00:23:45.750 --> 00:23:48.200 align:middle line:84%
STEVEN JOHNSON:
18.01 question, you

00:23:48.200 --> 00:23:50.700 align:middle line:84%
have a derivative in an integral
you don't like, how can you

00:23:50.700 --> 00:23:51.300 align:middle line:90%
get rid of it?

00:23:51.300 --> 00:23:57.320 align:middle line:90%


00:23:57.320 --> 00:23:59.510 align:middle line:90%
AUDIENCE: Integrate by parts.

00:23:59.510 --> 00:24:04.550 align:middle line:84%
FRANK SCHAFER: Yeah, so we
integrate that term by parts,

00:24:04.550 --> 00:24:07.980 align:middle line:90%
and that gives us--

00:24:07.980 --> 00:24:29.220 align:middle line:90%


00:24:29.220 --> 00:24:31.380 align:middle line:84%
all right, so that's from
the integration by parts,

00:24:31.380 --> 00:24:34.290 align:middle line:84%
now the prime on
the lambda, which

00:24:34.290 --> 00:24:39.870 align:middle line:84%
will be exactly going towards
the ODE that Steven mentioned.

00:24:39.870 --> 00:24:52.870 align:middle line:90%


00:24:52.870 --> 00:24:55.120 align:middle line:84%
STEVEN JOHNSON: Time is
always a time derivative?

00:24:55.120 --> 00:24:55.930 align:middle line:90%
FRANK SCHAFER: Yes.

00:24:55.930 --> 00:24:57.138 align:middle line:90%
Yes, I should have said that.

00:24:57.138 --> 00:25:06.273 align:middle line:90%


00:25:06.273 --> 00:25:08.940 align:middle line:84%
STEVEN JOHNSON: OK, can you also
comment on the shape of lambda?

00:25:08.940 --> 00:25:11.933 align:middle line:84%
Like, why is lambda-- is lambda
a matrix, a vector, a scalar,

00:25:11.933 --> 00:25:13.350 align:middle line:84%
what is the-- why
is it transpose?

00:25:13.350 --> 00:25:18.440 align:middle line:84%
Like, what's the
size of this lambda?

00:25:18.440 --> 00:25:22.610 align:middle line:84%
FRANK SCHAFER: The size of this
lambda, so it's such that--

00:25:22.610 --> 00:25:28.140 align:middle line:84%
right, this output should
be a scalar, right,

00:25:28.140 --> 00:25:31.060 align:middle line:84%
because we optimize the
scalar cost function,

00:25:31.060 --> 00:25:34.550 align:middle line:84%
so the size of lambda
is basically in the--

00:25:34.550 --> 00:25:42.980 align:middle line:84%
well, in the adjoint space
of f, right-- or of u prime.

00:25:42.980 --> 00:25:45.380 align:middle line:84%
STEVEN JOHNSON: Yeah, so
the solution here is not

00:25:45.380 --> 00:25:46.730 align:middle line:90%
a scalar. u is not a scalar.

00:25:46.730 --> 00:25:49.160 align:middle line:90%
It's a column vector, right?

00:25:49.160 --> 00:25:51.480 align:middle line:84%
You have n equations
and n variables.

00:25:51.480 --> 00:25:53.980 align:middle line:84%
Lambda is a column vector with
the same number of components

00:25:53.980 --> 00:25:55.270 align:middle line:90%
and has the same--

00:25:55.270 --> 00:25:56.790 align:middle line:90%
it has the same shape as u.

00:25:56.790 --> 00:26:03.930 align:middle line:90%


00:26:03.930 --> 00:26:05.940 align:middle line:84%
FRANK SCHAFER: Yeah, so
what we want to do next

00:26:05.940 --> 00:26:08.160 align:middle line:84%
is basically insert
back this term

00:26:08.160 --> 00:26:12.240 align:middle line:90%
into that equation, so we--

00:26:12.240 --> 00:26:13.630 align:middle line:90%
that was our term here.

00:26:13.630 --> 00:26:18.690 align:middle line:84%
And so we take now this
part, insert it back,

00:26:18.690 --> 00:26:21.420 align:middle line:84%
and we're already going
to what's our goal,

00:26:21.420 --> 00:26:26.700 align:middle line:84%
and reorder all terms such
that we have this s separated,

00:26:26.700 --> 00:26:27.330 align:middle line:90%
basically.

00:26:27.330 --> 00:26:30.220 align:middle line:90%


00:26:30.220 --> 00:26:37.080 align:middle line:84%
So what we end up with
is basically this dG dp.

00:26:37.080 --> 00:26:53.570 align:middle line:90%


00:26:53.570 --> 00:26:55.820 align:middle line:84%
STEVEN JOHNSON: It's a little
funny because in Greek--

00:26:55.820 --> 00:26:58.910 align:middle line:84%
in linear algebra, we're used
to Greek letters being scalars,

00:26:58.910 --> 00:27:02.463 align:middle line:84%
but for adjoint methods,
the adjoint vector

00:27:02.463 --> 00:27:04.130 align:middle line:84%
is always called
lambda because it comes

00:27:04.130 --> 00:27:05.600 align:middle line:90%
from Lagrange multipliers.

00:27:05.600 --> 00:27:18.654 align:middle line:90%


00:27:18.654 --> 00:27:20.487 align:middle line:84%
FRANK SCHAFER: Oh, I'm
missing a prime here.

00:27:20.487 --> 00:27:25.160 align:middle line:90%


00:27:25.160 --> 00:27:27.230 align:middle line:84%
OK, let's write that
directly into one.

00:27:27.230 --> 00:27:43.410 align:middle line:90%


00:27:43.410 --> 00:27:45.810 align:middle line:84%
OK, so not much happened
here, basically.

00:27:45.810 --> 00:27:48.310 align:middle line:84%
It's just looking
at all the terms.

00:27:48.310 --> 00:27:51.420 align:middle line:90%
So we leave that term here.

00:27:51.420 --> 00:27:53.790 align:middle line:90%
This is that term.

00:27:53.790 --> 00:27:55.230 align:middle line:90%
That is that term.

00:27:55.230 --> 00:27:59.670 align:middle line:84%
We moved this term which doesn't
depend on f to the front,

00:27:59.670 --> 00:28:04.570 align:middle line:84%
and we had another term that
was depending on S here,

00:28:04.570 --> 00:28:07.950 align:middle line:84%
which we moved to the back,
basically, so these two

00:28:07.950 --> 00:28:11.720 align:middle line:90%
terms were, like, swapped.

00:28:11.720 --> 00:28:14.640 align:middle line:84%
AUDIENCE: So again
the goal here is--

00:28:14.640 --> 00:28:16.922 align:middle line:84%
the S, which is d u-- the
derivative of the solution's

00:28:16.922 --> 00:28:19.380 align:middle line:84%
expected parameter, that's the
annoying term you don't know

00:28:19.380 --> 00:28:21.588 align:middle line:84%
how to deal with, so you're
going to try and group it

00:28:21.588 --> 00:28:25.620 align:middle line:84%
all together and then make
that term 0 so that you

00:28:25.620 --> 00:28:28.380 align:middle line:90%
don't have to deal with it.

00:28:28.380 --> 00:28:37.690 align:middle line:84%
FRANK SCHAFER: Yeah, so we
are free to choose lambda,

00:28:37.690 --> 00:28:40.120 align:middle line:84%
so we can choose lambda
to be whatever we want.

00:28:40.120 --> 00:28:47.130 align:middle line:84%
So why don't we take basically
the choice lambda prime of T

00:28:47.130 --> 00:28:55.860 align:middle line:84%
is equal to minus
lambda T fu minus gu?

00:28:55.860 --> 00:28:58.920 align:middle line:84%
Right, if we take
that choice, we

00:28:58.920 --> 00:29:01.990 align:middle line:84%
will have that
this term vanishes,

00:29:01.990 --> 00:29:05.190 align:middle line:84%
and we can also,
since this is an ODE,

00:29:05.190 --> 00:29:09.310 align:middle line:84%
specify, well, basically
the initial condition.

00:29:09.310 --> 00:29:17.400 align:middle line:84%
So we can specify that lambda
of t should be equal to 0.

00:29:17.400 --> 00:29:21.180 align:middle line:84%
If we do that, we have
that this term cancels,

00:29:21.180 --> 00:29:26.580 align:middle line:84%
and one of the terms from
this integration by parts

00:29:26.580 --> 00:29:27.195 align:middle line:90%
also cancels.

00:29:27.195 --> 00:29:29.770 align:middle line:90%


00:29:29.770 --> 00:29:35.947 align:middle line:90%
Then it's the question of what--

00:29:35.947 --> 00:29:38.400 align:middle line:84%
STEVEN JOHNSON: And why did
you choose capital T to be

00:29:38.400 --> 00:29:40.393 align:middle line:90%
that, lambda capital T to be 0?

00:29:40.393 --> 00:29:42.310 align:middle line:84%
FRANK SCHAFER: Yeah,
that's the next question,

00:29:42.310 --> 00:29:43.143 align:middle line:90%
and that's because--

00:29:43.143 --> 00:29:45.870 align:middle line:90%


00:29:45.870 --> 00:29:51.760 align:middle line:84%
basically, what is s of t0,
which comes into that term,

00:29:51.760 --> 00:29:57.060 align:middle line:84%
so we know that's s of t0,
right, by definition of s,

00:29:57.060 --> 00:30:01.830 align:middle line:84%
it's the sensitivity
of the initial state

00:30:01.830 --> 00:30:04.083 align:middle line:90%
with respect to the parameter.

00:30:04.083 --> 00:30:06.000 align:middle line:84%
And, right, and we know
that the initial state

00:30:06.000 --> 00:30:08.515 align:middle line:84%
doesn't depend on the
parameter, so that term--

00:30:08.515 --> 00:30:09.015 align:middle line:90%


00:30:09.015 --> 00:30:09.610 align:middle line:84%
STEVEN JOHNSON: Or
it could, right?

00:30:09.610 --> 00:30:10.530 align:middle line:90%
FRANK SCHAFER: Oh, it could.

00:30:10.530 --> 00:30:11.580 align:middle line:84%
STEVEN JOHNSON: It could,
but whatever it is,

00:30:11.580 --> 00:30:12.480 align:middle line:90%
you know what it is.

00:30:12.480 --> 00:30:15.090 align:middle line:84%
Like, you don't-- you have the
initial condition in closed

00:30:15.090 --> 00:30:20.070 align:middle line:84%
form, right, so even if it
depends on some parameters,

00:30:20.070 --> 00:30:20.950 align:middle line:90%
you know what it is.

00:30:20.950 --> 00:30:23.970 align:middle line:84%
But here, here only the--
you're simplifying it

00:30:23.970 --> 00:30:27.540 align:middle line:84%
to-- only the
system of equations

00:30:27.540 --> 00:30:28.978 align:middle line:90%
depends on the parameters.

00:30:28.978 --> 00:30:29.770 align:middle line:90%
FRANK SCHAFER: Yes.

00:30:29.770 --> 00:30:31.720 align:middle line:90%
Yup.

00:30:31.720 --> 00:30:35.620 align:middle line:84%
Exactly, so either it's easy,
or it's, well, 0, basically.

00:30:35.620 --> 00:30:40.130 align:middle line:90%


00:30:40.130 --> 00:30:44.480 align:middle line:84%
Yes, nice, so we have in the end
that just this term, basically,

00:30:44.480 --> 00:30:48.422 align:middle line:84%
survives, so we have that
dg, the derivative of g with

00:30:48.422 --> 00:30:50.880 align:middle line:84%
respect to the parameters-- or
the gradient, in this case--

00:30:50.880 --> 00:30:54.180 align:middle line:84%
is equal to that derivative,
which is easy to compute.

00:30:54.180 --> 00:30:57.000 align:middle line:84%
It depends on this
lambda, and it

00:30:57.000 --> 00:31:01.530 align:middle line:84%
depends on the derivative
of f with respect to p.

00:31:01.530 --> 00:31:03.960 align:middle line:90%
That's a Jacobian, basically.

00:31:03.960 --> 00:31:08.820 align:middle line:90%
So let me let this here.

00:31:08.820 --> 00:31:11.970 align:middle line:84%
Right here, so what's
kind of the procedure

00:31:11.970 --> 00:31:14.160 align:middle line:84%
that we need to do
to solve it, right?

00:31:14.160 --> 00:31:20.190 align:middle line:84%
So when we solve
that integral, we

00:31:20.190 --> 00:31:22.800 align:middle line:84%
realize that we
first have to solve

00:31:22.800 --> 00:31:25.120 align:middle line:84%
this ordinary differential
equation, which

00:31:25.120 --> 00:31:26.370 align:middle line:90%
gets a special name, actually.

00:31:26.370 --> 00:31:27.990 align:middle line:90%
So this is the adjoint ODE.

00:31:27.990 --> 00:31:36.720 align:middle line:90%


00:31:36.720 --> 00:31:40.500 align:middle line:84%
But we also see that
the forward solution

00:31:40.500 --> 00:31:43.500 align:middle line:90%
is embedded in that ODE, right?

00:31:43.500 --> 00:31:47.950 align:middle line:84%
So to solve for the quantity
which we're interested in,

00:31:47.950 --> 00:31:52.390 align:middle line:84%
we basically have a
three-step procedure.

00:31:52.390 --> 00:32:02.538 align:middle line:90%
So we first solve for u of t.

00:32:02.538 --> 00:32:05.350 align:middle line:84%
Well, that's at least the
easiest way to think about it.

00:32:05.350 --> 00:32:09.270 align:middle line:84%
We first would solve
for the ODE for u of t,

00:32:09.270 --> 00:32:11.040 align:middle line:90%
then we have that information.

00:32:11.040 --> 00:32:17.805 align:middle line:84%
In the next step, we solve
for lambda of T. I can also--

00:32:17.805 --> 00:32:19.680 align:middle line:84%
STEVEN JOHNSON: Can you
write down ODEs again

00:32:19.680 --> 00:32:21.090 align:middle line:90%
and just these steps?

00:32:21.090 --> 00:32:24.000 align:middle line:84%
Just to summarize, you're
solving an ODE for u of t,

00:32:24.000 --> 00:32:27.470 align:middle line:84%
and write down the
ODE for lambda, maybe.

00:32:27.470 --> 00:32:42.618 align:middle line:90%


00:32:42.618 --> 00:32:49.320 align:middle line:84%
Maybe transpose it back,
so just a lambda prime.

00:32:49.320 --> 00:32:51.150 align:middle line:84%
Usually, you would
transpose it, right?

00:32:51.150 --> 00:32:51.900 align:middle line:90%
FRANK SCHAFER: OK.

00:32:51.900 --> 00:32:54.540 align:middle line:90%


00:32:54.540 --> 00:32:55.410 align:middle line:90%
Then it's f.

00:32:55.410 --> 00:32:56.610 align:middle line:84%
STEVEN JOHNSON: Just
transposing both sides

00:32:56.610 --> 00:32:57.825 align:middle line:90%
of that equation for lambda.

00:32:57.825 --> 00:33:06.110 align:middle line:90%


00:33:06.110 --> 00:33:07.215 align:middle line:90%
FRANK SCHAFER: gu, right?

00:33:07.215 --> 00:33:08.536 align:middle line:90%
STEVEN JOHNSON: gu transpose.

00:33:08.536 --> 00:33:11.718 align:middle line:90%


00:33:11.718 --> 00:33:13.760 align:middle line:84%
And there's an initial
condition, right, so for--

00:33:13.760 --> 00:33:16.010 align:middle line:84%
FRANK SCHAFER: Yeah, so that
has an initial condition.

00:33:16.010 --> 00:33:26.318 align:middle line:90%


00:33:26.318 --> 00:33:28.360 align:middle line:84%
Right, the initial condition
is kind of important

00:33:28.360 --> 00:33:31.810 align:middle line:84%
because we see, the first
ODE, we solve forwards

00:33:31.810 --> 00:33:34.750 align:middle line:84%
in time, and then
the adjoint ODE,

00:33:34.750 --> 00:33:37.390 align:middle line:84%
as you are now used to
probably from reverse-mode AD,

00:33:37.390 --> 00:33:39.470 align:middle line:84%
we have to solve
backwards in time.

00:33:39.470 --> 00:33:42.460 align:middle line:84%
So we have also this
forward-backwards workflow,

00:33:42.460 --> 00:33:45.490 align:middle line:84%
and then once we
know u and lambda,

00:33:45.490 --> 00:33:59.795 align:middle line:84%
we can actually solve the
integration for dG dp.

00:33:59.795 --> 00:34:01.420 align:middle line:84%
STEVEN JOHNSON: Can
you write that out?

00:34:01.420 --> 00:34:06.370 align:middle line:84%
Just because it simplifies
now, so several of the terms

00:34:06.370 --> 00:34:07.910 align:middle line:90%
have dropped out.

00:34:07.910 --> 00:34:09.770 align:middle line:90%
FRANK SCHAFER: Oh, just g--

00:34:09.770 --> 00:34:11.020 align:middle line:90%
STEVEN JOHNSON: And write big.

00:34:11.020 --> 00:34:21.320 align:middle line:90%


00:34:21.320 --> 00:34:23.060 align:middle line:90%
FRANK SCHAFER: OK, that's a--

00:34:23.060 --> 00:34:25.429 align:middle line:84%
STEVEN JOHNSON: No,
no, wait, there's no--

00:34:25.429 --> 00:34:27.050 align:middle line:84%
I thought you wanted to write
it in terms of lambda, right?

00:34:27.050 --> 00:34:28.050 align:middle line:90%
FRANK SCHAFER: Oh, yeah.

00:34:28.050 --> 00:34:29.900 align:middle line:84%
STEVEN JOHNSON: Yeah,
there's no s anymore.

00:34:29.900 --> 00:34:30.733 align:middle line:90%
FRANK SCHAFER: Wait.

00:34:30.733 --> 00:34:32.650 align:middle line:90%
Yeah, exactly.

00:34:32.650 --> 00:34:39.915 align:middle line:84%
And g-- yeah, that
should be right.

00:34:39.915 --> 00:34:42.540 align:middle line:84%
STEVEN JOHNSON: And then plus a
boundary-- oh, no, the boundary

00:34:42.540 --> 00:34:43.800 align:middle line:90%
term is 0 in your case.

00:34:43.800 --> 00:34:45.505 align:middle line:84%
FRANK SCHAFER:
Yeah, I set it to 0.

00:34:45.505 --> 00:34:47.130 align:middle line:84%
STEVEN JOHNSON: So
before you continue,

00:34:47.130 --> 00:34:48.172 align:middle line:90%
let me just compare this.

00:34:48.172 --> 00:34:50.639 align:middle line:84%
We talked about adjoint
methods in class before,

00:34:50.639 --> 00:34:54.570 align:middle line:84%
but for solving, like,
linear systems or nonlinear

00:34:54.570 --> 00:34:57.690 align:middle line:84%
equations where the dependence
on parameter, and it

00:34:57.690 --> 00:34:59.130 align:middle line:90%
was of the same flavor.

00:34:59.130 --> 00:35:01.770 align:middle line:84%
So first, you solve
the forward equations.

00:35:01.770 --> 00:35:04.230 align:middle line:84%
You solve ax equals
b for x, right,

00:35:04.230 --> 00:35:06.840 align:middle line:84%
and then we solved
an adjoint equation

00:35:06.840 --> 00:35:11.190 align:middle line:84%
that involved a transpose or a
transpose of a Jacobian, right?

00:35:11.190 --> 00:35:12.630 align:middle line:84%
But whatever the
adjoint equation

00:35:12.630 --> 00:35:15.415 align:middle line:90%
was of the same kind of--

00:35:15.415 --> 00:35:18.540 align:middle line:84%
same flavor and same size as
the original problem, but it

00:35:18.540 --> 00:35:19.647 align:middle line:90%
was linear, right?

00:35:19.647 --> 00:35:21.480 align:middle line:84%
And then once you have
the forward solution,

00:35:21.480 --> 00:35:23.730 align:middle line:84%
the adjoint solution, you
just take some dot products.

00:35:23.730 --> 00:35:25.890 align:middle line:84%
So here, you solve
an ODE, right,

00:35:25.890 --> 00:35:28.470 align:middle line:84%
and you're using whatever
your favorite ODE solver is.

00:35:28.470 --> 00:35:33.090 align:middle line:84%
Then you solve an adjoint ODE,
which is sort of transposed,

00:35:33.090 --> 00:35:36.660 align:middle line:84%
and it's linear now, even if
the original one was linear,

00:35:36.660 --> 00:35:38.830 align:middle line:84%
and it's backwards in time
if the original one was

00:35:38.830 --> 00:35:39.730 align:middle line:90%
forwards in time.

00:35:39.730 --> 00:35:42.520 align:middle line:84%
And then once you have the
forward solution u of t

00:35:42.520 --> 00:35:44.560 align:middle line:84%
and the adjoint
solution lambda of T,

00:35:44.560 --> 00:35:48.340 align:middle line:84%
you take some dot products,
which for functions, the analog

00:35:48.340 --> 00:35:50.230 align:middle line:90%
of that is integrals, right?

00:35:50.230 --> 00:35:53.740 align:middle line:84%
And so everything in that
sense becomes easy now.

00:35:53.740 --> 00:35:56.800 align:middle line:84%
Independent-- even if you
have 10,000 parameters,

00:35:56.800 --> 00:36:01.570 align:middle line:84%
you solve one forward ODE, one
adjoint ODE of the same size,

00:36:01.570 --> 00:36:03.170 align:middle line:90%
and then some dot products.

00:36:03.170 --> 00:36:05.560 align:middle line:84%
So this is why you can
compute derivatives

00:36:05.560 --> 00:36:11.290 align:middle line:84%
with a huge number of
parameters efficiently,

00:36:11.290 --> 00:36:14.140 align:middle line:84%
and they're kind of always of
the same flavor, these adjoint,

00:36:14.140 --> 00:36:16.155 align:middle line:90%
reverse-mode things.

00:36:16.155 --> 00:36:18.280 align:middle line:84%
FRANK SCHAFER: Yes, and
now there are a few tricks,

00:36:18.280 --> 00:36:20.830 align:middle line:84%
basically, to evaluate
that efficiently,

00:36:20.830 --> 00:36:24.550 align:middle line:84%
or different styles to
evaluate that equation.

00:36:24.550 --> 00:36:27.220 align:middle line:84%
The first thing to
notice is basically

00:36:27.220 --> 00:36:31.090 align:middle line:84%
that we don't necessarily, for
this continuous adjoint method,

00:36:31.090 --> 00:36:35.830 align:middle line:84%
have to store and compute the
full continuous solution of u

00:36:35.830 --> 00:36:41.240 align:middle line:84%
of t because an ODE is
basically reversible.

00:36:41.240 --> 00:36:44.830 align:middle line:84%
And so we can solve
the ODE forwards,

00:36:44.830 --> 00:36:48.070 align:middle line:84%
just save the final
value of that ODE,

00:36:48.070 --> 00:36:52.300 align:middle line:84%
and then solve it basically
in lockstep backwards together

00:36:52.300 --> 00:36:54.790 align:middle line:90%
with lambda to have--

00:36:54.790 --> 00:36:58.030 align:middle line:84%
well, to avoid this kind of
storing the continuous solution

00:36:58.030 --> 00:37:01.450 align:middle line:90%
of u of t at all times.

00:37:01.450 --> 00:37:04.990 align:middle line:84%
And everybody happy with
that kind of trick, right?

00:37:04.990 --> 00:37:05.695 align:middle line:90%
So--

00:37:05.695 --> 00:37:08.195 align:middle line:84%
STEVEN JOHNSON: I'm not happy
with that kind of trick, like,

00:37:08.195 --> 00:37:10.211 align:middle line:84%
if it's chaotic or
something like that.

00:37:10.211 --> 00:37:10.270 align:middle line:84%
FRANK SCHAFER: But
ODEs are reversible--

00:37:10.270 --> 00:37:11.990 align:middle line:84%
STEVEN JOHNSON: Solving
forwards might be exponentially

00:37:11.990 --> 00:37:13.610 align:middle line:84%
decaying, and
solving it backwards

00:37:13.610 --> 00:37:14.902 align:middle line:90%
might be exponentially growing.

00:37:14.902 --> 00:37:16.850 align:middle line:84%
So that trick doesn't
always work, right?

00:37:16.850 --> 00:37:18.017 align:middle line:90%
FRANK SCHAFER: Yes, exactly.

00:37:18.017 --> 00:37:21.180 align:middle line:84%
That trick has to be done with
care, and there are some--

00:37:21.180 --> 00:37:23.840 align:middle line:84%
right, so that trick, just
to visualize it again,

00:37:23.840 --> 00:37:27.350 align:middle line:84%
it basically says, if we
have some ODE at u of t0

00:37:27.350 --> 00:37:32.120 align:middle line:84%
and we solve it to some
final time, u of capital T,

00:37:32.120 --> 00:37:35.150 align:middle line:84%
I was saying, you can
just store this value

00:37:35.150 --> 00:37:37.640 align:middle line:90%
and start solving it backwards.

00:37:37.640 --> 00:37:40.340 align:middle line:84%
But depending on
your physical system,

00:37:40.340 --> 00:37:42.170 align:middle line:84%
well, your trajectory
might not--

00:37:42.170 --> 00:37:44.540 align:middle line:84%
because your numerical solver
might not be reversible,

00:37:44.540 --> 00:37:47.673 align:middle line:84%
you might deviate from
your true solution.

00:37:47.673 --> 00:37:49.340 align:middle line:84%
And then if you solve
it for long times,

00:37:49.340 --> 00:37:52.110 align:middle line:84%
again, backwards, that might
be numerically very bad,

00:37:52.110 --> 00:37:54.260 align:middle line:84%
and so the first thing
people are usually doing

00:37:54.260 --> 00:37:58.880 align:middle line:84%
is introducing so-called
checkpoints, which only means,

00:37:58.880 --> 00:38:02.060 align:middle line:84%
once you solve it back and
you reach your checkpoint, you

00:38:02.060 --> 00:38:05.930 align:middle line:84%
basically reset your
solution to the state which

00:38:05.930 --> 00:38:06.650 align:middle line:90%
you had forwards.

00:38:06.650 --> 00:38:09.860 align:middle line:84%
So that reduces a bit
the memory consumption.

00:38:09.860 --> 00:38:13.280 align:middle line:84%
And the second trick people are
doing, if it's really unstable

00:38:13.280 --> 00:38:16.190 align:middle line:84%
and your ODE solver is not
working, then what you would do

00:38:16.190 --> 00:38:17.900 align:middle line:84%
is maybe also have
these checkpoints

00:38:17.900 --> 00:38:20.240 align:middle line:84%
but always just store
a continuous solution

00:38:20.240 --> 00:38:24.600 align:middle line:84%
within the checkpoints that you
solve forwards again in time.

00:38:24.600 --> 00:38:27.330 align:middle line:84%
STEVEN JOHNSON: So just
another comment on that,

00:38:27.330 --> 00:38:29.060 align:middle line:84%
so one thing we
have to be always

00:38:29.060 --> 00:38:30.560 align:middle line:84%
careful about in
presenting things

00:38:30.560 --> 00:38:33.000 align:middle line:84%
is explaining the solution
before we explain the problem,

00:38:33.000 --> 00:38:33.500 align:middle line:90%
right?

00:38:33.500 --> 00:38:36.410 align:middle line:84%
So the issue here
that you're trying

00:38:36.410 --> 00:38:38.750 align:middle line:84%
to solve with going
backwards and reversing

00:38:38.750 --> 00:38:41.240 align:middle line:84%
and so forth is--
so in principle,

00:38:41.240 --> 00:38:44.390 align:middle line:84%
you solve it forward,
right, to find u of t,

00:38:44.390 --> 00:38:46.850 align:middle line:84%
and then you solve it
backwards to find lambda T,

00:38:46.850 --> 00:38:48.770 align:middle line:84%
and then you take some
dot products, right?

00:38:48.770 --> 00:38:52.400 align:middle line:84%
The problem you can run
into is that then you

00:38:52.400 --> 00:38:56.090 align:middle line:84%
need to store u of t
not just at the endpoint

00:38:56.090 --> 00:38:59.900 align:middle line:84%
but at all the intermediate
times, which is fine if u of t

00:38:59.900 --> 00:39:01.730 align:middle line:84%
is just a small
number of parameters.

00:39:01.730 --> 00:39:04.520 align:middle line:84%
And you just store it
at a bunch of points,

00:39:04.520 --> 00:39:07.820 align:middle line:84%
and then you basically
can interpolate

00:39:07.820 --> 00:39:09.320 align:middle line:90%
with polynomials in between.

00:39:09.320 --> 00:39:12.230 align:middle line:84%
Right, this is how
ODE solvers work.

00:39:12.230 --> 00:39:14.810 align:middle line:84%
But this is a problem
if you're solving

00:39:14.810 --> 00:39:18.380 align:middle line:84%
a huge system of ODEs,
where, say, it's really

00:39:18.380 --> 00:39:20.790 align:middle line:90%
a discretized PDE, for example.

00:39:20.790 --> 00:39:24.290 align:middle line:84%
So you have u is, say, the
electric field at every point

00:39:24.290 --> 00:39:27.830 align:middle line:84%
in space as a function of time
in some big computational cell,

00:39:27.830 --> 00:39:29.390 align:middle line:90%
then solving--

00:39:29.390 --> 00:39:32.390 align:middle line:84%
then usually when you solve it,
you march it forward in time,

00:39:32.390 --> 00:39:34.340 align:middle line:84%
and you kind of just
only store the solution

00:39:34.340 --> 00:39:35.420 align:middle line:90%
at the current time.

00:39:35.420 --> 00:39:39.290 align:middle line:84%
But here, you need to
store all the solutions

00:39:39.290 --> 00:39:42.330 align:middle line:84%
at all the intermediate times
all the way until the end

00:39:42.330 --> 00:39:45.360 align:middle line:84%
and then go backwards, and
you can run out of memory.

00:39:45.360 --> 00:39:48.620 align:middle line:84%
And so this is the basic
problem with adjoint methods

00:39:48.620 --> 00:39:52.430 align:middle line:84%
and when you have,
like, evolving in time

00:39:52.430 --> 00:39:54.140 align:middle line:84%
or going through
big recurrences,

00:39:54.140 --> 00:39:56.210 align:middle line:84%
is you need to store all
the intermediate ones.

00:39:56.210 --> 00:39:58.760 align:middle line:84%
And so there's all
these tricks to try

00:39:58.760 --> 00:40:00.800 align:middle line:84%
and only store some of
the intermediate values

00:40:00.800 --> 00:40:04.100 align:middle line:84%
at some checkpoints and kind of
reconstruct things on the fly

00:40:04.100 --> 00:40:09.560 align:middle line:84%
as you integrate lambda T
backwards so that you don't

00:40:09.560 --> 00:40:13.580 align:middle line:84%
need to store everything,
but that's sort of the issue

00:40:13.580 --> 00:40:15.200 align:middle line:84%
that you're
struggling with here.

00:40:15.200 --> 00:40:19.850 align:middle line:84%
But for small ODEs, to only
have a few things at any time,

00:40:19.850 --> 00:40:21.740 align:middle line:84%
you just store the
whole solution.

00:40:21.740 --> 00:40:22.545 align:middle line:90%
It's not that hard.

00:40:22.545 --> 00:40:23.420 align:middle line:90%
FRANK SCHAFER: Right.

00:40:23.420 --> 00:40:25.220 align:middle line:90%
True.

00:40:25.220 --> 00:40:27.950 align:middle line:84%
Yeah, well, for small
ODEs that contain

00:40:27.950 --> 00:40:31.470 align:middle line:84%
some parametric function, that's
very expensive to evaluate,

00:40:31.470 --> 00:40:31.970 align:middle line:90%
right?

00:40:31.970 --> 00:40:34.190 align:middle line:84%
Like, what Chris
is basically doing

00:40:34.190 --> 00:40:36.990 align:middle line:84%
is putting a neural network
inside the drift function,

00:40:36.990 --> 00:40:40.310 align:middle line:84%
so even if the ODE
itself looks very simple,

00:40:40.310 --> 00:40:42.600 align:middle line:84%
if you have a neural
network in each timestep,

00:40:42.600 --> 00:40:45.380 align:middle line:84%
you will have to store all
intermediate computations also,

00:40:45.380 --> 00:40:46.730 align:middle line:90%
and outputs of that.

00:40:46.730 --> 00:40:51.560 align:middle line:84%
So, yeah, that makes
the continuous adjoint

00:40:51.560 --> 00:40:54.490 align:middle line:90%
very meaningful.

00:40:54.490 --> 00:41:00.830 align:middle line:84%
Yeah, right, so there's
a third kind of trick

00:41:00.830 --> 00:41:06.822 align:middle line:84%
which can be used to simplify
that workflow even a bit more.

00:41:06.822 --> 00:41:09.280 align:middle line:84%
Basically, that's the first
trick, and as we now discussed,

00:41:09.280 --> 00:41:10.750 align:middle line:90%
it's not always applicable.

00:41:10.750 --> 00:41:14.750 align:middle line:84%
But if it's applicable, it can
be nice and very efficient.

00:41:14.750 --> 00:41:20.050 align:middle line:84%
The third trick is basically to
look at this integration term

00:41:20.050 --> 00:41:28.280 align:middle line:84%
and basically realize that
an integration can also

00:41:28.280 --> 00:41:33.596 align:middle line:84%
be phrased as a solution to an
ordinary differential equation.

00:41:33.596 --> 00:41:44.770 align:middle line:84%
So I'm not sure if
that was covered or--

00:41:44.770 --> 00:41:47.800 align:middle line:84%
but, yeah, let's say
I have a function

00:41:47.800 --> 00:41:53.510 align:middle line:84%
F. I want to integrate it as
[INAUDIBLE] prime to delta t.

00:41:53.510 --> 00:41:57.225 align:middle line:90%


00:41:57.225 --> 00:41:59.350 align:middle line:84%
But everybody agrees, that's
kind of the same form?

00:41:59.350 --> 00:42:04.780 align:middle line:84%
So we have some integration,
and now the claim

00:42:04.780 --> 00:42:07.780 align:middle line:84%
is that we can write that
as an ordinary differential

00:42:07.780 --> 00:42:13.000 align:middle line:90%
equation small f of t.

00:42:13.000 --> 00:42:16.360 align:middle line:84%
And, yeah, now we want
to basically apply

00:42:16.360 --> 00:42:21.320 align:middle line:84%
Euler's method to that, and so
if we apply Euler's method--

00:42:21.320 --> 00:42:24.640 align:middle line:84%
STEVEN JOHNSON: So, wait,
stop here for a second.

00:42:24.640 --> 00:42:26.660 align:middle line:84%
So before you again
give the solution,

00:42:26.660 --> 00:42:29.050 align:middle line:84%
so you're going to write
a differential equation w

00:42:29.050 --> 00:42:30.460 align:middle line:90%
prime equals F of T, right?

00:42:30.460 --> 00:42:34.910 align:middle line:84%
So wt is going to
be a new variable.

00:42:34.910 --> 00:42:37.330 align:middle line:84%
What's the initial condition
of that, that you're

00:42:37.330 --> 00:42:38.205 align:middle line:90%
going to want to use?

00:42:38.205 --> 00:42:40.413 align:middle line:84%
Again, at the end, you're
going to want to write down

00:42:40.413 --> 00:42:42.670 align:middle line:84%
a differential equation
whose solution gives that

00:42:42.670 --> 00:42:44.815 align:middle line:90%
integral, so what--

00:42:44.815 --> 00:42:46.690 align:middle line:84%
you're going to write
a differential equation

00:42:46.690 --> 00:42:49.510 align:middle line:90%
dw dt equals little f of t.

00:42:49.510 --> 00:42:51.265 align:middle line:84%
What initial condition
should you use?

00:42:51.265 --> 00:42:54.340 align:middle line:90%


00:42:54.340 --> 00:42:56.220 align:middle line:90%
Any guesses?

00:42:56.220 --> 00:42:58.150 align:middle line:90%
To get-- to turn it back--

00:42:58.150 --> 00:43:00.120 align:middle line:84%
so its solution will
give you the same thing

00:43:00.120 --> 00:43:03.090 align:middle line:84%
as that definite
integral from t0 to t.

00:43:03.090 --> 00:43:08.535 align:middle line:90%


00:43:08.535 --> 00:43:09.530 align:middle line:90%
AUDIENCE: [INAUDIBLE].

00:43:09.530 --> 00:43:12.828 align:middle line:84%
STEVEN JOHNSON: 0, OK,
so but at what time?

00:43:12.828 --> 00:43:13.370 align:middle line:90%
AUDIENCE: t0.

00:43:13.370 --> 00:43:22.530 align:middle line:84%
STEVEN JOHNSON: At t0, so w of
t0 equals 0, and then what's--

00:43:22.530 --> 00:43:24.510 align:middle line:84%
capital F of T
equals what, then?

00:43:24.510 --> 00:43:28.140 align:middle line:84%
So now the integral you
want, the first line,

00:43:28.140 --> 00:43:30.930 align:middle line:90%
capital-- is that an I or an F?

00:43:30.930 --> 00:43:31.973 align:middle line:90%
I can't--

00:43:31.973 --> 00:43:33.390 align:middle line:84%
FRANK SCHAFER:
That's an F. Sorry.

00:43:33.390 --> 00:43:34.470 align:middle line:84%
STEVEN JOHNSON: That's
a capital F, OK.

00:43:34.470 --> 00:43:35.520 align:middle line:90%
FRANK SCHAFER: Sorry.

00:43:35.520 --> 00:43:38.250 align:middle line:84%
STEVEN JOHNSON: It has
the second line going kind

00:43:38.250 --> 00:43:39.450 align:middle line:90%
of-- looks a little bit--

00:43:39.450 --> 00:43:42.120 align:middle line:84%
OK, so anyway, so your capital
F of T, your integral that you

00:43:42.120 --> 00:43:44.040 align:middle line:90%
want is what in terms of w?

00:43:44.040 --> 00:43:45.920 align:middle line:84%
So if you have-- the
differential equation,

00:43:45.920 --> 00:43:48.840 align:middle line:84%
its initial condition
t equals 0 is 0--

00:43:48.840 --> 00:43:49.950 align:middle line:90%
t0 is 0.

00:43:49.950 --> 00:43:54.770 align:middle line:84%
Its derivative is little f
of t, so then the integral

00:43:54.770 --> 00:43:56.686 align:middle line:90%
is what now?

00:43:56.686 --> 00:43:58.120 align:middle line:90%
AUDIENCE: [INAUDIBLE].

00:43:58.120 --> 00:44:00.820 align:middle line:84%
FRANK SCHAFER: Yeah, right,
so I can write that integral.

00:44:00.820 --> 00:44:02.860 align:middle line:84%
Let me write one step
in between, basically,

00:44:02.860 --> 00:44:04.180 align:middle line:90%
and kind of slide it.

00:44:04.180 --> 00:44:06.862 align:middle line:90%


00:44:06.862 --> 00:44:09.070 align:middle line:84%
STEVEN JOHNSON: You're kind
of discretizing it first,

00:44:09.070 --> 00:44:10.528 align:middle line:84%
so before you
discretize it, I want

00:44:10.528 --> 00:44:12.987 align:middle line:84%
to make sure they understand
the connection between the ODE

00:44:12.987 --> 00:44:13.800 align:middle line:90%
and the integral.

00:44:13.800 --> 00:44:16.440 align:middle line:84%
So don't discretize
it yet, all right?

00:44:16.440 --> 00:44:19.773 align:middle line:84%
Just, this is an exact
relationship, right?

00:44:19.773 --> 00:44:22.315 align:middle line:84%
FRANK SCHAFER: Oh, so you just
want to have plugged in the w,

00:44:22.315 --> 00:44:22.570 align:middle line:90%
so--

00:44:22.570 --> 00:44:24.362 align:middle line:84%
STEVEN JOHNSON: Yeah,
yeah, it's w of what?

00:44:24.362 --> 00:44:27.200 align:middle line:90%


00:44:27.200 --> 00:44:28.200 align:middle line:90%
No, there's no integral.

00:44:28.200 --> 00:44:29.550 align:middle line:90%
It's equal to w of--

00:44:29.550 --> 00:44:34.270 align:middle line:90%


00:44:34.270 --> 00:44:36.130 align:middle line:90%
it's w of capital T, right?

00:44:36.130 --> 00:44:37.030 align:middle line:90%
That's--

00:44:37.030 --> 00:44:37.600 align:middle line:90%
FRANK SCHAFER: Oh, right.

00:44:37.600 --> 00:44:37.830 align:middle line:90%
STEVEN JOHNSON: Right.

00:44:37.830 --> 00:44:38.450 align:middle line:84%
FRANK SCHAFER:
OK, now I see what

00:44:38.450 --> 00:44:39.700 align:middle line:90%
you want you want me to write.

00:44:39.700 --> 00:44:41.710 align:middle line:90%
STEVEN JOHNSON: Right.

00:44:41.710 --> 00:44:44.050 align:middle line:84%
So the point is, if you
have a differential equation

00:44:44.050 --> 00:44:47.740 align:middle line:84%
w prime equals f of t, the
solution is just the integral.

00:44:47.740 --> 00:44:50.600 align:middle line:84%
w is just the integral of
f, which is what you want,

00:44:50.600 --> 00:44:53.350 align:middle line:84%
and then you put the initial
condition at t0 equals 0.

00:44:53.350 --> 00:44:55.480 align:middle line:84%
That's the left edge
of the integral,

00:44:55.480 --> 00:44:58.360 align:middle line:84%
and then the final integral
you want is just w of t.

00:44:58.360 --> 00:45:01.990 align:middle line:84%
So that's-- he's turning--
the integral you want is just

00:45:01.990 --> 00:45:06.210 align:middle line:84%
a differential equation, is
this differential equation,

00:45:06.210 --> 00:45:09.518 align:middle line:84%
and now you're going to
discretize it, right?

00:45:09.518 --> 00:45:11.560 align:middle line:84%
FRANK SCHAFER: Right, now
if I'm discretizing it,

00:45:11.560 --> 00:45:15.180 align:middle line:84%
I will see the same,
basically, as for--

00:45:15.180 --> 00:45:16.533 align:middle line:90%
yeah, for an Euler step.

00:45:16.533 --> 00:45:17.700 align:middle line:90%
I should write it down, or--

00:45:17.700 --> 00:45:19.560 align:middle line:84%
STEVEN JOHNSON: Sure, if
you want to discretize it.

00:45:19.560 --> 00:45:21.870 align:middle line:84%
Yeah, I just wanted to--
because not everyone here

00:45:21.870 --> 00:45:24.522 align:middle line:84%
has done a lot of
differential equations, right,

00:45:24.522 --> 00:45:25.980 align:middle line:84%
or maybe hasn't
done them recently,

00:45:25.980 --> 00:45:29.730 align:middle line:84%
so I want to make
sure they understand,

00:45:29.730 --> 00:45:31.230 align:middle line:90%
understood that trick.

00:45:31.230 --> 00:45:49.115 align:middle line:90%


00:45:49.115 --> 00:45:50.140 align:middle line:90%
It's good.

00:45:50.140 --> 00:45:51.986 align:middle line:90%
Take it all the way up now.

00:45:51.986 --> 00:45:52.962 align:middle line:90%
FRANK SCHAFER: Oh, OK.

00:45:52.962 --> 00:45:54.426 align:middle line:90%
STEVEN JOHNSON: [INAUDIBLE].

00:45:54.426 --> 00:46:02.240 align:middle line:90%


00:46:02.240 --> 00:46:06.470 align:middle line:84%
FRANK SCHAFER: Right, so
I'm basically writing down

00:46:06.470 --> 00:46:09.110 align:middle line:84%
what the Euler steps would
be in the discretization

00:46:09.110 --> 00:46:10.130 align:middle line:90%
for that integral.

00:46:10.130 --> 00:46:13.620 align:middle line:90%


00:46:13.620 --> 00:46:19.590 align:middle line:84%
That's the first, and then
I just keep iterating.

00:46:19.590 --> 00:46:32.010 align:middle line:90%


00:46:32.010 --> 00:46:33.545 align:middle line:90%
Let's think a moment for--

00:46:33.545 --> 00:46:46.410 align:middle line:90%


00:46:46.410 --> 00:46:50.670 align:middle line:84%
So these are n Euler steps
iterated on the function.

00:46:50.670 --> 00:46:54.620 align:middle line:90%


00:46:54.620 --> 00:46:57.043 align:middle line:84%
There's an i missing,
probably, somewhere.

00:46:57.043 --> 00:47:01.780 align:middle line:90%


00:47:01.780 --> 00:47:03.910 align:middle line:84%
Right, because once
I have my first step,

00:47:03.910 --> 00:47:08.200 align:middle line:84%
the time changes, and then
that's flagged back also

00:47:08.200 --> 00:47:09.850 align:middle line:90%
into the function.

00:47:09.850 --> 00:47:12.100 align:middle line:84%
STEVEN JOHNSON: OK, so this
is really an approximation

00:47:12.100 --> 00:47:13.350 align:middle line:90%
for the original thing, right?

00:47:13.350 --> 00:47:18.190 align:middle line:84%
So you're writing "equals"
here, but just to be clear,

00:47:18.190 --> 00:47:19.990 align:middle line:84%
right, the original
equation is--

00:47:19.990 --> 00:47:22.200 align:middle line:84%
you have an integral and
the differential equation.

00:47:22.200 --> 00:47:24.378 align:middle line:84%
That's an exact
relationship, and now you're

00:47:24.378 --> 00:47:26.170 align:middle line:84%
going to write the
discrete analog of that,

00:47:26.170 --> 00:47:27.420 align:middle line:90%
or the discrete approximation.

00:47:27.420 --> 00:47:30.460 align:middle line:84%
So w of t plus delta t
is really approximately

00:47:30.460 --> 00:47:34.710 align:middle line:84%
equal to w of t plus t delta
t, and this is approximately.

00:47:34.710 --> 00:47:36.940 align:middle line:84%
FRANK SCHAFER: Yeah,
if I do it again--

00:47:36.940 --> 00:47:40.300 align:middle line:90%
something like an Euler step.

00:47:40.300 --> 00:47:44.560 align:middle line:84%
STEVEN JOHNSON: So you can
approximate the derivative

00:47:44.560 --> 00:47:47.830 align:middle line:84%
by a difference, and then
the integral of your--

00:47:47.830 --> 00:47:50.125 align:middle line:84%
is essentially
approximated by a sum.

00:47:50.125 --> 00:47:55.670 align:middle line:90%


00:47:55.670 --> 00:47:57.710 align:middle line:84%
FRANK SCHAFER: Right,
and so this now has,

00:47:57.710 --> 00:48:00.740 align:middle line:84%
then, also, I mean,
the typical form

00:48:00.740 --> 00:48:04.070 align:middle line:84%
of what you would do numerically
to solve an integral, right?

00:48:04.070 --> 00:48:11.490 align:middle line:84%
So it's-- yeah, you have the
function value at different

00:48:11.490 --> 00:48:14.700 align:middle line:84%
points, and then with the
discretization that you use

00:48:14.700 --> 00:48:16.382 align:middle line:90%
and summed it all up.

00:48:16.382 --> 00:48:18.090 align:middle line:84%
STEVEN JOHNSON: This
is a very simple way

00:48:18.090 --> 00:48:21.710 align:middle line:84%
to do an approximate integral
numerically, just like--

00:48:21.710 --> 00:48:25.470 align:middle line:84%
Euler integration for ODEs
and this approximate sum

00:48:25.470 --> 00:48:28.260 align:middle line:84%
for an integral, you should
never, ever do this in reality,

00:48:28.260 --> 00:48:31.350 align:middle line:84%
almost, because there's
exponentially more

00:48:31.350 --> 00:48:34.200 align:middle line:84%
accurate ways to integrate
approximate integrals.

00:48:34.200 --> 00:48:37.800 align:middle line:84%
But it's a nice way to
really simply think of--

00:48:37.800 --> 00:48:40.080 align:middle line:84%
if you're confused by
integrals and derivatives,

00:48:40.080 --> 00:48:43.110 align:middle line:84%
you can think of them as
differences and sums or sums

00:48:43.110 --> 00:48:44.740 align:middle line:90%
and differences, right?

00:48:44.740 --> 00:48:46.490 align:middle line:84%
FRANK SCHAFER: Yeah,
right, that statement

00:48:46.490 --> 00:48:48.947 align:middle line:84%
is true for both, right,
the Euler solver for ODEs

00:48:48.947 --> 00:48:50.780 align:middle line:84%
and the kind of derivation
for the integral.

00:48:50.780 --> 00:48:54.223 align:middle line:90%


00:48:54.223 --> 00:48:56.390 align:middle line:84%
Yeah, that's actually the
full derivation, I'm sure.

00:48:56.390 --> 00:48:58.807 align:middle line:84%
STEVEN JOHNSON: Yeah, so does
everyone see that basically,

00:48:58.807 --> 00:49:00.860 align:middle line:84%
then, if you plug in,
the initial t is 0.

00:49:00.860 --> 00:49:02.903 align:middle line:90%
w of t0 is 0.

00:49:02.903 --> 00:49:05.320 align:middle line:84%
Right, so and then why don't
you take it one step further?

00:49:05.320 --> 00:49:10.650 align:middle line:84%
So then w of t0, if w of t0
is 0, the first term is 0.

00:49:10.650 --> 00:49:14.400 align:middle line:84%
The second term is approximately
the integral, right,

00:49:14.400 --> 00:49:16.530 align:middle line:84%
so it's just a restating
the same thing, just

00:49:16.530 --> 00:49:17.650 align:middle line:90%
with sums and differences.

00:49:17.650 --> 00:49:22.548 align:middle line:84%
So this is-- so the solution of
the ODE is really the integral.

00:49:22.548 --> 00:49:23.340 align:middle line:90%
FRANK SCHAFER: Yes.

00:49:23.340 --> 00:49:27.260 align:middle line:90%


00:49:27.260 --> 00:49:29.300 align:middle line:84%
Yeah, to summarize
that, so we can have,

00:49:29.300 --> 00:49:33.005 align:middle line:84%
then, basically all the
three methods above.

00:49:33.005 --> 00:49:34.880 align:middle line:84%
STEVEN JOHNSON: So can
you finish and write--

00:49:34.880 --> 00:49:35.750 align:middle line:90%
so the point at the--

00:49:35.750 --> 00:49:37.250 align:middle line:84%
what you're going
to do then is just

00:49:37.250 --> 00:49:41.717 align:middle line:84%
merge the solution of the
adjoint ODE with that integral

00:49:41.717 --> 00:49:44.300 align:middle line:84%
in the third step, so instead
of doing them in separate steps,

00:49:44.300 --> 00:49:47.630 align:middle line:84%
so you can maybe just
write down the derivative.

00:49:47.630 --> 00:49:48.618 align:middle line:90%
It has a--

00:49:48.618 --> 00:49:49.910 align:middle line:90%
FRANK SCHAFER: That one, right?

00:49:49.910 --> 00:49:51.327 align:middle line:84%
STEVEN JOHNSON:
Yeah, so what's w?

00:49:51.327 --> 00:49:56.448 align:middle line:84%
w is now going to be-- no, no,
w is going to be lambda and--

00:49:56.448 --> 00:49:57.365 align:middle line:90%
OK, it doesn't matter.

00:49:57.365 --> 00:50:03.652 align:middle line:90%


00:50:03.652 --> 00:50:05.860 align:middle line:84%
FRANK SCHAFER: Yeah, depending
on the other side of--

00:50:05.860 --> 00:50:07.140 align:middle line:84%
STEVEN JOHNSON: You want to go
in the other direction, right?

00:50:07.140 --> 00:50:08.190 align:middle line:90%
Yeah.

00:50:08.190 --> 00:50:10.720 align:middle line:84%
FRANK SCHAFER: Probably
want to solve it like that.

00:50:10.720 --> 00:50:12.095 align:middle line:84%
STEVEN JOHNSON:
But the point is,

00:50:12.095 --> 00:50:14.460 align:middle line:84%
you think of this as
a coupled ODE, for w

00:50:14.460 --> 00:50:16.990 align:middle line:84%
along with the adjoint
ODE for lambda prime.

00:50:16.990 --> 00:50:19.830 align:middle line:84%
So if you write down the lambda
prime underneath, right--

00:50:19.830 --> 00:50:32.610 align:middle line:90%


00:50:32.610 --> 00:50:33.360 align:middle line:90%
FRANK SCHAFER: gu.

00:50:33.360 --> 00:50:43.047 align:middle line:90%


00:50:43.047 --> 00:50:45.630 align:middle line:84%
STEVEN JOHNSON: So you can think
of this as one system of ODEs

00:50:45.630 --> 00:50:52.050 align:middle line:84%
for a vector that contains
w and lambda, right,

00:50:52.050 --> 00:50:54.330 align:middle line:84%
so you just do the
two things together

00:50:54.330 --> 00:50:57.885 align:middle line:90%
instead of the separate steps.

00:50:57.885 --> 00:51:01.680 align:middle line:84%
Oh, and then I guess,
yeah, you could also

00:51:01.680 --> 00:51:03.870 align:middle line:84%
integrate the original
equation backwards as well.

00:51:03.870 --> 00:51:07.310 align:middle line:90%


00:51:07.310 --> 00:51:09.865 align:middle line:84%
All right, so now your unknowns
are w, lambda, and u, so,

00:51:09.865 --> 00:51:12.365 align:middle line:84%
like, one big vector of those
three things stacked together.

00:51:12.365 --> 00:51:18.930 align:middle line:90%


00:51:18.930 --> 00:51:20.700 align:middle line:84%
And the advantage
of this is that you

00:51:20.700 --> 00:51:23.730 align:middle line:84%
don't need to store
the lambdas, I guess,

00:51:23.730 --> 00:51:26.070 align:middle line:84%
and maybe the u's. If you
were able to integrate

00:51:26.070 --> 00:51:28.770 align:middle line:84%
the whole thing backwards, you
don't need to store anything.

00:51:28.770 --> 00:51:32.520 align:middle line:84%
You just pass this to
your ODE integrator,

00:51:32.520 --> 00:51:34.980 align:middle line:84%
and it only keeps track
of your current step.

00:51:34.980 --> 00:51:36.840 align:middle line:84%
And it just walks
from beginning to end,

00:51:36.840 --> 00:51:39.540 align:middle line:84%
and at the end of
the day, your w

00:51:39.540 --> 00:51:40.950 align:middle line:90%
is the integral that you want--

00:51:40.950 --> 00:51:42.785 align:middle line:90%
is the derivative.

00:51:42.785 --> 00:51:45.750 align:middle line:84%
FRANK SCHAFER: Yeah, so that's
the most memory-efficient one

00:51:45.750 --> 00:51:51.150 align:middle line:84%
to basically solve for the
sensitivity dG dp in the end.

00:51:51.150 --> 00:51:55.060 align:middle line:90%


00:51:55.060 --> 00:51:55.660 align:middle line:90%
Right.

00:51:55.660 --> 00:51:56.327 align:middle line:90%
That's all for--

00:51:56.327 --> 00:51:58.900 align:middle line:84%
STEVEN JOHNSON: So I
think we should maybe

00:51:58.900 --> 00:52:00.620 align:middle line:84%
take a break for
the-- or in a minute,

00:52:00.620 --> 00:52:03.250 align:middle line:84%
but are you basically--
is this basically it?

00:52:03.250 --> 00:52:04.900 align:middle line:84%
Or are you going to
show some examples?

00:52:04.900 --> 00:52:06.692 align:middle line:84%
FRANK SCHAFER: I would
have the integration

00:52:06.692 --> 00:52:08.810 align:middle line:84%
of that numerically,
but it takes another 10,

00:52:08.810 --> 00:52:10.155 align:middle line:90%
15 minutes at least.

00:52:10.155 --> 00:52:12.655 align:middle line:84%
STEVEN JOHNSON: Yeah, I see you
want to show an example of--

00:52:12.655 --> 00:52:14.530 align:middle line:84%
yeah, I mean, we can do
that after the break,

00:52:14.530 --> 00:52:17.290 align:middle line:84%
but maybe we can just take a
break for a couple minutes now.

00:52:17.290 --> 00:52:19.510 align:middle line:84%
But do people have
questions before we--

00:52:19.510 --> 00:52:21.220 align:middle line:90%
about this step?

00:52:21.220 --> 00:52:23.372 align:middle line:84%
You have forward ODE,
adjoint ODE, and then

00:52:23.372 --> 00:52:25.330 align:middle line:84%
a dot product, which is
basically the integral.

00:52:25.330 --> 00:52:28.210 align:middle line:84%
And then there's these tricks to
try and basically combine them

00:52:28.210 --> 00:52:30.460 align:middle line:84%
into one ODE that
you solve instead

00:52:30.460 --> 00:52:33.280 align:middle line:84%
of having to store u of
T, store lambda of T,

00:52:33.280 --> 00:52:34.345 align:middle line:90%
and then do the integral.

00:52:34.345 --> 00:52:37.552 align:middle line:90%


00:52:37.552 --> 00:52:41.448 align:middle line:84%
AUDIENCE: So say you have
some data point that you're

00:52:41.448 --> 00:52:47.210 align:middle line:84%
comparing to something you're
looking for, would you--

00:52:47.210 --> 00:52:50.130 align:middle line:84%
so if the system's not
chaotic, you'd probably

00:52:50.130 --> 00:52:52.130 align:middle line:84%
want to start it at
the final data point

00:52:52.130 --> 00:52:56.018 align:middle line:84%
and integrate backwards
with the lambda equation,

00:52:56.018 --> 00:52:58.680 align:middle line:84%
but if it is, then
would you just

00:52:58.680 --> 00:53:01.826 align:middle line:84%
want to integrate forward
to get the full solution

00:53:01.826 --> 00:53:05.214 align:middle line:90%
and then just solve that?

00:53:05.214 --> 00:53:07.375 align:middle line:84%
STEVEN JOHNSON: Yeah, so
suppose capital G-- wait,

00:53:07.375 --> 00:53:11.020 align:middle line:84%
so suppose capital G is a sum
and not an integral, right?

00:53:11.020 --> 00:53:13.668 align:middle line:84%
So you're-- or you have a
bunch of delta functions,

00:53:13.668 --> 00:53:15.460 align:middle line:84%
is another way of
thinking about it, right?

00:53:15.460 --> 00:53:18.850 align:middle line:84%
So basically, you're
comparing the solution u of T

00:53:18.850 --> 00:53:21.520 align:middle line:84%
to, say, some known
solution, some measured data,

00:53:21.520 --> 00:53:23.350 align:middle line:90%
at only a discrete set of times.

00:53:23.350 --> 00:53:26.320 align:middle line:84%
So now G is a sum,
right, so one way

00:53:26.320 --> 00:53:29.380 align:middle line:84%
to do it would be to
compute u of T, lambda of T,

00:53:29.380 --> 00:53:32.260 align:middle line:90%
and then just do the sum.

00:53:32.260 --> 00:53:36.010 align:middle line:84%
But is there a way to combine
that into a single ODE

00:53:36.010 --> 00:53:39.160 align:middle line:84%
if now capital G
is not an integral,

00:53:39.160 --> 00:53:43.480 align:middle line:84%
it's a discrete summation
over a set of times?

00:53:43.480 --> 00:53:45.880 align:middle line:84%
FRANK SCHAFER: Yeah,
basically, you can write it--

00:53:45.880 --> 00:53:48.963 align:middle line:84%
go to this kind of
discrete formulation.

00:53:48.963 --> 00:53:50.380 align:middle line:84%
Probably the easiest
way, I think,

00:53:50.380 --> 00:53:54.190 align:middle line:84%
to think about it is
that these describe

00:53:54.190 --> 00:53:56.170 align:middle line:84%
the kind of continuous
changes that you want

00:53:56.170 --> 00:54:01.630 align:middle line:84%
to have in the cost
function, and so

00:54:01.630 --> 00:54:04.840 align:middle line:84%
what you will have if
you just have your cost

00:54:04.840 --> 00:54:08.350 align:middle line:84%
function compared at
discrete time points you--

00:54:08.350 --> 00:54:10.300 align:middle line:84%
right, you basically
have your solution.

00:54:10.300 --> 00:54:15.950 align:middle line:84%
And then at some point,
you compare your cost,

00:54:15.950 --> 00:54:19.600 align:middle line:84%
and so what will happen
is that you just solve--

00:54:19.600 --> 00:54:22.780 align:middle line:84%
you will have a
backward solution

00:54:22.780 --> 00:54:28.340 align:middle line:84%
starting from here for
the adjoint and for u.

00:54:28.340 --> 00:54:32.680 align:middle line:84%
And then at these time points
where you have your comparison,

00:54:32.680 --> 00:54:36.590 align:middle line:84%
you basically have to--
you can update your state

00:54:36.590 --> 00:54:40.910 align:middle line:84%
by the change that comes in just
from those nodes, basically.

00:54:40.910 --> 00:54:45.510 align:middle line:84%
So we'll just have,
like, partial derivatives

00:54:45.510 --> 00:54:49.570 align:middle line:84%
added at those time points
to your adjoint state.

00:54:49.570 --> 00:54:51.558 align:middle line:84%
STEVEN JOHNSON: Yeah,
so, I mean, ODE solvers,

00:54:51.558 --> 00:54:53.350 align:middle line:84%
you can tell them to
stop at certain times,

00:54:53.350 --> 00:54:54.808 align:middle line:84%
so as you go
backwards in time, you

00:54:54.808 --> 00:54:56.523 align:middle line:84%
can just have it
stop at that time

00:54:56.523 --> 00:54:58.690 align:middle line:84%
and then update something
and then stop at that time

00:54:58.690 --> 00:54:59.560 align:middle line:90%
and add--

00:54:59.560 --> 00:55:01.660 align:middle line:84%
at the next time
and add something to

00:55:01.660 --> 00:55:03.520 align:middle line:84%
accumulate your sum
as you go along.

00:55:03.520 --> 00:55:06.190 align:middle line:84%
But mathematically,
you could basically

00:55:06.190 --> 00:55:09.260 align:middle line:84%
think of it as jump conditions
that occur at those times,

00:55:09.260 --> 00:55:14.530 align:middle line:84%
and so there's also ways to
include those in differential

00:55:14.530 --> 00:55:17.050 align:middle line:84%
equation solvers, where,
oh, every once in a while,

00:55:17.050 --> 00:55:19.630 align:middle line:90%
these times, something jumps.

00:55:19.630 --> 00:55:21.470 align:middle line:84%
There's a discontinuity
in the solution,

00:55:21.470 --> 00:55:24.978 align:middle line:84%
and then in between, it's not
changing at all, in this case.

00:55:24.978 --> 00:55:26.808 align:middle line:90%
FRANK SCHAFER: Yup.

00:55:26.808 --> 00:55:28.350 align:middle line:84%
STEVEN JOHNSON:
Probably, it's easier

00:55:28.350 --> 00:55:32.527 align:middle line:84%
just to say let me integrate
it up to this time,

00:55:32.527 --> 00:55:34.110 align:middle line:84%
get that solution
up to the next time,

00:55:34.110 --> 00:55:36.240 align:middle line:84%
and just have a callback
at those discrete times

00:55:36.240 --> 00:55:37.560 align:middle line:90%
and just accumulate the sum.

00:55:37.560 --> 00:55:39.907 align:middle line:90%


00:55:39.907 --> 00:55:41.907 align:middle line:84%
AUDIENCE: One more question
about that, so maybe

00:55:41.907 --> 00:55:44.590 align:middle line:84%
cycling back to the idea of
matrix calculus, so here,

00:55:44.590 --> 00:55:46.360 align:middle line:90%
everything is still--

00:55:46.360 --> 00:55:48.850 align:middle line:84%
basically, if you
want to generalize it,

00:55:48.850 --> 00:55:50.710 align:middle line:84%
say you have a
matrix-valued ODE,

00:55:50.710 --> 00:55:55.404 align:middle line:84%
then your lambdas become
some matrix-valued thing.

00:55:55.404 --> 00:55:58.446 align:middle line:84%
So they live in the dual
state to whatever you

00:55:58.446 --> 00:56:01.390 align:middle line:84%
want to take the derivative of,
and as long as it sort of makes

00:56:01.390 --> 00:56:06.420 align:middle line:84%
sense, the ODEs that come out
at the other end, that will

00:56:06.420 --> 00:56:07.920 align:middle line:90%
give you the right sensitivity?

00:56:07.920 --> 00:56:08.590 align:middle line:90%
Is that--

00:56:08.590 --> 00:56:09.465 align:middle line:90%
STEVEN JOHNSON: Yeah.

00:56:09.465 --> 00:56:11.690 align:middle line:84%
Yeah, so if you have
a more general space--

00:56:11.690 --> 00:56:14.710 align:middle line:84%
so u, u lives in some
arbitrary vector space,

00:56:14.710 --> 00:56:17.920 align:middle line:84%
right, then you have to replace
the lambda transpose there

00:56:17.920 --> 00:56:20.230 align:middle line:90%
with an inner product, right?

00:56:20.230 --> 00:56:27.190 align:middle line:84%
And then this fu transpose
is some more general adjoint

00:56:27.190 --> 00:56:31.630 align:middle line:84%
operator in that Hilbert
space, right, so all of this

00:56:31.630 --> 00:56:32.180 align:middle line:90%
still works.

00:56:32.180 --> 00:56:34.097 align:middle line:84%
So you can think of this
just-- it's literally

00:56:34.097 --> 00:56:35.140 align:middle line:90%
the same derivation.

00:56:35.140 --> 00:56:36.730 align:middle line:84%
You can think of it
as just a change.

00:56:36.730 --> 00:56:39.220 align:middle line:84%
It's just, lambda
transpose is now

00:56:39.220 --> 00:56:42.430 align:middle line:90%
notation for that inner product.

00:56:42.430 --> 00:56:43.900 align:middle line:84%
It's just-- you
have to understand

00:56:43.900 --> 00:56:46.030 align:middle line:84%
what the notation means
in a more general sense,

00:56:46.030 --> 00:56:49.547 align:middle line:84%
but it's literally
the same, same thing.

00:56:49.547 --> 00:56:51.380 align:middle line:84%
I don't know, have you
done anything where--

00:56:51.380 --> 00:56:53.250 align:middle line:84%
I guess you're doing
quantum systems,

00:56:53.250 --> 00:56:56.837 align:middle line:84%
so probably, your states
live in some more--

00:56:56.837 --> 00:56:58.670 align:middle line:84%
FRANK SCHAFER: Density
matrices, yeah, sure.

00:56:58.670 --> 00:57:00.200 align:middle line:84%
STEVEN JOHNSON: --live in
more general Hilbert spaces

00:57:00.200 --> 00:57:00.980 align:middle line:90%
all the time.

00:57:00.980 --> 00:57:03.677 align:middle line:90%
FRANK SCHAFER: Yeah.

00:57:03.677 --> 00:57:05.760 align:middle line:84%
Yeah, and numerically, you
can also then vectorize

00:57:05.760 --> 00:57:06.843 align:middle line:90%
the density matrix, right?

00:57:06.843 --> 00:57:09.580 align:middle line:90%
And they have-- yeah.

00:57:09.580 --> 00:57:11.790 align:middle line:84%
Yeah, rewrite, basically,
also the definitions

00:57:11.790 --> 00:57:14.220 align:middle line:84%
of f to deal with
vectors depending

00:57:14.220 --> 00:57:16.690 align:middle line:84%
on your implementation,
but, yeah, right.

00:57:16.690 --> 00:57:18.940 align:middle line:84%
STEVEN JOHNSON: Yeah, so we
talked about that as well.

00:57:18.940 --> 00:57:21.510 align:middle line:84%
So one way of dealing with
matrices and other things

00:57:21.510 --> 00:57:23.700 align:middle line:84%
is just to turn them into
column vectors, right,

00:57:23.700 --> 00:57:28.200 align:middle line:84%
but if it's more natural
in your system space

00:57:28.200 --> 00:57:30.510 align:middle line:84%
to talk about
matrices, then you'd

00:57:30.510 --> 00:57:33.180 align:middle line:84%
really rather deal with
that Hilbert space directly.

00:57:33.180 --> 00:57:34.055 align:middle line:90%
FRANK SCHAFER: Right.

00:57:34.055 --> 00:57:37.290 align:middle line:84%
STEVEN JOHNSON: And if these
are PDEs, so u is now not--

00:57:37.290 --> 00:57:39.337 align:middle line:84%
is like a function
of space, right?

00:57:39.337 --> 00:57:40.920 align:middle line:84%
Of course, on a
computer, you probably

00:57:40.920 --> 00:57:43.770 align:middle line:84%
discretized it, but
it's nice conceptually

00:57:43.770 --> 00:57:45.540 align:middle line:84%
to think about this
as a function of space

00:57:45.540 --> 00:57:47.100 align:middle line:90%
and this inner--

00:57:47.100 --> 00:57:49.770 align:middle line:84%
lambda is also a function
of space, for example,

00:57:49.770 --> 00:57:51.510 align:middle line:84%
and then this inner
product is some kind

00:57:51.510 --> 00:57:53.470 align:middle line:90%
of integral over a space.

00:57:53.470 --> 00:57:56.970 align:middle line:84%
So it is really powerful
to be able to not

00:57:56.970 --> 00:57:59.097 align:middle line:84%
have to turn everything
into a column vector

00:57:59.097 --> 00:58:00.555 align:middle line:84%
when you want to
do linear algebra.

00:58:00.555 --> 00:58:06.490 align:middle line:90%


00:58:06.490 --> 00:58:10.330 align:middle line:84%
Got a five-minute break, so
we'll come back at 12:10.

00:58:10.330 --> 00:58:13.460 align:middle line:84%
And I could go then, or if
you want to show some more

00:58:13.460 --> 00:58:15.080 align:middle line:90%
examples, you can do that.

00:58:15.080 --> 00:58:16.630 align:middle line:90%
But--

00:58:16.630 --> 00:58:20.000 align:middle line:90%