Summary:
Cannot compile dynr.cook in package dynr.
Description:
I tried the dynr::LinearSDE of dynr demo: (dynr::LinearSDE)dynr::LinearSDE
Reproducible Steps:
res <- dynr.cook(model, verbose = FALSE)
Current Output:
May I present to you your error messages?
ld: warning: -undefined dynamic_lookup may not work with chained fixups
ERROR(s) during compilation: source code errors or compiler configuration errors!
Program source:
1: #include <math.h>
2: #include <gsl/gsl_matrix.h>
3: #include <gsl/gsl_blas.h>
4:
5:
6: /**
7: * This function takes a double and gives back a double
8: * It computes the logistic function (i.e. the inverse of the logit link function)
9: * @param x, the double value e.g. a normally distributed number
10: * @return logistic(x), the double value e.g. a number between 0 and 1
11: /
12: double mathfunction_logistic(const double x){
13: double value = 1.0/(1.0 + exp(-x));
14: return value;
15: }
16:
17: /*
18: * This function takes a gsl_vector and modifies its second argument (another gsl_vector)
19: * It computes the softmax function (e.g. for multinomial logistic regression)
20: * @param x, vector of double values e.g. a vector of normally distributed numbers
21: * @param result, softmax(x), e.g. a vector of numbers between 0 and 1 that sum to 1
22: */
23: void mathfunction_softmax(const gsl_vector *x, gsl_vector result){
24: / Elementwise exponentiation /
25: size_t index=0;
26: for(index=0; index < x->size; index++){
27: gsl_vector_set(result, index, exp(gsl_vector_get(x, index)));
28: }
29:
30: / Sum for the scaling coeficient /
31: double scale = 0.0;
32: for(index=0; index < x->size; index++){
33: scale += gsl_vector_get(result, index);
34: }
35:
36: / Multiply all elements of result by 1/scale */
37: gsl_blas_dscal(1/scale, result);
38: }
39:
40:
41: 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){
42: gsl_matrix *Amatrix = gsl_matrix_calloc(2, 2);
43:
44: gsl_matrix_set(Amatrix, 1, 0, param[0]);
45: gsl_matrix_set(Amatrix, 0, 1, 1);
46: gsl_matrix_set(Amatrix, 1, 1, param[1]);
47:
48: gsl_blas_dgemv(CblasNoTrans, 1.0, Amatrix, x, 0.0, F_dx_dt);
49:
50: gsl_matrix_free(Amatrix);
51:
52: }
53:
54:
55: void function_dF_dx(double t, size_t regime, double *param, const gsl_vector *co_variate, gsl_matrix *F_dx_dt_dx){
56: gsl_matrix_set(F_dx_dt_dx, 1, 0, param[0]);
57: gsl_matrix_set(F_dx_dt_dx, 0, 1, 1);
58: gsl_matrix_set(F_dx_dt_dx, 1, 1, param[1]);
59:
60: }
61:
62:
63:
64: void function_measurement(size_t t, size_t regime, double *param, const gsl_vector *eta, const gsl_vector *co_variate, gsl_matrix *Ht, gsl_vector *y){
65:
66:
67: gsl_matrix_set(Ht, 0, 0, 1);
68:
69: gsl_blas_dgemv(CblasNoTrans, 1.0, Ht, eta, 0.0, y);
70:
71: }
72:
73:
74:
75: void function_noise_cov(size_t t, size_t regime, double *param, gsl_matrix *y_noise_cov, gsl_matrix *eta_noise_cov){
76:
77:
78: gsl_matrix_set(eta_noise_cov, 0, 0, -13.8155105579643);
79: gsl_matrix_set(eta_noise_cov, 1, 1, param[2]);
80:
81: gsl_matrix_set(y_noise_cov, 0, 0, param[3]);
82:
83: }
84:
85:
86:
87: void function_initial_condition(double *param, gsl_vector **co_variate, gsl_vector **pr_0, gsl_vector **eta_0, gsl_matrix **error_cov_0, size_t *index_sbj){
88:
89: gsl_vector *Pvector = gsl_vector_calloc(1);
90: gsl_vector Pintercept = gsl_vector_calloc(1);
91: gsl_vector Padd = gsl_vector_calloc(1);
92: gsl_vector Preset = gsl_vector_calloc(1);
93: gsl_vector_set(Pvector, 0, 1);
94: gsl_vector_add(Padd, Pvector);
95: gsl_vector_add(Padd, Pintercept);
96: gsl_vector_add(Preset, Pvector);
97: gsl_vector_add(Preset, Pintercept);
98: gsl_vector eta_local = gsl_vector_calloc(2);
99: size_t num_regime=pr_0[0]->size;
100: size_t dim_latent_var=error_cov_0[0]->size1;
101: size_t num_sbj=(eta_0[0]->size)/(dim_latent_var);
102: size_t i;
103: size_t regime;
104: for(regime=0; regime < num_regime; regime++){
105: for(i=0; i < num_sbj; i++){
106: gsl_vector_set(eta_local, 0, param[4]);
107: gsl_vector_set(eta_local, 1, 1);
108: gsl_vector_set(eta_0[regime], idim_latent_var+0, gsl_vector_get(eta_local, 0));
109: gsl_vector_set(eta_0[regime], idim_latent_var+1, gsl_vector_get(eta_local, 1));
110: gsl_vector_set_zero(eta_local);
111: }
112: }
113: for(i=0; i < num_sbj; i++){
114: mathfunction_softmax(Padd, pr_0[i]);
115: }
116: gsl_vector_free(Pvector);
117: gsl_vector_free(Pintercept);
118: gsl_vector_free(Padd);
119: gsl_vector_free(Preset);
120: gsl_vector_free(eta_local);
121: }
122:
123:
124: /
125: * This function modifies some of the parameters so that it satisfies the model constraint.
126: * Do not include parameters in noise_cov matrices
127: */
128: void function_transform(double *param){
129: }
130:
131:
132:
133: void function_regime_switch(size_t t, size_t type, double *param, const gsl_vector co_variate, gsl_matrix regime_switch_mat){
134: gsl_matrix_set_identity(regime_switch_mat);
135: }
136:
137:
138:
139: /
140: * The dP/dt function: depend on function_dF_dx, needs to be compiled on the user end
141: * but user does not need to modify it or care about it.
142: */
143: void mathfunction_mat_to_vec(const gsl_matrix *mat, gsl_vector *vec){
144: size_t i,j;
145: size_t nx=mat->size1;
146: /convert matrix to vector/
147: for(i=0; i<nx; i++){
148: gsl_vector_set(vec,i,gsl_matrix_get(mat,i,i));
149: for (j=i+1;j<nx;j++){
150: gsl_vector_set(vec,i+j+nx-1,gsl_matrix_get(mat,i,j));
151: /printf("%lu",i+j+nx-1);}/
152: }
153: }
154: }
155: void mathfunction_vec_to_mat(const gsl_vector *vec, gsl_matrix *mat){
156: size_t i,j;
157: size_t nx=mat->size1;
158: /convert vector to matrix/
159: for(i=0; i<nx; i++){
160: gsl_matrix_set(mat,i,i,gsl_vector_get(vec,i));
161: for (j=i+1;j<nx;j++){
162: gsl_matrix_set(mat,i,j,gsl_vector_get(vec,i+j+nx-1));
163: gsl_matrix_set(mat,j,i,gsl_vector_get(vec,i+j+nx-1));
164: }
165: }
166: }
167: void function_dP_dt(double t, size_t regime, const gsl_vector *p, double *param, size_t n_param, const gsl_vector *co_variate, gsl_vector F_dP_dt){
168:
169: size_t nx;
170: nx = (size_t) floor(sqrt(2(double) p->size));
171: gsl_matrix *P_mat=gsl_matrix_calloc(nx,nx);
172: mathfunction_vec_to_mat(p,P_mat);
173: gsl_matrix *F_dx_dt_dx=gsl_matrix_calloc(nx,nx);
174: function_dF_dx(t, regime, param, co_variate, F_dx_dt_dx);
175: gsl_matrix *dFP=gsl_matrix_calloc(nx,nx);
176: gsl_matrix *dP_dt=gsl_matrix_calloc(nx,nx);
177: gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, F_dx_dt_dx, P_mat, 0.0, dFP);
178: gsl_matrix_transpose_memcpy(dP_dt, dFP);
179: gsl_matrix_add(dP_dt, dFP);
180: size_t n_Q_vec=(1+nx)*nx/2;
181: gsl_vector *Q_vec=gsl_vector_calloc(n_Q_vec);
182: size_t i;
183: for(i=1;i<=n_Q_vec;i++){
184: gsl_vector_set(Q_vec,n_Q_vec-i,param[n_param-i]);
185: }
186: gsl_matrix *Q_mat=gsl_matrix_calloc(nx,nx);
187: mathfunction_vec_to_mat(Q_vec,Q_mat);
188: gsl_matrix_add(dP_dt, Q_mat);
189: mathfunction_mat_to_vec(dP_dt, F_dP_dt);
190: gsl_matrix_free(P_mat);
191: gsl_matrix_free(F_dx_dt_dx);
192: gsl_matrix_free(dFP);
193: gsl_matrix_free(dP_dt);
194: gsl_vector_free(Q_vec);
195: gsl_matrix_free(Q_mat);
196: }
Error in CompileCode(code, language, verbose, libLFile): Compilation ERROR, function(s)/method(s) not created!
Expected Output:
If applicable, the output you expected from dynr.
dynr Version: 0.1.16-91
R Version:
4.2.2
Operating System:
macOS Monterey 12.6 (Apple M1 Pro)
Summary:
Cannot compile dynr.cook in package dynr.
Description:
I tried the dynr::LinearSDE of dynr demo: (dynr::LinearSDE)dynr::LinearSDE
Reproducible Steps:
res <- dynr.cook(model, verbose = FALSE)
Current Output:
May I present to you your error messages?
ld: warning: -undefined dynamic_lookup may not work with chained fixups
ERROR(s) during compilation: source code errors or compiler configuration errors!
Program source:
1: #include <math.h>
2: #include <gsl/gsl_matrix.h>
3: #include <gsl/gsl_blas.h>
4:
5:
6: /**
7: * This function takes a double and gives back a double
8: * It computes the logistic function (i.e. the inverse of the logit link function)
9: * @param x, the double value e.g. a normally distributed number
10: * @return logistic(x), the double value e.g. a number between 0 and 1
11: /
12: double mathfunction_logistic(const double x){
13: double value = 1.0/(1.0 + exp(-x));
14: return value;
15: }
16:
17: /*
18: * This function takes a gsl_vector and modifies its second argument (another gsl_vector)
19: * It computes the softmax function (e.g. for multinomial logistic regression)
20: * @param x, vector of double values e.g. a vector of normally distributed numbers
21: * @param result, softmax(x), e.g. a vector of numbers between 0 and 1 that sum to 1
22: */
23: void mathfunction_softmax(const gsl_vector *x, gsl_vector result){
24: / Elementwise exponentiation /
25: size_t index=0;
26: for(index=0; index < x->size; index++){
27: gsl_vector_set(result, index, exp(gsl_vector_get(x, index)));
28: }
29:
30: / Sum for the scaling coeficient /
31: double scale = 0.0;
32: for(index=0; index < x->size; index++){
33: scale += gsl_vector_get(result, index);
34: }
35:
36: / Multiply all elements of result by 1/scale */
37: gsl_blas_dscal(1/scale, result);
38: }
39:
40:
41: 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){
42: gsl_matrix *Amatrix = gsl_matrix_calloc(2, 2);
43:
44: gsl_matrix_set(Amatrix, 1, 0, param[0]);
45: gsl_matrix_set(Amatrix, 0, 1, 1);
46: gsl_matrix_set(Amatrix, 1, 1, param[1]);
47:
48: gsl_blas_dgemv(CblasNoTrans, 1.0, Amatrix, x, 0.0, F_dx_dt);
49:
50: gsl_matrix_free(Amatrix);
51:
52: }
53:
54:
55: void function_dF_dx(double t, size_t regime, double *param, const gsl_vector *co_variate, gsl_matrix *F_dx_dt_dx){
56: gsl_matrix_set(F_dx_dt_dx, 1, 0, param[0]);
57: gsl_matrix_set(F_dx_dt_dx, 0, 1, 1);
58: gsl_matrix_set(F_dx_dt_dx, 1, 1, param[1]);
59:
60: }
61:
62:
63:
64: void function_measurement(size_t t, size_t regime, double *param, const gsl_vector *eta, const gsl_vector *co_variate, gsl_matrix *Ht, gsl_vector *y){
65:
66:
67: gsl_matrix_set(Ht, 0, 0, 1);
68:
69: gsl_blas_dgemv(CblasNoTrans, 1.0, Ht, eta, 0.0, y);
70:
71: }
72:
73:
74:
75: void function_noise_cov(size_t t, size_t regime, double *param, gsl_matrix *y_noise_cov, gsl_matrix *eta_noise_cov){
76:
77:
78: gsl_matrix_set(eta_noise_cov, 0, 0, -13.8155105579643);
79: gsl_matrix_set(eta_noise_cov, 1, 1, param[2]);
80:
81: gsl_matrix_set(y_noise_cov, 0, 0, param[3]);
82:
83: }
84:
85:
86:
87: void function_initial_condition(double *param, gsl_vector **co_variate, gsl_vector **pr_0, gsl_vector **eta_0, gsl_matrix **error_cov_0, size_t *index_sbj){
88:
89: gsl_vector *Pvector = gsl_vector_calloc(1);
90: gsl_vector Pintercept = gsl_vector_calloc(1);
91: gsl_vector Padd = gsl_vector_calloc(1);
92: gsl_vector Preset = gsl_vector_calloc(1);
93: gsl_vector_set(Pvector, 0, 1);
94: gsl_vector_add(Padd, Pvector);
95: gsl_vector_add(Padd, Pintercept);
96: gsl_vector_add(Preset, Pvector);
97: gsl_vector_add(Preset, Pintercept);
98: gsl_vector eta_local = gsl_vector_calloc(2);
99: size_t num_regime=pr_0[0]->size;
100: size_t dim_latent_var=error_cov_0[0]->size1;
101: size_t num_sbj=(eta_0[0]->size)/(dim_latent_var);
102: size_t i;
103: size_t regime;
104: for(regime=0; regime < num_regime; regime++){
105: for(i=0; i < num_sbj; i++){
106: gsl_vector_set(eta_local, 0, param[4]);
107: gsl_vector_set(eta_local, 1, 1);
108: gsl_vector_set(eta_0[regime], idim_latent_var+0, gsl_vector_get(eta_local, 0));
109: gsl_vector_set(eta_0[regime], idim_latent_var+1, gsl_vector_get(eta_local, 1));
110: gsl_vector_set_zero(eta_local);
111: }
112: }
113: for(i=0; i < num_sbj; i++){
114: mathfunction_softmax(Padd, pr_0[i]);
115: }
116: gsl_vector_free(Pvector);
117: gsl_vector_free(Pintercept);
118: gsl_vector_free(Padd);
119: gsl_vector_free(Preset);
120: gsl_vector_free(eta_local);
121: }
122:
123:
124: /
125: * This function modifies some of the parameters so that it satisfies the model constraint.
126: * Do not include parameters in noise_cov matrices
127: */
128: void function_transform(double *param){
129: }
130:
131:
132:
133: void function_regime_switch(size_t t, size_t type, double *param, const gsl_vector co_variate, gsl_matrix regime_switch_mat){
134: gsl_matrix_set_identity(regime_switch_mat);
135: }
136:
137:
138:
139: /
140: * The dP/dt function: depend on function_dF_dx, needs to be compiled on the user end
141: * but user does not need to modify it or care about it.
142: */
143: void mathfunction_mat_to_vec(const gsl_matrix *mat, gsl_vector *vec){
144: size_t i,j;
145: size_t nx=mat->size1;
146: /convert matrix to vector/
147: for(i=0; i<nx; i++){
148: gsl_vector_set(vec,i,gsl_matrix_get(mat,i,i));
149: for (j=i+1;j<nx;j++){
150: gsl_vector_set(vec,i+j+nx-1,gsl_matrix_get(mat,i,j));
151: /printf("%lu",i+j+nx-1);}/
152: }
153: }
154: }
155: void mathfunction_vec_to_mat(const gsl_vector *vec, gsl_matrix *mat){
156: size_t i,j;
157: size_t nx=mat->size1;
158: /convert vector to matrix/
159: for(i=0; i<nx; i++){
160: gsl_matrix_set(mat,i,i,gsl_vector_get(vec,i));
161: for (j=i+1;j<nx;j++){
162: gsl_matrix_set(mat,i,j,gsl_vector_get(vec,i+j+nx-1));
163: gsl_matrix_set(mat,j,i,gsl_vector_get(vec,i+j+nx-1));
164: }
165: }
166: }
167: void function_dP_dt(double t, size_t regime, const gsl_vector *p, double *param, size_t n_param, const gsl_vector *co_variate, gsl_vector F_dP_dt){
168:
169: size_t nx;
170: nx = (size_t) floor(sqrt(2(double) p->size));
171: gsl_matrix *P_mat=gsl_matrix_calloc(nx,nx);
172: mathfunction_vec_to_mat(p,P_mat);
173: gsl_matrix *F_dx_dt_dx=gsl_matrix_calloc(nx,nx);
174: function_dF_dx(t, regime, param, co_variate, F_dx_dt_dx);
175: gsl_matrix *dFP=gsl_matrix_calloc(nx,nx);
176: gsl_matrix *dP_dt=gsl_matrix_calloc(nx,nx);
177: gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, F_dx_dt_dx, P_mat, 0.0, dFP);
178: gsl_matrix_transpose_memcpy(dP_dt, dFP);
179: gsl_matrix_add(dP_dt, dFP);
180: size_t n_Q_vec=(1+nx)*nx/2;
181: gsl_vector *Q_vec=gsl_vector_calloc(n_Q_vec);
182: size_t i;
183: for(i=1;i<=n_Q_vec;i++){
184: gsl_vector_set(Q_vec,n_Q_vec-i,param[n_param-i]);
185: }
186: gsl_matrix *Q_mat=gsl_matrix_calloc(nx,nx);
187: mathfunction_vec_to_mat(Q_vec,Q_mat);
188: gsl_matrix_add(dP_dt, Q_mat);
189: mathfunction_mat_to_vec(dP_dt, F_dP_dt);
190: gsl_matrix_free(P_mat);
191: gsl_matrix_free(F_dx_dt_dx);
192: gsl_matrix_free(dFP);
193: gsl_matrix_free(dP_dt);
194: gsl_vector_free(Q_vec);
195: gsl_matrix_free(Q_mat);
196: }
Error in CompileCode(code, language, verbose, libLFile): Compilation ERROR, function(s)/method(s) not created!
Expected Output:
If applicable, the output you expected from dynr.
dynr Version: 0.1.16-91
R Version:
4.2.2
Operating System:
macOS Monterey 12.6 (Apple M1 Pro)