**A**n ICLR 2019 paper by Neklyudov, Egorov and Vetrov on an optimal choice of the proposal in an independent Metropolis algorithm I discovered via an X validated question. Namely whether or not the expected Metropolis-Hastings acceptance ratio is always one (which it is not when the support of the proposal is restricted). The paper mentions the domination of the Accept-Reject algorithm by the associated independent Metropolis-Hastings algorithm, which has actually been stated in our Monte Carlo Statistical Methods (1999, Lemma 6.3.2) and may prove even older. The authors also note that the expected acceptance probability is equal to one minus the total variation distance between the joint defined as target x Metropolis-Hastings proposal distribution and its time-reversed version. Which seems to suffer from the same difficulty as the one mentioned in the X validated question. Namely that it only holds when the support of the Metropolis-Hastings proposal is at least the support of the target (or else when the support of the joint defined as target x Metropolis-Hastings proposal distribution is somewhat symmetric. Replacing total variation with Kullback-Leibler then leads to a manageable optimisation target if the proposal is a parameterised independent distribution. With a GAN version when the proposal is not explicitly available. I find it rather strange that one still seeks independent proposals for running Metropolis-Hastings algorithms as the result will depend on the family of proposals considered and as performances will deteriorate with dimension (the authors mention a 10% acceptance rate, which sounds quite low). [As an aside, ICLR 2020 will take part in Addis Abeba next April.]

## Archive for optimisation

## an independent sampler that maximizes the acceptance rate of the MH algorithm

Posted in Books, Kids, Statistics, University life with tags accept-reject algorithm, adaptive Monte Carlo algorithm, Addis Abeba, Bayesian GANs, Ethiopia, ICLR 2019, importance sampling, Kullback-Leibler divergence, Monte Carlo Statistical Methods, optimal acceptance rate, optimisation, reversibility, simulation, total variation on September 3, 2019 by xi'an## Le Monde puzzle [#1099]

Posted in Books, Kids, R with tags brute force, Le Monde, mathematical puzzle, optimisation, powers of two, R on April 28, 2019 by xi'an**A** simple 2×2 Le Monde mathematical puzzle:

Arielle and Brandwein play a game out of two distinct even integers between 1500 and 2500, and y. Providing one another with either the pair (x/2,y+x/2) or the pair (x+y/2,y/2) until they run out of even possibilities or exceed 6 rounds. When x=2304, what is the value of y that makes Brandwein win?

Which I solved by a recursive function (under the constraint of a maximum of 11 levels of recursion):

nezt=function(x,y,i=1){ if ((i>11)||((is.odd(x)&is.odd(y)))){ return(-1) }else{ z=-1 if (is.even(x)) z=-nezt(x/2,y+x/2,i+1) if (is.even(y)) z=max(z,-nezt(y/2,x+y/2,i+1)) return(z)}}

and checking all values of y between 1500 and 2500 when x=2304, which produces y=1792 as the only value when Arielle loses. The reason behind (?) is that both 2304 and 1792 are divisible by 2⁸, which means no strategy avoids reaching stalemate after 8 steps, when it is Arielle’s turn to play.

## Le Monde puzzle [#1092]

Posted in Statistics with tags brute force, latin square, Le Monde, mathematical puzzle, optimisation, R, simulated annealing, sudoku on April 18, 2019 by xi'an**A** Latin square Le Monde mathematical puzzle that I found rather dreary:

A hidden 3×3 board contains all numbers from 1 to 9. Anselm wants to guess the board and makes two proposals. Berenicke tells him how many entries are in the right rows and colums for each proposal, along with the information that no entry is at the right location. Anselm deduces the right board.

Which I solved by brute force and not even simulated annealing, first defining a target

ordoku1=ordoku2=matrix(1,9,2) ordoku1[,1]=c(1,1,1,2,2,2,3,3,3) ordoku1[,2]=rep(1:3,3) ordoku2[,1]=c(3,2,3,1,2,3,2,1,1) ordoku2[,2]=c(2,2,3,2,3,1,1,3,1) fitz=function(ordo){ (sum(ordo[c(1,4,7),2]==1)==1)+(sum(ordo[c(2,5,8),2]==2)==1)+ (sum(ordo[c(3,6,9),2]==3)==0)+(sum(ordo[c(1,2,3),1]==1)==1)+ (sum(ordo[c(4,5,6),1]==2)==1)+(sum(ordo[c(7,8,9),1]==3)==2)+ (sum(ordo[c(6,7,9),2]==1)==2)+(sum(ordo[c(1,2,4),2]==2)==1)+ (sum(ordo[c(3,5,8),2]==3)==2)+(sum(ordo[c(4,8,9),1]==1)==1)+ (sum(ordo[c(7,2,5),1]==2)==1)+(sum(ordo[c(1,3,6),1]==3)==0)+ (!(0%in%apply((ordo-ordoku1)^2,1,sum)))+(!(0%in%apply((ordo-ordoku2)^2,1,sum))) }

on a 9×9 board entry reproducing all items of information given by Berenicke. If all constraints are met, the function returns 14. And then searched for a solution at random:

temp=1 randw=function(ordo){ for (t in 1:1e6){ chlg=sample(1:9,2) temp=ordo[chlg[1],] ordo[chlg[1],]=ordo[chlg[2],] ordo[chlg[2],]=temp if (fitz(ordo)==14){ print(ordo);break()}}}

which produces the correct board

4 3 5 6 7 1 9 2 8

## Le Monde puzzle [#1088]

Posted in Books, Kids, R with tags black block, brute force, geometry, Ising model, Le Monde, mathematical puzzle, optimisation, simulated annealing, triangle on March 29, 2019 by xi'an**A** board (Ising!) Le Monde mathematical puzzle in the optimisation mode, again:

On a 7×7 board, what is the maximal number of locations that one can occupy when imposing at least two empty neighbours ?

Which I tried to solve by brute force and simulated annealing (what else?!), first defining a target

targ=function(tabz){ sum(tabz[-c(1,9),-c(1,9)]-1.2*(tabz[-c(1,9),-c(1,9)]*tabz[-c(8,9),-c(1,9)] +tabz[-c(1,9),-c(1,9)]*tabz[-c(1,2),-c(1,9)] +tabz[-c(1,9),-c(1,9)]*tabz[-c(1,9),-c(8,9)] +tabz[-c(1,9),-c(1,9)]*tabz[-c(1,9),-c(1,2)]>2))}

on a 9×9 board where I penalise prohibited configuration by a factor 1.2 (a wee bit more than empty nodes). The perimeter of the 9×9 board is filled with ones and never actualised. (In the above convoluted products, the goal is to count how many neighbours of the entries equal to one are also equal to one. More than 2 is penalised.) The simulated annealing move is then updating the 9×9 grid gridz:

temp=1 maxarg=curarg=targ(gridz) for (t in 1:1e3){ for (v in 1:1e4){ i=sample(2:8,1);j=sample(2:8,1) newgrid=gridz;newgrid[i,j]=1-gridz[i,j] newarg=targ(newgrid) if (log(runif(1))<temp*(newarg-curarg)){ gridz=newgrid;curarg=newarg}} temp=temp+.01}

and calls to the procedure always return 28 entries as the optimum, as in

[,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 1 0 1 0 1 0 1 [2,] 0 1 1 0 1 1 0 [3,] 1 1 0 1 0 1 1 [4,] 0 0 1 0 1 0 0 [5,] 1 1 0 1 0 1 1 [6,] 0 1 1 0 1 1 0 [7,] 1 0 1 0 1 0 1

As it happens, I had misread the wording of the original puzzle, which considered a dynamic placement of the units on the board, one at a time with two free neighbours imposed.

## Le Monde puzzle [#1086]

Posted in pictures, Statistics, Travel with tags black block, brute force, geometry, Le Monde, mathematical puzzle, optimisation, triangle on March 7, 2019 by xi'an**A** terse Le Monde mathematical puzzle in the optimisation mode:

What is the maximal fraction of the surface of a triangle occupied by an inner triangle ABC where Abigail picks a summit A on a first side, Berenice B on a second side, and then Abigails picks C on the third side, towards Abigail maximising and Berenice minimising this surface?

Which I first tried to solve by pen & paper, completing another black block for the occasion, as coding the brute force R version sounded too painful:

leading me to conclude that, for a rectangle triangle (although the result sounds independent of this feature), the optimum was the middle triangle, weighting one-fourth of the original surface. Reprogramming the question in the plane to Angkor produced the same output, modulo my approximation of the triangle continuum with a 200×200/2grid:

## Le Monde puzzle [#1075]

Posted in Books, Kids, R with tags CEREMADE, competition, Dauphine, Le Monde, mathematical puzzle, optimisation, R, simulated annealing on November 22, 2018 by xi'an**A** Le Monde mathematical puzzle from after the competition:

A sequence of five integers can only be modified by subtracting an integer N from two neighbours of an entry and adding 2N to the entry. Given the configuration below, what is the minimal number of steps to reach non-negative entries everywhere? Is this feasible for any configuration?

As I quickly found a solution by hand in four steps, but missed the mathematical principle behind!, I was not very enthusiastic in trying a simulated annealing version by selecting the place to change inversely proportional to its value, but I eventually tried and also obtained the same solution:

[,1] [,2] [,3] [,4] [,5] -3 1 1 1 1 1 -1 1 1 -1 0 1 0 1 -1 -1 1 0 0 1 1 0 0 0 0

But *(update!)* Jean-Louis Fouley came up with one step less!

[,1] [,2] [,3] [,4] [,5] -3 1 1 1 1 3 -2 1 1 -2 2 0 0 1 -2 1 0 0 0 0

The second part of the question is more interesting, but again without a clear mathematical lead, I could only attempt a large number of configurations and check whether all admitted “solutions”. So far none failed.

## Le Monde puzzle [#1070]

Posted in Books, Kids, R, University life with tags CEREMADE, competition, Dauphine, dynamic programming, Le Monde, mathematical puzzle, optimisation, R on October 11, 2018 by xi'an**R**ewording Le Monde mathematical puzzle fifth competition problem

For the 3×3 tables below, what are the minimal number of steps to move from left to rights when the yellow tokens can only be move to an empty location surrounded by two other tokens?

In the 4×4 table below, there are 6 green tokens. How many steps from left to right?

Painful and moderately mathematical, once more… For the first question, a brute force simulation of random valid moves of length less than 100 returns solutions in 4 steps:

[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] 1 1 1 0 0 1 0 0 1 1 0 1 0 1 1 0 0 1 0 0 1 1 1 1 0 0 1 0 0 1 1 0 1 0 1 1 0 0 1 0 0 1 1 1 1

But this is not an acceptable move because of the “other” constraint. Imposing this constraint leads to a solution in 9 steps, but is this the lowest bound?! It actually took me most of the weekend (apart from a long drive to and from a short half-marathon!) to figure out a better strategy than brute force random exploration: the trick I eventually figured out is to start from the finishing (rightmost) value F of the grid and look at values with solutions available in 1,2,… steps. This is not exactly dynamic programming, but it keeps the running time under control if there is a solution associated with the starting (leftmost) value S. (Robin proceeded reverse-wise, which in retrospect is presumably equivalent, if faster!) The 3×3 grid has 9 choose 5, ie 126, possible configurations with 5 coins, which means the number of cases remains under control. And even so for the 4×4 grid with 6 coins, with 8008 configurations. This led to a 9 step solution for n=3 and the proposed starting grid in yellow:

[1] 1 1 1 0 0 1 0 0 1 [1] 1 1 0 0 1 1 0 0 1 [1] 1 1 0 1 1 0 0 0 1 [1] 0 1 0 1 1 1 0 0 1 [1] 0 1 1 1 0 1 0 0 1 [1] 1 1 1 1 0 0 0 0 1 [1] 0 1 1 1 1 0 0 0 1 [1] 0 0 1 1 1 0 0 1 1 [1] 0 0 1 1 0 0 1 1 1 [1] 0 0 1 0 0 1 1 1 1

and a 19 step solution for n=4:

[1] 1 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 [1] 1 0 0 0 0 1 0 0 0 0 1 1 0 0 1 1 [1] 1 0 0 0 0 1 1 0 0 0 1 1 0 0 1 0 [1] 1 1 0 0 0 1 1 0 0 0 0 1 0 0 1 0 [1] 1 1 0 0 0 0 1 1 0 0 0 1 0 0 1 0 [1] 1 1 1 0 0 0 1 1 0 0 0 0 0 0 1 0 [1] 1 0 1 1 0 0 1 1 0 0 0 0 0 0 1 0 [1] 1 1 1 1 0 0 1 0 0 0 0 0 0 0 1 0 [1] 1 1 0 1 0 1 1 0 0 0 0 0 0 0 1 0 [1] 1 0 0 1 1 1 1 0 0 0 0 0 0 0 1 0 [1] 0 0 0 1 1 1 1 0 0 0 1 0 0 0 1 0 [1] 0 0 0 1 1 1 0 0 0 1 1 0 0 0 1 0 [1] 0 0 0 1 1 1 0 0 1 1 0 0 0 0 1 0 [1] 0 0 0 1 0 1 0 0 1 1 0 0 0 1 1 0 [1] 0 0 0 1 0 1 0 0 1 0 0 0 1 1 1 0 [1] 0 0 0 1 1 1 0 0 1 0 0 0 1 0 1 0 [1] 0 0 0 1 0 1 0 0 1 1 0 0 1 0 1 0 [1] 0 0 0 1 0 1 0 0 0 1 1 0 1 0 1 0 [1] 0 0 0 1 0 1 1 0 0 1 1 0 1 0 0 0

The first resolution takes less than a minute and the second one just a few minutes (or less than my short morning run!). Surprisingly, using this approach does not require more work, which makes me wonder at the solution Le Monde journalists will propose. Given the (misguided) effort put into my resolution, seeing a larger number of points for this puzzle is no wonder.