Im Wintersemster 2018/19 habe ich die Vorlesung “Lineare Algebra 1” gehalten. Hier die lecture notes dazu:

March 27, 2019

## Handout/Lecture Notes “Lineare Algebra 1”

Posted by Dirk under Math, Teaching, Uncategorized | Tags: lecture notes, linear algebra |Leave a Comment

December 13, 2018

## An index-free way to take the gradient of a neural network

Posted by Dirk under machine learning, Math, Optimization, Uncategorized | Tags: chain rule, kronecker product, machine learning, neural network, optimization, vectorization |1 Comment

Taking the derivative of the loss function of a neural network can be quite cumbersome. Even taking the derivative of a single layer in a neural network often results in expressions cluttered with indices. In this post I’d like to show an index-free way to do it.

Consider the map where is the weight matrix, is the bias, is the input, and is the activation function. Usually represents both a scalar function (i.e. mapping ) and the function mapping which applies in each coordinate. In training neural networks, we would try to optimize for best parameters and . So we need to take the derivative with respect to and . So we consider the map

This map is a concatenation of the map and and since the former map is linear in the joint variable , the derivative of should be pretty simple. What makes the computation a little less straightforward is the fact the we are usually not used to view matrix-vector products as linear maps in but in . So let’s rewrite the thing:

There are two particular notions which come in handy here: The Kronecker product of matrices and the vectorization of matrices. Vectorization takes some given columnwise and maps it by

The Kronecker product of matrices and is a matrix in

We will build on the following marvelous identity: For matrices , , of compatible size we have that

Why is this helpful? It allows us to rewrite

So we can also rewrite

So our map mapping can be rewritten as

mapping . Since is just a concatenation of applied coordinate wise and a linear map, now given as a matrix, the derivative of (i.e. the Jacobian, a matrix in ) is calculated simply as

While this representation of the derivative of a single layer of a neural network with respect to its parameters is not particularly simple, it is still index free and moreover, straightforward to implement in languages which provide functions for the Kronecker product and vectorization. If you do this, make sure to take advantage of sparse matrices for the identity matrix and the diagonal matrix as otherwise the memory of your computer will be flooded with zeros.

Now let’s add a scalar function (e.g. to produce a scalar loss that we can minimize), i.e. we consider the map

The derivative is obtained by just another application of the chain rule:

If we want to take gradients, we just transpose the expression and get

Note that the right hand side is indeed vector in and hence, can be reshaped to a tupel of an matrix and an vector.

A final remark: the Kronecker product is related to tensor products. If and represent linear maps and , respectively, then represents the tensor product of the maps, . This relation to tensor products and tensors explains where the tensor in TensorFlow comes from.

September 13, 2018

## The fundamental theorem of optimal transport

Posted by Dirk under Math, Optimization, Regularization | Tags: calculus of variations, optimal transport |Leave a Comment

The problem of optimal transport of mass from one distribution to another can be stated in many forms. Here is the formulation going back to Kantorovich: We have two measurable sets and , coming with two measures and . We also have a function which assigns a transport cost, i.e. is the cost that it takes to carry one unit of mass from point to . What we want is a plan that says where the mass in should be placed in (or vice versa). There are different ways to formulate this mathematically.

A simple way is to look for a map which says that thet mass in should be moved to . While natural, there is a serious problem with this: What if not all mass at should go to the same point in ? This happens in simple situations where all mass in sits in just one point, but there are at least two different points in where mass should end up. This is not going to work with a map as above. So, the map is not flexible enough to model all kinds of transport we may need.

What we want is a way to distribute mass from one point in to the whole set . This looks like we want maps which map points in to functions on , i.e. something like where stands for some set of functions on . We can de-curry this function to some by . That’s good in principle, be we still run into problems when the target mass distribution is singular in the sense that is a “continuous” set and there are single points in that carry some mass according to . Since we are in the world of measure theory already, the way out suggests itself: Instead of a function on we look for a measure on as a transport plan.

The demand that we should carry *all* of the mass in to reach *all* of is formulated by marginals. For simplicity we just write these constraints as

(with the understanding that the first equation really means that for all continuous function it holds that ).

This leads us to the full transport problem

There is the following theorem which characterizes optimality of a plan and which is the topic of this post:

