What comes to mind when you hear the term ‘random process’? Do you think of Brownian motion? Do you think of particles hopping around? Do you think of a drunkard staggering home?

Today I’m going to tell you about a version of the drunkard’s walk with a few modifications. Firstly, we don’t have just one drunkard: we can have any positive real number of drunkards. Secondly, our drunkards have no memory; where they go next doesn’t depend on where they’ve been. Thirdly, there are special places, such as entrances to bars, where drunkards magically appear and disappear.

The second condition says that our drunkards satisfy the Markov property, making their random walk into a **Markov process**. The third condition is really what I want to tell you about, because it makes our Markov process into a more general ‘open Markov process’.

There are a collection of places the drunkards can be, for example:

We call this set the set of **states**. There are certain probabilities associated with traveling between these places. We call these **transition rates**. For example it is more likely for a drunkard to go from the bar to the taco truck than to go from the bar to home so the transition rate between the bar and the taco truck should be greater than the transition rate from the bar to home. Sometimes you can’t get from one place to another without passing through intermediate places. In reality the drunkard can’t go directly from the bar to the taco truck: he or she has to go from the bar to sidewalk to the taco truck.

This information can all be summarized by drawing a directed graph where the positive numbers labelling the edges are the transition rates:

For simplicity we draw only three states: home, bar, taco truck. Drunkards go from home to the bar and back, but they never go straight from home to the taco truck.

We can keep track of where all of our drunkards are using a vector with 3 entries:

We call this our **population distribution**. The first entry is the number of drunkards that are at home, the second is how many are at the bar, and the third is how many are at the taco truck.

There is a set of coupled, linear, first-order differential equations we can write down using the information in our graph that tells us how the number of drunkards in each place change with time. This is called the **master equation**:

where is a 3×3 matrix which we call the **Hamiltonian**. The off-diagonal entries are nonnegative:

and the columns sum to zero:

We call a matrix satisfying these conditions **infinitesimal stochastic**. **Stochastic** matrices have columns that sum to one. If we take the exponential of an infinitesimal stochastic matrix we get one whose columns sum to one, hence the label ‘infinitesimal’.

The Hamiltonian for the graph above is

John has written a lot about Markov processes and infinitesimal stochastic Hamiltonians in previous posts.

Given two vectors describing the populations of drunkards which obey the same master equation, we can calculate the **relative entropy** of relative to :

This is an example of a ‘divergence’. In statistics, a divergence a way of measuring the distance between probability distributions, which may not be symmetrical and may even not obey the triangle inequality.

The relative entropy is important because it decreases monotonically with time, making it a Lyapunov function for Markov processes. Indeed, it is a well known fact that

This is true for any two population distributions which evolve according to the same master equation, though you have to allow infinity as a possible value for the relative entropy and negative infinity for its time derivative.

Why is entropy *decreasing?* Doesn’t the Second Law of Thermodynamics say entropy *increases?*

Don’t worry: the reason is that I have not put a minus sign in my definition of relative entropy. Put one in if you like, and then it will increase. Sometimes without the minus sign it’s called the Kullback–Leibler divergence. This *decreases* with the passage of time, saying that any two population distributions and get ‘closer together’ as they get randomized with the passage of time.

That itself is a nice result, but I want to tell you what happens when you allow drunkards to appear and disappear at certain states. Drunkards appear at the bar once they’ve had enough to drink and once they are home for long enough they can disappear. The set of places where drunkards can appear or disappear is called the set of **boundary states**. So for the above process

is the set of boundary states. This changes the way in which the population of drunkards changes with time!

The drunkards at the taco truck obey the master equation. For them,

still holds. But because the populations can appear or disappear at the boundary states the master equation no longer holds at those states! Instead it is useful to define the flow of drunkards into the state by

This quantity describes by how much the rate of change of the populations at the boundary states differ from that given by the master equation.

The reason why we are interested in open Markov processes is because you can take two open Markov processes and glue them together along some subset of their boundary states to get a new open Markov process! This allows us to build up or break down complicated Markov processes using open Markov processes as the building blocks.

For example we can draw the graph corresponding to the drunkards’ walk again, only now we will distinguish boundary states from internal states by coloring internal states blue and having boundary states be white:

Consider another open Markov process with states

where

are the boundary states, leaving

as an internal state:

Since the boundary states of this process overlap with the boundary states of the first process we can compose the two to form a new Markov process:

Notice the boundary states are now internal states. I hope any Markov process that could approximately model your behavior has more interesting nodes! There is a nice way to figure out the Hamiltonian of the composite from the Hamiltonians of the pieces, but we will leave that for another time.

We can ask ourselves, how does relative entropy change with time in open Markov processes? You can read my paper for the details, but here is the punchline:

This is a version of the Second Law of Thermodynamics for open Markov processes.

It is important to notice that the sum is only over the boundary states! This inequality tells us that relative entropy still decreases inside our process, but depending on the flow of populations through the boundary states the relative entropy of the whole process could either increase or decrease! This inequality will be important when we study how the relative entropy changes in different parts of a bigger more complicated process.

That is all for now, but I leave it as an exercise for you to imagine a Markov process that describes your life. How many states does it have? What are the relative transition rates? Are there states you would like to spend more or less time in? Are there states somewhere you would like to visit?

Here is my paper, which proves the above inequality:

• Blake Pollard, A Second Law for open Markov processes.

If you have comments or corrections, let me know!

]]>

