Code Monkey home page Code Monkey logo

baylum's People

Contributors

guiguerin avatar imgoej avatar nfrerebeau avatar philippe-a avatar r-baylum avatar rlumsk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

imgoej

baylum's Issues

AgeC14_Computation() - cal. C-14 plot shows no data

Expected behaviour

The C-14 ages vs ages plot shows something.

Observed behaviour

Only the plot frame is shown, the values are off-scale.

Running mini example

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)

Comments

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.

Need Clarification on CSV Files for BayLum Package

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:

  • DiscPos.csv
  • DoseEnv.csv
  • DoseSource.csv
  • rule.csv

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

Generate_DataFile_MG(): regeneration doses are off

Expected behaviour

To extract the proper regen-doses to pair with LxTx values.

Observed behaviour

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.

Running mini example

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)

pic1

One possible solution

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)

Rplot2

But I haven't done a lot to check how this may break compatibility for other setups.

Age_OSLC14() ... crashes with Compilation error on line 8.

Expected behaviour

The function runs without any error according to the manual description.

Observed behaviour

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] 

Running mini example

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
  )

Error analysis

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]]

Solution?

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]]

Slicer stuck at value with infinite density - for model AgesMultiCS2_EXPZO in `AgeS_Computation()`

Problem

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?

Intermediate solution

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.

SCMatrix() - endless loop

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?

Waring: closing unsued connection

Expected behaviour

There should be no warning when running the function Generate_DataFile

Observed behaviour

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

Running mini example

library(BayLum)

Calibration curves for 14C ages

Expected behaviour:

Calibration curves for radiocarbon in the package should give calibrated ages in ka (the unit of OSL ages)

Observed behaviour:

Calibrated ages are given in years.

Running mini example

library(BayLum)

Drop AppVeyor integration

@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.

Remove split pdf() and dev.off() calls in all functions

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()
 }

Update Vignette

  • Make sure that everything is evaluated the time the vignette is built
  • Check example data and consider adding data to 'inst/extdata'

Age_OSLC14() ... Compilation error on line 72

Observed behaviour

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. 

Running mini example

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
  )

Solution?

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.

Labels for figures produced by MCMC_plot

Expected behaviour

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.

Observed behaviour

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).

Running mini example

library(BayLum)
load(DATA3)
priorage <- c(10,60) 
Age <- Age_Computation(
  DATA = DATA3,
  SampleName = "FER1",
  PriorAge = priorage,
  Iter = 100,
  quiet = FALSE)

"Gelman and Rubin" instead of "Gelman and Rudin"

Expected behaviour

In the output of all Age calculation (C14, OSL, and combination) functions and of Palaeodose_Computation, one should read "Rubin"

Observed behaviour

One reads "Rudin"

Running mini example

library(BayLum)

AgeS_Computation(): ERROR RUNTIME when running method = "rjparallel"

Expected behaviour

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.

Observed behaviour

I encounter runtime error.

Running mini example

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
)

Notes

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

Move to GitHub actions

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.