Theorem 1 (Fundamental theorem of optimal transport)Under some technicalities we can say that a plan which fulfills the marginal constraints is optimal if and only if one of the following equivalent conditions is satisfied:

- The support of is -cyclically monotone.
- There exists a -concave function such that its -superdifferential contains the support of , i.e. .

A few clarifications: The technicalities involve continuity, integrability, and boundedness conditions of and integrability conditions on the marginals. The full theorem can be found as Theorem 1.13 in A user’s guide to optimal transport by Ambrosio and Gigli. Also the notions -cyclically monotone, -concave and -superdifferential probably need explanation. We start with a simpler notion: -monotonicity:

Definition 2A set is-monotone, if for all it holds that

If you find it unclear what this has to do with monotonicity, look at this example:

Example 1Let and let be the usual scalar product. Then -monotonicity is the condition that for all it holds that

which may look more familiar. Indeed, when and are subset of the real line, the above conditions means that the set somehow “moves up in ” if we “move right in ”. So -monotonicity for is something like “monotonically increasing”. Similarly, for , -monotonicity means “monotonically decreasing”.

You may say that both and are strange cost functions and I can’t argue with that. But here comes: ( being the euclidean norm) seems more natural, right? But if we have a transport plan for this for some marginals and we also have

i.e., the transport cost for differs from the one for only by a constant independent of , so may well use the latter.

The fundamental theorem of optimal transport uses the notion of -cyclical monotonicity which is stronger that just -monotonicity:

Definition 3A set is -cyclically monotone, if for all , and all permutations of it holds that

For we get back the notion of -monotonicity.

Definition 4A function is-concaveif there exists some function such that

This definition of -concavity resembles the notion of convex conjugate:

Example 2Again using we get that a function is -concave if

and, as an infimum over linear functions, is clearly concave in the usual way.

Definition 5The -superdifferential of a-concavefunction is

where is the

-conjugateof defined by

Again one may look at and observe that the -superdifferential is the usual superdifferential related to the supergradient of concave functions (there is a Wikipedia page for subgradient only, but the concept is the same with reversed signs in some sense).

Now let us sketch the proof of the fundamental theorem of optimal transport: \medskip

*Proof (of the fundamental theorem of optimal transport).* Let be an optimal transport plan. We aim to show that is -cyclically monotone and assume the contrary. That is, we assume that there are points and a permutation such that

We aim to construct a such that is still feasible but has a smaller transport cost. To do so, we note that continuity of implies that there are neighborhoods of and of such that for all and it holds that

We use this to construct a better plan : Take the mass of in the sets and shift it around. The full construction is a little messy to write down: Define a probability measure on the product as the product of the measures . Now let and be the projections of onto and , respectively, and set

where denotes the pushforward of measures. Note that the new measure is signed and that fulfills

- is a non-negative measure
- is feasible, i.e. has the correct marginals

which, all together, gives a contradiction to optimality of . The implication of item 1 to item 2 of the theorem is not really related to optimal transport but a general fact about -concavity and -cyclical monotonicity (c.f.~this previous blog post of mine where I wrote a similar statement for convexity). So let us just prove the implication from item 2 to optimality of : Let fulfill item 2, i.e. is feasible and is contained in the -superdifferential of some -concave function . Moreover let be any feasible transport plan. We aim to show that . By definition of the -superdifferential and the -conjugate we have

Since by assumption, this gives

which shows the claim.

Corollary 6If is a measure on which is supported on a -superdifferential of a -concave function, then is an optimal transport plan for its marginals with respect to the transport cost .

June 6, 2018

## Best stepsizes for Douglas-Rachford for Lipschitz + strongly montone

Posted by Dirk under Math, Optimization, Uncategorized | Tags: algorithms, Douglas-Rachford, monotone inclusion, stepsize |Leave a Comment

This is a short follow up on my last post where I wrote about the sweet spot of the stepsize of the Douglas-Rachford iteration. For the case -Lipschitz + -strongly monotone, the iteration with stepsize converges linear with rate

Here is animated plot of this contraction factor depending on and and acts as time variable:

What is interesting is, that this factor has increasing or decreasing in depending on the values of and .

For each pair there is a best and also a smallest contraction factor . Here are plots of these quantities:

