Error : Initialization from source failed. variable chi_chol_Imag missing error occurred during calling the sampler; sampling not done
translatedModel<-stanc(file="GST_bayesian_unconstrained4.stan",model_name='CPTbehavioral')
compiledModel<-stan_model(stanc_ret=translatedModel,verbose=FALSE)
chiDimensions<-4
chiDimensionsDoubled<-chiDimensions*2
numberOfGates<-4
chi1<-matrix(c(1.4000, -0.0136, 0.0136, 0.0005,
-0.1360, 0.2005, -0.0005, 0.0000,
0.0136, -0.0005, 0.2005, 0.0000,
0.0005, 0.0000, 0.0000, 0.1990,
0.0000, 0.0007, 0.0007, 0.0000,
-0.0007, 0.0000, -0.0197, 0.0001,
-0.0007, 0.0197, 0.0000, 0.0001,
0.0000, -0.0001, -0.0001, 0.0000), chiDimensionsDoubled,chiDimensions,byrow=TRUE)
chi2<-matrix(c( 0.7985, -0.0129, 0.0033, 0.0067,
-0.0129, 0.8048, -0.0067, 0.0095,
0.0033, -0.0067, 0.2115, -0.1449,
0.0067, 0.0095, -0.1449, 0.1852,
0.0000, -0.6154, -0.0077, 0.0505,
0.6154, 0.0000, -0.0715, 0.0085,
0.0077, 0.0715, 0.0000, -0.0011,
-0.0505, -0.0085, 0.0011, 0.0000), chiDimensionsDoubled,chiDimensions,byrow=TRUE)
chi3<-matrix(c( 0.7985, -0.0033, 0.0129, 0.0067,
-0.0033, 0.2115, -0.0067, 0.1449,
0.0129, -0.0067, 0.8048, -0.0095,
0.0067, 0.1449, -0.0095, 0.1852,
0.0000, -0.0078, -0.6154, -0.0505,
0.0078, 0.0000, -0.0715, -0.0011,
0.6154, 0.0715, 0.0000, 0.0085,
0.0505, 0.0011, -0.0085, 0.0000), chiDimensionsDoubled,chiDimensions,byrow=TRUE)
chi4<-matrix(c( 0.1992, -0.0134, 0.0548, 0.0005,
-0.0134, 1.4028, -0.0005, -0.0412,
0.0548, -0.0005, 0.1997, -0.0002,
0.0005, -0.0412, -0.0002, 0.1983,
0.0000, 0.0047, -0.0018, 0.0594,
-0.0047, 0.0000, -0.0790, 0.0026,
0.0018, 0.0790, 0.0000, -0.0039,
-0.0594, -0.0026, 0.0039, 0.0000), chiDimensionsDoubled,chiDimensions,byrow=TRUE)
chi_Init<-list(chi1,chi2,chi3,chi4)
chi_Init_Real<-list(chi1[1:4,1:4],chi2[1:4,1:4],chi3[1:4,1:4],chi4[1:4,1:4])
chi_Init_Imag<-list(chi1[5:8,1:4],chi2[5:8,1:4],chi3[5:8,1:4],chi4[5:8,1:4])
chi_chol_Real<-list()
chi_chol_Imag<-list()
for (i in 1:4){
chi_chol_Real[[i]]<-t(chol(chi_Init_Real[[i]]))
chi_chol_Imag[[i]]<-chi_chol_Real[[i]]
}
expData = list('chiDimensions'=chiDimensions,
'chiDimensionsDoubled'=chiDimensionsDoubled,
'numberOfGates'=numberOfGates)
inits = function(){
return(
list(
chi_chol_Imag=chi_chol_Imag,
chi_chol_Real=chi_chol_Real
)
)
}
hierarchical= sampling(compiledModel,data=expData, init=inits, iter=250, chains=1)#,
$chi_chol_Imag
$chi_chol_Imag[[1]]
[,1] [,2] [,3] [,4]
[1,] 1.1832159566 0.000000e+00 0.000000e+00 0.000000
[2,] -0.0114940979 4.476247e-01 0.000000e+00 0.000000
[3,] 0.0114940979 -8.218619e-04 4.476240e-01 0.000000
[4,] 0.0004225771 1.085093e-05 -1.083102e-05 0.446094
$chi_chol_Imag[[2]][1,] 0.893588272 0.000000000 0.0000000 0.0000000[,1] [,2] [,3] [,4]
[2,] -0.014436179 0.896990299 0.0000000 0.0000000
[3,] 0.003692976 -0.007409988 0.4598168 0.0000000
[4,] 0.007497860 0.010711644 -0.3150131 0.2929092
$chi_chol_Imag[[3]][1,] 0.893588272 0.0000000 0.000000000 0.0000000[,1] [,2] [,3] [,4]
[2,] -0.003692976 0.4598765 0.000000000 0.0000000
[3,] 0.014436179 -0.0144532 0.896873849 0.0000000
[4,] 0.007497860 0.3151448 -0.005634447 0.2929092
$chi_chol_Imag[[4]][1,] 0.446318272 0.000000000 0.0000000000 0.0000000[,1] [,2] [,3] [,4]
[2,] -0.030023418 1.184017987 0.0000000000 0.0000000
[3,] 0.122782336 0.002691129 0.4296711019 0.0000000
[4,] 0.001120277 -0.034768362 -0.0005678391 0.4439477
$chi_chol_Real
$chi_chol_Real[[1]][1,] 1.1832159566 0.000000e+00 0.000000e+00 0.000000[,1] [,2] [,3] [,4]
[2,] -0.0114940979 4.476247e-01 0.000000e+00 0.000000
[3,] 0.0114940979 -8.218619e-04 4.476240e-01 0.000000
[4,] 0.0004225771 1.085093e-05 -1.083102e-05 0.446094
$chi_chol_Real[[2]][1,] 0.893588272 0.000000000 0.0000000 0.0000000[,1] [,2] [,3] [,4]
[2,] -0.014436179 0.896990299 0.0000000 0.0000000
[3,] 0.003692976 -0.007409988 0.4598168 0.0000000
[4,] 0.007497860 0.010711644 -0.3150131 0.2929092
$chi_chol_Real[[3]][1,] 0.893588272 0.0000000 0.000000000 0.0000000[,1] [,2] [,3] [,4]
[2,] -0.003692976 0.4598765 0.000000000 0.0000000
[3,] 0.014436179 -0.0144532 0.896873849 0.0000000
[4,] 0.007497860 0.3151448 -0.005634447 0.2929092
$chi_chol_Real[[4]][1,] 0.446318272 0.000000000 0.0000000000 0.0000000[,1] [,2] [,3] [,4]
[2,] -0.030023418 1.184017987 0.0000000000 0.0000000
[3,] 0.122782336 0.002691129 0.4296711019 0.0000000
[4,] 0.001120277 -0.034768362 -0.0005678391 0.4439477
Sorry for the incomplete code. I was hoping that it would be enough. I'll post a more complete version:
data {
int<lower=1> chiDimensions;
int<lower=1> numberOfGates;
}
parameters{
#Array of matrices. The length of the array is the number of gates that are being estimated.
cholesky_factor_cov[chiDimensions] chi_chol_Imag[numberOfGates];
cholesky_factor_cov[chiDimensions] chi_chol_Real[numberOfGates];
}
model {
}
Here are the complete flies. All you have to do is change the working directory.
drho_init<-matrix(c(1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0),nrow=rhoDimensions,ncol=rhoDimensions)
E_init<-matrix(c(1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0),nrow=rhoDimensions,ncol=rhoDimensions)
pi1.1 initialized to invalid value (inf)
Sorry about that. I forgot to clear my environment before I tested it and sent it to you. This version should produce the error I'm experiencing.
pi1.1 initialized to invalid value (inf)
Initialization between (-2, 2) failed after 100 attempts.
Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
simplex[rhoDimensions] pi1;
> pi1_init
[1] 1 0
SAMPLING FOR MODEL 'CPTbehavioral' NOW (CHAIN 1). Error : Initialization from source failed. variable chi_chol_Real missing
error occurred during calling the sampler; sampling not doneSo is it the length of the initial value I'm giving for pi1 or is it that I'm giving it a case where the values are 1 and 0. Would perturbing it slightly help? If it's the length, should I then just give it one number?
R does gratuitously drop length 1 dimensions but that's not the problem here. This code:
chi_Init<-list(chi1,chi2,chi3,chi4)
chi_Init_Real<-list(chi1[1:4,1:4],chi2[1:4,1:4],chi3[1:4,1:4],chi4[1:4,1:4])
chi_Init_Imag<-list(chi1[5:8,1:4],chi2[5:8,1:4],chi3[5:8,1:4],chi4[5:8,1:4])
explicitely makes a list of matrices. You need to make an array as in Patrick's post above.
Krzysztof