From bc34b2304a4772c559df567f90e5bff33d68867c Mon Sep 17 00:00:00 2001 From: timjzee Date: Tue, 19 Mar 2024 17:40:09 +0100 Subject: [PATCH 1/7] Update ulam-function.R --- R/ulam-function.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/ulam-function.R b/R/ulam-function.R index f743892..0bf5cc0 100644 --- a/R/ulam-function.R +++ b/R/ulam-function.R @@ -1440,7 +1440,7 @@ ulam <- function( flist , data , pars , pars_omit , start , chains=1 , cores=1 , if ( rstanout==TRUE ) stanfit <- rstan::read_stan_csv(cmdstanfit$output_files()) else - stanfit <- cmdstanfit + stanfit <- read_cmdstan_csv(cmdstanfit$output_files()) } } else { if ( cmdstan==FALSE ) { @@ -1471,7 +1471,7 @@ ulam <- function( flist , data , pars , pars_omit , start , chains=1 , cores=1 , if ( rstanout==TRUE ) stanfit <- rstan::read_stan_csv(cmdstanfit$output_files()) else - stanfit <- cmdstanfit + stanfit <- read_cmdstan_csv(cmdstanfit$output_files()) } } } else { From 7cd5ba03a2855a194ba0342178a29f2cf0fd9f5c Mon Sep 17 00:00:00 2001 From: timjzee Date: Tue, 19 Mar 2024 18:10:26 +0100 Subject: [PATCH 2/7] Update ulam-function.R --- R/ulam-function.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/ulam-function.R b/R/ulam-function.R index 0bf5cc0..6440032 100644 --- a/R/ulam-function.R +++ b/R/ulam-function.R @@ -1440,7 +1440,7 @@ ulam <- function( flist , data , pars , pars_omit , start , chains=1 , cores=1 , if ( rstanout==TRUE ) stanfit <- rstan::read_stan_csv(cmdstanfit$output_files()) else - stanfit <- read_cmdstan_csv(cmdstanfit$output_files()) + stanfit <- as_cmdstan_fit(cmdstanfit$output_files()) } } else { if ( cmdstan==FALSE ) { @@ -1471,7 +1471,7 @@ ulam <- function( flist , data , pars , pars_omit , start , chains=1 , cores=1 , if ( rstanout==TRUE ) stanfit <- rstan::read_stan_csv(cmdstanfit$output_files()) else - stanfit <- read_cmdstan_csv(cmdstanfit$output_files()) + stanfit <- as_cmdstan_fit(cmdstanfit$output_files()) } } } else { From 1a040c38c01652cfa495c3cff4f75ca1807352a0 Mon Sep 17 00:00:00 2001 From: timjzee Date: Wed, 26 Jun 2024 19:50:46 +0200 Subject: [PATCH 3/7] Fix log_lik for multi_normals with >2 variables --- R/ulam_templates.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/ulam_templates.R b/R/ulam_templates.R index f9e8f07..8f00ecf 100644 --- a/R/ulam_templates.R +++ b/R/ulam_templates.R @@ -472,7 +472,9 @@ ulam_dists <- list( out <- concat( out , indent , out_var , " ~ multi_normal( " , MU_var , " , " , SIGMA , " );\n" ) } else { - out <- concat( out , indent , "log_lik = multi_normal_lpdf( " , out_var , " | " , MU_var , " , " , SIGMA , " );\n" ) + out <- concat( out , indent , "for ( j in 1:" , n_cases , " ) {\n" ) + out <- concat( out , indent , indent , "log_lik[j] = multi_normal_lpdf( " , out_var , "[j] | " , MU_var , "[j] , " , SIGMA , " );\n" ) + out <- concat( out , indent , "}\n" ) } # close local environment, if necessary From a58e536754656df014e5f6c274a9d5dcf106cc4b Mon Sep 17 00:00:00 2001 From: timjzee Date: Wed, 3 Jul 2024 12:56:12 +0200 Subject: [PATCH 4/7] Check error location --- R/ulam-function.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/ulam-function.R b/R/ulam-function.R index 6440032..267ca6e 100644 --- a/R/ulam-function.R +++ b/R/ulam-function.R @@ -1037,7 +1037,9 @@ ulam <- function( flist , data , pars , pars_omit , start , chains=1 , cores=1 , # add by default built <- compose_distibution( left_symbol , flist[[i]] , as_log_lik=TRUE ) m_gq2 <- concat( m_gq2 , built ) + message(left_symbol) N <- symbols[[left_symbol]]$dims[[2]] + message("Worked") m_gq1 <- concat( m_gq1 , indent , "vector[" , N , "] log_lik;\n" ) # save N to attr so nobs/compare can get it later nobs_save <- N From d86334d242e2827a45e9914303bf5cf0f5d4a5ba Mon Sep 17 00:00:00 2001 From: timjzee Date: Wed, 3 Jul 2024 13:49:21 +0200 Subject: [PATCH 5/7] Check error --- R/ulam-function.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/ulam-function.R b/R/ulam-function.R index 267ca6e..cfbb363 100644 --- a/R/ulam-function.R +++ b/R/ulam-function.R @@ -1037,7 +1037,7 @@ ulam <- function( flist , data , pars , pars_omit , start , chains=1 , cores=1 , # add by default built <- compose_distibution( left_symbol , flist[[i]] , as_log_lik=TRUE ) m_gq2 <- concat( m_gq2 , built ) - message(left_symbol) + message(symbols) N <- symbols[[left_symbol]]$dims[[2]] message("Worked") m_gq1 <- concat( m_gq1 , indent , "vector[" , N , "] log_lik;\n" ) From cb59daf3862df0650a28f65eaa7215d0f28e2710 Mon Sep 17 00:00:00 2001 From: timjzee Date: Wed, 3 Jul 2024 13:59:55 +0200 Subject: [PATCH 6/7] Debug --- R/ulam-function.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/ulam-function.R b/R/ulam-function.R index cfbb363..a2c2b20 100644 --- a/R/ulam-function.R +++ b/R/ulam-function.R @@ -1037,6 +1037,7 @@ ulam <- function( flist , data , pars , pars_omit , start , chains=1 , cores=1 , # add by default built <- compose_distibution( left_symbol , flist[[i]] , as_log_lik=TRUE ) m_gq2 <- concat( m_gq2 , built ) + message(left_symbol) message(symbols) N <- symbols[[left_symbol]]$dims[[2]] message("Worked") From 8af64396d8a85a4768112d21cabacf3b626e397e Mon Sep 17 00:00:00 2001 From: timjzee Date: Wed, 3 Jul 2024 14:27:10 +0200 Subject: [PATCH 7/7] Hacky fix for #2 --- R/ulam-function.R | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/R/ulam-function.R b/R/ulam-function.R index a2c2b20..dc3f1a9 100644 --- a/R/ulam-function.R +++ b/R/ulam-function.R @@ -1037,10 +1037,7 @@ ulam <- function( flist , data , pars , pars_omit , start , chains=1 , cores=1 , # add by default built <- compose_distibution( left_symbol , flist[[i]] , as_log_lik=TRUE ) m_gq2 <- concat( m_gq2 , built ) - message(left_symbol) - message(symbols) - N <- symbols[[left_symbol]]$dims[[2]] - message("Worked") + N <- symbols[[left_symbol[1]]]$dims[[2]] m_gq1 <- concat( m_gq1 , indent , "vector[" , N , "] log_lik;\n" ) # save N to attr so nobs/compare can get it later nobs_save <- N