Since I was in Banff, my student Franciscus Rebro took over this week and explained more about cospan categories. These are a tool for constructing categories where the morphisms are networks such as electrical circuit diagrams, signal flow diagrams, Markov processes and the like. For some more details see:

• John Baez and Brendan Fong, A compositional framework for passive linear networks.

Cospan categories are really best thought of as *bicategories*, and Franciscus gets into this aspect too.

]]>

and sends it to its behavior as viewed from outside. From outside, all you can see is the relation between currents and potentials at the ‘terminals’—the little bits of wire that poke out of the black box:

I came close to defining the black box functor, but I didn’t quite make it! This time let’s finish the job.

The black box functor

goes from the category where morphisms are circuits made of resistors, to the category where morphisms are linear relations. Let me remind you how these categories work, and introduce a bit of new notation.

Here is the category

• an object is a finite set;

• a morphism from to is an isomorphism class of cospans

in the category of graphs with edges labelled by **resistances**: numbers in Here we think of the finite sets and as graphs with no edges. We call the set of **inputs** and the set of **outputs**.

• we compose morphisms in by composing isomorphism classes of cospans.

And here is the category

• an object is a finite-dimensional real vector space;

• a morphism from to is a **linear relation** meaning a linear subspace

• we compose a linear relation and a linear relation in the usual way we compose relations, getting:

In case you’re wondering: I’ve just introduced the wiggly arrow notation

for a linear relation from to because it suggests that a relation is a bit like a function but more general. Indeed, a function is a special case of a relation, and composing functions is a special case of composing relations.

Now, how do we define the black box functor?

Defining it on objects is easy. An object of is a finite set and we define

The idea is that could be a set of inputs or outputs, and then

is a list of numbers: the potentials and currents at those inputs or outputs.

So, the interesting part is defining the black box functor on morphisms!

For this we start with a morphism in :

The labelled graph consists of:

• a set of **nodes**,

• a set of **edges**,

• maps sending each edge to its **source** and **target**,

• a map sending each edge to its **resistance**.

The cospan gives maps

These say how the inputs and outputs are interpreted as nodes in the circuit. We’ll call the nodes that come from inputs or outputs ‘terminals’. So, mathematically,

is the set of **terminals**: the union of the images of and

In the simplest case, the maps and are one-to-one, with disjoint ranges. Then each terminal either comes from a *single* input, or a *single* output, but *not both!* This is a good picture to keep in mind. But some subtleties arise when we leave this simplest case and consider other cases.

Now, the black box functor is supposed to send our circuit to a linear relation. I’ll call the circuit for short, though it’s really the whole cospan

So, our black box functor is supposed to send this circuit to a linear relation

This is a relation between the potentials and currents at the input terminals and the potentials and currents at the output terminals! How is it defined?

I’ll start by outlining how this works.

First, our circuit picks out a subspace

This is the subspace of allowed potentials and currents on the terminals. I’ll explain this and why it’s called a bit later. Briefly, it comes from the principle of minimum power, described last time.

Then, the map

gives a linear relation

This says how the potentials and currents at the inputs are related to those at the terminals. Similarly, the map

gives a linear relation

This says how the potentials and currents at the *outputs* are related to those at the terminals.

Next, we can ‘turn around’ any linear relation

to get a relation

defined by

Here we are just switching the input and output potentials, but when we switch the currents we also throw in a minus sign. The reason is that we care about the current flowing *in* to an input, but *out* of an output.

Finally, one more trick: given a linear subspace

of a vector space we get a linear relation

called **the identity restricted to** , defined like this:

If is all of this relation is actually the identity function on Otherwise it’s a partially defined function that’s defined only on and is the identity there. (A partially defined function is an example of a relation.) My notation is probably bad, but I don’t know a better one, so bear with me.

Let’s use all these ideas to define

To do this, we compose three linear relations:

1) We start with

2) We compose this with

3) Then we compose this with

Note that:

1) says how the potentials and currents at the inputs are related to those at the terminals,

2) picks out which potentials and currents at the terminals are actually allowed, and

3) says how the potentials and currents at the terminals are related to those at the outputs.

So, I hope all makes sense, at least in some rough way. In brief, here’s the formula:

Now I just need to fill in some details. First, how do we define and They work exactly the same way, by ‘copying potentials and adding currents’, so I’ll just talk about one. Second, how do we define the subspace This uses the principle of minimum power.

Any function between finite sets

gives a linear map

Mathematicians call this linear map the **pullback along** and for any it’s defined by

In our application, we think of as a list of potentials at terminals. The function could map a bunch of inputs to the same terminal, and the above formula says the potential at this terminal gives the potential at all those inputs. So, we are *copying potentials*.

We also get a linear map going the other way:

Mathematicians call this the **pushforward along** and for any it’s defined by

In our application, we think of as a list of currents entering at some inputs. The function could map a bunch of inputs to the same terminal, and the above formula says the current at this terminal is the sum of the currents at all those inputs. So, we are *adding currents*.

Putting these together, our map

gives a linear relation

where the pair is related to the pair iff

and

So, here’s the rule of thumb when attaching the points of to the input terminals of our circuit: *copy potentials, but add up currents*. More formally:

Finally, how does our circuit define a subspace

of allowed potential-current pairs at the terminals? The trick is to use the ideas we discussed last time. If we know the potential at all nodes of our circuit, say , we know the power used by the circuit:

We saw last time that if we fix the potentials at the terminals, the circuit will choose potentials at the other nodes to minimize this power. We can describe the potential at the terminals by

So, the power for a given potential at the terminals is

