latin: Random latin squares

Description Usage Arguments Details Author(s) References See Also Examples

Description

Various functionality for generating random latin squares

Usage

1
2
3
4
5
6
7
8

Arguments

a

A latin square

i

An incidence array

n,include.improper,size,start,burnin

Various control arguments; see details section

Details

From Jacobson and Matthew 1996, an n-by-n latin square LS is equivalent to an n-by-n-by-n array A with entries 0 or 1; the dimensions of A are identified with the rows, columns and symbols of LS; a 1 appears in cell (r,c,s) of A iffi the symbol s appears in row r, column s of LS. Jacobson and Matthew call this an incidence cube.

The notation is readily generalized to latin hypercubes and incidence() is dimensionally vectorized.

An improper incidence cube is an incidence cube that includes a single -1 entry; all other entries must be 0 or 1; and all line sums must equal 1.

Author(s)

Robin K. S. Hankin

References

M. T. Jacobson and P. Matthews 1996. “Generating uniformly distributed random latin squares”. Journal of Combinatorial Designs, volume 4, No. 6, pp405–437

See Also

is.magic

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
rlatin(5)
rlatin(n=2, size=4, burnin=10)

# An example that allows one to optimize an objective function
# [here f()] over latin squares:
gr <- function(x){ another_latin(matrix(x,7,7)) }
set.seed(0)
index <- sample(49,20)
f <- function(x){ sum(x[index])}
jj <- optim(par=as.vector(latin(7)), fn=f, gr=gr, method="SANN", control=list(maxit=10))
best_latin <- matrix(jj$par,7,7)
print(best_latin)
print(f(best_latin))

#compare starting value:
f(circulant(7))

magic documentation built on May 2, 2019, 12:21 p.m.