latin {magic}R Documentation

Random latin squares

Description

Various functionality for generating random latin squares

Usage

incidence(a)
is.incidence(a, include.improper)
is.incidence.improper(a)
unincidence(a)
inc_to_inc(a)
another_latin(a)
another_incidence(i)
rlatin(n,size=NULL,start=NULL,burnin=NULL)

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\times n latin square LS is equivalent to an n\times n\times 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


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))



[Package magic version 1.6-1 Index]