Actually this is half the power: I stuck in a factor of 1/2 for some reason we’ll soon see. This is a quadratic function

so its derivative is linear. And, our work last time showed something interesting: to compute the current flowing into a terminal we just differentiate with respect to the potential at that terminal:

This is the reason for the 1/2: when we take the derivative of we bring down a 2 from differentiating all those squares, and to make that go away we need a 1/2.

The space of allowed potential-current pairs at the terminals is thus the linear subspace

And this completes our precise description of the black box functor!

The hard part is this:

**Theorem.** is a functor.

In other words, we have to prove that it preserves composition:

For that, read our paper:

• John Baez and Brendan Fong, A compositional framework for passive linear networks.

]]>

• Naftali Tishby, Sensing and acting under information constraints—a principled approach to biology and intelligence, 28 October 2014.

Tishby’s talk wasn’t easy for me to follow—he assumed you already knew rate-distortion theory and the Bellman equation, and I didn’t—but it was *great!*

It was about the ‘action-perception loop':

This is the feedback loop in which living organisms—like us—*take actions* depending on our goals and what we perceive, and *perceive things* depending on the actions we take and the state of the world.

How do we do this so well? Among other things, we need to balance the *cost* of storing information about the *past* against the *payoff* of achieving our desired goals in the *future*.

Tishby presented a detailed yet highly general mathematical model of this! And he ended by testing the model on experiments with cats listening to music and rats swimming to land.

It’s beautiful stuff. I want to learn it. I hope to blog about it as I understand more. But for now, let me just dive in and say some basic stuff. I’ll start with the two buzzwords I dropped on you. I hate it when people use terminology without ever explaining it.

**Rate-distortion theory** is a branch of information theory which seeks to find the minimum rate at which bits must be communicated over a noisy channel so that the signal can be approximately reconstructed at the other end without exceeding a given distortion. Shannon’s first big result in this theory, the ‘rate-distortion theorem’, gives a formula for this minimum rate. Needless to say, it still requires a lot of extra work to determine and achieve this minimum rate in practice.

For the basic definitions and a statement of the theorem, try this:

• Natasha Devroye, Rate-distortion theory, course notes, University of Chicago, Illinois, Fall 2009.

One of the people organizing this conference is a big expert on rate-distortion theory, and he wrote a book about it.

• Toby Berger, *Rate Distortion Theory: A Mathematical Basis for Data Compression*, Prentice–Hall, 1971.

Unfortunately it’s out of print and selling for $259 used on Amazon! An easier option might be this:

• Thomas M. Cover and Joy A. Thomas, *Elements of Information Theory*, Chapter 10: Rate Distortion Theory, Wiley, New York, 2006.

The **Bellman equation** reduces the task of finding an optimal course of action to choosing what to do at each step. So, you’re trying to maximize the ‘total reward’—the sum of rewards at each time step—and Bellman’s equation says what to do at each time step.

If you’ve studied physics, this should remind you of how starting from the principle of least action, we can get a differential equation describing the motion of a particle: the **Euler–Lagrange equation**.

And in fact they’re deeply related. The relation is obscured by two little things. First, Bellman’s equation is usually formulated in a context where time passes in discrete steps, while the Euler–Lagrange equation is usually formulated in continuous time. Second, Bellman’s equation is really the discrete-time version not of the Euler–Lagrange equation but a more or less equivalent thing: the ‘Hamilton–Jacobi equation’.

Ah, another buzzword to demystify! I was scared of the Hamilton–Jacobi equation for years, until I taught a course on classical mechanics that covered it. Now I think it’s the greatest thing in the world!

Briefly: the Hamilton–Jacobi equation concerns the least possible action to get from a fixed starting point to a point in space at time If we call this least possible action the **Hamilton–Jacobi equation** says

where is the particle’s momentum at the endpoint of its path, and is its energy there.

If we replace derivatives by differences, and talk about *maximizing total reward* instead of *minimizing action*, we get Bellman’s equation:

• Bellman equation, Wikipedia.

Bellman’s equation can be useful whenever you’re trying to figure out an optimal course of action. An important example is a ‘Markov decision process’. To prepare you for Tishby’s talk, I should say what this is.

In a Markov process, something randomly hops around from state to state with fixed probabilities. In the simplest case there’s a finite set of **states**, and time proceeds in discrete steps. At each time step, the probability to hop from state to state is some fixed number

This sort of thing is called a **Markov chain**, or if you feel the need to be more insistent, a **discrete-time Markov chain**.

A **Markov decision process** is a generalization where an outside agent gets to change these probabilities! The agent gets to choose **actions** from some set If at a given time he chooses the action the probability of the system hopping from state to state is Needless to say, these probabilities have to sum to one for any fixed

That would already be interesting, but the real fun is that there’s also a **reward** This is a real number saying how much joy or misery the agent experiences if he does action and the system hops from to

The problem is to choose a **policy**—a function from states to actions—that maximizes the total expected reward over some period of time. This is precisely the kind of thing Bellman’s equation is good for!

If you’re an economist you might also want to ‘discount’ future rewards, saying that a reward time steps in the future gets multiplied by where is some **discount factor**. This extra tweak is easily handled, and you can see it all here:

• Markov decision process, Wikipedia.

There’s a further generalization where the agent can’t see all the details of the system! Instead, when he takes an action and the system hops from state to state he sees something: a point in some set of **observations**. He makes the observation with probability

(I don’t know why this probability depends on but not Maybe it ultimately doesn’t matter much.)

