X-Git-Url: https://git.auder.net/?p=valse.git;a=blobdiff_plain;f=pkg%2FR%2FgenerateXY.R;h=fe86045b1f08d3d21cf3161474d6992909b9f1de;hp=069c4702960603083fefea62f8431b9f72d1cb8b;hb=ffdf94474d96cdd3e9d304ce809df7e62aa957ed;hpb=20d12623f4f395ba126570b3230fc80214191d8e diff --git a/pkg/R/generateXY.R b/pkg/R/generateXY.R index 069c470..fe86045 100644 --- a/pkg/R/generateXY.R +++ b/pkg/R/generateXY.R @@ -1,4 +1,4 @@ -#' generateXY +#' generateXY #' #' Generate a sample of (X,Y) of size n #' @@ -12,28 +12,28 @@ #' @return list with X and Y #' #' @export -generateXY = function(n, π, meanX, β, covX, covY) +generateXY <- function(n, π, meanX, β, covX, covY) { - p <- dim(covX)[1] - m <- dim(covY)[1] - k <- dim(covY)[3] - - X <- matrix(nrow=0, ncol=p) - Y <- matrix(nrow=0, ncol=m) - - #random generation of the size of each population in X~Y (unordered) - sizePop <- rmultinom(1, n, π) - class <- c() #map i in 1:n --> index of class in 1:k - - for (i in 1:k) - { - class <- c(class, rep(i, sizePop[i])) - newBlockX <- MASS::mvrnorm(sizePop[i], meanX, covX) - X <- rbind( X, newBlockX ) - Y <- rbind( Y, t(apply( newBlockX, 1, function(row) - MASS::mvrnorm(1, row %*% β[,,i], covY[,,i]) )) ) - } - - shuffle = sample(n) - list("X"=X[shuffle,], "Y"=Y[shuffle,], "class"=class[shuffle]) + p <- dim(covX)[1] + m <- dim(covY)[1] + k <- dim(covY)[3] + + X <- matrix(nrow = 0, ncol = p) + Y <- matrix(nrow = 0, ncol = m) + + # random generation of the size of each population in X~Y (unordered) + sizePop <- rmultinom(1, n, π) + class <- c() #map i in 1:n --> index of class in 1:k + + for (i in 1:k) + { + class <- c(class, rep(i, sizePop[i])) + newBlockX <- MASS::mvrnorm(sizePop[i], meanX, covX) + X <- rbind(X, newBlockX) + Y <- rbind(Y, t(apply(newBlockX, 1, function(row) MASS::mvrnorm(1, row %*% + β[, , i], covY[, , i])))) + } + + shuffle <- sample(n) + list(X = X[shuffle, ], Y = Y[shuffle, ], class = class[shuffle]) }