let me explain:
My data
is a 5x5 grid of points (so n=25). Now say I want to choose J points. I can work out all possible combination combo
using the function combn
. But this is a very large matrix, and with what I want to achieve at the end, I can actually define a equivalence class by rotation (90, 180, 270 degree) and reflection. So for example, p1
is equivalent to p2,p3,p4,p5...,p8
data<-expand.grid(1:5,1:5)
J=5 # for example
combo<-combn(25,J)
# rotation symmetry
p1=c(1,6,15,20,25)
p2=c(3,4,5,21,22)
p3=c(1,6,11,20,25)
p4=c(4,5,21,22,23)
# reflection symmetry
p5=c(5,10,11,16,21)
p6=c(1,2,23,24,25)
p7=c(5,10,15,16,21)
p8=c(1,2,3,24,25)
# to help you visualize
par(mfrow=c(4,2))
equiv<-rbind(p1,p2,p3,p4,p5,p6,p7,p8)
fn<-function(x){
p.col=rep(1,25);p.col[x]=2
plot(expand.grid(1:5,1:5),col=p.col,asp=1)}
apply(equiv,1,fn)
After this, I can simply eliminate the equivalent rows, so that my combo
is a much smaller matrix.
So basically, I am looking for a script that ultimately gives me the compact version of combo
.
Any help is appreciated. Thanks.
edit: I haven't tried anything yet. I was hoping there will be some R package for graph theory/combinatorics that does this.
For each combination, you can enumerate the other elements of the equivalence class, compute some numeric quantity that identifies them (say, an MD5 checksum), and only keep the combination if it has the smallest value.
In your example, we only keep one of the 8 elements: