Previous posts in this series:

Silent Duels and an Old Paper of Restrepo

Silent Duels—Parsing the Construction

Last time we waded into Restrepo’s silent duel paper. You can see the original and my re-typeset version on Github along with all of the code in this series. We digested Section 2 and a bit further, plotting some simplified examples of the symmetric version of the game.

I admit, this paper is not an easy read. Sections 3-6 present the central definitions, lemmas, and proofs. They’re a slog of dense notation with no guiding intuition. The symbols don’t even get catchy names or “think of this as” explanations! I think this disparity in communication has something to do with the period in which the paper was written, and something to do with the infancy of computing at the time. The paper was published in 1957, which marked the year IBM switched from vacuum tubes to transistors, long before Moore’s Law was even a twinkle in Gordon Moore’s eye. We can’t blame Restrepo for not appealing to our modern sensibilities.

I spent an embarrassing amount of time struggling through Sections 3-6 when I still didn’t really understand the form of the optimal strategy. It’s not until the very *end* of the paper (Section 8, the proof of Theorem 1) that we get a construction. See the last post for a detailed description of the data that constitutes the optimal strategy. In brief, it’s a partition of into subintervals with a probability distribution on each interval, and the time you take your -th action is chosen randomly according to . Optionally, the last distribution can include a point-mass at time , i.e., “wait until the last moment for a guaranteed hit.”

Section 8 describes how to choose the ‘s and ‘s, with the distributions and built according to the formulas built up in the previous sections.

Since our goal is still to understand how to construct the solution—even if *why *it works is still a mystery—we’ll write a program that implements this algorithm in two posts. First, we’ll work with a simplified symmetric game, where the answer is provided for us as a test case. In a followup post, we’ll rework the code to construct the generic solution, and pick nits about code quality, and the finer points of the algorithm Restrepo leaves out.

Ultimately, if what the program outputs matches up with Restrepo’s examples (in lieu of understanding enough of the paper to construct our own), we will declare victory—we’ll have successfully sanity-checked Restrepo’s construction. Then we can move on to studying why this solution works and what caveats hide beneath the math.

## Follow the Formulas

The input to the game is a choice of actions for player 1, actions for player 2, and probability distributions for the two player’s success probabilities (respectively). Here’s the algorithm as stated by Restrepo, with the referenced equations following. If you’re following along with my “work through the paper organically” shtick, I recommend you try parsing the text below before reading on. Recall is the “wait until the end” probability for player 1’s last action, and is the analogous probability for player 2.

Let’s sort through this mess.

First, the broad picture. The whole construction depends on , these point masses for the players’ final actions. However, there’s this condition that , i.e., at most one can be nonzero. This makes some vaguely intuitive sense: a player with more actions will have extra “to spare,” and so it may make sense for them to wait until the very end to get a guaranteed hit. But only one player can have such an advantage over the other, so only one of the two parameters may be nonzero. That’s my informal justification for .

If we don’t know at the beginning, Restrepo’s construction (the choice of ‘s and ‘s) is a *deterministic* function of , and the other fixed inputs.

The construction asserts that the optimal solution has and we need to find an input such that and they produce as output. We’re doing a search for the “right” output parameters, and using knowledge about the chained relationship of equations to look at the output, and use it to tweak the input to get the output closer to what we want. It’s not gradient descent, but it could probably be rephrased that way.

In particular, consider the case when we get , and the other should be clear. Suppose that starting from we construct all our ‘s and ‘s and get . Then we can try again with , but since is illegal we’ll use for as small a as we need (to make the next sentence true). Restrepo claims that picking something close enough to 1 will *reverse* the output, i.e. will make . He then finishes with (my paraphrase), “obviously are continuous in terms of , so a solution exists with for some choice of ; that’s the optimal solution.” Restrepo is relying on the intermediate value theorem from calculus, but to *find* that value the simplest option is binary search. We have the upper and lower bounds, and , and we know when we found our target: when the output has .

This binary search will come back in full swing in the next post, since we already know that the symmetric silent duel starts with . No search for is needed, and we can fix them both to zero for now—or rather, assume the right values are known.

What remains is to determine how to compute the ‘s and ‘s from a starting . We’ll go through the algorithm step by step using the symmetric game where (same action success probability) and (same action count) to ground our study. A followup post will revisit these formulas in full generality.

## The symmetric game

