Description Usage Arguments Value Examples
A graycode neighbour is generated by randomly picking two groups and put them together, or randomly pick one group and split it into 2 groups, only generate one random neighbour each time
1 2 3 4 5 6 7 | partition_random_neighbour(x, method = "ChangeOne",
IncludeOrigin = FALSE)
partition_all_neighbour(x, method = "ChangeOne", IncludeOrigin = FALSE)
partition_all_neighbour_restricted(x, group = NULL, apart = NULL,
method = "ChangeOne", IncludeOrigin = FALSE)
|
x |
a numerical vector representing a graycode |
method |
which method used to generate neighbours; either |
IncludeOrigin |
logical; indicating whether the input graycode should be included |
group |
a vector indicating which elements should be grouped together |
apart |
a vector indicating which elements should not be grouped together |
a random neighbouring partition or a matrix of all neighbouring partitions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | partition_random_neighbour(x = c(1,2,3,1),
IncludeOrigin = FALSE) # "ChangeOne" method by default
partition_all_neighbour(x = c(1,2,3,1),
IncludeOrigin = FALSE)
partition_random_neighbour(c(1,2,3,4,2,4,1),
method="GroupSplit",
IncludeOrigin = FALSE)
partition_all_neighbour(c(1,2,2,3,3,3,3),
method="GroupSplit",
IncludeOrigin = FALSE)
partition_all_neighbour_restricted(x = c(1,2,3,1),
group=NULL,
apart=c(2,3),
IncludeOrigin = TRUE)
partition_all_neighbour_restricted(x=c(1,2,3,1),
group = c(2,3),
apart = NULL,
IncludeOrigin = TRUE)
# the following example shows the distribution of generating random partition is not uniform
x <- c(1,2,2,2,3,3,3)
allneighbour <- NULL
for (j in c(1:1000)){
oneneighbour <- partition_random_neighbour(x, method = "GroupSplit")
allneighbour <- rbind(allneighbour, oneneighbour)
}
dim(allneighbour)
uniquecode <- unique(allneighbour)
dim(uniquecode)
dim(partition_all_neighbour(x, method="GroupSplit"))
count1<-count2<-count3<-count4<-count5<-count6<-count7<-count8<-count9<-0
for (i in c(1: dim(allneighbour)[1])){
if (all(uniquecode[1,] == allneighbour[i,])) count1 <- count1 + 1
if (all(uniquecode[2,] == allneighbour[i,])) count2 <- count2 + 1
if (all(uniquecode[3,] == allneighbour[i,])) count3 <- count3 + 1
if (all(uniquecode[4,] == allneighbour[i,])) count4 <- count4 + 1
if (all(uniquecode[5,] == allneighbour[i,])) count5 <- count5 + 1
if (all(uniquecode[6,] == allneighbour[i,])) count6 <- count6 + 1
if (all(uniquecode[7,] == allneighbour[i,])) count7 <- count7 + 1
if (all(uniquecode[8,] == allneighbour[i,])) count8 <- count8 + 1
if (all(uniquecode[9,] == allneighbour[i,])) count9 <- count9 + 1
}
c(count1, count2, count3, count4, count5, count6, count7, count8, count9)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.