Williams designs with 5 products
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
In a previous post I created small Williams designs for an even number of products. This worked very well, also because the number of permutations could be restricted significantly due to symmetry. Unfortunately this does not work so well with an odd number of products. The symmetry is not so obvious. In fact, using brute force I can find non-symmetric solutions for five products. However, I am lacking force to handle more than five products in a reasonable time.
design setup
The design fixed parameters
To get the design I used a few assumptions. The number of rows is twice the number of columns. This is because I remember reading there are no solutions with the same number of rows as columns. The first row reads 1:n. The first column is all elements of 1:n twice.
Filling in the design
The approach is actually very simple.
- Look at the first not yet know point.
- Examine which value it could have.
- not yet used in current row
- at most once used in current column
- at maximum once used after the product in current row, one column to the left (carry over)
- if this is the second column and the first column of this row is the same as the first column of the previous row, then the current value must be higher than the value of one row up.
- Try the possible values in a loop
- Within that loop go back to step one
Implemented recursively. In all actually, it is quite brute force. I should be doing this in C or Julia rather than in R which is relatively slow.
Tricks
Compared to the version with an even number of products I implemented some things a bit smarter. Removed some if within a for loop by selecting the objects over which the loop sequences. I also noticed some things which surprised me in making things faster. For instance, creating temporary variables (e.g. row <- desconst$todo[desobject$count,2L]) is faster than using desconst$todo[desobject$count,2L] to index matrices later on. Merging two simple lines of code into one complex line of code is slower. Apparently it is cheaper to store a small result than have the interpreter figure out a complex line of code. Hence I used quite a lot of local variables, certainly more than I find ‘nice’.
Designs
design symmetric in columns
designs four rows symmetric in columns
[,1] [,2] [,3] [,4] [,5]
[1,] 1 2 3 4 5
[2,] 1 3 4 2 5
[3,] 2 3 5 1 4
[4,] 2 4 1 5 3
[5,] 3 1 5 4 2
[6,] 3 5 2 1 4
[7,] 4 1 2 5 3
[8,] 4 5 1 3 2
[9,] 5 2 4 3 1
[10,] 5 4 3 2 1
design not symmetric in columns
R code
generation
checking
prints
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.