Git Product home page Git Product logo

siminf's People

Contributors

irewe avatar robineriksson avatar stewid avatar tjmckinley avatar trosendal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

siminf's Issues

extTrans non-sequential alternative?

Dear authors,

I'm using SimInf to model transmission between an insect vector and two livestock host species. The insect vector is susceptible to being blown around by the wind so I'd like to use extTrans events to move them between nodes, which represent grid cells on a surface. However, the extTrans events do not work, because they are processed sequentially and order matters. For example, after moving 50% of the vector population from node 1 to node 2, an external transfer sampling from node 2 will include the vector population just transferred from node 1 in the sampling. This is undesirable behavior for this scenario. Am I missing something in the documentation that would allow for multiple extTrans events to be processed before laying down the resulting vector population distribution over the grid? If not, this would be a very handy functionality for vector or particle dispersion over a gridded surface.

Cheers,

Logan

return ABC particle distances

When determining a good tolerance vector, getting feedback from the resulting
abc-SMC particles would be very much appreciated. Instead of "hacking" this into
the acceptance function, it would be nice if the computed distances of accepted particles
could be included in the output object. Furthermore, adaptively selecting the tolerance from
the quantiles of accepted samples could then also, be implemented within the solver.

TLDR;

  1. distances of accepted ABC particles in the output object like the weights.
  2. Implement adaptivity in the tolerance from the distances of accepted particles.

trajectory method - variable names

I'm playing with the trajectory method and wonder why you chose the name 'Node' for that item in the dataframe? I notice if I want the sparse variant I can submit a similar df to the U before running the model so that makes sense but the u0 object has the column name 'ID' doesn't it? Shouldn't these be the same?

method events()

On the theme of our discussion about methods for U(), V() and tspan() perhaps another to add to the list is events()

?

SIR model breaks (unknown error message)

When using the SIR model recently added to the SimInf package, I get the following error message:
Error in siminf_error(result$error) : Unknown error code.

The following document contains an example of this error, seemingly caused by a external movement event which should be possible: 20170216_siminf_unknown_error_example.pdf

The following version of the SimInf package is currently installed on my computer:

Package: SimInf
Version: 3.0.0
Packaged: 2017-01-29 17:25:44 UTC; stefan
Repository: CRAN
Date/Publication: 2017-01-29 18:59:07
Built: R 3.3.2; x86_64-pc-linux-gnu; 2017-02-07 13:03:40 UTC; unix

Thanks for your work in developing this package!

Simulate the SIR or SEIR model on SimInf

Thanks for your development of the SimInf package, which provides several types of dynamic models such as SIS. In my situation, there is no transition from the Infectious compartment to the Susceptible compartment, there i need to modify the model setting in the package. My idea is:

  • firstly, set the transition rate from the Infectious compartment zero;
  • secondly, add the rate (transition from the Infectious compartment to Recovery compartment) to the exit rate.

But that way will influence the total number of population in all nodes. Is there any other ways can help to build the SIR model using SimInf?

how to specify a SEIR model with a seasonal beta (i.e., the infectious rate)

Hi, everyone! I would like to inquire how to specify a SEIR, in which the infectious rate is seasonal, using mparse(). that is,

transitions <- c("S -> betaSI/(S+E+I+R) -> E", "E -> alphaE -> I","I -> gammaI -> R")
compartments <- c("S", "E","I", "R")

I want the "beta" to be four values corresponding to each season within a year. Thanks.

Now, I'm dealing with hand-foot-mouth disease (HFMD) data in one province (which contains 46 counties) in the northwestern China, which has long time series (418 weeks). I also have information about population and annual birth population in each county but have no information about travelings, therefore, it is difficult to specify the "events". A way to get around this problem I think would be assuming a proportion of individuals travelling between counties. However, that would be too many choices (a lot of assumptions) to find the best assumption that fit my data best. My ultimate goal is to explore optimal control through simulation. I would like to know if there is way to resolve my problem. Any comments would be appreciated.

Steven

SimInf Error

Error: "C:/rtools40/mingw64/bin/"gcc -I"C:/R/R/R-411.0/include" -DNDEBUG -I"C:/R/R/R-4.1.0/library/SimInf/include" -DSIMINF_MODEL_RUN=run_249c247652b7 -DSIMINF_R_INIT=R_init_SimInf_249c247652b7 -DSIMINF_FORCE_SYMBOLS=FALSE -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c C:/Users/HP840G1/AppData/Local/Temp/RtmpGi9NPi/SimInf_249c247652b7.c -o C:/Users/HP840G1/AppData/Local/Temp/RtmpGi9NPi/SimInf_249c247652b7.osh: line 6: tmp.def: No such file or directorysh: line 7: tmp.def: No such file or directoryC:/rtools40/mingw64/bin/gcc -shared -s -static-libgcc -o C:/Users/HP840G1/AppData/Local/Temp/RtmpGi9NPi/SimInf_249c247652b7.dll tmp.def C:/Users/HP840G1/AppData/Local/Temp/RtmpGi9NPi/SimInf_249c247652b7.o -LC:/R/R/R-411.0/bin/x64 -lRgcc.exe: error: tmp.def: No such file or directory ###I HAVE FAILED TO GET THIS PACKAGE UP AND RUNNING. THAT IS THE ERROR AM CONTINUOUSLY GETTING