Comparing the plot of te optimal contraction factor to the animated plot above, you see that the right choice of the stepsize matters a lot.

June 6, 2018

## The sweet spot of the Douglas-Rachford iteration

Posted by Dirk under Math, Optimization | Tags: algorithms, Douglas-Rachford, monotone inclusion, stepsize |1 Comment

I blogged about the Douglas-Rachford method before here and here. It’s a method to solve monotone inclusions in the form

with monotone multivalued operators from a Hilbert space into itself. Using the resolvent and the reflector , the Douglas-Rachford iteration is concisely written as

The convergence of the method has been clarified is a number of papers, see, e.g.

Lions, Pierre-Louis, and Bertrand Mercier. “Splitting algorithms for the sum of two nonlinear operators.” SIAM Journal on Numerical Analysis 16.6 (1979): 964-979.

for the first treatment in the context of monotone operators and

Svaiter, Benar Fux. “On weak convergence of the Douglas–Rachford method.” SIAM Journal on Control and Optimization 49.1 (2011): 280-287.

for a recent very general convergence result.

Since is monotone if is monotone and , we can introduce a stepsize for the Douglas-Rachford iteration

It turns out, that this stepsize matters a lot in practice; too small and too large stepsizes lead to slow convergence. It is a kind of folk wisdom, that there is “sweet spot” for the stepsize. In a recent preprint Quoc Tran-Dinh and I investigated this sweet spot in the simple case of linear operators and and this tweet has a visualization.

A few days ago Walaa Moursi and Lieven Vandenberghe published the preprint “Douglas-Rachford splitting for a Lipschitz continuous and a strongly monotone operator” and derived some linear convergence rates in the special case they mention in the title. One result (Theorem 4.3) goes as follows: If is monotone and Lipschitz continuous with constant and is maximally monotone and -strongly monotone, than the Douglas-Rachford iterates converge strongly to a solution with a linear rate

This is a surprisingly complicated expression, but there is a nice thing about it: It allows to optimize for the stepsize! The rate depends on the stepsize as

and the two plots of this function below show the sweet spot clearly.

If one knows the Lipschitz constant of and the constant of strong monotonicity of , one can minimize to get on optimal stepsize (in the sense that the guaranteed contraction factor is as small as possible). As Moursi and Vandenberghe explain in their Remark 5.4, this optimization involves finding the root of a polynomial of degree 5, so it is possible but cumbersome.

Now I wonder if there is any hope to show that the adaptive stepsize Quoc and I proposed here (which basically amounts to in the case of single valued – note that the role of and is swapped in our paper) is able to find the sweet spot (experimentally it does).

<p

June 4, 2018

## Subgradients, cyclical monotonicity and the fundamental theorem of calculus

Posted by Dirk under Math, Uncategorized | Tags: calculus, convex functions, convexity, fundamental theorem of calculus |1 Comment

The fundamental theorem of calculus relates the derivative of a function to the function itself via an integral. A little bit more precise, it says that one can recover a function from its derivative up to an additive constant (on a simply connected domain).

In one space dimension, one can fix some in the domain (which has to be an interval) and then set

Then with .

Actually, a similar claim is true in higher space dimensions: If is defined on a simply connected domain in we can recover from its gradient up to an additive constant as follows: Select some and set

for any path from to . Then it holds under suitable conditions that

And now for something completely different: Convex functions and subgradients.

A function on is convex if for every there exists a *subgradient* such that for all one has the *subgradient inequality*

Writing this down for and with interchanged roles (and as corresponding subgradient to ), we see that

In other words: For a convex function it holds that the subgradient is a (multivalued) *monotone mapping*. Recall that a multivalued map is monotone, if for every and it holds that . It is not hard to see that not every monotone map is actually a subgradient of a convex function (not even, if we go to “maximally monotone maps”, a notion that we sweep under the rug in this post). A simple counterexample is a (singlevalued) linear monotone map represented by

(which can not be a subgradient of some , since it is not symmetric).

Another hint that monotonicity of a map does not imply that the map is a subgradient is that subgradients have some stronger properties than monotone maps. Let us write down the subgradient inequalities for a number of points :

If we sum all these up, we obtain

This property is called *-cyclical monotonicity*. In these terms we can say that a subgradient of a convex function is cyclical monotone, which means that it is -cyclically monotone for every integer .