Again, the goal is to choose a **policy** that maximizes the expected total reward. But a policy is a bit different now. The action at any time can only depend on all the observations made thus far.

Partially observable Markov decision processes are also called **POMPD**s. If you want to learn about them, try these:

• Partially observable Markov decision process, Wikipedia.

• Tony Cassandra, Partially observable Markov decision processes.

The latter includes an introduction *without any formulas* to POMDPs and how to choose optimal policies. I’m not sure who would study this subject and not want to see formulas, but it’s certainly a good exercise to explain things using just words—and it makes certain things easier to understand (though not others, in a way that depends on who is trying to learn the stuff).

I already explained the action-perception loop, with the help of this picture from the University of Bielefeld’s Department of Cognitive Neuroscience:

Nafthali Tishby has a nice picture of it that’s more abstract:

We’re assuming time comes in discrete steps, just to keep things simple.

At each time

• the **world** has some state and

• the **agent** has some state

Why the letter ? This stands for **memory**: it can be the state of the agent’s memory, but I prefer to think of it as the state of the agent.

At each time

• the agent takes an **action** which affects the world’s next state, and

• the world provides a **sensation** to the agent, which affect’s the agent’s next state.

This is simplified but very nice. Note that there’s a symmetry interchanging the world and the agent!

We could make it fancier by having lots of agents who all interact, but there are a lot of questions already. The big question Tishby focuses on is optimizing how much the agent should remember about the past if they

• get a reward depending on the action taken and the resulting state of the world

but

• pay a price for the information stored from sensations.

Tishby formulates this optimization question as something like a partially observed Markov decision process, uses rate-distortion theory to analyze how much information needs to be stored to achieve a given reward, and uses Bellman’s equation to solve the optimization problem!

So, everything I sketched fits together somehow!

I hope what I’m saying now is roughly right: it will take me more time to get the details straight. If you’re having trouble absorbing all the information I just threw at you, don’t feel bad: so am I. But the math feels really natural and good to me. It involves a lot of my favorite ideas (like generalizations of the principle of least action, and relative entropy), and it seems ripe to be combined with network theory ideas.

For details, I highly recommend this paper:

• Naftali Tishby and Daniel Polani, Information theory of decisions and actions, in *Perception-Reason-Action Cycle: Models, Algorithms and System*. Vassilis, Hussain and Taylor, Springer, Berlin, 2010.

I’m going to print this out, put it by my bed, and read it every night until I’ve absorbed it.

]]>

I’m giving a short 30-minute talk at a workshop on Biological and Bio-Inspired Information Theory at the Banff International Research Institute.

I’ll say more about the workshop later, but here’s my talk, in PDF and video form:

• Biodiversity, entropy and thermodynamics.

Most of the people at this workshop study neurobiology and cell signalling, not evolutionary game theory or biodiversity. So, the talk is just a quick intro to some things we’ve seen before here. Starting from scratch, I derive the Lotka–Volterra equation describing how the distribution of organisms of different species changes with time. Then I use it to prove a version of the Second Law of Thermodynamics.

This law says that if there is a ‘dominant distribution’—a distribution of species whose mean fitness is at least as great as that of any population it finds itself amidst—then as time passes, the information *any* population has ‘left to learn’ always decreases!

Of course reality is more complicated, but this result is a good start.

This was proved by Siavash Shahshahani in 1979. For more, see:

• Lou Jost, Entropy and diversity.

• Marc Harper, The replicator equation as an inference dynamic.

• Marc Harper, Information geometry and evolutionary game theory.

and more recent papers by Harper.

]]>

This time we use the principle of minimum power to determine what a circuit made of resistors actually *does*. Its ‘behavior’ is described by a functor sending circuits to linear relations between the potentials and currents at the input and output terminals. We call this the ‘black box’ functor, since it takes a circuit:

and puts a metaphorical ‘black box’ around it:

hiding the circuit’s internal details and letting us see only how it acts as viewed ‘from outside’.

For more, see the lecture notes here:

]]>

and puts a ‘black box’ around it:

forgetting the internal details of the circuit and remembering only how the it *behaves as viewed from outside*. As viewed from outside, all the circuit does is define a relation between the potentials and currents at the inputs and outputs. We call this relation the circuit’s **behavior**. Lots of different choices of the resistances would give the same behavior. In fact, we could even replace the whole fancy circuit by a single edge with a single resistor on it, and get a circuit with the same behavior!

The idea is that when we use a circuit to do something, all we care about is its behavior: what it does as viewed from outside, not what it’s made of.

Furthermore, we’d like the behavior of a system made of parts to depend in a simple way on the external behaviors of its parts. We don’t want to have to ‘peek inside’ the parts to figure out what the whole will do! Of course, in some situations we *do* need to peek inside the parts to see what the whole will do. But in this particular case we don’t—at least in the idealization we are considering. And this fact is described mathematically by saying that black boxing is a functor.

So, how do circuits made of resistors behave? To answer this we first need to remember what they *are!*

Remember that for us, a **circuit made of resistors** is a mathematical structure like this:

It’s a cospan where:

• is a **graph labelled by resistances**. So, it consists of a finite set of **nodes**, a finite set of **edges**, two functions

sending each edge to its **source** and **target** nodes, and a function

that labels each edge with its **resistance**.

• is a map of graphs labelled by resistances, where has no edges. A labelled graph with no edges has nothing but nodes! So, the map is just a trick for specifying a finite set of nodes called **inputs** and mapping them to Thus picks out some nodes of and declares them to be inputs. (However, may not be one-to-one! We’ll take advantage of that subtlety later.)

