Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2024-08-07 update : adding matrix normalization func. and using AR1 in spatial func. #53

20 changes: 7 additions & 13 deletions inst/stan/functions/construct_aux_rt.stan
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@ vector construct_aux_rt(vector log_state_rt,

// presets
int n_time = dims(state_deviation_noise_vec)[1];
vector[n_time] log_aux_site_rt;
real state_deviation_t_i = 0;
// To explain state_deviation_t_i = 0 initialization,
// we need a state_deviation_t_i value for t_1 = 1, so we will
// initialize the process with index 1 of spatial
// deviation noise matrix w/out spatial_deviation ar coeff, so we set
// state_deviation_t_i to 0 initially.

for (t_i in 1:n_time) {
state_deviation_t_i = state_deviation_ar_coeff * state_deviation_t_i +
state_deviation_noise_vec[t_i];
log_aux_site_rt[t_i] = log_state_rt[t_i] + state_deviation_t_i;
}
vector[n_time] log_aux_site_rt = ar1(
log_state_rt,
state_deviation_ar_coeff,
1,
cbernalz marked this conversation as resolved.
Show resolved Hide resolved
state_deviation_noise_vec,
0
cbernalz marked this conversation as resolved.
Show resolved Hide resolved
cbernalz marked this conversation as resolved.
Show resolved Hide resolved
);

return log_aux_site_rt;
}
11 changes: 11 additions & 0 deletions inst/stan/functions/matrix_normalization.stan
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Normalizes a matrix using its determinant to the power of 1 / n.
* @param matrx A matrix, usually the correlation matrix need to normalize
* @return A matrix that has been normalized.
*
*/
matrix matrix_normalization(matrix matrx) {
int n = cols(matrx);
matrix[n,n] norm_matrx = matrx / pow(determinant(matrx), 1.0 / n);
return norm_matrx;
}
2 changes: 2 additions & 0 deletions inst/stan/functions/spatial_functions.stan
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* File to call all desired spatial functions for use with expose_functions()
*/
functions{
#include ar1.stan
#include exponential_decay_corr_func.stan
#include independence_corr_func.stan
#include construct_spatial_rt.stan
Expand All @@ -10,4 +11,5 @@ functions{
#include construct_aux_rt.stan
#include state_deviation_noise_vec_aux_rng.stan
#include aux_site_process_rng.stan
#include matrix_normalization.stan
}
Loading
Loading