Adjustments for CRAN upload
[valse.git] / test / helper.R
1 #' Generate a sample of (X,Y) of size n with default values
2 #'
3 #' @param n sample size
4 #' @param p number of covariates
5 #' @param m size of the response
6 #' @param k number of clusters
7 #'
8 #' @return list with X and Y
9 #'
10 generateXYdefault = function(n, p, m, k)
11 {
12 meanX = rep(0, p)
13 covX = diag(p)
14 covY = diag(m)
15 ω = rep(1./k,k)
16 #initialize beta to a random number of non-zero random value
17 β = array(0, dim=c(p,m,k))
18 for (j in 1:p)
19 {
20 nonZeroCount = sample(1:m, 1)
21 if (nonZeroCount >= 2)
22 β[j,1:nonZeroCount,] = matrix(runif(nonZeroCount*k), ncol=k)
23 else
24 β[j,1,] = runif(k)
25 }
26
27 sample_IO = generateXY(n, ω, meanX, β, covX, covY)
28 return (list(X=sample_IO$X,Y=sample_IO$Y))
29 }
30
31 #' Initialize the parameters in a basic way (zero for the conditional mean, uniform for
32 #' weights, identity for covariance matrices, and uniformly distributed for the
33 #' clustering)
34 #'
35 #' @param n sample size
36 #' @param p number of covariates
37 #' @param m size of the response
38 #' @param k number of clusters
39 #'
40 #' @return list with phiInit, rhoInit,piInit,gamInit
41 #'
42 basicInitParameters = function(n,p,m,k)
43 {
44 phiInit = array(0, dim=c(p,m,k))
45
46 piInit = (1./k)*rep(1,k)
47
48 rhoInit = array(dim=c(m,m,k))
49 for (i in 1:k)
50 rhoInit[,,i] = diag(m)
51
52 gamInit = 0.1 * matrix(1, nrow=n, ncol=k)
53 R = sample(1:k, n, replace=TRUE)
54 for (i in 1:n)
55 gamInit[i,R[i]] = 0.9
56 gamInit = gamInit/sum(gamInit[1,])
57
58 return (list("phiInit"=phiInit, "rhoInit"=rhoInit, "piInit"=piInit, "gamInit"=gamInit))
59 }