Untitled
unknown
plain_text
a month ago
1.4 kB
7
Indexable
Never
gen.gaussian <- function() { sign <- sample(c(-1, 1), 1) alpha <- runif(1, 0, 1) beta <- runif(1, 0, 3) return(list(fun = function(x) {sign * alpha * exp(- beta * x^2)}, sign = sign, alpha = alpha, beta = beta, type = "gaussian")) } gen.sine <- function() { alpha <- runif(1, 0, 1) beta <- runif(1, 0, 3) return(list(fun = function(x) {beta * sin(2 * pi * alpha * x)}, alpha = alpha, beta = beta, type = "sine")) } gen.cos <- function() { alpha <- runif(1, 0, 1) beta <- runif(1, 0, 3) return(list(fun = function(x) {beta * cos(2 * pi * alpha * x)}, alpha = alpha, beta = beta, type = "cosine")) } gen.logis <- function() { alpha <- runif(1, 0, 1) beta <- runif(1, 0, 3) return(list(fun = function(x) {beta/(1 + exp(-alpha * x))}, alpha = alpha, beta = beta, type = "logistic")) } function.list <- list(gen.gaussian, gen.sine, gen.cos, gen.logis) gen.mixing.matrix <- function(d, seed = 7) { set.seed(seed) foos.idx <- sample(1:length(function.list), d^2, T) return(function(x) { m <- matrix(0, nrow = d, ncol = d) cnt <- 1 for (i in 1:d) { for (j in 1:d) { set.seed(seed) foo <- function.list[[foos.idx[cnt]]]() m[i, j] <- foo$fun(x) cnt <- cnt + 1 } } m }) }
Leave a Comment