• is another map of graphs labelled by resistances, where again has no edges, and we call its nodes **outputs**.

So what does a circuit made of resistors *do?* This is described by the principle of minimum power.

Recall from Part 27 that when we put it to work, our circuit has a **current** flowing along each edge This is described by a function

It also has a **voltage** across each edge. The word ‘across’ is standard here, but don’t worry about it too much; what matters is that we have another function

describing the voltage across each edge

Resistors heat up when current flows through them, so they eat up electrical power and turn this power into heat. How much? The **power** is given by

So far, so good. But what does it mean to minimize power?

To understand this, we need to manipulate the formula for power using the laws of electrical circuits described in Part 27. First, **Ohm’s law** says that for linear resistors, the current is proportional to the voltage. More precisely, for each edge

where is the resistance of that edge. So, the bigger the resistance, the less current flows: that makes sense. Using Ohm’s law we get

Now we see that power is always nonnegative! Now it makes more sense to minimize it. Of course we could minimize it simply by setting all the voltages equal to zero. That would work, but that would be boring: it gives a circuit with no current flowing through it. The fun starts when we minimize power *subject to some constraints*.

For this we need to remember another law of electrical circuits: a spinoff of **Kirchhoff’s voltage law**. This says that we can find a function called the **potential**

such that

for each In other words, the voltage across each edge is the difference of potentials at the two ends of this edge.

Using this, we can rewrite the power as

Now we’re really ready to minimize power! Our circuit made of resistors has certain nodes called **terminals**:

These are the nodes that are either inputs or outputs. More precisely, they’re the nodes in the image of

or

The **principle of minimum power** says that:

If we fix the potential on all terminals, the potential at other nodes will minimize the power

subject to this constraint.

This should remind you of all the other minimum or maximum principles you know, like the principle of least action, or the way a system in thermodynamic equilibrium maximizes its entropy. All these principles—or at least, most of them—are connected. I could talk about this endlessly. But not now!

Now let’s just *use* the principle of minimum power. Let’s see what it tells us about the behavior of an electrical circuit.

Let’s imagine changing the potential by adding some multiple of a function

If this other function vanishes at the terminals:

then doesn’t change at the terminals as we change the number

Now suppose **obeys the principle of minimum power**. In other words, supposes it minimizes power subject to the constraint of taking the values it does at the terminals. Then we must have

whenever

This is just the first derivative test for a minimum. But the converse is true, too! The reason is that our power function is a sum of nonnegative quadratic terms. Its graph will look like a paraboloid. So, the power has no points where its derivative vanishes except minima, even when we constrain by making it lie on a linear subspace.

We can go ahead and start working out the derivative:

To work out the derivative of these quadratic terms at we only need to keep the part that’s proportional to The rest gives zero. So:

The principle of minimum power says this is zero whenever is a function that vanishes at terminals. By linearity, it’s enough to consider functions that are zero at every node except one node that is not a terminal. By linearity we can also assume

Given this, the only nonzero terms in the sum

will be those involving edges whose source or target is We get

So, the principle of minimum power says precisely

for all nodes that aren’t terminals.

What does this mean? You could just say it’s a set of linear equations that must be obeyed by the potential So, the principle of minimum power says that fixing the potential at terminals, the potential at other nodes must be chosen in a way that obeys a set of linear equations.

But what do these equations *mean?* They have a nice meaning. Remember, Kirchhoff’s voltage law says

and Ohm’s law says

Putting these together,

so the principle of minimum power merely says that

for any node that is not a terminal.

This is **Kirchhoff’s current law**: for any node except a terminal, the total current flowing into that node must equal the total current flowing out! That makes a lot of sense. We allow current to flow in or out of our circuit at terminals, but ‘inside’ the circuit charge is conserved, so if current flows into some other node, an equal amount has to flow out.

In short: the principle of minimum power implies Kirchoff’s current law! Conversely, we can run the whole argument backward and derive the principle of minimum power from Kirchhoff’s current law. (In both the forwards and backwards versions of this argument, we use Kirchhoff’s voltage law and Ohm’s law.)

When the node is a terminal, the quantity

need not be zero. But it has an important meaning: it’s the amount of current flowing into that terminal!

We’ll call this the **current at the terminal** This is something we can measure even when our circuit has a black box around it:

So is the potential at the terminal It’s these currents and potentials *at terminals* that matter when we try to describe the behavior of a circuit while ignoring its inner workings.

Now let me quickly sketch how black boxing becomes a functor.

A circuit made of resistors gives a *linear relation* between the potentials and currents at terminals. A relation is something that can hold or fail to hold. A ‘linear’ relation is one defined using linear equations.

A bit more precisely, suppose we choose potentials and currents at the terminals:

Then we seek potentials and currents at all the nodes and edges of our circuit:

that are compatible with our choice of and Here **compatible** means that

and

whenever but also

for every and

whenever (The last two equations combine Kirchoff’s laws and Ohm’s law.)

There either exist and making all these equations true, in which case we say our potentials and currents at the terminals obey the relation… or they *don’t* exist, in which case we say the potentials and currents at the terminals *don’t* obey the relation.

The relation is clearly linear, since it’s defined by a bunch of linear equations. With a little work, we can make it into a linear relation between potentials and currents in

and potentials and currents in

Remember, is our set of inputs and is our set of outputs.

In fact, this process of getting a linear relation from a circuit made of resistors defines a functor:

Here is the category where morphisms are circuits made of resistors, while is the category where morphisms are linear relations.