Error with observation process

Hi again!
My group and I are trying to use the pfilter function in a MCMC function, however we get the following error:
Error: The observation process must be a function when data contains multiple rows for a time-point.
We are trying to use our own data in the pfilter is that even possible? We tried to define our own function in several
ways but still, we don't really get it to work. Our code looks like this:

# Load packages ----------------------------------------------------------------

library(SimInf)
library(ggplot2)

# Load data  -------------------------------------------------------------------
time <- c(1, 8, 15, 22, 29, 36, 43, 50, 57, 64, 64, 
          71, 78, 85,92, 99, 106, 113, 120, 127, 134, 
          141, 148, 155, 162, 169, 176, 183, 190, 197,
          204, 218, 225, 232, 239, 246, 253, 260, 267,
          274, 281, 288, 295, 302, 309, 316, 323, 330, 
          337, 344, 351, 358, 365, 372, 379, 386)
I <- c(32, 28, 58, 62, 56, 90, 118, 129, 339, 731, 821,
       837, 1336, 2141, 2671, 2956, 3038, 3018, 3096,
       3264, 2970, 2669, 2622, 1901, 1371, 1254, 1166,
       1332, 1498, 1476, 1587, 1808, 2213, 2853, 3405,
       3783, 3858, 3619, 3057, 2577, 2013, 532, 888,
       554, 316, 240, 131, 62, 63, 70, 83, 91, 127,
       216, 267, 342)
infected <- data.frame(time,I)
colnames(infected) <- c("time", "Iobs")
obs_fn <- Iobs ~ poisson(I + 1e-6)

# Functions --------------------------------------------------------------------


## Single node model
getModel <- function() {
  n <- 1
  transitions <- c("S -> beta*S*I/(S+I) -> I",
                   "I -> gamma*I -> S")
  compartments <- c("S", "I")
  u0 <- data.frame(S = 389880, I = 32)
  tspan <- seq(from = 1, to = 392, by = 7)

  model <- mparse(transitions = transitions,
                  compartments = compartments,
                  gdata = c(beta = 0.7, gamma = 1/15),
                  u0 = u0,
                  tspan = tspan)
  
  ## generate observation
  infected <- trajectory(run(model), "I")[, c("time", "I")]
  colnames(infected) <- c("time", "Iobs")
  
  ## observation process
  obs_process <- Iobs ~ poisson(I + 1e-6)
  
  return(list("model"=model,"obs"=infected,"obs_fn"=obs_process))
}

updateModel <- function(par,betaVec,i) {
  name <- c("beta")
  par[name] <- betaVec[i]
  return(par)
}

mcmc <- function(Nsamples=5,S=0.001, numparticles=10, data=infected) {
  ##'Seed for reproducability
  set.seed(0)
  
  ## model object
  theModel <- getModel()
  model <- theModel$model
  #obs <- theModel$obs
  #obs_fn <- theModel$obs_fn
  
  ## initial parameter guess
  betaModel <- model@gdata
  betaVec <- c(0.5, 0.6, 0.7, 0.8, 0.9)
  likelihood <- c()
  
  ## Estimate likelihood by a particle filter
  filter <- function(model, obs_process=obs_fn, data=infected, npart=numparticles){
    pfilter(model,obs_process,data,npart)
  }
  
  ## initialize the chain
  pf <- filter(model)
  initialLikelihood <- pf@loglik
  
  ##' Main MCMC loop
  print("start loop")
  for (i in 1:length(betaVec)) {
    
    ## update model
    betaModel <- updateModel(betaModel,betaVec,i)
    model@gdata <- betaModel
    
    ## new likelihood
    ## using "try" statement becaus it can fail
    run <- try(
      pf <- filter(model),
      silent=TRUE
    )
    
    ## catching try-error
    if(is(run, "try-error")){
      likelihood <- append(likelihood,-Inf)
    } else {
      likelihood <- append(likelihood,run@loglik)
    }
  }
  data <- data.frame(betaVec,likelihood)
  data[order(data$betaVec),]
  return(data)
}

# Running MCMC -----------------------------------------------------------------