By a remarkable result by Rockafellar, the converse is also true:

Theorem 1 (Rockafellar, 1966)Let by a cyclically monotone map. Then there exists a convex function such that .

Even more remarkable, the proof is somehow “just an application of the fundamental theorem of calculus” where we recover a function by its subgradient (up to an additive constant that depends on the basepoint).

*Proof:* we aim to “reconstruct” from . The trick is to choose some base point and corresponding and set

where the supremum is taken over all integers and all pairs . As a supremum of affine functions is clearly convex (even lower semicontinuous) and since is cyclically monotone (this shows that is *proper*, i.e. not equal to everywhere). Finally, for we have

with the supremum taken over all integers and all pairs . The right hand side is equal to and this shows that is indeed convex.

Where did we use the fundamental theorem of calculus? Let us have another look at equation~(0). Just for simplicity, let us denote . Now consider a path from to and points with . Then the term inside the supremum of~(0) equals

This is Riemannian sum for an integral of the form . By monotonicity of , we increase this sum, if we add another point (e.g. , and hence, the supremum does converge to the integral, i.e.~(0) is equal to

where is any path from to .

May 29, 2018

## Mixing norms the Luxemburg way

Posted by Dirk under Math, Uncategorized | Tags: Luxemburg norm, normed spaces |1 Comment

In my last blog post I wrote about Luxemburg norms which are constructions to get norms out of a non-homogeneous function which satisfies and are increasing and convex (and thus, continuous). The definition of the Luxemburg norm in this case is

and we saw that if .

Actually, one can have a little more flexibility in the construction as one can also use different functions in each coordinate: If are functions as above, we can define

and it still holds that if and only if . The proof that this construction indeed gives a norm is the same as in the one in the previous post.

This construction allows, among other things, to construct norms that behave like different -norms in different directions. Here is a simple example: In the case of we can split the variables into two groups, say the first variables and the last variables. The first group shall be treated with a -norm and the second group with a -norm. For the respective Luxemburg norm one has

Note that there is a different way to do a similar thing, namely a *mixed norm* defined as

As any two norms, these are equivalent, but they induce a different geometry. On top of that, one could in principle also consider functionals

which is again something different.

A bit more general, we may consider all these three conditions for general partitions of the index sets and a different exponent for each set.

Here are some observations on the differences:

- For the Luxemburg norm the only thing that counts are the exponents (or functions ). If you partition the index set into two parts but give the same exponents to both, the Luxemburg norm is the same as if you would consider the two parts as just one part.
- The mixed norm is not the -norm, even if the set the exponent to for every part.
- The Luxemburg norm has the flexibility to use other functionals than just the powers.
- For the mixed norms one could consider additional mixing by not just summing the norms of the different parts, which is the same as taking the -norm of the vector of norms. Of course, other norms are possible, e.g. constructions like
are also norms. (Actually, the term

*mixed norm*is often used for the above construction with .)

Here are some pictures that show the different geometry that these three functionals induce. We consider i.e., three-dimensional space, and picture the norm-balls (of level sets in the case the functionals ).

- Consider the case and the first exponent to be and the second . The mixed norm is
the -functional is

and for the Luxemburg norm it holds that

Here are animated images of the respective level sets/norm balls for radii :

You may note the different shapes of the balls of the mixed norm and the Luxemburg norm. Also, the shape of their norm balls stays the same as you scale the radius. The last observation is not true for the functional: Different directions scale differently.

- Now consider and the same exponents. This makes the mixed norm equal to the -norm, since
The -functional is

and for the Luxemburg norm it holds that

Here are animated images of the respective level sets/norm balls of the functional and the Luxemburg norm for the same radii as above (I do not show the balls for the mixed norm – they are just the standard cross-polytopes/-norm balls/octahedra): Again note how the Luxemburg ball keeps its shape while the level sets of the -functional changes shape while scaling.

- Now we consider three different exponents: , and . The mixed norm is again the -norm. The -functional is
and for the Luxemburg norm it holds that

Here are animated images of the respective level sets/norm balls of the functional and the Luxemburg norm for the same radii as above (again, the balls for the mixed norm are just the standard cross-polytopes/-norm balls/octahedra):