More precisely, here is the category

• an object of is a finite set;

• a morphism from to is an isomorphism class of circuits made of resistors:

having as its set of inputs and as its set of outputs;

• we compose morphisms in by composing isomorphism classes of cospans.

(Remember, circuits made of resistors are cospans. This lets us talk about isomorphisms between them. If you forget the how isomorphism between cospans work, you can review it in Part 31.)

And here is the category

• an object of is a finite-dimensional real vector space;

• a morphism from to is a **linear relation** meaning a linear subspace of the vector space

• we compose a linear relation and a linear relation in the usual way we compose relations, getting:

So far I’ve set up most of the necessary background but not precisely defined the black boxing functor

There are some nuances I’ve glossed over, like the difference between inputs and outputs as elements of and and their images in If you want to see the precise definition and the *proof* that it’s a functor, read our paper:

• John Baez and Brendan Fong, A compositional framework for passive linear networks.

The proof is fairly long: there may be a much quicker one, but at least this one has the virtue of introducing a lot of nice ideas that will be useful elsewhere.

Next time I’ll define the black box functor more carefully.

]]>

This time I explain more about how ‘cospans’ represent gadgets with two ends, an input end and an output end:

I describe how to glue such gadgets together by composing cospans. We compose cospans using a category-theoretic construction called a ‘pushout’, so I also explain pushouts. At the end, I explain how this gives us a category where the morphisms are electrical circuits made of resistors, and sketch what we’ll do next: study the behavior of these circuits.

These lecture notes provide extra details:

]]>

• Y. Berezin, Avi Gozolchiani, O. Guez and Shlomo Havlin, Stability of climate networks with time, *Scientific Reports* **2** (2012).

Some of the authors are the same, and the way they define climate networks is very similar. But their goal here is different: they want to see see how stable climate networks are over time. This is important, since the other paper wants to predict El Niños by *changes* in climate networks.

They divide the world into 9 zones:

For each zone they construct several **climate networks**. Each one is an array of numbers , one for each year and each pair of grid points in that zone. They call a **link strength**: it’s a measure of how how correlated the weather is at those two grid points during that year.

I’ll say more later about how they compute these link strengths. In Part 3 we explained one method for doing it. This paper uses a similar but subtly different method.

The paper’s first big claim is that doesn’t change much from year to year, “in complete contrast” to the pattern of local daily air temperature and pressure fluctuations. In simple terms: *the strength of the correlation between weather at two different points tends to be quite stable.*

Moreover, the definition of link strength involves an adjustable time delay, . We can measure the correlation between the weather at point at any given time and point at a time days later. The link strength is computed by taking a *maximum* over time delays . Naively speaking, the value of that gives the maximum correlation is “how long it typically takes for weather at point to affect weather at point ”. Or the other way around, if is negative.

This is a naive way of explaining the idea, because I’m mixing up correlation with causation. But you get the idea, I hope.

Their second big claim is that when the link strength between two points and is big, the value of that gives the maximum correlation doesn’t change much from year to year. In simple terms: *if the weather at two locations is strongly correlated, the amount of time it takes for weather at one point to reach the other point doesn’t change very much.*

How do Berezin *et al* define their climate network?

They use data obtained from here:

This is not exactly the same data set that Ludescher *et al* use, namely:

“Reanalysis 2″ is a newer attempt to reanalyze and fix up the same pile of data. That’s a very interesting issue, but never mind that now!

Berezin *et al* use data for:

• the geopotential height for six different pressures

and

• the air temperature at those different heights

The **geopotential height** for some pressure says roughly how high you have to go for air to have that pressure. Click the link if you want a more precise definition! Here’s the geopotential height field for the pressure of 500 millibars on some particular day of some particular year:

The height is in meters.

Berezin *et al* use daily values for this data for:

• locations world-wide on a grid with a resolution of 5° × 5°,

during:

• the years from 1948 to 2006.

They divide the globe into 9 zones, and separately study each zone:

So, they’ve got twelve different functions of space and time, where space is a rectangle discretized using a 5° × 5° grid, and time is discretized in days. From each such function they build a ‘climate network’.

How do they do it?

Berezin’s method of defining a climate network is similar to Ludescher *et al*‘s, but different. Compare Part 3 if you want to think about this.

Let be any one of their functions, evaluated at the grid point on day of year .

Let be minus its **climatological average**. For example, if is June 1st and is 1970, we average the temperature at location over all June 1sts from 1948 to 2006, and subtract that from to get . In other words:

where is the number of years considered.

For any function of time , let be the average of the function over all days in year . This is different than the ‘running average’ used by Ludescher *et al*, and I can’t even be 100% sure that Berezin mean what I just said: they use the notation .

Let and be two grid points, and any number of days in the interval . Define the **cross-covariance function** at time by:

I believe Berezin mean to consider this quantity, because they mention two grid points and . Their notation omits the subscripts and so it is impossible to be completely sure what they mean! But what I wrote is the reasonable quantity to consider here, so I’ll assume this is what they meant.

They normalize this quantity and take its absolute value, forming:

They then take the maximum value of over delays , subtract its mean over delays in this range, and divide by the standard deviation. They write something like this:

and say that the maximum, mean and standard deviation are taken over the (not written) variable .

Each number is called a **link strength**. For each year, the matrix of numbers where and range over all grid points in our zone is called a **climate network**.

We can think of a climate network as a weighted complete graph with the grid points as nodes. Remember, an **undirected graph** is one without arrows on the edges. A **complete graph** is an undirected graph with one edge between any pair of nodes:

