Closed mhunter1 closed 8 years ago
Original comment by Sy-Miin Chow (Bitbucket: symiin, GitHub: symiin).
It would be relatively easy for me to work on this. Can you please prioritize implementing the printex method for the prep.formulaDynamics recipe object? You are more familiar with the formulaDynamics object. For me to modify the plot function to show the equation with the estimated parameter values I need to use some of the code in the printex method for this recipe object.
Original comment by Sy-Miin Chow (Bitbucket: symiin, GitHub: symiin).
Wrote an R script for generating data from a RS predator-prey model (SimulateRS-PP.R) Started a recipe script in RS-PPmodel.R But dynr.cook gives me this weird error in compiling the Jacobian C code complaining an xstart. Not sure where that came from. Does anyone have any insights? If not, I will just look more closely later to see whether I made an error elsewhere.
formula=list( list(prey~ r1prey - a12preypredator - a11prey^2, predator~ -r2predator + a21preypredator - a22predator^2), list(prey~ r1prey - a12preypredator, predator~ -r2predator + a21preypredator))
dynm<-prep.formulaDynamics(formula=formula, startval=c(r1=3, r2=2, a12 = 1, a21 = 1, a11 =.5, a22 = .5), isContinuousTime=TRUE) #,jacobian=jacob
ERROR(s) during compilation: source code errors or compiler configuration errors!
Program source:
1: #include
cat(writeCcode(model$dynamics)$c.string) void function_dx_dt(double t, size_t regime, const gsl_vector x, double param, size_t n_param, const gsl_vector co_variate, gsl_vector F_dx_dt){ switch (regime) { case 0: gsl_vector_set(F_dx_dt,0,param[0] gsl_vector_get(x,0) - param[2] gsl_vector_get(x,0) gsl_vector_get(x,1) - param[4] pow(gsl_vector_get(x,0), 2)); gsl_vector_set(F_dx_dt,1,-param[1] gsl_vector_get(x,1) + param[3] gsl_vector_get(x,0) gsl_vector_get(x,1) - param[5] pow(gsl_vector_get(x,1), 2)); break;
case 1:
gsl_vector_set(F_dx_dt,0,param[0] * gsl_vector_get(x,0) - param[2] * gsl_vector_get(x,0) * gsl_vector_get(x,1));
gsl_vector_set(F_dx_dt,1,-param[1] * gsl_vector_get(x,1) + param[3] * gsl_vector_get(x,0) * gsl_vector_get(x,1));
break;
}
}
void function_dF_dx(double t, size_t regime, double param, const gsl_vector co_variate, gsl_matrix F_dx_dt_dx){ switch (regime) { case 0: gsl_matrix_set(F_dx_dt_dx,0,0,param[0] - param[2] gsl_vector_get(xstart,1) - param[4] (2 gsl_vector_get(xstart,0))); gsl_matrix_set(F_dx_dt_dx,0,1,-(param[2] gsl_vector_get(xstart,0))); gsl_matrix_set(F_dx_dt_dx,1,0,param[3] gsl_vector_get(xstart,1)); gsl_matrix_set(F_dx_dt_dx,1,1,param[3] gsl_vector_get(xstart,0) - param[1] - param[5] (2 * gsl_vector_get(xstart,1))); break;
case 1:
gsl_matrix_set(F_dx_dt_dx,0,0,param[0] - param[2] * gsl_vector_get(xstart,1));
gsl_matrix_set(F_dx_dt_dx,0,1,-(param[2] * gsl_vector_get(xstart,0)));
gsl_matrix_set(F_dx_dt_dx,1,0,param[3] * gsl_vector_get(xstart,1));
gsl_matrix_set(F_dx_dt_dx,1,1,param[3] * gsl_vector_get(xstart,0) - param[1]);
break;
}
}
Original comment by Sy-Miin Chow (Bitbucket: symiin, GitHub: symiin).
I was running the single-regime predator-prey model but found another potential bug. Seems like there is an error in the generated dx_dt code, which refers to x_tend and xstart but they are undeclared. The recipe for fitting this single-regime model is in PPmodel.R in the demo folder in Symiin_Lu/dynr. Script for generating the data is called SimulatePP.R in the same folder. Lu, please take a look and see what is going on.
cat(writeCcode(model$dynamics)$c.string) void function_dx_dt(double t, size_t regime, const gsl_vector x, double param, size_t n_param, const gsl_vector co_variate, gsl_vector F_dx_dt){ gsl_vector_set(x_tend,0,param[0] gsl_vector_get(xstart,0) - param[2] gsl_vector_get(xstart,0) gsl_vector_get(xstart,1)); gsl_vector_set(x_tend,1,-param[1] gsl_vector_get(xstart,1) + param[3] gsl_vector_get(xstart,0) gsl_vector_get(xstart,1)); }
/**
res <- dynr.cook(model, data=data,debug_flag=FALSE) Setting PKG_CPPFLAGS to -I/opt/local/include Setting PKG_LIBS to -L/opt/local/lib -lgsl -lgslcblas Compilation argument: /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB PPmodelRecipe.c.c 2> PPmodelRecipe.c.c.err.txt llvm-gcc-4.2 -arch x86_64 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/opt/local/include -I/usr/local/include -fPIC -mtune=core2 -g -O2 -c PPmodelRecipe.c.c -o PPmodelRecipe.c.o PPmodelRecipe.c.c: In function ‘function_dx_dt’: PPmodelRecipe.c.c:42: error: ‘x_tend’ undeclared (first use in this function) PPmodelRecipe.c.c:42: error: (Each undeclared identifier is reported only once PPmodelRecipe.c.c:42: error: for each function it appears in.) PPmodelRecipe.c.c:42: error: ‘xstart’ undeclared (first use in this function) PPmodelRecipe.c.c: In function ‘function_dF_dx’: PPmodelRecipe.c.c:51: error: ‘Jx’ undeclared (first use in this function) PPmodelRecipe.c.c:51: error: expected ‘]’ before ‘)’ token PPmodelRecipe.c.c:51: error: expected ‘;’ before ‘)’ token PPmodelRecipe.c.c:51: error: expected statement before ‘)’ token PPmodelRecipe.c.c:52: error: expected ‘]’ before ‘)’ token PPmodelRecipe.c.c:52: error: expected ‘;’ before ‘)’ token PPmodelRecipe.c.c:52: error: expected statement before ‘)’ token PPmodelRecipe.c.c:53: error: expected ‘]’ before ‘)’ token PPmodelRecipe.c.c:53: error: expected ‘;’ before ‘)’ token PPmodelRecipe.c.c:53: error: expected statement before ‘)’ token PPmodelRecipe.c.c:54: error: expected ‘]’ before ‘)’ token PPmodelRecipe.c.c:54: error: void value not ignored as it ought to be PPmodelRecipe.c.c:54: error: expected ‘;’ before ‘)’ token PPmodelRecipe.c.c:54: error: expected statement before ‘)’ token make: *** [PPmodelRecipe.c.o] Error 1
ERROR(s) during compilation: source code errors or compiler configuration errors!
Program source:
1: #include
Original report by Lu Ou (Bitbucket: luou, GitHub: luou).