traitecoevo / hmde

Implementation of hierarchical Bayesian longitudinal models to estimate differential equation parameters.
Other
2 stars 3 forks source link

Parameter names not updating with stan file. #31

Closed Tess-LaCoil closed 1 month ago

Tess-LaCoil commented 1 month ago

On branch function-update I've changed the names of population-level parameters to pop_theta_mu and pop_theta_sigma to generalise away from the species terminology. Despite re-loading and re-compiling the stan files, when the samples are extracted I am getting the old parameter names anyway.

This happens on both Ubuntu and Windows

multi_ind_trout <- hmde_model("constant_multi_ind") |>
  hmde_assign_data(n_obs = nrow(Trout_Size_Data),         #integer
                   n_ind = length(unique(Trout_Size_Data$ind_id)),               #integer
                   y_obs = Trout_Size_Data$y_obs,         #vector length N_obs
                   obs_index = Trout_Size_Data$obs_index, #vector length N_obs
                   time = Trout_Size_Data$time,           #Vector length N_obs
                   ind_id = Trout_Size_Data$ind_id,       #Vector length N_obs
                   y_0_obs = Trout_Size_Data$y_obs[which(Trout_Size_Data$obs_index == 1)]           #vector length N_ind
  ) |>
  hmde_run(chains = 2, iter = 100, cores = 1,
           verbose = FALSE, show_messages = FALSE)

samples <- rstan::extract(multi_ind_trout, permuted = TRUE, inc_warmup = FALSE)
names(samples)

> [1] "ind_y_0"            "ind_beta"           "species_beta_mu"    "species_beta_sigma"
[5] "global_error_sigma" "y_hat"              "Delta_hat"          "lp__"  
//From constant_multi_ind.stan
parameters {
  //Individual level
  real<lower=0> ind_y_0[n_ind];
  real<lower=0> ind_beta[n_ind];

  real pop_beta_mu;
  real<lower=0> pop_beta_sigma;

  //Global level
  real<lower=0> global_error_sigma;
}
dfalster commented 1 month ago

This is working fine for me.

> samples <- rstan::extract(multi_ind_trout, permuted = TRUE, inc_warmup = FALSE)
+ names(samples)
[1] "ind_y_0"            "ind_beta"           "pop_beta_mu"        "pop_beta_sigma"    
[5] "global_error_sigma" "y_hat"              "Delta_hat"          "lp__"              
>

As noted in #30, I think you need to remove old installation and reinstall. Somehow you're loading an old installation

Tess-LaCoil commented 1 month ago

Re-installing from remote did not update the names so I have created a separate branch and pull request for it.

Tess-LaCoil commented 1 month ago

Forced re-install from remote with the updated names worked.