Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upSporadic error during fitting or cross-validation in: sampleMcmc -> alignPosterior -> abind #27
Comments
|
I think I fixed this issue just an hour ago - was some unclearly-sourced bug happening at the stage of aligning the number of latent factors on different chains after the HMSC model was fitted (commit 45f6071). Please try again now. |
|
@gtikhonov Great, thank you! I'll retry |
|
@gtikhonov I was about to ask about this issue too, but maybe it got fixed by the same modifications? Same pattern, except this error shows up when I'm using a spatial random effect. Models again run fine with short chains, and sometimes fit and cross-validate with long chains, but eventually I get this error (either at fitting or cross val): Error in if (alphapw[alpha[h], 1] > 0) { : argument is of length zero |
|
Yes, this issue can have the same conceptual source - varying number of factors in different chains. Did it happen with recent versions? |
|
Yes, it happened with an installation from ~16 October |
|
Well, currently I do not notice any logical flaws which could lead to such situation. Although this does not guarantee that there are none. Just to ensure several things:
You can start with point 3) if refitting your models takes considerable time. If you can replicate this behaviour with any sharable code that I can rerun, that would be helpful. |
|
Ok, I will work through that list and see what I can figure out. The first thing I notice is that I was using the CRAN version, so I will re-install from github. I haven't included alignPost=TRUE when using sampleMcmc but can start...but TRUE is maybe the default? |
|
Ok, I re-installed from github using (correct?): Then I ran the following code and still go the same error. This was on an HPC cluster just fyi. Maybe I can upload a model object for you to try? #####################################
|
|
I've fixed the minor bug that caused this misbehaviour. It was just due ti setting some indices to 0 instead of 1. Perhaps I just had too much Python coding recently and it did not catch my eye immediately.
objects - these are vectors and all values of 0 must be replaced to 1. Then you can use the fitted object in the postprocessing. |
|
Great, thank you for the quick response! Will give it a try. |
|
Hi Gleb, I seem to be getting the same error when running multiple chains using the sampleMcmc function. Error in abind(cpL[[j]]$Delta[[r]], array(1, DeltaAddDim), along = 1) : I don't get it every time, but it is the majority of times. It seems to be an issue with joining the chains at the end as the chains appear to run fine. I haven't yet had an issue when running a single chain. Here is my model structure: m <- Hmsc(Y = Y, Temp is continuous. I have not encountered this error when I run models with temp or dispersal on their own as fixed effects. I am running the current GitHub version of Hmsc in R.3.6.1. |
|
Yes, it is a very annoying problem caused by a small utility that is called from |
|
Thanks for the quick reply and solution. I really appreciate the package. |
Hi. When fitting several lists of 3-4 models I've been getting the following error, but not every time.
For example, when I run fit the models using short chains (e.g. 50 samples with thin = 3) as a test, all three models will fit and cross-validate successfully.
But, when I try with more samples (using the mcmc parameters as below) I eventually get the error I show below. Sometimes the error comes up during model fitting, other times during cross-validation. Sometime on the first model in the list, sometimes the second.
The models all have 100 sites, 100 species, 5 continuous environmental covariates, 3 trait covariates (one of which is a 3-level factor), and a phylogeny. Random effects include site (non-spatial), year, and project.
#read in models
redHPC1=readRDS("t02ns.rds")
#make list for cross validation results
crossFit=list("a")
#set fitting parameters
nChains = 2
thin = 5
samples = 1000
transient = 400thin
verbose = 150thin
for (i in 1:length(redHPC1)) {
#run the model in parallel
redHPC1[[i]] = sampleMcmc(redHPC1[[i]], thin = thin, samples = samples,
transient = transient, nChains = nChains, nParallel = 2,
verbose = verbose, initPar = "fixed effects")
#save results
saveRDS(redHPC1, file = "t02nsFIT.rds")
#do cross-validation
partition = createPartition(redHPC1[[i]], nfolds = 2, column = "Site")
preds = computePredictedValues(redHPC1[[i]],partition=partition,nParallel = 2)
crossFit[[i]] = evaluateModelFit(hM=redHPC1[[i]], predY=preds)
#save cross-validation results
saveRDS(crossFit, file = "t02nsCROSS.rds")
}`
[1] "Setting updater$Gamma2=FALSE due to specified phylogeny matrix"
Error in abind(cpL[[j]]$Delta[[r]], array(1, DeltaAddDim), along = 1) :
arg 'X2' has dims=1, 2; but need dims=X, 1
Calls: sampleMcmc -> alignPosterior -> abind