run <- mcmc()
ggplot(run, aes(betaVec,likelihood)) +
  geom_point() +
  geom_line(color='red', aes(betaVec,likelihood)) + 
  xlab("Beta value") + 
  ylab("Likelihood") +
  ggtitle("Likelihood for different Beta values")`

Thank you in advance
Aikaterini

Loading the Confidence Interval for the Result

Hi,

Thank you for your great package! It makes my life easier!

It is me again. I used another laptop to install the package and it turns out to be successful.

I ran a model, which ran successfully.

I would like to draw a graph without drawing the susceptible variable. So I tried ggplot by extracting values from Result.

However, when I tried to view the result. It showed an error.

View(result)
Error in if (more || nchar(output) > 80) { : 
  missing value where TRUE/FALSE needed

Could you please help take a look?

Multithreaded operations

Hi,
I installed SimInf on my server (2 CPUs, 64 Cores, and 128 threads), but only half the threads worked when running the model. And parallel::detectCores() detected 128 cores.
Here is my information:
`R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936 LC_CTYPE=Chinese (Simplified)_China.936
[3] LC_MONETARY=Chinese (Simplified)_China.936 LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.936
system code page: 65001

attached base packages:
[1] stats graphics grDevices utils datasets methods base `

Make it possible to write the pts_fun argument to mparse as a text string with linebreaks

Make it possible to write the C snippet of the pts_fun argument to mparse as a text string with line breaks instead of as a set of lines.

Now you have to write, for example,

pts_fun <- c("v_new[0] = 0.9 * v[0] + u[1];",
             "if (ldata[0] > 0)",
             "    v_new[0] += 0.1 * (v[-1] - v[0]);",
             "if (ldata[1] > 0)",
             "    v_new[0] += 0.1 * (v[1] - v[0]);",
             "return 1;")

Make it possible to instead write

pts_fun <- "
    v_new[0] = 0.9 * v[0] + u[1];
    if (ldata[0] > 0)
        v_new[0] += 0.1 * (v[-1] - v[0]);
    if (ldata[1] > 0)
        v_new[0] += 0.1 * (v[1] - v[0]);
    return 1;
"

'stdlib.h' file not found R

I created a function for a model which includes more compartments than the SEIR model and I get the error that 'stdlib.h' file not found. This happens when I run model in the run() function.

Not Able to Install the Package

Hi,
I am trying install the package.
But there is an error. Could you please take a look at it?

> install.packages("SimInf")
Warning in install.packages :
  unable to access index for repository https://cran.rstudio.com/src/contrib:
  无法打开URL'https://cran.rstudio.com/src/contrib/PACKAGES'
Installing package into ‘C:/Users/Administrator/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
Warning in install.packages :
  unable to access index for repository https://cran.rstudio.com/src/contrib:
  无法打开URL'https://cran.rstudio.com/src/contrib/PACKAGES'
Warning in install.packages :
  package ‘SimInf’ is not available (for R version 4.0.2)
Warning in install.packages :
  unable to access index for repository https://cran.rstudio.com/bin/windows/contrib/4.0:
  无法打开URL'https://cran.rstudio.com/bin/windows/contrib/4.0/PACKAGES'

无法打开 means "unable to open".

Pause and resume run to input new events

Dear authors,

I am looking for a way to pause a model run at a predefined timepoint, extract information to create new events, insert the events, and resume the model run. I hope I haven't missed anything in the documentation. Is this possible? I thought I was on to something with the continue() function, but it seems I was wrong.

Cheers,

Logan

Error on installation

Hi,
My group and I are doing a project on hotspot prediction for Covid-19 and were recommended to use your package by Robin Eriksson. However, when trying to install a specific branch through Rstudio we get an error. When installing the master branch we get no errors, however when trying to install the pmcmc or the particle-filter branches we get the error below.

ERROR: package installation failed Error: Failed to install 'SimInf' from GitHub: System command 'Rcmd.exe' failed, exit status: 1, stdout + stderr (last 10 lines): E> "C:/rtools40/mingw64/bin/"gcc -I"C:/PROGRA~1/R/R-41~1.2/include" -DNDEBUG -I../windows/gsl-2.7/include -I. -I../inst/include -DR_NO_REMAP -DSTRICT_R_HEADERS -fopenmp -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -Wall -pedantic -fdiagnostics-color=always -c models/SISe.c -o models/SISe.o E> C:/rtools40/mingw64/bin/gcc -shared -s -static-libgcc -o SimInf.dll SimInf-win.def init.o SimInf.o solvers/SimInf_solver.o solvers/aem/SimInf_solver_aem.o solvers/ssm/SimInf_solver_ssm.o misc/SimInf_abc.o misc/SimInf_arg.o misc/SimInf_forward_euler_linear_decay.o misc/SimInf_ldata.o misc/SimInf_local_spread.o misc/SimInf_openmp.o misc/SimInf_trajectory.o misc/binheap.o models/SISe3_sp.o models/SISe3.o models/SEIR.o models/SISe_sp.o models/SIR.o models/SISe.o -L../windows/gsl-2.7/lib/x64 -lm -lgsl -lgslcblas -fopenmp -LC:/PROGRA~1/R/R-41~1.2/bin/x6

We are unsure if this is because we are doing something wrong or if this is due to the package being under development. If we are doing something wrong would you be able to help us install either the pmcmc or the particle-filter branch. We are using windows laptops and we have installed rtools correctly (hopefully). We have also ubuntu as windows subsystems.

Thank you in advance
Aikaterini

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.