crp2a / baylum Goto Github PK
View Code? Open in Web Editor NEWChronological Bayesian models integrated for Optically Stimulated Luminescence (OSL) Dating
Home Page: https://crp2a.github.io/BayLum
License: GNU General Public License v3.0
Chronological Bayesian models integrated for Optically Stimulated Luminescence (OSL) Dating
Home Page: https://crp2a.github.io/BayLum
License: GNU General Public License v3.0
Error in rjags::jags.model(file = con, data = dataList, n.chains = n.chains, :
RUNTIME ERROR:
Compilation error on line 72.
Unknown variable k
Either supply values for this variable with the data
or define it on the left hand side of a relation.
The following example sets is a copy & paste example from the manual. However, here the example exchanges thesamplenature
. Now the first sample is the C-14 sample, not the OSL sample (as it is in the original sample).
library(BayLum)
## Load data
# OSL data
data(DATA1,envir = environment())
data(DATA2,envir = environment())
Data <- combine_DataFiles(DATA2,DATA1)
# 14C data
C14Cal <- DATA_C14$C14[1,1]
SigmaC14Cal <- DATA_C14$C14[1,2]
Names <- DATA_C14$Names[1]
# Prior Age
prior=rep(c(1,60),3)
samplenature = matrix(
data = c(0, 1, 1,
1, 0, 0),
ncol = 3,
nrow = 2,
byrow = TRUE
)
SC <- matrix(data=c(1,1,1,0,1,1,0,0,1,0,0,0),ncol=3,nrow=4,byrow=TRUE)
## Age computation of samples
Age <-
Age_OSLC14(
DATA = Data,
Data_C14Cal = C14Cal,
Data_SigmaC14Cal = SigmaC14Cal,
SampleNames = c(Names, "GDB5", "GDB3"),
Nb_sample = 3,
SampleNature = samplenature,
PriorAge = prior,
StratiConstraints = SC,
Iter = 50,
n.chains = 2
)
Lines 364 onwards in Age_OSLC14()
contains probably the root of the problem. It calculates the variable ind_change
, which is preset to 1
and expresses the index change in the sample nature matrix. If like in the example above, C-14 comes first, later the function jumps into the wrong if
expression and sets the object q
to 0
. If that happens, a loop in the BUGS model fails, and the variable k
gets never set. Unfortunately, it appears that this is a bug that is not straightforward to fix. Luckily it seems to disappear when the number of samples is increased to at least four. Nevertheless, given the odd code, the function may cause other unwanted effects, and a fix is strongly recommended.
@nfrerebeau The repository still has some kind of AppVeyor integration, which is triggered, for instance, by a PR. Please remove the AppVeyor integration in the GitHub repository settings and probably directly on the AppVeyor website.
There should be proper titles for the axes of the figures produced by the function MCMC_plot (or one Age computation function, which calls MCMC_plot). For the chains (left panel), xlab = iteration, ylab = Age (ka) for the top row, D (Gy) for the middle row, sD (Gy) for the bottom row.
When running the function MCMC_plot or one Age computation function, several problems appear in the figures showing the MCMC (unnecessary titles appear, but no axis title appears).
library(BayLum)
load(DATA3)
priorage <- c(10,60)
Age <- Age_Computation(
DATA = DATA3,
SampleName = "FER1",
PriorAge = priorage,
Iter = 100,
quiet = FALSE)
The function runs without any error according to the manual description.
Error in rjags::jags.model(file = con, data = dataList, n.chains = n.chains, :
RUNTIME ERROR:
Compilation error on line 8.
Attempt to redefine node Sigma[1,1]
This example is a copy & paste from the manual, except
for the distribution, which is set to gaussian
.
library(BayLum)
## Load data
# OSL data
data(DATA1,envir = environment())
data(DATA2,envir = environment())
Data <- combine_DataFiles(DATA2,DATA1)
# 14C data
C14Cal <- DATA_C14$C14[1,1]
SigmaC14Cal <- DATA_C14$C14[1,2]
Names <- DATA_C14$Names[1]
# Prior Age
prior=rep(c(1,60),3)
samplenature=matrix(data=c(1,0,1,0,1,0),ncol=3,nrow=2,byrow=TRUE)
SC <- matrix(data=c(1,1,1,0,1,1,0,0,1,0,0,0),ncol=3,nrow=4,byrow=TRUE)
## Age computation of samples
Age <-
Age_OSLC14(
DATA = Data,
Data_C14Cal = C14Cal,
Data_SigmaC14Cal = SigmaC14Cal,
SampleNames = c("GDB5", Names, "GDB3"),
Nb_sample = 3,
SampleNature = samplenature,
PriorAge = prior,
StratiConstraints = SC,
distribution = "gaussian",
LIN_fit = TRUE,
Origin_fit = FALSE,
Iter = 50,
n.chains = 2
)
It appears to be an error in the underlying model (the BUGS code) for a particular setting.
Below are listed the relevant code line 8 in the BUGs model (ModelOSL
).
##LIN_FIT = TRUE & Origin_fit = FALSE >> FAILED
Sigma[CS_OSL[i1],CS_OSL[i1]]=A[i1]*A[i2]*Gamma[CS_OSL[i1],CS_OSL[i1]]
##LIN_FIT = FALSE & Origin_fit = FALSE >> OK
Sigma[CS_OSL[i1],CS_OSL[i2]]=A[i1]*A[i2]*Gamma[CS_OSL[i1],CS_OSL[i2]]
##LIN_FIT = TRUE & Origin_fit = TRUE >> OK
Sigma[CS_OSL[i1],CS_OSL[i2]]=A[i1]*A[i2]*Gamma[CS_OSL[i1],CS_OSL[i2]]
##LIN_FIT = FALSE & Origin_fit = TRUE >> OK
Sigma[CS_OSL[i1],CS_OSL[i2]]=A[i1]*A[i2]*Gamma[CS_OSL[i1],CS_OSL[i2]]
##uses the default configuration
Sigma[CS_OSL[i1],CS_OSL[i2]]=A[i1]*A[i2]*Gamma[CS_OSL[i1],CS_OSL[i2]]
AgesMultiOSL_EXPLIN
fails and I guess the model should read:
Sigma[CS_OSL[i1],CS_OSL[i2]]=A[i1]*A[i2]*Gamma[CS_OSL[i1],CS_OSL[i1]]
Double check whether we should avoid this construction.
if(SavePdf){
pdf(file=paste(OutputFilePath,OutputFileName[1],'.pdf',sep=""))
}
plot_MCMC(echantillon, sample_names = SampleNames, variables = "Age")
if(SavePdf){
dev.off()
}
To extract the proper regen-doses to pair with LxTx values.
In my own sample all regen-doses take the value of the test dose. In the FER1 example case it varies between one or two values per aliquot.
library(BayLum)
# path to project folder
Path = paste0(system.file("extdata/", package = "BayLum"), "/")
# foldername of sample
FolderNames = "FER1"
# generate datafile
GD = Generate_DataFile_MG(Path = Path, FolderNames = FolderNames, BinPerSample = 1, Nb_sample = 1)
# check LxTx vs regeneration dose plots
LT_RegenDose(GD, Path = Path, FolderNames = FolderNames, BinPerSample = 1, Nb_sample = 1, SG = F)
Problem seems to arise when index numbers are extracted for all relevent Lx and Tx in line 246:
ind <- object@METADATA[(object@METADATA[["POSITION"]] %in% XLS_file[[2]]) & object@METADATA[["SEL"]], "ID"]
This is fixed if above is replaced with:
ind = unlist(lapply(1:J[bf], function(x) {
object@METADATA[(object@METADATA[["POSITION"]] %in% XLS_file[[x,2]]) & object@METADATA[["SEL"]], "ID"]
}))
My solution also requires a change to lines 303-307, which should be replaced with:
ITemps = matrix(data = NA, nrow = J[bf], ncol = K[bf])
for (j in 1:J[bf]) {
first = (j-1)*Nb_measurement+1
last = first+Nb_measurement-1
index = ind[first[bf]:last[bf]]
index = index[c(TRUE,FALSE)]
index = index[(1:K[bf]+1)]
ITemps[j, ] = object@METADATA[index, "IRR_TIME"]
}
Now we get:
# generate datafile
GD = Generate_DataFile_MG(Path = Path, FolderNames = FolderNames, BinPerSample = 1, Nb_sample = 1)
# check LxTx vs regeneration dose plots
LT_RegenDose(GD, Path = Path, FolderNames = FolderNames, BinPerSample = 1, Nb_sample = 1, SG = F)
But I haven't done a lot to check how this may break compatibility for other setups.
In the output of all Age calculation (C14, OSL, and combination) functions and of Palaeodose_Computation, one should read "Rubin"
One reads "Rudin"
library(BayLum)
Due to a change in R-devel, setting the default version of the RDS-files to '3', CRAN checks throw out an error. Results: Sources packages built using R-devel are not compatible anymore with R-versions <3.5.0. See the discussion on the R-devel mailing list.
Update: CRAN switched back to version '2' (R-devel mailing list).
Keep an eye on it.
I encountered a weird error on data I had analysed in the past using the following code (same data, of course):
AgeS_Computation(...,
LIN_fit = FALSE,
Origin_fit = TRUE,
distribution = c("gaussian"),
Iter = 5000,
t = 5,
n.chains = 3,
jags_method = "rjags")
The adaptation process always stopped with an error message telling Slicer stuck at value with infinite density
.
This did not happen in the past. The problem does not seem new, I just never saw it in 'BayLum'
. Something must have changed
with the random number generator but I could not figure out what.
Still, I believe the problem can be easily fixed in 'BayLum'
by changing the model as follows:
xa[(index[bf]+j)]~dnorm(6.5,1/(9.2^2))
to xa[(index[bf]+j)]~dnorm(6.5,1/(9.2^2))T(0.0001,)
and
De[(index[bf]+j),1]~dnorm(D[i],pD[i])
to De[(index[bf]+j),1]~dnorm(D[i],pD[i]) T(0.0001,)
Only truncating the De
node does not work, it has to be the parameter xa
too, and it should not make
any difference to the outcome. However, @philippe-a can you please double-check?
I have adjusted the function AgeS_Computation()
to inject a model on the fly via the new argument model
. This way, changes can be tested without touching the models in 'BayLum'
. I guess it was a useful change anyway.
There should be no warning when running the function Generate_DataFile
One gets the following warning when running the function Generate_DatFile:
## Warning: fermeture de la connexion inutilisée 5 (E:/Documents Guillaume/
## Stats/BayLum/Ferrassie/FER1/bin.BIN)
Note: no running mini example as there is no bin file included in the package
library(BayLum)
Calibration curves for radiocarbon in the package should give calibrated ages in ka (the unit of OSL ages)
Calibrated ages are given in years.
library(BayLum)
BayLum currently uses the third-party CI services Travis and Appveyor. Would it be possible to use GitHub Actions instead? This would reduce the number of services to manage by bringing everything under one roof.
I expect to not encounter runtime error.
Error: The following error occured when compiling and adapting the model using rjags:
Error in setParameters(init.values[[i]], i) : RUNTIME ERROR:
.RNG.seed supplied but RNG type not set
It may help to use failed.jags(c('model','data','inits')) to see model/data/inits syntax with line numbers
In addition: Warning message:
The length of the initial values argument supplied found does not correspond to the number of chains specified. Some initial values were recycled or ignored.
I encounter runtime error.
library(BayLum)
## load data
data(DATA1,envir = environment())
data(DATA2,envir = environment())
Data <- combine_DataFiles(DATA2,DATA1)
## Age computation of samples GDB5 and GDB3,
Age <- AgeS_Computation(
DATA = Data,
Nb_sample = 2,
SampleNames = c("GDB5","GDB3"),
PriorAge = c(1,10,20,60),
Iter = 1000,
quiet = FALSE,
jags_method = "rjparallel",
n.chains = 3, SaveEstimates = TRUE,
startburnin = 10000,
startsample = 10000
)
I was able to surpass the hurdle by removing the "inits" argument from the following inside "AgeS_Computation":
results_runjags <- runjags::autorun.jags(model = temp_file,
data = dataList, n.chains = n.chains, monitor = c("A",
"D", "sD"), adapt = max(Iter, 1000), silent.jags = quiet,
method = "rjparallel", inits = list(.RNG.seed = c(1234,
1234, 1234)), max.time = process_settings$max.time,
interactive = process_settings$interactive, startburnin = process_settings$startburnin,
startsample = process_settings$startsample)
I am running:
> packageVersion("BayLum")
[1] ‘0.2.1.9000.4’
> packageVersion("rjags")
[1] ‘4.12’
Cheers
For markdown documents!
The C-14 ages vs ages plot shows something.
Only the plot frame is shown, the values are off-scale.
library(BayLum)
## Load data
data(DATA_C14,envir = environment())
C14Cal <- DATA_C14$C14[,1]
SigmaC14Cal <- DATA_C14$C14[,2]
Names <- DATA_C14$Names
nb_sample <- length(Names)
## Age computation of samples without stratigraphic relations
Age <- AgeC14_Computation(
Data_C14Cal = C14Cal,
Data_SigmaC14Cal = SigmaC14Cal,
SampleNames = Names,
Nb_sample = nb_sample,
PriorAge = rep(c(20,60),nb_sample),
Iter = 500,
quiet = TRUE)
The C-14 dataset ( data(DATA_C14,envir = environment())
) has its unit in years ('a'), but the plot expects kyears ('ka'). It appears that the values are never re-calculated. The question remains whether the dataset should be changed or the function. Further, I did not test for side effects, but it appears that internally the dataset is never re-calculated into 'ka', means, it is unlikely that the calculation output is overall correct . To be tested. Other functions might be affected as well, I did not test it.
Cosmetic issue:
@nfrerebeau The badge needs a token, which I cannot generate because I don't own crp2a. Would you mind adding the token in the README so that the small button is shown again correctly?
Calling the function SCMatrix()
in the vignette causes an endless loop. Reason unknown and needs to be further investigated.
SC <- SCMatrix(Nb_sample = 2,
SampleNames = c("samp1", "samp2"))
Update: It is not an endless loop, but a user entry that is unexpectedly requested. Should be modified?
Hello,
I am trying to use the BayLum package and I am having difficulty understanding the structure and content of the following files that are required for importing data from a BINX-file:
Could you provide some guidance or examples on how these files should be structured and what kind of data they should contain?
Any help would be greatly appreciated.
Thank you
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.