A **weighted graph** is an undirected graph where each edge is labelled by a number called its **weight**. But right now we’re also calling the weight the ‘link strength’.

A lot of what’s usually called ‘network theory’ is the study of weighted graphs. You can learn about it here:

• Ernesto Estrada, *The Structure of Complex Networks: Theory and Applications*, Oxford U. Press, Oxford, 2011.

Suffice it to say that given a weighted graph, there are lot of quantities you can compute from it, which are believed to tell us interesting things!

I will not delve into the real meat of the paper, namely what they actually *do* with their climate networks! The paper is free online, so you can read this yourself.

I will just quote their conclusions and show you a couple of graphs.

The conclusions touch on an issue that’s important for the network-based approach to El Niño prediction. If climate networks are ‘stable’, not changing much in time, why would we use them to predict a time-dependent phenomenon like the El Niño Southern Oscillation?

We have established the stability of the network of connections between the dynamics of climate variables (e.g. temperatures and geopotential heights) in different geographical regions. This stability stands in fierce contrast to the observed instability of the original climatological field pattern. Thus the coupling between different regions is, to a large extent, constant and predictable. The links in the climate network seem to encapsulate information that is missed in analysis of the original field.

The strength of the physical connection, , that each link in this network represents, changes only between 5% to 30% over time. A clear boundary between links that represent real physical dependence and links that emerge due to noise is shown to exist. The distinction is based on both the high link average strength and on the low variability of time delays .

Recent studies indicate that the strength of the links in the climate network changes during the El Niño Southern Oscillation and the North Atlantic Oscillation cycles. These changes are within the standard deviation of the strength of the links found here. Indeed in Fig. 3 it is clearly seen that the coefficient of variation of links in the El Niño basin (zone 9) is larger than other regions such as zone 1. Note that even in the El Niño basin the coefficient of variation is relatively small (less than 30%).

Beside the stability of single links, also the hierarchy of the link strengths in the climate network is preserved to a large extent. We have shown that this hierarchy is partially due to the two dimensional space in which the network is embedded, and partially due to pure physical coupling processes. Moreover the contribution of each of these effects, and the level of noise was explicitly estimated. The spatial effect is typically around 50% of the observed stability, and the noise reduces the stability value by typically 5%–10%.

The network structure was further shown to be consistent across different altitudes, and a monotonic relation between the altitude distance and the correspondence between the network structures is shown to exist. This yields another indication that the observed network structure represents effects of physical coupling.

The stability of the network and the contributions of different effects were summarized in specific relation to different geographical areas, and a clear distinction between equatorial and off–equatorial areas was observed. Generally, the network structure of equatorial regions is less stable and more fluctuative.

The stability and consistence of the network structure during time and across different altitudes stands in contrast to the known unstable variability of the daily anomalies of climate variables. This contrast indicates an analogy between the behavior of nodes in the climate network and the behavior of coupled chaotic oscillators. While the fluctuations of each coupled oscillators are highly erratic and unpredictable, the interactions between the oscillators is stable and can be predicted. The possible outreach of such an analogy lies in the search for known behavior patterns of coupled chaotic oscillators in the climate system. For example, existence of phase slips in coupled chaotic oscillators is one of the fingerprints for their cooperated behavior, which is evident in each of the individual oscillators. Some abrupt changes in climate variables, for example, might be related to phase slips, and can be understood better in this context.

On the basis of our measured coefficient of variation of single links (around 15%), and the significant overall network stability of 20–40%, one may speculatively assess the extent of climate change. However, for this assessment our current available data is too short and does not include enough time from periods before the temperature trends. An assessment of the relation between the network stability and climate change might be possible mainly through launching of global climate model “experiments” realizing other climate conditions, which we indeed intend to perform.

A further future outreach of our work can be a mapping between network features (such as network motifs) and known physical processes. Such a mapping was previously shown to exist between an autonomous cluster in the climate network and El Niño. Further structures without such a climate interpretation might point towards physical coupling processes which were not observed earlier.

(I have expanded some acronyms and deleted some reference numbers.)

Finally, here two nice graphs showing the average link strength as a function of distance. The first is based on four climate networks for Zone 1, the southern half of South America:

The second is based on four climate networks for Zone 9, a big patch of the Pacific north of the Equator which roughly corresponds to the ‘El Niño basin':

As we expect, temperatures and geopotential heights get less correlated at points further away. But the rate at which the correlation drops off conveys interesting information! Graham Jones has made some interesting charts of this for the rectangle of the Pacific that Ludescher *et al* use for El Niño prediction, and I’ll show you those next time.

• El Niño project (part 1): basic introduction to El Niño and our project here.

• El Niño project (part 2): introduction to the physics of El Niño.

• El Niño project (part 3): summary of the work of Ludescher *et al*.

• El Niño project (part 4): how Graham Jones replicated the work by Ludescher *et al*, using software written in R.

• El Niño project (part 5): how to download R and use it to get files of climate data.

• El Niño project (part 6): Steve Wenner’s statistical analysis of the work of Ludescher *et al*.

• El Niño project (part 7): the definition of El Niño.

• El Niño project (part 8): Berezin *et al* on the stability of climate networks.

]]>

Cospans may sound scary, but they’re not. A **cospan** is just a diagram consisting of an object with two morphisms going into it:

We can talk about cospans in any category. A cospan is an abstract way of thinking about a ‘chunk of stuff’ with two ‘ends’ and It could be any sort of stuff: a set, a graph, an electrical circuit, a network of any kind, or even a piece of matter (in some mathematical theory of matter).