The basic idea of the construction is that we start from a computation of the last action parameters , and use those inductively to compute the parameters of earlier actions via a few integrals and substitutions. In other words, the construction is a recursion, and the interval in which the players take their last action is the base case. As I started writing the programs below, I wanted to give a name to these values. Restrepo seems to refer to them as “parameters” in the paper. I call them *transition times*, since the mark the instants at which a player “transitions” from one action interval to the next .

For a simple probability function , the end of the algorithm results in equations similar to: choose such that .

Recall, Player 1 has a special function used in each step to construct their optimal strategy, called by Restrepo. It’s defined for non-symmetric game as follows, where recall is the opponent’s action probability:

[Note the is a product ; not an iterated function application.]

Here the asks us to look at all the transition times computed in previous recursive steps, and compute the product of an action failure at those instants. This is the product . This is multiplied by a mysterious fraction involving , which in the symmetric case reduces to . In Python code, computing is given below—called simply “f_star” because I don’t yet understand how to interpret it in a meaningful way. I chose to use SymPy to compute symbolic integrals, derivatives, and solve equations, so in the function below, `prob_fun`

and `prob_fun_var`

are SymPy expressions and lambdas.

from sympy import diff def f_star(prob_fun, prob_fun_var, larger_transition_times): '''Compute f* as in Restrepo '57. In this implementation, we're working in the simplified example where P = Q (both players probabilities of success are the same). ''' x = prob_fun_var P = prob_fun product = 1 for a in larger_transition_times: product *= (1 - P(a)) return product * diff(P(x), x) / P(x)**3

In this symmetric instance of the problem we already know that is the optimal solution (Restrepo states that in section 2), so we can fix , and compute , which we do next.

In the paper, Restrepo says “compute without parameters in the definition of ” and this I take to mean, because there are no larger action instants, the product is empty, i.e., we pass an empty list of `larger_transition_times`

. Restrepo does violate this by occasionally referring to and , but if we included either of these , and this would make the definition of zero, which would produce a non-distribution, so that can’t be right. This is one of those cases where, when reading a math paper, you have to infer the interpretation that is most sensible, and give the author the benefit of the doubt.

Following the rest of the equations is trivial, except in that we are solving for which is a limit of integration. Since SciPy works symbolically, however, we can simply tell it to integrate without telling it , and ask it to solve for .

from sympy import Integral from sympy import Symbol from sympy.solvers import solve from sympy.functions.elementary.miscellaneous import Max def compute_a_n(prob_fun, alpha=0): P = prob_fun t = Symbol('t0', positive=True) a_n = Symbol('a_n', positive=True) a_n_integral = Integral( ((1 + alpha) - (1 - alpha) * P(t)) * f_star(P, t, []), (t, a_n, 1)) a_n_integrated = a_n_integral.doit() # yes now "do it" P_a_n_solutions = solve(a_n_integrated - 2 * (1 - alpha), P(a_n)) P_a_n = Max(*P_a_n_solutions) print("P(a_n) = %s" % P_a_n) a_n_solutions = solve(P(a_n) - P_a_n, a_n) a_n_solutions_in_range = [soln for soln in a_n_solutions if 0 &lt; soln &lt;= 1] assert len(a_n_solutions_in_range) == 1 a_n = a_n_solutions_in_range[0] print("a_n = %s" % a_n) h_n_integral = Integral(f_star(P, t, []), (t, a_n, 1)) h_n_integrated = h_n_integral.doit() h_n = (1 - alpha) / h_n_integrated print("h_n = %s" % h_n) return (a_n, h_n)

There are three phases here. First, we integrate and solve for (blindly according to equation 27 in the paper). If you work out this integral by hand (expanding ), you’ll notice it looks like , which suggests a natural substitution, . After computing the integral (entering phase 2), we can maintain that substitution to first solve for , say the output of that is some known number which in the code we call `P_a_n`

, and then solve for . Since that last equation can have multiple solutions, we pick the one between 0 and 1. Since must be increasing in , that guarantees uniqueness.

Note, we didn’t *need* to maintain the substitution in the integral, and perform a second solve. We could just tell sympy to solve directly for , and it would solve in addition to computing the integral. But as I was writing, it was helpful for me to check my work in terms of the substitution. In the next post we’ll clean that code up a bit.

Finally, in the third phase we compute the , which is a normalizing factor that ultimately ensures the probability distribution for the action in this interval has total probability mass 1.

