Step 2: Integrate Sylvester equation solver within the rprocess
\nFor this I consider the following toy example
library(pomp)\nlibrary(magrittr)\nlibrary(maotai)\n\nreadLines(\"sylvester.h\") |> paste(collapse=\"\\n\") -> global.h\nreadLines(\"sylvester.c\") -> global.c\nglobal.c[grepl(\"include \\\"my_sylvester.h\\\"\",global.c)] <- global.h\nextract(global.c,!grepl(\"include \\\"sylvester.h\\\"\",global.c)) |>\n paste(collapse=\"\\n\") -> global.c\n\nricker() |>\n simulate(rmeasure=Csnippet(\"\n int n = 2, m=2;\n double A[4] = {1.0, 3.0, 2.0, 4.0};\n double B[4] = {1.0, 0.0, 0.0, 1.0};\n double C[4] = {5.0, 7.0, 6.0, 8.0};\n double X[3][3];\n solve_sylvester(A, B, C, &m, &n);\n y = rnorm(N+C[0],1);\n y = (y > 0) ? y : 0;\"),\n dmeasure=Csnippet(\"\n lik = dnorm(y,N,1,0);\n if (give_log) lik = log(lik);\"),\n statenames=\"N\",\n globals=global.c\n) -> rick4\n\nrick4 |>\n pfilter(Np=10000) |>\n logLik() |>\n replicate(n=10) |>\n logmeanexp(se=TRUE)\n
I have not been able to make this toy example to work. I am getting the following error:
\nError: in ‘simulate’: unable to load shared object '/tmp/RtmpMQc4ey/833422/pomp_753876c7d31d99a58252ecbdc9d0ea9d.so':\n /tmp/RtmpMQc4ey/833422/pomp_753876c7d31d99a58252ecbdc9d0ea9d.so: undefined symbol: dtrsyl_\n
Is this error indicating the compilation was not successful? How to link the lapack library during compilation? In step 1 I use system(\"R CMD SHLIB lapack_test.c -llapack\")
.
On the one hand, @etsagued, the answer to your question is relatively straightforward. Have a look at FAQ 3.7, which gives instructions on linking C snippets with external libraries.
\nOn the other hand, I wonder whether for such a model it is necessary to use simulation-based methods. Given the linear structure of the problem, more efficient approaches are available, no?
","upvoteCount":1,"url":"https://github.com/kingaa/pomp/discussions/211#discussioncomment-9066978"}}}-
I am new to the pomp package and would like to use it to estimate a nonlinear state-space model where the state-space form is a solution to a Sylvester equation of the form AX + XB = C. The main difficulty so far has been to speed up the code by using the C snippets. It is not entirely obvious to me on how to solve the Sylvester equation within the C snippets. I have proceeded in two steps. Step 1: Call a lapack routine and use it R
Step 2: Integrate Sylvester equation solver within the rprocess
I have not been able to make this toy example to work. I am getting the following error:
Is this error indicating the compilation was not successful? How to link the lapack library during compilation? In step 1 I use |
Beta Was this translation helpful? Give feedback.
-
On the one hand, @etsagued, the answer to your question is relatively straightforward. Have a look at FAQ 3.7, which gives instructions on linking C snippets with external libraries. On the other hand, I wonder whether for such a model it is necessary to use simulation-based methods. Given the linear structure of the problem, more efficient approaches are available, no? |
Beta Was this translation helpful? Give feedback.
-
Thank you very much your promptitude! I actually use the FAQ 3.7 to create the toy example above. I will reread it again and try to make it work. Sorry I was not clear in my previous exposition. My model have a linear and nonlinear part. The linear part is a solution to a Sylvester equation which is then combined in a nonlinear with nonadditive shocks to create the full model. That is why, I thought I could use the MIF algorithm. Thanks! |
Beta Was this translation helpful? Give feedback.
-
I finally made to work. As explained in the example FAQ 3.7, I create a directory "include" that contains "sylvester.h" and another one "libs" with "sylvester.so" in it and everything worked beautifully. Thank you again for your help! |
Beta Was this translation helpful? Give feedback.
-
Sure thing! I look forward to hearing about your results! |
Beta Was this translation helpful? Give feedback.
On the one hand, @etsagued, the answer to your question is relatively straightforward. Have a look at FAQ 3.7, which gives instructions on linking C snippets with external libraries.
On the other hand, I wonder whether for such a model it is necessary to use simulation-based methods. Given the linear structure of the problem, more efficient approaches are available, no?