The $profiles() method returns a list of data frames with profiling data if any profiling data was written to the profile CSV files. See save_profile_files() to control where the files are saved.

Support for profiling Stan programs is available with CmdStan >= 2.26 and requires adding profiling statements to the Stan program.

profiles()

Value

A list of data frames with profiling data if the profiling CSV files were created.

See also

Examples

# \dontrun{ # first fit a model using MCMC mcmc_program <- write_stan_file( 'data { int<lower=0> N; int<lower=0,upper=1> y[N]; } parameters { real<lower=0,upper=1> theta; } model { profile("likelihood") { y ~ bernoulli(theta); } } generated quantities { int y_rep[N]; profile("gq") { y_rep = bernoulli_rng(rep_vector(theta, N)); } } ' ) mod_mcmc <- cmdstan_model(mcmc_program)
#> Warning in '/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpmzUYEz/model-d65431ed4576.stan', line 3, column 4: Declaration #> of arrays by placing brackets after a variable name is deprecated and #> will be removed in Stan 2.32.0. Instead use the array keyword before the #> type. This can be changed automatically using the auto-format flag to #> stanc #> Warning in '/var/folders/s0/zfzm55px2nd2v__zlw5xfj2h0000gn/T/RtmpmzUYEz/model-d65431ed4576.stan', line 14, column 4: Declaration #> of arrays by placing brackets after a variable name is deprecated and #> will be removed in Stan 2.32.0. Instead use the array keyword before the #> type. This can be changed automatically using the auto-format flag to #> stanc
data <- list(N = 10, y = c(1,1,0,0,0,1,0,1,0,0)) fit <- mod_mcmc$sample(data = data, seed = 123, refresh = 0)
#> Running MCMC with 4 sequential chains... #> #> Chain 1 finished in 0.0 seconds. #> Chain 2 finished in 0.0 seconds. #> Chain 3 finished in 0.0 seconds. #> Chain 4 finished in 0.0 seconds. #> #> All 4 chains finished successfully. #> Mean chain execution time: 0.0 seconds. #> Total execution time: 0.5 seconds. #>
fit$profiles()
#> [[1]] #> name thread_id total_time forward_time reverse_time chain_stack #> 1 gq 0x10f232e00 0.000386068 0.000386068 0.000000000 0 #> 2 likelihood 0x10f232e00 0.001285670 0.000903227 0.000382445 7169 #> no_chain_stack autodiff_calls no_autodiff_calls #> 1 0 0 1000 #> 2 0 7169 1 #> #> [[2]] #> name thread_id total_time forward_time reverse_time chain_stack #> 1 gq 0x101daee00 0.000393415 0.000393415 0.000000000 0 #> 2 likelihood 0x101daee00 0.001305930 0.000932404 0.000373525 7155 #> no_chain_stack autodiff_calls no_autodiff_calls #> 1 0 0 1000 #> 2 0 7155 1 #> #> [[3]] #> name thread_id total_time forward_time reverse_time chain_stack #> 1 gq 0x1121b1e00 0.000534289 0.000534289 0.000000000 0 #> 2 likelihood 0x1121b1e00 0.001384640 0.000993686 0.000390953 6879 #> no_chain_stack autodiff_calls no_autodiff_calls #> 1 0 0 1000 #> 2 0 6879 1 #> #> [[4]] #> name thread_id total_time forward_time reverse_time chain_stack #> 1 gq 0x113ecce00 0.000356809 0.000356809 0.000000000 0 #> 2 likelihood 0x113ecce00 0.001137030 0.000803924 0.000333102 6892 #> no_chain_stack autodiff_calls no_autodiff_calls #> 1 0 0 1000 #> 2 0 6892 1 #>
# }