The steps to compute the iterated lower action parameters ( for ) are similar, but the formulas are slightly different:

Note that the last action instant and its normalizing constant show up in the equation to compute . In code, this is largely the same as the `compute_a_n`

function, but in a loop. Along the way, we print some helpful diagnostics for demonstration purposes. These should end up as unit tests, but as I write the code for the first time I prefer to debug this way. I’m not even sure if I understand the construction well enough to do the math myself and write down unit tests that make sense; the first time I tried I misread the definition of and I filled pages with confounding and confusing integrals!

from collections import deque def compute_as_and_bs(prob_fun, n, alpha=0): '''Compute the a's and b's for the symmetric silent duel.''' P = prob_fun t = Symbol('t0', positive=True) a_n, h_n = compute_a_n(prob_fun, alpha=alpha) normalizing_constants = deque([h_n]) transitions = deque([a_n]) f_star_products = deque([1, 1 - P(a_n)]) for step in range(n): # prepending new a's and h's to the front of the list last_a = transitions[0] last_h = normalizing_constants[0] next_a = Symbol('a', positive=True) next_a_integral = Integral( (1 - P(t)) * f_star(P, t, transitions), (t, next_a, last_a)) next_a_integrated = next_a_integral.doit() # print("%s" % next_a_integrated) P_next_a_solutions = solve(next_a_integrated - 1 / last_h, P(next_a)) print("P(a_{n-%d}) is one of %s" % (step + 1, P_next_a_solutions)) P_next_a = Max(*P_next_a_solutions) next_a_solutions = solve(P(next_a) - P_next_a, next_a) next_a_solutions_in_range = [ soln for soln in next_a_solutions if 0 &lt; soln &lt;= 1] assert len(next_a_solutions_in_range) == 1 next_a_soln = next_a_solutions_in_range[0] print("a_{n-%d} = %s" % (step + 1, next_a_soln)) next_h_integral = Integral( f_star(P, t, transitions), (t, next_a_soln, last_a)) next_h = 1 / next_h_integral.doit() print("h_{n-%d} = %s" % (step + 1, next_h)) print("dF_{n-%d} coeff = %s" % (step + 1, next_h * f_star_products[-1])) f_star_products.append(f_star_products[-1] * (1 - P_next_a)) transitions.appendleft(next_a_soln) normalizing_constants.appendleft(next_h) return transitions

Finally, we can run it with the simplest possible probability function:

x = Symbol('x') compute_as_and_bs(Lambda((x,), x), 3)

The output is

P(a_n) = 1/3 a_n = 1/3 h_n = 1/4 P(a_{n-1}) is one of [1/5] a_{n-1} = 1/5 h_{n-1} = 3/16 dF_{n-1} coeff = 1/8 P(a_{n-2}) is one of [1/7] a_{n-2} = 1/7 h_{n-2} = 5/32 dF_{n-2} coeff = 1/12 P(a_{n-3}) is one of [1/9] a_{n-3} = 1/9 h_{n-3} = 35/256 dF_{n-3} coeff = 1/16

This matches up so far with Restrepo’s example, since gives . Since we have the normalizing constants , we can also verify the probability distribution for each action aligns with Restrepo’s example. The constant in the point mass function is supposed to be . This is what I printed out as `dF_{n-k}`

. In Restrepo’s example, this is expected to be , which is exactly what’s printed out.

Another example using :

P(a_n) = 1/3 a_n = 3**(2/3)/3 h_n = 1/4 P(a_{n-1}) is one of [-1/3, 1/5] a_{n-1} = 5**(2/3)/5 h_{n-1} = 3/16 dF_{n-1} coeff = 1/8 P(a_{n-2}) is one of [-1/5, 1/7] a_{n-2} = 7**(2/3)/7 h_{n-2} = 5/32 dF_{n-2} coeff = 1/12 P(a_{n-3}) is one of [-1/7, 1/9] a_{n-3} = 3**(1/3)/3 h_{n-3} = 35/256 dF_{n-3} coeff = 1/16

One thing to notice here is that the normalizing constants don’t appear to depend on the distribution. Is this a coincidence for this example, or a pattern? I’m not entirely sure.

Next time we’ll rewrite the code from this post so that it can be used to compute the generic (non-symmetric) solution, see what they can tell us, and from there we’ll start diving into the propositions and proofs.

Until next time!