# a model with interactions
p <- 50
beta <- numeric(length = p)
beta[1:5] <- runif(n = 5, min = 10, max = 50)
beta[6:p] <- runif(n = p - 5, min = 0, max = 0.3)
beta <- sample(beta)
gamma <- matrix(data = runif(n = p^2, min = 0, max = 0.1), nrow = p, ncol = p)
gamma[lower.tri(gamma, diag = TRUE)] <- 0
gamma[1,2] <- 5
gamma[5,9] <- 12
f <- function(x) { return(sum(x * beta) + (x %*% gamma %*% x))}
# 10 iterations of SB
sa <- sb(p, interaction = TRUE)
for (i in 1 : 10) {
x <- ask(sa)
y <- list()
for (i in names(x)) {
y[[i]] <- f(x[[i]])
}
tell(sa, y)
}
print(sa)
plot(sa)
Run the code above in your browser using DataLab