#' @export
generateXY = function(meanX, covX, covY, pi, beta, n)
{
- p = dim(covX)[1]
- m = dim(covY)[1]
- k = dim(covY)[3]
-
- X = matrix(nrow=n,ncol=p)
- Y = matrix(nrow=n,ncol=m)
- class = matrix(nrow = n)
-
- require(MASS) #simulate from a multivariate normal distribution
- for (i in 1:n)
- {
- class[i] = sample(1:k, 1, prob=pi)
- X[i,] = mvrnorm(1, meanX, covX)
- print(X[i,])
- print(beta[,,class[i]])
- Y[i,] = mvrnorm(1, X[i,] %*% beta[,,class[i]], covY[,,class[i]])
- }
-
- return (list(X=X,Y=Y, class = class))
+ p = dim(covX)[1]
+ m = dim(covY)[1]
+ k = dim(covY)[3]
+
+ X = matrix(nrow=n,ncol=p)
+ Y = matrix(nrow=n,ncol=m)
+ class = matrix(nrow = n)
+
+ require(MASS) #simulate from a multivariate normal distribution
+ for (i in 1:n)
+ {
+ class[i] = sample(1:k, 1, prob=pi)
+ X[i,] = mvrnorm(1, meanX, covX)
+ Y[i,] = mvrnorm(1, X[i,] %*% beta[,,class[i]], covY[,,class[i]])
+ }
+
+ return (list(X=X,Y=Y, class = class))
}
#' Generate a sample of (X,Y) of size n with default values
#' @export
generateXYdefault = function(n, p, m, k)
{
- meanX = rep(0, p)
- covX = diag(p)
- covY = array(dim=c(m,m,k))
- for(r in 1:k)
- {
- covY[,,r] = diag(m)
- }
- pi = rep(1./k,k)
- #initialize beta to a random number of non-zero random value
- beta = array(0, dim=c(p,m,k))
- for (j in 1:p)
- {
- nonZeroCount = sample(1:m, 1)
- beta[j,1:nonZeroCount,] = matrix(runif(nonZeroCount*k), ncol=k)
- }
-
- sample_IO = generateXY(meanX, covX, covY, pi, beta, n)
- return (list(X=sample_IO$X,Y=sample_IO$Y))
+ meanX = rep(0, p)
+ covX = diag(p)
+ covY = array(dim=c(m,m,k))
+ for(r in 1:k)
+ {
+ covY[,,r] = diag(m)
+ }
+ pi = rep(1./k,k)
+ #initialize beta to a random number of non-zero random value
+ beta = array(0, dim=c(p,m,k))
+ for (j in 1:p)
+ {
+ nonZeroCount = sample(1:m, 1)
+ beta[j,1:nonZeroCount,] = matrix(runif(nonZeroCount*k), ncol=k)
+ }
+
+ sample_IO = generateXY(meanX, covX, covY, pi, beta, n)
+ return (list(X=sample_IO$X,Y=sample_IO$Y))
}
#' Initialize the parameters in a basic way (zero for the conditional mean, uniform for weights,
#' @export
basicInitParameters = function(n,p,m,k)
{
- phiInit = array(0, dim=c(p,m,k))
-
- piInit = (1./k)*rep(1,k)
-
- rhoInit = array(dim=c(m,m,k))
- for (i in 1:k)
- rhoInit[,,i] = diag(m)
-
- gamInit = 0.1 * matrix(1, nrow=n, ncol=k)
- R = sample(1:k, n, replace=TRUE)
- for (i in 1:n)
- gamInit[i,R[i]] = 0.9
- gamInit = gamInit/sum(gamInit[1,])
-
- return (list("phiInit" = phiInit, "rhoInit" = rhoInit, "piInit" = piInit, "gamInit" = gamInit))
+ phiInit = array(0, dim=c(p,m,k))
+
+ piInit = (1./k)*rep(1,k)
+
+ rhoInit = array(dim=c(m,m,k))
+ for (i in 1:k)
+ rhoInit[,,i] = diag(m)
+
+ gamInit = 0.1 * matrix(1, nrow=n, ncol=k)
+ R = sample(1:k, n, replace=TRUE)
+ for (i in 1:n)
+ gamInit[i,R[i]] = 0.9
+ gamInit = gamInit/sum(gamInit[1,])
+
+ return (list("phiInit" = phiInit, "rhoInit" = rhoInit, "piInit" = piInit, "gamInit" = gamInit))
}