lapack - How to implement user-defined function from c in stan -
i trying use hmc mcmc sampling self-defined target function. had hmc code, doesn't work well. knew "stan" has more powerful hmc model. want implement code "stan".
i have coded target function derivative function in c. involves for-loop, , functions needed cholesky decomposition , other linear algebras lapack. don't want recode in stan. there way use functions directly? appreciate if can give clues how modify code, or teach me how modify "stan" code. following part of code:
void get_v(double phi, double sigmasq, double k, double *neardist, double *neardistm, int *nearind, double *w, int n, int m, double *v){ double 1 = 1.0, var; int i, j, dim ,info, int_one = 1; double *u, *temp_neardistm; char uplo = 'l'; char side = 'l', diag = 'n'; char trans = 'n', trans2 = 't'; var = (double)(1/k) * sigmasq; v[0] = var; (i = 1; < n ; i++){ if(i < m) { dim = i; } else { dim = m; } ... // cholesky decomposition of temp_neardistm info = -1; dpotrf_(&uplo, &dim, temp_neardistm, &dim, &info); if (info != 0) {free(temp_neardistm); return ;} ... // vi dtrsm_(&side, &uplo, &trans, &diag, &dim, &int_one, &one, temp_neardistm, &dim, u, &dim); v[i] = (var - sigmasq * (sq_sum(u, dim)) ); ... } }
Comments
Post a Comment