We call the object the **apex** of the cospan and call the morphisms the **legs** of the cospan. We sometimes call the objects and the **feet** of the cospan. We call the **input** and the **output**. We say the cospan goes **from to ** though the direction is just a convention: we can flip a cospan and get a cospan going the other way!

If you’re wondering about the name ‘cospan’, it’s because a **span** is a diagram like this:

Since a ‘span’ is another name for a bridge, and this looks like a bridge from to category theorists called it a span! And category theorists use the prefix ‘co-‘ when they turn all the arrows around. Spans came first historically, and we will use those too at times. But now let’s think about how to compose cospans.

Composing cospans is supposed to be like gluing together chunks of stuff by attaching the output of the first to the input of the second. So, we say two cospans are **composable** if the output of the first equals the input of the second, like this:

We then compose them by forming a new cospan going all the way from to :

The new object and the new morphisms are built using a process called a ‘pushout’ which I’ll explain in a minute. The result is cospan from to called the **composite** of the cospans we started with. Here it is:

So how does a pushout work? It’s a general construction that you can define in any category, though it only *exists* if the category is somewhat nice. (Ours always will be.) You start with a diagram like this:

and you want to get a commuting diamond like this:

which is in some sense ‘the best’ given the diagram we started with. For example, suppose we’re in the category of sets and is a set included in both and Then we’d like to be the union of and There are other choices of that would give a commuting diamond, but the union is the best. Something similar is happening when we compose circuits, but instead of the category of sets we’re using the category of labelled graphs we discussed last time.

How do we make precise the idea that is ‘the best’? We consider any other potential solution to this problem, that is, some other commuting diamond:

Then is ‘the best’ if there exists a unique morphism from to the ‘competitor’ making the whole combined diagram commute:

This property is called a **universal property**: instead of saying that is the ‘best’, grownups say it is **universal**.

When has this universal property we call it the **pushout** of the original diagram, and we may write it as Actually we should call the whole diagram

the pushout, or a **pushout square**, because the morphisms matter too. The universal property is not really a property just of but of the whole pushout square. But often we’ll be sloppy and call just the object the pushout.

**Puzzle 1.** Suppose we have a diagram in the category of sets

where and the maps are the inclusions of this intersection in the sets and Prove that is the pushout, or more precisely the diagram

is a pushout square, where are the inclusions of and in the union

More generally, a pushout in the category of sets is a way of gluing together sets and with some ‘overlap’ given by the maps

And this works for labelled graphs, too!

**Puzzle 2.** Suppose we have two circuits of resistors that are composable, like this:

and this:

These give cospans in the category where

(Remember from last time that is the category of graphs with edges labelled by elements of some set ) Show that if we compose these cospans we get a cospan corresponding to this circuit:

If you’re a mathematician you might find it easier to solve this kind of problem in general, which requires pondering how pushouts work in Alternatively, you might find it easier to think about this particular example: then you can just check that the answer we want has the desired property of a pushout!

If this stuff seems complicated, well, just know that category theory is a very general, powerful tool and I’m teaching you just the microscopic fragment of it that we need right now. Category theory ultimately seems very simple: I can’t really think of any math that’s simpler! It only seem complicated when it’s unfamiliar and you have a fragmentary view of it.

So where are we? We know that circuits made of resistors are a special case of cospans. We know how to compose cospans. So, we know how to compose circuits… and in the last puzzle, we saw this does just what we want.

The advantage of this rather highbrow approach is that a huge amount is known about composing cospans! In particular, suppose we have any category where **pushouts exist**: that is, where we can always complete any diagram like this:

to a pushout square. Then we can form a category where:

• an object is an object of

• a morphism from an object to an object is an equivalence classes of cospans from to

• we compose cospans in the manner just described.

Why did I say ‘equivalence class’? It’s because the pushout is not usually *unique*. It’s unique only *up to isomorphism*. So, composing cospans would be ill-defined unless we work with some kind of equivalence class of cospans.

To be precise, suppose we have two cospans from to :

Then a **map of cospans** from one to the other is a commuting diagram like this:

We say that this is an **isomorphism** of cospans if is an isomorphism.

This gives our equivalence relation on cospans! It’s an old famous theorem in category theory—so famous that it’s hard to find a reference for the proof—that whenever is a category with pushouts, there’s a category where:

• an object is an object of

• a morphism from an object to an object is an isomorphism class of cospans from to

• we compose isomorphism classes of cospans by picking representatives, composing them and then taking the isomorphism class.

This takes some work to prove, but it’s true, so this is how we get our category of circuits!

Next time we’ll do something with this category. Namely, we’ll cook up a category of ‘behaviors’. The behavior of a circuit made of resistors just says which currents and potentials its terminals can have. If we put a circuit in a metaphorical ‘black box’ and refuse to peek inside, all we can see is its behavior.

Then we’ll cook up a functor from the category of circuits to the category of behaviors. We’ll call this the ‘black box functor’. Saying that it’s a functor mainly means that

Here and are circuits that we can compose, and is their composite. The black square is the black box functor, so is the behavior of the circuit There’s a way to compose behaviors, too, and the equation above says that the behavior of the composite circuit is the composite of their behaviors!

This is very important, because it says we can figure out what a big circuit does if we know what its pieces do. And this is one of the grand themes of network theory: understanding big complicated networks by understanding their pieces. We may not always be able to do this, in practice! But it’s something we’re always concerned with.

]]>