-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sporadic 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, I just started to explore the package but keep running into the same issue - "Error in if (alphapw[alpha[h], 1] > 0) { : argument is of length zero". I've been trying to run a relatively basic model for now, with the following setup:
and for the prediction:
I got the Hmsc package from github, via and have R 3.6.3 installed. please let me know if I should provide more information (first time posting something on github), and if you have an idea of how I can fix this. |
Hi Amy, I'm not sure if this has anything to do with it, but I noticed that the install code refers to v3.0-2, whereas the latest version is 3.0-12. If you run Hope that helps! Ryan |
Hi,
The variable alphapw relates to a spatial random effect. Would be good to set up the random effect rL and how it matches with studyDesign$ID.
Otso
From: amybauer ***@***.***>
Sent: tiistai 5. lokakuuta 2021 1:08
To: hmsc-r/HMSC ***@***.***>
Cc: Subscribed ***@***.***>
Subject: Re: [hmsc-r/HMSC] Sporadic error during fitting or cross-validation in: sampleMcmc -> alignPosterior -> abind (#27)
Hi, I just started to explore the package but keep running into the same issue - "Error in if (alphapw[alpha[h], 1] > 0) { : argument is of length zero".
I tried both adding sampleMcmc(... , alignPost = TRUE) and alignPosterior(hM) prior to calling the predict(...), but it did not fix the issue. Maybe I am being blind to something obvious? Any help would be greatly appreciated!
I've been trying to run a relatively basic model for now, with the following setup:
simul <- Hmsc(Y=Y, XData = X,
XFormula = XFormula,
# TrData = TrData,
# TrFormula = TrFormula ,
# C = C,
studyDesign = studyDesign,
ranLevels=list(ID=rL),
distr = "probit")
thin = 10
samples = 1000
nChains = 3
transient = 100
mod_HMSC2 = sampleMcmc(simul,
samples = samples,
thin = thin,
transient = transient,
nChains = nChains,
nParallel = 6,
verbose = T,
alignPost = TRUE)
and for the prediction:
grid = read.csv("rpt_check.csv")
grid = grid[1:500, ]
xy.grid = as.matrix(cbind(grid$x,grid$y))
XData.grid = data.frame(ndvi_mn_r = grid$ndvi_mn_r, stringsAsFactors = T)
#XData.grid[is.na(XData.grid)] <- 0
m = mod_HMSC2[[1]]
Gradient = prepareGradient(mod_HMSC2, XDataNew = XData.grid,sDataNew = list(ID = xy.grid))
alignPosterior(mod_HMSC2)
#nParallel=7
predY = predict(mod_HMSC2, Gradient = Gradient, predictEtaMean = TRUE)
I'm using this version of the Hmsc package:
library(devtools)
install_github("hmsc-r/HMSC", ref = "v3.0-2")
and have R 3.6.3 installed.
please let me know if I should provide more information (first time posting something on github), and if you have an idea of how I can fix this.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<#27 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AEIYMZVVOGJIOZKDNK2WOFLUFIQSFANCNFSM4JD4LQ6Q>.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Hi Otso,
Weirdly, this did run on another computer that I don't have access to regularly, and ultimately, I need it to run on my computer anyways (at least for the fitting part), so again, any help is greatly appreciated! Thanks, |
Hi,
This looks basically as it should, assuming that studyDesign$ID is a factor rather than string. So can’t figure out from the error message what was the cause of the problem, probably best if you produce a reproducible example so somebody can look more close what goes wrong.
O2
From: amybauer ***@***.***>
Sent: tiistai 5. lokakuuta 2021 18:25
To: hmsc-r/HMSC ***@***.***>
Cc: Ovaskainen, Otso T ***@***.***>; Comment ***@***.***>
Subject: Re: [hmsc-r/HMSC] Sporadic error during fitting or cross-validation in: sampleMcmc -> alignPosterior -> abind (#27)
Hi Otso,
thanks for getting back to me!
This is how it is set up:
studyDesign = dat[,c("ID")]
studyDesign<-as.data.frame(studyDesign)
names(studyDesign)<-"ID"
xy = as.matrix(cbind(dat$Longitudes,dat$Latitudes))
rownames(xy)=dat$ID
colnames(xy)=c("x-coordinate","y-coordinate")
rL = HmscRandomLevel(sData=xy)
ranlevels = list(ID = rL)
ranlevels
Weirdly, this did run on another computer that I don't have access to regularly, and ultimately, I need it to run on my computer anyways (at least for the fitting part), so again, any help is greatly appreciated!
The Hmsc package and R versions on both computers are identical.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#27 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AEIYMZVRW4YIX6F7P5CFJUDUFMKFDANCNFSM4JD4LQ6Q>.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Hi everyone, again, thanks so much for trying to help me - I managed to get it to run, though I don't know how exactly. When I added the trait matrix, it gave me the same error again, but I also was able to work around that: I am just posting this in case anyone else runs into the same problem and is on the search for possible solutions. |
EDIT: I added more details to my initial post that may be helpful Hi everyone, another update from my end: it looks like I (partially) figured out where the error is sneaking in. The model itself runs with any setting I have tried so far, but the prediction does not. The models generally seem to converge nicely, too. Below, you can see an overview of parameter settings I have fitted my model to, and whether they worked for predictions or not (highlighted in red) - I put them in the same table to hopefully aid with comparison between fittings that were used (un-)successfully. The parameters that I have run a model on and successfully predicted something with vary, but it never works with more than 2 chains. I haven't been able to figure out a pattern behind this. |
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
The text was updated successfully, but these errors were encountered: